Version Description
rtMedia 4.6.1 with added server side validation for terms of services checkbox, minor bug fixes along with warnings and PHPCS fixes
=
Download this release
Release Info
Developer | rtcamp |
Plugin | rtMedia for WordPress, BuddyPress and bbPress |
Version | 4.6.1 |
Comparing to | |
See all releases |
Code changes from version 4.6.0 to 4.6.1
- app/admin/RTMediaAdmin.php +533 -378
- app/admin/RTMediaFormHandler.php +368 -341
- app/admin/RTMediaUploadTermsAdmin.php +4 -0
- app/admin/templates/tmpl-rtm-album-favourites-importer.php +8 -0
- app/admin/templates/tmpl-rtm-image.php +8 -0
- app/admin/templates/tmpl-rtm-map-mapping-failure.php +9 -1
- app/admin/templates/tmpl-rtm-msg-div.php +9 -1
- app/admin/templates/tmpl-rtm-p-tag.php +9 -1
- app/admin/templates/tmpl-rtm-theme-overlay.php +9 -1
- app/assets/admin/js/admin.min.js +1 -1
- app/assets/admin/js/settings.js +197 -84
- app/assets/js/admin-upload-terms.js +59 -40
- app/assets/js/admin-upload-terms.min.js +1 -1
- app/assets/js/rtMedia.backbone.js +47 -9
- app/assets/js/rtMedia.js +26 -14
- app/assets/js/rtm-upload-terms.js +304 -132
- app/assets/js/rtm-upload-terms.min.js +1 -1
- app/assets/js/rtmedia.min.js +1 -1
- app/helper/BPMediaBranding.php +10 -5
- app/helper/RTMediaActivityModel.php +88 -18
- app/helper/RTMediaAddon.php +48 -33
- app/helper/RTMediaAdminWidget.php +24 -15
- app/helper/RTMediaCommentModel.php +26 -17
- app/helper/RTMediaCommentNotification.php +43 -21
- app/helper/RTMediaFeed.php +22 -12
- app/helper/RTMediaInteractionModel.php +15 -16
- app/helper/RTMediaLicense.php +86 -53
- app/helper/RTMediaLikeNotification.php +57 -32
- app/helper/RTMediaModel.php +130 -81
- app/helper/RTMediaNotification.php +51 -21
- app/helper/RTMediaSettings.php +90 -79
- app/helper/RTMediaSupport.php +192 -156
- app/helper/RTMediaThemes.php +26 -25
- app/helper/RTMediaUploadException.php +15 -10
- app/helper/db/RTDBModel.php +63 -35
- app/helper/db/RTDBUpdate.php +73 -28
- app/helper/db/rt_plugin_info.php +96 -29
- app/helper/rtDimensions.php +74 -60
- app/helper/rtForm.php +315 -261
- app/helper/rtFormInvalidArgumentsException.php +26 -13
- app/helper/rtPluginUpdateChecker.php +19 -5
- app/helper/rtProgress.php +13 -14
- app/helper/rtUploadAttachment.php +12 -2
- app/importers/BPMediaAlbumimporter.php +242 -91
- app/importers/BPMediaBPActivityPlusImporter.php +6 -6
- app/importers/BPMediaImporter.php +105 -24
- app/importers/RTMediaActivityUpgrade.php +121 -37
- app/importers/RTMediaMediaSizeImporter.php +146 -56
- app/importers/RTMediaMigration.php +323 -137
- app/main/RTMedia.php +768 -331
- app/main/RTMediaUploadTerms.php +57 -9
- app/main/contexts/RTMediaContext.php +35 -23
- app/main/controllers/activity/RTMediaActivity.php +53 -25
- app/main/controllers/activity/RTMediaBuddyPressActivity.php +380 -249
- app/main/controllers/api/RTMediaApiLogin.php +12 -2
- app/main/controllers/api/RTMediaJsonApi.php +427 -194
- app/main/controllers/api/RTMediaJsonApiFunctions.php +163 -52
- app/main/controllers/group/RTMediaGroup.php +21 -8
- app/main/controllers/group/RTMediaGroupExtension.php +117 -68
- app/main/controllers/media/RTMediaAlbum.php +121 -106
- app/main/controllers/media/RTMediaComment.php +116 -78
- app/main/controllers/media/RTMediaFeatured.php +146 -37
- app/main/controllers/media/RTMediaGalleryItemAction.php +49 -20
- app/main/controllers/media/RTMediaGroupFeatured.php +135 -32
- app/main/controllers/media/RTMediaLike.php +160 -50
- app/main/controllers/media/RTMediaLoginPopup.php +30 -19
- app/main/controllers/media/RTMediaMedia.php +235 -173
- app/main/controllers/media/RTMediaMeta.php +98 -14
- app/main/controllers/media/RTMediaTags.php +76 -28
- app/main/controllers/media/RTMediaUserInteraction.php +156 -43
- app/main/controllers/media/RTMediaViewCount.php +27 -11
- app/main/controllers/privacy/RTMediaFriends.php +22 -11
- app/main/controllers/privacy/RTMediaPrivacy.php +225 -103
- app/main/controllers/shortcodes/RTMediaGalleryShortcode.php +147 -86
- app/main/controllers/shortcodes/RTMediaUploadShortcode.php +38 -15
- app/main/controllers/template/RTMediaAJAX.php +51 -30
- app/main/controllers/template/RTMediaNav.php +294 -78
- app/main/controllers/template/RTMediaTemplate.php +75 -42
app/admin/RTMediaAdmin.php
CHANGED
@@ -1,23 +1,51 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
/**
|
4 |
-
*
|
5 |
*
|
6 |
-
* @package
|
7 |
* @subpackage Admin
|
8 |
-
*
|
9 |
*/
|
|
|
10 |
if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
11 |
|
12 |
/**
|
13 |
-
*
|
14 |
*/
|
15 |
class RTMediaAdmin {
|
16 |
|
|
|
|
|
|
|
|
|
|
|
17 |
public $rtmedia_upgrade;
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
public $rtmedia_settings;
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
public $rtmedia_encoding;
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
public $rtmedia_support;
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
public $rtmedia_feed;
|
22 |
|
23 |
/**
|
@@ -28,7 +56,7 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
28 |
public function __construct() {
|
29 |
global $rtmedia;
|
30 |
|
31 |
-
// Actions and filters
|
32 |
add_action( 'init', array( $this, 'video_transcoding_survey_response' ) );
|
33 |
add_filter( 'plugin_action_links_' . RTMEDIA_BASE_NAME, array( &$this, 'plugin_add_settings_link' ) );
|
34 |
|
@@ -39,21 +67,25 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
39 |
|
40 |
add_action( 'wp_ajax_rtmedia_submit_request', array( $this->rtmedia_support, 'submit_request' ), 1 );
|
41 |
|
42 |
-
add_action( 'wp_ajax_rtmedia_linkback', array( $this, 'linkback' ), 1 ); //
|
43 |
add_action( 'wp_ajax_rtmedia_rt_album_deactivate', 'BPMediaAlbumimporter::bp_album_deactivate', 1 );
|
44 |
add_action( 'wp_ajax_rtmedia_rt_album_import', 'BPMediaAlbumimporter::bpmedia_ajax_import_callback', 1 );
|
45 |
add_action( 'wp_ajax_rtmedia_rt_album_import_favorites', 'BPMediaAlbumimporter::bpmedia_ajax_import_favorites', 1 );
|
46 |
add_action( 'wp_ajax_rtmedia_rt_album_import_step_favorites', 'BPMediaAlbumimporter::bpmedia_ajax_import_step_favorites', 1 );
|
47 |
add_action( 'wp_ajax_rtmedia_rt_album_cleanup', 'BPMediaAlbumimporter::cleanup_after_install' );
|
48 |
-
add_action( 'wp_ajax_rtmedia_convert_videos_form', array( $this, 'convert_videos_mailchimp_send' ), 1 ); //
|
49 |
add_action( 'wp_ajax_rtmedia_correct_upload_filetypes', array( $this, 'correct_upload_filetypes' ), 1 );
|
50 |
add_filter( 'plugin_row_meta', array( $this, 'plugin_meta_premium_addon_link' ), 1, 2 );
|
51 |
add_action( 'wp_dashboard_setup', array( $this, 'add_dashboard_widgets' ), 0 );
|
52 |
add_action( 'wp_ajax_rtmedia_export_settings', array( $this, 'export_settings' ), 10 );
|
53 |
-
add_action(
|
54 |
-
|
55 |
-
|
56 |
-
|
|
|
|
|
|
|
|
|
57 |
add_filter( 'media_row_actions', array( $this, 'modify_medialibrary_permalink' ), 10, 2 );
|
58 |
|
59 |
if ( ! isset( $rtmedia->options ) ) {
|
@@ -96,22 +128,34 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
96 |
add_action( 'admin_init', array( $this, 'check_permalink_admin_notice' ) );
|
97 |
}
|
98 |
|
99 |
-
add_action(
|
100 |
-
|
101 |
-
|
102 |
-
|
|
|
|
|
|
|
|
|
103 |
add_action( 'admin_init', array( $this, 'rtmedia_bp_add_update_type' ) );
|
104 |
-
add_action(
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
add_action( 'wp_ajax_rtmedia_hide_premium_addon_notice', array( $this, 'rtmedia_hide_premium_addon_notice' ), 1 );
|
113 |
|
114 |
-
new RTMediaMediaSizeImporter(); // do not delete this line. We only need to create object of this class if we are in admin section
|
115 |
if ( class_exists( 'BuddyPress' ) ) {
|
116 |
new RTMediaActivityUpgrade();
|
117 |
}
|
@@ -131,19 +175,19 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
131 |
/**
|
132 |
* Display admin notice.
|
133 |
*/
|
134 |
-
function install_transcoder_admin_notice() {
|
135 |
$show_notice = get_site_option( 'install_transcoder_admin_notice', 1 );
|
136 |
if ( '1' === $show_notice || 1 === $show_notice ) :
|
137 |
-
|
138 |
<div class="notice notice-info install-transcoder-notice is-dismissible">
|
139 |
<?php wp_nonce_field( '_install_transcoder_hide_notice_', 'install_transcoder_hide_notice_nonce' ); ?>
|
140 |
<p>
|
141 |
<?php
|
142 |
$allowed_tags = array(
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
);
|
148 |
echo wp_kses( __( 'Install <a href="https://wordpress.org/plugins/transcoder/" target="_blank">Transcoder plugin</a> to convert audio/video files and thumbnails generation.', 'buddypress-media' ), $allowed_tags );
|
149 |
?>
|
@@ -162,20 +206,24 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
162 |
});
|
163 |
});
|
164 |
</script>
|
165 |
-
|
166 |
endif;
|
167 |
}
|
|
|
168 |
/**
|
169 |
* Set option to hide admin notice when user click on dismiss button.
|
170 |
*/
|
171 |
-
function install_transcoder_hide_admin_notice() {
|
172 |
if ( check_ajax_referer( '_install_transcoder_hide_notice_', 'install_transcoder_notice_nonce' ) ) {
|
173 |
update_site_option( 'install_transcoder_admin_notice', '0' );
|
174 |
}
|
175 |
die();
|
176 |
}
|
177 |
|
178 |
-
|
|
|
|
|
|
|
179 |
foreach ( glob( RTMEDIA_PATH . 'app/admin/templates/*.php' ) as $filename ) {
|
180 |
$slug = rtrim( basename( $filename ), '.php' );
|
181 |
|
@@ -184,9 +232,9 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
184 |
echo '</script>';
|
185 |
}
|
186 |
|
187 |
-
$
|
188 |
|
189 |
-
if ( ! empty( $
|
190 |
/**
|
191 |
* Filter is use to enable comment option in side the media that are being uploaded in the comment section.
|
192 |
*
|
@@ -195,10 +243,11 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
195 |
* @param True to hide the option and false to show the option.
|
196 |
*/
|
197 |
$display = apply_filters( 'rtmedia_disable_media_in_commented_media', true );
|
198 |
-
if ( $display ) {
|
|
|
199 |
<style type="text/css">
|
200 |
.rtm-option-wrapper .form-table[data-depends="buddypress_enableOnComment"] {
|
201 |
-
|
202 |
}
|
203 |
</style>
|
204 |
<?php
|
@@ -206,23 +255,39 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
206 |
}
|
207 |
}
|
208 |
|
209 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
210 |
$rtm_id = rtmedia_id( $post->ID );
|
211 |
|
212 |
if ( $rtm_id ) {
|
213 |
-
$link
|
214 |
-
$title
|
215 |
-
|
|
|
|
|
216 |
}
|
217 |
|
218 |
return $action;
|
219 |
}
|
220 |
|
221 |
-
|
|
|
|
|
|
|
222 |
new RTMediaMigration();
|
223 |
}
|
224 |
|
225 |
-
|
|
|
|
|
|
|
226 |
do_action( 'rtmedia_addon_license_save_hook' );
|
227 |
}
|
228 |
|
@@ -231,8 +296,6 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
231 |
*
|
232 |
* @access public
|
233 |
*
|
234 |
-
* @param void
|
235 |
-
*
|
236 |
* @return void
|
237 |
*/
|
238 |
public function rtmedia_network_admin_notices() {
|
@@ -242,12 +305,10 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
242 |
}
|
243 |
|
244 |
/**
|
245 |
-
* Show
|
246 |
*
|
247 |
* @access public
|
248 |
*
|
249 |
-
* @param void
|
250 |
-
*
|
251 |
* @return void
|
252 |
*/
|
253 |
public function rtmedia_admin_notices() {
|
@@ -263,8 +324,8 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
263 |
}
|
264 |
}
|
265 |
|
266 |
-
|
267 |
-
* rtMedia Pro split release admin notice
|
268 |
*/
|
269 |
public function rtmedia_premium_addon_notice() {
|
270 |
$site_option = rtmedia_get_site_option( 'rtmedia_premium_addon_notice' );
|
@@ -276,17 +337,24 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
276 |
<p>
|
277 |
<span>
|
278 |
<?php
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
?>
|
284 |
<b><?php esc_html_e( 'rtMedia: ', 'buddypress-media' ); ?></b>
|
285 |
-
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
286 |
</span>
|
287 |
-
<a href="#"
|
288 |
-
onclick="rtmedia_hide_premium_addon_notice('<?php echo esc_js( wp_create_nonce( 'rtcamp_pro_split' ) ); ?>');"
|
289 |
-
style="float:right">Dismiss</a>
|
290 |
</p>
|
291 |
</div>
|
292 |
<script type="text/javascript">
|
@@ -304,11 +372,10 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
304 |
}
|
305 |
}
|
306 |
|
307 |
-
|
308 |
* Hide pro split release notice
|
309 |
*/
|
310 |
-
|
311 |
-
function rtmedia_hide_premium_addon_notice() {
|
312 |
if ( check_ajax_referer( 'rtcamp_pro_split', '_rtm_nonce' ) && rtmedia_update_site_option( 'rtmedia_premium_addon_notice', 'hide' ) ) {
|
313 |
echo '1';
|
314 |
} else {
|
@@ -318,12 +385,10 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
318 |
}
|
319 |
|
320 |
/**
|
321 |
-
* Show
|
322 |
*
|
323 |
* @access public
|
324 |
*
|
325 |
-
* @param void
|
326 |
-
*
|
327 |
* @return void
|
328 |
*/
|
329 |
public function rtmedia_inspirebook_release_notice() {
|
@@ -334,14 +399,13 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
334 |
<div class="updated rtmedia-inspire-book-notice">
|
335 |
<p>
|
336 |
<span>
|
337 |
-
<a href="https://rtmedia.io/products/inspirebook/"
|
338 |
-
|
339 |
-
<b><?php esc_html_e( 'Meet InspireBook', 'buddypress-media' ) ?></b>
|
340 |
</a>
|
341 |
<?php esc_html_e( ' - First official rtMedia premium theme.', 'buddypress-media' ); ?>
|
342 |
</span>
|
343 |
<a href="#" onclick="rtmedia_hide_inspirebook_notice()" style="float:right">Dismiss</a>
|
344 |
-
<?php wp_nonce_field( '_rtmedia_hide_inspirebook_notice_','rtmedia_hide_inspirebook_nonce' ); ?>
|
345 |
</p>
|
346 |
</div>
|
347 |
<script type="text/javascript">
|
@@ -366,8 +430,6 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
366 |
*
|
367 |
* @access public
|
368 |
*
|
369 |
-
* @param void
|
370 |
-
*
|
371 |
* @return void
|
372 |
*/
|
373 |
public function rtmedia_hide_inspirebook_release_notice() {
|
@@ -385,8 +447,6 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
385 |
*
|
386 |
* @access public
|
387 |
*
|
388 |
-
* @param void
|
389 |
-
*
|
390 |
* @return void
|
391 |
*/
|
392 |
public function rtmedia_bp_add_update_type() {
|
@@ -400,8 +460,6 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
400 |
*
|
401 |
* @access public
|
402 |
*
|
403 |
-
* @param void
|
404 |
-
*
|
405 |
* @return void
|
406 |
*/
|
407 |
public function check_permalink_admin_notice() {
|
@@ -416,8 +474,6 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
416 |
*
|
417 |
* @access public
|
418 |
*
|
419 |
-
* @param void
|
420 |
-
*
|
421 |
* @return void
|
422 |
*/
|
423 |
public function rtmedia_permalink_notice() {
|
@@ -431,8 +487,6 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
431 |
*
|
432 |
* @access public
|
433 |
*
|
434 |
-
* @param void
|
435 |
-
*
|
436 |
* @return void
|
437 |
*/
|
438 |
public function rtmedia_addon_update_notice() {
|
@@ -447,12 +501,10 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
447 |
?>
|
448 |
<div class="error rtmedia-addon-upate-notice">
|
449 |
<p>
|
450 |
-
<strong><?php esc_html_e( 'rtMedia:', 'buddypress-media' ) ?></strong>
|
451 |
-
<?php esc_html_e( 'Please update all premium add-ons that you have purchased from', 'buddypress-media' ) ?>
|
452 |
-
<a href="https://rtmedia.io/my-account/"
|
453 |
-
|
454 |
-
<a href="#" onclick="rtmedia_hide_addon_update_notice()"
|
455 |
-
style="float:right"><?php esc_html_e( 'Dismiss', 'buddypress-media' ) ?></a>
|
456 |
<?php wp_nonce_field( 'rtmedia-addon-update-notice-3_8', 'rtmedia-addon-notice' ); ?>
|
457 |
</p>
|
458 |
</div>
|
@@ -474,68 +526,66 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
474 |
}
|
475 |
|
476 |
/**
|
477 |
-
* Show
|
478 |
*
|
479 |
* @access public
|
480 |
*
|
481 |
-
* @
|
482 |
-
*
|
483 |
-
* @return bool $return_falg
|
484 |
*/
|
485 |
public function check_for_addon_update_notice() {
|
486 |
-
$
|
487 |
|
488 |
-
// check for rtMedia Instagram version
|
489 |
if ( defined( 'RTMEDIA_INSTAGRAM_PATH' ) ) {
|
490 |
$plugin_info = get_plugin_data( RTMEDIA_INSTAGRAM_PATH . 'index.php' );
|
491 |
if ( isset( $plugin_info['Version'] ) && ( - 1 === version_compare( $plugin_info['Version'], '2.1.14' ) ) ) {
|
492 |
-
$
|
493 |
}
|
494 |
} elseif ( defined( 'RTMEDIA_PHOTO_TAGGING_PATH' ) ) {
|
495 |
-
// check for rtMedia Photo Tagging version
|
496 |
$plugin_info = get_plugin_data( RTMEDIA_PHOTO_TAGGING_PATH . 'index.php' );
|
497 |
if ( isset( $plugin_info['Version'] ) && ( - 1 === version_compare( $plugin_info['Version'], '2.2.14' ) ) ) {
|
498 |
-
$
|
499 |
}
|
500 |
} elseif ( defined( 'RTMEDIA_FFMPEG_PATH' ) ) {
|
501 |
-
// check for rtMedia FFPMEG version
|
502 |
$plugin_info = get_plugin_data( RTMEDIA_FFMPEG_PATH . 'index.php' );
|
503 |
if ( isset( $plugin_info['Version'] ) && ( - 1 === version_compare( $plugin_info['Version'], '2.1.14' ) ) ) {
|
504 |
-
$
|
505 |
}
|
506 |
} elseif ( defined( 'RTMEDIA_KALTURA_PATH' ) ) {
|
507 |
-
// check for rtMedia Kaltura version
|
508 |
$plugin_info = get_plugin_data( RTMEDIA_KALTURA_PATH . 'index.php' );
|
509 |
if ( isset( $plugin_info['Version'] ) && ( - 1 === version_compare( $plugin_info['Version'], '3.0.16' ) ) ) {
|
510 |
-
$
|
511 |
}
|
512 |
} elseif ( defined( 'RTMEDIA_PRO_PATH' ) ) {
|
513 |
-
// check for rtMedia Pro version
|
514 |
$plugin_info = get_plugin_data( RTMEDIA_PRO_PATH . 'index.php' );
|
515 |
if ( isset( $plugin_info['Version'] ) && ( - 1 === version_compare( $plugin_info['Version'], '2.6' ) ) ) {
|
516 |
-
$
|
517 |
}
|
518 |
} elseif ( defined( 'RTMEDIA_SOCIAL_SYNC_PATH' ) ) {
|
519 |
-
// check for rtMedia Social Sync version
|
520 |
$plugin_info = get_plugin_data( RTMEDIA_SOCIAL_SYNC_PATH . 'index.php' );
|
521 |
if ( isset( $plugin_info['Version'] ) && ( - 1 === version_compare( $plugin_info['Version'], '1.3.1' ) ) ) {
|
522 |
-
$
|
523 |
}
|
524 |
} elseif ( defined( 'RTMEDIA_MEMBERSHIP_PATH' ) ) {
|
525 |
-
// check for rtMedia Membership version
|
526 |
$plugin_info = get_plugin_data( RTMEDIA_MEMBERSHIP_PATH . 'index.php' );
|
527 |
if ( isset( $plugin_info['Version'] ) && ( - 1 === version_compare( $plugin_info['Version'], '2.1.5' ) ) ) {
|
528 |
-
$
|
529 |
}
|
530 |
} elseif ( defined( 'RTMEDIA_WATERMARK_PATH' ) ) {
|
531 |
-
// check for rtMedia Photo Watermak version
|
532 |
$plugin_info = get_plugin_data( RTMEDIA_WATERMARK_PATH . 'index.php' );
|
533 |
if ( isset( $plugin_info['Version'] ) && ( - 1 === version_compare( $plugin_info['Version'], '1.1.8' ) ) ) {
|
534 |
-
$
|
535 |
}
|
536 |
}
|
537 |
|
538 |
-
return $
|
539 |
}
|
540 |
|
541 |
/**
|
@@ -543,8 +593,6 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
543 |
*
|
544 |
* @access public
|
545 |
*
|
546 |
-
* @param void
|
547 |
-
*
|
548 |
* @return void
|
549 |
*/
|
550 |
public function bp_admin_tabs() {
|
@@ -554,12 +602,10 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
554 |
}
|
555 |
|
556 |
/**
|
557 |
-
* Show
|
558 |
*
|
559 |
* @access public
|
560 |
*
|
561 |
-
* @param void
|
562 |
-
*
|
563 |
* @return void
|
564 |
*/
|
565 |
public function rtmedia_advertisement() {
|
@@ -578,8 +624,6 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
578 |
*
|
579 |
* @access public
|
580 |
*
|
581 |
-
* @param void
|
582 |
-
*
|
583 |
* @return void
|
584 |
*/
|
585 |
public function rtmedia_dashboard_widget_function() {
|
@@ -597,7 +641,7 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
597 |
global $wpdb;
|
598 |
$results = wp_cache_get( 'rt-stats', 'rt-dashboard' );
|
599 |
if ( false === $results ) {
|
600 |
-
$results = $wpdb->get_results( $wpdb->prepare( "select media_type, count(id) as count from {$rtmedia_model->table_name} where blog_id=%d group by media_type", get_current_blog_id() ) ); //
|
601 |
wp_cache_set( 'stats', $results, 'rt-dashboard', HOUR_IN_SECONDS );
|
602 |
}
|
603 |
if ( $results ) {
|
@@ -621,7 +665,8 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
621 |
<h4 class="sub"><?php esc_html_e( 'Usage Stats', 'buddypress-media' ); ?></h4>
|
622 |
|
623 |
<table>
|
624 |
-
<tbody>
|
|
|
625 |
$total_count = wp_cache_get( 'total_count', 'rt-dashboard' );
|
626 |
if ( false === $total_count ) {
|
627 |
$total_count = $wpdb->get_var( "select count(*) from {$wpdb->users}" );
|
@@ -630,40 +675,40 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
630 |
?>
|
631 |
<tr>
|
632 |
<td class="b"> <?php echo esc_html( $total_count ); ?> </td>
|
633 |
-
<td class="t"><?php esc_html_e( 'Total ', 'buddypress-media' ) ?></td>
|
634 |
</tr>
|
635 |
<?php
|
636 |
$with_media_count = wp_cache_get( 'with_media', 'rt-dashboard' );
|
637 |
if ( false === $with_media_count ) {
|
638 |
-
$with_media_count = $wpdb->get_var( "select count(distinct media_author) from {$rtmedia_model->table_name}" ); //
|
639 |
wp_cache_set( 'with_media', $with_media_count, 'rt-dashboard', HOUR_IN_SECONDS );
|
640 |
}
|
641 |
?>
|
642 |
<tr>
|
643 |
<td class="b"> <?php echo esc_html( $with_media_count ); ?> </td>
|
644 |
-
<td class="t"><?php esc_html_e( 'With Media', 'buddypress-media' ) ?></td>
|
645 |
</tr>
|
646 |
<?php
|
647 |
$comments = wp_cache_get( 'comments', 'rt-dashboard' );
|
648 |
if ( false === $comments ) {
|
649 |
-
$comments = $wpdb->get_var( "select count(*) from {$wpdb->comments} where comment_post_ID in ( select media_id from {$rtmedia_model->table_name} )" ); //
|
650 |
wp_cache_set( 'comments', $comments, 'rt-dashboard', HOUR_IN_SECONDS );
|
651 |
}
|
652 |
?>
|
653 |
<tr>
|
654 |
<td class="b"> <?php echo esc_html( $comments ); ?> </td>
|
655 |
-
<td class="t"><?php esc_html_e( 'Comments ', 'buddypress-media' ) ?></td>
|
656 |
</tr>
|
657 |
<?php
|
658 |
$likes = wp_cache_get( 'likes', 'rt-dashboard' );
|
659 |
if ( false === $likes ) {
|
660 |
-
$likes = $wpdb->get_var( "select sum(likes) from {$rtmedia_model->table_name}" ); //
|
661 |
wp_cache_set( 'likes', $likes, 'rt-dashboard', HOUR_IN_SECONDS );
|
662 |
}
|
663 |
?>
|
664 |
<tr>
|
665 |
<td class="b"> <?php echo esc_html( $likes ); ?> </td>
|
666 |
-
<td class="t"><?php esc_html_e( 'Likes', 'buddypress-media' ) ?></td>
|
667 |
</tr>
|
668 |
</tbody>
|
669 |
</table>
|
@@ -691,34 +736,32 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
691 |
*
|
692 |
* @access public
|
693 |
*
|
694 |
-
* @param void
|
695 |
-
*
|
696 |
* @return void
|
697 |
*/
|
698 |
public function add_dashboard_widgets() {
|
699 |
-
wp_add_dashboard_widget(
|
700 |
-
|
701 |
-
'
|
702 |
-
|
|
|
|
|
|
|
|
|
703 |
global $wp_meta_boxes;
|
704 |
|
705 |
// Get the regular dashboard widgets array
|
706 |
-
// (which has our new widget already but at the end)
|
707 |
-
|
708 |
$normal_dashboard = $wp_meta_boxes['dashboard']['normal']['core'];
|
709 |
|
710 |
-
// Backup and delete our new dashboard widget from the end of the array
|
711 |
-
|
712 |
$example_widget_backup = array( 'rtmedia_dashboard_widget' => $normal_dashboard['rtmedia_dashboard_widget'] );
|
713 |
unset( $normal_dashboard['rtmedia_dashboard_widget'] );
|
714 |
|
715 |
-
// Merge the two arrays together so our widget is at the beginning
|
716 |
-
|
717 |
$sorted_dashboard = array_merge( $example_widget_backup, $normal_dashboard );
|
718 |
|
719 |
-
// Save the sorted array back into the original metaboxes
|
720 |
-
|
721 |
-
$wp_meta_boxes['dashboard']['normal']['core'] = $sorted_dashboard;
|
722 |
}
|
723 |
|
724 |
/**
|
@@ -726,7 +769,7 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
726 |
*
|
727 |
* @access public
|
728 |
*
|
729 |
-
* @param array $links
|
730 |
*
|
731 |
* @return array $links
|
732 |
*/
|
@@ -744,7 +787,7 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
744 |
*
|
745 |
* @access public
|
746 |
*
|
747 |
-
* @param object $admin_bar
|
748 |
*
|
749 |
* @return void
|
750 |
*/
|
@@ -753,7 +796,8 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
753 |
return;
|
754 |
}
|
755 |
|
756 |
-
$admin_bar->add_menu(
|
|
|
757 |
'id' => 'rtMedia',
|
758 |
'title' => 'rtMedia',
|
759 |
'href' => admin_url( 'admin.php?page=rtmedia-settings' ),
|
@@ -762,7 +806,8 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
762 |
),
|
763 |
)
|
764 |
);
|
765 |
-
$admin_bar->add_menu(
|
|
|
766 |
'id' => 'rt-media-dashborad',
|
767 |
'parent' => 'rtMedia',
|
768 |
'title' => esc_html__( 'Settings', 'buddypress-media' ),
|
@@ -774,7 +819,8 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
774 |
)
|
775 |
);
|
776 |
if ( ! is_rtmedia_vip_plugin() ) {
|
777 |
-
$admin_bar->add_menu(
|
|
|
778 |
'id' => 'rt-media-addons',
|
779 |
'parent' => 'rtMedia',
|
780 |
'title' => esc_html__( 'Addons', 'buddypress-media' ),
|
@@ -786,7 +832,8 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
786 |
)
|
787 |
);
|
788 |
}
|
789 |
-
$admin_bar->add_menu(
|
|
|
790 |
'id' => 'rt-media-support',
|
791 |
'parent' => 'rtMedia',
|
792 |
'title' => esc_html__( 'Support', 'buddypress-media' ),
|
@@ -798,7 +845,8 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
798 |
)
|
799 |
);
|
800 |
if ( ! is_rtmedia_vip_plugin() ) {
|
801 |
-
$admin_bar->add_menu(
|
|
|
802 |
'id' => 'rt-media-themes',
|
803 |
'parent' => 'rtMedia',
|
804 |
'title' => esc_html__( 'Themes', 'buddypress-media' ),
|
@@ -811,7 +859,8 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
811 |
);
|
812 |
}
|
813 |
if ( ! is_rtmedia_vip_plugin() ) {
|
814 |
-
$admin_bar->add_menu(
|
|
|
815 |
'id' => 'rt-media-hire-us',
|
816 |
'parent' => 'rtMedia',
|
817 |
'title' => esc_html__( 'Hire Us', 'buddypress-media' ),
|
@@ -824,7 +873,8 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
824 |
);
|
825 |
}
|
826 |
if ( has_filter( 'rtmedia_license_tabs' ) || has_action( 'rtmedia_addon_license_details' ) ) {
|
827 |
-
$admin_bar->add_menu(
|
|
|
828 |
'id' => 'rt-media-license',
|
829 |
'parent' => 'rtMedia',
|
830 |
'title' => esc_html__( 'Licenses', 'buddypress-media' ),
|
@@ -843,7 +893,7 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
843 |
*
|
844 |
* @access public
|
845 |
*
|
846 |
-
* @param string $hook
|
847 |
*
|
848 |
* @return void
|
849 |
*/
|
@@ -874,36 +924,44 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
874 |
|
875 |
/* Only one JS file should enqueue */
|
876 |
if ( '' === $suffix ) {
|
877 |
-
wp_enqueue_script( 'rtmedia-admin-tabs', RTMEDIA_URL . 'app/assets/admin/js/vendors/tabs.js', array( 'backbone' ), RTMEDIA_VERSION );
|
878 |
-
wp_enqueue_script( 'rtmedia-admin-scripts', RTMEDIA_URL . 'app/assets/admin/js/scripts.js', array( 'backbone' ), RTMEDIA_VERSION );
|
879 |
-
wp_enqueue_script( 'rtmedia-admin', RTMEDIA_URL . 'app/assets/admin/js/settings.js', array( 'backbone', 'wp-util' ), RTMEDIA_VERSION );
|
880 |
} else {
|
881 |
-
wp_enqueue_script( 'rtmedia-admin', RTMEDIA_URL . 'app/assets/admin/js/admin.min.js', array( 'backbone', 'wp-util' ), RTMEDIA_VERSION );
|
882 |
}
|
883 |
|
884 |
-
wp_localize_script(
|
885 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
886 |
wp_localize_script( 'rtmedia-admin', 'rtmedia_admin_ajax', $admin_ajax );
|
887 |
wp_localize_script( 'rtmedia-admin', 'rtmedia_admin_url', admin_url() );
|
888 |
/* path for file upload using ajax */
|
889 |
-
wp_localize_script( 'rtmedia-admin', 'rtmedia_fileupload_url', RTMEDIA_URL.'app/helper/rtUploadAttachment.php' );
|
890 |
|
891 |
$rtmedia_admin_strings = array(
|
892 |
-
'no_refresh'
|
893 |
-
'something_went_wrong'
|
894 |
-
'are_you_sure'
|
895 |
-
'disable_encoding'
|
896 |
-
'enable_encoding'
|
897 |
-
'settings_changed'
|
898 |
-
'video_thumbnail_error'
|
899 |
'video_thumbnail_invalid_value' => esc_html__( 'Invalid value for number of video thumbnails in media sizes settings. Setting it to round value', 'buddypress-media' ),
|
900 |
-
'jpeg_quality_negative_error'
|
901 |
-
'jpeg_quality_percentage_error'
|
902 |
-
'jpeg_quality_invalid_value'
|
903 |
-
'per_page_media_negative_value'
|
904 |
-
'per_page_media_positive_error'
|
905 |
-
'request_failed'
|
906 |
-
'wrong_css_input'
|
907 |
);
|
908 |
|
909 |
wp_localize_script( 'rtmedia-admin', 'rtmedia_admin_strings', $rtmedia_admin_strings );
|
@@ -912,20 +970,20 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
912 |
|
913 |
$rtmedia_admin_support_strings = array(
|
914 |
'wp_admin_username_error' => esc_html__( 'Please enter WP Admin Login.', 'buddypress-media' ),
|
915 |
-
'wp_admin_pwd_error'
|
916 |
-
'ssh_ftp_host_error'
|
917 |
'ssh_ftp_username_error' => esc_html__( 'Please enter SSH / FTP login.', 'buddypress-media' ),
|
918 |
-
'ssh_ftp_pwd_error'
|
919 |
-
'all_fields_error'
|
920 |
);
|
921 |
|
922 |
wp_localize_script( 'rtmedia-admin', 'rtmedia_admin_support_strings', $rtmedia_admin_support_strings );
|
923 |
|
924 |
-
|
925 |
wp_enqueue_style( 'rtmedia-admin', RTMEDIA_URL . 'app/assets/admin/css/admin' . $suffix . '.css', '', RTMEDIA_VERSION );
|
926 |
} else {
|
927 |
|
928 |
-
|
929 |
wp_enqueue_style( 'rtmedia-widget', RTMEDIA_URL . 'app/assets/admin/css/widget' . $suffix . '.css', '', RTMEDIA_VERSION );
|
930 |
}
|
931 |
}
|
@@ -936,60 +994,107 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
936 |
* @access public
|
937 |
* @global string 'buddypress-media'
|
938 |
*
|
939 |
-
* @param void
|
940 |
-
*
|
941 |
* @return void
|
942 |
*/
|
943 |
public function menu() {
|
944 |
-
add_menu_page(
|
945 |
-
|
946 |
-
'
|
947 |
-
|
948 |
-
|
949 |
-
|
950 |
-
|
951 |
-
|
952 |
-
|
953 |
-
|
954 |
-
|
955 |
-
|
956 |
-
) );
|
957 |
-
|
958 |
-
add_submenu_page( 'rtmedia-settings', esc_html__( 'Support', 'buddypress-media' ), esc_html__( 'Support', 'buddypress-media' ), 'manage_options', 'rtmedia-support', array(
|
959 |
-
$this,
|
960 |
-
'support_page',
|
961 |
-
) );
|
962 |
|
963 |
-
|
964 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
965 |
$this,
|
966 |
-
'
|
967 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
968 |
}
|
969 |
|
970 |
if ( ! is_rtmedia_vip_plugin() ) {
|
971 |
-
add_submenu_page(
|
972 |
-
|
973 |
-
'
|
974 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
975 |
}
|
976 |
|
977 |
if ( has_filter( 'rtmedia_license_tabs' ) || has_action( 'rtmedia_addon_license_details' ) ) {
|
978 |
-
add_submenu_page(
|
979 |
-
|
980 |
-
'
|
981 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
982 |
}
|
983 |
|
984 |
}
|
985 |
|
986 |
/**
|
987 |
-
* Hide
|
988 |
*
|
989 |
* @access public
|
990 |
*
|
991 |
-
* @param void
|
992 |
-
*
|
993 |
* @return void
|
994 |
*/
|
995 |
public function rtmedia_hide_addon_update_notice() {
|
@@ -1001,14 +1106,11 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
1001 |
die();
|
1002 |
}
|
1003 |
|
1004 |
-
|
1005 |
/**
|
1006 |
* Render the BuddyPress Media Settings page.
|
1007 |
*
|
1008 |
* @access public
|
1009 |
*
|
1010 |
-
* @param void
|
1011 |
-
*
|
1012 |
* @return void
|
1013 |
*/
|
1014 |
public function settings_page() {
|
@@ -1020,8 +1122,6 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
1020 |
*
|
1021 |
* @access public
|
1022 |
*
|
1023 |
-
* @param void
|
1024 |
-
*
|
1025 |
* @return void
|
1026 |
*/
|
1027 |
public function privacy_page() {
|
@@ -1033,8 +1133,6 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
1033 |
*
|
1034 |
* @access public
|
1035 |
*
|
1036 |
-
* @param void
|
1037 |
-
*
|
1038 |
* @return void
|
1039 |
*/
|
1040 |
public function rt_importer_page() {
|
@@ -1046,8 +1144,6 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
1046 |
*
|
1047 |
* @access public
|
1048 |
*
|
1049 |
-
* @param void
|
1050 |
-
*
|
1051 |
* @return void
|
1052 |
*/
|
1053 |
public function convert_videos_page() {
|
@@ -1059,8 +1155,6 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
1059 |
*
|
1060 |
* @access public
|
1061 |
*
|
1062 |
-
* @param void
|
1063 |
-
*
|
1064 |
* @return void
|
1065 |
*/
|
1066 |
public function addons_page() {
|
@@ -1072,8 +1166,6 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
1072 |
*
|
1073 |
* @access public
|
1074 |
*
|
1075 |
-
* @param void
|
1076 |
-
*
|
1077 |
* @return void
|
1078 |
*/
|
1079 |
public function support_page() {
|
@@ -1085,8 +1177,6 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
1085 |
*
|
1086 |
* @access public
|
1087 |
*
|
1088 |
-
* @param void
|
1089 |
-
*
|
1090 |
* @return void
|
1091 |
*/
|
1092 |
public function theme_page() {
|
@@ -1098,14 +1188,15 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
1098 |
*
|
1099 |
* @access public
|
1100 |
*
|
1101 |
-
* @param void
|
1102 |
-
*
|
1103 |
* @return void
|
1104 |
*/
|
1105 |
public function hire_us_page() {
|
1106 |
$this->render_page( 'rtmedia-hire-us' );
|
1107 |
}
|
1108 |
|
|
|
|
|
|
|
1109 |
public function license_page() {
|
1110 |
$this->render_page( 'rtmedia-license' );
|
1111 |
}
|
@@ -1115,13 +1206,11 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
1115 |
*
|
1116 |
* @access static
|
1117 |
*
|
1118 |
-
* @param void
|
1119 |
-
*
|
1120 |
* @return string | array
|
1121 |
*/
|
1122 |
-
static function get_current_tab() {
|
1123 |
-
$
|
1124 |
-
return isset( $
|
1125 |
}
|
1126 |
|
1127 |
/**
|
@@ -1130,12 +1219,12 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
1130 |
* @access public
|
1131 |
* @global string 'buddypress-media'
|
1132 |
*
|
1133 |
-
* @param string $page
|
1134 |
-
* @param array
|
1135 |
*
|
1136 |
* @return void
|
1137 |
*/
|
1138 |
-
public function render_page( $
|
1139 |
?>
|
1140 |
|
1141 |
<div class="wrap bp-media-admin <?php echo esc_attr( $this->get_current_tab() ); ?>">
|
@@ -1144,9 +1233,9 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
1144 |
<h2 class="nav-tab-wrapper"><?php $this->rtmedia_tabs(); ?>
|
1145 |
<span class="alignright by">
|
1146 |
<a class="rt-link"
|
1147 |
-
|
1148 |
-
|
1149 |
-
|
1150 |
<img src="<?php echo esc_url( RTMEDIA_URL ); ?>app/assets/admin/img/rtcamp-logo.png" alt="rtCamp"/>
|
1151 |
</a>
|
1152 |
</span>
|
@@ -1158,77 +1247,79 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
1158 |
<div id="bp-media-settings-boxes" class="bp-media-settings-boxes-container rtm-setting-container">
|
1159 |
|
1160 |
<?php
|
1161 |
-
if ( 'rtmedia-settings' === $
|
1162 |
?>
|
1163 |
-
<form id="bp_media_settings_form" name="bp_media_settings_form" method="post"
|
1164 |
-
enctype="multipart/form-data">
|
1165 |
<div class="bp-media-metabox-holder">
|
1166 |
<div class="rtm-button-container top">
|
1167 |
-
<?php
|
1168 |
-
|
|
|
|
|
1169 |
<div class="rtm-success rtm-fly-warning rtm-save-settings-msg">
|
1170 |
<?php esc_html_e( 'Settings saved successfully!', 'buddypress-media' ); ?>
|
1171 |
</div>
|
1172 |
<?php } ?>
|
1173 |
<input type="hidden" name="rtmedia-options-save" value="true">
|
1174 |
-
<input type="submit"
|
1175 |
-
class="rtmedia-settings-submit button button-primary button-big"
|
1176 |
-
value="<?php esc_attr_e( 'Save Settings', 'buddypress-media' ); ?>">
|
1177 |
</div>
|
1178 |
<?php
|
1179 |
settings_fields( $option_group );
|
1180 |
-
if ( 'rtmedia-settings' === $
|
1181 |
echo '<div id="rtm-settings-tabs">';
|
1182 |
$sub_tabs = $this->settings_sub_tabs();
|
1183 |
-
RTMediaFormHandler::rtForm_settings_tabs_content( $
|
1184 |
echo '</div>';
|
1185 |
} else {
|
1186 |
-
do_settings_sections( $
|
1187 |
}
|
1188 |
?>
|
1189 |
|
1190 |
<div class="rtm-button-container bottom">
|
1191 |
<div class="rtm-social-links alignleft">
|
1192 |
-
<a href="http://twitter.com/rtMediaWP" class="twitter" target="_blank"
|
1193 |
-
|
1194 |
-
|
1195 |
-
|
1196 |
-
|
1197 |
-
|
1198 |
-
<a href="
|
1199 |
-
|
|
|
|
|
|
|
|
|
1200 |
</div>
|
1201 |
|
1202 |
<input type="hidden" name="rtmedia-options-save" value="true">
|
1203 |
-
<input type="submit"
|
1204 |
-
class="rtmedia-settings-submit button button-primary button-big"
|
1205 |
-
value="<?php esc_attr_e( 'Save Settings', 'buddypress-media' ); ?>">
|
1206 |
</div>
|
1207 |
</div>
|
1208 |
-
</form
|
|
|
1209 |
} else {
|
1210 |
?>
|
1211 |
<div class="bp-media-metabox-holder">
|
1212 |
<?php
|
1213 |
-
if ( 'rtmedia-addons' === $
|
1214 |
-
RTMediaAddon::render_addons( $
|
1215 |
-
}
|
1216 |
$rtmedia_support = new RTMediaSupport( false );
|
1217 |
-
$rtmedia_support->render_support( $
|
1218 |
-
}
|
1219 |
-
RTMediaThemes::render_themes( $
|
1220 |
} else {
|
1221 |
-
if ( 'rtmedia-license' === $
|
1222 |
-
RTMediaLicense::render_license( $
|
1223 |
} else {
|
1224 |
-
do_settings_sections( $
|
1225 |
}
|
1226 |
}
|
1227 |
-
do_action( 'rtmedia_admin_page_insert', $
|
1228 |
?>
|
1229 |
</div>
|
1230 |
<?php
|
1231 |
-
do_action( 'rtmedia_admin_page_append', $
|
1232 |
}
|
1233 |
?>
|
1234 |
</div>
|
@@ -1239,7 +1330,8 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
1239 |
|
1240 |
</div>
|
1241 |
|
1242 |
-
</div><!-- .bp-media-admin
|
|
|
1243 |
}
|
1244 |
|
1245 |
/**
|
@@ -1247,19 +1339,15 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
1247 |
*
|
1248 |
* @access public
|
1249 |
*
|
1250 |
-
* @
|
1251 |
-
* @param void
|
1252 |
-
*
|
1253 |
-
* @return string $tabs_html
|
1254 |
*/
|
1255 |
public function tab() {
|
1256 |
|
1257 |
-
$tabs_html = '';
|
1258 |
$idle_class = 'nav-tab';
|
1259 |
$active_class = 'nav-tab nav-tab-active';
|
1260 |
$tabs = array();
|
1261 |
|
1262 |
-
// Check to see which tab we are on
|
1263 |
$tab = $this->get_current_tab();
|
1264 |
/* rtMedia */
|
1265 |
$tabs[] = array(
|
@@ -1279,16 +1367,14 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
1279 |
*
|
1280 |
* @access public
|
1281 |
*
|
1282 |
-
* @param void
|
1283 |
-
*
|
1284 |
* @return void
|
1285 |
*/
|
1286 |
public function rtmedia_tabs() {
|
1287 |
-
// Declare local variables
|
1288 |
$idle_class = 'nav-tab';
|
1289 |
$active_class = 'nav-tab nav-tab-active';
|
1290 |
|
1291 |
-
// Setup core admin tabs
|
1292 |
$tabs = array(
|
1293 |
array(
|
1294 |
'href' => get_admin_url( null, esc_url( add_query_arg( array( 'page' => 'rtmedia-settings' ), 'admin.php' ) ) ),
|
@@ -1332,7 +1418,7 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
1332 |
|
1333 |
$tabs = apply_filters( 'media_add_tabs', $tabs );
|
1334 |
|
1335 |
-
// Loop through tabs and build navigation
|
1336 |
foreach ( array_values( $tabs ) as $tab_data ) {
|
1337 |
$is_current = (bool) ( $tab_data['slug'] === $this->get_current_tab() );
|
1338 |
$tab_class = $is_current ? $active_class : $idle_class;
|
@@ -1350,32 +1436,34 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
1350 |
*
|
1351 |
* @access public
|
1352 |
*
|
1353 |
-
* @param string $page
|
1354 |
*
|
1355 |
* @return void
|
1356 |
*/
|
1357 |
-
public function settings_content_tabs( $
|
1358 |
global $wp_settings_sections, $wp_settings_fields;
|
1359 |
|
1360 |
-
if ( ! isset( $wp_settings_sections ) || ! isset( $wp_settings_sections[ $
|
1361 |
return;
|
1362 |
}
|
1363 |
|
1364 |
-
foreach ( (array) $wp_settings_sections[ $
|
1365 |
if ( $section['title'] ) {
|
1366 |
-
|
|
|
|
|
1367 |
}
|
1368 |
|
1369 |
if ( $section['callback'] ) {
|
1370 |
call_user_func( $section['callback'], $section );
|
1371 |
}
|
1372 |
|
1373 |
-
if ( ! isset( $wp_settings_fields ) || ! isset( $wp_settings_fields[ $
|
1374 |
continue;
|
1375 |
}
|
1376 |
|
1377 |
echo '<table class="form-table">';
|
1378 |
-
do_settings_fields( $
|
1379 |
echo '</table>';
|
1380 |
}
|
1381 |
}
|
@@ -1385,14 +1473,12 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
1385 |
*
|
1386 |
* @access public
|
1387 |
*
|
1388 |
-
* @param void
|
1389 |
-
*
|
1390 |
* @return array $tabs
|
1391 |
*/
|
1392 |
public function settings_sub_tabs() {
|
1393 |
-
$tabs
|
1394 |
|
1395 |
-
// Check to see which tab we are on
|
1396 |
$tab = $this->get_current_tab();
|
1397 |
/* rtMedia */
|
1398 |
|
@@ -1410,7 +1496,7 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
1410 |
'icon' => 'dashicons-groups',
|
1411 |
'title' => esc_html__( 'rtMedia BuddyPress', 'buddypress-media' ),
|
1412 |
'name' => esc_html__( 'BuddyPress', 'buddypress-media' ),
|
1413 |
-
'callback' => array( 'RTMediaFormHandler', 'buddypress_content' ), //change it to BuddyPress Content
|
1414 |
);
|
1415 |
}
|
1416 |
|
@@ -1472,24 +1558,29 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
1472 |
* @access public
|
1473 |
* @global type $rtmedia_admin
|
1474 |
*
|
1475 |
-
* @param void
|
1476 |
-
*
|
1477 |
* @return void
|
1478 |
*/
|
1479 |
public function save_multisite_options() {
|
1480 |
global $rtmedia_admin;
|
1481 |
-
do_action( 'rtmedia_sanitize_settings', wp_unslash( $_POST ) ); //
|
1482 |
|
1483 |
$rtmedia_options = filter_input( INPUT_POST, 'rtmedia_options' );
|
1484 |
if ( isset( $rtmedia_options ) ) {
|
1485 |
-
//todo: How we can sanitize array?
|
1486 |
rtmedia_update_site_option( 'rtmedia_options', $rtmedia_options );
|
1487 |
-
|
1488 |
-
// redirect to settings page in network
|
1489 |
-
|
1490 |
-
|
1491 |
-
|
1492 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1493 |
exit;
|
1494 |
}
|
1495 |
}
|
@@ -1499,20 +1590,19 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
1499 |
*
|
1500 |
* @access public
|
1501 |
*
|
1502 |
-
* @param void
|
1503 |
-
*
|
1504 |
* @return void
|
1505 |
*/
|
1506 |
public function admin_sidebar() {
|
1507 |
do_action( 'rtmedia_before_default_admin_widgets' );
|
1508 |
$current_user = wp_get_current_user();
|
1509 |
-
|
1510 |
-
$
|
1511 |
-
|
1512 |
-
|
1513 |
-
|
1514 |
-
|
1515 |
-
|
|
|
1516 |
|
1517 |
new RTMediaAdminWidget( 'spread-the-word', esc_html__( 'Spread the Word', 'buddypress-media' ), $addons );
|
1518 |
|
@@ -1532,8 +1622,13 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
1532 |
do_action( 'rtmedia_after_default_admin_widgets' );
|
1533 |
}
|
1534 |
|
|
|
|
|
|
|
|
|
|
|
1535 |
public function linkback() {
|
1536 |
-
//
|
1537 |
$linkback = filter_input( INPUT_POST, 'linkback' );
|
1538 |
if ( isset( $linkback ) && $linkback ) {
|
1539 |
return rtmedia_update_site_option( 'rtmedia-add-linkback', true );
|
@@ -1577,6 +1672,7 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
1577 |
|
1578 |
ob_start();
|
1579 |
include $file_path;
|
|
|
1580 |
$settings_data_json = ob_get_clean();
|
1581 |
wp_delete_file( $file_path );
|
1582 |
|
@@ -1615,29 +1711,45 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
1615 |
$response['rtm_response_msg'] = esc_html__( 'Could not update rtMedia Settings', 'buddypress-media' );
|
1616 |
}
|
1617 |
}
|
|
|
1618 |
wp_send_json( $response );
|
1619 |
}
|
1620 |
|
|
|
|
|
|
|
1621 |
public function convert_videos_mailchimp_send() {
|
1622 |
-
//todo: nonce required
|
1623 |
-
$interested = filter_input( INPUT_POST, 'linkback', FILTER_SANITIZE_STRING );
|
1624 |
-
$choice
|
1625 |
-
$url
|
1626 |
-
$email
|
|
|
1627 |
if ( 'Yes' === $interested && ! empty( $choice ) ) {
|
1628 |
-
wp_remote_get(
|
1629 |
-
|
1630 |
-
|
1631 |
-
|
1632 |
-
|
1633 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1634 |
} else {
|
1635 |
rtmedia_update_site_option( 'rtmedia-survey', 0 );
|
1636 |
}
|
|
|
1637 |
esc_html_e( 'Thank you for your time.', 'buddypress-media' );
|
1638 |
wp_die();
|
1639 |
}
|
1640 |
|
|
|
|
|
|
|
1641 |
public function video_transcoding_survey_response() {
|
1642 |
$survey_done = filter_input( INPUT_GET, 'survey-done', FILTER_SANITIZE_STRING );
|
1643 |
if ( isset( $survey_done ) && ( md5( 'survey-done' ) === $survey_done ) ) {
|
@@ -1645,6 +1757,14 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
1645 |
}
|
1646 |
}
|
1647 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1648 |
public function plugin_meta_premium_addon_link( $plugin_meta, $plugin_file ) {
|
1649 |
if ( plugin_basename( RTMEDIA_PATH . 'index.php' ) === $plugin_file ) {
|
1650 |
$plugin_meta[] = '<a href="https://rtmedia.io/products/?utm_source=dashboard&utm_medium=plugin&utm_campaign=buddypress-media" title="' . esc_attr__( 'Premium Add-ons', 'buddypress-media' ) . '">' . esc_html__( 'Premium Add-ons', 'buddypress-media' ) . '</a>';
|
@@ -1653,11 +1773,15 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
1653 |
return $plugin_meta;
|
1654 |
}
|
1655 |
|
|
|
|
|
|
|
1656 |
public function upload_filetypes_error() {
|
1657 |
global $rtmedia;
|
1658 |
$upload_filetypes = rtmedia_get_site_option( 'upload_filetypes', 'jpg jpeg png gif' );
|
1659 |
$upload_filetypes = explode( ' ', $upload_filetypes );
|
1660 |
$flag = false;
|
|
|
1661 |
if ( isset( $rtmedia->options['images_enabled'] ) && $rtmedia->options['images_enabled'] ) {
|
1662 |
$not_supported_image = array_diff( array( 'jpg', 'jpeg', 'png', 'gif' ), $upload_filetypes );
|
1663 |
if ( ! empty( $not_supported_image ) ) {
|
@@ -1665,12 +1789,15 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
1665 |
<div class="error upload-filetype-network-settings-error">
|
1666 |
<p>
|
1667 |
<?php wp_nonce_field( '_rtm_file_type_error_', 'rtm-file-type-error' ); ?>
|
1668 |
-
<?php
|
1669 |
-
|
1670 |
-
|
|
|
|
|
|
|
1671 |
<br />
|
1672 |
<strong><?php esc_html_e( 'Recommended:', 'buddypress-media' ); ?></strong>
|
1673 |
-
<input type="button" class="button update-network-settings-upload-filetypes" value="<?php esc_attr_e( 'Update Network Settings Automatically', 'buddypress-media' )
|
1674 |
<img style="display:none;" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" />
|
1675 |
</p>
|
1676 |
</div>
|
@@ -1683,11 +1810,11 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
1683 |
?>
|
1684 |
<div class="error upload-filetype-network-settings-error">
|
1685 |
<p>
|
1686 |
-
<?php esc_html_e( 'You have video enabled on BuddyPress Media but your network allowed filetypes do not permit uploading of mp4. Click ', 'buddypress-media' ) ?>
|
1687 |
-
<a href='<?php echo esc_url( network_admin_url( 'settings.php#upload_filetypes' ) )
|
1688 |
-
<?php esc_html_e( ' to change your settings manually.', 'buddypress-media' ) ?>
|
1689 |
<br />
|
1690 |
-
<strong><?php esc_html_e( 'Recommended:', 'buddypress-media' )
|
1691 |
<input type="button" class="button update-network-settings-upload-filetypes" value="<?php esc_attr_e( 'Update Network Settings Automatically', 'buddypress-media' ); ?>">
|
1692 |
<img style="display:none;" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" />
|
1693 |
</p>
|
@@ -1701,9 +1828,9 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
1701 |
?>
|
1702 |
<div class="error upload-filetype-network-settings-error">
|
1703 |
<p>
|
1704 |
-
<?php esc_html_e( 'You have audio enabled on BuddyPress Media but your network allowed filetypes do not permit uploading of mp3. Click ', 'buddypress-media' ) ?>
|
1705 |
-
<a href='<?php echo esc_url( network_admin_url( 'settings.php#upload_filetypes' ) )
|
1706 |
-
<?php esc_html_e( ' to change your settings manually.', 'buddypress-media' ) ?>
|
1707 |
<br />
|
1708 |
<strong><?php esc_html_e( 'Recommended:', 'buddypress-media' ); ?></strong>
|
1709 |
<input type="button" class="button update-network-settings-upload-filetypes" value="<?php esc_attr_e( 'Update Network Settings Automatically', 'buddypress-media' ); ?>">
|
@@ -1733,13 +1860,19 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
1733 |
}
|
1734 |
}
|
1735 |
|
|
|
|
|
|
|
1736 |
public function correct_upload_filetypes() {
|
1737 |
if ( ! check_ajax_referer( '_rtm_file_type_error_', '_rtm_nonce' ) ) {
|
1738 |
wp_send_json( false );
|
1739 |
}
|
|
|
1740 |
global $rtmedia;
|
1741 |
-
$upload_filetypes_orig =
|
|
|
1742 |
$upload_filetypes = explode( ' ', $upload_filetypes );
|
|
|
1743 |
if ( isset( $rtmedia->options['images_enabled'] ) && $rtmedia->options['images_enabled'] ) {
|
1744 |
$not_supported_image = array_diff( array( 'jpg', 'jpeg', 'png', 'gif' ), $upload_filetypes );
|
1745 |
if ( ! empty( $not_supported_image ) ) {
|
@@ -1769,7 +1902,10 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
1769 |
wp_die();
|
1770 |
}
|
1771 |
|
1772 |
-
|
|
|
|
|
|
|
1773 |
$site_option = rtmedia_get_site_option( 'rtmedia-update-template-notice-v3_9_4' );
|
1774 |
|
1775 |
if ( ! $site_option || 'hide' !== $site_option ) {
|
@@ -1792,7 +1928,10 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
1792 |
}
|
1793 |
}
|
1794 |
|
1795 |
-
|
|
|
|
|
|
|
1796 |
|
1797 |
if ( check_ajax_referer( 'rtmedia_template_notice', '_rtm_nonce' ) && rtmedia_update_site_option( 'rtmedia-update-template-notice-v3_9_4', 'hide' ) ) {
|
1798 |
echo '1';
|
@@ -1802,21 +1941,28 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
1802 |
die();
|
1803 |
}
|
1804 |
|
1805 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1806 |
|
1807 |
-
// wrapper class
|
1808 |
$wrapper_class = '';
|
1809 |
if ( ! empty( $args['wrapper_class'] ) && is_array( $args['wrapper_class'] ) ) {
|
1810 |
$wrapper_class = implode( ' ', $args['wrapper_class'] );
|
1811 |
}
|
1812 |
|
1813 |
-
// tabs
|
1814 |
-
if ( 'rtmedia-settings' === $
|
1815 |
$sub_tabs = apply_filters( 'rtmedia_pro_settings_tabs_content', $sub_tabs );
|
1816 |
ksort( $sub_tabs );
|
1817 |
}
|
1818 |
$tab_position_class = 'rtm-vertical-tabs';
|
1819 |
-
if ( 'rtmedia-addons' === $
|
1820 |
$tab_position_class = 'rtm-horizotanl-tabs';
|
1821 |
}
|
1822 |
?>
|
@@ -1828,8 +1974,10 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
1828 |
$i = 1;
|
1829 |
foreach ( $sub_tabs as $tab ) {
|
1830 |
|
1831 |
-
// tab status
|
1832 |
-
$active_class =
|
|
|
|
|
1833 |
if ( ! empty( $tab['args'] ) && ( empty( $tab['args']['status'] ) || 'valid' !== $tab['args']['status'] ) ) {
|
1834 |
$error_class = 'error';
|
1835 |
}
|
@@ -1837,21 +1985,21 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
1837 |
$active_class = 'active';
|
1838 |
}
|
1839 |
|
1840 |
-
// tab icon
|
1841 |
-
$icon = '';
|
1842 |
-
if ( isset( $tab['icon'] ) && ! empty( $tab['icon'] ) ) {
|
1843 |
-
$icon = '<i class="' . esc_attr( $tab['icon'] ) . ' dashicons"></i>';
|
1844 |
-
}
|
1845 |
?>
|
1846 |
-
<li class="<?php echo esc_attr( $active_class ) ?> <?php echo esc_attr( $error_class ) ?>">
|
1847 |
-
<a id="tab-<?php echo esc_attr( substr( $tab['href'], 1 ) ) ?>" title="<?php echo esc_attr( $tab['title'] ); ?>"
|
1848 |
-
|
1849 |
-
|
1850 |
-
|
|
|
|
|
|
|
|
|
|
|
1851 |
</a>
|
1852 |
</li>
|
1853 |
<?php
|
1854 |
-
$i
|
1855 |
}
|
1856 |
?>
|
1857 |
</ul>
|
@@ -1864,7 +2012,7 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
1864 |
if ( 1 === $k ) {
|
1865 |
$active_class = ' active';
|
1866 |
}
|
1867 |
-
$k
|
1868 |
if ( isset( $tab['icon'] ) && ! empty( $tab['icon'] ) ) {
|
1869 |
$icon = '<i class="' . esc_attr( $tab['icon'] ) . '"></i>';
|
1870 |
}
|
@@ -1872,9 +2020,9 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
1872 |
$tab_without_hash = $tab_without_hash[1];
|
1873 |
echo '<div class="rtm-content' . esc_attr( $active_class ) . '" id="' . esc_attr( $tab_without_hash ) . '">';
|
1874 |
if ( isset( $tab['args'] ) ) {
|
1875 |
-
call_user_func( $tab['callback'], $
|
1876 |
} else {
|
1877 |
-
call_user_func( $tab['callback'], $
|
1878 |
}
|
1879 |
echo '</div>';
|
1880 |
}
|
@@ -1889,13 +2037,13 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
1889 |
* To remove setting saved parameter from url once satting saved
|
1890 |
* Add parameter to this array WP will remove variable from Query string
|
1891 |
*
|
1892 |
-
* @param $removable_query_args
|
1893 |
*
|
1894 |
* @return array $removable_query_args
|
1895 |
*/
|
1896 |
-
function removable_query_args( $removable_query_args ) {
|
1897 |
-
$
|
1898 |
-
if ( isset( $
|
1899 |
$removable_query_args[] = 'settings-saved';
|
1900 |
}
|
1901 |
|
@@ -1903,22 +2051,29 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
1903 |
}
|
1904 |
|
1905 |
/**
|
1906 |
-
* Display
|
1907 |
*
|
1908 |
* @since 4.1.7
|
1909 |
*
|
1910 |
* @return void
|
1911 |
*/
|
1912 |
-
function rtm_addon_license_notice() {
|
1913 |
|
1914 |
-
|
1915 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1916 |
$license_doc = 'https://rtmedia.io/docs/license/';
|
1917 |
-
|
1918 |
-
|
1919 |
-
|
1920 |
-
);
|
1921 |
-
|
1922 |
return;
|
1923 |
}
|
1924 |
|
@@ -1928,14 +2083,14 @@ if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
|
1928 |
return;
|
1929 |
}
|
1930 |
|
1931 |
-
$message = '';
|
1932 |
foreach ( $addons as $addon ) {
|
1933 |
if ( empty( $addon['args']['status'] ) || 'valid' !== $addon['args']['status'] ) {
|
1934 |
$message = sprintf(
|
1935 |
-
|
|
|
1936 |
admin_url( 'admin.php?page=rtmedia-license' )
|
1937 |
);
|
1938 |
-
echo '<div class="error"><p>' . $message . '</p></div>';
|
1939 |
break;
|
1940 |
}
|
1941 |
}
|
1 |
<?php
|
|
|
2 |
/**
|
3 |
+
* File contents Admin class.
|
4 |
*
|
5 |
+
* @package rtMedia
|
6 |
* @subpackage Admin
|
|
|
7 |
*/
|
8 |
+
|
9 |
if ( ! class_exists( 'RTMediaAdmin' ) ) {
|
10 |
|
11 |
/**
|
12 |
+
* Class for RTMedia admin functionality.
|
13 |
*/
|
14 |
class RTMediaAdmin {
|
15 |
|
16 |
+
/**
|
17 |
+
* Check if rtmedia upgrade available
|
18 |
+
*
|
19 |
+
* @var mixed rtmedia_upgrade
|
20 |
+
*/
|
21 |
public $rtmedia_upgrade;
|
22 |
+
|
23 |
+
/**
|
24 |
+
* RTMedia settings.
|
25 |
+
*
|
26 |
+
* @var RTMediaSettings
|
27 |
+
*/
|
28 |
public $rtmedia_settings;
|
29 |
+
|
30 |
+
/**
|
31 |
+
* Encoding.
|
32 |
+
*
|
33 |
+
* @var mixed rtmedia_encoding
|
34 |
+
*/
|
35 |
public $rtmedia_encoding;
|
36 |
+
|
37 |
+
/**
|
38 |
+
* Support class object.
|
39 |
+
*
|
40 |
+
* @var RTMediaSupport
|
41 |
+
*/
|
42 |
public $rtmedia_support;
|
43 |
+
|
44 |
+
/**
|
45 |
+
* Feed for rtMedia.
|
46 |
+
*
|
47 |
+
* @var mixed
|
48 |
+
*/
|
49 |
public $rtmedia_feed;
|
50 |
|
51 |
/**
|
56 |
public function __construct() {
|
57 |
global $rtmedia;
|
58 |
|
59 |
+
// Actions and filters.
|
60 |
add_action( 'init', array( $this, 'video_transcoding_survey_response' ) );
|
61 |
add_filter( 'plugin_action_links_' . RTMEDIA_BASE_NAME, array( &$this, 'plugin_add_settings_link' ) );
|
62 |
|
67 |
|
68 |
add_action( 'wp_ajax_rtmedia_submit_request', array( $this->rtmedia_support, 'submit_request' ), 1 );
|
69 |
|
70 |
+
add_action( 'wp_ajax_rtmedia_linkback', array( $this, 'linkback' ), 1 ); // todo: is it being used ?
|
71 |
add_action( 'wp_ajax_rtmedia_rt_album_deactivate', 'BPMediaAlbumimporter::bp_album_deactivate', 1 );
|
72 |
add_action( 'wp_ajax_rtmedia_rt_album_import', 'BPMediaAlbumimporter::bpmedia_ajax_import_callback', 1 );
|
73 |
add_action( 'wp_ajax_rtmedia_rt_album_import_favorites', 'BPMediaAlbumimporter::bpmedia_ajax_import_favorites', 1 );
|
74 |
add_action( 'wp_ajax_rtmedia_rt_album_import_step_favorites', 'BPMediaAlbumimporter::bpmedia_ajax_import_step_favorites', 1 );
|
75 |
add_action( 'wp_ajax_rtmedia_rt_album_cleanup', 'BPMediaAlbumimporter::cleanup_after_install' );
|
76 |
+
add_action( 'wp_ajax_rtmedia_convert_videos_form', array( $this, 'convert_videos_mailchimp_send' ), 1 ); // todo: is it being used ?
|
77 |
add_action( 'wp_ajax_rtmedia_correct_upload_filetypes', array( $this, 'correct_upload_filetypes' ), 1 );
|
78 |
add_filter( 'plugin_row_meta', array( $this, 'plugin_meta_premium_addon_link' ), 1, 2 );
|
79 |
add_action( 'wp_dashboard_setup', array( $this, 'add_dashboard_widgets' ), 0 );
|
80 |
add_action( 'wp_ajax_rtmedia_export_settings', array( $this, 'export_settings' ), 10 );
|
81 |
+
add_action(
|
82 |
+
'wp_ajax_rtmedia_hide_addon_update_notice',
|
83 |
+
array(
|
84 |
+
$this,
|
85 |
+
'rtmedia_hide_addon_update_notice',
|
86 |
+
),
|
87 |
+
1
|
88 |
+
);
|
89 |
add_filter( 'media_row_actions', array( $this, 'modify_medialibrary_permalink' ), 10, 2 );
|
90 |
|
91 |
if ( ! isset( $rtmedia->options ) ) {
|
128 |
add_action( 'admin_init', array( $this, 'check_permalink_admin_notice' ) );
|
129 |
}
|
130 |
|
131 |
+
add_action(
|
132 |
+
'wp_ajax_rtmedia_hide_template_override_notice',
|
133 |
+
array(
|
134 |
+
$this,
|
135 |
+
'rtmedia_hide_template_override_notice',
|
136 |
+
),
|
137 |
+
1
|
138 |
+
);
|
139 |
add_action( 'admin_init', array( $this, 'rtmedia_bp_add_update_type' ) );
|
140 |
+
add_action(
|
141 |
+
'wp_ajax_rtmedia_hide_inspirebook_release_notice',
|
142 |
+
array(
|
143 |
+
$this,
|
144 |
+
'rtmedia_hide_inspirebook_release_notice',
|
145 |
+
),
|
146 |
+
1
|
147 |
+
);
|
148 |
+
add_action(
|
149 |
+
'wp_ajax_rtmedia_hide_social_sync_notice',
|
150 |
+
array(
|
151 |
+
$this,
|
152 |
+
'rtmedia_hide_social_sync_notice',
|
153 |
+
),
|
154 |
+
1
|
155 |
+
);
|
156 |
add_action( 'wp_ajax_rtmedia_hide_premium_addon_notice', array( $this, 'rtmedia_hide_premium_addon_notice' ), 1 );
|
157 |
|
158 |
+
new RTMediaMediaSizeImporter(); // do not delete this line. We only need to create object of this class if we are in admin section.
|
159 |
if ( class_exists( 'BuddyPress' ) ) {
|
160 |
new RTMediaActivityUpgrade();
|
161 |
}
|
175 |
/**
|
176 |
* Display admin notice.
|
177 |
*/
|
178 |
+
public function install_transcoder_admin_notice() {
|
179 |
$show_notice = get_site_option( 'install_transcoder_admin_notice', 1 );
|
180 |
if ( '1' === $show_notice || 1 === $show_notice ) :
|
181 |
+
?>
|
182 |
<div class="notice notice-info install-transcoder-notice is-dismissible">
|
183 |
<?php wp_nonce_field( '_install_transcoder_hide_notice_', 'install_transcoder_hide_notice_nonce' ); ?>
|
184 |
<p>
|
185 |
<?php
|
186 |
$allowed_tags = array(
|
187 |
+
'a' => array(
|
188 |
+
'href' => array(),
|
189 |
+
'target' => array(),
|
190 |
+
),
|
191 |
);
|
192 |
echo wp_kses( __( 'Install <a href="https://wordpress.org/plugins/transcoder/" target="_blank">Transcoder plugin</a> to convert audio/video files and thumbnails generation.', 'buddypress-media' ), $allowed_tags );
|
193 |
?>
|
206 |
});
|
207 |
});
|
208 |
</script>
|
209 |
+
<?php
|
210 |
endif;
|
211 |
}
|
212 |
+
|
213 |
/**
|
214 |
* Set option to hide admin notice when user click on dismiss button.
|
215 |
*/
|
216 |
+
public function install_transcoder_hide_admin_notice() {
|
217 |
if ( check_ajax_referer( '_install_transcoder_hide_notice_', 'install_transcoder_notice_nonce' ) ) {
|
218 |
update_site_option( 'install_transcoder_admin_notice', '0' );
|
219 |
}
|
220 |
die();
|
221 |
}
|
222 |
|
223 |
+
/**
|
224 |
+
* Include admin templates.
|
225 |
+
*/
|
226 |
+
public function rtm_admin_templates() {
|
227 |
foreach ( glob( RTMEDIA_PATH . 'app/admin/templates/*.php' ) as $filename ) {
|
228 |
$slug = rtrim( basename( $filename ), '.php' );
|
229 |
|
232 |
echo '</script>';
|
233 |
}
|
234 |
|
235 |
+
$page_name = sanitize_text_field( filter_input( INPUT_GET, 'page', FILTER_SANITIZE_STRING ) );
|
236 |
|
237 |
+
if ( ! empty( $page_name ) && 'rtmedia-settings' === $page_name ) {
|
238 |
/**
|
239 |
* Filter is use to enable comment option in side the media that are being uploaded in the comment section.
|
240 |
*
|
243 |
* @param True to hide the option and false to show the option.
|
244 |
*/
|
245 |
$display = apply_filters( 'rtmedia_disable_media_in_commented_media', true );
|
246 |
+
if ( $display ) {
|
247 |
+
?>
|
248 |
<style type="text/css">
|
249 |
.rtm-option-wrapper .form-table[data-depends="buddypress_enableOnComment"] {
|
250 |
+
display: none !important;
|
251 |
}
|
252 |
</style>
|
253 |
<?php
|
255 |
}
|
256 |
}
|
257 |
|
258 |
+
/**
|
259 |
+
* Function to modify media library permalink.
|
260 |
+
*
|
261 |
+
* @param array $action Action details array.
|
262 |
+
* @param object $post Post Object.
|
263 |
+
*
|
264 |
+
* @return mixed
|
265 |
+
*/
|
266 |
+
public function modify_medialibrary_permalink( $action, $post ) {
|
267 |
$rtm_id = rtmedia_id( $post->ID );
|
268 |
|
269 |
if ( $rtm_id ) {
|
270 |
+
$link = get_rtmedia_permalink( $rtm_id );
|
271 |
+
$title = _draft_or_post_title( $post->post_parent );
|
272 |
+
|
273 |
+
// translators: 1. Title.
|
274 |
+
$action['view'] = '<a href="' . esc_url( $link ) . '" title="' . esc_attr( sprintf( 'View "%s"', $title ) ) . '" rel="permalink">' . esc_html__( 'View', 'buddypress-media' ) . '</a>';
|
275 |
}
|
276 |
|
277 |
return $action;
|
278 |
}
|
279 |
|
280 |
+
/**
|
281 |
+
* Get rtmedia migration object.
|
282 |
+
*/
|
283 |
+
public function rtmedia_migration() {
|
284 |
new RTMediaMigration();
|
285 |
}
|
286 |
|
287 |
+
/**
|
288 |
+
* Add-on License save hook.
|
289 |
+
*/
|
290 |
+
public function rtmedia_addon_license_save_hook() {
|
291 |
do_action( 'rtmedia_addon_license_save_hook' );
|
292 |
}
|
293 |
|
296 |
*
|
297 |
* @access public
|
298 |
*
|
|
|
|
|
299 |
* @return void
|
300 |
*/
|
301 |
public function rtmedia_network_admin_notices() {
|
305 |
}
|
306 |
|
307 |
/**
|
308 |
+
* Show rtMedia admin notices.
|
309 |
*
|
310 |
* @access public
|
311 |
*
|
|
|
|
|
312 |
* @return void
|
313 |
*/
|
314 |
public function rtmedia_admin_notices() {
|
324 |
}
|
325 |
}
|
326 |
|
327 |
+
/**
|
328 |
+
* For rtMedia Pro split release admin notice
|
329 |
*/
|
330 |
public function rtmedia_premium_addon_notice() {
|
331 |
$site_option = rtmedia_get_site_option( 'rtmedia_premium_addon_notice' );
|
337 |
<p>
|
338 |
<span>
|
339 |
<?php
|
340 |
+
$product_page = 'https://rtmedia.io/products/?utm_source=dashboard&utm_medium=plugin&utm_campaign=buddypress-media';
|
341 |
+
|
342 |
+
// translators: 1. Product page link.
|
343 |
+
$message = sprintf( __( 'Check 30+ premium rtMedia add-ons on our <a href="%s">store</a>.', 'buddypress-media' ), $product_page );
|
344 |
?>
|
345 |
<b><?php esc_html_e( 'rtMedia: ', 'buddypress-media' ); ?></b>
|
346 |
+
<?php
|
347 |
+
echo wp_kses(
|
348 |
+
$message,
|
349 |
+
array(
|
350 |
+
'a' => array(
|
351 |
+
'href' => array(),
|
352 |
+
),
|
353 |
+
)
|
354 |
+
);
|
355 |
+
?>
|
356 |
</span>
|
357 |
+
<a href="#" onclick="rtmedia_hide_premium_addon_notice('<?php echo esc_js( wp_create_nonce( 'rtcamp_pro_split' ) ); ?>');" style="float:right"><?php esc_html_e( 'Dismiss', 'buddypress-media' ); ?>></a>
|
|
|
|
|
358 |
</p>
|
359 |
</div>
|
360 |
<script type="text/javascript">
|
372 |
}
|
373 |
}
|
374 |
|
375 |
+
/**
|
376 |
* Hide pro split release notice
|
377 |
*/
|
378 |
+
public function rtmedia_hide_premium_addon_notice() {
|
|
|
379 |
if ( check_ajax_referer( 'rtcamp_pro_split', '_rtm_nonce' ) && rtmedia_update_site_option( 'rtmedia_premium_addon_notice', 'hide' ) ) {
|
380 |
echo '1';
|
381 |
} else {
|
385 |
}
|
386 |
|
387 |
/**
|
388 |
+
* Show rtMedia inspirebook release notice.
|
389 |
*
|
390 |
* @access public
|
391 |
*
|
|
|
|
|
392 |
* @return void
|
393 |
*/
|
394 |
public function rtmedia_inspirebook_release_notice() {
|
399 |
<div class="updated rtmedia-inspire-book-notice">
|
400 |
<p>
|
401 |
<span>
|
402 |
+
<a href="https://rtmedia.io/products/inspirebook/" target="_blank">
|
403 |
+
<b><?php esc_html_e( 'Meet InspireBook', 'buddypress-media' ); ?></b>
|
|
|
404 |
</a>
|
405 |
<?php esc_html_e( ' - First official rtMedia premium theme.', 'buddypress-media' ); ?>
|
406 |
</span>
|
407 |
<a href="#" onclick="rtmedia_hide_inspirebook_notice()" style="float:right">Dismiss</a>
|
408 |
+
<?php wp_nonce_field( '_rtmedia_hide_inspirebook_notice_', 'rtmedia_hide_inspirebook_nonce' ); ?>
|
409 |
</p>
|
410 |
</div>
|
411 |
<script type="text/javascript">
|
430 |
*
|
431 |
* @access public
|
432 |
*
|
|
|
|
|
433 |
* @return void
|
434 |
*/
|
435 |
public function rtmedia_hide_inspirebook_release_notice() {
|
447 |
*
|
448 |
* @access public
|
449 |
*
|
|
|
|
|
450 |
* @return void
|
451 |
*/
|
452 |
public function rtmedia_bp_add_update_type() {
|
460 |
*
|
461 |
* @access public
|
462 |
*
|
|
|
|
|
463 |
* @return void
|
464 |
*/
|
465 |
public function check_permalink_admin_notice() {
|
474 |
*
|
475 |
* @access public
|
476 |
*
|
|
|
|
|
477 |
* @return void
|
478 |
*/
|
479 |
public function rtmedia_permalink_notice() {
|
487 |
*
|
488 |
* @access public
|
489 |
*
|
|
|
|
|
490 |
* @return void
|
491 |
*/
|
492 |
public function rtmedia_addon_update_notice() {
|
501 |
?>
|
502 |
<div class="error rtmedia-addon-upate-notice">
|
503 |
<p>
|
504 |
+
<strong><?php esc_html_e( 'rtMedia:', 'buddypress-media' ); ?></strong>
|
505 |
+
<?php esc_html_e( 'Please update all premium add-ons that you have purchased from', 'buddypress-media' ); ?>
|
506 |
+
<a href="https://rtmedia.io/my-account/" target="_blank"><?php esc_html_e( 'your account', 'buddypress-media' ); ?></a>.
|
507 |
+
<a href="#" onclick="rtmedia_hide_addon_update_notice()" style="float:right"><?php esc_html_e( 'Dismiss', 'buddypress-media' ); ?></a>
|
|
|
|
|
508 |
<?php wp_nonce_field( 'rtmedia-addon-update-notice-3_8', 'rtmedia-addon-notice' ); ?>
|
509 |
</p>
|
510 |
</div>
|
526 |
}
|
527 |
|
528 |
/**
|
529 |
+
* Show rtMedia addon update notice.
|
530 |
*
|
531 |
* @access public
|
532 |
*
|
533 |
+
* @return bool $return_flag
|
|
|
|
|
534 |
*/
|
535 |
public function check_for_addon_update_notice() {
|
536 |
+
$return_flag = false;
|
537 |
|
538 |
+
// check for rtMedia Instagram version.
|
539 |
if ( defined( 'RTMEDIA_INSTAGRAM_PATH' ) ) {
|
540 |
$plugin_info = get_plugin_data( RTMEDIA_INSTAGRAM_PATH . 'index.php' );
|
541 |
if ( isset( $plugin_info['Version'] ) && ( - 1 === version_compare( $plugin_info['Version'], '2.1.14' ) ) ) {
|
542 |
+
$return_flag = true;
|
543 |
}
|
544 |
} elseif ( defined( 'RTMEDIA_PHOTO_TAGGING_PATH' ) ) {
|
545 |
+
// check for rtMedia Photo Tagging version.
|
546 |
$plugin_info = get_plugin_data( RTMEDIA_PHOTO_TAGGING_PATH . 'index.php' );
|
547 |
if ( isset( $plugin_info['Version'] ) && ( - 1 === version_compare( $plugin_info['Version'], '2.2.14' ) ) ) {
|
548 |
+
$return_flag = true;
|
549 |
}
|
550 |
} elseif ( defined( 'RTMEDIA_FFMPEG_PATH' ) ) {
|
551 |
+
// check for rtMedia FFPMEG version.
|
552 |
$plugin_info = get_plugin_data( RTMEDIA_FFMPEG_PATH . 'index.php' );
|
553 |
if ( isset( $plugin_info['Version'] ) && ( - 1 === version_compare( $plugin_info['Version'], '2.1.14' ) ) ) {
|
554 |
+
$return_flag = true;
|
555 |
}
|
556 |
} elseif ( defined( 'RTMEDIA_KALTURA_PATH' ) ) {
|
557 |
+
// check for rtMedia Kaltura version.
|
558 |
$plugin_info = get_plugin_data( RTMEDIA_KALTURA_PATH . 'index.php' );
|
559 |
if ( isset( $plugin_info['Version'] ) && ( - 1 === version_compare( $plugin_info['Version'], '3.0.16' ) ) ) {
|
560 |
+
$return_flag = true;
|
561 |
}
|
562 |
} elseif ( defined( 'RTMEDIA_PRO_PATH' ) ) {
|
563 |
+
// check for rtMedia Pro version.
|
564 |
$plugin_info = get_plugin_data( RTMEDIA_PRO_PATH . 'index.php' );
|
565 |
if ( isset( $plugin_info['Version'] ) && ( - 1 === version_compare( $plugin_info['Version'], '2.6' ) ) ) {
|
566 |
+
$return_flag = true;
|
567 |
}
|
568 |
} elseif ( defined( 'RTMEDIA_SOCIAL_SYNC_PATH' ) ) {
|
569 |
+
// check for rtMedia Social Sync version.
|
570 |
$plugin_info = get_plugin_data( RTMEDIA_SOCIAL_SYNC_PATH . 'index.php' );
|
571 |
if ( isset( $plugin_info['Version'] ) && ( - 1 === version_compare( $plugin_info['Version'], '1.3.1' ) ) ) {
|
572 |
+
$return_flag = true;
|
573 |
}
|
574 |
} elseif ( defined( 'RTMEDIA_MEMBERSHIP_PATH' ) ) {
|
575 |
+
// check for rtMedia Membership version.
|
576 |
$plugin_info = get_plugin_data( RTMEDIA_MEMBERSHIP_PATH . 'index.php' );
|
577 |
if ( isset( $plugin_info['Version'] ) && ( - 1 === version_compare( $plugin_info['Version'], '2.1.5' ) ) ) {
|
578 |
+
$return_flag = true;
|
579 |
}
|
580 |
} elseif ( defined( 'RTMEDIA_WATERMARK_PATH' ) ) {
|
581 |
+
// check for rtMedia Photo Watermak version.
|
582 |
$plugin_info = get_plugin_data( RTMEDIA_WATERMARK_PATH . 'index.php' );
|
583 |
if ( isset( $plugin_info['Version'] ) && ( - 1 === version_compare( $plugin_info['Version'], '1.1.8' ) ) ) {
|
584 |
+
$return_flag = true;
|
585 |
}
|
586 |
}
|
587 |
|
588 |
+
return $return_flag;
|
589 |
}
|
590 |
|
591 |
/**
|
593 |
*
|
594 |
* @access public
|
595 |
*
|
|
|
|
|
596 |
* @return void
|
597 |
*/
|
598 |
public function bp_admin_tabs() {
|
602 |
}
|
603 |
|
604 |
/**
|
605 |
+
* Show rtMedia advertisement.
|
606 |
*
|
607 |
* @access public
|
608 |
*
|
|
|
|
|
609 |
* @return void
|
610 |
*/
|
611 |
public function rtmedia_advertisement() {
|
624 |
*
|
625 |
* @access public
|
626 |
*
|
|
|
|
|
627 |
* @return void
|
628 |
*/
|
629 |
public function rtmedia_dashboard_widget_function() {
|
641 |
global $wpdb;
|
642 |
$results = wp_cache_get( 'rt-stats', 'rt-dashboard' );
|
643 |
if ( false === $results ) {
|
644 |
+
$results = $wpdb->get_results( $wpdb->prepare( "select media_type, count(id) as count from {$rtmedia_model->table_name} where blog_id=%d group by media_type", get_current_blog_id() ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
645 |
wp_cache_set( 'stats', $results, 'rt-dashboard', HOUR_IN_SECONDS );
|
646 |
}
|
647 |
if ( $results ) {
|
665 |
<h4 class="sub"><?php esc_html_e( 'Usage Stats', 'buddypress-media' ); ?></h4>
|
666 |
|
667 |
<table>
|
668 |
+
<tbody>
|
669 |
+
<?php
|
670 |
$total_count = wp_cache_get( 'total_count', 'rt-dashboard' );
|
671 |
if ( false === $total_count ) {
|
672 |
$total_count = $wpdb->get_var( "select count(*) from {$wpdb->users}" );
|
675 |
?>
|
676 |
<tr>
|
677 |
<td class="b"> <?php echo esc_html( $total_count ); ?> </td>
|
678 |
+
<td class="t"><?php esc_html_e( 'Total ', 'buddypress-media' ); ?></td>
|
679 |
</tr>
|
680 |
<?php
|
681 |
$with_media_count = wp_cache_get( 'with_media', 'rt-dashboard' );
|
682 |
if ( false === $with_media_count ) {
|
683 |
+
$with_media_count = $wpdb->get_var( "select count(distinct media_author) from {$rtmedia_model->table_name}" ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
684 |
wp_cache_set( 'with_media', $with_media_count, 'rt-dashboard', HOUR_IN_SECONDS );
|
685 |
}
|
686 |
?>
|
687 |
<tr>
|
688 |
<td class="b"> <?php echo esc_html( $with_media_count ); ?> </td>
|
689 |
+
<td class="t"><?php esc_html_e( 'With Media', 'buddypress-media' ); ?></td>
|
690 |
</tr>
|
691 |
<?php
|
692 |
$comments = wp_cache_get( 'comments', 'rt-dashboard' );
|
693 |
if ( false === $comments ) {
|
694 |
+
$comments = $wpdb->get_var( "select count(*) from {$wpdb->comments} where comment_post_ID in ( select media_id from {$rtmedia_model->table_name} )" ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
695 |
wp_cache_set( 'comments', $comments, 'rt-dashboard', HOUR_IN_SECONDS );
|
696 |
}
|
697 |
?>
|
698 |
<tr>
|
699 |
<td class="b"> <?php echo esc_html( $comments ); ?> </td>
|
700 |
+
<td class="t"><?php esc_html_e( 'Comments ', 'buddypress-media' ); ?></td>
|
701 |
</tr>
|
702 |
<?php
|
703 |
$likes = wp_cache_get( 'likes', 'rt-dashboard' );
|
704 |
if ( false === $likes ) {
|
705 |
+
$likes = $wpdb->get_var( "select sum(likes) from {$rtmedia_model->table_name}" ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
706 |
wp_cache_set( 'likes', $likes, 'rt-dashboard', HOUR_IN_SECONDS );
|
707 |
}
|
708 |
?>
|
709 |
<tr>
|
710 |
<td class="b"> <?php echo esc_html( $likes ); ?> </td>
|
711 |
+
<td class="t"><?php esc_html_e( 'Likes', 'buddypress-media' ); ?></td>
|
712 |
</tr>
|
713 |
</tbody>
|
714 |
</table>
|
736 |
*
|
737 |
* @access public
|
738 |
*
|
|
|
|
|
739 |
* @return void
|
740 |
*/
|
741 |
public function add_dashboard_widgets() {
|
742 |
+
wp_add_dashboard_widget(
|
743 |
+
'rtmedia_dashboard_widget',
|
744 |
+
esc_html__( 'Right Now in rtMedia', 'buddypress-media' ),
|
745 |
+
array(
|
746 |
+
&$this,
|
747 |
+
'rtmedia_dashboard_widget_function',
|
748 |
+
)
|
749 |
+
);
|
750 |
global $wp_meta_boxes;
|
751 |
|
752 |
// Get the regular dashboard widgets array
|
753 |
+
// (which has our new widget already but at the end).
|
|
|
754 |
$normal_dashboard = $wp_meta_boxes['dashboard']['normal']['core'];
|
755 |
|
756 |
+
// Backup and delete our new dashboard widget from the end of the array.
|
|
|
757 |
$example_widget_backup = array( 'rtmedia_dashboard_widget' => $normal_dashboard['rtmedia_dashboard_widget'] );
|
758 |
unset( $normal_dashboard['rtmedia_dashboard_widget'] );
|
759 |
|
760 |
+
// Merge the two arrays together so our widget is at the beginning.
|
|
|
761 |
$sorted_dashboard = array_merge( $example_widget_backup, $normal_dashboard );
|
762 |
|
763 |
+
// Save the sorted array back into the original metaboxes.
|
764 |
+
$wp_meta_boxes['dashboard']['normal']['core'] = $sorted_dashboard; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.OverrideProhibited
|
|
|
765 |
}
|
766 |
|
767 |
/**
|
769 |
*
|
770 |
* @access public
|
771 |
*
|
772 |
+
* @param array $links Existing links array.
|
773 |
*
|
774 |
* @return array $links
|
775 |
*/
|
787 |
*
|
788 |
* @access public
|
789 |
*
|
790 |
+
* @param object $admin_bar Admin bar object.
|
791 |
*
|
792 |
* @return void
|
793 |
*/
|
796 |
return;
|
797 |
}
|
798 |
|
799 |
+
$admin_bar->add_menu(
|
800 |
+
array(
|
801 |
'id' => 'rtMedia',
|
802 |
'title' => 'rtMedia',
|
803 |
'href' => admin_url( 'admin.php?page=rtmedia-settings' ),
|
806 |
),
|
807 |
)
|
808 |
);
|
809 |
+
$admin_bar->add_menu(
|
810 |
+
array(
|
811 |
'id' => 'rt-media-dashborad',
|
812 |
'parent' => 'rtMedia',
|
813 |
'title' => esc_html__( 'Settings', 'buddypress-media' ),
|
819 |
)
|
820 |
);
|
821 |
if ( ! is_rtmedia_vip_plugin() ) {
|
822 |
+
$admin_bar->add_menu(
|
823 |
+
array(
|
824 |
'id' => 'rt-media-addons',
|
825 |
'parent' => 'rtMedia',
|
826 |
'title' => esc_html__( 'Addons', 'buddypress-media' ),
|
832 |
)
|
833 |
);
|
834 |
}
|
835 |
+
$admin_bar->add_menu(
|
836 |
+
array(
|
837 |
'id' => 'rt-media-support',
|
838 |
'parent' => 'rtMedia',
|
839 |
'title' => esc_html__( 'Support', 'buddypress-media' ),
|
845 |
)
|
846 |
);
|
847 |
if ( ! is_rtmedia_vip_plugin() ) {
|
848 |
+
$admin_bar->add_menu(
|
849 |
+
array(
|
850 |
'id' => 'rt-media-themes',
|
851 |
'parent' => 'rtMedia',
|
852 |
'title' => esc_html__( 'Themes', 'buddypress-media' ),
|
859 |
);
|
860 |
}
|
861 |
if ( ! is_rtmedia_vip_plugin() ) {
|
862 |
+
$admin_bar->add_menu(
|
863 |
+
array(
|
864 |
'id' => 'rt-media-hire-us',
|
865 |
'parent' => 'rtMedia',
|
866 |
'title' => esc_html__( 'Hire Us', 'buddypress-media' ),
|
873 |
);
|
874 |
}
|
875 |
if ( has_filter( 'rtmedia_license_tabs' ) || has_action( 'rtmedia_addon_license_details' ) ) {
|
876 |
+
$admin_bar->add_menu(
|
877 |
+
array(
|
878 |
'id' => 'rt-media-license',
|
879 |
'parent' => 'rtMedia',
|
880 |
'title' => esc_html__( 'Licenses', 'buddypress-media' ),
|
893 |
*
|
894 |
* @access public
|
895 |
*
|
896 |
+
* @param string $hook Hook name.
|
897 |
*
|
898 |
* @return void
|
899 |
*/
|
924 |
|
925 |
/* Only one JS file should enqueue */
|
926 |
if ( '' === $suffix ) {
|
927 |
+
wp_enqueue_script( 'rtmedia-admin-tabs', RTMEDIA_URL . 'app/assets/admin/js/vendors/tabs.js', array( 'backbone' ), RTMEDIA_VERSION, true );
|
928 |
+
wp_enqueue_script( 'rtmedia-admin-scripts', RTMEDIA_URL . 'app/assets/admin/js/scripts.js', array( 'backbone' ), RTMEDIA_VERSION, true );
|
929 |
+
wp_enqueue_script( 'rtmedia-admin', RTMEDIA_URL . 'app/assets/admin/js/settings.js', array( 'backbone', 'wp-util' ), RTMEDIA_VERSION, true );
|
930 |
} else {
|
931 |
+
wp_enqueue_script( 'rtmedia-admin', RTMEDIA_URL . 'app/assets/admin/js/admin.min.js', array( 'backbone', 'wp-util' ), RTMEDIA_VERSION, true );
|
932 |
}
|
933 |
|
934 |
+
wp_localize_script(
|
935 |
+
'rtmedia-admin',
|
936 |
+
'RTMedia_Admin_Settings_JS',
|
937 |
+
array(
|
938 |
+
'rtmedia_default_sizes_error_message' => esc_html__( 'Invalid value for [default_size_property].', 'buddypress-media' ),
|
939 |
+
)
|
940 |
+
);
|
941 |
+
|
942 |
+
wp_localize_script( 'rtmedia-admin', 'rtmedia_on_label', __( 'ON', 'buddypress-media' ) );
|
943 |
+
wp_localize_script( 'rtmedia-admin', 'rtmedia_off_label', __( 'OFF', 'buddypress-media' ) );
|
944 |
wp_localize_script( 'rtmedia-admin', 'rtmedia_admin_ajax', $admin_ajax );
|
945 |
wp_localize_script( 'rtmedia-admin', 'rtmedia_admin_url', admin_url() );
|
946 |
/* path for file upload using ajax */
|
947 |
+
wp_localize_script( 'rtmedia-admin', 'rtmedia_fileupload_url', RTMEDIA_URL . 'app/helper/rtUploadAttachment.php' );
|
948 |
|
949 |
$rtmedia_admin_strings = array(
|
950 |
+
'no_refresh' => esc_html__( 'Please do not refresh this page.', 'buddypress-media' ),
|
951 |
+
'something_went_wrong' => esc_html__( 'Something went wrong. Please ', 'buddypress-media' ) . '<a href onclick="location.reload();">' . esc_html__( 'refresh', 'buddypress-media' ) . '</a>' . esc_html__( ' page.', 'buddypress-media' ),
|
952 |
+
'are_you_sure' => esc_html__( 'This will subscribe you to the free plan.', 'buddypress-media' ),
|
953 |
+
'disable_encoding' => esc_html__( 'Are you sure you want to disable the encoding service?', 'buddypress-media' ),
|
954 |
+
'enable_encoding' => esc_html__( 'Are you sure you want to enable the encoding service?', 'buddypress-media' ),
|
955 |
+
'settings_changed' => esc_html__( 'Settings have changed, you should save them!', 'buddypress-media' ),
|
956 |
+
'video_thumbnail_error' => esc_html__( 'Number of video thumbnails to be generated should be greater than 0 in media sizes settings. Setting it to default value 2.', 'buddypress-media' ),
|
957 |
'video_thumbnail_invalid_value' => esc_html__( 'Invalid value for number of video thumbnails in media sizes settings. Setting it to round value', 'buddypress-media' ),
|
958 |
+
'jpeg_quality_negative_error' => esc_html__( 'Number of percentage in JPEG image quality should be greater than 0 in media sizes settings. Setting it to default value 90.', 'buddypress-media' ),
|
959 |
+
'jpeg_quality_percentage_error' => esc_html__( 'Number of percentage in JPEG image quality should be less than 100 in media sizes settings. Setting it to 100.', 'buddypress-media' ),
|
960 |
+
'jpeg_quality_invalid_value' => esc_html__( 'Invalid value for percentage in JPEG image quality in media sizes settings. Setting it to round value', 'buddypress-media' ),
|
961 |
+
'per_page_media_negative_value' => esc_html__( 'Please enter positive integer value only. Setting number of media per page value to default value 10.', 'buddypress-media' ),
|
962 |
+
'per_page_media_positive_error' => esc_html__( 'Please enter positive integer value only. Setting number of media per page value to round value', 'buddypress-media' ),
|
963 |
+
'request_failed' => esc_html__( 'Request failed.', 'buddypress-media' ),
|
964 |
+
'wrong_css_input' => esc_html__( 'You can not use @import statement in custom css', 'buddypress-media' ),
|
965 |
);
|
966 |
|
967 |
wp_localize_script( 'rtmedia-admin', 'rtmedia_admin_strings', $rtmedia_admin_strings );
|
970 |
|
971 |
$rtmedia_admin_support_strings = array(
|
972 |
'wp_admin_username_error' => esc_html__( 'Please enter WP Admin Login.', 'buddypress-media' ),
|
973 |
+
'wp_admin_pwd_error' => esc_html__( 'Please enter WP Admin password.', 'buddypress-media' ),
|
974 |
+
'ssh_ftp_host_error' => esc_html__( 'Please enter SSH / FTP host.', 'buddypress-media' ),
|
975 |
'ssh_ftp_username_error' => esc_html__( 'Please enter SSH / FTP login.', 'buddypress-media' ),
|
976 |
+
'ssh_ftp_pwd_error' => esc_html__( 'Please enter SSH / FTP password.', 'buddypress-media' ),
|
977 |
+
'all_fields_error' => esc_html__( 'Please fill all the fields.', 'buddypress-media' ),
|
978 |
);
|
979 |
|
980 |
wp_localize_script( 'rtmedia-admin', 'rtmedia_admin_support_strings', $rtmedia_admin_support_strings );
|
981 |
|
982 |
+
// Only one CSS file should enqueue.
|
983 |
wp_enqueue_style( 'rtmedia-admin', RTMEDIA_URL . 'app/assets/admin/css/admin' . $suffix . '.css', '', RTMEDIA_VERSION );
|
984 |
} else {
|
985 |
|
986 |
+
// This CSS is using for "Right Now in rtMedia" Widget section on Dashboard.
|
987 |
wp_enqueue_style( 'rtmedia-widget', RTMEDIA_URL . 'app/assets/admin/css/widget' . $suffix . '.css', '', RTMEDIA_VERSION );
|
988 |
}
|
989 |
}
|
994 |
* @access public
|
995 |
* @global string 'buddypress-media'
|
996 |
*
|
|
|
|
|
997 |
* @return void
|
998 |
*/
|
999 |
public function menu() {
|
1000 |
+
add_menu_page(
|
1001 |
+
'rtMedia',
|
1002 |
+
'rtMedia',
|
1003 |
+
'manage_options',
|
1004 |
+
'rtmedia-settings',
|
1005 |
+
array(
|
1006 |
+
$this,
|
1007 |
+
'settings_page',
|
1008 |
+
),
|
1009 |
+
RTMEDIA_URL . 'app/assets/admin/img/rtmedia-logo.png',
|
1010 |
+
'40.1111'
|
1011 |
+
);
|
|
|
|
|
|
|
|
|
|
|
|
|
1012 |
|
1013 |
+
add_submenu_page(
|
1014 |
+
'rtmedia-settings',
|
1015 |
+
esc_html__( 'Settings', 'buddypress-media' ),
|
1016 |
+
esc_html__( 'Settings', 'buddypress-media' ),
|
1017 |
+
'manage_options',
|
1018 |
+
'rtmedia-settings',
|
1019 |
+
array(
|
1020 |
+
$this,
|
1021 |
+
'settings_page',
|
1022 |
+
)
|
1023 |
+
);
|
1024 |
+
|
1025 |
+
add_submenu_page(
|
1026 |
+
'rtmedia-settings',
|
1027 |
+
esc_html__( 'Addons', 'buddypress-media' ),
|
1028 |
+
esc_html__( 'Addons', 'buddypress-media' ),
|
1029 |
+
'manage_options',
|
1030 |
+
'rtmedia-addons',
|
1031 |
+
array(
|
1032 |
$this,
|
1033 |
+
'addons_page',
|
1034 |
+
)
|
1035 |
+
);
|
1036 |
+
|
1037 |
+
add_submenu_page(
|
1038 |
+
'rtmedia-settings',
|
1039 |
+
esc_html__( 'Support', 'buddypress-media' ),
|
1040 |
+
esc_html__( 'Support', 'buddypress-media' ),
|
1041 |
+
'manage_options',
|
1042 |
+
'rtmedia-support',
|
1043 |
+
array(
|
1044 |
+
$this,
|
1045 |
+
'support_page',
|
1046 |
+
)
|
1047 |
+
);
|
1048 |
+
|
1049 |
+
if ( ! is_rtmedia_vip_plugin() ) {
|
1050 |
+
add_submenu_page(
|
1051 |
+
'rtmedia-settings',
|
1052 |
+
esc_html__( 'Themes', 'buddypress-media' ),
|
1053 |
+
esc_html__( 'Themes', 'buddypress-media' ),
|
1054 |
+
'manage_options',
|
1055 |
+
'rtmedia-themes',
|
1056 |
+
array(
|
1057 |
+
$this,
|
1058 |
+
'theme_page',
|
1059 |
+
)
|
1060 |
+
);
|
1061 |
}
|
1062 |
|
1063 |
if ( ! is_rtmedia_vip_plugin() ) {
|
1064 |
+
add_submenu_page(
|
1065 |
+
'rtmedia-settings',
|
1066 |
+
esc_html__( 'Hire Us', 'buddypress-media' ),
|
1067 |
+
esc_html__( 'Hire Us', 'buddypress-media' ),
|
1068 |
+
'manage_options',
|
1069 |
+
'rtmedia-hire-us',
|
1070 |
+
array(
|
1071 |
+
$this,
|
1072 |
+
'hire_us_page',
|
1073 |
+
)
|
1074 |
+
);
|
1075 |
}
|
1076 |
|
1077 |
if ( has_filter( 'rtmedia_license_tabs' ) || has_action( 'rtmedia_addon_license_details' ) ) {
|
1078 |
+
add_submenu_page(
|
1079 |
+
'rtmedia-settings',
|
1080 |
+
esc_html__( 'Licenses', 'buddypress-media' ),
|
1081 |
+
esc_html__( 'Licenses', 'buddypress-media' ),
|
1082 |
+
'manage_options',
|
1083 |
+
'rtmedia-license',
|
1084 |
+
array(
|
1085 |
+
$this,
|
1086 |
+
'license_page',
|
1087 |
+
)
|
1088 |
+
);
|
1089 |
}
|
1090 |
|
1091 |
}
|
1092 |
|
1093 |
/**
|
1094 |
+
* Hide rtMedia addon update notice.
|
1095 |
*
|
1096 |
* @access public
|
1097 |
*
|
|
|
|
|
1098 |
* @return void
|
1099 |
*/
|
1100 |
public function rtmedia_hide_addon_update_notice() {
|
1106 |
die();
|
1107 |
}
|
1108 |
|
|
|
1109 |
/**
|
1110 |
* Render the BuddyPress Media Settings page.
|
1111 |
*
|
1112 |
* @access public
|
1113 |
*
|
|
|
|
|
1114 |
* @return void
|
1115 |
*/
|
1116 |
public function settings_page() {
|
1122 |
*
|
1123 |
* @access public
|
1124 |
*
|
|
|
|
|
1125 |
* @return void
|
1126 |
*/
|
1127 |
public function privacy_page() {
|
1133 |
*
|
1134 |
* @access public
|
1135 |
*
|
|
|
|
|
1136 |
* @return void
|
1137 |
*/
|
1138 |
public function rt_importer_page() {
|
1144 |
*
|
1145 |
* @access public
|
1146 |
*
|
|
|
|
|
1147 |
* @return void
|
1148 |
*/
|
1149 |
public function convert_videos_page() {
|
1155 |
*
|
1156 |
* @access public
|
1157 |
*
|
|
|
|
|
1158 |
* @return void
|
1159 |
*/
|
1160 |
public function addons_page() {
|
1166 |
*
|
1167 |
* @access public
|
1168 |
*
|
|
|
|
|
1169 |
* @return void
|
1170 |
*/
|
1171 |
public function support_page() {
|
1177 |
*
|
1178 |
* @access public
|
1179 |
*
|
|
|
|
|
1180 |
* @return void
|
1181 |
*/
|
1182 |
public function theme_page() {
|
1188 |
*
|
1189 |
* @access public
|
1190 |
*
|
|
|
|
|
1191 |
* @return void
|
1192 |
*/
|
1193 |
public function hire_us_page() {
|
1194 |
$this->render_page( 'rtmedia-hire-us' );
|
1195 |
}
|
1196 |
|
1197 |
+
/**
|
1198 |
+
* Render license page.
|
1199 |
+
*/
|
1200 |
public function license_page() {
|
1201 |
$this->render_page( 'rtmedia-license' );
|
1202 |
}
|
1206 |
*
|
1207 |
* @access static
|
1208 |
*
|
|
|
|
|
1209 |
* @return string | array
|
1210 |
*/
|
1211 |
+
public static function get_current_tab() {
|
1212 |
+
$page_name = sanitize_text_field( filter_input( INPUT_GET, 'page', FILTER_SANITIZE_STRING ) );
|
1213 |
+
return isset( $page_name ) ? $page_name : 'rtmedia-settings';
|
1214 |
}
|
1215 |
|
1216 |
/**
|
1219 |
* @access public
|
1220 |
* @global string 'buddypress-media'
|
1221 |
*
|
1222 |
+
* @param string $page_name page name to render.
|
1223 |
+
* @param array $option_group option group.
|
1224 |
*
|
1225 |
* @return void
|
1226 |
*/
|
1227 |
+
public function render_page( $page_name, $option_group = null ) {
|
1228 |
?>
|
1229 |
|
1230 |
<div class="wrap bp-media-admin <?php echo esc_attr( $this->get_current_tab() ); ?>">
|
1233 |
<h2 class="nav-tab-wrapper"><?php $this->rtmedia_tabs(); ?>
|
1234 |
<span class="alignright by">
|
1235 |
<a class="rt-link"
|
1236 |
+
href="https://rtmedia.io/?utm_source=dashboard&utm_medium=plugin&utm_campaign=buddypress-media"
|
1237 |
+
target="_blank"
|
1238 |
+
title="rtCamp : <?php esc_attr_e( 'Empowering The Web With WordPress', 'buddypress-media' ); ?>">
|
1239 |
<img src="<?php echo esc_url( RTMEDIA_URL ); ?>app/assets/admin/img/rtcamp-logo.png" alt="rtCamp"/>
|
1240 |
</a>
|
1241 |
</span>
|
1247 |
<div id="bp-media-settings-boxes" class="bp-media-settings-boxes-container rtm-setting-container">
|
1248 |
|
1249 |
<?php
|
1250 |
+
if ( 'rtmedia-settings' === $page_name ) {
|
1251 |
?>
|
1252 |
+
<form id="bp_media_settings_form" name="bp_media_settings_form" method="post" enctype="multipart/form-data">
|
|
|
1253 |
<div class="bp-media-metabox-holder">
|
1254 |
<div class="rtm-button-container top">
|
1255 |
+
<?php
|
1256 |
+
$is_setting_save = filter_input( INPUT_GET, 'settings-saved', FILTER_VALIDATE_BOOLEAN );
|
1257 |
+
if ( ! empty( $is_setting_save ) ) {
|
1258 |
+
?>
|
1259 |
<div class="rtm-success rtm-fly-warning rtm-save-settings-msg">
|
1260 |
<?php esc_html_e( 'Settings saved successfully!', 'buddypress-media' ); ?>
|
1261 |
</div>
|
1262 |
<?php } ?>
|
1263 |
<input type="hidden" name="rtmedia-options-save" value="true">
|
1264 |
+
<input type="submit" class="rtmedia-settings-submit button button-primary button-big" value="<?php esc_attr_e( 'Save Settings', 'buddypress-media' ); ?>">
|
|
|
|
|
1265 |
</div>
|
1266 |
<?php
|
1267 |
settings_fields( $option_group );
|
1268 |
+
if ( 'rtmedia-settings' === $page_name ) {
|
1269 |
echo '<div id="rtm-settings-tabs">';
|
1270 |
$sub_tabs = $this->settings_sub_tabs();
|
1271 |
+
RTMediaFormHandler::rtForm_settings_tabs_content( $page_name, $sub_tabs );
|
1272 |
echo '</div>';
|
1273 |
} else {
|
1274 |
+
do_settings_sections( $page_name );
|
1275 |
}
|
1276 |
?>
|
1277 |
|
1278 |
<div class="rtm-button-container bottom">
|
1279 |
<div class="rtm-social-links alignleft">
|
1280 |
+
<a href="http://twitter.com/rtMediaWP" class="twitter" target="_blank">
|
1281 |
+
<span class="dashicons dashicons-twitter"></span>
|
1282 |
+
</a>
|
1283 |
+
<a href="https://www.facebook.com/rtmediawp" class="facebook" target="_blank">
|
1284 |
+
<span class="dashicons dashicons-facebook"></span>
|
1285 |
+
</a>
|
1286 |
+
<a href="http://profiles.wordpress.org/rtcamp" class="wordpress" target="_blank">
|
1287 |
+
<span class="dashicons dashicons-wordpress"></span>
|
1288 |
+
</a>
|
1289 |
+
<a href="https://rtmedia.io/feed/" class="rss" target="_blank">
|
1290 |
+
<span class="dashicons dashicons-rss"></span>
|
1291 |
+
</a>
|
1292 |
</div>
|
1293 |
|
1294 |
<input type="hidden" name="rtmedia-options-save" value="true">
|
1295 |
+
<input type="submit" class="rtmedia-settings-submit button button-primary button-big" value="<?php esc_attr_e( 'Save Settings', 'buddypress-media' ); ?>">
|
|
|
|
|
1296 |
</div>
|
1297 |
</div>
|
1298 |
+
</form>
|
1299 |
+
<?php
|
1300 |
} else {
|
1301 |
?>
|
1302 |
<div class="bp-media-metabox-holder">
|
1303 |
<?php
|
1304 |
+
if ( 'rtmedia-addons' === $page_name ) {
|
1305 |
+
RTMediaAddon::render_addons( $page_name );
|
1306 |
+
} elseif ( 'rtmedia-support' === $page_name ) {
|
1307 |
$rtmedia_support = new RTMediaSupport( false );
|
1308 |
+
$rtmedia_support->render_support( $page_name );
|
1309 |
+
} elseif ( 'rtmedia-themes' === $page_name ) {
|
1310 |
+
RTMediaThemes::render_themes( $page_name );
|
1311 |
} else {
|
1312 |
+
if ( 'rtmedia-license' === $page_name ) {
|
1313 |
+
RTMediaLicense::render_license( $page_name );
|
1314 |
} else {
|
1315 |
+
do_settings_sections( $page_name );
|
1316 |
}
|
1317 |
}
|
1318 |
+
do_action( 'rtmedia_admin_page_insert', $page_name );
|
1319 |
?>
|
1320 |
</div>
|
1321 |
<?php
|
1322 |
+
do_action( 'rtmedia_admin_page_append', $page_name );
|
1323 |
}
|
1324 |
?>
|
1325 |
</div>
|
1330 |
|
1331 |
</div>
|
1332 |
|
1333 |
+
</div><!-- .bp-media-admin -->
|
1334 |
+
<?php
|
1335 |
}
|
1336 |
|
1337 |
/**
|
1339 |
*
|
1340 |
* @access public
|
1341 |
*
|
1342 |
+
* @return void
|
|
|
|
|
|
|
1343 |
*/
|
1344 |
public function tab() {
|
1345 |
|
|
|
1346 |
$idle_class = 'nav-tab';
|
1347 |
$active_class = 'nav-tab nav-tab-active';
|
1348 |
$tabs = array();
|
1349 |
|
1350 |
+
// Check to see which tab we are on.
|
1351 |
$tab = $this->get_current_tab();
|
1352 |
/* rtMedia */
|
1353 |
$tabs[] = array(
|
1367 |
*
|
1368 |
* @access public
|
1369 |
*
|
|
|
|
|
1370 |
* @return void
|
1371 |
*/
|
1372 |
public function rtmedia_tabs() {
|
1373 |
+
// Declare local variables.
|
1374 |
$idle_class = 'nav-tab';
|
1375 |
$active_class = 'nav-tab nav-tab-active';
|
1376 |
|
1377 |
+
// Setup core admin tabs.
|
1378 |
$tabs = array(
|
1379 |
array(
|
1380 |
'href' => get_admin_url( null, esc_url( add_query_arg( array( 'page' => 'rtmedia-settings' ), 'admin.php' ) ) ),
|
1418 |
|
1419 |
$tabs = apply_filters( 'media_add_tabs', $tabs );
|
1420 |
|
1421 |
+
// Loop through tabs and build navigation.
|
1422 |
foreach ( array_values( $tabs ) as $tab_data ) {
|
1423 |
$is_current = (bool) ( $tab_data['slug'] === $this->get_current_tab() );
|
1424 |
$tab_class = $is_current ? $active_class : $idle_class;
|
1436 |
*
|
1437 |
* @access public
|
1438 |
*
|
1439 |
+
* @param string $page_name page name.
|
1440 |
*
|
1441 |
* @return void
|
1442 |
*/
|
1443 |
+
public function settings_content_tabs( $page_name ) {
|
1444 |
global $wp_settings_sections, $wp_settings_fields;
|
1445 |
|
1446 |
+
if ( ! isset( $wp_settings_sections ) || ! isset( $wp_settings_sections[ $page_name ] ) ) {
|
1447 |
return;
|
1448 |
}
|
1449 |
|
1450 |
+
foreach ( (array) $wp_settings_sections[ $page_name ] as $section ) {
|
1451 |
if ( $section['title'] ) {
|
1452 |
+
?>
|
1453 |
+
<h3><?php esc_html( $section['title'] ); ?></h3>
|
1454 |
+
<?php
|
1455 |
}
|
1456 |
|
1457 |
if ( $section['callback'] ) {
|
1458 |
call_user_func( $section['callback'], $section );
|
1459 |
}
|
1460 |
|
1461 |
+
if ( ! isset( $wp_settings_fields ) || ! isset( $wp_settings_fields[ $page_name ] ) || ! isset( $wp_settings_fields[ $page_name ][ $section['id'] ] ) ) {
|
1462 |
continue;
|
1463 |
}
|
1464 |
|
1465 |
echo '<table class="form-table">';
|
1466 |
+
do_settings_fields( $page_name, $section['id'] );
|
1467 |
echo '</table>';
|
1468 |
}
|
1469 |
}
|
1473 |
*
|
1474 |
* @access public
|
1475 |
*
|
|
|
|
|
1476 |
* @return array $tabs
|
1477 |
*/
|
1478 |
public function settings_sub_tabs() {
|
1479 |
+
$tabs = array();
|
1480 |
|
1481 |
+
// Check to see which tab we are on.
|
1482 |
$tab = $this->get_current_tab();
|
1483 |
/* rtMedia */
|
1484 |
|
1496 |
'icon' => 'dashicons-groups',
|
1497 |
'title' => esc_html__( 'rtMedia BuddyPress', 'buddypress-media' ),
|
1498 |
'name' => esc_html__( 'BuddyPress', 'buddypress-media' ),
|
1499 |
+
'callback' => array( 'RTMediaFormHandler', 'buddypress_content' ), // change it to BuddyPress Content.
|
1500 |
);
|
1501 |
}
|
1502 |
|
1558 |
* @access public
|
1559 |
* @global type $rtmedia_admin
|
1560 |
*
|
|
|
|
|
1561 |
* @return void
|
1562 |
*/
|
1563 |
public function save_multisite_options() {
|
1564 |
global $rtmedia_admin;
|
1565 |
+
do_action( 'rtmedia_sanitize_settings', wp_unslash( $_POST ) ); // phpcs:ignore WordPress.Security.NonceVerification.NoNonceVerification
|
1566 |
|
1567 |
$rtmedia_options = filter_input( INPUT_POST, 'rtmedia_options' );
|
1568 |
if ( isset( $rtmedia_options ) ) {
|
1569 |
+
// todo: How we can sanitize array?
|
1570 |
rtmedia_update_site_option( 'rtmedia_options', $rtmedia_options );
|
1571 |
+
|
1572 |
+
// redirect to settings page in network.
|
1573 |
+
wp_safe_redirect(
|
1574 |
+
esc_url_raw(
|
1575 |
+
add_query_arg(
|
1576 |
+
array(
|
1577 |
+
'page' => 'rtmedia-settings',
|
1578 |
+
'updated' => 'true',
|
1579 |
+
),
|
1580 |
+
( is_multisite() ? network_admin_url( 'admin.php' ) : admin_url( 'admin.php' ) )
|
1581 |
+
)
|
1582 |
+
)
|
1583 |
+
);
|
1584 |
exit;
|
1585 |
}
|
1586 |
}
|
1590 |
*
|
1591 |
* @access public
|
1592 |
*
|
|
|
|
|
1593 |
* @return void
|
1594 |
*/
|
1595 |
public function admin_sidebar() {
|
1596 |
do_action( 'rtmedia_before_default_admin_widgets' );
|
1597 |
$current_user = wp_get_current_user();
|
1598 |
+
// translators: 1. Home url.
|
1599 |
+
$message = sprintf( esc_html__( 'I use @rtMediaWP http://rt.cx/rtmedia on %s', 'buddypress-media' ), home_url() );
|
1600 |
+
$addons = '<div id="social" class="rtm-social-share">
|
1601 |
+
<p><a href="http://twitter.com/home/?status=' . esc_attr( $message ) . '" class="button twitter" target= "_blank" title="' . esc_attr__( 'Post to Twitter Now', 'buddypress-media' ) . '">' . esc_html__( 'Post to Twitter', 'buddypress-media' ) . '<span class="dashicons dashicons-twitter"></span></a></p>
|
1602 |
+
<p><a href="https://www.facebook.com/sharer/sharer.php?u=https://rtmedia.io/" class="button facebook" target="_blank" title="' . esc_attr__( 'Share on Facebook Now', 'buddypress-media' ) . '">' . esc_html__( 'Share on Facebook', 'buddypress-media' ) . '<span class="dashicons dashicons-facebook"></span></a></p>
|
1603 |
+
<p><a href="https://wordpress.org/support/plugin/buddypress-media/reviews/#new-post" class="button wordpress" target= "_blank" title="' . esc_attr__( 'Rate rtMedia on Wordpress.org', 'buddypress-media' ) . '">' . esc_html__( 'Rate on Wordpress.org', 'buddypress-media' ) . '<span class="dashicons dashicons-wordpress"></span></a></p>
|
1604 |
+
<p><a href="' . sprintf( '%s', 'https://rtmedia.io/feed/' ) . '" class="button rss" target="_blank" title="' . esc_attr__( 'Subscribe to our Feeds', 'buddypress-media' ) . '">' . esc_html__( 'Subscribe to our Feeds', 'buddypress-media' ) . '<span class="dashicons dashicons-rss"></span></a></p>
|
1605 |
+
</div>';
|
1606 |
|
1607 |
new RTMediaAdminWidget( 'spread-the-word', esc_html__( 'Spread the Word', 'buddypress-media' ), $addons );
|
1608 |
|
1622 |
do_action( 'rtmedia_after_default_admin_widgets' );
|
1623 |
}
|
1624 |
|
1625 |
+
/**
|
1626 |
+
* Function to save linkback.
|
1627 |
+
*
|
1628 |
+
* @return mixed
|
1629 |
+
*/
|
1630 |
public function linkback() {
|
1631 |
+
// todo: remove code looks like old setting save code new code at app/helper/RTMediaSettings.php.
|
1632 |
$linkback = filter_input( INPUT_POST, 'linkback' );
|
1633 |
if ( isset( $linkback ) && $linkback ) {
|
1634 |
return rtmedia_update_site_option( 'rtmedia-add-linkback', true );
|
1672 |
|
1673 |
ob_start();
|
1674 |
include $file_path;
|
1675 |
+
|
1676 |
$settings_data_json = ob_get_clean();
|
1677 |
wp_delete_file( $file_path );
|
1678 |
|
1711 |
$response['rtm_response_msg'] = esc_html__( 'Could not update rtMedia Settings', 'buddypress-media' );
|
1712 |
}
|
1713 |
}
|
1714 |
+
|
1715 |
wp_send_json( $response );
|
1716 |
}
|
1717 |
|
1718 |
+
/**
|
1719 |
+
* Ajax callback function Convert videos mailchimp.
|
1720 |
+
*/
|
1721 |
public function convert_videos_mailchimp_send() {
|
1722 |
+
// todo: nonce required.
|
1723 |
+
$interested = sanitize_text_field( filter_input( INPUT_POST, 'linkback', FILTER_SANITIZE_STRING ) );
|
1724 |
+
$choice = sanitize_text_field( filter_input( INPUT_POST, 'choice', FILTER_SANITIZE_STRING ) );
|
1725 |
+
$url = filter_input( INPUT_POST, 'url', FILTER_SANITIZE_URL );
|
1726 |
+
$email = filter_input( INPUT_POST, 'email', FILTER_SANITIZE_EMAIL );
|
1727 |
+
|
1728 |
if ( 'Yes' === $interested && ! empty( $choice ) ) {
|
1729 |
+
wp_remote_get(
|
1730 |
+
esc_url_raw(
|
1731 |
+
add_query_arg(
|
1732 |
+
array(
|
1733 |
+
'rtmedia-convert-videos-form' => 1,
|
1734 |
+
'choice' => $choice,
|
1735 |
+
'url' => $url,
|
1736 |
+
'email' => $email,
|
1737 |
+
),
|
1738 |
+
'https://rtmedia.io/'
|
1739 |
+
)
|
1740 |
+
)
|
1741 |
+
);
|
1742 |
} else {
|
1743 |
rtmedia_update_site_option( 'rtmedia-survey', 0 );
|
1744 |
}
|
1745 |
+
|
1746 |
esc_html_e( 'Thank you for your time.', 'buddypress-media' );
|
1747 |
wp_die();
|
1748 |
}
|
1749 |
|
1750 |
+
/**
|
1751 |
+
* Function to save Video transcoding survey response.
|
1752 |
+
*/
|
1753 |
public function video_transcoding_survey_response() {
|
1754 |
$survey_done = filter_input( INPUT_GET, 'survey-done', FILTER_SANITIZE_STRING );
|
1755 |
if ( isset( $survey_done ) && ( md5( 'survey-done' ) === $survey_done ) ) {
|
1757 |
}
|
1758 |
}
|
1759 |
|
1760 |
+
/**
|
1761 |
+
* Premium addon link.
|
1762 |
+
*
|
1763 |
+
* @param array $plugin_meta Plugin meta.
|
1764 |
+
* @param string $plugin_file Plugin file.
|
1765 |
+
*
|
1766 |
+
* @return array
|
1767 |
+
*/
|
1768 |
public function plugin_meta_premium_addon_link( $plugin_meta, $plugin_file ) {
|
1769 |
if ( plugin_basename( RTMEDIA_PATH . 'index.php' ) === $plugin_file ) {
|
1770 |
$plugin_meta[] = '<a href="https://rtmedia.io/products/?utm_source=dashboard&utm_medium=plugin&utm_campaign=buddypress-media" title="' . esc_attr__( 'Premium Add-ons', 'buddypress-media' ) . '">' . esc_html__( 'Premium Add-ons', 'buddypress-media' ) . '</a>';
|
1773 |
return $plugin_meta;
|
1774 |
}
|
1775 |
|
1776 |
+
/**
|
1777 |
+
* Show upload file types error.
|
1778 |
+
*/
|
1779 |
public function upload_filetypes_error() {
|
1780 |
global $rtmedia;
|
1781 |
$upload_filetypes = rtmedia_get_site_option( 'upload_filetypes', 'jpg jpeg png gif' );
|
1782 |
$upload_filetypes = explode( ' ', $upload_filetypes );
|
1783 |
$flag = false;
|
1784 |
+
|
1785 |
if ( isset( $rtmedia->options['images_enabled'] ) && $rtmedia->options['images_enabled'] ) {
|
1786 |
$not_supported_image = array_diff( array( 'jpg', 'jpeg', 'png', 'gif' ), $upload_filetypes );
|
1787 |
if ( ! empty( $not_supported_image ) ) {
|
1789 |
<div class="error upload-filetype-network-settings-error">
|
1790 |
<p>
|
1791 |
<?php wp_nonce_field( '_rtm_file_type_error_', 'rtm-file-type-error' ); ?>
|
1792 |
+
<?php
|
1793 |
+
// translators: 1. Not supported image types.
|
1794 |
+
printf( esc_html__( 'You have images enabled on rtMedia but your network allowed filetypes do not permit uploading of %s. Click ', 'buddypress-media' ), esc_html( implode( ', ', $not_supported_image ) ) );
|
1795 |
+
?>
|
1796 |
+
<a href='<?php echo esc_url( network_admin_url( 'settings.php#upload_filetypes' ) ); ?>'><?php esc_html_e( 'here', 'buddypress-media' ); ?></a>
|
1797 |
+
<?php esc_html_e( ' to change your settings manually.', 'buddypress-media' ); ?>
|
1798 |
<br />
|
1799 |
<strong><?php esc_html_e( 'Recommended:', 'buddypress-media' ); ?></strong>
|
1800 |
+
<input type="button" class="button update-network-settings-upload-filetypes" value="<?php esc_attr_e( 'Update Network Settings Automatically', 'buddypress-media' ); ?>">
|
1801 |
<img style="display:none;" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" />
|
1802 |
</p>
|
1803 |
</div>
|
1810 |
?>
|
1811 |
<div class="error upload-filetype-network-settings-error">
|
1812 |
<p>
|
1813 |
+
<?php esc_html_e( 'You have video enabled on BuddyPress Media but your network allowed filetypes do not permit uploading of mp4. Click ', 'buddypress-media' ); ?>
|
1814 |
+
<a href='<?php echo esc_url( network_admin_url( 'settings.php#upload_filetypes' ) ); ?>'><?php esc_html_e( 'here', 'buddypress-media' ); ?></a>
|
1815 |
+
<?php esc_html_e( ' to change your settings manually.', 'buddypress-media' ); ?>
|
1816 |
<br />
|
1817 |
+
<strong><?php esc_html_e( 'Recommended:', 'buddypress-media' ); ?></strong>
|
1818 |
<input type="button" class="button update-network-settings-upload-filetypes" value="<?php esc_attr_e( 'Update Network Settings Automatically', 'buddypress-media' ); ?>">
|
1819 |
<img style="display:none;" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" />
|
1820 |
</p>
|
1828 |
?>
|
1829 |
<div class="error upload-filetype-network-settings-error">
|
1830 |
<p>
|
1831 |
+
<?php esc_html_e( 'You have audio enabled on BuddyPress Media but your network allowed filetypes do not permit uploading of mp3. Click ', 'buddypress-media' ); ?>
|
1832 |
+
<a href='<?php echo esc_url( network_admin_url( 'settings.php#upload_filetypes' ) ); ?>'><?php esc_html_e( 'here', 'buddypress-media' ); ?></a>
|
1833 |
+
<?php esc_html_e( ' to change your settings manually.', 'buddypress-media' ); ?>
|
1834 |
<br />
|
1835 |
<strong><?php esc_html_e( 'Recommended:', 'buddypress-media' ); ?></strong>
|
1836 |
<input type="button" class="button update-network-settings-upload-filetypes" value="<?php esc_attr_e( 'Update Network Settings Automatically', 'buddypress-media' ); ?>">
|
1860 |
}
|
1861 |
}
|
1862 |
|
1863 |
+
/**
|
1864 |
+
* Correct upload filetypes.
|
1865 |
+
*/
|
1866 |
public function correct_upload_filetypes() {
|
1867 |
if ( ! check_ajax_referer( '_rtm_file_type_error_', '_rtm_nonce' ) ) {
|
1868 |
wp_send_json( false );
|
1869 |
}
|
1870 |
+
|
1871 |
global $rtmedia;
|
1872 |
+
$upload_filetypes_orig = rtmedia_get_site_option( 'upload_filetypes', 'jpg jpeg png gif' );
|
1873 |
+
$upload_filetypes = $upload_filetypes_orig;
|
1874 |
$upload_filetypes = explode( ' ', $upload_filetypes );
|
1875 |
+
|
1876 |
if ( isset( $rtmedia->options['images_enabled'] ) && $rtmedia->options['images_enabled'] ) {
|
1877 |
$not_supported_image = array_diff( array( 'jpg', 'jpeg', 'png', 'gif' ), $upload_filetypes );
|
1878 |
if ( ! empty( $not_supported_image ) ) {
|
1902 |
wp_die();
|
1903 |
}
|
1904 |
|
1905 |
+
/**
|
1906 |
+
* Update template notice.
|
1907 |
+
*/
|
1908 |
+
public function rtmedia_update_template_notice() {
|
1909 |
$site_option = rtmedia_get_site_option( 'rtmedia-update-template-notice-v3_9_4' );
|
1910 |
|
1911 |
if ( ! $site_option || 'hide' !== $site_option ) {
|
1928 |
}
|
1929 |
}
|
1930 |
|
1931 |
+
/**
|
1932 |
+
* Hide template override notice.
|
1933 |
+
*/
|
1934 |
+
public function rtmedia_hide_template_override_notice() {
|
1935 |
|
1936 |
if ( check_ajax_referer( 'rtmedia_template_notice', '_rtm_nonce' ) && rtmedia_update_site_option( 'rtmedia-update-template-notice-v3_9_4', 'hide' ) ) {
|
1937 |
echo '1';
|
1941 |
die();
|
1942 |
}
|
1943 |
|
1944 |
+
/**
|
1945 |
+
* Render Admin UI.
|
1946 |
+
*
|
1947 |
+
* @param string $page_name Page name.
|
1948 |
+
* @param array $sub_tabs Sub tabs for page.
|
1949 |
+
* @param array $args Arguments to render page.
|
1950 |
+
*/
|
1951 |
+
public static function render_admin_ui( $page_name, $sub_tabs, $args = array() ) {
|
1952 |
|
1953 |
+
// wrapper class.
|
1954 |
$wrapper_class = '';
|
1955 |
if ( ! empty( $args['wrapper_class'] ) && is_array( $args['wrapper_class'] ) ) {
|
1956 |
$wrapper_class = implode( ' ', $args['wrapper_class'] );
|
1957 |
}
|
1958 |
|
1959 |
+
// tabs.
|
1960 |
+
if ( 'rtmedia-settings' === $page_name ) {
|
1961 |
$sub_tabs = apply_filters( 'rtmedia_pro_settings_tabs_content', $sub_tabs );
|
1962 |
ksort( $sub_tabs );
|
1963 |
}
|
1964 |
$tab_position_class = 'rtm-vertical-tabs';
|
1965 |
+
if ( 'rtmedia-addons' === $page_name ) {
|
1966 |
$tab_position_class = 'rtm-horizotanl-tabs';
|
1967 |
}
|
1968 |
?>
|
1974 |
$i = 1;
|
1975 |
foreach ( $sub_tabs as $tab ) {
|
1976 |
|
1977 |
+
// tab status.
|
1978 |
+
$active_class = '';
|
1979 |
+
$error_class = '';
|
1980 |
+
|
1981 |
if ( ! empty( $tab['args'] ) && ( empty( $tab['args']['status'] ) || 'valid' !== $tab['args']['status'] ) ) {
|
1982 |
$error_class = 'error';
|
1983 |
}
|
1985 |
$active_class = 'active';
|
1986 |
}
|
1987 |
|
|
|
|
|
|
|
|
|
|
|
1988 |
?>
|
1989 |
+
<li class="<?php echo esc_attr( $active_class ); ?> <?php echo esc_attr( $error_class ); ?>">
|
1990 |
+
<a id="tab-<?php echo esc_attr( substr( $tab['href'], 1 ) ); ?>" title="<?php echo esc_attr( $tab['title'] ); ?>" href="<?php echo esc_url( $tab['href'] ); ?>" class="rtmedia-tab-title <?php echo esc_attr( sanitize_title( $tab['name'] ) ); ?>">
|
1991 |
+
<?php
|
1992 |
+
if ( isset( $tab['icon'] ) && ! empty( $tab['icon'] ) ) {
|
1993 |
+
?>
|
1994 |
+
<i class="<?php echo esc_attr( $tab['icon'] ); ?> dashicons"></i>
|
1995 |
+
<?php
|
1996 |
+
}
|
1997 |
+
?>
|
1998 |
+
<span><?php echo esc_html( $tab['name'] ); ?></span>
|
1999 |
</a>
|
2000 |
</li>
|
2001 |
<?php
|
2002 |
+
$i++;
|
2003 |
}
|
2004 |
?>
|
2005 |
</ul>
|
2012 |
if ( 1 === $k ) {
|
2013 |
$active_class = ' active';
|
2014 |
}
|
2015 |
+
$k++;
|
2016 |
if ( isset( $tab['icon'] ) && ! empty( $tab['icon'] ) ) {
|
2017 |
$icon = '<i class="' . esc_attr( $tab['icon'] ) . '"></i>';
|
2018 |
}
|
2020 |
$tab_without_hash = $tab_without_hash[1];
|
2021 |
echo '<div class="rtm-content' . esc_attr( $active_class ) . '" id="' . esc_attr( $tab_without_hash ) . '">';
|
2022 |
if ( isset( $tab['args'] ) ) {
|
2023 |
+
call_user_func( $tab['callback'], $page_name, $tab['args'] );
|
2024 |
} else {
|
2025 |
+
call_user_func( $tab['callback'], $page_name );
|
2026 |
}
|
2027 |
echo '</div>';
|
2028 |
}
|
2037 |
* To remove setting saved parameter from url once satting saved
|
2038 |
* Add parameter to this array WP will remove variable from Query string
|
2039 |
*
|
2040 |
+
* @param array $removable_query_args arguments.
|
2041 |
*
|
2042 |
* @return array $removable_query_args
|
2043 |
*/
|
2044 |
+
public function removable_query_args( $removable_query_args ) {
|
2045 |
+
$page_name = filter_input( INPUT_GET, 'page', FILTER_SANITIZE_STRING );
|
2046 |
+
if ( isset( $page_name ) && 'rtmedia-settings' === $page_name ) {
|
2047 |
$removable_query_args[] = 'settings-saved';
|
2048 |
}
|
2049 |
|
2051 |
}
|
2052 |
|
2053 |
/**
|
2054 |
+
* Display invalid license notice to admins.
|
2055 |
*
|
2056 |
* @since 4.1.7
|
2057 |
*
|
2058 |
* @return void
|
2059 |
*/
|
2060 |
+
public function rtm_addon_license_notice() {
|
2061 |
|
2062 |
+
$page_name = filter_input( INPUT_GET, 'page', FILTER_SANITIZE_STRING );
|
2063 |
+
$args = array(
|
2064 |
+
'a' => array(
|
2065 |
+
'href' => array(),
|
2066 |
+
),
|
2067 |
+
);
|
2068 |
+
|
2069 |
+
if ( ! empty( $page_name ) && 'rtmedia-license' === $page_name ) {
|
2070 |
+
$my_account = 'https://rtmedia.io/my-account';
|
2071 |
$license_doc = 'https://rtmedia.io/docs/license/';
|
2072 |
+
|
2073 |
+
// translators: 1. Account page and link.
|
2074 |
+
$message = sprintf( __( 'Your license keys can be found on <a href="%1$s">my-account</a> page. For more details, please refer to <a href="%2$s">License documentation</a> page.', 'buddypress-media' ), $my_account, $license_doc );
|
2075 |
+
echo '<div class="notice"><p>' . wp_kses( $message, $args ) . '</p></div>';
|
2076 |
+
|
2077 |
return;
|
2078 |
}
|
2079 |
|
2083 |
return;
|
2084 |
}
|
2085 |
|
|
|
2086 |
foreach ( $addons as $addon ) {
|
2087 |
if ( empty( $addon['args']['status'] ) || 'valid' !== $addon['args']['status'] ) {
|
2088 |
$message = sprintf(
|
2089 |
+
// translators: 1. License page link.
|
2090 |
+
__( 'We found an invalid or expired license key for an rtMedia add-on. Please go to the <a href="%1$s">Licenses page</a> to fix this issue.', 'buddypress-media' ),
|
2091 |
admin_url( 'admin.php?page=rtmedia-license' )
|
2092 |
);
|
2093 |
+
echo '<div class="error"><p>' . wp_kses( $message, $args ) . '</p></div>';
|
2094 |
break;
|
2095 |
}
|
2096 |
}
|
app/admin/RTMediaFormHandler.php
CHANGED
@@ -1,17 +1,24 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
*
|
4 |
-
*
|
|
|
|
|
5 |
*/
|
6 |
|
7 |
/**
|
8 |
-
*
|
9 |
*
|
10 |
* @author udit
|
11 |
*/
|
12 |
class RTMediaFormHandler {
|
13 |
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
15 |
$defaults = array(
|
16 |
'key' => '',
|
17 |
'desc' => '',
|
@@ -20,35 +27,34 @@ class RTMediaFormHandler {
|
|
20 |
'selects' => array(),
|
21 |
);
|
22 |
$args = wp_parse_args( $args, $defaults );
|
23 |
-
extract( $args );
|
24 |
|
25 |
-
if ( ! empty( $key ) ) {
|
26 |
-
$args['name'] = 'rtmedia-options[' . $key . ']';
|
27 |
}
|
28 |
|
29 |
$args['rtForm_options'] = array();
|
30 |
-
if ( ! empty( $selects ) ) {
|
31 |
-
foreach ( $selects as $value => $key ) {
|
32 |
$args['rtForm_options'][] = array(
|
33 |
$key => $value,
|
34 |
-
'selected' => ( $default === $value ) ? true : false,
|
35 |
);
|
36 |
}
|
37 |
}
|
38 |
|
39 |
-
$
|
40 |
-
$
|
41 |
}
|
42 |
|
43 |
/**
|
44 |
-
* Show
|
45 |
*
|
46 |
* @access static
|
47 |
*
|
48 |
-
* @param array $args
|
49 |
-
* @param bool
|
50 |
*
|
51 |
-
* @return string $
|
52 |
*/
|
53 |
public static function textarea( $args, $echo = true ) {
|
54 |
$defaults = array(
|
@@ -57,39 +63,44 @@ class RTMediaFormHandler {
|
|
57 |
'show_desc' => false,
|
58 |
);
|
59 |
$args = wp_parse_args( $args, $defaults );
|
60 |
-
extract( $args );
|
61 |
|
62 |
-
if ( ! isset( $value ) ) {
|
63 |
-
trigger_error( esc_html__( 'Please provide a "value" in the argument.', 'buddypress-media' ) );
|
64 |
|
65 |
-
return;
|
66 |
}
|
67 |
|
68 |
-
if ( ! empty( $key ) ) {
|
69 |
-
$args['name'] = 'rtmedia-options[' . $key . ']';
|
70 |
}
|
71 |
|
72 |
-
$args['rtForm_options'] = array(
|
|
|
|
|
|
|
|
|
|
|
73 |
|
74 |
-
$
|
75 |
|
76 |
if ( $echo ) {
|
77 |
-
$
|
78 |
} else {
|
79 |
-
return $
|
80 |
}
|
81 |
-
|
|
|
82 |
}
|
83 |
|
84 |
/**
|
85 |
-
* Show
|
86 |
*
|
87 |
* @access static
|
88 |
*
|
89 |
-
* @param array $args
|
90 |
-
* @param bool
|
91 |
*
|
92 |
-
* @return string $
|
93 |
*/
|
94 |
public static function checkbox( $args, $echo = true ) {
|
95 |
$defaults = array(
|
@@ -98,36 +109,41 @@ class RTMediaFormHandler {
|
|
98 |
'show_desc' => false,
|
99 |
);
|
100 |
$args = wp_parse_args( $args, $defaults );
|
101 |
-
extract( $args );
|
102 |
|
103 |
-
if ( ! isset( $value ) ) {
|
104 |
-
trigger_error( esc_html__( 'Please provide a "value" in the argument.', 'buddypress-media' ) );
|
105 |
|
106 |
return;
|
107 |
}
|
108 |
|
109 |
-
if ( ! empty( $key ) ) {
|
110 |
-
$args['name'] = 'rtmedia-options[' . $key . ']';
|
111 |
}
|
112 |
|
113 |
-
$args['rtForm_options'] = array(
|
|
|
|
|
|
|
|
|
|
|
114 |
|
115 |
-
$
|
116 |
|
117 |
if ( $echo ) {
|
118 |
-
$
|
119 |
} else {
|
120 |
-
return $
|
121 |
}
|
122 |
-
|
|
|
123 |
}
|
124 |
|
125 |
/**
|
126 |
-
* Show
|
127 |
*
|
128 |
* @access static
|
129 |
*
|
130 |
-
* @param
|
131 |
*
|
132 |
* @return void
|
133 |
*/
|
@@ -139,39 +155,42 @@ class RTMediaFormHandler {
|
|
139 |
'show_desc' => false,
|
140 |
);
|
141 |
$args = wp_parse_args( $args, $defaults );
|
142 |
-
extract( $args );
|
143 |
|
144 |
-
if ( 2 > count( $radios ) ) {
|
145 |
-
trigger_error( esc_html__( 'Need to specify atleast two radios, else use a checkbox instead', 'buddypress-media' ) );
|
146 |
|
147 |
return;
|
148 |
}
|
149 |
|
150 |
-
if ( ! empty( $key ) ) {
|
151 |
-
$args['name'] = 'rtmedia-options[' . $key . ']';
|
152 |
}
|
153 |
|
154 |
$args['rtForm_options'] = array();
|
155 |
-
foreach ( $radios as $value => $key ) {
|
156 |
$args['rtForm_options'][] = array(
|
157 |
$key => $value,
|
158 |
-
'
|
|
|
159 |
);
|
160 |
}
|
161 |
|
162 |
-
$
|
163 |
-
$
|
164 |
}
|
165 |
|
166 |
/**
|
167 |
-
* Show
|
|
|
|
|
168 |
*
|
169 |
* @access static
|
|
|
170 |
* @return void
|
171 |
*/
|
172 |
public static function dimensions( $args ) {
|
173 |
-
$
|
174 |
-
$
|
175 |
}
|
176 |
|
177 |
/**
|
@@ -179,34 +198,33 @@ class RTMediaFormHandler {
|
|
179 |
*
|
180 |
* @access static
|
181 |
*
|
182 |
-
* @param
|
183 |
*
|
184 |
* @return void
|
185 |
*/
|
186 |
public static function number( $args ) {
|
|
|
187 |
global $rtmedia;
|
|
|
188 |
$options = $rtmedia->options;
|
189 |
$defaults = array(
|
190 |
'key' => '',
|
191 |
'desc' => '',
|
192 |
);
|
193 |
$args = wp_parse_args( $args, $defaults );
|
194 |
-
extract( $args );
|
195 |
|
196 |
-
if ( ! isset( $value ) ) {
|
197 |
-
trigger_error( esc_html__( 'Please provide a "value" in the argument.', 'buddypress-media' ) );
|
198 |
|
199 |
return;
|
200 |
}
|
201 |
|
202 |
-
if ( ! empty( $key ) ) {
|
203 |
-
$args['name'] = 'rtmedia-options[' . $key . ']';
|
204 |
}
|
205 |
|
206 |
-
$
|
207 |
-
|
208 |
-
$numObj = new rtForm();
|
209 |
-
$numObj->display_number( $args );
|
210 |
}
|
211 |
|
212 |
/**
|
@@ -214,7 +232,7 @@ class RTMediaFormHandler {
|
|
214 |
*
|
215 |
* @access static
|
216 |
*
|
217 |
-
* @param array $args
|
218 |
*
|
219 |
* @return void
|
220 |
*/
|
@@ -226,22 +244,19 @@ class RTMediaFormHandler {
|
|
226 |
'desc' => '',
|
227 |
);
|
228 |
$args = wp_parse_args( $args, $defaults );
|
229 |
-
extract( $args );
|
230 |
|
231 |
-
if ( ! isset( $value ) ) {
|
232 |
-
trigger_error( esc_html__( 'Please provide a "value" in the argument.', 'buddypress-media' ) );
|
233 |
|
234 |
return;
|
235 |
}
|
236 |
|
237 |
-
if ( ! empty( $key ) ) {
|
238 |
-
$args['name'] = 'rtmedia-options[' . $key . ']';
|
239 |
}
|
240 |
|
241 |
-
$
|
242 |
-
|
243 |
-
$numObj = new rtForm();
|
244 |
-
$numObj->display_textbox( $args );
|
245 |
}
|
246 |
|
247 |
/**
|
@@ -249,9 +264,12 @@ class RTMediaFormHandler {
|
|
249 |
*
|
250 |
* @access static
|
251 |
*
|
252 |
-
* @param
|
|
|
253 |
*
|
254 |
-
* @return
|
|
|
|
|
255 |
*/
|
256 |
public static function link( $args, $echo = true ) {
|
257 |
|
@@ -262,32 +280,31 @@ class RTMediaFormHandler {
|
|
262 |
'desc' => '',
|
263 |
);
|
264 |
$args = wp_parse_args( $args, $defaults );
|
265 |
-
extract( $args );
|
266 |
|
267 |
-
if ( ! isset( $href ) ) {
|
268 |
-
trigger_error( esc_html__( 'Please provide a "href" in the argument.', 'buddypress-media' ) );
|
269 |
|
270 |
-
return;
|
271 |
}
|
272 |
|
273 |
-
if ( ! isset( $text ) ) {
|
274 |
-
trigger_error( esc_html__( 'Please provide a "text" in the argument.', 'buddypress-media' ) );
|
275 |
|
276 |
-
return;
|
277 |
}
|
278 |
|
279 |
-
if( isset( $target ) && ! empty( $target ) ) {
|
280 |
-
$args['misc'] = array( 'target' => $target
|
281 |
}
|
282 |
|
283 |
-
$
|
284 |
|
285 |
if ( $echo ) {
|
286 |
|
287 |
-
$
|
288 |
} else {
|
289 |
|
290 |
-
return $
|
291 |
}
|
292 |
}
|
293 |
|
@@ -301,6 +318,8 @@ class RTMediaFormHandler {
|
|
301 |
* @param array $args arguments to create button.
|
302 |
*
|
303 |
* @return void
|
|
|
|
|
304 |
*/
|
305 |
public static function button( $args ) {
|
306 |
$defaults = array(
|
@@ -310,13 +329,13 @@ class RTMediaFormHandler {
|
|
310 |
$args = wp_parse_args( $args, $defaults );
|
311 |
|
312 |
if ( empty( $args['value'] ) ) {
|
313 |
-
trigger_error( esc_html__( 'Please provide a "value" in the argument.', 'buddypress-media' ) );
|
314 |
|
315 |
return;
|
316 |
}
|
317 |
|
318 |
-
$
|
319 |
-
$
|
320 |
}
|
321 |
|
322 |
/**
|
@@ -330,6 +349,7 @@ class RTMediaFormHandler {
|
|
330 |
*
|
331 |
* @return void
|
332 |
*
|
|
|
333 |
*/
|
334 |
public static function fileinput( $args ) {
|
335 |
$defaults = array(
|
@@ -339,13 +359,13 @@ class RTMediaFormHandler {
|
|
339 |
$args = wp_parse_args( $args, $defaults );
|
340 |
|
341 |
if ( empty( $args['value'] ) ) {
|
342 |
-
trigger_error( esc_html__( 'Please provide a "value" in the argument.', 'buddypress-media' ) );
|
343 |
|
344 |
return;
|
345 |
}
|
346 |
|
347 |
-
$
|
348 |
-
$
|
349 |
}
|
350 |
|
351 |
/**
|
@@ -356,6 +376,8 @@ class RTMediaFormHandler {
|
|
356 |
* @param array $args Arguments to create file input control for default thumbnail generator settings.
|
357 |
*
|
358 |
* @return void
|
|
|
|
|
359 |
*/
|
360 |
public static function inputfile( $args ) {
|
361 |
global $rtmedia;
|
@@ -372,24 +394,22 @@ class RTMediaFormHandler {
|
|
372 |
$args['name'] = $args['key'];
|
373 |
}
|
374 |
|
375 |
-
$args['value'] = $args['value'];
|
376 |
-
|
377 |
$num_obj = new rtForm();
|
378 |
$num_obj->display_inputfile( $args );
|
379 |
}
|
380 |
|
381 |
|
382 |
/**
|
383 |
-
*
|
384 |
*
|
385 |
* @access static
|
386 |
*
|
387 |
-
* @param
|
388 |
-
* @param
|
389 |
*
|
390 |
* @return array $section
|
391 |
*/
|
392 |
-
static function extract_settings( $section_name, $options ) {
|
393 |
$section = array();
|
394 |
foreach ( $options as $key => $value ) {
|
395 |
$compare = strncmp( $key, $section_name, strlen( $section_name ) );
|
@@ -402,15 +422,15 @@ class RTMediaFormHandler {
|
|
402 |
}
|
403 |
|
404 |
/**
|
405 |
-
*
|
406 |
*
|
407 |
* @access static
|
408 |
*
|
409 |
-
* @param
|
410 |
*
|
411 |
* @return array $render
|
412 |
*/
|
413 |
-
static function display_render_options( $options ) {
|
414 |
$radios = array();
|
415 |
$radios['load_more'] = '<strong>' . esc_html__( 'Load More', 'buddypress-media' ) . '</strong>';
|
416 |
$radios['pagination'] = '<strong>' . esc_html__( 'Pagination', 'buddypress-media' ) . '</strong>';
|
@@ -424,7 +444,7 @@ class RTMediaFormHandler {
|
|
424 |
}
|
425 |
|
426 |
$render = array(
|
427 |
-
'general_enableComments'
|
428 |
'title' => esc_html__( 'Allow user to comment on uploaded media', 'buddypress-media' ),
|
429 |
'callback' => array( 'RTMediaFormHandler', 'checkbox' ),
|
430 |
'args' => array(
|
@@ -434,27 +454,27 @@ class RTMediaFormHandler {
|
|
434 |
),
|
435 |
'group' => '10',
|
436 |
),
|
437 |
-
'general_enableGallerysearch'
|
438 |
-
'title'
|
439 |
'callback' => array( 'RTMediaFormHandler', 'checkbox' ),
|
440 |
-
'args'
|
441 |
-
'key'
|
442 |
'value' => $options['general_enableGallerysearch'],
|
443 |
-
'desc'
|
444 |
),
|
445 |
-
'group'
|
446 |
),
|
447 |
-
'general_enableLikes'
|
448 |
'title' => __( 'Enable likes for media', 'buddypress-media' ),
|
449 |
'callback' => array( 'RTMediaFormHandler', 'checkbox' ),
|
450 |
-
'args'
|
451 |
-
'key'
|
452 |
'value' => $options['general_enableLikes'],
|
453 |
-
'desc'
|
454 |
),
|
455 |
-
'group'
|
456 |
),
|
457 |
-
'general_enableLightbox'
|
458 |
'title' => esc_html__( 'Use lightbox to display media', 'buddypress-media' ),
|
459 |
'callback' => array( 'RTMediaFormHandler', 'checkbox' ),
|
460 |
'args' => array(
|
@@ -464,7 +484,7 @@ class RTMediaFormHandler {
|
|
464 |
),
|
465 |
'group' => '15',
|
466 |
),
|
467 |
-
'general_perPageMedia'
|
468 |
'title' => esc_html__( 'Number of media per page', 'buddypress-media' ),
|
469 |
'callback' => array( 'RTMediaFormHandler', 'number' ),
|
470 |
'args' => array(
|
@@ -476,7 +496,7 @@ class RTMediaFormHandler {
|
|
476 |
),
|
477 |
'group' => '15',
|
478 |
),
|
479 |
-
'general_display_media'
|
480 |
'title' => esc_html__( 'Media display pagination option', 'buddypress-media' ),
|
481 |
'callback' => array( 'RTMediaFormHandler', 'radio' ),
|
482 |
'args' => array(
|
@@ -488,7 +508,7 @@ class RTMediaFormHandler {
|
|
488 |
),
|
489 |
'group' => '15',
|
490 |
),
|
491 |
-
'general_masonry_layout'
|
492 |
'title' => esc_html__( 'Enable', 'buddypress-media' ) . ' <a href="http://masonry.desandro.com/" target="_blank">Masonry</a> ' . esc_html__( 'Cascading grid layout', 'buddypress-media' ),
|
493 |
'callback' => array( 'RTMediaFormHandler', 'checkbox' ),
|
494 |
'args' => array(
|
@@ -501,18 +521,18 @@ class RTMediaFormHandler {
|
|
501 |
'after_content' => esc_html__( 'You might need to', 'buddypress-media' ) . ' <a id="rtm-masonry-change-thumbnail-info" href="' . get_admin_url() . 'admin.php?page=rtmedia-settings#rtmedia-sizes">' . esc_html__( 'change thumbnail size', 'buddypress-media' ) . '</a> ' . esc_html__( 'and uncheck the crop box for thumbnails.', 'buddypress-media' ) . '<br /><br />' . esc_html__( 'To set gallery for fixed width, set image height to 0 and width as per your requirement and vice-versa.', 'buddypress-media' ),
|
502 |
),
|
503 |
'general_masonry_layout_activity' => array(
|
504 |
-
'title'
|
505 |
-
'callback'
|
506 |
-
'args'
|
507 |
'key' => 'general_masonry_layout_activity',
|
508 |
'value' => $options['general_masonry_layout_activity'],
|
509 |
'desc' => esc_html__( 'If you enable masonry view, it is advisable to', 'buddypress-media' ) . ' <a href="' . $regenerate_link . '">regenerate thumbnail</a> ' . esc_html__( 'for masonry view.', 'buddypress-media' ),
|
510 |
'class' => array( 'rtm_enable_masonry_view' ),
|
511 |
),
|
512 |
-
'depends'
|
513 |
-
'group'
|
514 |
),
|
515 |
-
'general_direct_upload'
|
516 |
'title' => esc_html__( 'Enable Direct Upload', 'buddypress-media' ),
|
517 |
'callback' => array( 'RTMediaFormHandler', 'checkbox' ),
|
518 |
'args' => array(
|
@@ -533,41 +553,39 @@ class RTMediaFormHandler {
|
|
533 |
}
|
534 |
|
535 |
/**
|
536 |
-
*
|
537 |
*
|
538 |
* @access static
|
539 |
*
|
540 |
-
* @param void
|
541 |
-
*
|
542 |
* @return void
|
543 |
*/
|
544 |
public static function display_content() {
|
545 |
global $rtmedia;
|
546 |
-
$options
|
547 |
-
$render_options
|
548 |
-
$render_options
|
549 |
-
$general_group
|
550 |
-
$general_group[10]
|
551 |
-
$general_group[11]
|
552 |
-
$general_group[15]
|
553 |
-
$general_group[18]
|
554 |
-
$general_group[19]
|
555 |
-
$general_group[14]
|
556 |
-
$general_group
|
557 |
ksort( $general_group );
|
558 |
self::render_tab_content( $render_options, $general_group, 20 );
|
559 |
}
|
560 |
|
561 |
/**
|
562 |
-
*
|
563 |
*
|
564 |
* @access static
|
565 |
*
|
566 |
-
* @param
|
567 |
*
|
568 |
* @return array $render
|
569 |
*/
|
570 |
-
static function render_general_content( $options ) {
|
571 |
$render = array(
|
572 |
'general_AllowUserData' => array(
|
573 |
'title' => esc_html__( 'Allow usage data tracking', 'buddypress-media' ),
|
@@ -587,7 +605,7 @@ class RTMediaFormHandler {
|
|
587 |
'desc' => esc_html__( 'Add rtMedia menu to WordPress admin bar for easy access to settings and moderation page (if enabled).', 'buddypress-media' ),
|
588 |
),
|
589 |
'group' => 10,
|
590 |
-
),
|
591 |
'rtmedia_add_linkback' => array(
|
592 |
'title' => esc_html__( 'Add a link to rtMedia in footer', 'buddypress-media' ),
|
593 |
'callback' => array( 'RTMediaFormHandler', 'checkbox' ),
|
@@ -597,7 +615,7 @@ class RTMediaFormHandler {
|
|
597 |
'desc' => esc_html__( 'Help us promote rtMedia.', 'buddypress-media' ),
|
598 |
),
|
599 |
'group' => 100,
|
600 |
-
),
|
601 |
'rtmedia_enable_api' => array(
|
602 |
'title' => esc_html__( 'Enable JSON API', 'buddypress-media' ),
|
603 |
'callback' => array( 'RTMediaFormHandler', 'checkbox' ),
|
@@ -608,7 +626,7 @@ class RTMediaFormHandler {
|
|
608 |
),
|
609 |
'group' => 80,
|
610 |
'after_content' => esc_html__( 'You can refer to the API document from', 'buddypress-media' ) . ' <a href="https://rtmedia.io/docs/developers/json-api/">' . esc_html__( 'here', 'buddypress-media' ) . '</a>',
|
611 |
-
),
|
612 |
);
|
613 |
|
614 |
return $render;
|
@@ -621,7 +639,7 @@ class RTMediaFormHandler {
|
|
621 |
*
|
622 |
* @return void
|
623 |
*/
|
624 |
-
static function general_content() {
|
625 |
global $rtmedia;
|
626 |
$options = $rtmedia->options;
|
627 |
$render_options = self::render_general_content( $options );
|
@@ -637,7 +655,7 @@ class RTMediaFormHandler {
|
|
637 |
}
|
638 |
|
639 |
/**
|
640 |
-
*
|
641 |
*
|
642 |
* @access public
|
643 |
*
|
@@ -645,9 +663,9 @@ class RTMediaFormHandler {
|
|
645 |
*
|
646 |
* @return array $render
|
647 |
*/
|
648 |
-
static function render_export_import() {
|
649 |
$render = array(
|
650 |
-
'rtmedia_export_settings'
|
651 |
'title' => esc_html__( 'Export rtMedia Settings', 'buddypress-media' ),
|
652 |
'callback' => array( 'RTMediaFormHandler', 'button' ),
|
653 |
'args' => array(
|
@@ -659,7 +677,7 @@ class RTMediaFormHandler {
|
|
659 |
),
|
660 |
'group' => 10,
|
661 |
),
|
662 |
-
'rtmedia_import_settings'
|
663 |
'title' => esc_html__( 'Import rtMedia Settings', 'buddypress-media' ),
|
664 |
'callback' => array( 'RTMediaFormHandler', 'fileinput' ),
|
665 |
'args' => array(
|
@@ -683,17 +701,17 @@ class RTMediaFormHandler {
|
|
683 |
),
|
684 |
'group' => 11,
|
685 |
),
|
686 |
-
'rtmedia_erase_personal_data'
|
687 |
-
'title'
|
688 |
-
'callback'
|
689 |
-
'args'
|
690 |
'id' => 'rtm-erase-data-button',
|
691 |
'key' => 'rtm-erase-data-button',
|
692 |
'value' => esc_html__( 'Erase Data', 'buddypress-media' ),
|
693 |
'desc' => esc_html__( 'This will erase your personal data.', 'buddypress-media' ),
|
694 |
'class' => array( 'button', 'button-primary', 'button-small' ),
|
695 |
),
|
696 |
-
'group'
|
697 |
'after_content' => esc_html__( 'Data will be expoted or erased along with wordpress user data.', 'buddypress-media' ),
|
698 |
),
|
699 |
);
|
@@ -711,7 +729,7 @@ class RTMediaFormHandler {
|
|
711 |
*
|
712 |
* @return void
|
713 |
*/
|
714 |
-
static function rtm_export_import() {
|
715 |
|
716 |
global $rtmedia;
|
717 |
$render_options = self::render_export_import();
|
@@ -741,12 +759,12 @@ class RTMediaFormHandler {
|
|
741 |
*
|
742 |
* @access static
|
743 |
*
|
744 |
-
* @param array
|
745 |
-
* @param string $key
|
746 |
*
|
747 |
-
* @return array
|
748 |
*/
|
749 |
-
static function get_type_details( $allowed_types, $key ) {
|
750 |
foreach ( $allowed_types as $type ) {
|
751 |
if ( $type['name'] === $key ) {
|
752 |
$data = array(
|
@@ -768,11 +786,11 @@ class RTMediaFormHandler {
|
|
768 |
*
|
769 |
* @access static
|
770 |
*
|
771 |
-
* @param
|
772 |
*
|
773 |
* @return array $render
|
774 |
*/
|
775 |
-
static function types_render_options( $options ) {
|
776 |
$render = array();
|
777 |
$allowed_media_type = rtmedia_get_allowed_types();
|
778 |
|
@@ -796,8 +814,6 @@ class RTMediaFormHandler {
|
|
796 |
*
|
797 |
* @access static
|
798 |
*
|
799 |
-
* @param void
|
800 |
-
*
|
801 |
* @return void
|
802 |
*/
|
803 |
public static function types_content() {
|
@@ -818,7 +834,9 @@ class RTMediaFormHandler {
|
|
818 |
<?php do_action( 'rtmedia_type_settings_before_heading' ); ?>
|
819 |
|
820 |
<tr>
|
821 |
-
<th
|
|
|
|
|
822 |
|
823 |
<th>
|
824 |
|
@@ -840,7 +858,7 @@ class RTMediaFormHandler {
|
|
840 |
</span>
|
841 |
</th>
|
842 |
|
843 |
-
<?php do_action( 'rtmedia_type_setting_columns_title' ) ?>
|
844 |
</tr>
|
845 |
|
846 |
<?php
|
@@ -850,27 +868,27 @@ class RTMediaFormHandler {
|
|
850 |
if ( isset( $section['settings_visibility'] ) && true === $section['settings_visibility'] ) {
|
851 |
do_action( 'rtmedia_type_settings_before_body' );
|
852 |
|
853 |
-
// allow upload
|
854 |
$uplaod_args = array(
|
855 |
'key' => 'allowedTypes_' . $key . '_enabled',
|
856 |
'value' => $section['enabled'],
|
857 |
);
|
858 |
-
$allow_upload_checkbox = self::checkbox( $uplaod_args,
|
859 |
$allow_upload_checkbox = apply_filters( 'rtmedia_filter_allow_upload_checkbox', $allow_upload_checkbox, $key, $uplaod_args );
|
860 |
|
861 |
-
// allow featured
|
862 |
$featured_args = array(
|
863 |
-
'key'
|
864 |
-
'value'
|
865 |
);
|
866 |
-
$featured_checkbox = self::checkbox( $featured_args,
|
867 |
$featured_checkbox = apply_filters( 'rtmedia_filter_featured_checkbox', $featured_checkbox, $key );
|
868 |
|
869 |
if ( ! isset( $section['extn'] ) || ! is_array( $section['extn'] ) ) {
|
870 |
$section['extn'] = array();
|
871 |
}
|
872 |
|
873 |
-
$extensions
|
874 |
?>
|
875 |
|
876 |
<tr>
|
@@ -895,57 +913,63 @@ class RTMediaFormHandler {
|
|
895 |
|
896 |
<td>
|
897 |
<span class="rtm-field-wrap">
|
898 |
-
<?php
|
899 |
-
//
|
900 |
-
echo wp_kses(
|
901 |
-
|
902 |
-
|
903 |
-
'
|
904 |
-
|
905 |
-
|
906 |
-
|
907 |
-
|
908 |
-
'
|
909 |
-
|
910 |
-
|
911 |
-
|
912 |
-
'
|
913 |
-
|
914 |
-
|
915 |
-
|
916 |
-
|
917 |
-
|
918 |
-
|
|
|
|
|
|
|
919 |
?>
|
920 |
</span>
|
921 |
</td>
|
922 |
|
923 |
<td>
|
924 |
-
<?php
|
925 |
-
//
|
926 |
-
echo wp_kses(
|
927 |
-
|
928 |
-
|
929 |
-
'
|
930 |
-
|
931 |
-
|
932 |
-
|
933 |
-
|
934 |
-
'
|
935 |
-
|
936 |
-
|
937 |
-
|
938 |
-
'
|
939 |
-
|
940 |
-
|
941 |
-
|
942 |
-
|
943 |
-
|
944 |
-
|
|
|
|
|
|
|
945 |
?>
|
946 |
</td>
|
947 |
|
948 |
-
<?php do_action( 'rtmedia_type_setting_columns_body', $key, $section ) ?>
|
949 |
</tr>
|
950 |
|
951 |
<?php do_action( 'rtmedia_other_type_settings_textarea', $key ); ?>
|
@@ -974,21 +998,21 @@ class RTMediaFormHandler {
|
|
974 |
*
|
975 |
* @access static
|
976 |
*
|
977 |
-
* @param array $options
|
978 |
*
|
979 |
* @return array $render
|
980 |
*/
|
981 |
-
static function sizes_render_options( $options ) {
|
982 |
$render = array();
|
983 |
foreach ( $options as $key => $value ) {
|
984 |
$data = explode( '_', $key );
|
985 |
if ( ! isset( $render[ $data[1] ] ) ) {
|
986 |
$render[ $data[1] ] = array();
|
987 |
-
$render[ $data[1] ]['title'] =
|
988 |
}
|
989 |
if ( ! isset( $render[ $data[1] ][ $data[2] ] ) ) {
|
990 |
$render[ $data[1] ][ $data[2] ] = array();
|
991 |
-
$render[ $data[1] ][ $data[2] ]['title'] =
|
992 |
}
|
993 |
|
994 |
$render[ $data[1] ][ $data[2] ][ $data[3] ] = $value;
|
@@ -998,12 +1022,10 @@ class RTMediaFormHandler {
|
|
998 |
}
|
999 |
|
1000 |
/**
|
1001 |
-
*
|
1002 |
*
|
1003 |
* @access static
|
1004 |
*
|
1005 |
-
* @param void
|
1006 |
-
*
|
1007 |
* @return void
|
1008 |
*/
|
1009 |
public static function sizes_content() {
|
@@ -1019,7 +1041,7 @@ class RTMediaFormHandler {
|
|
1019 |
|
1020 |
<table class="form-table">
|
1021 |
<tr>
|
1022 |
-
<th><strong><?php esc_html_e( 'Category', 'buddypress-media' ) ?></strong></th>
|
1023 |
<th><strong><?php esc_html_e( 'Entity', 'buddypress-media' ); ?></strong></th>
|
1024 |
<th><strong><?php esc_html_e( 'Width', 'buddypress-media' ); ?></strong></th>
|
1025 |
<th><strong><?php esc_html_e( 'Height', 'buddypress-media' ); ?></strong></th>
|
@@ -1031,7 +1053,7 @@ class RTMediaFormHandler {
|
|
1031 |
$entities = $section;
|
1032 |
unset( $entities['title'] );
|
1033 |
$count = 0;
|
1034 |
-
$row_span = count( $entities );
|
1035 |
foreach ( $entities as $entity ) {
|
1036 |
?>
|
1037 |
<tr>
|
@@ -1073,15 +1095,15 @@ class RTMediaFormHandler {
|
|
1073 |
$options = $rtmedia->options;
|
1074 |
|
1075 |
$render_jpeg_image_quality = array(
|
1076 |
-
'title'
|
1077 |
-
'callback'
|
1078 |
-
'args'
|
1079 |
-
'key'
|
1080 |
-
'value'
|
1081 |
-
'class'
|
1082 |
-
'desc'
|
1083 |
-
'min'
|
1084 |
-
'max'
|
1085 |
),
|
1086 |
);
|
1087 |
?>
|
@@ -1099,8 +1121,6 @@ class RTMediaFormHandler {
|
|
1099 |
*
|
1100 |
* @access static
|
1101 |
*
|
1102 |
-
* @param void
|
1103 |
-
*
|
1104 |
* @return void
|
1105 |
*/
|
1106 |
public static function custom_css_content() {
|
@@ -1119,31 +1139,31 @@ class RTMediaFormHandler {
|
|
1119 |
*
|
1120 |
* @access static
|
1121 |
*
|
1122 |
-
* @param array $options
|
1123 |
*
|
1124 |
* @return array $render
|
1125 |
*/
|
1126 |
-
static function custom_css_render_options( $options ) {
|
1127 |
$render = array(
|
1128 |
'disable_styles' => array(
|
1129 |
-
'title'
|
1130 |
-
'callback'
|
1131 |
-
'args'
|
1132 |
-
'id'
|
1133 |
-
'key'
|
1134 |
-
'value'
|
1135 |
-
'desc'
|
1136 |
),
|
1137 |
'group' => 10,
|
1138 |
),
|
1139 |
'custom_styles' => array(
|
1140 |
-
'title'
|
1141 |
-
'callback'
|
1142 |
-
'args'
|
1143 |
-
'id'
|
1144 |
-
'key'
|
1145 |
-
'value'
|
1146 |
-
'desc'
|
1147 |
),
|
1148 |
'group' => 10,
|
1149 |
),
|
@@ -1157,48 +1177,48 @@ class RTMediaFormHandler {
|
|
1157 |
*
|
1158 |
* @access static
|
1159 |
*
|
1160 |
-
* @param array $options
|
1161 |
*
|
1162 |
* @return array $render
|
1163 |
*/
|
1164 |
-
static function privacy_render_options( $options ) {
|
1165 |
global $rtmedia;
|
1166 |
|
1167 |
$render = array(
|
1168 |
'enable' => array(
|
1169 |
-
'title'
|
1170 |
-
'callback'
|
1171 |
-
'args'
|
1172 |
-
'id'
|
1173 |
-
'key'
|
1174 |
-
'value'
|
1175 |
-
'desc'
|
1176 |
),
|
1177 |
'group' => 10,
|
1178 |
),
|
1179 |
'default' => array(
|
1180 |
-
'title'
|
1181 |
-
'callback'
|
1182 |
-
'args'
|
1183 |
-
'key'
|
1184 |
-
'radios'
|
1185 |
-
'default'
|
1186 |
-
'desc'
|
1187 |
),
|
1188 |
'group' => 10,
|
1189 |
'depends' => 'privacy_enabled',
|
1190 |
),
|
1191 |
'user_override' => array(
|
1192 |
-
'title'
|
1193 |
-
'callback'
|
1194 |
-
'args'
|
1195 |
-
'key'
|
1196 |
-
'value'
|
1197 |
-
'desc'
|
1198 |
),
|
1199 |
-
'group'
|
1200 |
-
'depends'
|
1201 |
-
'after_content'
|
1202 |
),
|
1203 |
);
|
1204 |
|
@@ -1210,20 +1230,18 @@ class RTMediaFormHandler {
|
|
1210 |
*
|
1211 |
* @access static
|
1212 |
*
|
1213 |
-
* @param void
|
1214 |
-
*
|
1215 |
* @return void
|
1216 |
*/
|
1217 |
public static function privacy_content() {
|
1218 |
global $rtmedia;
|
1219 |
|
1220 |
-
$general_group
|
1221 |
-
$general_group[10]
|
1222 |
-
$general_group
|
1223 |
|
1224 |
-
$options
|
1225 |
-
$render_options
|
1226 |
-
$render_options
|
1227 |
|
1228 |
self::render_tab_content( $render_options, $general_group, 10 );
|
1229 |
}
|
@@ -1233,11 +1251,11 @@ class RTMediaFormHandler {
|
|
1233 |
*
|
1234 |
* @access static
|
1235 |
*
|
1236 |
-
* @param array $options
|
1237 |
*
|
1238 |
* @return array $render
|
1239 |
*/
|
1240 |
-
static function buddypress_render_options( $options ) {
|
1241 |
$render = array(
|
1242 |
'rtmedia-enable-on-profile' => array(
|
1243 |
'title' => esc_html__( 'Enable media in profile', 'buddypress-media' ),
|
@@ -1373,8 +1391,6 @@ class RTMediaFormHandler {
|
|
1373 |
*
|
1374 |
* @access static
|
1375 |
*
|
1376 |
-
* @param void
|
1377 |
-
*
|
1378 |
* @return void
|
1379 |
*/
|
1380 |
public static function buddypress_content() {
|
@@ -1389,11 +1405,11 @@ class RTMediaFormHandler {
|
|
1389 |
$render_options = self::buddypress_render_options( $rtmedia->options );
|
1390 |
// Change option description when 'Activity Streams' component is disabled.
|
1391 |
if ( ! bp_is_active( 'activity' ) ) {
|
1392 |
-
$
|
1393 |
-
$render_options['rtmedia-
|
1394 |
-
$render_options['rtmedia-
|
1395 |
-
$render_options['rtmedia-enable-
|
1396 |
-
|
1397 |
}
|
1398 |
|
1399 |
// Change option description when 'User Groups' component is disabled.
|
@@ -1411,7 +1427,7 @@ class RTMediaFormHandler {
|
|
1411 |
/**
|
1412 |
* Disable inputs and change background color to differentiate disabled inputs,
|
1413 |
* if 'Activity Streams' component is disabled in BuddyPress Settings.
|
1414 |
-
|
1415 |
if ( ! bp_is_active( 'activity' ) ) {
|
1416 |
?>
|
1417 |
<script>
|
@@ -1441,12 +1457,12 @@ class RTMediaFormHandler {
|
|
1441 |
*
|
1442 |
* @access static
|
1443 |
*
|
1444 |
-
* @param string
|
1445 |
-
* @param array
|
1446 |
*
|
1447 |
* @return void
|
1448 |
*/
|
1449 |
-
public static function rtForm_settings_tabs_content( $page, $sub_tabs ) {
|
1450 |
$args = array(
|
1451 |
'wrapper_class' => array(
|
1452 |
'rtm-settings-tab-container',
|
@@ -1456,16 +1472,16 @@ class RTMediaFormHandler {
|
|
1456 |
}
|
1457 |
|
1458 |
/**
|
1459 |
-
*
|
1460 |
*
|
1461 |
* @access static
|
1462 |
*
|
1463 |
-
* @param string $page
|
1464 |
-
* @param string $section
|
1465 |
*
|
1466 |
* @return void
|
1467 |
*/
|
1468 |
-
public static function rtForm_do_settings_fields( $page, $section ) {
|
1469 |
global $wp_settings_fields;
|
1470 |
|
1471 |
if ( ! isset( $wp_settings_fields ) || ! isset( $wp_settings_fields[ $page ] ) || ! isset( $wp_settings_fields[ $page ][ $section ] ) ) {
|
@@ -1490,14 +1506,13 @@ class RTMediaFormHandler {
|
|
1490 |
}
|
1491 |
}
|
1492 |
|
1493 |
-
|
1494 |
-
*
|
1495 |
*
|
1496 |
-
* @param array $
|
1497 |
-
* @param array $groups
|
1498 |
-
* @param int
|
1499 |
*/
|
1500 |
-
|
1501 |
public static function render_tab_content( $options, $groups = array(), $default_group = 0 ) {
|
1502 |
if ( ! empty( $groups ) ) {
|
1503 |
foreach ( $groups as $key => $value ) {
|
@@ -1532,36 +1547,40 @@ class RTMediaFormHandler {
|
|
1532 |
}
|
1533 |
}
|
1534 |
|
1535 |
-
|
1536 |
-
*
|
1537 |
*
|
1538 |
-
* @param string $group
|
1539 |
*/
|
1540 |
-
|
1541 |
public static function render_option_group( $group ) {
|
1542 |
?>
|
1543 |
<h3 class="rtm-option-title"><?php echo esc_html( $group ); ?></h3>
|
1544 |
<?php
|
1545 |
}
|
1546 |
|
1547 |
-
|
1548 |
-
*
|
1549 |
-
*
|
|
|
1550 |
*/
|
1551 |
-
|
1552 |
public static function render_option_content( $option ) {
|
1553 |
?>
|
1554 |
|
1555 |
-
<table class="form-table" <?php
|
1556 |
<tr>
|
1557 |
<th>
|
1558 |
-
<?php
|
1559 |
-
|
1560 |
-
|
1561 |
-
|
1562 |
-
'
|
1563 |
-
|
1564 |
-
|
|
|
|
|
|
|
|
|
|
|
1565 |
</th>
|
1566 |
<td>
|
1567 |
<fieldset>
|
@@ -1570,13 +1589,18 @@ class RTMediaFormHandler {
|
|
1570 |
<span class="rtm-tooltip">
|
1571 |
<i class="dashicons dashicons-info"></i>
|
1572 |
<span class="rtm-tip">
|
1573 |
-
<?php
|
1574 |
-
|
1575 |
-
|
1576 |
-
|
1577 |
-
'
|
1578 |
-
|
1579 |
-
|
|
|
|
|
|
|
|
|
|
|
1580 |
</span>
|
1581 |
</span>
|
1582 |
</fieldset>
|
@@ -1589,14 +1613,17 @@ class RTMediaFormHandler {
|
|
1589 |
?>
|
1590 |
<div class="rtm-message rtm-notice">
|
1591 |
<?php
|
1592 |
-
echo wp_kses(
|
1593 |
-
'
|
1594 |
-
|
1595 |
-
'
|
1596 |
-
|
1597 |
-
|
1598 |
-
|
1599 |
-
|
|
|
|
|
|
|
1600 |
?>
|
1601 |
</div>
|
1602 |
<?php
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* Display different type of form elements
|
4 |
+
*
|
5 |
+
* @package rtMedia
|
6 |
+
* @subpackage Admin
|
7 |
*/
|
8 |
|
9 |
/**
|
10 |
+
* Class for different form elements display.
|
11 |
*
|
12 |
* @author udit
|
13 |
*/
|
14 |
class RTMediaFormHandler {
|
15 |
|
16 |
+
/**
|
17 |
+
* Show Select box.
|
18 |
+
*
|
19 |
+
* @param array $args Arguments to display selectbox.
|
20 |
+
*/
|
21 |
+
public static function selectBox( $args ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid
|
22 |
$defaults = array(
|
23 |
'key' => '',
|
24 |
'desc' => '',
|
27 |
'selects' => array(),
|
28 |
);
|
29 |
$args = wp_parse_args( $args, $defaults );
|
|
|
30 |
|
31 |
+
if ( ! empty( $args['key'] ) ) {
|
32 |
+
$args['name'] = 'rtmedia-options[' . $args['key'] . ']';
|
33 |
}
|
34 |
|
35 |
$args['rtForm_options'] = array();
|
36 |
+
if ( ! empty( $args['selects'] ) ) {
|
37 |
+
foreach ( $args['selects'] as $value => $key ) {
|
38 |
$args['rtForm_options'][] = array(
|
39 |
$key => $value,
|
40 |
+
'selected' => ( $args['default'] === $value ) ? true : false,
|
41 |
);
|
42 |
}
|
43 |
}
|
44 |
|
45 |
+
$chk_obj = new rtForm();
|
46 |
+
$chk_obj->display_select( $args );
|
47 |
}
|
48 |
|
49 |
/**
|
50 |
+
* Show rtMedia textarea in admin options.
|
51 |
*
|
52 |
* @access static
|
53 |
*
|
54 |
+
* @param array $args arguments to display textarea.
|
55 |
+
* @param bool $echo Do echo or not.
|
56 |
*
|
57 |
+
* @return string $chk_obj->get_textarea( $args )
|
58 |
*/
|
59 |
public static function textarea( $args, $echo = true ) {
|
60 |
$defaults = array(
|
63 |
'show_desc' => false,
|
64 |
);
|
65 |
$args = wp_parse_args( $args, $defaults );
|
|
|
66 |
|
67 |
+
if ( ! isset( $args['value'] ) ) {
|
68 |
+
trigger_error( esc_html__( 'Please provide a "value" in the argument.', 'buddypress-media' ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error
|
69 |
|
70 |
+
return '';
|
71 |
}
|
72 |
|
73 |
+
if ( ! empty( $args['key'] ) ) {
|
74 |
+
$args['name'] = 'rtmedia-options[' . $args['key'] . ']';
|
75 |
}
|
76 |
|
77 |
+
$args['rtForm_options'] = array(
|
78 |
+
array(
|
79 |
+
'' => 1,
|
80 |
+
'checked' => $args['value'],
|
81 |
+
),
|
82 |
+
);
|
83 |
|
84 |
+
$chk_obj = new rtForm();
|
85 |
|
86 |
if ( $echo ) {
|
87 |
+
$chk_obj->display_textarea( $args );
|
88 |
} else {
|
89 |
+
return $chk_obj->get_textarea( $args );
|
90 |
}
|
91 |
+
|
92 |
+
return '';
|
93 |
}
|
94 |
|
95 |
/**
|
96 |
+
* Show rtMedia checkbox in admin options.
|
97 |
*
|
98 |
* @access static
|
99 |
*
|
100 |
+
* @param array $args arguments to display checkbox.
|
101 |
+
* @param bool $echo Do echo or not.
|
102 |
*
|
103 |
+
* @return string $chk_obj->get_switch( $args )
|
104 |
*/
|
105 |
public static function checkbox( $args, $echo = true ) {
|
106 |
$defaults = array(
|
109 |
'show_desc' => false,
|
110 |
);
|
111 |
$args = wp_parse_args( $args, $defaults );
|
|
|
112 |
|
113 |
+
if ( ! isset( $args['value'] ) ) {
|
114 |
+
trigger_error( esc_html__( 'Please provide a "value" in the argument.', 'buddypress-media' ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error
|
115 |
|
116 |
return;
|
117 |
}
|
118 |
|
119 |
+
if ( ! empty( $args['key'] ) ) {
|
120 |
+
$args['name'] = 'rtmedia-options[' . $args['key'] . ']';
|
121 |
}
|
122 |
|
123 |
+
$args['rtForm_options'] = array(
|
124 |
+
array(
|
125 |
+
'' => 1,
|
126 |
+
'checked' => $args['value'],
|
127 |
+
),
|
128 |
+
);
|
129 |
|
130 |
+
$chk_obj = new rtForm();
|
131 |
|
132 |
if ( $echo ) {
|
133 |
+
$chk_obj->display_switch( $args );
|
134 |
} else {
|
135 |
+
return $chk_obj->get_switch( $args );
|
136 |
}
|
137 |
+
|
138 |
+
return '';
|
139 |
}
|
140 |
|
141 |
/**
|
142 |
+
* Show rtMedia radio in admin options.
|
143 |
*
|
144 |
* @access static
|
145 |
*
|
146 |
+
* @param array $args Arguments to show radio buttons.
|
147 |
*
|
148 |
* @return void
|
149 |
*/
|
155 |
'show_desc' => false,
|
156 |
);
|
157 |
$args = wp_parse_args( $args, $defaults );
|
|
|
158 |
|
159 |
+
if ( 2 > count( $args['radios'] ) ) {
|
160 |
+
trigger_error( esc_html__( 'Need to specify atleast two radios, else use a checkbox instead', 'buddypress-media' ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error
|
161 |
|
162 |
return;
|
163 |
}
|
164 |
|
165 |
+
if ( ! empty( $args['key'] ) ) {
|
166 |
+
$args['name'] = 'rtmedia-options[' . $args['key'] . ']';
|
167 |
}
|
168 |
|
169 |
$args['rtForm_options'] = array();
|
170 |
+
foreach ( $args['radios'] as $value => $key ) {
|
171 |
$args['rtForm_options'][] = array(
|
172 |
$key => $value,
|
173 |
+
// The function 'strval()' is used to fix the privacy levels being integer to match the saved privacy value.
|
174 |
+
'checked' => ( strval( $args['default'] ) === strval( $value ) ) ? true : false,
|
175 |
);
|
176 |
}
|
177 |
|
178 |
+
$obj_rad = new rtForm();
|
179 |
+
$obj_rad->display_radio( $args );
|
180 |
}
|
181 |
|
182 |
/**
|
183 |
+
* Show rtMedia dimensions in admin options.
|
184 |
+
*
|
185 |
+
* @param array $args Arguments.
|
186 |
*
|
187 |
* @access static
|
188 |
+
*
|
189 |
* @return void
|
190 |
*/
|
191 |
public static function dimensions( $args ) {
|
192 |
+
$dmn_obj = new rtDimensions();
|
193 |
+
$dmn_obj->display_dimensions( $args );
|
194 |
}
|
195 |
|
196 |
/**
|
198 |
*
|
199 |
* @access static
|
200 |
*
|
201 |
+
* @param array $args arguments show numbers options.
|
202 |
*
|
203 |
* @return void
|
204 |
*/
|
205 |
public static function number( $args ) {
|
206 |
+
|
207 |
global $rtmedia;
|
208 |
+
|
209 |
$options = $rtmedia->options;
|
210 |
$defaults = array(
|
211 |
'key' => '',
|
212 |
'desc' => '',
|
213 |
);
|
214 |
$args = wp_parse_args( $args, $defaults );
|
|
|
215 |
|
216 |
+
if ( ! isset( $args['value'] ) ) {
|
217 |
+
trigger_error( esc_html__( 'Please provide a "value" in the argument.', 'buddypress-media' ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error
|
218 |
|
219 |
return;
|
220 |
}
|
221 |
|
222 |
+
if ( ! empty( $args['key'] ) ) {
|
223 |
+
$args['name'] = 'rtmedia-options[' . $args['key'] . ']';
|
224 |
}
|
225 |
|
226 |
+
$num_obj = new rtForm();
|
227 |
+
$num_obj->display_number( $args );
|
|
|
|
|
228 |
}
|
229 |
|
230 |
/**
|
232 |
*
|
233 |
* @access static
|
234 |
*
|
235 |
+
* @param array $args arguments to create textbox.
|
236 |
*
|
237 |
* @return void
|
238 |
*/
|
244 |
'desc' => '',
|
245 |
);
|
246 |
$args = wp_parse_args( $args, $defaults );
|
|
|
247 |
|
248 |
+
if ( ! isset( $args['value'] ) ) {
|
249 |
+
trigger_error( esc_html__( 'Please provide a "value" in the argument.', 'buddypress-media' ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error
|
250 |
|
251 |
return;
|
252 |
}
|
253 |
|
254 |
+
if ( ! empty( $args['key'] ) ) {
|
255 |
+
$args['name'] = 'rtmedia-options[' . $args['key'] . ']';
|
256 |
}
|
257 |
|
258 |
+
$num_obj = new rtForm();
|
259 |
+
$num_obj->display_textbox( $args );
|
|
|
|
|
260 |
}
|
261 |
|
262 |
/**
|
264 |
*
|
265 |
* @access static
|
266 |
*
|
267 |
+
* @param array $args arguments to create link.
|
268 |
+
* @param bool $echo Echo or not.
|
269 |
*
|
270 |
+
* @return string $link_obj
|
271 |
+
*
|
272 |
+
* @throws rtFormInvalidArgumentsException Invalid argument exception.
|
273 |
*/
|
274 |
public static function link( $args, $echo = true ) {
|
275 |
|
280 |
'desc' => '',
|
281 |
);
|
282 |
$args = wp_parse_args( $args, $defaults );
|
|
|
283 |
|
284 |
+
if ( ! isset( $args['href'] ) ) {
|
285 |
+
trigger_error( esc_html__( 'Please provide a "href" in the argument.', 'buddypress-media' ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error
|
286 |
|
287 |
+
return '';
|
288 |
}
|
289 |
|
290 |
+
if ( ! isset( $args['text'] ) ) {
|
291 |
+
trigger_error( esc_html__( 'Please provide a "text" in the argument.', 'buddypress-media' ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error
|
292 |
|
293 |
+
return '';
|
294 |
}
|
295 |
|
296 |
+
if ( isset( $args['target'] ) && ! empty( $args['target'] ) ) {
|
297 |
+
$args['misc'] = array( 'target' => $args['target'] );
|
298 |
}
|
299 |
|
300 |
+
$link_obj = new rtForm();
|
301 |
|
302 |
if ( $echo ) {
|
303 |
|
304 |
+
$link_obj->display_link( $args );
|
305 |
} else {
|
306 |
|
307 |
+
return $link_obj->get_link( $args );
|
308 |
}
|
309 |
}
|
310 |
|
318 |
* @param array $args arguments to create button.
|
319 |
*
|
320 |
* @return void
|
321 |
+
*
|
322 |
+
* @throws rtFormInvalidArgumentsException Invalid argument exception.
|
323 |
*/
|
324 |
public static function button( $args ) {
|
325 |
$defaults = array(
|
329 |
$args = wp_parse_args( $args, $defaults );
|
330 |
|
331 |
if ( empty( $args['value'] ) ) {
|
332 |
+
trigger_error( esc_html__( 'Please provide a "value" in the argument.', 'buddypress-media' ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error
|
333 |
|
334 |
return;
|
335 |
}
|
336 |
|
337 |
+
$button_obj = new rtForm();
|
338 |
+
$button_obj->display_button( $args );
|
339 |
}
|
340 |
|
341 |
/**
|
349 |
*
|
350 |
* @return void
|
351 |
*
|
352 |
+
* @throws rtFormInvalidArgumentsException Invalid argument exception.
|
353 |
*/
|
354 |
public static function fileinput( $args ) {
|
355 |
$defaults = array(
|
359 |
$args = wp_parse_args( $args, $defaults );
|
360 |
|
361 |
if ( empty( $args['value'] ) ) {
|
362 |
+
trigger_error( esc_html__( 'Please provide a "value" in the argument.', 'buddypress-media' ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error
|
363 |
|
364 |
return;
|
365 |
}
|
366 |
|
367 |
+
$file_obj = new rtForm();
|
368 |
+
$file_obj->display_file_input( $args );
|
369 |
}
|
370 |
|
371 |
/**
|
376 |
* @param array $args Arguments to create file input control for default thumbnail generator settings.
|
377 |
*
|
378 |
* @return void
|
379 |
+
*
|
380 |
+
* @throws rtFormInvalidArgumentsException Invalid argument exception.
|
381 |
*/
|
382 |
public static function inputfile( $args ) {
|
383 |
global $rtmedia;
|
394 |
$args['name'] = $args['key'];
|
395 |
}
|
396 |
|
|
|
|
|
397 |
$num_obj = new rtForm();
|
398 |
$num_obj->display_inputfile( $args );
|
399 |
}
|
400 |
|
401 |
|
402 |
/**
|
403 |
+
* Extract settings.
|
404 |
*
|
405 |
* @access static
|
406 |
*
|
407 |
+
* @param string $section_name Section name.
|
408 |
+
* @param array $options Options array.
|
409 |
*
|
410 |
* @return array $section
|
411 |
*/
|
412 |
+
public static function extract_settings( $section_name, $options ) {
|
413 |
$section = array();
|
414 |
foreach ( $options as $key => $value ) {
|
415 |
$compare = strncmp( $key, $section_name, strlen( $section_name ) );
|
422 |
}
|
423 |
|
424 |
/**
|
425 |
+
* Display render options.
|
426 |
*
|
427 |
* @access static
|
428 |
*
|
429 |
+
* @param array $options Options array.
|
430 |
*
|
431 |
* @return array $render
|
432 |
*/
|
433 |
+
public static function display_render_options( $options ) {
|
434 |
$radios = array();
|
435 |
$radios['load_more'] = '<strong>' . esc_html__( 'Load More', 'buddypress-media' ) . '</strong>';
|
436 |
$radios['pagination'] = '<strong>' . esc_html__( 'Pagination', 'buddypress-media' ) . '</strong>';
|
444 |
}
|
445 |
|
446 |
$render = array(
|
447 |
+
'general_enableComments' => array(
|
448 |
'title' => esc_html__( 'Allow user to comment on uploaded media', 'buddypress-media' ),
|
449 |
'callback' => array( 'RTMediaFormHandler', 'checkbox' ),
|
450 |
'args' => array(
|
454 |
),
|
455 |
'group' => '10',
|
456 |
),
|
457 |
+
'general_enableGallerysearch' => array(
|
458 |
+
'title' => esc_html__( 'Enable gallery media search', 'buddypress-media' ),
|
459 |
'callback' => array( 'RTMediaFormHandler', 'checkbox' ),
|
460 |
+
'args' => array(
|
461 |
+
'key' => 'general_enableGallerysearch',
|
462 |
'value' => $options['general_enableGallerysearch'],
|
463 |
+
'desc' => esc_html__( 'This will enable the search box in gallery page.', 'buddypress-media' ),
|
464 |
),
|
465 |
+
'group' => '14',
|
466 |
),
|
467 |
+
'general_enableLikes' => array(
|
468 |
'title' => __( 'Enable likes for media', 'buddypress-media' ),
|
469 |
'callback' => array( 'RTMediaFormHandler', 'checkbox' ),
|
470 |
+
'args' => array(
|
471 |
+
'key' => 'general_enableLikes',
|
472 |
'value' => $options['general_enableLikes'],
|
473 |
+
'desc' => __( 'Enabling this setting will add like feature for media.', 'buddypress-media' ),
|
474 |
),
|
475 |
+
'group' => '11',
|
476 |
),
|
477 |
+
'general_enableLightbox' => array(
|
478 |
'title' => esc_html__( 'Use lightbox to display media', 'buddypress-media' ),
|
479 |
'callback' => array( 'RTMediaFormHandler', 'checkbox' ),
|
480 |
'args' => array(
|
484 |
),
|
485 |
'group' => '15',
|
486 |
),
|
487 |
+
'general_perPageMedia' => array(
|
488 |
'title' => esc_html__( 'Number of media per page', 'buddypress-media' ),
|
489 |
'callback' => array( 'RTMediaFormHandler', 'number' ),
|
490 |
'args' => array(
|
496 |
),
|
497 |
'group' => '15',
|
498 |
),
|
499 |
+
'general_display_media' => array(
|
500 |
'title' => esc_html__( 'Media display pagination option', 'buddypress-media' ),
|
501 |
'callback' => array( 'RTMediaFormHandler', 'radio' ),
|
502 |
'args' => array(
|
508 |
),
|
509 |
'group' => '15',
|
510 |
),
|
511 |
+
'general_masonry_layout' => array(
|
512 |
'title' => esc_html__( 'Enable', 'buddypress-media' ) . ' <a href="http://masonry.desandro.com/" target="_blank">Masonry</a> ' . esc_html__( 'Cascading grid layout', 'buddypress-media' ),
|
513 |
'callback' => array( 'RTMediaFormHandler', 'checkbox' ),
|
514 |
'args' => array(
|
521 |
'after_content' => esc_html__( 'You might need to', 'buddypress-media' ) . ' <a id="rtm-masonry-change-thumbnail-info" href="' . get_admin_url() . 'admin.php?page=rtmedia-settings#rtmedia-sizes">' . esc_html__( 'change thumbnail size', 'buddypress-media' ) . '</a> ' . esc_html__( 'and uncheck the crop box for thumbnails.', 'buddypress-media' ) . '<br /><br />' . esc_html__( 'To set gallery for fixed width, set image height to 0 and width as per your requirement and vice-versa.', 'buddypress-media' ),
|
522 |
),
|
523 |
'general_masonry_layout_activity' => array(
|
524 |
+
'title' => esc_html__( 'Enable Masonry Cascading grid layout for activity', 'buddypress-media' ),
|
525 |
+
'callback' => array( 'RTMediaFormHandler', 'checkbox' ),
|
526 |
+
'args' => array(
|
527 |
'key' => 'general_masonry_layout_activity',
|
528 |
'value' => $options['general_masonry_layout_activity'],
|
529 |
'desc' => esc_html__( 'If you enable masonry view, it is advisable to', 'buddypress-media' ) . ' <a href="' . $regenerate_link . '">regenerate thumbnail</a> ' . esc_html__( 'for masonry view.', 'buddypress-media' ),
|
530 |
'class' => array( 'rtm_enable_masonry_view' ),
|
531 |
),
|
532 |
+
'depends' => 'general_masonry_layout',
|
533 |
+
'group' => '18',
|
534 |
),
|
535 |
+
'general_direct_upload' => array(
|
536 |
'title' => esc_html__( 'Enable Direct Upload', 'buddypress-media' ),
|
537 |
'callback' => array( 'RTMediaFormHandler', 'checkbox' ),
|
538 |
'args' => array(
|
553 |
}
|
554 |
|
555 |
/**
|
556 |
+
* Display content.
|
557 |
*
|
558 |
* @access static
|
559 |
*
|
|
|
|
|
560 |
* @return void
|
561 |
*/
|
562 |
public static function display_content() {
|
563 |
global $rtmedia;
|
564 |
+
$options = $rtmedia->options;
|
565 |
+
$render_options = self::display_render_options( $options );
|
566 |
+
$render_options = apply_filters( 'rtmedia_display_content_add_itmes', $render_options, $options );
|
567 |
+
$general_group = array();
|
568 |
+
$general_group[10] = esc_html__( 'Single Media View', 'buddypress-media' );
|
569 |
+
$general_group[11] = esc_html__( 'Media Likes', 'buddypress-media' );
|
570 |
+
$general_group[15] = esc_html__( 'List Media View', 'buddypress-media' );
|
571 |
+
$general_group[18] = esc_html__( 'Masonry View', 'buddypress-media' );
|
572 |
+
$general_group[19] = esc_html__( 'Direct Upload', 'buddypress-media' );
|
573 |
+
$general_group[14] = esc_html__( 'Gallery Media Search', 'buddypress-media' );
|
574 |
+
$general_group = apply_filters( 'rtmedia_display_content_groups', $general_group );
|
575 |
ksort( $general_group );
|
576 |
self::render_tab_content( $render_options, $general_group, 20 );
|
577 |
}
|
578 |
|
579 |
/**
|
580 |
+
* Render general content.
|
581 |
*
|
582 |
* @access static
|
583 |
*
|
584 |
+
* @param array $options General options.
|
585 |
*
|
586 |
* @return array $render
|
587 |
*/
|
588 |
+
public static function render_general_content( $options ) {
|
589 |
$render = array(
|
590 |
'general_AllowUserData' => array(
|
591 |
'title' => esc_html__( 'Allow usage data tracking', 'buddypress-media' ),
|
605 |
'desc' => esc_html__( 'Add rtMedia menu to WordPress admin bar for easy access to settings and moderation page (if enabled).', 'buddypress-media' ),
|
606 |
),
|
607 |
'group' => 10,
|
608 |
+
),
|
609 |
'rtmedia_add_linkback' => array(
|
610 |
'title' => esc_html__( 'Add a link to rtMedia in footer', 'buddypress-media' ),
|
611 |
'callback' => array( 'RTMediaFormHandler', 'checkbox' ),
|
615 |
'desc' => esc_html__( 'Help us promote rtMedia.', 'buddypress-media' ),
|
616 |
),
|
617 |
'group' => 100,
|
618 |
+
),
|
619 |
'rtmedia_enable_api' => array(
|
620 |
'title' => esc_html__( 'Enable JSON API', 'buddypress-media' ),
|
621 |
'callback' => array( 'RTMediaFormHandler', 'checkbox' ),
|
626 |
),
|
627 |
'group' => 80,
|
628 |
'after_content' => esc_html__( 'You can refer to the API document from', 'buddypress-media' ) . ' <a href="https://rtmedia.io/docs/developers/json-api/">' . esc_html__( 'here', 'buddypress-media' ) . '</a>',
|
629 |
+
),
|
630 |
);
|
631 |
|
632 |
return $render;
|
639 |
*
|
640 |
* @return void
|
641 |
*/
|
642 |
+
public static function general_content() {
|
643 |
global $rtmedia;
|
644 |
$options = $rtmedia->options;
|
645 |
$render_options = self::render_general_content( $options );
|
655 |
}
|
656 |
|
657 |
/**
|
658 |
+
* Render export import.
|
659 |
*
|
660 |
* @access public
|
661 |
*
|
663 |
*
|
664 |
* @return array $render
|
665 |
*/
|
666 |
+
public static function render_export_import() {
|
667 |
$render = array(
|
668 |
+
'rtmedia_export_settings' => array(
|
669 |
'title' => esc_html__( 'Export rtMedia Settings', 'buddypress-media' ),
|
670 |
'callback' => array( 'RTMediaFormHandler', 'button' ),
|
671 |
'args' => array(
|
677 |
),
|
678 |
'group' => 10,
|
679 |
),
|
680 |
+
'rtmedia_import_settings' => array(
|
681 |
'title' => esc_html__( 'Import rtMedia Settings', 'buddypress-media' ),
|
682 |
'callback' => array( 'RTMediaFormHandler', 'fileinput' ),
|
683 |
'args' => array(
|
701 |
),
|
702 |
'group' => 11,
|
703 |
),
|
704 |
+
'rtmedia_erase_personal_data' => array(
|
705 |
+
'title' => esc_html__( 'Erase your personal data', 'buddypress-media' ),
|
706 |
+
'callback' => array( 'RTMediaFormHandler', 'button' ),
|
707 |
+
'args' => array(
|
708 |
'id' => 'rtm-erase-data-button',
|
709 |
'key' => 'rtm-erase-data-button',
|
710 |
'value' => esc_html__( 'Erase Data', 'buddypress-media' ),
|
711 |
'desc' => esc_html__( 'This will erase your personal data.', 'buddypress-media' ),
|
712 |
'class' => array( 'button', 'button-primary', 'button-small' ),
|
713 |
),
|
714 |
+
'group' => 11,
|
715 |
'after_content' => esc_html__( 'Data will be expoted or erased along with wordpress user data.', 'buddypress-media' ),
|
716 |
),
|
717 |
);
|
729 |
*
|
730 |
* @return void
|
731 |
*/
|
732 |
+
public static function rtm_export_import() {
|
733 |
|
734 |
global $rtmedia;
|
735 |
$render_options = self::render_export_import();
|
759 |
*
|
760 |
* @access static
|
761 |
*
|
762 |
+
* @param array $allowed_types allowed types.
|
763 |
+
* @param string $key Key.
|
764 |
*
|
765 |
+
* @return array|bool $data
|
766 |
*/
|
767 |
+
public static function get_type_details( $allowed_types, $key ) {
|
768 |
foreach ( $allowed_types as $type ) {
|
769 |
if ( $type['name'] === $key ) {
|
770 |
$data = array(
|
786 |
*
|
787 |
* @access static
|
788 |
*
|
789 |
+
* @param array $options options array to render.
|
790 |
*
|
791 |
* @return array $render
|
792 |
*/
|
793 |
+
public static function types_render_options( $options ) {
|
794 |
$render = array();
|
795 |
$allowed_media_type = rtmedia_get_allowed_types();
|
796 |
|
814 |
*
|
815 |
* @access static
|
816 |
*
|
|
|
|
|
817 |
* @return void
|
818 |
*/
|
819 |
public static function types_content() {
|
834 |
<?php do_action( 'rtmedia_type_settings_before_heading' ); ?>
|
835 |
|
836 |
<tr>
|
837 |
+
<th>
|
838 |
+
<strong><?php esc_html_e( 'Media Type', 'buddypress-media' ); ?></strong>
|
839 |
+
</th>
|
840 |
|
841 |
<th>
|
842 |
|
858 |
</span>
|
859 |
</th>
|
860 |
|
861 |
+
<?php do_action( 'rtmedia_type_setting_columns_title' ); ?>
|
862 |
</tr>
|
863 |
|
864 |
<?php
|
868 |
if ( isset( $section['settings_visibility'] ) && true === $section['settings_visibility'] ) {
|
869 |
do_action( 'rtmedia_type_settings_before_body' );
|
870 |
|
871 |
+
// allow upload.
|
872 |
$uplaod_args = array(
|
873 |
'key' => 'allowedTypes_' . $key . '_enabled',
|
874 |
'value' => $section['enabled'],
|
875 |
);
|
876 |
+
$allow_upload_checkbox = self::checkbox( $uplaod_args, false );
|
877 |
$allow_upload_checkbox = apply_filters( 'rtmedia_filter_allow_upload_checkbox', $allow_upload_checkbox, $key, $uplaod_args );
|
878 |
|
879 |
+
// allow featured.
|
880 |
$featured_args = array(
|
881 |
+
'key' => 'allowedTypes_' . $key . '_featured',
|
882 |
+
'value' => $section['featured'],
|
883 |
);
|
884 |
+
$featured_checkbox = self::checkbox( $featured_args, false );
|
885 |
$featured_checkbox = apply_filters( 'rtmedia_filter_featured_checkbox', $featured_checkbox, $key );
|
886 |
|
887 |
if ( ! isset( $section['extn'] ) || ! is_array( $section['extn'] ) ) {
|
888 |
$section['extn'] = array();
|
889 |
}
|
890 |
|
891 |
+
$extensions = implode( ', ', $section['extn'] );
|
892 |
?>
|
893 |
|
894 |
<tr>
|
913 |
|
914 |
<td>
|
915 |
<span class="rtm-field-wrap">
|
916 |
+
<?php
|
917 |
+
// escaping done into inner function.
|
918 |
+
echo wp_kses(
|
919 |
+
$allow_upload_checkbox,
|
920 |
+
array(
|
921 |
+
'span' => array(
|
922 |
+
'class' => array(),
|
923 |
+
'data-on' => array(),
|
924 |
+
'data-off' => array(),
|
925 |
+
),
|
926 |
+
'label' => array(
|
927 |
+
'for' => array(),
|
928 |
+
'class' => array(),
|
929 |
+
),
|
930 |
+
'input' => array(
|
931 |
+
'type' => array(),
|
932 |
+
'checked' => array(),
|
933 |
+
'data-toggle' => array(),
|
934 |
+
'id' => array(),
|
935 |
+
'name' => array(),
|
936 |
+
'value' => array(),
|
937 |
+
),
|
938 |
+
)
|
939 |
+
);
|
940 |
?>
|
941 |
</span>
|
942 |
</td>
|
943 |
|
944 |
<td>
|
945 |
+
<?php
|
946 |
+
// escaping done into inner function.
|
947 |
+
echo wp_kses(
|
948 |
+
$featured_checkbox,
|
949 |
+
array(
|
950 |
+
'span' => array(
|
951 |
+
'class' => array(),
|
952 |
+
'data-on' => array(),
|
953 |
+
'data-off' => array(),
|
954 |
+
),
|
955 |
+
'label' => array(
|
956 |
+
'for' => array(),
|
957 |
+
'class' => array(),
|
958 |
+
),
|
959 |
+
'input' => array(
|
960 |
+
'type' => array(),
|
961 |
+
'checked' => array(),
|
962 |
+
'data-toggle' => array(),
|
963 |
+
'id' => array(),
|
964 |
+
'name' => array(),
|
965 |
+
'value' => array(),
|
966 |
+
),
|
967 |
+
)
|
968 |
+
);
|
969 |
?>
|
970 |
</td>
|
971 |
|
972 |
+
<?php do_action( 'rtmedia_type_setting_columns_body', $key, $section ); ?>
|
973 |
</tr>
|
974 |
|
975 |
<?php do_action( 'rtmedia_other_type_settings_textarea', $key ); ?>
|
998 |
*
|
999 |
* @access static
|
1000 |
*
|
1001 |
+
* @param array $options options.
|
1002 |
*
|
1003 |
* @return array $render
|
1004 |
*/
|
1005 |
+
public static function sizes_render_options( $options ) {
|
1006 |
$render = array();
|
1007 |
foreach ( $options as $key => $value ) {
|
1008 |
$data = explode( '_', $key );
|
1009 |
if ( ! isset( $render[ $data[1] ] ) ) {
|
1010 |
$render[ $data[1] ] = array();
|
1011 |
+
$render[ $data[1] ]['title'] = $data[1];
|
1012 |
}
|
1013 |
if ( ! isset( $render[ $data[1] ][ $data[2] ] ) ) {
|
1014 |
$render[ $data[1] ][ $data[2] ] = array();
|
1015 |
+
$render[ $data[1] ][ $data[2] ]['title'] = esc_html( $data[2] );
|
1016 |
}
|
1017 |
|
1018 |
$render[ $data[1] ][ $data[2] ][ $data[3] ] = $value;
|
1022 |
}
|
1023 |
|
1024 |
/**
|
1025 |
+
* Display media sizes table.
|
1026 |
*
|
1027 |
* @access static
|
1028 |
*
|
|
|
|
|
1029 |
* @return void
|
1030 |
*/
|
1031 |
public static function sizes_content() {
|
1041 |
|
1042 |
<table class="form-table">
|
1043 |
<tr>
|
1044 |
+
<th><strong><?php esc_html_e( 'Category', 'buddypress-media' ); ?></strong></th>
|
1045 |
<th><strong><?php esc_html_e( 'Entity', 'buddypress-media' ); ?></strong></th>
|
1046 |
<th><strong><?php esc_html_e( 'Width', 'buddypress-media' ); ?></strong></th>
|
1047 |
<th><strong><?php esc_html_e( 'Height', 'buddypress-media' ); ?></strong></th>
|
1053 |
$entities = $section;
|
1054 |
unset( $entities['title'] );
|
1055 |
$count = 0;
|
1056 |
+
$row_span = count( $entities );
|
1057 |
foreach ( $entities as $entity ) {
|
1058 |
?>
|
1059 |
<tr>
|
1095 |
$options = $rtmedia->options;
|
1096 |
|
1097 |
$render_jpeg_image_quality = array(
|
1098 |
+
'title' => esc_html__( 'JPEG/JPG image quality (1-100)', 'buddypress-media' ),
|
1099 |
+
'callback' => array( 'RTMediaFormHandler', 'number' ),
|
1100 |
+
'args' => array(
|
1101 |
+
'key' => 'general_jpeg_image_quality',
|
1102 |
+
'value' => $options['general_jpeg_image_quality'],
|
1103 |
+
'class' => array( 'rtmedia-setting-text-box' ),
|
1104 |
+
'desc' => esc_html__( 'Enter JPEG/JPG Image Quality. Minimum value is 1. 100 is original quality.', 'buddypress-media' ),
|
1105 |
+
'min' => 1,
|
1106 |
+
'max' => 100,
|
1107 |
),
|
1108 |
);
|
1109 |
?>
|
1121 |
*
|
1122 |
* @access static
|
1123 |
*
|
|
|
|
|
1124 |
* @return void
|
1125 |
*/
|
1126 |
public static function custom_css_content() {
|
1139 |
*
|
1140 |
* @access static
|
1141 |
*
|
1142 |
+
* @param array $options options.
|
1143 |
*
|
1144 |
* @return array $render
|
1145 |
*/
|
1146 |
+
public static function custom_css_render_options( $options ) {
|
1147 |
$render = array(
|
1148 |
'disable_styles' => array(
|
1149 |
+
'title' => esc_html__( 'rtMedia default styles', 'buddypress-media' ),
|
1150 |
+
'callback' => array( 'RTMediaFormHandler', 'checkbox' ),
|
1151 |
+
'args' => array(
|
1152 |
+
'id' => 'rtmedia-disable-styles',
|
1153 |
+
'key' => 'styles_enabled',
|
1154 |
+
'value' => $options['styles_enabled'],
|
1155 |
+
'desc' => esc_html__( 'Load default rtMedia styles. You need to write your own style for rtMedia if you disable it.', 'buddypress-media' ),
|
1156 |
),
|
1157 |
'group' => 10,
|
1158 |
),
|
1159 |
'custom_styles' => array(
|
1160 |
+
'title' => esc_html__( 'Paste your CSS code', 'buddypress-media' ),
|
1161 |
+
'callback' => array( 'RTMediaFormHandler', 'textarea' ),
|
1162 |
+
'args' => array(
|
1163 |
+
'id' => 'rtmedia-custom-css',
|
1164 |
+
'key' => 'styles_custom',
|
1165 |
+
'value' => wp_filter_nohtml_kses( $options['styles_custom'] ),
|
1166 |
+
'desc' => esc_html__( 'Custom rtMedia CSS container', 'buddypress-media' ),
|
1167 |
),
|
1168 |
'group' => 10,
|
1169 |
),
|
1177 |
*
|
1178 |
* @access static
|
1179 |
*
|
1180 |
+
* @param array $options Options array.
|
1181 |
*
|
1182 |
* @return array $render
|
1183 |
*/
|
1184 |
+
public static function privacy_render_options( $options ) {
|
1185 |
global $rtmedia;
|
1186 |
|
1187 |
$render = array(
|
1188 |
'enable' => array(
|
1189 |
+
'title' => esc_html__( 'Enable privacy', 'buddypress-media' ),
|
1190 |
+
'callback' => array( 'RTMediaFormHandler', 'checkbox' ),
|
1191 |
+
'args' => array(
|
1192 |
+
'id' => 'rtmedia-privacy-enable',
|
1193 |
+
'key' => 'privacy_enabled',
|
1194 |
+
'value' => $options['privacy_enabled'],
|
1195 |
+
'desc' => esc_html__( 'Enable privacy in rtMedia', 'buddypress-media' ),
|
1196 |
),
|
1197 |
'group' => 10,
|
1198 |
),
|
1199 |
'default' => array(
|
1200 |
+
'title' => esc_html__( 'Default privacy', 'buddypress-media' ),
|
1201 |
+
'callback' => array( 'RTMediaFormHandler', 'radio' ),
|
1202 |
+
'args' => array(
|
1203 |
+
'key' => 'privacy_default',
|
1204 |
+
'radios' => $rtmedia->privacy_settings['levels'],
|
1205 |
+
'default' => $options['privacy_default'],
|
1206 |
+
'desc' => esc_html__( 'Set default privacy for media', 'buddypress-media' ),
|
1207 |
),
|
1208 |
'group' => 10,
|
1209 |
'depends' => 'privacy_enabled',
|
1210 |
),
|
1211 |
'user_override' => array(
|
1212 |
+
'title' => esc_html__( 'Allow users to set privacy for their content', 'buddypress-media' ),
|
1213 |
+
'callback' => array( 'RTMediaFormHandler', 'checkbox' ),
|
1214 |
+
'args' => array(
|
1215 |
+
'key' => 'privacy_userOverride',
|
1216 |
+
'value' => $options['privacy_userOverride'],
|
1217 |
+
'desc' => esc_html__( 'If you choose this, users will be able to change privacy of their own uploads.', 'buddypress-media' ),
|
1218 |
),
|
1219 |
+
'group' => 10,
|
1220 |
+
'depends' => 'privacy_enabled',
|
1221 |
+
'after_content' => esc_html__( 'For group uploads, BuddyPress groups privacy is used.', 'buddypress-media' ),
|
1222 |
),
|
1223 |
);
|
1224 |
|
1230 |
*
|
1231 |
* @access static
|
1232 |
*
|
|
|
|
|
1233 |
* @return void
|
1234 |
*/
|
1235 |
public static function privacy_content() {
|
1236 |
global $rtmedia;
|
1237 |
|
1238 |
+
$general_group = array();
|
1239 |
+
$general_group[10] = 'Privacy Settings';
|
1240 |
+
$general_group = apply_filters( 'rtmedia_privacy_settings_groups', $general_group );
|
1241 |
|
1242 |
+
$options = self::extract_settings( 'privacy', $rtmedia->options );
|
1243 |
+
$render_options = self::privacy_render_options( $options );
|
1244 |
+
$render_options = apply_filters( 'rtmedia_privacy_settings_options', $render_options );
|
1245 |
|
1246 |
self::render_tab_content( $render_options, $general_group, 10 );
|
1247 |
}
|
1251 |
*
|
1252 |
* @access static
|
1253 |
*
|
1254 |
+
* @param array $options Options.
|
1255 |
*
|
1256 |
* @return array $render
|
1257 |
*/
|
1258 |
+
public static function buddypress_render_options( $options ) {
|
1259 |
$render = array(
|
1260 |
'rtmedia-enable-on-profile' => array(
|
1261 |
'title' => esc_html__( 'Enable media in profile', 'buddypress-media' ),
|
1391 |
*
|
1392 |
* @access static
|
1393 |
*
|
|
|
|
|
1394 |
* @return void
|
1395 |
*/
|
1396 |
public static function buddypress_content() {
|
1405 |
$render_options = self::buddypress_render_options( $rtmedia->options );
|
1406 |
// Change option description when 'Activity Streams' component is disabled.
|
1407 |
if ( ! bp_is_active( 'activity' ) ) {
|
1408 |
+
$desc = esc_html__( 'Please Enable BuddyPress Activity Streams to update option', 'buddypress-media' );
|
1409 |
+
$render_options['rtmedia-enable-on-activity']['args']['desc'] = $desc;
|
1410 |
+
$render_options['rtmedia-activity-feed-limit']['args']['desc'] = $desc;
|
1411 |
+
$render_options['rtmedia-enable-like-activity']['args']['desc'] = $desc;
|
1412 |
+
$render_options['rtmedia-enable-comment-activity']['args']['desc'] = $desc;
|
1413 |
}
|
1414 |
|
1415 |
// Change option description when 'User Groups' component is disabled.
|
1427 |
/**
|
1428 |
* Disable inputs and change background color to differentiate disabled inputs,
|
1429 |
* if 'Activity Streams' component is disabled in BuddyPress Settings.
|
1430 |
+
*/
|
1431 |
if ( ! bp_is_active( 'activity' ) ) {
|
1432 |
?>
|
1433 |
<script>
|
1457 |
*
|
1458 |
* @access static
|
1459 |
*
|
1460 |
+
* @param string $page Page.
|
1461 |
+
* @param array $sub_tabs Subtabs.
|
1462 |
*
|
1463 |
* @return void
|
1464 |
*/
|
1465 |
+
public static function rtForm_settings_tabs_content( $page, $sub_tabs ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid
|
1466 |
$args = array(
|
1467 |
'wrapper_class' => array(
|
1468 |
'rtm-settings-tab-container',
|
1472 |
}
|
1473 |
|
1474 |
/**
|
1475 |
+
* Show settings fields.
|
1476 |
*
|
1477 |
* @access static
|
1478 |
*
|
1479 |
+
* @param string $page Page name.
|
1480 |
+
* @param string $section Section name.
|
1481 |
*
|
1482 |
* @return void
|
1483 |
*/
|
1484 |
+
public static function rtForm_do_settings_fields( $page, $section ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid
|
1485 |
global $wp_settings_fields;
|
1486 |
|
1487 |
if ( ! isset( $wp_settings_fields ) || ! isset( $wp_settings_fields[ $page ] ) || ! isset( $wp_settings_fields[ $page ][ $section ] ) ) {
|
1506 |
}
|
1507 |
}
|
1508 |
|
1509 |
+
/**
|
1510 |
+
* Render each tab content
|
1511 |
*
|
1512 |
+
* @param array $options Existing options.
|
1513 |
+
* @param array $groups Groups array to show data.
|
1514 |
+
* @param int $default_group Default group.
|
1515 |
*/
|
|
|
1516 |
public static function render_tab_content( $options, $groups = array(), $default_group = 0 ) {
|
1517 |
if ( ! empty( $groups ) ) {
|
1518 |
foreach ( $groups as $key => $value ) {
|
1547 |
}
|
1548 |
}
|
1549 |
|
1550 |
+
/**
|
1551 |
+
* Render option group title inside single tab
|
1552 |
*
|
1553 |
+
* @param string $group Group.
|
1554 |
*/
|
|
|
1555 |
public static function render_option_group( $group ) {
|
1556 |
?>
|
1557 |
<h3 class="rtm-option-title"><?php echo esc_html( $group ); ?></h3>
|
1558 |
<?php
|
1559 |
}
|
1560 |
|
1561 |
+
/**
|
1562 |
+
* Render options
|
1563 |
+
*
|
1564 |
+
* @param array $option existing options array.
|
1565 |
*/
|
|
|
1566 |
public static function render_option_content( $option ) {
|
1567 |
?>
|
1568 |
|
1569 |
+
<table class="form-table" <?php echo ( isset( $option['depends'] ) && '' !== $option['depends'] ) ? 'data-depends="' . esc_attr( $option['depends'] ) . '"' : ''; ?> >
|
1570 |
<tr>
|
1571 |
<th>
|
1572 |
+
<?php
|
1573 |
+
echo wp_kses(
|
1574 |
+
$option['title'],
|
1575 |
+
array(
|
1576 |
+
'a' => array(
|
1577 |
+
'id' => array(),
|
1578 |
+
'href' => array(),
|
1579 |
+
'target' => array(),
|
1580 |
+
),
|
1581 |
+
)
|
1582 |
+
);
|
1583 |
+
?>
|
1584 |
</th>
|
1585 |
<td>
|
1586 |
<fieldset>
|
1589 |
<span class="rtm-tooltip">
|
1590 |
<i class="dashicons dashicons-info"></i>
|
1591 |
<span class="rtm-tip">
|
1592 |
+
<?php
|
1593 |
+
echo wp_kses(
|
1594 |
+
( isset( $option['args']['desc'] ) ) ? $option['args']['desc'] : 'NA',
|
1595 |
+
array(
|
1596 |
+
'a' => array(
|
1597 |
+
'id' => array(),
|
1598 |
+
'href' => array(),
|
1599 |
+
'target' => array(),
|
1600 |
+
),
|
1601 |
+
)
|
1602 |
+
);
|
1603 |
+
?>
|
1604 |
</span>
|
1605 |
</span>
|
1606 |
</fieldset>
|
1613 |
?>
|
1614 |
<div class="rtm-message rtm-notice">
|
1615 |
<?php
|
1616 |
+
echo wp_kses(
|
1617 |
+
wpautop( $option['after_content'] ),
|
1618 |
+
array(
|
1619 |
+
'a' => array(
|
1620 |
+
'id' => array(),
|
1621 |
+
'href' => array(),
|
1622 |
+
'target' => array(),
|
1623 |
+
),
|
1624 |
+
'p' => array(),
|
1625 |
+
)
|
1626 |
+
);
|
1627 |
?>
|
1628 |
</div>
|
1629 |
<?php
|
app/admin/RTMediaUploadTermsAdmin.php
CHANGED
@@ -25,6 +25,7 @@ if ( ! class_exists( 'RTMediaUploadTermsAdmin' ) && ! is_plugin_active( 'rtmedia
|
|
25 |
* @var string
|
26 |
*/
|
27 |
public $upload_terms_message;
|
|
|
28 |
/**
|
29 |
* Error message for label on front end side.
|
30 |
*
|
@@ -72,6 +73,7 @@ if ( ! class_exists( 'RTMediaUploadTermsAdmin' ) && ! is_plugin_active( 'rtmedia
|
|
72 |
* Default option value for admin settings
|
73 |
*
|
74 |
* @param array $defaults Default values of rtMedia admin settings.
|
|
|
75 |
* @return array defaults
|
76 |
*/
|
77 |
public function add_admin_option_default_value( $defaults ) {
|
@@ -118,6 +120,7 @@ if ( ! class_exists( 'RTMediaUploadTermsAdmin' ) && ! is_plugin_active( 'rtmedia
|
|
118 |
* Add setting option in rtmedia settings
|
119 |
*
|
120 |
* @param array $general_group Add group message.
|
|
|
121 |
* @return array $general_group
|
122 |
*/
|
123 |
public function admin_setting_add_terms_section( $general_group ) {
|
@@ -131,6 +134,7 @@ if ( ! class_exists( 'RTMediaUploadTermsAdmin' ) && ! is_plugin_active( 'rtmedia
|
|
131 |
*
|
132 |
* @param array $render_options Rendering according to selected options.
|
133 |
* @param array $options Options selected in settings.
|
|
|
134 |
* @return array $render_option
|
135 |
*/
|
136 |
public function admin_setting_add_terms_option( $render_options, $options ) {
|
25 |
* @var string
|
26 |
*/
|
27 |
public $upload_terms_message;
|
28 |
+
|
29 |
/**
|
30 |
* Error message for label on front end side.
|
31 |
*
|
73 |
* Default option value for admin settings
|
74 |
*
|
75 |
* @param array $defaults Default values of rtMedia admin settings.
|
76 |
+
*
|
77 |
* @return array defaults
|
78 |
*/
|
79 |
public function add_admin_option_default_value( $defaults ) {
|
120 |
* Add setting option in rtmedia settings
|
121 |
*
|
122 |
* @param array $general_group Add group message.
|
123 |
+
*
|
124 |
* @return array $general_group
|
125 |
*/
|
126 |
public function admin_setting_add_terms_section( $general_group ) {
|
134 |
*
|
135 |
* @param array $render_options Rendering according to selected options.
|
136 |
* @param array $options Options selected in settings.
|
137 |
+
*
|
138 |
* @return array $render_option
|
139 |
*/
|
140 |
public function admin_setting_add_terms_option( $render_options, $options ) {
|
app/admin/templates/tmpl-rtm-album-favourites-importer.php
CHANGED
@@ -1,3 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
<br />
|
2 |
<div class="bp-album-favorites">
|
3 |
<strong>
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Displays album favourites Div.
|
4 |
+
*
|
5 |
+
* @package rtMedia
|
6 |
+
*/
|
7 |
+
|
8 |
+
?>
|
9 |
<br />
|
10 |
<div class="bp-album-favorites">
|
11 |
<strong>
|
app/admin/templates/tmpl-rtm-image.php
CHANGED
@@ -1,3 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
<# if(data.class && '' !== data.class){ #>
|
2 |
<img class="bpm-ajax-loader" src="{{data.src}}" /> <strong>{{data.norefresh}}</strong>
|
3 |
<# } else { #>
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Displays image tag.
|
4 |
+
*
|
5 |
+
* @package rtMedia
|
6 |
+
*/
|
7 |
+
|
8 |
+
?>
|
9 |
<# if(data.class && '' !== data.class){ #>
|
10 |
<img class="bpm-ajax-loader" src="{{data.src}}" /> <strong>{{data.norefresh}}</strong>
|
11 |
<# } else { #>
|
app/admin/templates/tmpl-rtm-map-mapping-failure.php
CHANGED
@@ -1 +1,9 @@
|
|
1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Display mapping fail message div.
|
4 |
+
*
|
5 |
+
* @package rtMedia
|
6 |
+
*/
|
7 |
+
|
8 |
+
?>
|
9 |
+
<div class="map_mapping_failure">{{map_data.msg}}</div>
|
app/admin/templates/tmpl-rtm-msg-div.php
CHANGED
@@ -1,3 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
<div class="{{data.class}}" id="{{data.id}}">
|
2 |
<p>{{data.msg}}</p>
|
3 |
-
</div>
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Displays Message Div.
|
4 |
+
*
|
5 |
+
* @package rtMedia
|
6 |
+
*/
|
7 |
+
|
8 |
+
?>
|
9 |
<div class="{{data.class}}" id="{{data.id}}">
|
10 |
<p>{{data.msg}}</p>
|
11 |
+
</div>
|
app/admin/templates/tmpl-rtm-p-tag.php
CHANGED
@@ -1,5 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
<# if( data.strong && '' !== data.strong ) { #>
|
2 |
<p><strong>{{data.msg}}</strong></p>
|
3 |
<# } else { #>
|
4 |
<p>{{data.msg}}</p>
|
5 |
-
<# } #>
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Displays message.
|
4 |
+
*
|
5 |
+
* @package rtMedia
|
6 |
+
*/
|
7 |
+
|
8 |
+
?>
|
9 |
<# if( data.strong && '' !== data.strong ) { #>
|
10 |
<p><strong>{{data.msg}}</strong></p>
|
11 |
<# } else { #>
|
12 |
<p>{{data.msg}}</p>
|
13 |
+
<# } #>
|
app/admin/templates/tmpl-rtm-theme-overlay.php
CHANGED
@@ -1,4 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
<div class="theme-overlay rtm-theme-overlay">
|
2 |
<div class="theme-backdrop rtm-close"></div>
|
3 |
<div class="rtm-theme-content-wrap">{{{data.themeContent}}}</div>
|
4 |
-
</div>
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Display theme information Div.
|
4 |
+
*
|
5 |
+
* @package rtMedia
|
6 |
+
*/
|
7 |
+
|
8 |
+
?>
|
9 |
<div class="theme-overlay rtm-theme-overlay">
|
10 |
<div class="theme-backdrop rtm-close"></div>
|
11 |
<div class="rtm-theme-content-wrap">{{{data.themeContent}}}</div>
|
12 |
+
</div>
|
app/assets/admin/js/admin.min.js
CHANGED
@@ -3,4 +3,4 @@
|
|
3 |
* @package rtMedia
|
4 |
*/
|
5 |
|
6 |
-
"function"!=typeof Object.create&&(Object.create=function(e){function t(){}return t.prototype=e,new t}),function(n,s){var r={init:function(e,t){var r=this;r.elem=t,r.$elem=n(t),r.options=n.extend({},n.fn.rtTab.options,e),r.rtTabs()},rtTabs:function(){var t=this,e=t.options.activeTab;if(t.$elem.find("li:nth-child("+e+")").addClass("active"),t.rtTabContent(activeTabContent="yes"),t.rtClick(),!0==("false"!==t.$elem.attr("data-hash"))){var r=s.location.hash;r&&t.$elem.find("li").find('a[href="'+r+'"]').trigger("click"),n(s).on("hashchange",function(){var e=s.location.hash;t.$elem.find("li").find('a[href="'+e+'"]').trigger("click")})}},rtClick:function(){var a=this,i=a.$elem.find("li");i.find("a").on("click",function(e){e.preventDefault(),i.removeClass("active"),a.rtTabContent(),n(this).parent().addClass("active");var t=n(this).attr("href");if(n(t).removeClass("hide"),!0==("false"!==a.$elem.attr("data-hash"))){var r=n(s).scrollTop();location.hash=n(this).attr("href"),n(s).scrollTop(r)}"function"==typeof a.options.onComplete&&a.options.onComplete.apply(a.elem,arguments)})},rtTabContent:function(r){this.$elem.find("li").find("a").each(function(){var e=n(this),t=e.attr("href");"yes"===r&&e.parent().hasClass("active")||n(t).addClass("hide")})}};n.fn.rtTab=function(t){return this.each(function(){var e=Object.create(r);e.init(t,this),n.data(this,"rtTab",e)})},n.fn.rtTab.options={activeTab:1,onComplete:null}}(jQuery,window,document),jQuery(document).ready(function(a){var e=document.createElement("div");e.setAttribute("class","rtm-warning rtm-fly-warning hide"),a(".rtm-tabs").rtTab(),a('input[name^="rtmedia-options"]').on("change",function(){a(".rtm-save-settings-msg").remove(),0===a(".rtm-fly-warning").length&&(e.innerText=rtmedia_admin_strings.settings_changed,a(".rtm-button-container.top").prepend(e),a(".rtm-fly-warning").slideDown())}),a(".rtm-img-size-setting .form-table tr:nth-child(7) td:last-child").attr("colspan","3"),a(".rtm-field-wrap .switch input[type=checkbox]").each(function(){var e=a(this);e.parents("table").attr("data-depends")||(e.is(":checked")?(e.parents("table").next(".rtm-notice").slideDown(),e.parents("table").siblings("table").each(function(){a(this).attr("data-depends")&&a(this).slideDown()})):(e.parents("table").next(".rtm-notice").slideUp(),e.parents("table").siblings("table").each(function(){a(this).attr("data-depends")&&a(this).slideUp()}))),e.parents("tr").next("tr").attr("data-depends")&&(e.is(":checked")?e.parents("tr").next("tr").slideDown():e.parents("tr").next("tr").slideUp())}),a(".rtm-field-wrap .switch input[type=checkbox]").on("change",function(){var e=a(this);e.parents("table").attr("data-depends")||(e.parents("table").next(".rtm-notice").slideToggle(),e.parents("table").siblings("table").each(function(){a(this).attr("data-depends")&&a(this).slideToggle()})),e.parents("tr").next("tr").attr("data-depends")&&e.parents("tr").next("tr").slideToggle()});new(Backbone.View.extend({el:a(".bp-media-admin"),events:{"click .rtm-theme":"render","click .rtm-close":"close","click .rtm-previous":"previousTheme","click .rtm-next":"nextTheme",keyup:"keyEvent"},initialize:function(){_.bindAll(this,"render","close","nextTheme","previousTheme","keyEvent"),this.keyEvent()},render:function(e){a(".rtm-theme").removeClass("rtm-modal-open");var t=a(e.currentTarget).addClass("rtm-modal-open").find(".rtm-theme-content").html();if(a(".rtm-theme-overlay")[0])a(".rtm-theme-overlay").show(),a(this.el).find(".rtm-theme-content-wrap").empty().append(t);else{var r={themeContent:t};a(this.el).append(rtMediaAdmin.templates.rtm_theme_overlay(r))}a(e.currentTarget).is(":first-child")?a(".rtm-previous").addClass("disabled"):a(e.currentTarget).is(":last-child")?a(".rtm-next").addClass("disabled"):a(".rtm-next, .rtm-previous").removeClass("disabled")},close:function(){a(".rtm-theme").removeClass("rtm-modal-open"),a(".rtm-theme-overlay").hide(),a(".rtm-next, .rtm-previous").removeClass("disabled")},nextTheme:function(e){return a(".rtm-next, .rtm-previous").removeClass("disabled"),a(".rtm-theme:last-child").hasClass("rtm-modal-open")&&a(e.currentTarget).addClass("disabled"),a(".rtm-modal-open").next().trigger("click"),!1},previousTheme:function(e){return a(".rtm-next, .rtm-previous").removeClass("disabled"),a(".rtm-theme:first-child").hasClass("rtm-modal-open")&&a(e.currentTarget).addClass("disabled"),a(".rtm-modal-open").prev().trigger("click"),!1},keyEvent:function(){a("body").on("keyup",function(e){return 39===e.keyCode?(a(".rtm-next, .rtm-previous").removeClass("disabled"),a(".rtm-theme:last-child").hasClass("rtm-modal-open")&&a(e.currentTarget).addClass("disabled"),a(".rtm-modal-open").next().trigger("click"),!1):37===e.keyCode?(a(".rtm-next, .rtm-previous").removeClass("disabled"),a(".rtm-theme:first-child").hasClass("rtm-modal-open")&&a(e.currentTarget).addClass("disabled"),a(".rtm-modal-open").prev().trigger("click"),!1):void(27===e.keyCode&&a(".rtm-close").trigger("click"))})}}));jQuery("#rtm-licenses .regular-text").each(function(){jQuery(this).keypress(function(e){if("13"==(e.keyCode?e.keyCode:e.which))return!1})}),jQuery("#bp_media_settings_form").on("submit",function(e){jQuery("#rtcss-notice").remove();var t=jQuery("#rtmedia-custom-css").val().match(/@import\s*(url)?\s*\(?([^;]+?)\)?;/);if(null!=t&&null!=t[0])return jQuery("#rtmedia-custom-css").after('<div id="rtcss-notice" class="error"><p>'+rtmedia_admin_strings.wrong_css_input+"</p></div>"),!1})});var rtMediaAdmin=new Object;function rtmedia_addon_do_not_show(){jQuery.post(rtmedia_admin_ajax,{action:"rtmedia_addon_popup_not_show_again"},function(e){jQuery("#TB_window").remove(),jQuery("#TB_overlay").remove()})}rtMediaAdmin.templates={rtm_image:wp.template("rtm-image"),rtm_msg_div:wp.template("rtm-msg-div"),rtm_album_favourites_importer:wp.template("rtm-album-favourites-importer"),rtm_map_mapping_failure:wp.template("rtm-map-mapping-failure"),rtm_p_tag:wp.template("rtm-p-tag"),rtm_theme_overlay:wp.template("rtm-theme-overlay")},jQuery(document).ready(function(v){var e=v("#rtm-licenses");0<e.length&&e.find(".license-inner:first input:first").focus();var t=document.createElement("div");function n(n){return jQuery.getJSON(ajaxurl,n,function(e){if(favorites=!1,e){var t=Math.ceil((5*parseInt(e.page)+parseInt(n.values.finished))/parseInt(n.values.total)*100);comments_total=jQuery("#bpmedia-bpalbumimporter .bp-album-comments span.total").html(),users_total=jQuery("#bpmedia-bpalbumimporter .bp-album-users span.total").html(),media_total=jQuery("#bpmedia-bpalbumimporter .bp-album-media span.total").html(),comments_finished=jQuery("#bpmedia-bpalbumimporter .bp-album-comments span.finished").html(),users_finished=jQuery("#bpmedia-bpalbumimporter .bp-album-users span.finished").html();var r=Math.ceil((parseInt(e.comments)+parseInt(comments_finished))/parseInt(comments_total)*100),a=Math.ceil(parseInt(e.users)/parseInt(users_total)*100);(100<t||100==t)&&(t=100,favorites=!0),jQuery(".bp-album-media #rtprogressbar>div").css("width",t+"%"),jQuery(".bp-album-comments #rtprogressbar>div").css("width",r+"%"),jQuery(".bp-album-users #rtprogressbar>div").css("width",a+"%"),media_finished=jQuery("#bpmedia-bpalbumimporter .bp-album-media span.finished").html(),parseInt(media_finished)<parseInt(media_total)&&jQuery("#bpmedia-bpalbumimporter .bp-album-media span.finished").html(parseInt(media_finished)+n.count),jQuery("#bpmedia-bpalbumimporter .bp-album-comments span.finished").html(parseInt(e.comments)+parseInt(comments_finished)),jQuery("#bpmedia-bpalbumimporter .bp-album-users span.finished").html(parseInt(e.users)),favorites&&(favorite_data={action:"rtmedia_rt_album_import_favorites",rtm_wpnonce:jQuery("#bpaimporter_wpnonce").val()},jQuery.post(ajaxurl,favorite_data,function(e){if(!e.hasOwnProperty(favorites)||0===e.favorites&&"0"===e.favorites)window.setTimeout(s,2e3);else{if(!jQuery(".bp-album-favorites").length){var t={users:e.users};jQuery(".bp-album-comments").after(rtMediaAdmin.templates.rtm_album_favourites_importer(t))}$favorites={},0!=e.offset||"0"!=e.offset?start=1*e.offset+1:start=1;for(var r=start;r<=e.users;r++)$count=1,r==e.users&&($count=parseInt(e.users%$count),0==$count&&($count=1)),newvals={action:"rtmedia_rt_album_import_step_favorites",offset:1*(r-1),redirect:r==e.users,rtm_wpnonce:jQuery("#bpaimporter_wpnonce").val()},$favorites[r]=newvals;var a=jQuery.Deferred();a.resolve(),jQuery.each($favorites,function(e,t){a=a.pipe(function(){return function(e){return jQuery.post(ajaxurl,e,function(e){redirect=!1,favorites_total=jQuery("#bpmedia-bpalbumimporter .bp-album-favorites span.total").html(),favorites_finished=jQuery("#bpmedia-bpalbumimporter .bp-album-favorites span.finished").html(),jQuery("#bpmedia-bpalbumimporter .bp-album-favorites span.finished").html(parseInt(favorites_finished)+1);var t=Math.ceil(parseInt(favorites_finished+1)/parseInt(favorites_total)*100);(100<t||100==t)&&(t=100,redirect=!0),jQuery(".bp-album-favorites #rtprogressbar>div").css("width",t+"%"),redirect&&window.setTimeout(s,2e3)})}(t)})})}},"json"))}else if(n.hasOwnProperty(page)){var i={msg:"Row "+e.page+" failed."};jQuery("#map_progress_msgs").html(rtMediaAdmin.templates.rtm_map_mapping_failure(i))}else{i={msg:rtmedia_admin_strings.request_failed};jQuery("#map_progress_msgs").html(rtMediaAdmin.templates.rtm_map_mapping_failure(i))}})}function s(){window.location=document.URL}t.className="support_form_loader",0<v(".rtm-save-settings-msg").length&&setTimeout(function(){v(".rtm-save-settings-msg").remove()},1e4),jQuery("#spread-the-word").on("click","#bp-media-add-linkback",function(){var e={action:"rtmedia_linkback",linkback:jQuery("#bp-media-add-linkback:checked").length};jQuery.post(rtmedia_admin_ajax,e,function(e){})}),jQuery("#bp-media-settings-boxes").on("change","#select-request",function(){if(jQuery(this).val()){jQuery("#bp_media_settings_form .bp-media-metabox-holder").html(),jQuery("#bp_media_settings_form .bp-media-metabox-holder").html(t);var e={action:"rtmedia_select_request",form:jQuery(this).val()};jQuery.post(ajaxurl,e,function(e){jQuery("#bp_media_settings_form .bp-media-metabox-holder").html(),jQuery("#bp_media_settings_form .bp-media-metabox-holder").html(e).fadeIn("slow")})}}),jQuery("#bp-media-settings-boxes").on("click","#cancel-request",function(){if(jQuery(this).val()){jQuery("#bp_media_settings_form .bp-media-metabox-holder").html(),jQuery("#bp_media_settings_form .bp-media-metabox-holder").html(t);jQuery.post(ajaxurl,{action:"rtmedia_cancel_request"},function(e){jQuery("#bp_media_settings_form .bp-media-metabox-holder").html(),jQuery("#bp_media_settings_form .bp-media-metabox-holder").html(e).fadeIn("slow")})}}),jQuery("#bp-media-settings-boxes").on("submit","#bp_media_settings_form, .rtmedia-settings-submit",function(e){var t=!0,r=new RegExp("^[0-9]+$");jQuery("input[name*='defaultSizes']").each(function(e){if(!r.test(jQuery(this).val()))return alert("Invalid value for "+jQuery(this).attr("name").replace("rtmedia-options[defaultSizes_","").replace("]","").replace(/_/g," ").replace(/(\b)([a-zA-Z] )/g,function(e){return e.toUpperCase()})),t=!1});var a=jQuery('input[name^="rtmedia-options[general_videothumbs]"]');if(t&&0<a.length&&void 0!==a){var i="",n=0;if(a.val()<=0?(i+=rtmedia_admin_strings.video_thumbnail_error,n=2):r.test(a.val())||(i+=rtmedia_admin_strings.video_thumbnail_invalid_value+" "+Math.round(a.val())+".",n=Math.round(a.val())),""!=i)return alert(i),a.val(n),t=!1}var s=jQuery('input[name^="rtmedia-options[general_jpeg_image_quality]"]');if(t&&0<s.length&&void 0!==s){i="";var o=0;if(s.val()<=0?(i+=rtmedia_admin_strings.jpeg_quality_negative_error,o=90):100<s.val()?(i+=rtmedia_admin_strings.jpeg_quality_percentage_error,o=100):r.test(s.val())||(i+=rtmedia_admin_strings.jpeg_quality_invalid_value+" "+Math.round(s.val())+".",o=Math.round(s.val())),""!=i)return alert(i),s.val(o),t=!1}var m=jQuery('input[name^="rtmedia-options[general_perPageMedia]"]');if(t&&0<m.length&&void 0!==m){i="";var u=0;if(m.val()<1?(i+=rtmedia_admin_strings.per_page_media_negative_value,u=10):jQuery.isNumeric(m.val())&&Math.floor(m.val())!=m.val()&&(i+=rtmedia_admin_strings.per_page_media_positive_error+" "+Math.round(m.val())+".",u=Math.round(m.val())),""!=i)return alert(i),m.val(u),t=!1}t||e.preventDefault()}),jQuery(document).on("click","#bpm-services .encoding-try-now,#rtm-services .encoding-try-now",function(e){if(e.preventDefault(),confirm(rtmedia_admin_strings.are_you_sure)){var t={src:rtmedia_admin_url+"images/wpspin_light.gif"};jQuery(this).after(rtMediaAdmin.templates.rtm_image(t));t={action:"rtmedia_free_encoding_subscribe"};jQuery.getJSON(ajaxurl,t,function(e){if(void 0===e.error&&e.apikey){var t=window.location.href,r=window.location.hash;t=t.replace(r,""),document.location.href=t+"&apikey="+e.apikey+r}else{jQuery(".encoding-try-now").next().remove(),jQuery("#settings-error-encoding-error").remove();var a={id:"settings-error-encoding-error",msg:e.error,class:"error"};jQuery("#bp-media-settings-boxes").before(rtMediaAdmin.templates.rtm_msg_div(a))}})}}),jQuery(document).on("click","#api-key-submit",function(e){if(e.preventDefault(),0==jQuery(this).next("img").length){var t={src:rtmedia_admin_url+"images/wpspin_light.gif"};jQuery(this).after(rtMediaAdmin.templates.rtm_image(t))}t={action:"rtmedia_enter_api_key",apikey:jQuery("#new-api-key").val()};jQuery.getJSON(ajaxurl,t,function(e){if(void 0===e.error&&e.apikey){var t=window.location.href,r=window.location.hash;-1==(t=t.replace(r,"")).toString().indexOf("&apikey="+e.apikey)&&(t+="&apikey="+e.apikey),-1==t.toString().indexOf("&update=true")&&(t+="&update=true"),document.location.href=t+r}else{jQuery("#settings-error-api-key-error").remove();var a={id:"settings-error-api-key-error",msg:e.error,class:"error"};jQuery("h2:first").after(rtMediaAdmin.templates.rtm_msg_div(a))}jQuery("#api-key-submit").next("img").remove()})}),jQuery(document).on("click","#disable-encoding",function(e){if(e.preventDefault(),confirm(rtmedia_admin_strings.disable_encoding)){var t={src:rtmedia_admin_url+"images/wpspin_light.gif"};jQuery(this).after(rtMediaAdmin.templates.rtm_image(t));t={action:"rtmedia_disable_encoding"};jQuery.post(ajaxurl,t,function(e){if(e){if(jQuery(".settings-error-encoding-disabled").remove(),0<jQuery("#settings-encoding-successfully-updated").length)jQuery("#settings-encoding-successfully-updated p").html(e);else{var t={id:"settings-encoding-successfully-updated",msg:e,class:"updated"};jQuery("h2:first").after(rtMediaAdmin.templates.rtm_msg_div(t))}jQuery("#rtmedia-encoding-usage").hide(),jQuery("#disable-encoding").next("img").remove(),jQuery("#disable-encoding").hide(),jQuery("#enable-encoding").show()}else{jQuery("#settings-error-encoding-disabled").remove();t={id:"settings-error-encoding-disabled",msg:rtmedia_admin_strings.something_went_wrong,class:"error"};jQuery("h2:first").after(rtMediaAdmin.templates.rtm_msg_div(t))}})}}),jQuery(document).on("click","#enable-encoding",function(e){if(e.preventDefault(),confirm(rtmedia_admin_strings.enable_encoding)){var t={src:rtmedia_admin_url+"images/wpspin_light.gif"};jQuery(this).after(rtMediaAdmin.templates.rtm_image(t));t={action:"rtmedia_enable_encoding"};jQuery.post(ajaxurl,t,function(e){if(e){if(jQuery(".settings-error-encoding-enabled").remove(),0<jQuery("#settings-encoding-successfully-updated").length)jQuery("#settings-encoding-successfully-updated p").html(e);else{var t={id:"settings-encoding-successfully-updated",msg:e,class:"updated"};jQuery("h2:first").after(rtMediaAdmin.templates.rtm_msg_div(t))}jQuery("#enable-encoding").next("img").remove(),jQuery("#enable-encoding").hide(),jQuery("#disable-encoding").show()}else{jQuery("#settings-error-encoding-disabled").remove();t={id:"settings-error-encoding-enabled",msg:rtmedia_admin_strings.something_went_wrong,class:"error"};jQuery("h2:first").after(rtMediaAdmin.templates.rtm_msg_div(t))}})}}),jQuery(".bp-media-encoding-table").on("click",".bpm-unsubscribe",function(e){e.preventDefault(),jQuery("#bpm-unsubscribe-dialog").dialog({dialogClass:"wp-dialog",modal:!0,buttons:{Unsubscribe:function(){jQuery(this).dialog("close");var e={src:rtmedia_admin_url+"images/wpspin_light.gif"};jQuery(".bpm-unsubscribe").after(rtMediaAdmin.templates.rtm_image(e));e={action:"rtmedia_unsubscribe_encoding_service",note:jQuery("#bpm-unsubscribe-note").val(),plan:jQuery(".bpm-unsubscribe").attr("data-plan"),price:jQuery(".bpm-unsubscribe").attr("data-price")};jQuery.getJSON(ajaxurl,e,function(e){if(void 0===e.error&&e.updated){jQuery(".bpm-unsubscribe").next().remove(),jQuery(".bpm-unsubscribe").after(e.form),jQuery(".bpm-unsubscribe").remove(),jQuery("#settings-unsubscribed-successfully").remove(),jQuery("#settings-unsubscribe-error").remove();var t={id:"settings-unsubscribed-successfully",msg:e.updated,class:"updated"};jQuery("h2:first").after(rtMediaAdmin.templates.rtm_msg_div(t)),window.location.hash="#settings-unsubscribed-successfully"}else{jQuery(".bpm-unsubscribe").next().remove(),jQuery("#settings-unsubscribed-successfully").remove(),jQuery("#settings-unsubscribe-error").remove();t={id:"settings-unsubscribe-error",msg:e.error,class:"error"};jQuery("h2:first").after(rtMediaAdmin.templates.rtm_msg_div(t)),window.location.hash="#settings-unsubscribe-error"}})}}})}),jQuery("#bpmedia-bpalbumimporter").on("change","#bp-album-import-accept",function(){jQuery(".bp-album-import-accept").toggleClass("i-accept"),jQuery(".bp-album-importer-wizard").slideToggle()}),jQuery("#rtprivacyinstall").click(function(e){e.preventDefault(),$progress_parent=jQuery("#rtprivacyinstaller"),$progress_parent.find(".rtprivacytype").each(function(){if($type=jQuery(this).attr("id"),"total"==$type){$values=[],jQuery(this).find("input").each(function(){$values[jQuery(this).attr("name")]=[jQuery(this).val()]}),$data={};for(var e=1;e<=$values.steps[0];e++)$count=20,e==$values.steps[0]&&($count=parseInt($values.laststep[0]),0==$count&&($count=20)),newvals={page:e,action:"rtmedia_privacy_install",count:$count,values:$values},$data[e]=newvals;var r=jQuery.Deferred();r.resolve(),jQuery.each($data,function(e,t){r=r.pipe(function(){return function(i){return jQuery.post(ajaxurl,i,function(e){if(0!=e){var t=!1,r=Math.ceil((20*parseInt(e)+parseInt(i.values.finished))/parseInt(i.values.total)*100);100<r&&(r=100,t=!0),jQuery("#rtprogressbar>div").css("width",r+"%"),finished=jQuery("#rtprivacyinstaller span.finished").html(),jQuery("#rtprivacyinstaller span.finished").html(parseInt(finished)+i.count),t&&jQuery.post(ajaxurl,{action:"rtmedia_privacy_redirect"},function(e){window.location=settings_url})}else{var a={msg:"Row "+e+" failed."};jQuery("#map_progress_msgs").html(rtMediaAdmin.templates.rtm_map_mapping_failure(a))}})}(t)})})}})}),jQuery("#bpmedia-bpalbumimport-cleanup").click(function(e){e.preventDefault(),jQuery.post(ajaxurl,{action:"rtmedia_rt_album_cleanup",rtm_wpnonce:jQuery("#bpaimporter_wpnonce").val()},function(e){window.location=settings_rt_album_import_url})}),jQuery("#bpmedia-bpalbumimporter").on("click","#bpmedia-bpalbumimport",function(e){if(e.preventDefault(),jQuery("#bp-album-import-accept").prop("checked")){if(jQuery(this).prop("disabled",!0),wp_admin_url=ajaxurl.replace("admin-ajax.php",""),!jQuery(".bpm-ajax-loader").length){var t={src:rtmedia_admin_url+"images/wpspin_light.gif",class:"bpm-ajax-loader",norefresh:rtmedia_admin_strings.no_refresh};jQuery(this).after(rtMediaAdmin.templates.rtm_image(t))}$progress_parent=jQuery("#bpmedia-bpalbumimport"),$values=[],jQuery(this).parent().find("input").each(function(){$values[jQuery(this).attr("name")]=[jQuery(this).val()]}),0==$values.steps[0]&&($values.steps[0]=1),$data={};for(i=1;i<=$values.steps[0];i++)$count=5,i==$values.steps[0]&&($count=parseInt($values.laststep[0]),0==$count&&($count=5)),newvals={page:i,action:"rtmedia_rt_album_import",count:$count,values:$values,rtm_wpnonce:jQuery("#bpaimporter_wpnonce").val()},$data[i]=newvals;var r=jQuery.Deferred();r.resolve(),jQuery.each($data,function(e,t){r=r.pipe(function(){return n(t)})})}else{jQuery("html, body").animate({scrollTop:jQuery("#bp-album-import-accept").offset().top},500);var a=jQuery(".bp-album-import-accept"),i=3;(function e(){a.css("background-color","#EE0000"),setTimeout(function(){a.css("background-color","#FFEBE8"),--i&&setTimeout(e,500)},500)})()}}),jQuery("#bp-media-settings-boxes").on("click",".interested",function(){jQuery(".interested-container").removeClass("hidden"),jQuery(".choice-free").attr("required","required")}),jQuery("#bp-media-settings-boxes").on("click",".not-interested",function(){jQuery(".interested-container").addClass("hidden"),jQuery(".choice-free").removeAttr("required")}),jQuery("#video-transcoding-main-container").on("click",".video-transcoding-survey",function(e){e.preventDefault();var t={action:"rtmedia_convert_videos_form",email:jQuery(".email").val(),url:jQuery(".url").val(),choice:jQuery('input[name="choice"]:checked').val(),interested:jQuery('input[name="interested"]:checked').val()};return jQuery.post(ajaxurl,t,function(e){var t={msg:e,strong:"yes"};jQuery("#video-transcoding-main-container").html(rtMediaAdmin.templates.rtm_p_tag(t))}),!1}),jQuery("#bpmedia-bpalbumimporter").on("click",".deactivate-bp-album",function(e){e.preventDefault(),$bpalbum=jQuery(this);var t={action:"rtmedia_rt_album_deactivate",rtm_wpnonce:jQuery("#bpaimporter_wpnonce").val()};jQuery.get(ajaxurl,t,function(e){if(e)location.reload();else{var t={msg:rtmedia_admin_strings.something_went_wrong};$bpalbum.parent().after(rtMediaAdmin.templates.rtm_p_tag(t))}})}),jQuery(".updated").on("click",".bpm-hide-encoding-notice",function(){var e={src:rtmedia_admin_url+"images/wpspin_light.gif"};jQuery(this).after(rtMediaAdmin.templates.rtm_image(e));e={action:"rtmedia_hide_encoding_notice"};jQuery.post(ajaxurl,e,function(e){e&&jQuery(".bpm-hide-encoding-notice").closest(".updated").remove()})}),jQuery("#rtmedia-bp-enable-activity").is(":checked")?jQuery(".rtmedia-bp-activity-setting").prop("readonly",!1):jQuery(".rtmedia-bp-activity-setting").prop("readonly",!0),jQuery("#rtmedia-bp-enable-activity").on("click",function(e){jQuery(this).is(":checked")?jQuery(".rtmedia-bp-activity-setting").prop("readonly",!1):jQuery(".rtmedia-bp-activity-setting").prop("readonly",!0)});var a;void 0!==rtmedia_on_label&&rtmedia_on_label,void 0!==rtmedia_off_label&&rtmedia_off_label,jQuery("input[type=file]").on("change",function(e){a=e.target.files,function(e){e.stopPropagation(),e.preventDefault();var r=new FormData;void 0!==e&&void 0!==e.target&&void 0!==e.target.name&&"rtFileInput"===e.target.name&&r.append("import_export_control",e.target.name);jQuery.each(a,function(e,t){r.append(e,t)});var t=jQuery("#rtmedia_admin_upload_nonce").val();void 0!==t&&""!==t&&r.append("rtmedia_admin_upload_nonce",t);r.append("action","rtmedia_admin_upload"),jQuery.ajax({url:rtmedia_admin_ajax,type:"POST",data:r,cache:!1,processData:!1,contentType:!1,success:function(e){if(e.hasOwnProperty("rtm_response")&&e.hasOwnProperty("rtm_response_msg")){jQuery("#rtm-setting-msg").remove();var t=jQuery("<div/>",{id:"rtm-setting-msg",class:"rtm-fly-warning"});"success"===e.rtm_response?(t.addClass("rtm-success rtm-save-settings-msg"),t.text(e.rtm_response_msg),jQuery(".rtm-button-container.top").append(t),location.reload()):"error"===e.rtm_response&&(t.addClass("rtm-warning"),t.text(e.rtm_response_msg),jQuery(".rtm-button-container.top").append(t),t.delay(3e3).fadeOut(100))}if(void 0===e.error){if(e.exceed_size_msg)return jQuery("#debuglog").val(""),alert(e.exceed_size_msg),!1;jQuery("#debuglog_temp_path").val(e.debug_attachmanet)}else jQuery("#debuglog").val(""),alert("ERRORS: "+e.error)}})}(e)}),jQuery("#rtmedia-submit-request").click(function(){var e=jQuery("#name").val(),t=jQuery("#email").val(),r=jQuery("#website").val(),a=jQuery("#subject").val(),i=jQuery("#details").val(),n=jQuery('input[name="request_type"]').val(),s=jQuery('input[name="request_id"]').val(),o=jQuery('input[name="server_address"]').val(),m=jQuery('input[name="ip_address"]').val(),u=jQuery('input[name="server_type"]').val(),d=jQuery('input[name="user_agent"]').val(),l={name:e,email:t,website:r,subject:a,details:i,request_id:s,request_type:"premium_support",server_address:o,ip_address:m,server_type:u,user_agent:d,debuglog_temp_path:jQuery('input[name="debuglog_temp_path"]').val()};if("bug_report"==n){var p=jQuery("#wp_admin_username").val();if(""==p)return alert(rtmedia_admin_support_strings.wp_admin_username_error),!1;var c=jQuery("#wp_admin_pwd").val();if(""==c)return alert(rtmedia_admin_support_strings.wp_admin_pwd_error),!1;var _=jQuery("#ssh_ftp_host").val();if(""==_)return alert(rtmedia_admin_support_strings.ssh_ftp_host_error),!1;var f=jQuery("#ssh_ftp_username").val();if(""==f)return alert(rtmedia_admin_support_strings.ssh_ftp_username_error),!1;var b=jQuery("#ssh_ftp_pwd").val();if(""==b)return alert(rtmedia_admin_support_strings.ssh_ftp_pwd_error),!1;l={name:e,email:t,website:r,subject:a,details:i,request_id:s,request_type:"premium_support",server_address:o,ip_address:m,server_type:u,user_agent:d,wp_admin_username:p,wp_admin_pwd:c,ssh_ftp_host:_,ssh_ftp_username:f,ssh_ftp_pwd:b}}for(formdata in l){if(""==l[formdata]&&"debuglog_temp_path"!=formdata)return alert("Please enter "+formdata.replace("_"," ")+" field."),!1;if(""==l[formdata]&&"debuglog_temp_path"==formdata)return alert("Please upload attachment."),!1}return data={action:"rtmedia_submit_request",form_data:l,support_wpnonce:jQuery("#support_wpnonce").val()},jQuery.post(ajaxurl,data,function(e){if("false"==(e=e.trim()))return alert(rtmedia_admin_support_strings.all_fields_error),!1;v("#rtmedia_service_contact_container").empty(),v("#rtmedia_service_contact_container").append(e)}),!1}),jQuery("#cancel-request").click(function(){return!1}),jQuery(".rtm_enable_masonry_view input[type=checkbox]").is(":checked")?jQuery(".rtm_enable_masonry_view").parents(".metabox-holder").find(".rtmedia-info").show():jQuery(".rtm_enable_masonry_view").parents(".metabox-holder").find(".rtmedia-info").hide(),jQuery(".rtm_enable_masonry_view input[type=checkbox]").on("click",function(e){jQuery(this).is(":checked")?jQuery(".rtm_enable_masonry_view").parents(".metabox-holder").find(".rtmedia-info").show():jQuery(".rtm_enable_masonry_view").parents(".metabox-holder").find(".rtmedia-info").hide()}),jQuery("#rtm-masonry-change-thumbnail-info").click(function(e){jQuery("html, body").animate({scrollTop:0},"500","swing")}),jQuery("#rtm-export-button").click(function(){data={action:"rtmedia_export_settings"},jQuery.post(ajaxurl,data,function(e){var t="data:text/json;charset=utf-8,"+encodeURIComponent(JSON.stringify(e)),r=document.createElement("a");r.setAttribute("href",t),r.setAttribute("download","rtm-settings.json"),jQuery("body").append(r),r.click(),r.remove()})}),jQuery("#rtm-export-data-button").click(function(){window.location.href="/wp-admin/tools.php?page=export_personal_data"}),jQuery("#rtm-erase-data-button").click(function(){window.location.href="/wp-admin/tools.php?page=remove_personal_data"})}),jQuery(window).load(function(){jQuery(".rtmedia-addon-thickbox").trigger("click")});
|
3 |
* @package rtMedia
|
4 |
*/
|
5 |
|
6 |
+
"function"!=typeof Object.create&&(Object.create=function(e){function t(){}return t.prototype=e,new t}),function(n,s){var r={init:function(e,t){var r=this;r.elem=t,r.$elem=n(t),r.options=n.extend({},n.fn.rtTab.options,e),r.rtTabs()},rtTabs:function(){var t=this,e=t.options.activeTab;if(t.$elem.find("li:nth-child("+e+")").addClass("active"),t.rtTabContent(activeTabContent="yes"),t.rtClick(),!0==("false"!==t.$elem.attr("data-hash"))){var r=s.location.hash;r&&t.$elem.find("li").find('a[href="'+r+'"]').trigger("click"),n(s).on("hashchange",function(){var e=s.location.hash;t.$elem.find("li").find('a[href="'+e+'"]').trigger("click")})}},rtClick:function(){var a=this,i=a.$elem.find("li");i.find("a").on("click",function(e){e.preventDefault(),i.removeClass("active"),a.rtTabContent(),n(this).parent().addClass("active");var t=n(this).attr("href");if(n(t).removeClass("hide"),!0==("false"!==a.$elem.attr("data-hash"))){var r=n(s).scrollTop();location.hash=n(this).attr("href"),n(s).scrollTop(r)}"function"==typeof a.options.onComplete&&a.options.onComplete.apply(a.elem,arguments)})},rtTabContent:function(r){this.$elem.find("li").find("a").each(function(){var e=n(this),t=e.attr("href");"yes"===r&&e.parent().hasClass("active")||n(t).addClass("hide")})}};n.fn.rtTab=function(t){return this.each(function(){var e=Object.create(r);e.init(t,this),n.data(this,"rtTab",e)})},n.fn.rtTab.options={activeTab:1,onComplete:null}}(jQuery,window,document),jQuery(document).ready(function(a){var e=document.createElement("div");e.setAttribute("class","rtm-warning rtm-fly-warning hide"),a(".rtm-tabs").rtTab(),a('input[name^="rtmedia-options"]').on("change",function(){a(".rtm-save-settings-msg").remove(),0===a(".rtm-fly-warning").length&&(e.innerText=rtmedia_admin_strings.settings_changed,a(".rtm-button-container.top").prepend(e),a(".rtm-fly-warning").slideDown())}),a(".rtm-img-size-setting .form-table tr:nth-child(7) td:last-child").attr("colspan","3"),a(".rtm-field-wrap .switch input[type=checkbox]").each(function(){var e=a(this);e.parents("table").attr("data-depends")||(e.is(":checked")?(e.parents("table").next(".rtm-notice").slideDown(),e.parents("table").siblings("table").each(function(){a(this).attr("data-depends")&&a(this).slideDown()})):(e.parents("table").next(".rtm-notice").slideUp(),e.parents("table").siblings("table").each(function(){a(this).attr("data-depends")&&a(this).slideUp()}))),e.parents("tr").next("tr").attr("data-depends")&&(e.is(":checked")?e.parents("tr").next("tr").slideDown():e.parents("tr").next("tr").slideUp())}),a(".rtm-field-wrap .switch input[type=checkbox]").on("change",function(){var e=a(this);e.parents("table").attr("data-depends")||(e.parents("table").next(".rtm-notice").slideToggle(),e.parents("table").siblings("table").each(function(){a(this).attr("data-depends")&&a(this).slideToggle()})),e.parents("tr").next("tr").attr("data-depends")&&e.parents("tr").next("tr").slideToggle()});new(Backbone.View.extend({el:a(".bp-media-admin"),events:{"click .rtm-theme":"render","click .rtm-close":"close","click .rtm-previous":"previousTheme","click .rtm-next":"nextTheme",keyup:"keyEvent"},initialize:function(){_.bindAll(this,"render","close","nextTheme","previousTheme","keyEvent"),this.keyEvent()},render:function(e){a(".rtm-theme").removeClass("rtm-modal-open");var t=a(e.currentTarget).addClass("rtm-modal-open").find(".rtm-theme-content").html();if(a(".rtm-theme-overlay")[0])a(".rtm-theme-overlay").show(),a(this.el).find(".rtm-theme-content-wrap").empty().append(t);else{var r={themeContent:t};a(this.el).append(rtMediaAdmin.templates.rtm_theme_overlay(r))}a(e.currentTarget).is(":first-child")?a(".rtm-previous").addClass("disabled"):a(e.currentTarget).is(":last-child")?a(".rtm-next").addClass("disabled"):a(".rtm-next, .rtm-previous").removeClass("disabled")},close:function(){a(".rtm-theme").removeClass("rtm-modal-open"),a(".rtm-theme-overlay").hide(),a(".rtm-next, .rtm-previous").removeClass("disabled")},nextTheme:function(e){return a(".rtm-next, .rtm-previous").removeClass("disabled"),a(".rtm-theme:last-child").hasClass("rtm-modal-open")&&a(e.currentTarget).addClass("disabled"),a(".rtm-modal-open").next().trigger("click"),!1},previousTheme:function(e){return a(".rtm-next, .rtm-previous").removeClass("disabled"),a(".rtm-theme:first-child").hasClass("rtm-modal-open")&&a(e.currentTarget).addClass("disabled"),a(".rtm-modal-open").prev().trigger("click"),!1},keyEvent:function(){a("body").on("keyup",function(e){return 39===e.keyCode?(a(".rtm-next, .rtm-previous").removeClass("disabled"),a(".rtm-theme:last-child").hasClass("rtm-modal-open")&&a(e.currentTarget).addClass("disabled"),a(".rtm-modal-open").next().trigger("click"),!1):37===e.keyCode?(a(".rtm-next, .rtm-previous").removeClass("disabled"),a(".rtm-theme:first-child").hasClass("rtm-modal-open")&&a(e.currentTarget).addClass("disabled"),a(".rtm-modal-open").prev().trigger("click"),!1):void(27===e.keyCode&&a(".rtm-close").trigger("click"))})}}));jQuery("#rtm-licenses .regular-text").each(function(){jQuery(this).keypress(function(e){if("13"==(e.keyCode?e.keyCode:e.which))return!1})}),jQuery("#bp_media_settings_form").on("submit",function(e){jQuery("#rtcss-notice").remove();var t=jQuery("#rtmedia-custom-css").val().match(/@import\s*(url)?\s*\(?([^;]+?)\)?;/);if(null!=t&&null!=t[0])return jQuery("#rtmedia-custom-css").after('<div id="rtcss-notice" class="error"><p>'+rtmedia_admin_strings.wrong_css_input+"</p></div>"),!1})});var rtMediaAdmin=new Object;function rtmedia_addon_do_not_show(){jQuery.post(rtmedia_admin_ajax,{action:"rtmedia_addon_popup_not_show_again"},function(e){jQuery("#TB_window").remove(),jQuery("#TB_overlay").remove()})}rtMediaAdmin.templates={rtm_image:wp.template("rtm-image"),rtm_msg_div:wp.template("rtm-msg-div"),rtm_album_favourites_importer:wp.template("rtm-album-favourites-importer"),rtm_map_mapping_failure:wp.template("rtm-map-mapping-failure"),rtm_p_tag:wp.template("rtm-p-tag"),rtm_theme_overlay:wp.template("rtm-theme-overlay")},jQuery(document).ready(function(g){var i=g("#bp-media-settings-boxes"),t=g("#bp_media_settings_form .bp-media-metabox-holder"),e=g("#rtm-licenses");0<e.length&&e.find(".license-inner:first input:first").focus();var r=document.createElement("div");function n(n){return jQuery.getJSON(ajaxurl,n,function(e){if(favorites=!1,e){var t=Math.ceil((5*parseInt(e.page)+parseInt(n.values.finished))/parseInt(n.values.total)*100);comments_total=jQuery("#bpmedia-bpalbumimporter .bp-album-comments span.total").html(),users_total=jQuery("#bpmedia-bpalbumimporter .bp-album-users span.total").html(),media_total=jQuery("#bpmedia-bpalbumimporter .bp-album-media span.total").html(),comments_finished=jQuery("#bpmedia-bpalbumimporter .bp-album-comments span.finished").html(),users_finished=jQuery("#bpmedia-bpalbumimporter .bp-album-users span.finished").html();var r=Math.ceil((parseInt(e.comments)+parseInt(comments_finished))/parseInt(comments_total)*100),a=Math.ceil(parseInt(e.users)/parseInt(users_total)*100);(100<t||100==t)&&(t=100,favorites=!0),jQuery(".bp-album-media #rtprogressbar>div").css("width",t+"%"),jQuery(".bp-album-comments #rtprogressbar>div").css("width",r+"%"),jQuery(".bp-album-users #rtprogressbar>div").css("width",a+"%"),media_finished=jQuery("#bpmedia-bpalbumimporter .bp-album-media span.finished").html(),parseInt(media_finished)<parseInt(media_total)&&jQuery("#bpmedia-bpalbumimporter .bp-album-media span.finished").html(parseInt(media_finished)+n.count),jQuery("#bpmedia-bpalbumimporter .bp-album-comments span.finished").html(parseInt(e.comments)+parseInt(comments_finished)),jQuery("#bpmedia-bpalbumimporter .bp-album-users span.finished").html(parseInt(e.users)),favorites&&(favorite_data={action:"rtmedia_rt_album_import_favorites",rtm_wpnonce:jQuery("#bpaimporter_wpnonce").val()},jQuery.post(ajaxurl,favorite_data,function(e){if(!e.hasOwnProperty(favorites)||0===e.favorites&&"0"===e.favorites)window.setTimeout(s,2e3);else{if(!jQuery(".bp-album-favorites").length){var t={users:e.users};jQuery(".bp-album-comments").after(rtMediaAdmin.templates.rtm_album_favourites_importer(t))}$favorites={},0!==e.offset||"0"!==e.offset?start=1*e.offset+1:start=1;for(var r=start;r<=e.users;r++)$count=1,r===e.users&&($count=parseInt(e.users%$count),0==$count&&($count=1)),newvals={action:"rtmedia_rt_album_import_step_favorites",offset:r-1,redirect:r===e.users,rtm_wpnonce:jQuery("#bpaimporter_wpnonce").val()},$favorites[r]=newvals;var a=jQuery.Deferred();a.resolve(),jQuery.each($favorites,function(e,t){a=a.pipe(function(){return function(e){return jQuery.post(ajaxurl,e,function(e){redirect=!1,favorites_total=jQuery("#bpmedia-bpalbumimporter .bp-album-favorites span.total").html(),favorites_finished=jQuery("#bpmedia-bpalbumimporter .bp-album-favorites span.finished").html(),jQuery("#bpmedia-bpalbumimporter .bp-album-favorites span.finished").html(parseInt(favorites_finished)+1);var t=Math.ceil(parseInt(favorites_finished+1)/parseInt(favorites_total)*100);(100<t||100==t)&&(t=100,redirect=!0),jQuery(".bp-album-favorites #rtprogressbar>div").css("width",t+"%"),redirect&&window.setTimeout(s,2e3)})}(t)})})}},"json"))}else if(n.hasOwnProperty(page)){var i={msg:"Row "+e.page+" failed."};jQuery("#map_progress_msgs").html(rtMediaAdmin.templates.rtm_map_mapping_failure(i))}else{i={msg:rtmedia_admin_strings.request_failed};jQuery("#map_progress_msgs").html(rtMediaAdmin.templates.rtm_map_mapping_failure(i))}})}function s(){window.location=document.URL}r.className="support_form_loader",0<g(".rtm-save-settings-msg").length&&setTimeout(function(){g(".rtm-save-settings-msg").remove()},1e4),jQuery("#spread-the-word").on("click","#bp-media-add-linkback",function(){var e={action:"rtmedia_linkback",linkback:jQuery("#bp-media-add-linkback:checked").length};jQuery.post(rtmedia_admin_ajax,e,function(e){})}),i.on("change","#select-request",function(){if(jQuery(this).val()){t.html(r);var e={action:"rtmedia_select_request",form:jQuery(this).val()};jQuery.post(ajaxurl,e,function(e){t.html(e).fadeIn("slow")})}}),i.on("click","#cancel-request",function(){if(jQuery(this).val()){t.html(),t.html(r);jQuery.post(ajaxurl,{action:"rtmedia_cancel_request"},function(e){t.html(),t.html(e).fadeIn("slow")})}}),i.on("submit","#bp_media_settings_form, .rtmedia-settings-submit",function(i){var e=!0,n=new RegExp("^[0-9]+$"),t="";g("input[name*='defaultSizes']").each(function(){var e=g(this);if(e.css("border-color","#7e8993").next(".error_msg").remove(),!n.test(e.val())){var t=e.attr("name");t=(t=(t=t.replace("rtmedia-options[defaultSizes_","")).replace("]","")).replace(/_/g," ");var r=RTMedia_Admin_Settings_JS.rtmedia_default_sizes_error_message;r=r.replace("[default_size_property]",t);var a=e.parents(".rtm-content").attr("id");return 0<a.length&&g("#tab-"+a).click(),i.preventDefault(),u(e,r)}});var r=jQuery('input[name^="rtmedia-options[general_videothumbs]"]');if(e&&0<r.length&&void 0!==r){t="";var a=0;if(r.val()<=0?(t+=rtmedia_admin_strings.video_thumbnail_error,a=2):n.test(r.val())||(t+=rtmedia_admin_strings.video_thumbnail_invalid_value+" "+Math.round(r.val())+".",a=Math.round(r.val())),""!==t)return alert(t),r.val(a),e=!1}var s=jQuery('input[name^="rtmedia-options[general_jpeg_image_quality]"]');if(e&&1===s.length&&void 0!==s&&(s.val()<=0?t+=rtmedia_admin_strings.jpeg_quality_negative_error:100<s.val()?t+=rtmedia_admin_strings.jpeg_quality_percentage_error:n.test(s.val())||(t+=rtmedia_admin_strings.jpeg_quality_invalid_value+" "+Math.round(s.val())+"."),""!==t)){s.next(".error_msg").remove();var o=s.parents(".rtm-content").attr("id");return 0<o.length&&g("#tab-"+o).click(),u(s,t)}var m=jQuery('input[name^="rtmedia-options[general_perPageMedia]"]');if(e&&1===m.length&&void 0!==m&&(m.val()<1?t+=rtmedia_admin_strings.per_page_media_negative_value:jQuery.isNumeric(m.val())&&Math.floor(m.val())!=m.val()&&(t+=rtmedia_admin_strings.per_page_media_positive_error+" "+Math.round(m.val())+"."),""!==t)){m.next(".error_msg").remove();var d=m.parents(".rtm-content").attr("id");return 0<d.length&&g("#tab-"+d).click(),u(m,t)}e||i.preventDefault()}),jQuery(document).on("click","#bpm-services .encoding-try-now,#rtm-services .encoding-try-now",function(e){if(e.preventDefault(),confirm(rtmedia_admin_strings.are_you_sure)){var t={src:rtmedia_admin_url+"images/wpspin_light.gif"};jQuery(this).after(rtMediaAdmin.templates.rtm_image(t));t={action:"rtmedia_free_encoding_subscribe"};jQuery.getJSON(ajaxurl,t,function(e){if(void 0===e.error&&e.apikey){var t=window.location.href,r=window.location.hash;t=t.replace(r,""),document.location.href=t+"&apikey="+e.apikey+r}else{jQuery(".encoding-try-now").next().remove(),jQuery("#settings-error-encoding-error").remove();var a={id:"settings-error-encoding-error",msg:e.error,class:"error"};i.before(rtMediaAdmin.templates.rtm_msg_div(a))}})}}),jQuery(document).on("click","#api-key-submit",function(e){if(e.preventDefault(),0==jQuery(this).next("img").length){var t={src:rtmedia_admin_url+"images/wpspin_light.gif"};jQuery(this).after(rtMediaAdmin.templates.rtm_image(t))}t={action:"rtmedia_enter_api_key",apikey:jQuery("#new-api-key").val()};jQuery.getJSON(ajaxurl,t,function(e){if(void 0===e.error&&e.apikey){var t=window.location.href,r=window.location.hash;-1===(t=t.replace(r,"")).toString().indexOf("&apikey="+e.apikey)&&(t+="&apikey="+e.apikey),-1===t.toString().indexOf("&update=true")&&(t+="&update=true"),document.location.href=t+r}else{jQuery("#settings-error-api-key-error").remove();var a={id:"settings-error-api-key-error",msg:e.error,class:"error"};jQuery("h2:first").after(rtMediaAdmin.templates.rtm_msg_div(a))}jQuery("#api-key-submit").next("img").remove()})}),jQuery(document).on("click","#disable-encoding",function(e){if(e.preventDefault(),confirm(rtmedia_admin_strings.disable_encoding)){var t={src:rtmedia_admin_url+"images/wpspin_light.gif"};jQuery(this).after(rtMediaAdmin.templates.rtm_image(t));t={action:"rtmedia_disable_encoding"};jQuery.post(ajaxurl,t,function(e){if(e){if(jQuery(".settings-error-encoding-disabled").remove(),0<jQuery("#settings-encoding-successfully-updated").length)jQuery("#settings-encoding-successfully-updated p").html(e);else{var t={id:"settings-encoding-successfully-updated",msg:e,class:"updated"};jQuery("h2:first").after(rtMediaAdmin.templates.rtm_msg_div(t))}jQuery("#rtmedia-encoding-usage").hide(),jQuery("#disable-encoding").next("img").remove(),jQuery("#disable-encoding").hide(),jQuery("#enable-encoding").show()}else{jQuery("#settings-error-encoding-disabled").remove();t={id:"settings-error-encoding-disabled",msg:rtmedia_admin_strings.something_went_wrong,class:"error"};jQuery("h2:first").after(rtMediaAdmin.templates.rtm_msg_div(t))}})}}),jQuery(document).on("click","#enable-encoding",function(e){if(e.preventDefault(),confirm(rtmedia_admin_strings.enable_encoding)){var t={src:rtmedia_admin_url+"images/wpspin_light.gif"};jQuery(this).after(rtMediaAdmin.templates.rtm_image(t));t={action:"rtmedia_enable_encoding"};jQuery.post(ajaxurl,t,function(e){if(e){if(jQuery(".settings-error-encoding-enabled").remove(),0<jQuery("#settings-encoding-successfully-updated").length)jQuery("#settings-encoding-successfully-updated p").html(e);else{var t={id:"settings-encoding-successfully-updated",msg:e,class:"updated"};jQuery("h2:first").after(rtMediaAdmin.templates.rtm_msg_div(t))}var r=jQuery("#enable-encoding");r.next("img").remove(),r.hide(),jQuery("#disable-encoding").show()}else{jQuery("#settings-error-encoding-disabled").remove();t={id:"settings-error-encoding-enabled",msg:rtmedia_admin_strings.something_went_wrong,class:"error"};jQuery("h2:first").after(rtMediaAdmin.templates.rtm_msg_div(t))}})}}),jQuery(".bp-media-encoding-table").on("click",".bpm-unsubscribe",function(e){e.preventDefault(),jQuery("#bpm-unsubscribe-dialog").dialog({dialogClass:"wp-dialog",modal:!0,buttons:{Unsubscribe:function(){jQuery(this).dialog("close");var e={src:rtmedia_admin_url+"images/wpspin_light.gif"},r=g(".bpm-unsubscribe");r.after(rtMediaAdmin.templates.rtm_image(e));e={action:"rtmedia_unsubscribe_encoding_service",note:jQuery("#bpm-unsubscribe-note").val(),plan:r.attr("data-plan"),price:r.attr("data-price")};jQuery.getJSON(ajaxurl,e,function(e){if(void 0===e.error&&e.updated){r.next().remove(),r.after(e.form),r.remove(),jQuery("#settings-unsubscribed-successfully").remove(),jQuery("#settings-unsubscribe-error").remove();var t={id:"settings-unsubscribed-successfully",msg:e.updated,class:"updated"};jQuery("h2:first").after(rtMediaAdmin.templates.rtm_msg_div(t)),window.location.hash="#settings-unsubscribed-successfully"}else{r.next().remove(),jQuery("#settings-unsubscribed-successfully").remove(),jQuery("#settings-unsubscribe-error").remove();t={id:"settings-unsubscribe-error",msg:e.error,class:"error"};jQuery("h2:first").after(rtMediaAdmin.templates.rtm_msg_div(t)),window.location.hash="#settings-unsubscribe-error"}})}}})}),jQuery("#bpmedia-bpalbumimporter").on("change","#bp-album-import-accept",function(){jQuery(".bp-album-import-accept").toggleClass("i-accept"),jQuery(".bp-album-importer-wizard").slideToggle()}),jQuery("#rtprivacyinstall").click(function(e){e.preventDefault(),$progress_parent=jQuery("#rtprivacyinstaller"),$progress_parent.find(".rtprivacytype").each(function(){if($type=jQuery(this).attr("id"),"total"===$type){$values=[],jQuery(this).find("input").each(function(){$values[jQuery(this).attr("name")]=[jQuery(this).val()]}),$data={};for(var e=1;e<=$values.steps[0];e++)$count=20,e===$values.steps[0]&&($count=parseInt($values.laststep[0]),0===$count&&($count=20)),newvals={page:e,action:"rtmedia_privacy_install",count:$count,values:$values},$data[e]=newvals;var r=jQuery.Deferred();r.resolve(),jQuery.each($data,function(e,t){r=r.pipe(function(){return function(i){return jQuery.post(ajaxurl,i,function(e){if(0!=e){var t=!1,r=Math.ceil((20*parseInt(e)+parseInt(i.values.finished))/parseInt(i.values.total)*100);100<r&&(r=100,t=!0),jQuery("#rtprogressbar>div").css("width",r+"%"),finished=jQuery("#rtprivacyinstaller span.finished").html(),jQuery("#rtprivacyinstaller span.finished").html(parseInt(finished)+i.count),t&&jQuery.post(ajaxurl,{action:"rtmedia_privacy_redirect"},function(e){window.location=settings_url})}else{var a={msg:"Row "+e+" failed."};jQuery("#map_progress_msgs").html(rtMediaAdmin.templates.rtm_map_mapping_failure(a))}})}(t)})})}})}),jQuery("#bpmedia-bpalbumimport-cleanup").click(function(e){e.preventDefault(),jQuery.post(ajaxurl,{action:"rtmedia_rt_album_cleanup",rtm_wpnonce:jQuery("#bpaimporter_wpnonce").val()},function(e){window.location=settings_rt_album_import_url})}),jQuery("#bpmedia-bpalbumimporter").on("click","#bpmedia-bpalbumimport",function(e){if(e.preventDefault(),jQuery("#bp-album-import-accept").prop("checked")){if(jQuery(this).prop("disabled",!0),wp_admin_url=ajaxurl.replace("admin-ajax.php",""),!jQuery(".bpm-ajax-loader").length){var t={src:rtmedia_admin_url+"images/wpspin_light.gif",class:"bpm-ajax-loader",norefresh:rtmedia_admin_strings.no_refresh};jQuery(this).after(rtMediaAdmin.templates.rtm_image(t))}$progress_parent=jQuery("#bpmedia-bpalbumimport"),$values=[],jQuery(this).parent().find("input").each(function(){$values[jQuery(this).attr("name")]=[jQuery(this).val()]}),0==$values.steps[0]&&($values.steps[0]=1),$data={};for(i=1;i<=$values.steps[0];i++)$count=5,i==$values.steps[0]&&($count=parseInt($values.laststep[0]),0==$count&&($count=5)),newvals={page:i,action:"rtmedia_rt_album_import",count:$count,values:$values,rtm_wpnonce:jQuery("#bpaimporter_wpnonce").val()},$data[i]=newvals;var r=jQuery.Deferred();r.resolve(),jQuery.each($data,function(e,t){r=r.pipe(function(){return n(t)})})}else{jQuery("html, body").animate({scrollTop:jQuery("#bp-album-import-accept").offset().top},500);var a=jQuery(".bp-album-import-accept"),i=3;(function e(){a.css("background-color","#EE0000"),setTimeout(function(){a.css("background-color","#FFEBE8"),--i&&setTimeout(e,500)},500)})()}}),i.on("click",".interested",function(){jQuery(".interested-container").removeClass("hidden"),jQuery(".choice-free").attr("required","required")}),i.on("click",".not-interested",function(){jQuery(".interested-container").addClass("hidden"),jQuery(".choice-free").removeAttr("required")}),jQuery("#video-transcoding-main-container").on("click",".video-transcoding-survey",function(e){e.preventDefault();var t={action:"rtmedia_convert_videos_form",email:jQuery(".email").val(),url:jQuery(".url").val(),choice:jQuery('input[name="choice"]:checked').val(),interested:jQuery('input[name="interested"]:checked').val()};return jQuery.post(ajaxurl,t,function(e){var t={msg:e,strong:"yes"};jQuery("#video-transcoding-main-container").html(rtMediaAdmin.templates.rtm_p_tag(t))}),!1}),jQuery("#bpmedia-bpalbumimporter").on("click",".deactivate-bp-album",function(e){e.preventDefault(),$bpalbum=jQuery(this);var t={action:"rtmedia_rt_album_deactivate",rtm_wpnonce:jQuery("#bpaimporter_wpnonce").val()};jQuery.get(ajaxurl,t,function(e){if(e)location.reload();else{var t={msg:rtmedia_admin_strings.something_went_wrong};$bpalbum.parent().after(rtMediaAdmin.templates.rtm_p_tag(t))}})}),jQuery(".updated").on("click",".bpm-hide-encoding-notice",function(){var e={src:rtmedia_admin_url+"images/wpspin_light.gif"};jQuery(this).after(rtMediaAdmin.templates.rtm_image(e));e={action:"rtmedia_hide_encoding_notice"};jQuery.post(ajaxurl,e,function(e){e&&jQuery(".bpm-hide-encoding-notice").closest(".updated").remove()})}),jQuery("#rtmedia-bp-enable-activity").is(":checked")?jQuery(".rtmedia-bp-activity-setting").prop("readonly",!1):jQuery(".rtmedia-bp-activity-setting").prop("readonly",!0),jQuery("#rtmedia-bp-enable-activity").on("click",function(e){jQuery(this).is(":checked")?jQuery(".rtmedia-bp-activity-setting").prop("readonly",!1):jQuery(".rtmedia-bp-activity-setting").prop("readonly",!0)});var a;function u(e,t){var r=jQuery(e);r.focus(),r.css("border-color","red");var a=r.parent();if(0<a.length&&"error_msg"!==a.attr("class")){var i=jQuery("<span />").attr("style","display:block").addClass("error_msg").html(t);r.after(i)}return return_code=!1}void 0!==rtmedia_on_label&&rtmedia_on_label,void 0!==rtmedia_off_label&&rtmedia_off_label,jQuery("input[type=file]").on("change",function(e){a=e.target.files,function(e){e.stopPropagation(),e.preventDefault();var r=new FormData;void 0!==e&&void 0!==e.target&&void 0!==e.target.name&&"rtFileInput"===e.target.name&&r.append("import_export_control",e.target.name);jQuery.each(a,function(e,t){r.append(e,t)});var t=jQuery("#rtmedia_admin_upload_nonce").val();void 0!==t&&""!==t&&r.append("rtmedia_admin_upload_nonce",t);r.append("action","rtmedia_admin_upload"),jQuery.ajax({url:rtmedia_admin_ajax,type:"POST",data:r,cache:!1,processData:!1,contentType:!1,success:function(e){if(e.hasOwnProperty("rtm_response")&&e.hasOwnProperty("rtm_response_msg")){jQuery("#rtm-setting-msg").remove();var t=jQuery("<div/>",{id:"rtm-setting-msg",class:"rtm-fly-warning"});"success"===e.rtm_response?(t.addClass("rtm-success rtm-save-settings-msg"),t.text(e.rtm_response_msg),jQuery(".rtm-button-container.top").append(t),location.reload()):"error"===e.rtm_response&&(t.addClass("rtm-warning"),t.text(e.rtm_response_msg),jQuery(".rtm-button-container.top").append(t),t.delay(3e3).fadeOut(100))}if(void 0===e.error){if(e.exceed_size_msg)return jQuery("#debuglog").val(""),alert(e.exceed_size_msg),!1;jQuery("#debuglog_temp_path").val(e.debug_attachmanet)}else jQuery("#debuglog").val(""),alert("ERRORS: "+e.error)}})}(e)}),jQuery("#rtmedia-submit-request").click(function(){var e=jQuery("#name").val(),t=jQuery("#email").val(),r=jQuery("#website").val(),a=jQuery("#subject").val(),i=jQuery("#details").val(),n=jQuery('input[name="request_type"]').val(),s=jQuery('input[name="request_id"]').val(),o=jQuery('input[name="server_address"]').val(),m=jQuery('input[name="ip_address"]').val(),d=jQuery('input[name="server_type"]').val(),u=jQuery('input[name="user_agent"]').val(),l={name:e,email:t,website:r,subject:a,details:i,request_id:s,request_type:"premium_support",server_address:o,ip_address:m,server_type:d,user_agent:u,debuglog_temp_path:jQuery('input[name="debuglog_temp_path"]').val()};if("bug_report"==n){var p=jQuery("#wp_admin_username").val();if(""===p)return alert(rtmedia_admin_support_strings.wp_admin_username_error),!1;var c=jQuery("#wp_admin_pwd").val();if(""===c)return alert(rtmedia_admin_support_strings.wp_admin_pwd_error),!1;var _=jQuery("#ssh_ftp_host").val();if(""===_)return alert(rtmedia_admin_support_strings.ssh_ftp_host_error),!1;var f=jQuery("#ssh_ftp_username").val();if(""===f)return alert(rtmedia_admin_support_strings.ssh_ftp_username_error),!1;var v=jQuery("#ssh_ftp_pwd").val();if(""===v)return alert(rtmedia_admin_support_strings.ssh_ftp_pwd_error),!1;l={name:e,email:t,website:r,subject:a,details:i,request_id:s,request_type:"premium_support",server_address:o,ip_address:m,server_type:d,user_agent:u,wp_admin_username:p,wp_admin_pwd:c,ssh_ftp_host:_,ssh_ftp_username:f,ssh_ftp_pwd:v}}for(formdata in l){if(""===l[formdata]&&"debuglog_temp_path"!==formdata)return alert("Please enter "+formdata.replace("_"," ")+" field."),!1;if(""===l[formdata]&&"debuglog_temp_path"===formdata)return alert("Please upload attachment."),!1}return data={action:"rtmedia_submit_request",form_data:l,support_wpnonce:jQuery("#support_wpnonce").val()},jQuery.post(ajaxurl,data,function(e){if("false"==(e=e.trim()))return alert(rtmedia_admin_support_strings.all_fields_error),!1;g("#rtmedia_service_contact_container").empty(),g("#rtmedia_service_contact_container").append(e)}),!1}),jQuery("#cancel-request").click(function(){return!1}),jQuery(".rtm_enable_masonry_view input[type=checkbox]").is(":checked")?jQuery(".rtm_enable_masonry_view").parents(".metabox-holder").find(".rtmedia-info").show():jQuery(".rtm_enable_masonry_view").parents(".metabox-holder").find(".rtmedia-info").hide(),jQuery(".rtm_enable_masonry_view input[type=checkbox]").on("click",function(e){jQuery(this).is(":checked")?jQuery(".rtm_enable_masonry_view").parents(".metabox-holder").find(".rtmedia-info").show():jQuery(".rtm_enable_masonry_view").parents(".metabox-holder").find(".rtmedia-info").hide()}),jQuery("#rtm-masonry-change-thumbnail-info").click(function(e){jQuery("html, body").animate({scrollTop:0},"500","swing")}),jQuery("#rtm-export-button").click(function(){data={action:"rtmedia_export_settings"},jQuery.post(ajaxurl,data,function(e){var t="data:text/json;charset=utf-8,"+encodeURIComponent(JSON.stringify(e)),r=document.createElement("a");r.setAttribute("href",t),r.setAttribute("download","rtm-settings.json"),jQuery("body").append(r),r.click(),r.remove()})}),jQuery("#rtm-export-data-button").click(function(){window.location.href="/wp-admin/tools.php?page=export_personal_data"}),jQuery("#rtm-erase-data-button").click(function(){window.location.href="/wp-admin/tools.php?page=remove_personal_data"})}),jQuery(window).load(function(){jQuery(".rtmedia-addon-thickbox").trigger("click")});
|
app/assets/admin/js/settings.js
CHANGED
@@ -11,7 +11,10 @@ rtMediaAdmin.templates = {
|
|
11 |
|
12 |
jQuery( document ).ready( function ( $ ) {
|
13 |
|
|
|
|
|
14 |
var rtm_licence = $( '#rtm-licenses' );
|
|
|
15 |
if ( rtm_licence.length > 0 ) {
|
16 |
rtm_licence.find( '.license-inner:first input:first' ).focus();
|
17 |
}
|
@@ -37,13 +40,10 @@ jQuery( document ).ready( function ( $ ) {
|
|
37 |
} );
|
38 |
|
39 |
/* Select Request */
|
40 |
-
|
41 |
-
if ( jQuery( this ).val() ) {
|
42 |
-
jQuery( '#bp_media_settings_form .bp-media-metabox-holder' ).html();
|
43 |
|
44 |
-
|
45 |
-
|
46 |
-
jQuery( '#bp_media_settings_form .bp-media-metabox-holder' ).html( support_form_loader_div );
|
47 |
var data = {
|
48 |
action: 'rtmedia_select_request',
|
49 |
form: jQuery( this ).val()
|
@@ -51,105 +51,146 @@ jQuery( document ).ready( function ( $ ) {
|
|
51 |
|
52 |
// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
|
53 |
jQuery.post( ajaxurl, data, function ( response ) {
|
54 |
-
|
55 |
-
jQuery( '#bp_media_settings_form .bp-media-metabox-holder' ).html( response ).fadeIn( 'slow' );
|
56 |
} );
|
57 |
}
|
|
|
58 |
} );
|
59 |
|
60 |
/* Cancel Request */
|
61 |
-
|
|
|
62 |
if ( jQuery( this ).val() ) {
|
63 |
-
|
64 |
|
65 |
// '<div class="support_form_loader"></div>'
|
66 |
|
67 |
-
|
68 |
var data = {
|
69 |
action: 'rtmedia_cancel_request'
|
70 |
};
|
71 |
|
72 |
// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
|
73 |
jQuery.post( ajaxurl, data, function ( response ) {
|
74 |
-
|
75 |
-
|
76 |
} );
|
77 |
}
|
|
|
78 |
} );
|
79 |
|
80 |
/* Submit Request */
|
81 |
|
82 |
-
|
83 |
var return_code = true;
|
84 |
var reg = new RegExp( '^[0-9]+$' );
|
|
|
85 |
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
}
|
94 |
} );
|
95 |
|
96 |
var general_videothumb = jQuery( 'input[name^="rtmedia-options[general_videothumbs]"]' );
|
|
|
97 |
if ( return_code && general_videothumb.length > 0 && typeof general_videothumb != "undefined" ) {
|
98 |
-
var error_msg =
|
99 |
var general_videothumb_val = 0;
|
|
|
100 |
if ( general_videothumb.val() <= 0 ) {
|
101 |
error_msg += rtmedia_admin_strings.video_thumbnail_error;
|
102 |
general_videothumb_val = 2;
|
103 |
-
} else if ( !reg.test( general_videothumb.val() ) ) {
|
104 |
error_msg += rtmedia_admin_strings.video_thumbnail_invalid_value + ' ' + Math.round( general_videothumb.val() ) + ".";
|
105 |
general_videothumb_val = Math.round( general_videothumb.val() );
|
106 |
}
|
107 |
-
|
|
|
108 |
alert( error_msg );
|
109 |
general_videothumb.val( general_videothumb_val );
|
110 |
return_code = false;
|
|
|
111 |
return false;
|
112 |
}
|
113 |
}
|
114 |
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
var general_jpeg_image_quality = jQuery( 'input[name^="rtmedia-options[general_jpeg_image_quality]"]' );
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
if ( general_jpeg_image_quality.val() <= 0 ) {
|
120 |
error_msg += rtmedia_admin_strings.jpeg_quality_negative_error;
|
121 |
-
general_jpeg_image_quality_val = 90;
|
122 |
} else if ( general_jpeg_image_quality.val() > 100 ) {
|
123 |
error_msg += rtmedia_admin_strings.jpeg_quality_percentage_error;
|
124 |
-
|
125 |
-
} else if ( !reg.test( general_jpeg_image_quality.val() ) ) {
|
126 |
error_msg += rtmedia_admin_strings.jpeg_quality_invalid_value + ' ' + Math.round( general_jpeg_image_quality.val() ) + ".";
|
127 |
-
general_jpeg_image_quality_val = Math.round( general_jpeg_image_quality.val() );
|
128 |
}
|
129 |
-
|
130 |
-
|
131 |
-
general_jpeg_image_quality.
|
132 |
-
|
133 |
-
|
|
|
|
|
|
|
|
|
|
|
134 |
}
|
135 |
}
|
136 |
|
|
|
|
|
|
|
|
|
|
|
|
|
137 |
var general_perPageMedia = jQuery( 'input[name^="rtmedia-options[general_perPageMedia]"]' );
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
if ( general_perPageMedia.val()
|
142 |
error_msg += rtmedia_admin_strings.per_page_media_negative_value;
|
143 |
-
general_perPageMedia_val = 10;
|
144 |
} else if ( jQuery.isNumeric( general_perPageMedia.val() ) && ( Math.floor( general_perPageMedia.val() ) != general_perPageMedia.val() ) ) {
|
145 |
error_msg += rtmedia_admin_strings.per_page_media_positive_error + " " + Math.round( general_perPageMedia.val() ) + ".";
|
146 |
-
general_perPageMedia_val = Math.round( general_perPageMedia.val() );
|
147 |
}
|
148 |
-
|
149 |
-
|
150 |
-
general_perPageMedia.
|
151 |
-
|
152 |
-
|
|
|
|
|
|
|
|
|
|
|
153 |
}
|
154 |
}
|
155 |
|
@@ -188,7 +229,7 @@ jQuery( document ).ready( function ( $ ) {
|
|
188 |
class : 'error'
|
189 |
};
|
190 |
|
191 |
-
|
192 |
}
|
193 |
} );
|
194 |
}
|
@@ -217,10 +258,10 @@ jQuery( document ).ready( function ( $ ) {
|
|
217 |
var hash = window.location.hash;
|
218 |
tempUrl = tempUrl.replace( hash, '' );
|
219 |
|
220 |
-
if ( tempUrl.toString().indexOf( '&apikey=' + response.apikey )
|
221 |
tempUrl += '&apikey=' + response.apikey;
|
222 |
}
|
223 |
-
if ( tempUrl.toString().indexOf( '&update=true' )
|
224 |
tempUrl += '&update=true';
|
225 |
}
|
226 |
|
@@ -292,6 +333,7 @@ jQuery( document ).ready( function ( $ ) {
|
|
292 |
|
293 |
jQuery( document ).on( 'click', '#enable-encoding', function ( e ) {
|
294 |
e.preventDefault();
|
|
|
295 |
if ( confirm( rtmedia_admin_strings.enable_encoding ) ) {
|
296 |
var data = {
|
297 |
src : rtmedia_admin_url + "images/wpspin_light.gif"
|
@@ -304,6 +346,7 @@ jQuery( document ).ready( function ( $ ) {
|
|
304 |
};
|
305 |
|
306 |
jQuery.post( ajaxurl, data, function ( response ) {
|
|
|
307 |
if ( response ) {
|
308 |
jQuery( '.settings-error-encoding-enabled' ).remove();
|
309 |
|
@@ -319,8 +362,9 @@ jQuery( document ).ready( function ( $ ) {
|
|
319 |
jQuery( 'h2:first' ).after( rtMediaAdmin.templates.rtm_msg_div( data ) );
|
320 |
}
|
321 |
|
322 |
-
jQuery( '#enable-encoding' )
|
323 |
-
|
|
|
324 |
jQuery( '#disable-encoding' ).show();
|
325 |
} else {
|
326 |
jQuery( '#settings-error-encoding-disabled' ).remove();
|
@@ -351,21 +395,23 @@ jQuery( document ).ready( function ( $ ) {
|
|
351 |
src : rtmedia_admin_url + "images/wpspin_light.gif"
|
352 |
};
|
353 |
|
354 |
-
|
|
|
|
|
355 |
|
356 |
var data = {
|
357 |
action: 'rtmedia_unsubscribe_encoding_service',
|
358 |
note: jQuery( '#bpm-unsubscribe-note' ).val(),
|
359 |
-
plan:
|
360 |
-
price:
|
361 |
};
|
362 |
|
363 |
// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
|
364 |
jQuery.getJSON( ajaxurl, data, function ( response ) {
|
365 |
if ( response.error === undefined && response.updated ) {
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
jQuery( '#settings-unsubscribed-successfully' ).remove();
|
370 |
jQuery( '#settings-unsubscribe-error' ).remove();
|
371 |
|
@@ -378,7 +424,7 @@ jQuery( document ).ready( function ( $ ) {
|
|
378 |
jQuery( 'h2:first' ).after( rtMediaAdmin.templates.rtm_msg_div( data ) );
|
379 |
window.location.hash = '#settings-unsubscribed-successfully';
|
380 |
} else {
|
381 |
-
|
382 |
jQuery( '#settings-unsubscribed-successfully' ).remove();
|
383 |
jQuery( '#settings-unsubscribe-error' ).remove();
|
384 |
|
@@ -399,9 +445,11 @@ jQuery( document ).ready( function ( $ ) {
|
|
399 |
|
400 |
function fireRequest( data ) {
|
401 |
return jQuery.post( ajaxurl, data, function ( response ) {
|
|
|
402 |
if ( response != 0 ) {
|
403 |
var redirect = false;
|
404 |
var progw = Math.ceil( ( ( ( parseInt( response ) * 20 ) + parseInt( data.values[ 'finished' ] ) ) / parseInt( data.values[ 'total' ] ) ) * 100 );
|
|
|
405 |
if ( progw > 100 ) {
|
406 |
progw = 100;
|
407 |
redirect = true
|
@@ -409,6 +457,7 @@ jQuery( document ).ready( function ( $ ) {
|
|
409 |
jQuery( '#rtprogressbar>div' ).css( 'width', progw + '%' );
|
410 |
finished = jQuery( '#rtprivacyinstaller span.finished' ).html();
|
411 |
jQuery( '#rtprivacyinstaller span.finished' ).html( parseInt( finished ) + data.count );
|
|
|
412 |
if ( redirect ) {
|
413 |
jQuery.post( ajaxurl, {
|
414 |
action: 'rtmedia_privacy_redirect'
|
@@ -436,7 +485,8 @@ jQuery( document ).ready( function ( $ ) {
|
|
436 |
$progress_parent = jQuery( '#rtprivacyinstaller' );
|
437 |
$progress_parent.find( '.rtprivacytype' ).each( function () {
|
438 |
$type = jQuery( this ).attr( 'id' );
|
439 |
-
|
|
|
440 |
$values = [];
|
441 |
jQuery( this ).find( 'input' ).each( function () {
|
442 |
|
@@ -446,12 +496,12 @@ jQuery( document ).ready( function ( $ ) {
|
|
446 |
$data = {};
|
447 |
for ( var i = 1; i <= $values[ 'steps' ][ 0 ]; i++ ) {
|
448 |
$count = 20;
|
449 |
-
if ( i
|
450 |
$count = parseInt( $values[ 'laststep' ][ 0 ] );
|
451 |
-
|
|
|
452 |
$count = 20
|
453 |
}
|
454 |
-
;
|
455 |
}
|
456 |
newvals = {
|
457 |
'page': i,
|
@@ -475,6 +525,7 @@ jQuery( document ).ready( function ( $ ) {
|
|
475 |
function fireimportRequest( data ) {
|
476 |
return jQuery.getJSON( ajaxurl, data, function ( response ) {
|
477 |
favorites = false;
|
|
|
478 |
if ( response ) {
|
479 |
var redirect = false;
|
480 |
var media_progw = Math.ceil( ( ( ( parseInt( response.page ) * 5 ) + parseInt( data.values[ 'finished' ] ) ) / parseInt( data.values[ 'total' ] ) ) * 100 );
|
@@ -485,6 +536,7 @@ jQuery( document ).ready( function ( $ ) {
|
|
485 |
users_finished = jQuery( '#bpmedia-bpalbumimporter .bp-album-users span.finished' ).html();
|
486 |
var comments_progw = Math.ceil( ( ( ( parseInt( response.comments ) ) + parseInt( comments_finished ) ) / parseInt( comments_total ) ) * 100 );
|
487 |
var users_progw = Math.ceil( ( parseInt( response.users ) / parseInt( users_total ) ) * 100 );
|
|
|
488 |
if ( media_progw > 100 || media_progw == 100 ) {
|
489 |
media_progw = 100;
|
490 |
favorites = true
|
@@ -494,34 +546,41 @@ jQuery( document ).ready( function ( $ ) {
|
|
494 |
jQuery( '.bp-album-comments #rtprogressbar>div' ).css( 'width', comments_progw + '%' );
|
495 |
jQuery( '.bp-album-users #rtprogressbar>div' ).css( 'width', users_progw + '%' );
|
496 |
media_finished = jQuery( '#bpmedia-bpalbumimporter .bp-album-media span.finished' ).html();
|
|
|
497 |
if ( parseInt( media_finished ) < parseInt( media_total ) )
|
498 |
jQuery( '#bpmedia-bpalbumimporter .bp-album-media span.finished' ).html( parseInt( media_finished ) + data.count );
|
499 |
jQuery( '#bpmedia-bpalbumimporter .bp-album-comments span.finished' ).html( parseInt( response.comments ) + parseInt( comments_finished ) );
|
500 |
jQuery( '#bpmedia-bpalbumimporter .bp-album-users span.finished' ).html( parseInt( response.users ) );
|
|
|
501 |
if ( favorites ) {
|
502 |
favorite_data = {
|
503 |
'action': 'rtmedia_rt_album_import_favorites',
|
504 |
rtm_wpnonce: jQuery('#bpaimporter_wpnonce').val()
|
505 |
-
}
|
506 |
jQuery.post( ajaxurl, favorite_data, function ( response ) {
|
|
|
507 |
if (response.hasOwnProperty(favorites) && (response.favorites !== 0 || response.favorites !== '0')) {
|
|
|
508 |
if ( !jQuery( '.bp-album-favorites' ).length ) {
|
509 |
var data = {
|
510 |
users : response.users
|
511 |
-
}
|
512 |
|
513 |
jQuery( '.bp-album-comments' ).after( rtMediaAdmin.templates.rtm_album_favourites_importer( data ) );
|
514 |
}
|
515 |
|
516 |
$favorites = {};
|
517 |
-
|
|
|
518 |
start = response.offset * 1 + 1;
|
519 |
else
|
520 |
start = 1
|
521 |
for ( var i = start; i <= response.users; i++ ) {
|
522 |
$count = 1;
|
523 |
-
|
|
|
524 |
$count = parseInt( response.users % $count );
|
|
|
525 |
if ( $count == 0 ) {
|
526 |
$count = 1;
|
527 |
}
|
@@ -529,10 +588,10 @@ jQuery( document ).ready( function ( $ ) {
|
|
529 |
|
530 |
newvals = {
|
531 |
'action': 'rtmedia_rt_album_import_step_favorites',
|
532 |
-
'offset': ( i - 1 )
|
533 |
-
'redirect': i
|
534 |
'rtm_wpnonce': jQuery('#bpaimporter_wpnonce').val()
|
535 |
-
}
|
536 |
$favorites[ i ] = newvals;
|
537 |
}
|
538 |
var $startingpoint = jQuery.Deferred();
|
@@ -548,6 +607,7 @@ jQuery( document ).ready( function ( $ ) {
|
|
548 |
}, 'json' );
|
549 |
}
|
550 |
} else {
|
|
|
551 |
if (data.hasOwnProperty(page)) {
|
552 |
var map_data = {
|
553 |
msg : "Row " + response.page + " failed."
|
@@ -572,11 +632,13 @@ jQuery( document ).ready( function ( $ ) {
|
|
572 |
favorites_finished = jQuery( '#bpmedia-bpalbumimporter .bp-album-favorites span.finished' ).html();
|
573 |
jQuery( '#bpmedia-bpalbumimporter .bp-album-favorites span.finished' ).html( parseInt( favorites_finished ) + 1 );
|
574 |
var favorites_progw = Math.ceil( ( parseInt( favorites_finished + 1 ) / parseInt( favorites_total ) ) * 100 );
|
|
|
575 |
if ( favorites_progw > 100 || favorites_progw == 100 ) {
|
576 |
favorites_progw = 100;
|
577 |
redirect = true;
|
578 |
}
|
579 |
jQuery( '.bp-album-favorites #rtprogressbar>div' ).css( 'width', favorites_progw + '%' );
|
|
|
580 |
if ( redirect ) {
|
581 |
window.setTimeout( reload_url, 2000 );
|
582 |
}
|
@@ -600,6 +662,7 @@ jQuery( document ).ready( function ( $ ) {
|
|
600 |
|
601 |
jQuery( '#bpmedia-bpalbumimporter' ).on( 'click', '#bpmedia-bpalbumimport', function ( e ) {
|
602 |
e.preventDefault();
|
|
|
603 |
if ( !jQuery( '#bp-album-import-accept' ).prop( 'checked' ) ) {
|
604 |
jQuery( 'html, body' ).animate( {
|
605 |
scrollTop: jQuery( '#bp-album-import-accept' ).offset().top
|
@@ -613,6 +676,7 @@ jQuery( document ).ready( function ( $ ) {
|
|
613 |
$el.css( "background-color", "#EE0000" );
|
614 |
setTimeout( function () {
|
615 |
$el.css( "background-color", originalColor );
|
|
|
616 |
if ( --i )
|
617 |
setTimeout( loop, x ); //restart loop
|
618 |
}, x );
|
@@ -646,6 +710,7 @@ jQuery( document ).ready( function ( $ ) {
|
|
646 |
$data = {};
|
647 |
for ( var i = 1; i <= $values[ 'steps' ][ 0 ]; i++ ) {
|
648 |
$count = 5;
|
|
|
649 |
if ( i == $values[ 'steps' ][ 0 ] ) {
|
650 |
$count = parseInt( $values[ 'laststep' ][ 0 ] );
|
651 |
if ( $count == 0 ) {
|
@@ -658,7 +723,7 @@ jQuery( document ).ready( function ( $ ) {
|
|
658 |
'count': $count,
|
659 |
'values': $values,
|
660 |
rtm_wpnonce: jQuery('#bpaimporter_wpnonce').val()
|
661 |
-
}
|
662 |
$data[ i ] = newvals;
|
663 |
}
|
664 |
var $startingpoint = jQuery.Deferred();
|
@@ -670,11 +735,11 @@ jQuery( document ).ready( function ( $ ) {
|
|
670 |
} );
|
671 |
} );
|
672 |
|
673 |
-
|
674 |
jQuery( '.interested-container' ).removeClass( 'hidden' );
|
675 |
jQuery( '.choice-free' ).attr( 'required', 'required' );
|
676 |
} );
|
677 |
-
|
678 |
jQuery( '.interested-container' ).addClass( 'hidden' );
|
679 |
jQuery( '.choice-free' ).removeAttr( 'required' );
|
680 |
} );
|
@@ -687,7 +752,7 @@ jQuery( document ).ready( function ( $ ) {
|
|
687 |
url: jQuery( '.url' ).val(),
|
688 |
choice: jQuery( 'input[name="choice"]:checked' ).val(),
|
689 |
interested: jQuery( 'input[name="interested"]:checked' ).val()
|
690 |
-
}
|
691 |
jQuery.post( ajaxurl, data, function ( response ) {
|
692 |
var p_data = {
|
693 |
msg :response,
|
@@ -696,6 +761,7 @@ jQuery( document ).ready( function ( $ ) {
|
|
696 |
|
697 |
jQuery( '#video-transcoding-main-container' ).html( rtMediaAdmin.templates.rtm_p_tag( p_data ) );
|
698 |
} );
|
|
|
699 |
return false;
|
700 |
} );
|
701 |
|
@@ -705,8 +771,9 @@ jQuery( document ).ready( function ( $ ) {
|
|
705 |
var data = {
|
706 |
action: 'rtmedia_rt_album_deactivate',
|
707 |
rtm_wpnonce: jQuery('#bpaimporter_wpnonce').val()
|
708 |
-
}
|
709 |
jQuery.get( ajaxurl, data, function ( response ) {
|
|
|
710 |
if ( response ) {
|
711 |
location.reload();
|
712 |
} else {
|
@@ -752,6 +819,7 @@ jQuery( document ).ready( function ( $ ) {
|
|
752 |
|
753 |
var onData = '';
|
754 |
var offData = '';
|
|
|
755 |
if ( rtmedia_on_label !== undefined )
|
756 |
onData = 'data-on-label="' + rtmedia_on_label + '"';
|
757 |
if ( rtmedia_off_label !== undefined )
|
@@ -794,30 +862,45 @@ jQuery( document ).ready( function ( $ ) {
|
|
794 |
user_agent: user_agent,
|
795 |
debuglog_temp_path: debuglog_temp_path
|
796 |
};
|
|
|
797 |
if ( request_type == "bug_report" ) {
|
798 |
var wp_admin_username = jQuery( '#wp_admin_username' ).val();
|
799 |
-
|
|
|
800 |
alert( rtmedia_admin_support_strings.wp_admin_username_error );
|
|
|
801 |
return false;
|
802 |
}
|
|
|
803 |
var wp_admin_pwd = jQuery( '#wp_admin_pwd' ).val();
|
804 |
-
|
|
|
805 |
alert( rtmedia_admin_support_strings.wp_admin_pwd_error );
|
|
|
806 |
return false;
|
807 |
}
|
|
|
808 |
var ssh_ftp_host = jQuery( '#ssh_ftp_host' ).val();
|
809 |
-
|
|
|
810 |
alert( rtmedia_admin_support_strings.ssh_ftp_host_error );
|
|
|
811 |
return false;
|
812 |
}
|
|
|
813 |
var ssh_ftp_username = jQuery( '#ssh_ftp_username' ).val();
|
814 |
-
|
|
|
815 |
alert( rtmedia_admin_support_strings.ssh_ftp_username_error );
|
|
|
816 |
return false;
|
817 |
}
|
|
|
818 |
var ssh_ftp_pwd = jQuery( '#ssh_ftp_pwd' ).val();
|
819 |
-
|
|
|
820 |
alert( rtmedia_admin_support_strings.ssh_ftp_pwd_error );
|
|
|
821 |
return false;
|
822 |
}
|
823 |
form_data = {
|
@@ -840,11 +923,14 @@ jQuery( document ).ready( function ( $ ) {
|
|
840 |
};
|
841 |
}
|
842 |
for ( formdata in form_data ) {
|
843 |
-
|
|
|
844 |
alert( "Please enter " + formdata.replace( "_", " " ) + " field." );
|
|
|
845 |
return false;
|
846 |
-
} else if ( form_data[ formdata ]
|
847 |
alert( "Please upload attachment." );
|
|
|
848 |
return false;
|
849 |
}
|
850 |
}
|
@@ -884,6 +970,7 @@ jQuery( document ).ready( function ( $ ) {
|
|
884 |
|
885 |
// Append nonce.
|
886 |
var rtmedia_admin_upload_nonce = jQuery( '#rtmedia_admin_upload_nonce' ).val();
|
|
|
887 |
if ( 'undefined' !== typeof rtmedia_admin_upload_nonce && '' !== rtmedia_admin_upload_nonce ) {
|
888 |
data.append( 'rtmedia_admin_upload_nonce', rtmedia_admin_upload_nonce );
|
889 |
}
|
@@ -899,6 +986,7 @@ jQuery( document ).ready( function ( $ ) {
|
|
899 |
processData: false,
|
900 |
contentType: false,
|
901 |
success: function( data ) {
|
|
|
902 |
if ( data.hasOwnProperty('rtm_response') && data.hasOwnProperty('rtm_response_msg') ) {
|
903 |
jQuery('#rtm-setting-msg').remove();
|
904 |
var setting_message = jQuery( '<div/>', {
|
@@ -906,7 +994,7 @@ jQuery( document ).ready( function ( $ ) {
|
|
906 |
'class' : 'rtm-fly-warning',
|
907 |
});
|
908 |
|
909 |
-
if( 'success' === data.rtm_response ) {
|
910 |
setting_message.addClass( 'rtm-success rtm-save-settings-msg' );
|
911 |
setting_message.text( data.rtm_response_msg );
|
912 |
jQuery('.rtm-button-container.top').append( setting_message );
|
@@ -919,7 +1007,8 @@ jQuery( document ).ready( function ( $ ) {
|
|
919 |
}
|
920 |
}
|
921 |
|
922 |
-
if( typeof data.error === 'undefined' ) {
|
|
|
923 |
if ( data.exceed_size_msg ) {
|
924 |
jQuery( '#debuglog' ).val( '' );
|
925 |
alert( data.exceed_size_msg );
|
@@ -946,11 +1035,13 @@ jQuery( document ).ready( function ( $ ) {
|
|
946 |
jQuery( '.rtm_enable_masonry_view' ).parents( '.metabox-holder' ).find( '.rtmedia-info' ).hide();
|
947 |
}
|
948 |
jQuery( '.rtm_enable_masonry_view input[type=checkbox]' ).on( "click", function ( e ) {
|
|
|
949 |
if ( jQuery( this ).is( ":checked" ) ) {
|
950 |
jQuery( '.rtm_enable_masonry_view' ).parents( '.metabox-holder' ).find( '.rtmedia-info' ).show();
|
951 |
} else {
|
952 |
jQuery( '.rtm_enable_masonry_view' ).parents( '.metabox-holder' ).find( '.rtmedia-info' ).hide();
|
953 |
}
|
|
|
954 |
} );
|
955 |
jQuery( "#rtm-masonry-change-thumbnail-info" ).click( function ( e ) {
|
956 |
jQuery( "html, body" ).animate( { scrollTop: 0 }, '500', 'swing' );
|
@@ -979,6 +1070,28 @@ jQuery( document ).ready( function ( $ ) {
|
|
979 |
window.location.href = '/wp-admin/tools.php?page=remove_personal_data';
|
980 |
});
|
981 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
982 |
} );
|
983 |
|
984 |
function rtmedia_addon_do_not_show() {
|
11 |
|
12 |
jQuery( document ).ready( function ( $ ) {
|
13 |
|
14 |
+
var bp_media_settings_box = $( '#bp-media-settings-boxes' );
|
15 |
+
var bp_media_metabox_holder = $( '#bp_media_settings_form .bp-media-metabox-holder' );
|
16 |
var rtm_licence = $( '#rtm-licenses' );
|
17 |
+
|
18 |
if ( rtm_licence.length > 0 ) {
|
19 |
rtm_licence.find( '.license-inner:first input:first' ).focus();
|
20 |
}
|
40 |
} );
|
41 |
|
42 |
/* Select Request */
|
43 |
+
bp_media_settings_box.on( 'change', '#select-request', function () {
|
|
|
|
|
44 |
|
45 |
+
if ( jQuery( this ).val() ) {
|
46 |
+
bp_media_metabox_holder.html( support_form_loader_div );
|
|
|
47 |
var data = {
|
48 |
action: 'rtmedia_select_request',
|
49 |
form: jQuery( this ).val()
|
51 |
|
52 |
// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
|
53 |
jQuery.post( ajaxurl, data, function ( response ) {
|
54 |
+
bp_media_metabox_holder.html( response ).fadeIn( 'slow' );
|
|
|
55 |
} );
|
56 |
}
|
57 |
+
|
58 |
} );
|
59 |
|
60 |
/* Cancel Request */
|
61 |
+
bp_media_settings_box.on( 'click', '#cancel-request', function () {
|
62 |
+
|
63 |
if ( jQuery( this ).val() ) {
|
64 |
+
bp_media_metabox_holder.html();
|
65 |
|
66 |
// '<div class="support_form_loader"></div>'
|
67 |
|
68 |
+
bp_media_metabox_holder.html( support_form_loader_div );
|
69 |
var data = {
|
70 |
action: 'rtmedia_cancel_request'
|
71 |
};
|
72 |
|
73 |
// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
|
74 |
jQuery.post( ajaxurl, data, function ( response ) {
|
75 |
+
bp_media_metabox_holder.html();
|
76 |
+
bp_media_metabox_holder.html( response ).fadeIn( 'slow' );
|
77 |
} );
|
78 |
}
|
79 |
+
|
80 |
} );
|
81 |
|
82 |
/* Submit Request */
|
83 |
|
84 |
+
bp_media_settings_box.on( 'submit', '#bp_media_settings_form, .rtmedia-settings-submit', function ( e ) {
|
85 |
var return_code = true;
|
86 |
var reg = new RegExp( '^[0-9]+$' );
|
87 |
+
var error_msg = '';
|
88 |
|
89 |
+
/**
|
90 |
+
* Validate the default dimensions of the 3 types of media.
|
91 |
+
* Changed the code from showing alert boxes to appending error messages to the selector.
|
92 |
+
*/
|
93 |
+
$( "input[name*='defaultSizes']" ).each( function () {
|
94 |
+
var current_element = $( this );
|
95 |
+
current_element.css( 'border-color', '#7e8993' ).next( '.error_msg' ).remove();
|
96 |
+
|
97 |
+
if ( ! reg.test( current_element.val() ) ) {
|
98 |
+
var name_attr = current_element.attr( 'name' );
|
99 |
+
name_attr = name_attr.replace( 'rtmedia-options[defaultSizes_', '' );
|
100 |
+
name_attr = name_attr.replace( ']', '' );
|
101 |
+
name_attr = name_attr.replace( /_/g, ' ' );
|
102 |
+
var error_msg = RTMedia_Admin_Settings_JS.rtmedia_default_sizes_error_message;
|
103 |
+
error_msg = error_msg.replace( '[default_size_property]', name_attr );
|
104 |
+
var current_element_parents_el = current_element.parents( '.rtm-content' ).attr( 'id' );
|
105 |
+
|
106 |
+
if ( 0 < current_element_parents_el.length ) {
|
107 |
+
$( '#tab-' + current_element_parents_el ).click();
|
108 |
+
}
|
109 |
+
|
110 |
+
e.preventDefault();
|
111 |
+
|
112 |
+
return rtp_show_error_message ( current_element, error_msg );
|
113 |
}
|
114 |
} );
|
115 |
|
116 |
var general_videothumb = jQuery( 'input[name^="rtmedia-options[general_videothumbs]"]' );
|
117 |
+
|
118 |
if ( return_code && general_videothumb.length > 0 && typeof general_videothumb != "undefined" ) {
|
119 |
+
var error_msg = '';
|
120 |
var general_videothumb_val = 0;
|
121 |
+
|
122 |
if ( general_videothumb.val() <= 0 ) {
|
123 |
error_msg += rtmedia_admin_strings.video_thumbnail_error;
|
124 |
general_videothumb_val = 2;
|
125 |
+
} else if ( ! reg.test( general_videothumb.val() ) ) {
|
126 |
error_msg += rtmedia_admin_strings.video_thumbnail_invalid_value + ' ' + Math.round( general_videothumb.val() ) + ".";
|
127 |
general_videothumb_val = Math.round( general_videothumb.val() );
|
128 |
}
|
129 |
+
|
130 |
+
if ( '' !== error_msg ) {
|
131 |
alert( error_msg );
|
132 |
general_videothumb.val( general_videothumb_val );
|
133 |
return_code = false;
|
134 |
+
|
135 |
return false;
|
136 |
}
|
137 |
}
|
138 |
|
139 |
+
/**
|
140 |
+
* Validate the media/page general setting.
|
141 |
+
* Changed the code from showing alert boxes to appending error messages to the selector.
|
142 |
+
*
|
143 |
+
* @type {jQuery|HTMLElement|Window.$.fn.init}
|
144 |
+
*/
|
145 |
var general_jpeg_image_quality = jQuery( 'input[name^="rtmedia-options[general_jpeg_image_quality]"]' );
|
146 |
+
|
147 |
+
if ( return_code && 1 === general_jpeg_image_quality.length && 'undefined' !== typeof general_jpeg_image_quality ) {
|
148 |
+
|
149 |
if ( general_jpeg_image_quality.val() <= 0 ) {
|
150 |
error_msg += rtmedia_admin_strings.jpeg_quality_negative_error;
|
|
|
151 |
} else if ( general_jpeg_image_quality.val() > 100 ) {
|
152 |
error_msg += rtmedia_admin_strings.jpeg_quality_percentage_error;
|
153 |
+
} else if ( ! reg.test( general_jpeg_image_quality.val() ) ) {
|
|
|
154 |
error_msg += rtmedia_admin_strings.jpeg_quality_invalid_value + ' ' + Math.round( general_jpeg_image_quality.val() ) + ".";
|
|
|
155 |
}
|
156 |
+
|
157 |
+
if ( '' !== error_msg ) {
|
158 |
+
general_jpeg_image_quality.next( '.error_msg' ).remove();
|
159 |
+
var general_jpeg_image_quality_parents_el = general_jpeg_image_quality.parents( '.rtm-content' ).attr( 'id' );
|
160 |
+
|
161 |
+
if ( 0 < general_jpeg_image_quality_parents_el.length ) {
|
162 |
+
$( '#tab-' + general_jpeg_image_quality_parents_el ).click();
|
163 |
+
}
|
164 |
+
|
165 |
+
return rtp_show_error_message ( general_jpeg_image_quality, error_msg );
|
166 |
}
|
167 |
}
|
168 |
|
169 |
+
/**
|
170 |
+
* Validate the media/page general setting.
|
171 |
+
* Changed the code from showing alert boxes to appending error messages to the selector.
|
172 |
+
*
|
173 |
+
* @type {jQuery}
|
174 |
+
*/
|
175 |
var general_perPageMedia = jQuery( 'input[name^="rtmedia-options[general_perPageMedia]"]' );
|
176 |
+
|
177 |
+
if ( return_code && 1 === general_perPageMedia.length && 'undefined' !== typeof general_perPageMedia ) {
|
178 |
+
|
179 |
+
if ( 1 > general_perPageMedia.val() ) {
|
180 |
error_msg += rtmedia_admin_strings.per_page_media_negative_value;
|
|
|
181 |
} else if ( jQuery.isNumeric( general_perPageMedia.val() ) && ( Math.floor( general_perPageMedia.val() ) != general_perPageMedia.val() ) ) {
|
182 |
error_msg += rtmedia_admin_strings.per_page_media_positive_error + " " + Math.round( general_perPageMedia.val() ) + ".";
|
|
|
183 |
}
|
184 |
+
|
185 |
+
if ( '' !== error_msg ) {
|
186 |
+
general_perPageMedia.next( '.error_msg' ).remove();
|
187 |
+
var general_perPageMedia_parents_el = general_perPageMedia.parents( '.rtm-content' ).attr( 'id' );
|
188 |
+
|
189 |
+
if ( 0 < general_perPageMedia_parents_el.length ) {
|
190 |
+
$( '#tab-' + general_perPageMedia_parents_el ).click();
|
191 |
+
}
|
192 |
+
|
193 |
+
return rtp_show_error_message ( general_perPageMedia, error_msg );
|
194 |
}
|
195 |
}
|
196 |
|
229 |
class : 'error'
|
230 |
};
|
231 |
|
232 |
+
bp_media_settings_box.before( rtMediaAdmin.templates.rtm_msg_div( data ) );
|
233 |
}
|
234 |
} );
|
235 |
}
|
258 |
var hash = window.location.hash;
|
259 |
tempUrl = tempUrl.replace( hash, '' );
|
260 |
|
261 |
+
if ( -1 === tempUrl.toString().indexOf( '&apikey=' + response.apikey ) ) {
|
262 |
tempUrl += '&apikey=' + response.apikey;
|
263 |
}
|
264 |
+
if ( -1 === tempUrl.toString().indexOf( '&update=true' ) ) {
|
265 |
tempUrl += '&update=true';
|
266 |
}
|
267 |
|
333 |
|
334 |
jQuery( document ).on( 'click', '#enable-encoding', function ( e ) {
|
335 |
e.preventDefault();
|
336 |
+
|
337 |
if ( confirm( rtmedia_admin_strings.enable_encoding ) ) {
|
338 |
var data = {
|
339 |
src : rtmedia_admin_url + "images/wpspin_light.gif"
|
346 |
};
|
347 |
|
348 |
jQuery.post( ajaxurl, data, function ( response ) {
|
349 |
+
|
350 |
if ( response ) {
|
351 |
jQuery( '.settings-error-encoding-enabled' ).remove();
|
352 |
|
362 |
jQuery( 'h2:first' ).after( rtMediaAdmin.templates.rtm_msg_div( data ) );
|
363 |
}
|
364 |
|
365 |
+
var enable_encoding_el = jQuery( '#enable-encoding' );
|
366 |
+
enable_encoding_el.next( 'img' ).remove();
|
367 |
+
enable_encoding_el.hide();
|
368 |
jQuery( '#disable-encoding' ).show();
|
369 |
} else {
|
370 |
jQuery( '#settings-error-encoding-disabled' ).remove();
|
395 |
src : rtmedia_admin_url + "images/wpspin_light.gif"
|
396 |
};
|
397 |
|
398 |
+
var bpm_unsubscribe = $( '.bpm-unsubscribe' );
|
399 |
+
|
400 |
+
bpm_unsubscribe.after( rtMediaAdmin.templates.rtm_image( data ) );
|
401 |
|
402 |
var data = {
|
403 |
action: 'rtmedia_unsubscribe_encoding_service',
|
404 |
note: jQuery( '#bpm-unsubscribe-note' ).val(),
|
405 |
+
plan: bpm_unsubscribe.attr( 'data-plan' ),
|
406 |
+
price: bpm_unsubscribe.attr( 'data-price' )
|
407 |
};
|
408 |
|
409 |
// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
|
410 |
jQuery.getJSON( ajaxurl, data, function ( response ) {
|
411 |
if ( response.error === undefined && response.updated ) {
|
412 |
+
bpm_unsubscribe.next().remove();
|
413 |
+
bpm_unsubscribe.after( response.form );
|
414 |
+
bpm_unsubscribe.remove();
|
415 |
jQuery( '#settings-unsubscribed-successfully' ).remove();
|
416 |
jQuery( '#settings-unsubscribe-error' ).remove();
|
417 |
|
424 |
jQuery( 'h2:first' ).after( rtMediaAdmin.templates.rtm_msg_div( data ) );
|
425 |
window.location.hash = '#settings-unsubscribed-successfully';
|
426 |
} else {
|
427 |
+
bpm_unsubscribe.next().remove();
|
428 |
jQuery( '#settings-unsubscribed-successfully' ).remove();
|
429 |
jQuery( '#settings-unsubscribe-error' ).remove();
|
430 |
|
445 |
|
446 |
function fireRequest( data ) {
|
447 |
return jQuery.post( ajaxurl, data, function ( response ) {
|
448 |
+
|
449 |
if ( response != 0 ) {
|
450 |
var redirect = false;
|
451 |
var progw = Math.ceil( ( ( ( parseInt( response ) * 20 ) + parseInt( data.values[ 'finished' ] ) ) / parseInt( data.values[ 'total' ] ) ) * 100 );
|
452 |
+
|
453 |
if ( progw > 100 ) {
|
454 |
progw = 100;
|
455 |
redirect = true
|
457 |
jQuery( '#rtprogressbar>div' ).css( 'width', progw + '%' );
|
458 |
finished = jQuery( '#rtprivacyinstaller span.finished' ).html();
|
459 |
jQuery( '#rtprivacyinstaller span.finished' ).html( parseInt( finished ) + data.count );
|
460 |
+
|
461 |
if ( redirect ) {
|
462 |
jQuery.post( ajaxurl, {
|
463 |
action: 'rtmedia_privacy_redirect'
|
485 |
$progress_parent = jQuery( '#rtprivacyinstaller' );
|
486 |
$progress_parent.find( '.rtprivacytype' ).each( function () {
|
487 |
$type = jQuery( this ).attr( 'id' );
|
488 |
+
|
489 |
+
if ( 'total' === $type ) {
|
490 |
$values = [];
|
491 |
jQuery( this ).find( 'input' ).each( function () {
|
492 |
|
496 |
$data = {};
|
497 |
for ( var i = 1; i <= $values[ 'steps' ][ 0 ]; i++ ) {
|
498 |
$count = 20;
|
499 |
+
if ( i === $values[ 'steps' ][ 0 ] ) {
|
500 |
$count = parseInt( $values[ 'laststep' ][ 0 ] );
|
501 |
+
|
502 |
+
if ( 0 === $count ) {
|
503 |
$count = 20
|
504 |
}
|
|
|
505 |
}
|
506 |
newvals = {
|
507 |
'page': i,
|
525 |
function fireimportRequest( data ) {
|
526 |
return jQuery.getJSON( ajaxurl, data, function ( response ) {
|
527 |
favorites = false;
|
528 |
+
|
529 |
if ( response ) {
|
530 |
var redirect = false;
|
531 |
var media_progw = Math.ceil( ( ( ( parseInt( response.page ) * 5 ) + parseInt( data.values[ 'finished' ] ) ) / parseInt( data.values[ 'total' ] ) ) * 100 );
|
536 |
users_finished = jQuery( '#bpmedia-bpalbumimporter .bp-album-users span.finished' ).html();
|
537 |
var comments_progw = Math.ceil( ( ( ( parseInt( response.comments ) ) + parseInt( comments_finished ) ) / parseInt( comments_total ) ) * 100 );
|
538 |
var users_progw = Math.ceil( ( parseInt( response.users ) / parseInt( users_total ) ) * 100 );
|
539 |
+
|
540 |
if ( media_progw > 100 || media_progw == 100 ) {
|
541 |
media_progw = 100;
|
542 |
favorites = true
|
546 |
jQuery( '.bp-album-comments #rtprogressbar>div' ).css( 'width', comments_progw + '%' );
|
547 |
jQuery( '.bp-album-users #rtprogressbar>div' ).css( 'width', users_progw + '%' );
|
548 |
media_finished = jQuery( '#bpmedia-bpalbumimporter .bp-album-media span.finished' ).html();
|
549 |
+
|
550 |
if ( parseInt( media_finished ) < parseInt( media_total ) )
|
551 |
jQuery( '#bpmedia-bpalbumimporter .bp-album-media span.finished' ).html( parseInt( media_finished ) + data.count );
|
552 |
jQuery( '#bpmedia-bpalbumimporter .bp-album-comments span.finished' ).html( parseInt( response.comments ) + parseInt( comments_finished ) );
|
553 |
jQuery( '#bpmedia-bpalbumimporter .bp-album-users span.finished' ).html( parseInt( response.users ) );
|
554 |
+
|
555 |
if ( favorites ) {
|
556 |
favorite_data = {
|
557 |
'action': 'rtmedia_rt_album_import_favorites',
|
558 |
rtm_wpnonce: jQuery('#bpaimporter_wpnonce').val()
|
559 |
+
};
|
560 |
jQuery.post( ajaxurl, favorite_data, function ( response ) {
|
561 |
+
|
562 |
if (response.hasOwnProperty(favorites) && (response.favorites !== 0 || response.favorites !== '0')) {
|
563 |
+
|
564 |
if ( !jQuery( '.bp-album-favorites' ).length ) {
|
565 |
var data = {
|
566 |
users : response.users
|
567 |
+
};
|
568 |
|
569 |
jQuery( '.bp-album-comments' ).after( rtMediaAdmin.templates.rtm_album_favourites_importer( data ) );
|
570 |
}
|
571 |
|
572 |
$favorites = {};
|
573 |
+
|
574 |
+
if ( 0 !== response.offset || '0' !== response.offset )
|
575 |
start = response.offset * 1 + 1;
|
576 |
else
|
577 |
start = 1
|
578 |
for ( var i = start; i <= response.users; i++ ) {
|
579 |
$count = 1;
|
580 |
+
|
581 |
+
if ( i === response.users ) {
|
582 |
$count = parseInt( response.users % $count );
|
583 |
+
|
584 |
if ( $count == 0 ) {
|
585 |
$count = 1;
|
586 |
}
|
588 |
|
589 |
newvals = {
|
590 |
'action': 'rtmedia_rt_album_import_step_favorites',
|
591 |
+
'offset': ( i - 1 ),
|
592 |
+
'redirect': i === response.users,
|
593 |
'rtm_wpnonce': jQuery('#bpaimporter_wpnonce').val()
|
594 |
+
};
|
595 |
$favorites[ i ] = newvals;
|
596 |
}
|
597 |
var $startingpoint = jQuery.Deferred();
|
607 |
}, 'json' );
|
608 |
}
|
609 |
} else {
|
610 |
+
|
611 |
if (data.hasOwnProperty(page)) {
|
612 |
var map_data = {
|
613 |
msg : "Row " + response.page + " failed."
|
632 |
favorites_finished = jQuery( '#bpmedia-bpalbumimporter .bp-album-favorites span.finished' ).html();
|
633 |
jQuery( '#bpmedia-bpalbumimporter .bp-album-favorites span.finished' ).html( parseInt( favorites_finished ) + 1 );
|
634 |
var favorites_progw = Math.ceil( ( parseInt( favorites_finished + 1 ) / parseInt( favorites_total ) ) * 100 );
|
635 |
+
|
636 |
if ( favorites_progw > 100 || favorites_progw == 100 ) {
|
637 |
favorites_progw = 100;
|
638 |
redirect = true;
|
639 |
}
|
640 |
jQuery( '.bp-album-favorites #rtprogressbar>div' ).css( 'width', favorites_progw + '%' );
|
641 |
+
|
642 |
if ( redirect ) {
|
643 |
window.setTimeout( reload_url, 2000 );
|
644 |
}
|
662 |
|
663 |
jQuery( '#bpmedia-bpalbumimporter' ).on( 'click', '#bpmedia-bpalbumimport', function ( e ) {
|
664 |
e.preventDefault();
|
665 |
+
|
666 |
if ( !jQuery( '#bp-album-import-accept' ).prop( 'checked' ) ) {
|
667 |
jQuery( 'html, body' ).animate( {
|
668 |
scrollTop: jQuery( '#bp-album-import-accept' ).offset().top
|
676 |
$el.css( "background-color", "#EE0000" );
|
677 |
setTimeout( function () {
|
678 |
$el.css( "background-color", originalColor );
|
679 |
+
|
680 |
if ( --i )
|
681 |
setTimeout( loop, x ); //restart loop
|
682 |
}, x );
|
710 |
$data = {};
|
711 |
for ( var i = 1; i <= $values[ 'steps' ][ 0 ]; i++ ) {
|
712 |
$count = 5;
|
713 |
+
|
714 |
if ( i == $values[ 'steps' ][ 0 ] ) {
|
715 |
$count = parseInt( $values[ 'laststep' ][ 0 ] );
|
716 |
if ( $count == 0 ) {
|
723 |
'count': $count,
|
724 |
'values': $values,
|
725 |
rtm_wpnonce: jQuery('#bpaimporter_wpnonce').val()
|
726 |
+
};
|
727 |
$data[ i ] = newvals;
|
728 |
}
|
729 |
var $startingpoint = jQuery.Deferred();
|
735 |
} );
|
736 |
} );
|
737 |
|
738 |
+
bp_media_settings_box.on( 'click', '.interested', function () {
|
739 |
jQuery( '.interested-container' ).removeClass( 'hidden' );
|
740 |
jQuery( '.choice-free' ).attr( 'required', 'required' );
|
741 |
} );
|
742 |
+
bp_media_settings_box.on( 'click', '.not-interested', function () {
|
743 |
jQuery( '.interested-container' ).addClass( 'hidden' );
|
744 |
jQuery( '.choice-free' ).removeAttr( 'required' );
|
745 |
} );
|
752 |
url: jQuery( '.url' ).val(),
|
753 |
choice: jQuery( 'input[name="choice"]:checked' ).val(),
|
754 |
interested: jQuery( 'input[name="interested"]:checked' ).val()
|
755 |
+
};
|
756 |
jQuery.post( ajaxurl, data, function ( response ) {
|
757 |
var p_data = {
|
758 |
msg :response,
|
761 |
|
762 |
jQuery( '#video-transcoding-main-container' ).html( rtMediaAdmin.templates.rtm_p_tag( p_data ) );
|
763 |
} );
|
764 |
+
|
765 |
return false;
|
766 |
} );
|
767 |
|
771 |
var data = {
|
772 |
action: 'rtmedia_rt_album_deactivate',
|
773 |
rtm_wpnonce: jQuery('#bpaimporter_wpnonce').val()
|
774 |
+
};
|
775 |
jQuery.get( ajaxurl, data, function ( response ) {
|
776 |
+
|
777 |
if ( response ) {
|
778 |
location.reload();
|
779 |
} else {
|
819 |
|
820 |
var onData = '';
|
821 |
var offData = '';
|
822 |
+
|
823 |
if ( rtmedia_on_label !== undefined )
|
824 |
onData = 'data-on-label="' + rtmedia_on_label + '"';
|
825 |
if ( rtmedia_off_label !== undefined )
|
862 |
user_agent: user_agent,
|
863 |
debuglog_temp_path: debuglog_temp_path
|
864 |
};
|
865 |
+
|
866 |
if ( request_type == "bug_report" ) {
|
867 |
var wp_admin_username = jQuery( '#wp_admin_username' ).val();
|
868 |
+
|
869 |
+
if ( '' === wp_admin_username ) {
|
870 |
alert( rtmedia_admin_support_strings.wp_admin_username_error );
|
871 |
+
|
872 |
return false;
|
873 |
}
|
874 |
+
|
875 |
var wp_admin_pwd = jQuery( '#wp_admin_pwd' ).val();
|
876 |
+
|
877 |
+
if ( '' === wp_admin_pwd ) {
|
878 |
alert( rtmedia_admin_support_strings.wp_admin_pwd_error );
|
879 |
+
|
880 |
return false;
|
881 |
}
|
882 |
+
|
883 |
var ssh_ftp_host = jQuery( '#ssh_ftp_host' ).val();
|
884 |
+
|
885 |
+
if ( '' === ssh_ftp_host ) {
|
886 |
alert( rtmedia_admin_support_strings.ssh_ftp_host_error );
|
887 |
+
|
888 |
return false;
|
889 |
}
|
890 |
+
|
891 |
var ssh_ftp_username = jQuery( '#ssh_ftp_username' ).val();
|
892 |
+
|
893 |
+
if ( '' === ssh_ftp_username ) {
|
894 |
alert( rtmedia_admin_support_strings.ssh_ftp_username_error );
|
895 |
+
|
896 |
return false;
|
897 |
}
|
898 |
+
|
899 |
var ssh_ftp_pwd = jQuery( '#ssh_ftp_pwd' ).val();
|
900 |
+
|
901 |
+
if ( '' === ssh_ftp_pwd ) {
|
902 |
alert( rtmedia_admin_support_strings.ssh_ftp_pwd_error );
|
903 |
+
|
904 |
return false;
|
905 |
}
|
906 |
form_data = {
|
923 |
};
|
924 |
}
|
925 |
for ( formdata in form_data ) {
|
926 |
+
|
927 |
+
if ( '' === form_data[ formdata ] && 'debuglog_temp_path' !== formdata ) {
|
928 |
alert( "Please enter " + formdata.replace( "_", " " ) + " field." );
|
929 |
+
|
930 |
return false;
|
931 |
+
} else if ( '' === form_data[ formdata ] && 'debuglog_temp_path' === formdata ) {
|
932 |
alert( "Please upload attachment." );
|
933 |
+
|
934 |
return false;
|
935 |
}
|
936 |
}
|
970 |
|
971 |
// Append nonce.
|
972 |
var rtmedia_admin_upload_nonce = jQuery( '#rtmedia_admin_upload_nonce' ).val();
|
973 |
+
|
974 |
if ( 'undefined' !== typeof rtmedia_admin_upload_nonce && '' !== rtmedia_admin_upload_nonce ) {
|
975 |
data.append( 'rtmedia_admin_upload_nonce', rtmedia_admin_upload_nonce );
|
976 |
}
|
986 |
processData: false,
|
987 |
contentType: false,
|
988 |
success: function( data ) {
|
989 |
+
|
990 |
if ( data.hasOwnProperty('rtm_response') && data.hasOwnProperty('rtm_response_msg') ) {
|
991 |
jQuery('#rtm-setting-msg').remove();
|
992 |
var setting_message = jQuery( '<div/>', {
|
994 |
'class' : 'rtm-fly-warning',
|
995 |
});
|
996 |
|
997 |
+
if ( 'success' === data.rtm_response ) {
|
998 |
setting_message.addClass( 'rtm-success rtm-save-settings-msg' );
|
999 |
setting_message.text( data.rtm_response_msg );
|
1000 |
jQuery('.rtm-button-container.top').append( setting_message );
|
1007 |
}
|
1008 |
}
|
1009 |
|
1010 |
+
if ( typeof data.error === 'undefined' ) {
|
1011 |
+
|
1012 |
if ( data.exceed_size_msg ) {
|
1013 |
jQuery( '#debuglog' ).val( '' );
|
1014 |
alert( data.exceed_size_msg );
|
1035 |
jQuery( '.rtm_enable_masonry_view' ).parents( '.metabox-holder' ).find( '.rtmedia-info' ).hide();
|
1036 |
}
|
1037 |
jQuery( '.rtm_enable_masonry_view input[type=checkbox]' ).on( "click", function ( e ) {
|
1038 |
+
|
1039 |
if ( jQuery( this ).is( ":checked" ) ) {
|
1040 |
jQuery( '.rtm_enable_masonry_view' ).parents( '.metabox-holder' ).find( '.rtmedia-info' ).show();
|
1041 |
} else {
|
1042 |
jQuery( '.rtm_enable_masonry_view' ).parents( '.metabox-holder' ).find( '.rtmedia-info' ).hide();
|
1043 |
}
|
1044 |
+
|
1045 |
} );
|
1046 |
jQuery( "#rtm-masonry-change-thumbnail-info" ).click( function ( e ) {
|
1047 |
jQuery( "html, body" ).animate( { scrollTop: 0 }, '500', 'swing' );
|
1070 |
window.location.href = '/wp-admin/tools.php?page=remove_personal_data';
|
1071 |
});
|
1072 |
|
1073 |
+
/**
|
1074 |
+
* This appends the error message to the received selector, showing that the validation has failed.
|
1075 |
+
*
|
1076 |
+
* @param selector
|
1077 |
+
* @param error_msg
|
1078 |
+
* @returns {boolean}
|
1079 |
+
*/
|
1080 |
+
function rtp_show_error_message( selector, error_msg ) {
|
1081 |
+
var elm_selector = jQuery( selector );
|
1082 |
+
elm_selector.focus();
|
1083 |
+
elm_selector.css( 'border-color', 'red' );
|
1084 |
+
var elm_selector_parent = elm_selector.parent();
|
1085 |
+
|
1086 |
+
if ( elm_selector_parent.length > 0 && 'error_msg' !== elm_selector_parent.attr( 'class' ) ) {
|
1087 |
+
var invalid_error_msg = jQuery( "<span />" ).attr( 'style', 'display:block' ).addClass( 'error_msg' ).html( error_msg );
|
1088 |
+
elm_selector.after( invalid_error_msg );
|
1089 |
+
}
|
1090 |
+
return_code = false;
|
1091 |
+
|
1092 |
+
return false;
|
1093 |
+
}
|
1094 |
+
|
1095 |
} );
|
1096 |
|
1097 |
function rtmedia_addon_do_not_show() {
|
app/assets/js/admin-upload-terms.js
CHANGED
@@ -10,70 +10,87 @@
|
|
10 |
* By: Yahil and Malav
|
11 |
*/
|
12 |
jQuery( document ).ready( function ( $ ) {
|
13 |
-
|
14 |
-
var
|
15 |
-
var
|
16 |
-
var
|
17 |
-
var
|
18 |
-
var
|
19 |
-
var
|
|
|
|
|
20 |
|
21 |
rtp_terms_option_toggle();
|
22 |
-
|
|
|
23 |
rtp_terms_option_toggle();
|
24 |
} );
|
25 |
-
|
26 |
-
|
|
|
|
|
27 |
|
28 |
if (return_code && general_enable_upload_terms.length > 0 && 'undefined' !== typeof general_enable_upload_terms ||
|
29 |
return_code && activity_enable_upload_terms.length > 0 && typeof 'undefined' !== activity_enable_upload_terms ) {
|
30 |
-
|
31 |
if ( true === general_enable_upload_terms.prop( 'checked' ) || true === activity_enable_upload_terms.prop( 'checked' ) ) {
|
32 |
-
|
33 |
-
|
|
|
34 |
if ( !/^(http|https|ftp):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/i.test( general_upload_terms_page_link.val() ) ) {
|
35 |
-
error_msg
|
|
|
36 |
return rtp_show_error_message ( general_upload_terms_page_link, error_msg );
|
37 |
}
|
38 |
|
39 |
-
/* Check "Terms of Service Message"
|
40 |
if ( '' === general_upload_terms_message.val().trim() ) {
|
41 |
-
error_msg
|
|
|
42 |
return rtp_show_error_message ( general_upload_terms_message, error_msg );
|
43 |
}
|
44 |
|
45 |
-
/* Check "Error Message"
|
46 |
if ( '' === general_upload_terms_error_message.val().trim() ) {
|
47 |
-
error_msg
|
|
|
48 |
return rtp_show_error_message ( general_upload_terms_error_message, error_msg );
|
49 |
}
|
50 |
}
|
|
|
51 |
}
|
|
|
52 |
if ( return_code && general_upload_terms_show_pricacy_message.length > 0 && 'undefined' !== typeof general_upload_terms_show_pricacy_message ) {
|
53 |
-
|
54 |
if ( general_upload_terms_show_pricacy_message.prop( 'checked' ) ) {
|
55 |
-
|
|
|
|
|
|
|
|
|
56 |
|
57 |
-
/* Check "Terms of Service Message" Emply Or Not */
|
58 |
-
if ( general_upload_terms_privacy_message.val().trim() == '' ) {
|
59 |
-
error_msg += rtm_upload_terms_error_msgs.privacy_msg;
|
60 |
return rtp_show_error_message ( general_upload_terms_privacy_message, error_msg );
|
61 |
}
|
62 |
}
|
|
|
63 |
}
|
64 |
} );
|
65 |
|
66 |
/* Show Error Message If Incorrect Validation */
|
67 |
function rtp_show_error_message( selector, error_msg ) {
|
68 |
-
|
|
|
69 |
elm_selector.focus();
|
70 |
elm_selector.css( 'border-color', 'red' );
|
|
|
71 |
if ( elm_selector.parent().length > 0 && 'error_msg' !== elm_selector.parent().attr( 'class' ) ) {
|
72 |
-
var invalid_error_msg =
|
73 |
elm_selector.after( invalid_error_msg );
|
74 |
}
|
75 |
return_code = false;
|
|
|
76 |
return false;
|
|
|
77 |
}
|
78 |
|
79 |
/**
|
@@ -82,22 +99,24 @@ jQuery( document ).ready( function ( $ ) {
|
|
82 |
* By: Yahil And Malav
|
83 |
*/
|
84 |
function rtp_terms_option_toggle() {
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
|
|
97 |
general_upload_terms_privacy_message.closest( '.form-table' ).slideDown();
|
98 |
-
|
99 |
general_upload_terms_privacy_message.closest( '.form-table' ).slideUp();
|
100 |
-
|
|
|
101 |
}
|
102 |
-
});
|
103 |
|
|
10 |
* By: Yahil and Malav
|
11 |
*/
|
12 |
jQuery( document ).ready( function ( $ ) {
|
13 |
+
|
14 |
+
var general_enable_upload_terms = $( 'input[name^="rtmedia-options[general_enable_upload_terms]"]' );
|
15 |
+
var activity_enable_upload_terms = $( 'input[name^="rtmedia-options[activity_enable_upload_terms]"]' );
|
16 |
+
var general_upload_terms_page_link = $( 'input[name^="rtmedia-options[general_upload_terms_page_link]"]' );
|
17 |
+
var general_upload_terms_message = $( 'input[name^="rtmedia-options[general_upload_terms_message]"]' );
|
18 |
+
var general_upload_terms_error_message = $( 'input[name^="rtmedia-options[general_upload_terms_error_message]"]' );
|
19 |
+
var general_upload_terms_show_pricacy_message = $( 'input[name^="rtmedia-options[general_upload_terms_show_pricacy_message]"]' );
|
20 |
+
var general_upload_terms_privacy_message = $( 'textarea[name^="rtmedia-options[general_upload_terms_privacy_message]"]' );
|
21 |
+
var return_code = true;
|
22 |
|
23 |
rtp_terms_option_toggle();
|
24 |
+
|
25 |
+
$( 'input[name^="rtmedia-options[general_enable_upload_terms]"], input[name^="rtmedia-options[activity_enable_upload_terms]"], input[name^="rtmedia-options[general_upload_terms_show_pricacy_message]"]' ).change( function () {
|
26 |
rtp_terms_option_toggle();
|
27 |
} );
|
28 |
+
|
29 |
+
$( '#bp-media-settings-boxes' ).on( 'submit', '#bp_media_settings_form, .rtmedia-settings-submit', function () {
|
30 |
+
|
31 |
+
var error_msg = '';
|
32 |
|
33 |
if (return_code && general_enable_upload_terms.length > 0 && 'undefined' !== typeof general_enable_upload_terms ||
|
34 |
return_code && activity_enable_upload_terms.length > 0 && typeof 'undefined' !== activity_enable_upload_terms ) {
|
35 |
+
|
36 |
if ( true === general_enable_upload_terms.prop( 'checked' ) || true === activity_enable_upload_terms.prop( 'checked' ) ) {
|
37 |
+
$( '.error_msg' ).remove();
|
38 |
+
$( '.rtm-form-text' ).css( 'border-color', '#ddd' );
|
39 |
+
|
40 |
if ( !/^(http|https|ftp):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/i.test( general_upload_terms_page_link.val() ) ) {
|
41 |
+
error_msg = rtm_upload_terms_error_msgs.valid_url;
|
42 |
+
|
43 |
return rtp_show_error_message ( general_upload_terms_page_link, error_msg );
|
44 |
}
|
45 |
|
46 |
+
/* Check "Terms of Service Message" Empty Or Not */
|
47 |
if ( '' === general_upload_terms_message.val().trim() ) {
|
48 |
+
error_msg = rtm_upload_terms_error_msgs.terms_msg;
|
49 |
+
|
50 |
return rtp_show_error_message ( general_upload_terms_message, error_msg );
|
51 |
}
|
52 |
|
53 |
+
/* Check "Error Message" Empty Or Not */
|
54 |
if ( '' === general_upload_terms_error_message.val().trim() ) {
|
55 |
+
error_msg = rtm_upload_terms_error_msgs.error_msg;
|
56 |
+
|
57 |
return rtp_show_error_message ( general_upload_terms_error_message, error_msg );
|
58 |
}
|
59 |
}
|
60 |
+
|
61 |
}
|
62 |
+
|
63 |
if ( return_code && general_upload_terms_show_pricacy_message.length > 0 && 'undefined' !== typeof general_upload_terms_show_pricacy_message ) {
|
64 |
+
|
65 |
if ( general_upload_terms_show_pricacy_message.prop( 'checked' ) ) {
|
66 |
+
$( '.error_msg' ).remove();
|
67 |
+
|
68 |
+
/* Check "Terms of Service Message" Empty Or Not */
|
69 |
+
if ( '' === general_upload_terms_privacy_message.val().trim() ) {
|
70 |
+
error_msg = rtm_upload_terms_error_msgs.privacy_msg;
|
71 |
|
|
|
|
|
|
|
72 |
return rtp_show_error_message ( general_upload_terms_privacy_message, error_msg );
|
73 |
}
|
74 |
}
|
75 |
+
|
76 |
}
|
77 |
} );
|
78 |
|
79 |
/* Show Error Message If Incorrect Validation */
|
80 |
function rtp_show_error_message( selector, error_msg ) {
|
81 |
+
|
82 |
+
var elm_selector = $( selector );
|
83 |
elm_selector.focus();
|
84 |
elm_selector.css( 'border-color', 'red' );
|
85 |
+
|
86 |
if ( elm_selector.parent().length > 0 && 'error_msg' !== elm_selector.parent().attr( 'class' ) ) {
|
87 |
+
var invalid_error_msg = $( '<span />' ).css( 'display', 'block' ).addClass( 'error_msg' ).html( error_msg );
|
88 |
elm_selector.after( invalid_error_msg );
|
89 |
}
|
90 |
return_code = false;
|
91 |
+
|
92 |
return false;
|
93 |
+
|
94 |
}
|
95 |
|
96 |
/**
|
99 |
* By: Yahil And Malav
|
100 |
*/
|
101 |
function rtp_terms_option_toggle() {
|
102 |
+
|
103 |
+
if ( true === general_enable_upload_terms.prop( 'checked' ) || true === activity_enable_upload_terms.prop( 'checked' ) ) {
|
104 |
+
general_upload_terms_page_link.closest( '.form-table' ).slideDown();
|
105 |
+
general_upload_terms_message.closest( '.form-table' ).slideDown();
|
106 |
+
general_upload_terms_error_message.closest( '.form-table' ).slideDown();
|
107 |
+
} else {
|
108 |
+
general_upload_terms_page_link.closest( '.form-table' ).slideUp();
|
109 |
+
general_upload_terms_message.closest( '.form-table' ).slideUp();
|
110 |
+
general_upload_terms_error_message.closest( '.form-table' ).slideUp();
|
111 |
+
}
|
112 |
+
|
113 |
+
// Show privacy message
|
114 |
+
if ( true === general_upload_terms_show_pricacy_message.prop( 'checked' ) ) {
|
115 |
general_upload_terms_privacy_message.closest( '.form-table' ).slideDown();
|
116 |
+
} else {
|
117 |
general_upload_terms_privacy_message.closest( '.form-table' ).slideUp();
|
118 |
+
}
|
119 |
+
|
120 |
}
|
|
|
121 |
|
122 |
+
});
|
app/assets/js/admin-upload-terms.min.js
CHANGED
@@ -3,4 +3,4 @@
|
|
3 |
* @package rtMedia
|
4 |
*/
|
5 |
|
6 |
-
jQuery(document).ready(function(
|
3 |
* @package rtMedia
|
4 |
*/
|
5 |
|
6 |
+
jQuery(document).ready(function(a){var r=a('input[name^="rtmedia-options[general_enable_upload_terms]"]'),t=a('input[name^="rtmedia-options[activity_enable_upload_terms]"]'),s=a('input[name^="rtmedia-options[general_upload_terms_page_link]"]'),o=a('input[name^="rtmedia-options[general_upload_terms_message]"]'),m=a('input[name^="rtmedia-options[general_upload_terms_error_message]"]'),n=a('input[name^="rtmedia-options[general_upload_terms_show_pricacy_message]"]'),i=a('textarea[name^="rtmedia-options[general_upload_terms_privacy_message]"]'),l=!0;function _(e,r){var t=a(e);if(t.focus(),t.css("border-color","red"),0<t.parent().length&&"error_msg"!==t.parent().attr("class")){var s=a("<span />").css("display","block").addClass("error_msg").html(r);t.after(s)}return l=!1}function e(){!0===r.prop("checked")||!0===t.prop("checked")?(s.closest(".form-table").slideDown(),o.closest(".form-table").slideDown(),m.closest(".form-table").slideDown()):(s.closest(".form-table").slideUp(),o.closest(".form-table").slideUp(),m.closest(".form-table").slideUp()),!0===n.prop("checked")?i.closest(".form-table").slideDown():i.closest(".form-table").slideUp()}e(),a('input[name^="rtmedia-options[general_enable_upload_terms]"], input[name^="rtmedia-options[activity_enable_upload_terms]"], input[name^="rtmedia-options[general_upload_terms_show_pricacy_message]"]').change(function(){e()}),a("#bp-media-settings-boxes").on("submit","#bp_media_settings_form, .rtmedia-settings-submit",function(){var e="";if((l&&0<r.length&&void 0!==r||l&&0<t.length&&"string"!==t)&&(!0===r.prop("checked")||!0===t.prop("checked"))){if(a(".error_msg").remove(),a(".rtm-form-text").css("border-color","#ddd"),!/^(http|https|ftp):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/i.test(s.val()))return e=rtm_upload_terms_error_msgs.valid_url,_(s,e);if(""===o.val().trim())return e=rtm_upload_terms_error_msgs.terms_msg,_(o,e);if(""===m.val().trim())return e=rtm_upload_terms_error_msgs.error_msg,_(m,e)}if(l&&0<n.length&&void 0!==n&&n.prop("checked")&&(a(".error_msg").remove(),""===i.val().trim()))return e=rtm_upload_terms_error_msgs.privacy_msg,_(i,e)})});
|
app/assets/js/rtMedia.backbone.js
CHANGED
@@ -5,6 +5,7 @@ var activity_id = -1;
|
|
5 |
var uploaderObj;
|
6 |
var objUploadView;
|
7 |
var rtmedia_load_template_flag = true;
|
|
|
8 |
|
9 |
|
10 |
jQuery( function( $ ) {
|
@@ -744,7 +745,7 @@ jQuery( function( $ ) {
|
|
744 |
rtMediaHook.call( 'rtmedia_js_after_files_added', [ up, files ] );
|
745 |
|
746 |
if ( typeof rtmedia_direct_upload_enabled != 'undefined' && rtmedia_direct_upload_enabled == '1' ) {
|
747 |
-
var allow_upload = rtMediaHook.call( 'rtmedia_js_upload_file',
|
748 |
if ( allow_upload == false ) {
|
749 |
return false;
|
750 |
}
|
@@ -796,7 +797,7 @@ jQuery( function( $ ) {
|
|
796 |
* To check if any media file is selected or not for uploading
|
797 |
*/
|
798 |
if ( jQuery( '#rtmedia_uploader_filelist' ).children( 'li' ).length > 0 ) {
|
799 |
-
var allow_upload = rtMediaHook.call( 'rtmedia_js_upload_file',
|
800 |
|
801 |
if ( allow_upload == false ) {
|
802 |
return false;
|
@@ -829,6 +830,9 @@ jQuery( function( $ ) {
|
|
829 |
} );
|
830 |
|
831 |
uploaderObj.uploader.bind( 'BeforeUpload', function( up, file ) {
|
|
|
|
|
|
|
832 |
up.settings.multipart_params.title = file.title.split( '.' )[ 0 ];
|
833 |
|
834 |
if ( typeof file.description != 'undefined' ) {
|
@@ -1100,12 +1104,16 @@ jQuery( document ).ready( function( $ ) {
|
|
1100 |
}
|
1101 |
var activity_attachemnt_ids = [ ];
|
1102 |
|
1103 |
-
if (
|
|
|
|
|
|
|
|
|
1104 |
objUploadView = new UploadView( rtMedia_update_plupload_config );
|
1105 |
objUploadView.initUploader();
|
1106 |
|
1107 |
setTimeout( function() {
|
1108 |
-
if (
|
1109 |
$( '#whats-new-options' ).prepend( $( '#whats-new-form .rtmedia-plupload-container' ) );
|
1110 |
if ( $( '#whats-new-form #rtm-file_upload-ui .privacy' ).length > 0 ) {
|
1111 |
$( '#whats-new-form .rtmedia-plupload-container' ).append( $( '#whats-new-form #rtm-file_upload-ui .privacy' ) );
|
@@ -1138,7 +1146,10 @@ jQuery( document ).ready( function( $ ) {
|
|
1138 |
}
|
1139 |
}
|
1140 |
|
1141 |
-
|
|
|
|
|
|
|
1142 |
objUploadView.uploader.refresh();
|
1143 |
$( '#rtmedia-whts-new-upload-container > div' ).css( 'top', '0' );
|
1144 |
$( '#rtmedia-whts-new-upload-container > div' ).css( 'left', '0' );
|
@@ -1318,7 +1329,7 @@ jQuery( document ).ready( function( $ ) {
|
|
1318 |
}
|
1319 |
}
|
1320 |
//Call upload event direct when direct upload is enabled (removed UPLOAD button and its triggered event)
|
1321 |
-
var allow_upload = rtMediaHook.call( 'rtmedia_js_upload_file',
|
1322 |
|
1323 |
if ( allow_upload == false ) {
|
1324 |
return false;
|
@@ -1400,6 +1411,8 @@ jQuery( document ).ready( function( $ ) {
|
|
1400 |
} );
|
1401 |
|
1402 |
objUploadView.uploader.bind( 'BeforeUpload', function( up, files ) {
|
|
|
|
|
1403 |
|
1404 |
$.each( objUploadView.upload_remove_array, function( i, rfile ) {
|
1405 |
if ( up.getFile( rfile ) ) {
|
@@ -1561,7 +1574,16 @@ jQuery( document ).ready( function( $ ) {
|
|
1561 |
}
|
1562 |
if ( ! media_uploading && objUploadView.uploader.files.length > 0 ) {
|
1563 |
$( '#whats-new-post-in' ).attr( 'disabled', 'disabled' );
|
1564 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1565 |
objUploadView.uploadFiles();
|
1566 |
media_uploading = true;
|
1567 |
return false;
|
@@ -1585,6 +1607,11 @@ jQuery( document ).ready( function( $ ) {
|
|
1585 |
$( 'div.activity' ).bind( 'fadeIn', function() {
|
1586 |
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' ) );
|
1587 |
rtMediaHook.call( 'rtmedia_js_after_activity_added', [ ] );
|
|
|
|
|
|
|
|
|
|
|
1588 |
} );
|
1589 |
$( 'div.activity' ).fadeIn( 100 );
|
1590 |
}
|
@@ -1613,12 +1640,19 @@ jQuery( document ).ready( function( $ ) {
|
|
1613 |
jQuery( '.plupload_filelist_content.rtm-plupload-list' ).html('');
|
1614 |
|
1615 |
rtMediaHook.call( 'rtmedia_js_after_activity_added', [ ] );
|
|
|
|
|
|
|
|
|
1616 |
}
|
1617 |
|
1618 |
rtmedia_on_activity_add();
|
1619 |
|
1620 |
$( '#whats-new-post-in' ).removeAttr( 'disabled' );
|
1621 |
-
|
|
|
|
|
|
|
1622 |
// Enabled TextBox color back to normal
|
1623 |
$( '#whats-new' ).css( 'color', '' );
|
1624 |
|
@@ -1786,7 +1820,7 @@ jQuery( document ).ready( function( $ ) {
|
|
1786 |
$( document ).on( 'click', '.rtmedia-like', function( e ) {
|
1787 |
e.preventDefault();
|
1788 |
var that = this;
|
1789 |
-
var like_nonce = $(
|
1790 |
$( this ).attr( 'disabled', 'disabled' );
|
1791 |
var url = $( this ).parent().attr( 'action' );
|
1792 |
$( that ).prepend( '<img class=\'rtm-like-loading\' src=\'' + rMedia_loading_file + '\' style=\'width:10px\' />' );
|
@@ -1895,6 +1929,10 @@ function rtmedia_selected_file_list( plupload, file, uploader, error, comment_me
|
|
1895 |
|
1896 |
new_button.on( 'click', function ( e ) {
|
1897 |
|
|
|
|
|
|
|
|
|
1898 |
if ( rtMediaHook.call( 'rtmedia_js_before_activity_added', { src: 'activity' } ) ) {
|
1899 |
objUploadView.uploadFiles( e );
|
1900 |
}
|
5 |
var uploaderObj;
|
6 |
var objUploadView;
|
7 |
var rtmedia_load_template_flag = true;
|
8 |
+
var rtmedia_add_media_button_post_update = false;
|
9 |
|
10 |
|
11 |
jQuery( function( $ ) {
|
745 |
rtMediaHook.call( 'rtmedia_js_after_files_added', [ up, files ] );
|
746 |
|
747 |
if ( typeof rtmedia_direct_upload_enabled != 'undefined' && rtmedia_direct_upload_enabled == '1' ) {
|
748 |
+
var allow_upload = rtMediaHook.call( 'rtmedia_js_upload_file', { src: 'uploader' } );
|
749 |
if ( allow_upload == false ) {
|
750 |
return false;
|
751 |
}
|
797 |
* To check if any media file is selected or not for uploading
|
798 |
*/
|
799 |
if ( jQuery( '#rtmedia_uploader_filelist' ).children( 'li' ).length > 0 ) {
|
800 |
+
var allow_upload = rtMediaHook.call( 'rtmedia_js_upload_file', { src: 'uploader' } );
|
801 |
|
802 |
if ( allow_upload == false ) {
|
803 |
return false;
|
830 |
} );
|
831 |
|
832 |
uploaderObj.uploader.bind( 'BeforeUpload', function( up, file ) {
|
833 |
+
// We send terms conditions data on backend to validate this on server side.
|
834 |
+
rtMediaHook.call( 'rtmedia_js_before_upload', { uploader: up, file: file, src: 'uploader' } );
|
835 |
+
|
836 |
up.settings.multipart_params.title = file.title.split( '.' )[ 0 ];
|
837 |
|
838 |
if ( typeof file.description != 'undefined' ) {
|
1104 |
}
|
1105 |
var activity_attachemnt_ids = [ ];
|
1106 |
|
1107 |
+
if ( ! rtmedia_add_media_button_post_update ) {
|
1108 |
+
rtmedia_add_media_button_post_update = $( '#rtmedia-add-media-button-post-update' );
|
1109 |
+
}
|
1110 |
+
|
1111 |
+
if ( rtmedia_add_media_button_post_update.length > 0 ) {
|
1112 |
objUploadView = new UploadView( rtMedia_update_plupload_config );
|
1113 |
objUploadView.initUploader();
|
1114 |
|
1115 |
setTimeout( function() {
|
1116 |
+
if ( rtmedia_add_media_button_post_update.length > 0 ) {
|
1117 |
$( '#whats-new-options' ).prepend( $( '#whats-new-form .rtmedia-plupload-container' ) );
|
1118 |
if ( $( '#whats-new-form #rtm-file_upload-ui .privacy' ).length > 0 ) {
|
1119 |
$( '#whats-new-form .rtmedia-plupload-container' ).append( $( '#whats-new-form #rtm-file_upload-ui .privacy' ) );
|
1146 |
}
|
1147 |
}
|
1148 |
|
1149 |
+
if ( ! rtmedia_add_media_button_post_update ) {
|
1150 |
+
rtmedia_add_media_button_post_update = $( '#rtmedia-add-media-button-post-update' );
|
1151 |
+
}
|
1152 |
+
$( '#whats-new-form' ).on( 'click', rtmedia_add_media_button_post_update, function( e ) {
|
1153 |
objUploadView.uploader.refresh();
|
1154 |
$( '#rtmedia-whts-new-upload-container > div' ).css( 'top', '0' );
|
1155 |
$( '#rtmedia-whts-new-upload-container > div' ).css( 'left', '0' );
|
1329 |
}
|
1330 |
}
|
1331 |
//Call upload event direct when direct upload is enabled (removed UPLOAD button and its triggered event)
|
1332 |
+
var allow_upload = rtMediaHook.call( 'rtmedia_js_upload_file', { src: 'activity' } );
|
1333 |
|
1334 |
if ( allow_upload == false ) {
|
1335 |
return false;
|
1411 |
} );
|
1412 |
|
1413 |
objUploadView.uploader.bind( 'BeforeUpload', function( up, files ) {
|
1414 |
+
// We send terms conditions data on backend to validate this on server side.
|
1415 |
+
rtMediaHook.call( 'rtmedia_js_before_upload', { uploader: up, file: files, src: 'activity' } );
|
1416 |
|
1417 |
$.each( objUploadView.upload_remove_array, function( i, rfile ) {
|
1418 |
if ( up.getFile( rfile ) ) {
|
1574 |
}
|
1575 |
if ( ! media_uploading && objUploadView.uploader.files.length > 0 ) {
|
1576 |
$( '#whats-new-post-in' ).attr( 'disabled', 'disabled' );
|
1577 |
+
if ( ! rtmedia_add_media_button_post_update ) {
|
1578 |
+
rtmedia_add_media_button_post_update = $( '#rtmedia-add-media-button-post-update' );
|
1579 |
+
}
|
1580 |
+
rtmedia_add_media_button_post_update.attr( 'disabled', 'disabled' );
|
1581 |
+
|
1582 |
+
var terms_condition_cb = $( '#rtmedia_upload_terms_conditions' );
|
1583 |
+
if ( terms_condition_cb.prop( 'checked' ) ) {
|
1584 |
+
terms_condition_cb.prop( 'disabled', true );
|
1585 |
+
}
|
1586 |
+
|
1587 |
objUploadView.uploadFiles();
|
1588 |
media_uploading = true;
|
1589 |
return false;
|
1607 |
$( 'div.activity' ).bind( 'fadeIn', function() {
|
1608 |
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' ) );
|
1609 |
rtMediaHook.call( 'rtmedia_js_after_activity_added', [ ] );
|
1610 |
+
if ( ! rtmedia_add_media_button_post_update ) {
|
1611 |
+
rtmedia_add_media_button_post_update = jQuery( '#rtmedia-add-media-button-post-update' );
|
1612 |
+
}
|
1613 |
+
|
1614 |
+
rtmedia_add_media_button_post_update.removeAttr( 'disabled' );
|
1615 |
} );
|
1616 |
$( 'div.activity' ).fadeIn( 100 );
|
1617 |
}
|
1640 |
jQuery( '.plupload_filelist_content.rtm-plupload-list' ).html('');
|
1641 |
|
1642 |
rtMediaHook.call( 'rtmedia_js_after_activity_added', [ ] );
|
1643 |
+
if ( ! rtmedia_add_media_button_post_update ) {
|
1644 |
+
rtmedia_add_media_button_post_update = jQuery( '#rtmedia-add-media-button-post-update' );
|
1645 |
+
}
|
1646 |
+
rtmedia_add_media_button_post_update.removeAttr( 'disabled' );
|
1647 |
}
|
1648 |
|
1649 |
rtmedia_on_activity_add();
|
1650 |
|
1651 |
$( '#whats-new-post-in' ).removeAttr( 'disabled' );
|
1652 |
+
if ( ! rtmedia_add_media_button_post_update ) {
|
1653 |
+
rtmedia_add_media_button_post_update = $( '#rtmedia-add-media-button-post-update' );
|
1654 |
+
}
|
1655 |
+
rtmedia_add_media_button_post_update.removeAttr( 'disabled' );
|
1656 |
// Enabled TextBox color back to normal
|
1657 |
$( '#whats-new' ).css( 'color', '' );
|
1658 |
|
1820 |
$( document ).on( 'click', '.rtmedia-like', function( e ) {
|
1821 |
e.preventDefault();
|
1822 |
var that = this;
|
1823 |
+
var like_nonce = $( '#rtm_media_like_nonce' ).val();
|
1824 |
$( this ).attr( 'disabled', 'disabled' );
|
1825 |
var url = $( this ).parent().attr( 'action' );
|
1826 |
$( that ).prepend( '<img class=\'rtm-like-loading\' src=\'' + rMedia_loading_file + '\' style=\'width:10px\' />' );
|
1929 |
|
1930 |
new_button.on( 'click', function ( e ) {
|
1931 |
|
1932 |
+
if ( ! rtmedia_add_media_button_post_update ) {
|
1933 |
+
rtmedia_add_media_button_post_update = jQuery( '#rtmedia-add-media-button-post-update' );
|
1934 |
+
}
|
1935 |
+
rtmedia_add_media_button_post_update.prop( 'disabled', true );
|
1936 |
if ( rtMediaHook.call( 'rtmedia_js_before_activity_added', { src: 'activity' } ) ) {
|
1937 |
objUploadView.uploadFiles( e );
|
1938 |
}
|
app/assets/js/rtMedia.js
CHANGED
@@ -853,41 +853,53 @@ jQuery( 'document' ).ready( function( $ ) {
|
|
853 |
});
|
854 |
}
|
855 |
|
856 |
-
|
|
|
|
|
|
|
857 |
jQuery( '.rtmedia-container' ).on( 'click', '.rtm-delete-media', function( e ) {
|
858 |
e.preventDefault();
|
859 |
-
var confirmation =
|
860 |
-
|
861 |
-
if ( typeof rtmedia_media_delete_confirmation != 'undefined' ) {
|
862 |
-
confirmation = rtmedia_media_delete_confirmation;
|
863 |
-
}
|
864 |
|
865 |
if ( confirm( confirmation ) ) { // If user confirms, send ajax request to delete the selected media
|
866 |
var curr_li = jQuery( this ).closest( 'li' );
|
867 |
var nonce = jQuery( '#rtmedia_media_delete_nonce' ).val();
|
|
|
868 |
|
869 |
var data = {
|
870 |
action: 'delete_uploaded_media',
|
871 |
nonce: nonce,
|
872 |
-
media_id: curr_li.attr( 'id' )
|
|
|
873 |
};
|
874 |
|
875 |
jQuery.ajax( {
|
876 |
-
url:
|
877 |
-
type: '
|
878 |
data: data,
|
879 |
-
|
|
|
880 |
|
881 |
-
if (
|
882 |
//Media delete
|
883 |
-
rtmedia_gallery_action_alert_message(
|
884 |
curr_li.remove();
|
885 |
-
|
|
|
886 |
rtm_masonry_reload( rtm_masonry_container );
|
887 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
888 |
} else { // Show alert message
|
889 |
-
rtmedia_gallery_action_alert_message(
|
890 |
}
|
|
|
891 |
}
|
892 |
} );
|
893 |
}
|
853 |
});
|
854 |
}
|
855 |
|
856 |
+
/**
|
857 |
+
* Delete media from gallery page under the user's profile when user clicks the delete button on the gallery item.
|
858 |
+
* Modified 11-Feb-2020 Adarsh Verma <adarsh.verma@rtcamp.com>
|
859 |
+
*/
|
860 |
jQuery( '.rtmedia-container' ).on( 'click', '.rtm-delete-media', function( e ) {
|
861 |
e.preventDefault();
|
862 |
+
var confirmation = RTMedia_Main_JS.media_delete_confirmation;
|
|
|
|
|
|
|
|
|
863 |
|
864 |
if ( confirm( confirmation ) ) { // If user confirms, send ajax request to delete the selected media
|
865 |
var curr_li = jQuery( this ).closest( 'li' );
|
866 |
var nonce = jQuery( '#rtmedia_media_delete_nonce' ).val();
|
867 |
+
var media_type = jQuery( this ).parents( '.rtmedia-list-item' ).data( 'media_type' );
|
868 |
|
869 |
var data = {
|
870 |
action: 'delete_uploaded_media',
|
871 |
nonce: nonce,
|
872 |
+
media_id: curr_li.attr( 'id' ),
|
873 |
+
media_type: media_type
|
874 |
};
|
875 |
|
876 |
jQuery.ajax( {
|
877 |
+
url: RTMedia_Main_JS.rtmedia_ajaxurl,
|
878 |
+
type: 'POST',
|
879 |
data: data,
|
880 |
+
dataType: 'JSON',
|
881 |
+
success: function( response ) {
|
882 |
|
883 |
+
if ( 'rtmedia-media-deleted' === response.data.code ) {
|
884 |
//Media delete
|
885 |
+
rtmedia_gallery_action_alert_message( RTMedia_Main_JS.media_delete_success, 'success' );
|
886 |
curr_li.remove();
|
887 |
+
|
888 |
+
if ( 'undefined' !== typeof rtmedia_masonry_layout && 'true' === rtmedia_masonry_layout ) {
|
889 |
rtm_masonry_reload( rtm_masonry_container );
|
890 |
}
|
891 |
+
|
892 |
+
// Update the media count in user profile & group's media tab.
|
893 |
+
jQuery( '#user-media span, #media-groups-li #media span' ).text( response.data.all_media_count );
|
894 |
+
|
895 |
+
// Update the count on sub navigations (Photo, Video & Music)
|
896 |
+
jQuery( '#rtmedia-nav-item-photo span' ).text( response.data.photos_count );
|
897 |
+
jQuery( '#rtmedia-nav-item-music span' ).text( response.data.music_count );
|
898 |
+
jQuery( '#rtmedia-nav-item-video span' ).text( response.data.videos_count );
|
899 |
} else { // Show alert message
|
900 |
+
rtmedia_gallery_action_alert_message( response.data.message, 'warning' );
|
901 |
}
|
902 |
+
|
903 |
}
|
904 |
} );
|
905 |
}
|
app/assets/js/rtm-upload-terms.js
CHANGED
@@ -1,139 +1,305 @@
|
|
1 |
-
|
2 |
-
|
3 |
/**
|
|
|
|
|
4 |
* Remove Terms Warning Popup,
|
5 |
* Add Warning Message Before Submit Button
|
6 |
* By: Malav Vasita <malav.vasita@rtcamp.com>
|
7 |
*/
|
8 |
if ( 'object' === typeof rtMediaHook ) {
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
}
|
86 |
|
87 |
-
jQuery(document).ready(function () {
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
|
127 |
/**
|
128 |
* Show Error Message On Admin Side
|
129 |
* Handle error on rtMedia settings
|
130 |
* By: Malav Vasita
|
131 |
*/
|
132 |
-
function rtp_display_terms_warning
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
|
|
|
|
137 |
}
|
138 |
|
139 |
/**
|
@@ -142,14 +308,20 @@ function rtp_display_terms_warning ( selector, rt_alert_msg ) {
|
|
142 |
* By: Malav Vasita
|
143 |
*/
|
144 |
function handle_privacy_message() {
|
145 |
-
jQuery( '#close_rtm_privacy_message' ).on( 'click', function(c) {
|
146 |
-
jQuery( '.privacy_message_wrapper' ).fadeOut( 'slow', function(c) {
|
147 |
-
jQuery( '.privacy_message_wrapper' ).remove();
|
148 |
-
jQuery.cookie( "rtm_show_privacy_message", "view", { expires : 1, path: "/" } );
|
149 |
-
});
|
150 |
-
});
|
151 |
-
}
|
152 |
|
153 |
-
jQuery(
|
154 |
-
|
155 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
var rtmediaTermsConditionsElement;
|
|
|
2 |
/**
|
3 |
+
* Check for terms and condition
|
4 |
+
*
|
5 |
* Remove Terms Warning Popup,
|
6 |
* Add Warning Message Before Submit Button
|
7 |
* By: Malav Vasita <malav.vasita@rtcamp.com>
|
8 |
*/
|
9 |
if ( 'object' === typeof rtMediaHook ) {
|
10 |
+
|
11 |
+
/**
|
12 |
+
* Check terms condition checkbox before uploading files.
|
13 |
+
*
|
14 |
+
* @param {object/boolean} args Arguments passed when calling this hook.
|
15 |
+
* @return {boolean}
|
16 |
+
*/
|
17 |
+
rtMediaHook.register( 'rtmedia_js_before_upload', function ( args ) {
|
18 |
+
if ( ! args ) {
|
19 |
+
return args;
|
20 |
+
}
|
21 |
+
|
22 |
+
if ( 'undefined' === typeof args.uploader || 'undefined' === typeof args.uploader.settings || 'undefined' === typeof args.uploader.settings.multipart_params || 'undefined' === typeof args.src ) {
|
23 |
+
return ( 'boolean' === typeof args ? args : true );
|
24 |
+
}
|
25 |
+
|
26 |
+
var multipart_params = args.uploader.settings.multipart_params;
|
27 |
+
var request_key = false;
|
28 |
+
var terms_key = false;
|
29 |
+
var isTermsEnabled = false;
|
30 |
+
|
31 |
+
if ( 'activity' === args.src ) {
|
32 |
+
request_key = 'activity_terms_condition_request';
|
33 |
+
terms_key = 'activity_terms_condition';
|
34 |
+
|
35 |
+
if ( 'true' === rtmedia_upload_terms_data.activity_terms_enabled ) {
|
36 |
+
isTermsEnabled = true;
|
37 |
+
}
|
38 |
+
} else if ( 'uploader' === args.src ) {
|
39 |
+
request_key = 'uploader_terms_condition_request';
|
40 |
+
terms_key = 'uploader_terms_condition';
|
41 |
+
|
42 |
+
if ( 'true' === rtmedia_upload_terms_data.uploader_terms_enabled ) {
|
43 |
+
isTermsEnabled = true;
|
44 |
+
}
|
45 |
+
}
|
46 |
+
|
47 |
+
if ( ! isTermsEnabled ) {
|
48 |
+
return true;
|
49 |
+
}
|
50 |
+
|
51 |
+
if ( request_key && terms_key && isTermsEnabled ) {
|
52 |
+
multipart_params[ request_key ] = 'true';
|
53 |
+
|
54 |
+
if ( rtmediaTermsConditionsElement && rtmediaTermsConditionsElement.length > 0 ) {
|
55 |
+
multipart_params[ terms_key ] = ( rtmediaTermsConditionsElement.prop( 'checked' ) ? 'true' : 'false' );
|
56 |
+
} else {
|
57 |
+
var terms = $( '#rtmedia_upload_terms_conditions' );
|
58 |
+
if ( terms.length > 0 ) {
|
59 |
+
rtmediaTermsConditionsElement = terms;
|
60 |
+
|
61 |
+
multipart_params[ terms_key ] = ( terms.prop( 'checked' ) ? 'true' : 'false' );
|
62 |
+
}
|
63 |
+
}
|
64 |
+
}
|
65 |
+
|
66 |
+
args.uploader.settings.multipart_params = multipart_params;
|
67 |
+
|
68 |
+
return true;
|
69 |
+
} );
|
70 |
+
|
71 |
+
/**
|
72 |
+
* Check for the terms checkbox to be checked before the media is uploaded.
|
73 |
+
* Show warning if unchecked else proceed.
|
74 |
+
|
75 |
+
* @param {object/boolean} args Arguments passed when calling this hook.
|
76 |
+
* @return {boolean}
|
77 |
+
*/
|
78 |
+
rtMediaHook.register( 'rtmedia_js_upload_file', function ( args ) {
|
79 |
+
if ( ! args ) {
|
80 |
+
return args;
|
81 |
+
}
|
82 |
+
|
83 |
+
var src = false;
|
84 |
+
if ( false !== args && 'undefined' !== typeof args.src ) {
|
85 |
+
src = args.src;
|
86 |
+
}
|
87 |
+
|
88 |
+
var parent = false;
|
89 |
+
var isTermsEnabled = false;
|
90 |
+
|
91 |
+
var terms = jQuery( '#rtmedia_upload_terms_conditions' );
|
92 |
+
if ( 'uploader' === src ) {
|
93 |
+
|
94 |
+
if ( 0 === terms.length ) {
|
95 |
+
parent = jQuery( '#drag-drop-area' );
|
96 |
+
} else {
|
97 |
+
parent = terms.parent( '.rtmedia-upload-terms' );
|
98 |
+
}
|
99 |
+
|
100 |
+
if ( ( 'undefined' !== typeof rtmedia_upload_terms_data && 'undefined' === typeof rtmedia_upload_terms_data.uploader_terms_enabled ) || 'true' === rtmedia_upload_terms_data.uploader_terms_enabled ) {
|
101 |
+
isTermsEnabled = true;
|
102 |
+
}
|
103 |
+
} else if ( 'activity' === src ) {
|
104 |
+
|
105 |
+
if ( 0 === terms.length ) {
|
106 |
+
parent = jQuery( '#whats-new-options' );
|
107 |
+
} else {
|
108 |
+
parent = terms.parent( '.rtmedia-upload-terms' );
|
109 |
+
}
|
110 |
+
|
111 |
+
if ( 'true' === rtmedia_upload_terms_data.activity_terms_enabled ) {
|
112 |
+
isTermsEnabled = true;
|
113 |
+
}
|
114 |
+
} else if ( jQuery( '#drag-drop-area' ).length ) {
|
115 |
+
if ( 0 === terms.length ) {
|
116 |
+
parent = jQuery( '#drag-drop-area' );
|
117 |
+
} else {
|
118 |
+
parent = terms.parent( '.rtmedia-upload-terms' );
|
119 |
+
}
|
120 |
+
|
121 |
+
if ( ( 'undefined' !== typeof rtmedia_upload_terms_data && 'undefined' === typeof rtmedia_upload_terms_data.uploader_terms_enabled ) || 'true' === rtmedia_upload_terms_data.uploader_terms_enabled ) {
|
122 |
+
isTermsEnabled = true;
|
123 |
+
}
|
124 |
+
}
|
125 |
+
|
126 |
+
if ( ! isTermsEnabled ) {
|
127 |
+
return ( 'boolean' === typeof args ? args : true );
|
128 |
+
}
|
129 |
+
|
130 |
+
if ( 0 === terms.length ) {
|
131 |
+
rtp_display_terms_warning( parent, rtmedia_upload_terms_data.message );
|
132 |
+
return false;
|
133 |
+
}
|
134 |
+
|
135 |
+
rtmediaTermsConditionsElement = terms;
|
136 |
+
if ( terms.prop( 'checked' ) ) {
|
137 |
+
return true;
|
138 |
+
} else {
|
139 |
+
rtp_display_terms_warning( parent, rtmedia_upload_terms_data.message );
|
140 |
+
return false;
|
141 |
+
}
|
142 |
+
|
143 |
+
} );
|
144 |
+
|
145 |
+
/**
|
146 |
+
* Show the warning message if the terms checkbox is unchecked before posting the media update.
|
147 |
+
*/
|
148 |
+
rtMediaHook.register( 'rtmedia_js_before_activity_added', function ( args ) {
|
149 |
+
|
150 |
+
var terms_conditions_checkbox, form;
|
151 |
+
var whats_new_submit = jQuery( '#aw-whats-new-submit' );
|
152 |
+
|
153 |
+
if ( args && 'activity' === args.src ) {
|
154 |
+
if ( 'false' === rtmedia_upload_terms_data.activity_terms_enabled ) {
|
155 |
+
return true;
|
156 |
+
}
|
157 |
+
|
158 |
+
form = jQuery( '#whats-new-form' );
|
159 |
+
terms_conditions_checkbox = form.find( '#rtmedia_upload_terms_conditions' );
|
160 |
+
} else {
|
161 |
+
terms_conditions_checkbox = jQuery( '#rtmedia_upload_terms_conditions' );
|
162 |
+
}
|
163 |
+
|
164 |
+
if ( 1 === terms_conditions_checkbox.length ) {
|
165 |
+
terms_conditions_checkbox.removeAttr( 'disabled' );
|
166 |
+
rtmediaTermsConditionsElement = terms_conditions_checkbox;
|
167 |
+
|
168 |
+
if ( false === args ) {
|
169 |
+
whats_new_submit.removeAttr( 'disabled' );
|
170 |
+
whats_new_submit.removeClass( 'loading' );
|
171 |
+
|
172 |
+
return args;
|
173 |
+
}
|
174 |
+
|
175 |
+
if ( ! terms_conditions_checkbox.is( ':checked' ) ) {
|
176 |
+
whats_new_submit.removeAttr( 'disabled' );
|
177 |
+
whats_new_submit.removeClass( 'loading' );
|
178 |
+
|
179 |
+
if ( args && 'activity' === args.src ) {
|
180 |
+
rtp_display_terms_warning( form.find('.rtmedia-upload-terms'), rtmedia_upload_terms_data.message );
|
181 |
+
} else {
|
182 |
+
rtp_display_terms_warning( terms_conditions_checkbox.parent( '.rtmedia-upload-terms' ), rtmedia_upload_terms_data.message );
|
183 |
+
}
|
184 |
+
|
185 |
+
return false;
|
186 |
+
} else {
|
187 |
+
terms_conditions_checkbox.prop( 'disabled', true );
|
188 |
+
}
|
189 |
+
} else {
|
190 |
+
rtp_display_terms_warning( form.find( '#whats-new-options' ), rtmedia_upload_terms_data.message );
|
191 |
+
|
192 |
+
return false;
|
193 |
+
}
|
194 |
+
|
195 |
+
return true;
|
196 |
+
|
197 |
+
} );
|
198 |
+
|
199 |
+
/**
|
200 |
+
* When Select Attribute for media [ rtmedia-custom-attributes: Add-Ons ] Issue:8,
|
201 |
+
* This Hook returns false that's why the attributes were not saved,
|
202 |
+
* Added: 'return true;'
|
203 |
+
* By: Yahil
|
204 |
+
*/
|
205 |
+
rtMediaHook.register( 'rtmedia_js_after_file_upload', function () {
|
206 |
+
|
207 |
+
var terms_conditions_checkbox = jQuery( '#rtmedia-upload-container #rtmedia_upload_terms_conditions' );
|
208 |
+
|
209 |
+
if ( 1 === terms_conditions_checkbox.length ) {
|
210 |
+
terms_conditions_checkbox.removeAttr( 'checked' );
|
211 |
+
jQuery( '.rt_alert_msg' ).remove();
|
212 |
+
}
|
213 |
+
|
214 |
+
return true;
|
215 |
+
|
216 |
+
});
|
217 |
+
|
218 |
+
/**
|
219 |
+
* Uncheck the terms checkbox after the activity is posted successfully.
|
220 |
+
*/
|
221 |
+
rtMediaHook.register( 'rtmedia_js_after_activity_added', function () {
|
222 |
+
|
223 |
+
jQuery( '#rtmedia_upload_terms_conditions' ).removeAttr( 'checked' ).removeAttr( 'disabled' );
|
224 |
+
|
225 |
+
return true;
|
226 |
+
|
227 |
+
} );
|
228 |
}
|
229 |
|
230 |
+
jQuery( document ).ready( function () {
|
231 |
+
var terms_conditions_checkbox = jQuery( '#rtmedia_upload_terms_conditions' );
|
232 |
+
|
233 |
+
/**
|
234 |
+
* Fires before ajax request.
|
235 |
+
* Send terms condition checkbox status on backend to validate it on server side.
|
236 |
+
*/
|
237 |
+
jQuery.ajaxPrefilter( function ( options, originalOptions, jqXHR ) {
|
238 |
+
if ( 'undefined' === typeof options || 'undefined' === typeof options.data || 'undefined' === typeof originalOptions || 'undefined' === typeof originalOptions.data ) {
|
239 |
+
return true;
|
240 |
+
}
|
241 |
+
|
242 |
+
if ( 'post_update' === originalOptions.data.action && terms_conditions_checkbox.length ) {
|
243 |
+
options.data += '&rtmedia_upload_terms_conditions=' + terms_conditions_checkbox.prop( 'checked' );
|
244 |
+
}
|
245 |
+
|
246 |
+
return true;
|
247 |
+
} );
|
248 |
+
|
249 |
+
|
250 |
+
terms_conditions_checkbox.on( 'click', function () {
|
251 |
+
|
252 |
+
// Focus on `start upload` button.
|
253 |
+
var upload_start_btn = jQuery( '.start-media-upload' );
|
254 |
+
upload_start_btn.focus();
|
255 |
+
|
256 |
+
// Show error message if terms-condition is not checked.
|
257 |
+
if ( terms_conditions_checkbox.is( ':checked' ) ) {
|
258 |
+
var alter_msg_span = terms_conditions_checkbox.siblings( 'span.rt_alert_msg' );
|
259 |
+
|
260 |
+
if ( 1 === alter_msg_span.length ) {
|
261 |
+
alter_msg_span.remove();
|
262 |
+
} else {
|
263 |
+
terms_conditions_checkbox.parent().siblings( 'span.rt_alert_msg' ).remove();
|
264 |
+
}
|
265 |
+
|
266 |
+
} else {
|
267 |
+
rtp_display_terms_warning( terms_conditions_checkbox.parent( '.rtmedia-upload-terms' ), rtmedia_upload_terms_data.message );
|
268 |
+
}
|
269 |
+
|
270 |
+
if ( 'undefined' !== typeof rtmedia_direct_upload_enabled && '1' === rtmedia_direct_upload_enabled ) {
|
271 |
+
var whats_new_submit = jQuery( '#aw-whats-new-submit' );
|
272 |
+
|
273 |
+
if ( whats_new_submit.length ) {
|
274 |
+
|
275 |
+
if ( '' !== jQuery( '#whats-new' ).val().trim() || jQuery( '#rtmedia_uploader_filelist' ).children( 'li' ).length ) {
|
276 |
+
whats_new_submit.trigger( 'click' );
|
277 |
+
}
|
278 |
+
|
279 |
+
} else {
|
280 |
+
upload_start_btn.trigger( 'click' );
|
281 |
+
}
|
282 |
+
|
283 |
+
}
|
284 |
+
} );
|
285 |
+
|
286 |
+
// Handle privacy message on website.
|
287 |
+
handle_privacy_message();
|
288 |
+
|
289 |
+
} );
|
290 |
|
291 |
/**
|
292 |
* Show Error Message On Admin Side
|
293 |
* Handle error on rtMedia settings
|
294 |
* By: Malav Vasita
|
295 |
*/
|
296 |
+
function rtp_display_terms_warning( selector, rt_alert_msg ) {
|
297 |
+
|
298 |
+
if ( 0 === jQuery( '.rt_alert_msg' ).length ) {
|
299 |
+
var invalid_error_msg = jQuery( '<span />' ).attr( 'style', 'color:red; display:block; clear:both;' ).addClass( 'rt_alert_msg' ).empty().append( rt_alert_msg );
|
300 |
+
selector.after( invalid_error_msg );
|
301 |
+
}
|
302 |
+
|
303 |
}
|
304 |
|
305 |
/**
|
308 |
* By: Malav Vasita
|
309 |
*/
|
310 |
function handle_privacy_message() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
311 |
|
312 |
+
jQuery( '#close_rtm_privacy_message' ).on( 'click', function () {
|
313 |
+
var privacy_wrapper = jQuery( '.privacy_message_wrapper' );
|
314 |
+
privacy_wrapper.fadeOut( 'slow', function () {
|
315 |
+
privacy_wrapper.remove();
|
316 |
+
jQuery.cookie(
|
317 |
+
'rtm_show_privacy_message',
|
318 |
+
'view',
|
319 |
+
{
|
320 |
+
expires: 1,
|
321 |
+
path: '/'
|
322 |
+
}
|
323 |
+
);
|
324 |
+
} );
|
325 |
+
} );
|
326 |
+
|
327 |
+
}
|
app/assets/js/rtm-upload-terms.min.js
CHANGED
@@ -3,4 +3,4 @@
|
|
3 |
* @package rtMedia
|
4 |
*/
|
5 |
|
6 |
-
function rtp_display_terms_warning(e,
|
3 |
* @package rtMedia
|
4 |
*/
|
5 |
|
6 |
+
var rtmediaTermsConditionsElement;function rtp_display_terms_warning(e,t){if(0===jQuery(".rt_alert_msg").length){var r=jQuery("<span />").attr("style","color:red; display:block; clear:both;").addClass("rt_alert_msg").empty().append(t);e.after(r)}}function handle_privacy_message(){jQuery("#close_rtm_privacy_message").on("click",function(){var e=jQuery(".privacy_message_wrapper");e.fadeOut("slow",function(){e.remove(),jQuery.cookie("rtm_show_privacy_message","view",{expires:1,path:"/"})})})}"object"==typeof rtMediaHook&&(rtMediaHook.register("rtmedia_js_before_upload",function(e){if(!e)return e;if(void 0===e.uploader||void 0===e.uploader.settings||void 0===e.uploader.settings.multipart_params||void 0===e.src)return"boolean"!=typeof e||e;var t=e.uploader.settings.multipart_params,r=!1,a=!1,d=!1;if("activity"===e.src?(r="activity_terms_condition_request",a="activity_terms_condition","true"===rtmedia_upload_terms_data.activity_terms_enabled&&(d=!0)):"uploader"===e.src&&(r="uploader_terms_condition_request",a="uploader_terms_condition","true"===rtmedia_upload_terms_data.uploader_terms_enabled&&(d=!0)),!d)return!0;if(r&&a&&d)if(t[r]="true",rtmediaTermsConditionsElement&&0<rtmediaTermsConditionsElement.length)t[a]=rtmediaTermsConditionsElement.prop("checked")?"true":"false";else{var i=$("#rtmedia_upload_terms_conditions");0<i.length&&(rtmediaTermsConditionsElement=i,t[a]=i.prop("checked")?"true":"false")}return e.uploader.settings.multipart_params=t,!0}),rtMediaHook.register("rtmedia_js_upload_file",function(e){if(!e)return e;var t=!1;!1!==e&&void 0!==e.src&&(t=e.src);var r=!1,a=!1,d=jQuery("#rtmedia_upload_terms_conditions");return"uploader"===t?(r=0===d.length?jQuery("#drag-drop-area"):d.parent(".rtmedia-upload-terms"),("undefined"!=typeof rtmedia_upload_terms_data&&void 0===rtmedia_upload_terms_data.uploader_terms_enabled||"true"===rtmedia_upload_terms_data.uploader_terms_enabled)&&(a=!0)):"activity"===t?(r=0===d.length?jQuery("#whats-new-options"):d.parent(".rtmedia-upload-terms"),"true"===rtmedia_upload_terms_data.activity_terms_enabled&&(a=!0)):jQuery("#drag-drop-area").length&&(r=0===d.length?jQuery("#drag-drop-area"):d.parent(".rtmedia-upload-terms"),("undefined"!=typeof rtmedia_upload_terms_data&&void 0===rtmedia_upload_terms_data.uploader_terms_enabled||"true"===rtmedia_upload_terms_data.uploader_terms_enabled)&&(a=!0)),a?0===d.length?(rtp_display_terms_warning(r,rtmedia_upload_terms_data.message),!1):!!(rtmediaTermsConditionsElement=d).prop("checked")||(rtp_display_terms_warning(r,rtmedia_upload_terms_data.message),!1):"boolean"!=typeof e||e}),rtMediaHook.register("rtmedia_js_before_activity_added",function(e){var t,r,a=jQuery("#aw-whats-new-submit");if(e&&"activity"===e.src){if("false"===rtmedia_upload_terms_data.activity_terms_enabled)return!0;t=(r=jQuery("#whats-new-form")).find("#rtmedia_upload_terms_conditions")}else t=jQuery("#rtmedia_upload_terms_conditions");return 1!==t.length?(rtp_display_terms_warning(r.find("#whats-new-options"),rtmedia_upload_terms_data.message),!1):(t.removeAttr("disabled"),rtmediaTermsConditionsElement=t,!1===e?(a.removeAttr("disabled"),a.removeClass("loading"),e):t.is(":checked")?(t.prop("disabled",!0),!0):(a.removeAttr("disabled"),a.removeClass("loading"),e&&"activity"===e.src?rtp_display_terms_warning(r.find(".rtmedia-upload-terms"),rtmedia_upload_terms_data.message):rtp_display_terms_warning(t.parent(".rtmedia-upload-terms"),rtmedia_upload_terms_data.message),!1))}),rtMediaHook.register("rtmedia_js_after_file_upload",function(){var e=jQuery("#rtmedia-upload-container #rtmedia_upload_terms_conditions");return 1===e.length&&(e.removeAttr("checked"),jQuery(".rt_alert_msg").remove()),!0}),rtMediaHook.register("rtmedia_js_after_activity_added",function(){return jQuery("#rtmedia_upload_terms_conditions").removeAttr("checked").removeAttr("disabled"),!0})),jQuery(document).ready(function(){var a=jQuery("#rtmedia_upload_terms_conditions");jQuery.ajaxPrefilter(function(e,t,r){return void 0===e||void 0===e.data||void 0===t||void 0===t.data||"post_update"===t.data.action&&a.length&&(e.data+="&rtmedia_upload_terms_conditions="+a.prop("checked")),!0}),a.on("click",function(){var e=jQuery(".start-media-upload");if(e.focus(),a.is(":checked")){var t=a.siblings("span.rt_alert_msg");1===t.length?t.remove():a.parent().siblings("span.rt_alert_msg").remove()}else rtp_display_terms_warning(a.parent(".rtmedia-upload-terms"),rtmedia_upload_terms_data.message);if("undefined"!=typeof rtmedia_direct_upload_enabled&&"1"===rtmedia_direct_upload_enabled){var r=jQuery("#aw-whats-new-submit");r.length?""===jQuery("#whats-new").val().trim()&&!jQuery("#rtmedia_uploader_filelist").children("li").length||r.trigger("click"):e.trigger("click")}}),handle_privacy_message()});
|
app/assets/js/rtmedia.min.js
CHANGED
@@ -3,4 +3,4 @@
|
|
3 |
* @package rtMedia
|
4 |
*/
|
5 |
|
6 |
-
var rtMagnificPopup,rtm_masonry_container;!function(e){"function"==typeof define&&define.amd?define(["jquery"],e):"object"==typeof exports?e(require("jquery")):e(window.jQuery||window.Zepto)}(function(d){function e(){}function m(e,t){y.ev.on(i+e+b,t)}function u(e,t,i,a){var r=document.createElement("div");return r.className="mfp-"+e,i&&(r.innerHTML=i),a?t&&t.appendChild(r):(r=d(r),t&&r.appendTo(t)),r}function p(e,t){y.ev.triggerHandler(i+e,t),y.st.callbacks&&(e=e.charAt(0).toLowerCase()+e.slice(1),y.st.callbacks[e]&&y.st.callbacks[e].apply(y,d.isArray(t)?t:[t]))}function f(e){return e===t&&y.currTemplate.closeBtn||(y.currTemplate.closeBtn=d(y.st.closeMarkup.replace("%title%",y.st.tClose)),t=e),y.currTemplate.closeBtn}function n(){d.magnificPopup.instance||((y=new e).init(),d.magnificPopup.instance=y)}var y,a,_,r,v,t,l="Close",c="BeforeClose",g="MarkupParse",h="Open",o="Change",i="mfp",b="."+i,j="mfp-ready",s="mfp-removing",w="mfp-prevent-close",Q=!!window.jQuery,C=d(window);e.prototype={constructor:e,init:function(){var e=navigator.appVersion;y.isIE7=-1!==e.indexOf("MSIE 7."),y.isIE8=-1!==e.indexOf("MSIE 8."),y.isLowIE=y.isIE7||y.isIE8,y.isAndroid=/android/gi.test(e),y.isIOS=/iphone|ipad|ipod/gi.test(e),y.supportsTransition=function(){var e=document.createElement("p").style,t=["ms","O","Moz","Webkit"];if(void 0!==e.transition)return!0;for(;t.length;)if(t.pop()+"Transition"in e)return!0;return!1}(),y.probablyMobile=y.isAndroid||y.isIOS||/(Opera Mini)|Kindle|webOS|BlackBerry|(Opera Mobi)|(Windows Phone)|IEMobile/i.test(navigator.userAgent),_=d(document),y.popupsCache={}},open:function(e){var t;if(!1===e.isObj){y.items=e.items.toArray(),y.index=0;var i,a=e.items;for(t=0;t<a.length;t++)if((i=a[t]).parsed&&(i=i.el[0]),i===e.el[0]){y.index=t;break}}else y.items=d.isArray(e.items)?e.items:[e.items],y.index=e.index||0;if(!y.isOpen){y.types=[],v="",e.mainEl&&e.mainEl.length?y.ev=e.mainEl.eq(0):y.ev=_,e.key?(y.popupsCache[e.key]||(y.popupsCache[e.key]={}),y.currTemplate=y.popupsCache[e.key]):y.currTemplate={},y.st=d.extend(!0,{},d.magnificPopup.defaults,e),y.fixedContentPos="auto"===y.st.fixedContentPos?!y.probablyMobile:y.st.fixedContentPos,y.st.modal&&(y.st.closeOnContentClick=!1,y.st.closeOnBgClick=!1,y.st.showCloseBtn=!1,y.st.enableEscapeKey=!1),y.bgOverlay||(y.bgOverlay=u("bg").on("click"+b,function(){y.close()}),y.wrap=u("wrap").attr("tabindex",-1).on("click"+b,function(e){y._checkIfClose(e.target)&&y.close()}),y.container=u("container",y.wrap)),y.contentContainer=u("content"),y.st.preloader&&(y.preloader=u("preloader",y.container,y.st.tLoading));var r=d.magnificPopup.modules;for(t=0;t<r.length;t++){var n=r[t];n=n.charAt(0).toUpperCase()+n.slice(1),y["init"+n].call(y)}p("BeforeOpen"),y.st.showCloseBtn&&(y.st.closeBtnInside?(m(g,function(e,t,i,a){i.close_replaceWith=f(a.type)}),v+=" mfp-close-btn-in"):y.wrap.append(f())),y.st.alignTop&&(v+=" mfp-align-top"),y.fixedContentPos?y.wrap.css({overflow:y.st.overflowY,overflowX:"hidden",overflowY:y.st.overflowY}):y.wrap.css({top:C.scrollTop(),position:"absolute"}),!1!==y.st.fixedBgPos&&("auto"!==y.st.fixedBgPos||y.fixedContentPos)||y.bgOverlay.css({height:_.height(),position:"absolute"}),y.st.enableEscapeKey&&_.on("keyup"+b,function(e){27===e.keyCode&&y.close()}),C.on("resize"+b,function(){y.updateSize()}),y.st.closeOnContentClick||(v+=" mfp-auto-cursor"),v&&y.wrap.addClass(v);var o=y.wH=C.height(),s={};if(y.fixedContentPos&&y._hasScrollBar(o)){var l=y._getScrollbarSize();l&&(s.marginRight=l)}y.fixedContentPos&&(y.isIE7?d("body, html").css("overflow","hidden"):s.overflow="hidden");var c=y.st.mainClass;return y.isIE7&&(c+=" mfp-ie7"),c&&y._addClassToMFP(c),y.updateItemHTML(),p("BuildControls"),d("html").css(s),y.bgOverlay.add(y.wrap).prependTo(y.st.prependTo||d(document.body)),y._lastFocusedEl=document.activeElement,setTimeout(function(){y.content?(y._addClassToMFP(j),y._setFocus()):y.bgOverlay.addClass(j),_.on("focusin"+b,y._onFocusIn)},16),y.isOpen=!0,y.updateSize(o),p(h),e}y.updateItemHTML()},close:function(){y.isOpen&&(p(c),y.isOpen=!1,y.st.removalDelay&&!y.isLowIE&&y.supportsTransition?(y._addClassToMFP(s),setTimeout(function(){y._close()},y.st.removalDelay)):y._close())},_close:function(){p(l);var e=s+" "+j+" ";if(y.bgOverlay.detach(),y.wrap.detach(),y.container.empty(),y.st.mainClass&&(e+=y.st.mainClass+" "),y._removeClassFromMFP(e),y.fixedContentPos){var t={marginRight:""};y.isIE7?d("body, html").css("overflow",""):t.overflow="",d("html").css(t)}_.off("keyup.mfp focusin"+b),y.ev.off(b),y.wrap.attr("class","mfp-wrap").removeAttr("style"),y.bgOverlay.attr("class","mfp-bg"),y.container.attr("class","mfp-container"),!y.st.showCloseBtn||y.st.closeBtnInside&&!0!==y.currTemplate[y.currItem.type]||y.currTemplate.closeBtn&&y.currTemplate.closeBtn.detach(),y._lastFocusedEl&&d(y._lastFocusedEl).focus(),y.currItem=null,y.content=null,y.currTemplate=null,y.prevHeight=0,p("AfterClose")},updateSize:function(e){if(y.isIOS){var t=document.documentElement.clientWidth/window.innerWidth,i=window.innerHeight*t;y.wrap.css("height",i),y.wH=i}else y.wH=e||C.height();y.fixedContentPos||y.wrap.css("height",y.wH),p("Resize")},updateItemHTML:function(){var e=y.items[y.index];y.contentContainer.detach(),y.content&&y.content.detach(),e.parsed||(e=y.parseEl(y.index));var t=e.type;if(p("BeforeChange",[y.currItem?y.currItem.type:"",t]),y.currItem=e,!y.currTemplate[t]){var i=!!y.st[t]&&y.st[t].markup;p("FirstMarkupParse",i),y.currTemplate[t]=!i||d(i)}r&&r!==e.type&&y.container.removeClass("mfp-"+r+"-holder");var a=y["get"+t.charAt(0).toUpperCase()+t.slice(1)](e,y.currTemplate[t]);y.appendContent(a,t),e.preloaded=!0,p(o,e),r=e.type,y.container.prepend(y.contentContainer),p("AfterChange")},appendContent:function(e,t){(y.content=e)?y.st.showCloseBtn&&y.st.closeBtnInside&&!0===y.currTemplate[t]?y.content.find(".mfp-close").length||y.content.append(f()):y.content=e:y.content="",p("BeforeAppend"),y.container.addClass("mfp-"+t+"-holder"),y.contentContainer.append(y.content)},parseEl:function(e){var t,i=y.items[e];if((i=i.tagName?{el:d(i)}:(t=i.type,{data:i,src:i.src})).el){for(var a=y.types,r=0;r<a.length;r++)if(i.el.hasClass("mfp-"+a[r])){t=a[r];break}i.src=i.el.attr("data-mfp-src"),i.src||(i.src=i.el.attr("href"))}return i.type=t||y.st.type||"inline",i.index=e,i.parsed=!0,y.items[e]=i,p("ElementParse",i),y.items[e]},addGroup:function(t,i){function e(e){e.mfpEl=this,y._openClick(e,t,i)}var a="click.magnificPopup";(i=i||{}).mainEl=t,i.items?(i.isObj=!0,t.off(a).on(a,e)):(i.isObj=!1,i.delegate?t.off(a).on(a,i.delegate,e):(i.items=t).off(a).on(a,e))},_openClick:function(e,t,i){if((void 0!==i.midClick?i.midClick:d.magnificPopup.defaults.midClick)||2!==e.which&&!e.ctrlKey&&!e.metaKey){var a=void 0!==i.disableOn?i.disableOn:d.magnificPopup.defaults.disableOn;if(a)if(d.isFunction(a)){if(!a.call(y))return!0}else if(C.width()<a)return!0;e.type&&(e.preventDefault(),y.isOpen&&e.stopPropagation()),i.el=d(e.mfpEl),i.delegate&&(i.items=t.find(i.delegate)),y.open(i)}},updateStatus:function(e,t){if(y.preloader){a!==e&&y.container.removeClass("mfp-s-"+a),t||"loading"!==e||(t=y.st.tLoading);var i={status:e,text:t};p("UpdateStatus",i),e=i.status,t=i.text,y.preloader.html(t),y.preloader.find("a").on("click",function(e){e.stopImmediatePropagation()}),y.container.addClass("mfp-s-"+e),a=e}},_checkIfClose:function(e){if(!d(e).hasClass(w)){var t=y.st.closeOnContentClick,i=y.st.closeOnBgClick;if(t&&i)return!0;if(!y.content||d(e).hasClass("mfp-close")||y.preloader&&e===y.preloader[0])return!0;if(e===y.content[0]||d.contains(y.content[0],e)){if(t)return!0}else if(i&&d.contains(document,e))return!0;return!1}},_addClassToMFP:function(e){y.bgOverlay.addClass(e),y.wrap.addClass(e)},_removeClassFromMFP:function(e){this.bgOverlay.removeClass(e),y.wrap.removeClass(e)},_hasScrollBar:function(e){return(y.isIE7?_.height():document.body.scrollHeight)>(e||C.height())},_setFocus:function(){(y.st.focus?y.content.find(y.st.focus).eq(0):y.wrap).focus()},_onFocusIn:function(e){if(e.target!==y.wrap[0]&&!d.contains(y.wrap[0],e.target))return y._setFocus(),!1},_parseMarkup:function(r,e,t){var n;t.data&&(e=d.extend(t.data,e)),p(g,[r,e,t]),d.each(e,function(e,t){if(void 0===t||!1===t)return!0;if(1<(n=e.split("_")).length){var i=r.find(b+"-"+n[0]);if(0<i.length){var a=n[1];"replaceWith"===a?i[0]!==t[0]&&i.replaceWith(t):"img"===a?i.is("img")?i.attr("src",t):i.replaceWith('<img src="'+t+'" class="'+i.attr("class")+'" />'):i.attr(n[1],t)}}else r.find(b+"-"+e).html(t)})},_getScrollbarSize:function(){if(void 0===y.scrollbarSize){var e=document.createElement("div");e.style.cssText="width: 99px; height: 99px; overflow: scroll; position: absolute; top: -9999px;",document.body.appendChild(e),y.scrollbarSize=e.offsetWidth-e.clientWidth,document.body.removeChild(e)}return y.scrollbarSize}},d.magnificPopup={instance:null,proto:e.prototype,modules:[],open:function(e,t){return n(),(e=e?d.extend(!0,{},e):{}).isObj=!0,e.index=t||0,this.instance.open(e)},close:function(){return d.magnificPopup.instance&&d.magnificPopup.instance.close()},registerModule:function(e,t){t.options&&(d.magnificPopup.defaults[e]=t.options),d.extend(this.proto,t.proto),this.modules.push(e)},defaults:{disableOn:0,key:null,midClick:!1,mainClass:"",preloader:!0,focus:"",closeOnContentClick:!1,closeOnBgClick:!0,closeBtnInside:!0,showCloseBtn:!0,enableEscapeKey:!0,modal:!1,alignTop:!1,removalDelay:0,prependTo:null,fixedContentPos:"auto",fixedBgPos:"auto",overflowY:"auto",closeMarkup:'<button title="%title%" type="button" class="mfp-close">×</button>',tClose:"Close (Esc)",tLoading:"Loading..."}},d.fn.magnificPopup=function(e){n();var t=d(this);if("string"==typeof e)if("open"===e){var i,a=Q?t.data("magnificPopup"):t[0].magnificPopup,r=parseInt(arguments[1],10)||0;i=a.items?a.items[r]:(i=t,a.delegate&&(i=i.find(a.delegate)),i.eq(r)),y._openClick({mfpEl:i},t,a)}else y.isOpen&&y[e].apply(y,Array.prototype.slice.call(arguments,1));else e=d.extend(!0,{},e),Q?t.data("magnificPopup",e):t[0].magnificPopup=e,y.addGroup(t,e);return t};function k(){I&&(T.after(I.addClass(x)).detach(),I=null)}var x,T,I,M="inline";d.magnificPopup.registerModule(M,{options:{hiddenClass:"hide",markup:"",tNotFound:"Content not found"},proto:{initInline:function(){y.types.push(M),m(l+"."+M,function(){k()})},getInline:function(e,t){if(k(),e.src){var i=y.st.inline,a=d(e.src);if(a.length){var r=a[0].parentNode;r&&r.tagName&&(T||(x=i.hiddenClass,T=u(x),x="mfp-"+x),I=a.after(T).detach().removeClass(x)),y.updateStatus("ready")}else y.updateStatus("error",i.tNotFound),a=d("<div>");return e.inlineElement=a}return y.updateStatus("ready"),y._parseMarkup(t,{},e),t}}});function P(){S&&d(document.body).removeClass(S)}function E(){P(),y.req&&y.req.abort()}var S,O="ajax";d.magnificPopup.registerModule(O,{options:{settings:null,cursor:"mfp-ajax-cur",tError:'<a href="%url%">The content</a> could not be loaded.'},proto:{initAjax:function(){y.types.push(O),S=y.st.ajax.cursor,m(l+"."+O,E),m("BeforeChange."+O,E)},getAjax:function(r){S&&d(document.body).addClass(S),y.updateStatus("loading");var e=d.extend({url:r.src,success:function(e,t,i){var a={data:e,xhr:i};p("ParseAjax",a),y.appendContent(d(a.data),O),r.finished=!0,P(),y._setFocus(),setTimeout(function(){y.wrap.addClass(j)},16),y.updateStatus("ready"),p("AjaxContentAdded")},error:function(){P(),r.finished=r.loadError=!0,y.updateStatus("error",y.st.ajax.tError.replace("%url%",r.src))}},y.st.ajax.settings);return y.req=d.ajax(e),""}}});var z;d.magnificPopup.registerModule("image",{options:{markup:'<div class="mfp-figure"><div class="mfp-close"></div><figure><div class="mfp-img"></div><figcaption><div class="mfp-bottom-bar"><div class="mfp-title"></div><div class="mfp-counter"></div></div></figcaption></figure></div>',cursor:"mfp-zoom-out-cur",titleSrc:"title",verticalFit:!0,tError:'<a href="%url%">The image</a> could not be loaded.'},proto:{initImage:function(){var e=y.st.image,t=".image";y.types.push("image"),m(h+t,function(){"image"===y.currItem.type&&e.cursor&&d(document.body).addClass(e.cursor)}),m(l+t,function(){e.cursor&&d(document.body).removeClass(e.cursor),C.off("resize"+b)}),m("Resize"+t,y.resizeImage),y.isLowIE&&m("AfterChange",y.resizeImage)},resizeImage:function(){var e=y.currItem;if(e&&e.img&&y.st.image.verticalFit){var t=0;y.isLowIE&&(t=parseInt(e.img.css("padding-top"),10)+parseInt(e.img.css("padding-bottom"),10)),e.img.css("max-height",y.wH-t)}},_onImageHasSize:function(e){e.img&&(e.hasSize=!0,z&&clearInterval(z),e.isCheckingImgSize=!1,p("ImageHasSize",e),e.imgHidden&&(y.content&&y.content.removeClass("mfp-loading"),e.imgHidden=!1))},findImageSize:function(t){var i=0,a=t.img[0],r=function(e){z&&clearInterval(z),z=setInterval(function(){0<a.naturalWidth?y._onImageHasSize(t):(200<i&&clearInterval(z),3===++i?r(10):40===i?r(50):100===i&&r(500))},e)};r(1)},getImage:function(e,t){var i=0,a=function(){e&&(e.img[0].complete?(e.img.off(".mfploader"),e===y.currItem&&(y._onImageHasSize(e),y.updateStatus("ready")),e.hasSize=!0,e.loaded=!0,p("ImageLoadComplete")):++i<200?setTimeout(a,100):r())},r=function(){e&&(e.img.off(".mfploader"),e===y.currItem&&(y._onImageHasSize(e),y.updateStatus("error",n.tError.replace("%url%",e.src))),e.hasSize=!0,e.loaded=!0,e.loadError=!0)},n=y.st.image,o=t.find(".mfp-img");if(o.length){var s=document.createElement("img");s.className="mfp-img",e.el&&e.el.find("img").length&&(s.alt=e.el.find("img").attr("alt")),e.img=d(s).on("load.mfploader",a).on("error.mfploader",r),s.src=e.src,o.is("img")&&(e.img=e.img.clone()),0<(s=e.img[0]).naturalWidth?e.hasSize=!0:s.width||(e.hasSize=!1)}return y._parseMarkup(t,{title:function(e){if(e.data&&void 0!==e.data.title)return e.data.title;var t=y.st.image.titleSrc;if(t){if(d.isFunction(t))return t.call(y,e);if(e.el)return e.el.attr(t)||""}return""}(e),img_replaceWith:e.img},e),y.resizeImage(),e.hasSize?(z&&clearInterval(z),e.loadError?(t.addClass("mfp-loading"),y.updateStatus("error",n.tError.replace("%url%",e.src))):(t.removeClass("mfp-loading"),y.updateStatus("ready"))):(y.updateStatus("loading"),e.loading=!0,e.hasSize||(e.imgHidden=!0,t.addClass("mfp-loading"),y.findImageSize(e))),t}}});var H;d.magnificPopup.registerModule("zoom",{options:{enabled:!1,easing:"ease-in-out",duration:300,opener:function(e){return e.is("img")?e:e.find("img")}},proto:{initZoom:function(){var e,n=y.st.zoom,t=".zoom";if(n.enabled&&y.supportsTransition){function i(e){var t=e.clone().removeAttr("style").removeAttr("class").addClass("mfp-animated-image"),i="all "+n.duration/1e3+"s "+n.easing,a={position:"fixed",zIndex:9999,left:0,top:0,"-webkit-backface-visibility":"hidden"},r="transition";return a["-webkit-"+r]=a["-moz-"+r]=a["-o-"+r]=a[r]=i,t.css(a),t}function a(){y.content.css("visibility","visible")}var r,o,s=n.duration;m("BuildControls"+t,function(){if(y._allowZoom()){if(clearTimeout(r),y.content.css("visibility","hidden"),!(e=y._getItemToZoom()))return void a();(o=i(e)).css(y._getOffset()),y.wrap.append(o),r=setTimeout(function(){o.css(y._getOffset(!0)),r=setTimeout(function(){a(),setTimeout(function(){o.remove(),e=o=null,p("ZoomAnimationEnded")},16)},s)},16)}}),m(c+t,function(){if(y._allowZoom()){if(clearTimeout(r),y.st.removalDelay=s,!e){if(!(e=y._getItemToZoom()))return;o=i(e)}o.css(y._getOffset(!0)),y.wrap.append(o),y.content.css("visibility","hidden"),setTimeout(function(){o.css(y._getOffset())},16)}}),m(l+t,function(){y._allowZoom()&&(a(),o&&o.remove(),e=null)})}},_allowZoom:function(){return"image"===y.currItem.type},_getItemToZoom:function(){return!!y.currItem.hasSize&&y.currItem.img},_getOffset:function(e){var t,i=(t=e?y.currItem.img:y.st.zoom.opener(y.currItem.el||y.currItem)).offset(),a=parseInt(t.css("padding-top"),10),r=parseInt(t.css("padding-bottom"),10);i.top-=d(window).scrollTop()-a;var n={width:t.width(),height:(Q?t.innerHeight():t[0].offsetHeight)-r-a};return void 0===H&&(H=void 0!==document.createElement("p").style.MozTransform),H?n["-moz-transform"]=n.transform="translate("+i.left+"px,"+i.top+"px)":(n.left=i.left,n.top=i.top),n}}});function B(e){if(y.currTemplate[A]){var t=y.currTemplate[A].find("iframe");t.length&&(e||(t[0].src="//about:blank"),y.isIE8&&t.css("display",e?"block":"none"))}}var A="iframe";d.magnificPopup.registerModule(A,{options:{markup:'<div class="mfp-iframe-scaler"><div class="mfp-close"></div><iframe class="mfp-iframe" src="//about:blank" frameborder="0" allowfullscreen></iframe></div>',srcAction:"iframe_src",patterns:{youtube:{index:"youtube.com",id:"v=",src:"//www.youtube.com/embed/%id%?autoplay=1"},vimeo:{index:"vimeo.com/",id:"/",src:"//player.vimeo.com/video/%id%?autoplay=1"},gmaps:{index:"//maps.google.",src:"%id%&output=embed"}}},proto:{initIframe:function(){y.types.push(A),m("BeforeChange",function(e,t,i){t!==i&&(t===A?B():i===A&&B(!0))}),m(l+"."+A,function(){B()})},getIframe:function(e,t){var i=e.src,a=y.st.iframe;d.each(a.patterns,function(){if(-1<i.indexOf(this.index))return this.id&&(i="string"==typeof this.id?i.substr(i.lastIndexOf(this.id)+this.id.length,i.length):this.id.call(this,i)),i=this.src.replace("%id%",i),!1});var r={};return a.srcAction&&(r[a.srcAction]=i),y._parseMarkup(t,r,e),y.updateStatus("ready"),t}}});function L(e){var t=y.items.length;return t-1<e?e-t:e<0?t+e:e}function $(e,t,i){return e.replace(/%curr%/gi,t+1).replace(/%total%/gi,i)}d.magnificPopup.registerModule("gallery",{options:{enabled:!1,arrowMarkup:'<button title="%title%" type="button" class="mfp-arrow mfp-arrow-%dir%"></button>',preload:[0,2],navigateByImgClick:!0,arrows:!0,tPrev:"Previous (Left arrow key)",tNext:"Next (Right arrow key)",tCounter:"%curr% of %total%"},proto:{initGallery:function(){var n=y.st.gallery,e=".mfp-gallery",r=Boolean(d.fn.mfpFastClick);if(y.direction=!0,!n||!n.enabled)return!1;v+=" mfp-gallery",m(h+e,function(){n.navigateByImgClick&&y.wrap.on("click"+e,".mfp-img",function(){if(1<y.items.length)return y.next(),!1}),_.on("keydown"+e,function(e){37===e.keyCode?y.prev():39===e.keyCode&&y.next()})}),m("UpdateStatus"+e,function(e,t){t.text&&(t.text=$(t.text,y.currItem.index,y.items.length))}),m(g+e,function(e,t,i,a){var r=y.items.length;i.counter=1<r?$(n.tCounter,a.index,r):""}),m("BuildControls"+e,function(){if(1<y.items.length&&n.arrows&&!y.arrowLeft){var e=n.arrowMarkup,t=y.arrowLeft=d(e.replace(/%title%/gi,n.tPrev).replace(/%dir%/gi,"left")).addClass(w),i=y.arrowRight=d(e.replace(/%title%/gi,n.tNext).replace(/%dir%/gi,"right")).addClass(w),a=r?"mfpFastClick":"click";t[a](function(){y.prev()}),i[a](function(){y.next()}),y.isIE7&&(u("b",t[0],!1,!0),u("a",t[0],!1,!0),u("b",i[0],!1,!0),u("a",i[0],!1,!0)),y.container.append(t.add(i))}}),m(o+e,function(){y._preloadTimeout&&clearTimeout(y._preloadTimeout),y._preloadTimeout=setTimeout(function(){y.preloadNearbyImages(),y._preloadTimeout=null},16)}),m(l+e,function(){_.off(e),y.wrap.off("click"+e),y.arrowLeft&&r&&y.arrowLeft.add(y.arrowRight).destroyMfpFastClick(),y.arrowRight=y.arrowLeft=null})},next:function(){y.direction=!0,y.index=L(y.index+1),y.updateItemHTML()},prev:function(){y.direction=!1,y.index=L(y.index-1),y.updateItemHTML()},goTo:function(e){y.direction=e>=y.index,y.index=e,y.updateItemHTML()},preloadNearbyImages:function(){var e,t=y.st.gallery.preload,i=Math.min(t[0],y.items.length),a=Math.min(t[1],y.items.length);for(e=1;e<=(y.direction?a:i);e++)y._preloadItem(y.index+e);for(e=1;e<=(y.direction?i:a);e++)y._preloadItem(y.index-e)},_preloadItem:function(e){if(e=L(e),!y.items[e].preloaded){var t=y.items[e];t.parsed||(t=y.parseEl(e)),p("LazyLoad",t),"image"===t.type&&(t.img=d('<img class="mfp-img" />').on("load.mfploader",function(){t.hasSize=!0}).on("error.mfploader",function(){t.hasSize=!0,t.loadError=!0,p("LazyLoadError",t)}).attr("src",t.src)),t.preloaded=!0}}}});var F,D,R="retina";function W(){C.off("touchmove"+D+" touchend"+D)}d.magnificPopup.registerModule(R,{options:{replaceSrc:function(e){return e.src.replace(/\.\w+$/,function(e){return"@2x"+e})},ratio:1},proto:{initRetina:function(){if(1<window.devicePixelRatio){var i=y.st.retina,a=i.ratio;1<(a=isNaN(a)?a():a)&&(m("ImageHasSize."+R,function(e,t){t.img.css({"max-width":t.img[0].naturalWidth/a,width:"100%"})}),m("ElementParse."+R,function(e,t){t.src=i.replaceSrc(t,a)}))}}}}),F="ontouchstart"in window,D=".mfpFastClick",d.fn.mfpFastClick=function(l){return d(this).each(function(){var t,i,a,r,n,o,s,e=d(this);F&&e.on("touchstart"+D,function(e){n=!1,s=1,o=e.originalEvent?e.originalEvent.touches[0]:e.touches[0],a=o.clientX,r=o.clientY,C.on("touchmove"+D,function(e){o=e.originalEvent?e.originalEvent.touches:e.touches,s=o.length,o=o[0],(10<Math.abs(o.clientX-a)||10<Math.abs(o.clientY-r))&&(n=!0,W())}).on("touchend"+D,function(e){W(),n||1<s||(t=!0,e.preventDefault(),clearTimeout(i),i=setTimeout(function(){t=!1},1e3),l())})}),e.on("click"+D,function(){t||l()})})},d.fn.destroyMfpFastClick=function(){d(this).off("touchstart"+D+" click"+D),F&&C.off("touchmove"+D+" touchend"+D)},n()}),"function"!=typeof Object.create&&(Object.create=function(e){function t(){}return t.prototype=e,new t}),function(n,o){var i={init:function(e,t){this.elem=t,this.$elem=n(t),this.options=n.extend({},n.fn.rtTab.options,e),this.rtTabs()},rtTabs:function(){var t=this,e=t.options.activeTab;if(t.$elem.find("li:nth-child("+e+")").addClass("active"),t.rtTabContent(activeTabContent="yes"),t.rtClick(),!0==("false"!==t.$elem.attr("data-hash"))){var i=o.location.hash;i&&t.$elem.find("li").find('a[href="'+i+'"]').trigger("click"),n(o).on("hashchange",function(){var e=o.location.hash;t.$elem.find("li").find('a[href="'+e+'"]').trigger("click")})}},rtClick:function(){var a=this,r=a.$elem.find("li");r.find("a").on("click",function(e){e.preventDefault(),r.removeClass("active"),a.rtTabContent(),n(this).parent().addClass("active");var t=n(this).attr("href");if(n(t).removeClass("hide"),!0==("false"!==a.$elem.attr("data-hash"))){var i=n(o).scrollTop();location.hash=n(this).attr("href"),n(o).scrollTop(i)}"function"==typeof a.options.onComplete&&a.options.onComplete.apply(a.elem,arguments)})},rtTabContent:function(i){this.$elem.find("li").find("a").each(function(){var e=n(this),t=e.attr("href");"yes"===i&&e.parent().hasClass("active")||n(t).addClass("hide")})}};n.fn.rtTab=function(t){return this.each(function(){var e=Object.create(i);e.init(t,this),n.data(this,"rtTab",e)})},n.fn.rtTab.options={activeTab:1,onComplete:null}}(jQuery,window,document);var comment_media=!1;function apply_rtMagnificPopup(t){jQuery("document").ready(function(s){var e="";if(e="undefined"==typeof rtmedia_load_more?"Loading media":rtmedia_load_more,"undefined"!=typeof rtmedia_lightbox_enabled&&"1"==rtmedia_lightbox_enabled){var n,l,c=!1;0<s(".activity-item .rtmedia-activity-container .rtmedia-list-item > a").siblings("p").children("a").length&&s(".activity-item .rtmedia-activity-container .rtmedia-list-item > a").siblings("p").children("a").addClass("no-popup"),rtMagnificPopup=jQuery(t).magnificPopup({delegate:"a:not(.no-popup, .mejs-time-slider, .mejs-volume-slider, .mejs-horizontal-volume-slider)",type:"ajax",fixedContentPos:!0,fixedBgPos:!0,tLoading:e+" #%curr%...",mainClass:"mfp-img-mobile",preload:[1,3],closeOnBgClick:!0,gallery:{enabled:!0,navigateByImgClick:!0,arrowMarkup:"",preload:[0,1]},image:{tError:'<a href="%url%">The image #%curr%</a> could not be loaded.',titleSrc:function(e){return e.el.attr("title")+"<small>by Marsel Van Oosten</small>"}},callbacks:{ajaxContentAdded:function(){e=jQuery.magnificPopup.instance,1===jQuery(e.items).size()&&jQuery(".mfp-arrow").remove();var e=jQuery.magnificPopup.instance,t=e.currItem.el,i=t.parent();if(i.is("li")||(i=i.parent()),(i.is(":nth-last-child(2)")||i.is(":last-child"))&&i.find("a").hasClass("rtmedia-list-item-a")){i.next();"block"==jQuery("#rtMedia-galary-next").css("display")&&(c||(n=e.ev.children(),c=!0,l=nextpage),jQuery("#rtMedia-galary-next").click())}var a=e.items.length;if(e.index!=a-1||i.is(":last-child")){"undefined"!=typeof _wpmejsSettings&&_wpmejsSettings.pluginPath;var o=jQuery(".rtmedia-container .rtmedia-single-meta").height(),r=!1;void 0!==e&&void 0!==e.probablyMobile&&1==e.probablyMobile&&(r=!0),s(".mfp-content .rtmedia-single-media .wp-audio-shortcode,.mfp-content .rtmedia-single-media .wp-video-shortcode,.mfp-content .rtmedia-single-media .bp_media_content video").attr("autoplay",!0),r&&s(".mfp-content .rtmedia-single-media .wp-video-shortcode,.mfp-content .rtmedia-single-media .bp_media_content video").attr("muted",!1),s(".mfp-content .rtmedia-single-media .wp-audio-shortcode,.mfp-content .rtmedia-single-media .wp-video-shortcode,.mfp-content .rtmedia-single-media .bp_media_content video").mediaelementplayer({classPrefix:"mejs-",defaultVideoWidth:480,hideVolumeOnTouchDevices:!1,features:["playpause","progress","current","volume","fullscreen"],defaultVideoHeight:270,alwaysShowControls:r,enableAutosize:!0,clickToPlayPause:!0,videoHeight:-1,success:function(n,e){n.addEventListener("loadeddata",function(e){var t=s(n).height(),i=s(window).height(),a=jQuery("div.rtm-ltb-action-container").height(),r=o-(a=a+50);i<t&&jQuery(".rtmedia-container #rtmedia-single-media-container .mejs-container").attr("style","height:"+r+"px !important; transition:0.2s")},!1),r&&s(n).hasClass("wp-video-shortcode")?jQuery("body").on("touchstart",".mejs-overlay-button",function(e){n.paused?n.play():n.pause()}):n.pause()}}),s(".mfp-content .mejs-audio .mejs-controls").css("position","relative"),rtMediaHook.call("rtmedia_js_popup_after_content_added",[]),"undefined"!=typeof bp&&void 0!==bp.mentions&&void 0!==bp.mentions.users&&(s("#atwho-container #atwho-ground-comment_content").remove(),s("#comment_content").bp_mentions(bp.mentions.users)),rtmedia_reset_video_and_audio_for_popup(),apply_rtMagnificPopup(".rtmedia-list-media.rtm-gallery-list, .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, ul.rtm-comment-container")}else t.click()},open:function(){var e=jQuery(".mfp-bg"),t=jQuery(".mfp-wrap");e.height(e.height()+t.height())},close:function(e){c&&(mfp.ev.empty(),mfp.ev.append(n),nextpage=l,c=!1,1<nextpage&&jQuery("#rtMedia-galary-next").show()),rtmedia_single_page_popup_close()},BeforeChange:function(e){}}})}jQuery(document).ajaxComplete(function(){jQuery("[id^=imgedit-leaving]").filter(function(){var e=jQuery(this).text();jQuery(this).text(e.replace("OK","Save"))})})})}var rtMediaHook={hooks:[],is_break:!1,register:function(e,t){void 0===rtMediaHook.hooks[e]&&(rtMediaHook.hooks[e]=[]),rtMediaHook.hooks[e].push(t)},call:function(e,arguments){if(void 0!==rtMediaHook.hooks[e])for(i=0;i<rtMediaHook.hooks[e].length;++i)if(1!=rtMediaHook.hooks[e][i](arguments))return!(rtMediaHook.is_break=!0);return!0}};function rtmedia_init_action_dropdown(e){var t,i;jQuery(e+" .click-nav > span,"+e+" .click-nav > div").toggleClass("no-js js"),jQuery(e+" .click-nav .js ul").hide(),jQuery(e+" .click-nav .clicker").click(function(e){t=jQuery("#rtm-media-options .click-nav .clicker").next("ul"),i=jQuery(this).next("ul"),jQuery.each(t,function(e,t){jQuery(t).html()!=i.html()&&jQuery(t).hide()}),jQuery(i).toggle(),e.stopPropagation()})}function bp_media_create_element(e){return!1}function rtmedia_version_compare(e,t){if(typeof e+typeof t!="stringstring")return!1;for(var i=e.split("."),a=t.split("."),r=0,n=Math.max(i.length,a.length);r<n;r++){if(i[r]&&!a[r]&&0<parseInt(i[r])||parseInt(i[r])>parseInt(a[r]))return!0;if(a[r]&&!i[r]&&0<parseInt(a[r])||parseInt(i[r])<parseInt(a[r]))return!1}return!0}function rtm_is_element_exist(e){return 0<jQuery(e).length}function rtm_masonry_reload(e){setTimeout(function(){e.masonry("reload")},250)}function rtm_search_media_text_validation(){""===jQuery("#media_search_input").val()?jQuery("#media_search").css("cursor","not-allowed"):jQuery("#media_search").css("cursor","pointer")}function rtmediaGetParameterByName(e){e=e.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]");var t=new RegExp("[\\?&]"+e+"=([^&#]*)").exec(location.search);return null==t?"":decodeURIComponent(t[1].replace(/\+/g," "))}function rtmedia_single_media_alert_message(e,t,i){var a="rtmedia-success";"warning"==t&&(a="rtmedia-warning");var r=!1;jQuery(".rtmedia-message-container").each(function(e,t){return t=jQuery(t),i&&t.hasClass("rtmedia-empty-comment-error-class")?(t.remove(),!(r=!0)):void 0!==i||t.hasClass("rtmedia-empty-comment-error-class")?void 0:(t.remove(),!(r=!0))});var n,o=jQuery("<div>",{title:"Click to dismiss",class:"rtmedia-message-container"+(i?" rtmedia-empty-comment-error-class":""),style:"margin:1em 0;"}),s=jQuery("<span>",{class:a});s.html(e),s.appendTo(o),i?(n=jQuery("#rt_media_comment_form"),jQuery("#comment_content").focus()):void 0===i&&(n=jQuery(".rtmedia-single-media .rtmedia-media")).css("opacity","0.2"),n.after(o),r&&(s.css({border:"2px solid #884646"}),setTimeout(function(){s.css({border:"none"})},500)),setTimeout(function(){o.remove(),void 0===i&&n.css("opacity","1")},3e3),o.click(function(){o.remove(),void 0===i&&n.css("opacity","1")})}function rtmedia_gallery_action_alert_message(e,t){var i="rtmedia-success";"warning"==t&&(i="rtmedia-warning");jQuery("body").append('<div class="rtmedia-gallery-alert-container"> </div>'),jQuery(".rtmedia-gallery-alert-container").append("<div class='rtmedia-gallery-message-box'><span class='"+i+"'>"+e+" </span></div>"),setTimeout(function(){jQuery(".rtmedia-gallery-alert-container").remove()},3e3),jQuery(".rtmedia-gallery-message-box").click(function(){jQuery(".rtmedia-gallery-alert-container").remove()})}function rtmedia_activity_masonry(){jQuery("#activity-stream .rtmedia-activity-container .rtmedia-list").masonry({itemSelector:".rtmedia-list-item",gutter:7});var e=0,t=setInterval(function(){5===(e+=1)&&clearInterval(t),jQuery.each(jQuery(".rtmedia-activity-container .rtmedia-list.masonry .rtmedia-item-title"),function(e,t){jQuery(t).width(jQuery(t).siblings(".rtmedia-item-thumbnail").children("img").width())}),rtm_masonry_reload(jQuery("#activity-stream .rtmedia-activity-container .rtmedia-list"))},1e3)}function get_parameter(e,t){if(!e)return!1;t=t||window.location.href;e=e.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]");var i=new RegExp(e+"=([^&#]*)").exec(t);return null!==i&&i[1]}function rtm_upload_terms_activity(){if(0<jQuery("#rtmedia_upload_terms_conditions").length){jQuery("#bp-nouveau-activity-form").on("click","#aw-whats-new-submit",function(e){var t=jQuery("#whats-new-form"),i=t.find("#rtmedia_upload_terms_conditions");if(0!==i.length&&!1===i.prop("checked")&&0===t.find("#message").length){e.preventDefault();var a=t.find(".rtmedia-upload-terms");rtp_display_terms_warning(a,rtmedia_upload_terms_check_terms_message)}});var t=jQuery("#whats-new-form");0<t.length&&jQuery("#whats-new-form, #rtmedia_upload_terms_conditions").on("click",function(e){t.find("input:hidden").each(function(){jQuery(this).prop("disabled",!1)})})}}jQuery("document").ready(function(n){function r(){if(0<jQuery("#rtmedia-media-view-form").length){var e=jQuery("#rtmedia-media-view-form").attr("action");jQuery.post(e,{},function(e){})}}function o(e,t,i){var a=new Date;a.setTime(a.getTime()+24*i*60*60*1e3);var r="expires="+a.toUTCString();document.cookie=e+"="+t+";"+r+";path=/"}jQuery(document).ajaxComplete(function(e,t,i){if("legacy"!==bp_template_pack&&bp_template_pack){var a=get_parameter("action",i.data);"activity_filter"!==a&&"post_update"!==a&&"get_single_activity_content"!==a&&"activity_get_older_updates"!==a||"undefined"==typeof rtmedia_masonry_layout||"true"!==rtmedia_masonry_layout||"undefined"==typeof rtmedia_masonry_layout_activity||"true"!==rtmedia_masonry_layout_activity?"activity_filter"!==a&&"post_update"!==a&&"get_single_activity_content"!==a&&"activity_get_older_updates"!==a||setTimeout(function(){apply_rtMagnificPopup(".rtmedia-list-media.rtm-gallery-list, .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, ul.rtm-comment-container"),rtmedia_activity_stream_comment_media()},1e3):setTimeout(function(){apply_rtMagnificPopup(".rtmedia-list-media.rtm-gallery-list, .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, ul.rtm-comment-container"),rtmedia_activity_masonry(),rtmedia_activity_stream_comment_media()},1e3)}}),jQuery(".rtmedia-uploader-div").css({opacity:"1",display:"block",visibility:"visible"}),jQuery(" #whats-new-options ").css({opacity:"1"}),void 0!==n.fn.rtTab&&n(".rtm-tabs").rtTab(),0<jQuery(".rtmedia-modal-link").length&&n(".rtmedia-modal-link").magnificPopup({type:"inline",midClick:!0,closeBtnInside:!0}),n("#rt_media_comment_form").submit(function(e){return""!=n.trim(n("#comment_content").val())||(0==jQuery("#rtmedia-single-media-container").length?rtmedia_gallery_action_alert_message(rtmedia_empty_comment_msg,"warning"):rtmedia_single_media_alert_message(rtmedia_empty_comment_msg,"warning"),!1)}),n("li.rtmedia-list-item p a").each(function(e){n(this).addClass("no-popup")}),n("li.rtmedia-list-item p a").each(function(e){n(this).addClass("no-popup")}),"undefined"!=typeof rtmedia_lightbox_enabled&&"1"==rtmedia_lightbox_enabled&&apply_rtMagnificPopup(".rtmedia-list-media.rtm-gallery-list, .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, ul.rtm-comment-container"),jQuery.ajaxPrefilter(function(e,t,i){try{if(null==t.data||void 0===t.data||void 0===t.data.action)return!0}catch(e){return!0}if("activity_get_older_updates"==t.data.action){var a=t.success;e.success=function(e){"function"==typeof a&&a(e),apply_rtMagnificPopup(".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"),rtMediaHook.call("rtmedia_js_after_activity_added",[])}}else if("get_single_activity_content"==t.data.action){a=t.success;e.success=function(e){"function"==typeof a&&a(e),setTimeout(function(){apply_rtMagnificPopup(".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"),jQuery("ul.activity-list li.rtmedia_update:first-child .wp-audio-shortcode, ul.activity-list li.rtmedia_update:first-child .wp-video-shortcode").mediaelementplayer({classPrefix:"mejs-",defaultVideoWidth:480,defaultVideoHeight:270})},900)}}}),jQuery.ajaxPrefilter(function(e,t,i){try{if(null==t.data||void 0===t.data||void 0===t.data.action)return!0}catch(e){return!0}if("activity_get_older_updates"==t.data.action){var a=t.success;e.success=function(e){"function"==typeof a&&a(e),apply_rtMagnificPopup(".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"),jQuery("ul.activity-list li.rtmedia_update div.rtmedia-item-thumbnail > audio.wp-audio-shortcode, ul.activity-list li.rtmedia_update div.rtmedia-item-thumbnail > video.wp-video-shortcode").mediaelementplayer({classPrefix:"mejs-",defaultVideoWidth:480,defaultVideoHeight:270}),setTimeout(function(){rtmedia_activity_stream_comment_media()},900),rtMediaHook.call("rtmedia_js_after_activity_added",[])}}}),jQuery(".rtmedia-container").on("click",".select-all",function(e){jQuery(this).toggleClass("unselect-all").toggleClass("select-all"),jQuery(this).attr("title",rtmedia_unselect_all_visible),jQuery(".rtmedia-list input").each(function(){jQuery(this).prop("checked",!0)}),jQuery(".rtmedia-list-item").addClass("bulk-selected")}),jQuery(".rtmedia-container").on("click",".unselect-all",function(e){jQuery(this).toggleClass("select-all").toggleClass("unselect-all"),jQuery(this).attr("title",rtmedia_select_all_visible),jQuery(".rtmedia-list input").each(function(){jQuery(this).prop("checked",!1)}),jQuery(".rtmedia-list-item").removeClass("bulk-selected")}),jQuery(".rtmedia-container").on("click",".rtmedia-move",function(e){jQuery(".rtmedia-delete-container").slideUp(),jQuery(".rtmedia-move-container").slideToggle()}),jQuery("#rtmedia-create-album-modal").on("click","#rtmedia_create_new_album",function(e){if($albumname=jQuery("<span/>").text(jQuery.trim(jQuery("#rtmedia_album_name").val())).html(),$album_description=jQuery("#rtmedia_album_description"),$context=jQuery.trim(jQuery("#rtmedia_album_context").val()),$context_id=jQuery.trim(jQuery("#rtmedia_album_context_id").val()),$privacy=jQuery.trim(jQuery("#rtmedia_select_album_privacy").val()),$create_album_nonce=jQuery.trim(jQuery("#rtmedia_create_album_nonce").val()),""!=$albumname){var t={action:"rtmedia_create_album",name:$albumname,description:$album_description.val(),context:$context,context_id:$context_id,create_album_nonce:$create_album_nonce};""!==$privacy&&(t.privacy=$privacy),n("#rtmedia_create_new_album").attr("disabled","disabled");var r=n("#rtmedia_create_new_album").html();n("#rtmedia_create_new_album").prepend("<img src='"+rMedia_loading_file+"' />"),jQuery.post(rtmedia_ajax_url,t,function(i){if(void 0!==i.album){i=jQuery.trim(i.album);var a=!0;$album_description.val(""),n("#rtmedia_album_name").focus(),jQuery(".rtmedia-user-album-list").each(function(){if(jQuery(this).children("optgroup").each(function(){if(jQuery(this).attr("value")===$context)return a=!1,void jQuery(this).append('<option value="'+i+'">'+$albumname+"</option>")}),a){var e=$context.charAt(0).toUpperCase()+$context.slice(1)+" "+rtmedia_main_js_strings.rtmedia_albums,t='<optgroup value="'+$context+'" label="'+e+'"><option value="'+i+'">'+$albumname+"</option></optgroup>";jQuery(this).append(t)}}),jQuery('select.rtmedia-user-album-list option[value="'+i+'"]').prop("selected",!0),jQuery(".rtmedia-create-new-album-container").slideToggle(),jQuery("#rtmedia_album_name").val(""),jQuery("#rtmedia-create-album-modal").append("<div class='rtmedia-success rtmedia-create-album-alert'><b>"+$albumname+"</b>"+rtmedia_album_created_msg+"</div>"),setTimeout(function(){jQuery(".rtmedia-create-album-alert").remove()},4e3),setTimeout(function(){galleryObj.reloadView(),jQuery(".close-reveal-modal").click()},2e3)}else void 0!==i.error?rtmedia_gallery_action_alert_message(i.error,"warning"):rtmedia_gallery_action_alert_message(rtmedia_something_wrong_msg,"warning");n("#rtmedia_create_new_album").removeAttr("disabled"),n("#rtmedia_create_new_album").html(r)})}else rtmedia_gallery_action_alert_message(rtmedia_empty_album_name_msg,"warning")}),jQuery(".rtmedia-container").on("click",".rtmedia-delete-selected",function(e){0<jQuery(".rtmedia-list :checkbox:checked").length?confirm(rtmedia_selected_media_delete_confirmation)&&jQuery(this).closest("form").attr("action","../../../"+rtmedia_media_slug+"/delete").submit():rtmedia_gallery_action_alert_message(rtmedia_no_media_selected,"warning")}),jQuery(".rtmedia-container").on("click",".rtmedia-move-selected",function(e){0<jQuery(".rtmedia-list :checkbox:checked").length?confirm(rtmedia_selected_media_move_confirmation)&&jQuery(this).closest("form").attr("action","").submit():rtmedia_gallery_action_alert_message(rtmedia_no_media_selected,"warning")}),jQuery("#buddypress").on("change",".rtm-activity-privacy-opt",function(){var e=jQuery(this).attr("id");e=(e=e.split("-"))[e.length-1];var a=this;data={activity_id:e,privacy:jQuery(this).val(),nonce:jQuery("#rtmedia_activity_privacy_nonce").val(),action:"rtm_change_activity_privacy"},jQuery.post(ajaxurl,data,function(e){var t="",i="";i="true"==e?(t=rtmedia_main_js_strings.privacy_update_success,"success"):(t=rtmedia_main_js_strings.privacy_update_error,"fail"),jQuery(a).after('<p class="rtm-ac-privacy-updated '+i+'">'+t+"</p>"),setTimeout(function(){jQuery(a).siblings(".rtm-ac-privacy-updated").remove()},2e3)})}),jQuery(".media_search_input").on("keyup",function(){rtm_search_media_text_validation()}),r(),rtMediaHook.register("rtmedia_js_popup_after_content_added",function(){r(),jQuery(".rtmedia-container").on("click",".rtmedia-delete-media",function(e){e.preventDefault(),confirm(rtmedia_media_delete_confirmation)&&jQuery(this).closest("form").submit()}),mfp=jQuery.magnificPopup.instance,1<jQuery(mfp.items).size()&&0==comment_media?function(){var n=jQuery.magnificPopup.instance,e=n.probablyMobile,t=function(e){for(var t=e+"=",i=document.cookie.split(";"),a=0;a<i.length;a++){for(var r=i[a];" "==r.charAt(0);)r=r.substring(1);if(0==r.indexOf(t))return r.substring(t.length,r.length)}return""}("rtmedia-touch-swipe-tooltip");e&&""===t?(jQuery("#mobile-swipe-overlay").show(),jQuery("#mobile-swipe-overlay").on("click",function(e){o("rtmedia-touch-swipe-tooltip",!0,365),jQuery(this).hide(),jQuery("#rtmedia-single-media-container .mejs-playpause-button").trigger("click")}),jQuery("#mobile-swipe-overlay").swipe({swipe:function(e,t,i,a,r,n){o("rtmedia-touch-swipe-tooltip",!0,365),jQuery("#mobile-swipe-overlay").hide(),jQuery("#rtmedia-single-media-container .mejs-playpause-button").trigger("click")},threshold:0})):jQuery("#rtmedia-single-media-container .mejs-playpause-button").trigger("click");jQuery(".mfp-arrow-right").on("click",function(e){n.next()}),jQuery(".mfp-arrow-left").on("click",function(e){n.prev()}),jQuery(".mfp-content .rtmedia-media").swipe({swipeLeft:function(e,t,i,a,r){n.next()},swipeRight:function(e,t,i,a,r){n.prev()},threshold:0})}():(jQuery(".mfp-arrow-right").hide(),jQuery(".mfp-arrow-left").hide(),jQuery(document).unbind("keydown")),rtmedia_disable_popup_navigation("#comment_content"),rtmedia_disable_popup_navigation_comment_media_focus();var e=n(window).height();jQuery(".rtm-lightbox-container .mejs-video").css({height:.8*e,"over-flow":"hidden"}),jQuery(".mfp-content .rtmedia-media").css({"max-height":.87*e,"over-flow":"hidden"}),rtmedia_init_action_dropdown(".rtm-lightbox-container .rtmedia-actions"),jQuery(".rtmedia-comment-link").on("click",function(e){e.preventDefault(),jQuery("#comment_content").focus()}),jQuery(".rtm-more").shorten({showChars:130});var t=n(".rtm-gallery-title"),i="";""!=(i=n.isEmptyObject(t)?n("#subnav.item-list-tabs li.selected ").html():t.html())&&n(".rtm-ltb-gallery-title .ltb-title").html(i);var a=n("#subnav.item-list-tabs li.selected span").html();return n("li.total").html(a),!0});var t=jQuery("#drag-drop-area"),i=jQuery("#whats-new");t.html();jQuery("#rtmedia-upload-container").after("<div id='rtm-drop-files-title'>"+rtmedia_drop_media_msg+"</div>"),"undefined"!=typeof rtmedia_bp_enable_activity&&"1"==rtmedia_bp_enable_activity&&jQuery("#whats-new-textarea").append("<div id='rtm-drop-files-title'>"+rtmedia_drop_media_msg+"</div>"),jQuery(document).on("dragover",function(e){e.preventDefault(),e.target!=this&&(jQuery("#rtm-media-gallery-uploader").show(),"undefined"!=typeof rtmedia_bp_enable_activity&&"1"==rtmedia_bp_enable_activity&&i.addClass("rtm-drag-drop-active"),t.addClass("rtm-drag-drop-active"),jQuery("#rtm-drop-files-title").show())}).on("dragleave",function(e){if(e.preventDefault(),0!=e.originalEvent.pageX&&0!=e.originalEvent.pageY)return!1;"undefined"!=typeof rtmedia_bp_enable_activity&&"1"==rtmedia_bp_enable_activity&&(i.removeClass("rtm-drag-drop-active"),i.removeAttr("style")),t.removeClass("rtm-drag-drop-active"),jQuery("#rtm-drop-files-title").hide()}).on("drop",function(e){e.preventDefault(),jQuery(".bp-suggestions").focus(),"undefined"!=typeof rtmedia_bp_enable_activity&&"1"==rtmedia_bp_enable_activity&&(i.removeClass("rtm-drag-drop-active"),i.removeAttr("style")),t.removeClass("rtm-drag-drop-active"),jQuery("#rtm-drop-files-title").hide()}),jQuery(".rtmedia-container").on("click",".rtmedia-delete-album",function(e){e.preventDefault(),confirm(rtmedia_album_delete_confirmation)&&jQuery(this).closest("form").submit()}),jQuery(".rtmedia-container").on("click",".rtmedia-delete-media",function(e){e.preventDefault(),confirm(rtmedia_media_delete_confirmation)&&jQuery(this).closest("form").submit()}),rtmedia_init_action_dropdown(""),n(document).click(function(){n(".click-nav ul").is(":visible")&&n(".click-nav ul",this).hide()}),jQuery(".rtmedia-comment-link").on("click",function(e){e.preventDefault(),jQuery("#comment_content").focus()}),0<jQuery(".rtm-more").length&&n(".rtm-more").shorten({showChars:200}),"undefined"!=typeof rtmedia_masonry_layout&&"true"==rtmedia_masonry_layout&&"undefined"!=typeof rtmedia_masonry_layout_activity&&"true"==rtmedia_masonry_layout_activity&&rtmedia_activity_masonry(),jQuery(document).ajaxComplete(function(e,t,i){var a=get_parameter("action",i.data);"post_update"!==a&&"get_single_activity_content"!==a&&"activity_get_older_updates"!==a||"undefined"==typeof rtmedia_masonry_layout||"true"!=rtmedia_masonry_layout||"undefined"==typeof rtmedia_masonry_layout_activity||"true"!=rtmedia_masonry_layout_activity||rtmedia_activity_masonry()}),"undefined"!=typeof rtmedia_masonry_layout&&"true"==rtmedia_masonry_layout&&0==jQuery(".rtmedia-container .rtmedia-list.rtm-no-masonry").length&&((rtm_masonry_container=jQuery(".rtmedia-container .rtmedia-list")).masonry({itemSelector:".rtmedia-list-item"}),setInterval(function(){jQuery.each(jQuery(".rtmedia-list.masonry .rtmedia-item-title"),function(e,t){jQuery(t).width(jQuery(t).siblings(".rtmedia-item-thumbnail").children("img").width())}),rtm_masonry_reload(rtm_masonry_container)},1e3),jQuery.each(jQuery(".rtmedia-list.masonry .rtmedia-item-title"),function(e,t){jQuery(t).width(jQuery(t).siblings(".rtmedia-item-thumbnail").children("img").width())})),0<jQuery(".rtm-uploader-tabs").length&&jQuery(".rtm-uploader-tabs li").click(function(e){jQuery(this).hasClass("active")||(jQuery(this).siblings().removeClass("active"),jQuery(this).parents(".rtm-uploader-tabs").siblings().hide(),class_name=jQuery(this).attr("class"),jQuery(this).parents(".rtm-uploader-tabs").siblings('[data-id="'+class_name+'"]').show(),jQuery(this).addClass("active"),"rtm-upload-tab"!=class_name?jQuery("div.moxie-shim").hide():jQuery("div.moxie-shim").show())}),jQuery(".rtmedia-container").on("click",".rtm-delete-media",function(e){e.preventDefault();var t="Are you sure you want to delete this media?";if("undefined"!=typeof rtmedia_media_delete_confirmation&&(t=rtmedia_media_delete_confirmation),confirm(t)){var i=jQuery(this).closest("li"),a={action:"delete_uploaded_media",nonce:jQuery("#rtmedia_media_delete_nonce").val(),media_id:i.attr("id")};jQuery.ajax({url:ajaxurl,type:"post",data:a,success:function(e){"1"==e?(rtmedia_gallery_action_alert_message(rtmedia_main_js_strings.file_delete_success,"success"),i.remove(),"undefined"!=typeof rtmedia_masonry_layout&&"true"==rtmedia_masonry_layout&&0==jQuery(".rtmedia-container .rtmedia-list.rtm-no-masonry").length&&rtm_masonry_reload(rtm_masonry_container)):rtmedia_gallery_action_alert_message(rtmedia_file_not_deleted,"warning")}})}})}),function(u){u.fn.shorten=function(e){"use strict";var m={showChars:100,minHideChars:10,ellipsesText:"...",moreText:rtmedia_read_more,lessText:rtmedia__show_less,onLess:function(){},onMore:function(){},errMsg:null,force:!1};return e&&u.extend(m,e),!(u(this).data("jquery.shorten")&&!m.force)&&(u(this).data("jquery.shorten",!0),u(document).off("click",".morelink"),u(document).on({click:function(){var e=u(this);return e.hasClass("less")?(e.removeClass("less"),e.html(m.moreText),e.parent().prev().hide(0,function(){e.parent().prev().prev().show()}).hide(0,function(){m.onLess()})):(e.addClass("less"),e.html(m.lessText),e.parent().prev().show(0,function(){e.parent().prev().prev().hide()}).show(0,function(){m.onMore()})),!1}},".morelink"),this.each(function(){var e=u(this),t=e.html();if(e.text().length>m.showChars+m.minHideChars){var i=t.substr(0,m.showChars);if(0<=i.indexOf("<")){for(var a=!1,r="",n=0,o=[],s=null,l=0,c=0;c<=m.showChars;l++)if("<"!=t[l]||a||(a=!0,"/"==(s=t.substring(l+1,t.indexOf(">",l)))[0]?s!="/"+o[0]?m.errMsg="ERROR en HTML: the top of the stack should be the tag that closes":o.shift():"br"!=s.toLowerCase()&&o.unshift(s)),a&&">"==t[l]&&(a=!1),a)r+=t.charAt(l);else if(c++,n<=m.showChars)r+=t.charAt(l),n++;else if(0<o.length){for(j=0;j<o.length;j++)r+="</"+o[j]+">";break}i=u("<div/>").html(r+'<span class="ellip">'+m.ellipsesText+"</span>").html()}else i+=m.ellipsesText;var d='<div class="shortcontent">'+i+'</div><div class="allcontent">'+t+'</div><span><a href="javascript://nop/" class="morelink">'+m.moreText+"</a></span>";e.html(d),e.find(".allcontent").hide(),u(".shortcontent p:last",e).css("margin-bottom",0)}}))}}(jQuery),window.onload=function(){"undefined"!=typeof rtmedia_masonry_layout&&"true"==rtmedia_masonry_layout&&0==jQuery(".rtmedia-container .rtmedia-list.rtm-no-masonry").length&&rtm_masonry_reload(rtm_masonry_container),rtm_search_media_text_validation(),check_condition("search")&&jQuery("#media_search_remove").show()},jQuery(document).ready(function(){rtm_upload_terms_activity(),jQuery("body").hasClass("has-sidebar")&&0===jQuery("#secondary").length&&(jQuery(".rtmedia-single-container").length||jQuery(".rtmedia-container").length)&&jQuery("body").removeClass("has-sidebar")});
|
3 |
* @package rtMedia
|
4 |
*/
|
5 |
|
6 |
+
var rtMagnificPopup,rtm_masonry_container;!function(e){"function"==typeof define&&define.amd?define(["jquery"],e):"object"==typeof exports?e(require("jquery")):e(window.jQuery||window.Zepto)}(function(d){function e(){}function m(e,t){y.ev.on(i+e+b,t)}function u(e,t,i,a){var r=document.createElement("div");return r.className="mfp-"+e,i&&(r.innerHTML=i),a?t&&t.appendChild(r):(r=d(r),t&&r.appendTo(t)),r}function p(e,t){y.ev.triggerHandler(i+e,t),y.st.callbacks&&(e=e.charAt(0).toLowerCase()+e.slice(1),y.st.callbacks[e]&&y.st.callbacks[e].apply(y,d.isArray(t)?t:[t]))}function f(e){return e===t&&y.currTemplate.closeBtn||(y.currTemplate.closeBtn=d(y.st.closeMarkup.replace("%title%",y.st.tClose)),t=e),y.currTemplate.closeBtn}function n(){d.magnificPopup.instance||((y=new e).init(),d.magnificPopup.instance=y)}var y,a,_,r,v,t,l="Close",c="BeforeClose",g="MarkupParse",h="Open",o="Change",i="mfp",b="."+i,j="mfp-ready",s="mfp-removing",w="mfp-prevent-close",Q=!!window.jQuery,C=d(window);e.prototype={constructor:e,init:function(){var e=navigator.appVersion;y.isIE7=-1!==e.indexOf("MSIE 7."),y.isIE8=-1!==e.indexOf("MSIE 8."),y.isLowIE=y.isIE7||y.isIE8,y.isAndroid=/android/gi.test(e),y.isIOS=/iphone|ipad|ipod/gi.test(e),y.supportsTransition=function(){var e=document.createElement("p").style,t=["ms","O","Moz","Webkit"];if(void 0!==e.transition)return!0;for(;t.length;)if(t.pop()+"Transition"in e)return!0;return!1}(),y.probablyMobile=y.isAndroid||y.isIOS||/(Opera Mini)|Kindle|webOS|BlackBerry|(Opera Mobi)|(Windows Phone)|IEMobile/i.test(navigator.userAgent),_=d(document),y.popupsCache={}},open:function(e){var t;if(!1===e.isObj){y.items=e.items.toArray(),y.index=0;var i,a=e.items;for(t=0;t<a.length;t++)if((i=a[t]).parsed&&(i=i.el[0]),i===e.el[0]){y.index=t;break}}else y.items=d.isArray(e.items)?e.items:[e.items],y.index=e.index||0;if(!y.isOpen){y.types=[],v="",e.mainEl&&e.mainEl.length?y.ev=e.mainEl.eq(0):y.ev=_,e.key?(y.popupsCache[e.key]||(y.popupsCache[e.key]={}),y.currTemplate=y.popupsCache[e.key]):y.currTemplate={},y.st=d.extend(!0,{},d.magnificPopup.defaults,e),y.fixedContentPos="auto"===y.st.fixedContentPos?!y.probablyMobile:y.st.fixedContentPos,y.st.modal&&(y.st.closeOnContentClick=!1,y.st.closeOnBgClick=!1,y.st.showCloseBtn=!1,y.st.enableEscapeKey=!1),y.bgOverlay||(y.bgOverlay=u("bg").on("click"+b,function(){y.close()}),y.wrap=u("wrap").attr("tabindex",-1).on("click"+b,function(e){y._checkIfClose(e.target)&&y.close()}),y.container=u("container",y.wrap)),y.contentContainer=u("content"),y.st.preloader&&(y.preloader=u("preloader",y.container,y.st.tLoading));var r=d.magnificPopup.modules;for(t=0;t<r.length;t++){var n=r[t];n=n.charAt(0).toUpperCase()+n.slice(1),y["init"+n].call(y)}p("BeforeOpen"),y.st.showCloseBtn&&(y.st.closeBtnInside?(m(g,function(e,t,i,a){i.close_replaceWith=f(a.type)}),v+=" mfp-close-btn-in"):y.wrap.append(f())),y.st.alignTop&&(v+=" mfp-align-top"),y.fixedContentPos?y.wrap.css({overflow:y.st.overflowY,overflowX:"hidden",overflowY:y.st.overflowY}):y.wrap.css({top:C.scrollTop(),position:"absolute"}),!1!==y.st.fixedBgPos&&("auto"!==y.st.fixedBgPos||y.fixedContentPos)||y.bgOverlay.css({height:_.height(),position:"absolute"}),y.st.enableEscapeKey&&_.on("keyup"+b,function(e){27===e.keyCode&&y.close()}),C.on("resize"+b,function(){y.updateSize()}),y.st.closeOnContentClick||(v+=" mfp-auto-cursor"),v&&y.wrap.addClass(v);var o=y.wH=C.height(),s={};if(y.fixedContentPos&&y._hasScrollBar(o)){var l=y._getScrollbarSize();l&&(s.marginRight=l)}y.fixedContentPos&&(y.isIE7?d("body, html").css("overflow","hidden"):s.overflow="hidden");var c=y.st.mainClass;return y.isIE7&&(c+=" mfp-ie7"),c&&y._addClassToMFP(c),y.updateItemHTML(),p("BuildControls"),d("html").css(s),y.bgOverlay.add(y.wrap).prependTo(y.st.prependTo||d(document.body)),y._lastFocusedEl=document.activeElement,setTimeout(function(){y.content?(y._addClassToMFP(j),y._setFocus()):y.bgOverlay.addClass(j),_.on("focusin"+b,y._onFocusIn)},16),y.isOpen=!0,y.updateSize(o),p(h),e}y.updateItemHTML()},close:function(){y.isOpen&&(p(c),y.isOpen=!1,y.st.removalDelay&&!y.isLowIE&&y.supportsTransition?(y._addClassToMFP(s),setTimeout(function(){y._close()},y.st.removalDelay)):y._close())},_close:function(){p(l);var e=s+" "+j+" ";if(y.bgOverlay.detach(),y.wrap.detach(),y.container.empty(),y.st.mainClass&&(e+=y.st.mainClass+" "),y._removeClassFromMFP(e),y.fixedContentPos){var t={marginRight:""};y.isIE7?d("body, html").css("overflow",""):t.overflow="",d("html").css(t)}_.off("keyup.mfp focusin"+b),y.ev.off(b),y.wrap.attr("class","mfp-wrap").removeAttr("style"),y.bgOverlay.attr("class","mfp-bg"),y.container.attr("class","mfp-container"),!y.st.showCloseBtn||y.st.closeBtnInside&&!0!==y.currTemplate[y.currItem.type]||y.currTemplate.closeBtn&&y.currTemplate.closeBtn.detach(),y._lastFocusedEl&&d(y._lastFocusedEl).focus(),y.currItem=null,y.content=null,y.currTemplate=null,y.prevHeight=0,p("AfterClose")},updateSize:function(e){if(y.isIOS){var t=document.documentElement.clientWidth/window.innerWidth,i=window.innerHeight*t;y.wrap.css("height",i),y.wH=i}else y.wH=e||C.height();y.fixedContentPos||y.wrap.css("height",y.wH),p("Resize")},updateItemHTML:function(){var e=y.items[y.index];y.contentContainer.detach(),y.content&&y.content.detach(),e.parsed||(e=y.parseEl(y.index));var t=e.type;if(p("BeforeChange",[y.currItem?y.currItem.type:"",t]),y.currItem=e,!y.currTemplate[t]){var i=!!y.st[t]&&y.st[t].markup;p("FirstMarkupParse",i),y.currTemplate[t]=!i||d(i)}r&&r!==e.type&&y.container.removeClass("mfp-"+r+"-holder");var a=y["get"+t.charAt(0).toUpperCase()+t.slice(1)](e,y.currTemplate[t]);y.appendContent(a,t),e.preloaded=!0,p(o,e),r=e.type,y.container.prepend(y.contentContainer),p("AfterChange")},appendContent:function(e,t){(y.content=e)?y.st.showCloseBtn&&y.st.closeBtnInside&&!0===y.currTemplate[t]?y.content.find(".mfp-close").length||y.content.append(f()):y.content=e:y.content="",p("BeforeAppend"),y.container.addClass("mfp-"+t+"-holder"),y.contentContainer.append(y.content)},parseEl:function(e){var t,i=y.items[e];if((i=i.tagName?{el:d(i)}:(t=i.type,{data:i,src:i.src})).el){for(var a=y.types,r=0;r<a.length;r++)if(i.el.hasClass("mfp-"+a[r])){t=a[r];break}i.src=i.el.attr("data-mfp-src"),i.src||(i.src=i.el.attr("href"))}return i.type=t||y.st.type||"inline",i.index=e,i.parsed=!0,y.items[e]=i,p("ElementParse",i),y.items[e]},addGroup:function(t,i){function e(e){e.mfpEl=this,y._openClick(e,t,i)}var a="click.magnificPopup";(i=i||{}).mainEl=t,i.items?(i.isObj=!0,t.off(a).on(a,e)):(i.isObj=!1,i.delegate?t.off(a).on(a,i.delegate,e):(i.items=t).off(a).on(a,e))},_openClick:function(e,t,i){if((void 0!==i.midClick?i.midClick:d.magnificPopup.defaults.midClick)||2!==e.which&&!e.ctrlKey&&!e.metaKey){var a=void 0!==i.disableOn?i.disableOn:d.magnificPopup.defaults.disableOn;if(a)if(d.isFunction(a)){if(!a.call(y))return!0}else if(C.width()<a)return!0;e.type&&(e.preventDefault(),y.isOpen&&e.stopPropagation()),i.el=d(e.mfpEl),i.delegate&&(i.items=t.find(i.delegate)),y.open(i)}},updateStatus:function(e,t){if(y.preloader){a!==e&&y.container.removeClass("mfp-s-"+a),t||"loading"!==e||(t=y.st.tLoading);var i={status:e,text:t};p("UpdateStatus",i),e=i.status,t=i.text,y.preloader.html(t),y.preloader.find("a").on("click",function(e){e.stopImmediatePropagation()}),y.container.addClass("mfp-s-"+e),a=e}},_checkIfClose:function(e){if(!d(e).hasClass(w)){var t=y.st.closeOnContentClick,i=y.st.closeOnBgClick;if(t&&i)return!0;if(!y.content||d(e).hasClass("mfp-close")||y.preloader&&e===y.preloader[0])return!0;if(e===y.content[0]||d.contains(y.content[0],e)){if(t)return!0}else if(i&&d.contains(document,e))return!0;return!1}},_addClassToMFP:function(e){y.bgOverlay.addClass(e),y.wrap.addClass(e)},_removeClassFromMFP:function(e){this.bgOverlay.removeClass(e),y.wrap.removeClass(e)},_hasScrollBar:function(e){return(y.isIE7?_.height():document.body.scrollHeight)>(e||C.height())},_setFocus:function(){(y.st.focus?y.content.find(y.st.focus).eq(0):y.wrap).focus()},_onFocusIn:function(e){if(e.target!==y.wrap[0]&&!d.contains(y.wrap[0],e.target))return y._setFocus(),!1},_parseMarkup:function(r,e,t){var n;t.data&&(e=d.extend(t.data,e)),p(g,[r,e,t]),d.each(e,function(e,t){if(void 0===t||!1===t)return!0;if(1<(n=e.split("_")).length){var i=r.find(b+"-"+n[0]);if(0<i.length){var a=n[1];"replaceWith"===a?i[0]!==t[0]&&i.replaceWith(t):"img"===a?i.is("img")?i.attr("src",t):i.replaceWith('<img src="'+t+'" class="'+i.attr("class")+'" />'):i.attr(n[1],t)}}else r.find(b+"-"+e).html(t)})},_getScrollbarSize:function(){if(void 0===y.scrollbarSize){var e=document.createElement("div");e.style.cssText="width: 99px; height: 99px; overflow: scroll; position: absolute; top: -9999px;",document.body.appendChild(e),y.scrollbarSize=e.offsetWidth-e.clientWidth,document.body.removeChild(e)}return y.scrollbarSize}},d.magnificPopup={instance:null,proto:e.prototype,modules:[],open:function(e,t){return n(),(e=e?d.extend(!0,{},e):{}).isObj=!0,e.index=t||0,this.instance.open(e)},close:function(){return d.magnificPopup.instance&&d.magnificPopup.instance.close()},registerModule:function(e,t){t.options&&(d.magnificPopup.defaults[e]=t.options),d.extend(this.proto,t.proto),this.modules.push(e)},defaults:{disableOn:0,key:null,midClick:!1,mainClass:"",preloader:!0,focus:"",closeOnContentClick:!1,closeOnBgClick:!0,closeBtnInside:!0,showCloseBtn:!0,enableEscapeKey:!0,modal:!1,alignTop:!1,removalDelay:0,prependTo:null,fixedContentPos:"auto",fixedBgPos:"auto",overflowY:"auto",closeMarkup:'<button title="%title%" type="button" class="mfp-close">×</button>',tClose:"Close (Esc)",tLoading:"Loading..."}},d.fn.magnificPopup=function(e){n();var t=d(this);if("string"==typeof e)if("open"===e){var i,a=Q?t.data("magnificPopup"):t[0].magnificPopup,r=parseInt(arguments[1],10)||0;i=a.items?a.items[r]:(i=t,a.delegate&&(i=i.find(a.delegate)),i.eq(r)),y._openClick({mfpEl:i},t,a)}else y.isOpen&&y[e].apply(y,Array.prototype.slice.call(arguments,1));else e=d.extend(!0,{},e),Q?t.data("magnificPopup",e):t[0].magnificPopup=e,y.addGroup(t,e);return t};function k(){I&&(T.after(I.addClass(x)).detach(),I=null)}var x,T,I,M="inline";d.magnificPopup.registerModule(M,{options:{hiddenClass:"hide",markup:"",tNotFound:"Content not found"},proto:{initInline:function(){y.types.push(M),m(l+"."+M,function(){k()})},getInline:function(e,t){if(k(),e.src){var i=y.st.inline,a=d(e.src);if(a.length){var r=a[0].parentNode;r&&r.tagName&&(T||(x=i.hiddenClass,T=u(x),x="mfp-"+x),I=a.after(T).detach().removeClass(x)),y.updateStatus("ready")}else y.updateStatus("error",i.tNotFound),a=d("<div>");return e.inlineElement=a}return y.updateStatus("ready"),y._parseMarkup(t,{},e),t}}});function P(){E&&d(document.body).removeClass(E)}function S(){P(),y.req&&y.req.abort()}var E,O="ajax";d.magnificPopup.registerModule(O,{options:{settings:null,cursor:"mfp-ajax-cur",tError:'<a href="%url%">The content</a> could not be loaded.'},proto:{initAjax:function(){y.types.push(O),E=y.st.ajax.cursor,m(l+"."+O,S),m("BeforeChange."+O,S)},getAjax:function(r){E&&d(document.body).addClass(E),y.updateStatus("loading");var e=d.extend({url:r.src,success:function(e,t,i){var a={data:e,xhr:i};p("ParseAjax",a),y.appendContent(d(a.data),O),r.finished=!0,P(),y._setFocus(),setTimeout(function(){y.wrap.addClass(j)},16),y.updateStatus("ready"),p("AjaxContentAdded")},error:function(){P(),r.finished=r.loadError=!0,y.updateStatus("error",y.st.ajax.tError.replace("%url%",r.src))}},y.st.ajax.settings);return y.req=d.ajax(e),""}}});var z;d.magnificPopup.registerModule("image",{options:{markup:'<div class="mfp-figure"><div class="mfp-close"></div><figure><div class="mfp-img"></div><figcaption><div class="mfp-bottom-bar"><div class="mfp-title"></div><div class="mfp-counter"></div></div></figcaption></figure></div>',cursor:"mfp-zoom-out-cur",titleSrc:"title",verticalFit:!0,tError:'<a href="%url%">The image</a> could not be loaded.'},proto:{initImage:function(){var e=y.st.image,t=".image";y.types.push("image"),m(h+t,function(){"image"===y.currItem.type&&e.cursor&&d(document.body).addClass(e.cursor)}),m(l+t,function(){e.cursor&&d(document.body).removeClass(e.cursor),C.off("resize"+b)}),m("Resize"+t,y.resizeImage),y.isLowIE&&m("AfterChange",y.resizeImage)},resizeImage:function(){var e=y.currItem;if(e&&e.img&&y.st.image.verticalFit){var t=0;y.isLowIE&&(t=parseInt(e.img.css("padding-top"),10)+parseInt(e.img.css("padding-bottom"),10)),e.img.css("max-height",y.wH-t)}},_onImageHasSize:function(e){e.img&&(e.hasSize=!0,z&&clearInterval(z),e.isCheckingImgSize=!1,p("ImageHasSize",e),e.imgHidden&&(y.content&&y.content.removeClass("mfp-loading"),e.imgHidden=!1))},findImageSize:function(t){var i=0,a=t.img[0],r=function(e){z&&clearInterval(z),z=setInterval(function(){0<a.naturalWidth?y._onImageHasSize(t):(200<i&&clearInterval(z),3===++i?r(10):40===i?r(50):100===i&&r(500))},e)};r(1)},getImage:function(e,t){var i=0,a=function(){e&&(e.img[0].complete?(e.img.off(".mfploader"),e===y.currItem&&(y._onImageHasSize(e),y.updateStatus("ready")),e.hasSize=!0,e.loaded=!0,p("ImageLoadComplete")):++i<200?setTimeout(a,100):r())},r=function(){e&&(e.img.off(".mfploader"),e===y.currItem&&(y._onImageHasSize(e),y.updateStatus("error",n.tError.replace("%url%",e.src))),e.hasSize=!0,e.loaded=!0,e.loadError=!0)},n=y.st.image,o=t.find(".mfp-img");if(o.length){var s=document.createElement("img");s.className="mfp-img",e.el&&e.el.find("img").length&&(s.alt=e.el.find("img").attr("alt")),e.img=d(s).on("load.mfploader",a).on("error.mfploader",r),s.src=e.src,o.is("img")&&(e.img=e.img.clone()),0<(s=e.img[0]).naturalWidth?e.hasSize=!0:s.width||(e.hasSize=!1)}return y._parseMarkup(t,{title:function(e){if(e.data&&void 0!==e.data.title)return e.data.title;var t=y.st.image.titleSrc;if(t){if(d.isFunction(t))return t.call(y,e);if(e.el)return e.el.attr(t)||""}return""}(e),img_replaceWith:e.img},e),y.resizeImage(),e.hasSize?(z&&clearInterval(z),e.loadError?(t.addClass("mfp-loading"),y.updateStatus("error",n.tError.replace("%url%",e.src))):(t.removeClass("mfp-loading"),y.updateStatus("ready"))):(y.updateStatus("loading"),e.loading=!0,e.hasSize||(e.imgHidden=!0,t.addClass("mfp-loading"),y.findImageSize(e))),t}}});var H;d.magnificPopup.registerModule("zoom",{options:{enabled:!1,easing:"ease-in-out",duration:300,opener:function(e){return e.is("img")?e:e.find("img")}},proto:{initZoom:function(){var e,n=y.st.zoom,t=".zoom";if(n.enabled&&y.supportsTransition){function i(e){var t=e.clone().removeAttr("style").removeAttr("class").addClass("mfp-animated-image"),i="all "+n.duration/1e3+"s "+n.easing,a={position:"fixed",zIndex:9999,left:0,top:0,"-webkit-backface-visibility":"hidden"},r="transition";return a["-webkit-"+r]=a["-moz-"+r]=a["-o-"+r]=a[r]=i,t.css(a),t}function a(){y.content.css("visibility","visible")}var r,o,s=n.duration;m("BuildControls"+t,function(){if(y._allowZoom()){if(clearTimeout(r),y.content.css("visibility","hidden"),!(e=y._getItemToZoom()))return void a();(o=i(e)).css(y._getOffset()),y.wrap.append(o),r=setTimeout(function(){o.css(y._getOffset(!0)),r=setTimeout(function(){a(),setTimeout(function(){o.remove(),e=o=null,p("ZoomAnimationEnded")},16)},s)},16)}}),m(c+t,function(){if(y._allowZoom()){if(clearTimeout(r),y.st.removalDelay=s,!e){if(!(e=y._getItemToZoom()))return;o=i(e)}o.css(y._getOffset(!0)),y.wrap.append(o),y.content.css("visibility","hidden"),setTimeout(function(){o.css(y._getOffset())},16)}}),m(l+t,function(){y._allowZoom()&&(a(),o&&o.remove(),e=null)})}},_allowZoom:function(){return"image"===y.currItem.type},_getItemToZoom:function(){return!!y.currItem.hasSize&&y.currItem.img},_getOffset:function(e){var t,i=(t=e?y.currItem.img:y.st.zoom.opener(y.currItem.el||y.currItem)).offset(),a=parseInt(t.css("padding-top"),10),r=parseInt(t.css("padding-bottom"),10);i.top-=d(window).scrollTop()-a;var n={width:t.width(),height:(Q?t.innerHeight():t[0].offsetHeight)-r-a};return void 0===H&&(H=void 0!==document.createElement("p").style.MozTransform),H?n["-moz-transform"]=n.transform="translate("+i.left+"px,"+i.top+"px)":(n.left=i.left,n.top=i.top),n}}});function B(e){if(y.currTemplate[A]){var t=y.currTemplate[A].find("iframe");t.length&&(e||(t[0].src="//about:blank"),y.isIE8&&t.css("display",e?"block":"none"))}}var A="iframe";d.magnificPopup.registerModule(A,{options:{markup:'<div class="mfp-iframe-scaler"><div class="mfp-close"></div><iframe class="mfp-iframe" src="//about:blank" frameborder="0" allowfullscreen></iframe></div>',srcAction:"iframe_src",patterns:{youtube:{index:"youtube.com",id:"v=",src:"//www.youtube.com/embed/%id%?autoplay=1"},vimeo:{index:"vimeo.com/",id:"/",src:"//player.vimeo.com/video/%id%?autoplay=1"},gmaps:{index:"//maps.google.",src:"%id%&output=embed"}}},proto:{initIframe:function(){y.types.push(A),m("BeforeChange",function(e,t,i){t!==i&&(t===A?B():i===A&&B(!0))}),m(l+"."+A,function(){B()})},getIframe:function(e,t){var i=e.src,a=y.st.iframe;d.each(a.patterns,function(){if(-1<i.indexOf(this.index))return this.id&&(i="string"==typeof this.id?i.substr(i.lastIndexOf(this.id)+this.id.length,i.length):this.id.call(this,i)),i=this.src.replace("%id%",i),!1});var r={};return a.srcAction&&(r[a.srcAction]=i),y._parseMarkup(t,r,e),y.updateStatus("ready"),t}}});function L(e){var t=y.items.length;return t-1<e?e-t:e<0?t+e:e}function $(e,t,i){return e.replace(/%curr%/gi,t+1).replace(/%total%/gi,i)}d.magnificPopup.registerModule("gallery",{options:{enabled:!1,arrowMarkup:'<button title="%title%" type="button" class="mfp-arrow mfp-arrow-%dir%"></button>',preload:[0,2],navigateByImgClick:!0,arrows:!0,tPrev:"Previous (Left arrow key)",tNext:"Next (Right arrow key)",tCounter:"%curr% of %total%"},proto:{initGallery:function(){var n=y.st.gallery,e=".mfp-gallery",r=Boolean(d.fn.mfpFastClick);if(y.direction=!0,!n||!n.enabled)return!1;v+=" mfp-gallery",m(h+e,function(){n.navigateByImgClick&&y.wrap.on("click"+e,".mfp-img",function(){if(1<y.items.length)return y.next(),!1}),_.on("keydown"+e,function(e){37===e.keyCode?y.prev():39===e.keyCode&&y.next()})}),m("UpdateStatus"+e,function(e,t){t.text&&(t.text=$(t.text,y.currItem.index,y.items.length))}),m(g+e,function(e,t,i,a){var r=y.items.length;i.counter=1<r?$(n.tCounter,a.index,r):""}),m("BuildControls"+e,function(){if(1<y.items.length&&n.arrows&&!y.arrowLeft){var e=n.arrowMarkup,t=y.arrowLeft=d(e.replace(/%title%/gi,n.tPrev).replace(/%dir%/gi,"left")).addClass(w),i=y.arrowRight=d(e.replace(/%title%/gi,n.tNext).replace(/%dir%/gi,"right")).addClass(w),a=r?"mfpFastClick":"click";t[a](function(){y.prev()}),i[a](function(){y.next()}),y.isIE7&&(u("b",t[0],!1,!0),u("a",t[0],!1,!0),u("b",i[0],!1,!0),u("a",i[0],!1,!0)),y.container.append(t.add(i))}}),m(o+e,function(){y._preloadTimeout&&clearTimeout(y._preloadTimeout),y._preloadTimeout=setTimeout(function(){y.preloadNearbyImages(),y._preloadTimeout=null},16)}),m(l+e,function(){_.off(e),y.wrap.off("click"+e),y.arrowLeft&&r&&y.arrowLeft.add(y.arrowRight).destroyMfpFastClick(),y.arrowRight=y.arrowLeft=null})},next:function(){y.direction=!0,y.index=L(y.index+1),y.updateItemHTML()},prev:function(){y.direction=!1,y.index=L(y.index-1),y.updateItemHTML()},goTo:function(e){y.direction=e>=y.index,y.index=e,y.updateItemHTML()},preloadNearbyImages:function(){var e,t=y.st.gallery.preload,i=Math.min(t[0],y.items.length),a=Math.min(t[1],y.items.length);for(e=1;e<=(y.direction?a:i);e++)y._preloadItem(y.index+e);for(e=1;e<=(y.direction?i:a);e++)y._preloadItem(y.index-e)},_preloadItem:function(e){if(e=L(e),!y.items[e].preloaded){var t=y.items[e];t.parsed||(t=y.parseEl(e)),p("LazyLoad",t),"image"===t.type&&(t.img=d('<img class="mfp-img" />').on("load.mfploader",function(){t.hasSize=!0}).on("error.mfploader",function(){t.hasSize=!0,t.loadError=!0,p("LazyLoadError",t)}).attr("src",t.src)),t.preloaded=!0}}}});var F,R,D="retina";function W(){C.off("touchmove"+R+" touchend"+R)}d.magnificPopup.registerModule(D,{options:{replaceSrc:function(e){return e.src.replace(/\.\w+$/,function(e){return"@2x"+e})},ratio:1},proto:{initRetina:function(){if(1<window.devicePixelRatio){var i=y.st.retina,a=i.ratio;1<(a=isNaN(a)?a():a)&&(m("ImageHasSize."+D,function(e,t){t.img.css({"max-width":t.img[0].naturalWidth/a,width:"100%"})}),m("ElementParse."+D,function(e,t){t.src=i.replaceSrc(t,a)}))}}}}),F="ontouchstart"in window,R=".mfpFastClick",d.fn.mfpFastClick=function(l){return d(this).each(function(){var t,i,a,r,n,o,s,e=d(this);F&&e.on("touchstart"+R,function(e){n=!1,s=1,o=e.originalEvent?e.originalEvent.touches[0]:e.touches[0],a=o.clientX,r=o.clientY,C.on("touchmove"+R,function(e){o=e.originalEvent?e.originalEvent.touches:e.touches,s=o.length,o=o[0],(10<Math.abs(o.clientX-a)||10<Math.abs(o.clientY-r))&&(n=!0,W())}).on("touchend"+R,function(e){W(),n||1<s||(t=!0,e.preventDefault(),clearTimeout(i),i=setTimeout(function(){t=!1},1e3),l())})}),e.on("click"+R,function(){t||l()})})},d.fn.destroyMfpFastClick=function(){d(this).off("touchstart"+R+" click"+R),F&&C.off("touchmove"+R+" touchend"+R)},n()}),"function"!=typeof Object.create&&(Object.create=function(e){function t(){}return t.prototype=e,new t}),function(n,o){var i={init:function(e,t){this.elem=t,this.$elem=n(t),this.options=n.extend({},n.fn.rtTab.options,e),this.rtTabs()},rtTabs:function(){var t=this,e=t.options.activeTab;if(t.$elem.find("li:nth-child("+e+")").addClass("active"),t.rtTabContent(activeTabContent="yes"),t.rtClick(),!0==("false"!==t.$elem.attr("data-hash"))){var i=o.location.hash;i&&t.$elem.find("li").find('a[href="'+i+'"]').trigger("click"),n(o).on("hashchange",function(){var e=o.location.hash;t.$elem.find("li").find('a[href="'+e+'"]').trigger("click")})}},rtClick:function(){var a=this,r=a.$elem.find("li");r.find("a").on("click",function(e){e.preventDefault(),r.removeClass("active"),a.rtTabContent(),n(this).parent().addClass("active");var t=n(this).attr("href");if(n(t).removeClass("hide"),!0==("false"!==a.$elem.attr("data-hash"))){var i=n(o).scrollTop();location.hash=n(this).attr("href"),n(o).scrollTop(i)}"function"==typeof a.options.onComplete&&a.options.onComplete.apply(a.elem,arguments)})},rtTabContent:function(i){this.$elem.find("li").find("a").each(function(){var e=n(this),t=e.attr("href");"yes"===i&&e.parent().hasClass("active")||n(t).addClass("hide")})}};n.fn.rtTab=function(t){return this.each(function(){var e=Object.create(i);e.init(t,this),n.data(this,"rtTab",e)})},n.fn.rtTab.options={activeTab:1,onComplete:null}}(jQuery,window,document);var comment_media=!1;function apply_rtMagnificPopup(t){jQuery("document").ready(function(s){var e="";if(e="undefined"==typeof rtmedia_load_more?"Loading media":rtmedia_load_more,"undefined"!=typeof rtmedia_lightbox_enabled&&"1"==rtmedia_lightbox_enabled){var n,l,c=!1;0<s(".activity-item .rtmedia-activity-container .rtmedia-list-item > a").siblings("p").children("a").length&&s(".activity-item .rtmedia-activity-container .rtmedia-list-item > a").siblings("p").children("a").addClass("no-popup"),rtMagnificPopup=jQuery(t).magnificPopup({delegate:"a:not(.no-popup, .mejs-time-slider, .mejs-volume-slider, .mejs-horizontal-volume-slider)",type:"ajax",fixedContentPos:!0,fixedBgPos:!0,tLoading:e+" #%curr%...",mainClass:"mfp-img-mobile",preload:[1,3],closeOnBgClick:!0,gallery:{enabled:!0,navigateByImgClick:!0,arrowMarkup:"",preload:[0,1]},image:{tError:'<a href="%url%">The image #%curr%</a> could not be loaded.',titleSrc:function(e){return e.el.attr("title")+"<small>by Marsel Van Oosten</small>"}},callbacks:{ajaxContentAdded:function(){e=jQuery.magnificPopup.instance,1===jQuery(e.items).size()&&jQuery(".mfp-arrow").remove();var e=jQuery.magnificPopup.instance,t=e.currItem.el,i=t.parent();if(i.is("li")||(i=i.parent()),(i.is(":nth-last-child(2)")||i.is(":last-child"))&&i.find("a").hasClass("rtmedia-list-item-a")){i.next();"block"==jQuery("#rtMedia-galary-next").css("display")&&(c||(n=e.ev.children(),c=!0,l=nextpage),jQuery("#rtMedia-galary-next").click())}var a=e.items.length;if(e.index!=a-1||i.is(":last-child")){"undefined"!=typeof _wpmejsSettings&&_wpmejsSettings.pluginPath;var o=jQuery(".rtmedia-container .rtmedia-single-meta").height(),r=!1;void 0!==e&&void 0!==e.probablyMobile&&1==e.probablyMobile&&(r=!0),s(".mfp-content .rtmedia-single-media .wp-audio-shortcode,.mfp-content .rtmedia-single-media .wp-video-shortcode,.mfp-content .rtmedia-single-media .bp_media_content video").attr("autoplay",!0),r&&s(".mfp-content .rtmedia-single-media .wp-video-shortcode,.mfp-content .rtmedia-single-media .bp_media_content video").attr("muted",!1),s(".mfp-content .rtmedia-single-media .wp-audio-shortcode,.mfp-content .rtmedia-single-media .wp-video-shortcode,.mfp-content .rtmedia-single-media .bp_media_content video").mediaelementplayer({classPrefix:"mejs-",defaultVideoWidth:480,hideVolumeOnTouchDevices:!1,features:["playpause","progress","current","volume","fullscreen"],defaultVideoHeight:270,alwaysShowControls:r,enableAutosize:!0,clickToPlayPause:!0,videoHeight:-1,success:function(n,e){n.addEventListener("loadeddata",function(e){var t=s(n).height(),i=s(window).height(),a=jQuery("div.rtm-ltb-action-container").height(),r=o-(a=a+50);i<t&&jQuery(".rtmedia-container #rtmedia-single-media-container .mejs-container").attr("style","height:"+r+"px !important; transition:0.2s")},!1),r&&s(n).hasClass("wp-video-shortcode")?jQuery("body").on("touchstart",".mejs-overlay-button",function(e){n.paused?n.play():n.pause()}):n.pause()}}),s(".mfp-content .mejs-audio .mejs-controls").css("position","relative"),rtMediaHook.call("rtmedia_js_popup_after_content_added",[]),"undefined"!=typeof bp&&void 0!==bp.mentions&&void 0!==bp.mentions.users&&(s("#atwho-container #atwho-ground-comment_content").remove(),s("#comment_content").bp_mentions(bp.mentions.users)),rtmedia_reset_video_and_audio_for_popup(),apply_rtMagnificPopup(".rtmedia-list-media.rtm-gallery-list, .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, ul.rtm-comment-container")}else t.click()},open:function(){var e=jQuery(".mfp-bg"),t=jQuery(".mfp-wrap");e.height(e.height()+t.height())},close:function(e){c&&(mfp.ev.empty(),mfp.ev.append(n),nextpage=l,c=!1,1<nextpage&&jQuery("#rtMedia-galary-next").show()),rtmedia_single_page_popup_close()},BeforeChange:function(e){}}})}jQuery(document).ajaxComplete(function(){jQuery("[id^=imgedit-leaving]").filter(function(){var e=jQuery(this).text();jQuery(this).text(e.replace("OK","Save"))})})})}var rtMediaHook={hooks:[],is_break:!1,register:function(e,t){void 0===rtMediaHook.hooks[e]&&(rtMediaHook.hooks[e]=[]),rtMediaHook.hooks[e].push(t)},call:function(e,arguments){if(void 0!==rtMediaHook.hooks[e])for(i=0;i<rtMediaHook.hooks[e].length;++i)if(1!=rtMediaHook.hooks[e][i](arguments))return!(rtMediaHook.is_break=!0);return!0}};function rtmedia_init_action_dropdown(e){var t,i;jQuery(e+" .click-nav > span,"+e+" .click-nav > div").toggleClass("no-js js"),jQuery(e+" .click-nav .js ul").hide(),jQuery(e+" .click-nav .clicker").click(function(e){t=jQuery("#rtm-media-options .click-nav .clicker").next("ul"),i=jQuery(this).next("ul"),jQuery.each(t,function(e,t){jQuery(t).html()!=i.html()&&jQuery(t).hide()}),jQuery(i).toggle(),e.stopPropagation()})}function bp_media_create_element(e){return!1}function rtmedia_version_compare(e,t){if(typeof e+typeof t!="stringstring")return!1;for(var i=e.split("."),a=t.split("."),r=0,n=Math.max(i.length,a.length);r<n;r++){if(i[r]&&!a[r]&&0<parseInt(i[r])||parseInt(i[r])>parseInt(a[r]))return!0;if(a[r]&&!i[r]&&0<parseInt(a[r])||parseInt(i[r])<parseInt(a[r]))return!1}return!0}function rtm_is_element_exist(e){return 0<jQuery(e).length}function rtm_masonry_reload(e){setTimeout(function(){e.masonry("reload")},250)}function rtm_search_media_text_validation(){""===jQuery("#media_search_input").val()?jQuery("#media_search").css("cursor","not-allowed"):jQuery("#media_search").css("cursor","pointer")}function rtmediaGetParameterByName(e){e=e.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]");var t=new RegExp("[\\?&]"+e+"=([^&#]*)").exec(location.search);return null==t?"":decodeURIComponent(t[1].replace(/\+/g," "))}function rtmedia_single_media_alert_message(e,t,i){var a="rtmedia-success";"warning"==t&&(a="rtmedia-warning");var r=!1;jQuery(".rtmedia-message-container").each(function(e,t){return t=jQuery(t),i&&t.hasClass("rtmedia-empty-comment-error-class")?(t.remove(),!(r=!0)):void 0!==i||t.hasClass("rtmedia-empty-comment-error-class")?void 0:(t.remove(),!(r=!0))});var n,o=jQuery("<div>",{title:"Click to dismiss",class:"rtmedia-message-container"+(i?" rtmedia-empty-comment-error-class":""),style:"margin:1em 0;"}),s=jQuery("<span>",{class:a});s.html(e),s.appendTo(o),i?(n=jQuery("#rt_media_comment_form"),jQuery("#comment_content").focus()):void 0===i&&(n=jQuery(".rtmedia-single-media .rtmedia-media")).css("opacity","0.2"),n.after(o),r&&(s.css({border:"2px solid #884646"}),setTimeout(function(){s.css({border:"none"})},500)),setTimeout(function(){o.remove(),void 0===i&&n.css("opacity","1")},3e3),o.click(function(){o.remove(),void 0===i&&n.css("opacity","1")})}function rtmedia_gallery_action_alert_message(e,t){var i="rtmedia-success";"warning"==t&&(i="rtmedia-warning");jQuery("body").append('<div class="rtmedia-gallery-alert-container"> </div>'),jQuery(".rtmedia-gallery-alert-container").append("<div class='rtmedia-gallery-message-box'><span class='"+i+"'>"+e+" </span></div>"),setTimeout(function(){jQuery(".rtmedia-gallery-alert-container").remove()},3e3),jQuery(".rtmedia-gallery-message-box").click(function(){jQuery(".rtmedia-gallery-alert-container").remove()})}function rtmedia_activity_masonry(){jQuery("#activity-stream .rtmedia-activity-container .rtmedia-list").masonry({itemSelector:".rtmedia-list-item",gutter:7});var e=0,t=setInterval(function(){5===(e+=1)&&clearInterval(t),jQuery.each(jQuery(".rtmedia-activity-container .rtmedia-list.masonry .rtmedia-item-title"),function(e,t){jQuery(t).width(jQuery(t).siblings(".rtmedia-item-thumbnail").children("img").width())}),rtm_masonry_reload(jQuery("#activity-stream .rtmedia-activity-container .rtmedia-list"))},1e3)}function get_parameter(e,t){if(!e)return!1;t=t||window.location.href;e=e.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]");var i=new RegExp(e+"=([^&#]*)").exec(t);return null!==i&&i[1]}function rtm_upload_terms_activity(){if(0<jQuery("#rtmedia_upload_terms_conditions").length){jQuery("#bp-nouveau-activity-form").on("click","#aw-whats-new-submit",function(e){var t=jQuery("#whats-new-form"),i=t.find("#rtmedia_upload_terms_conditions");if(0!==i.length&&!1===i.prop("checked")&&0===t.find("#message").length){e.preventDefault();var a=t.find(".rtmedia-upload-terms");rtp_display_terms_warning(a,rtmedia_upload_terms_check_terms_message)}});var t=jQuery("#whats-new-form");0<t.length&&jQuery("#whats-new-form, #rtmedia_upload_terms_conditions").on("click",function(e){t.find("input:hidden").each(function(){jQuery(this).prop("disabled",!1)})})}}jQuery("document").ready(function(n){function r(){if(0<jQuery("#rtmedia-media-view-form").length){var e=jQuery("#rtmedia-media-view-form").attr("action");jQuery.post(e,{},function(e){})}}function o(e,t,i){var a=new Date;a.setTime(a.getTime()+24*i*60*60*1e3);var r="expires="+a.toUTCString();document.cookie=e+"="+t+";"+r+";path=/"}jQuery(document).ajaxComplete(function(e,t,i){if("legacy"!==bp_template_pack&&bp_template_pack){var a=get_parameter("action",i.data);"activity_filter"!==a&&"post_update"!==a&&"get_single_activity_content"!==a&&"activity_get_older_updates"!==a||"undefined"==typeof rtmedia_masonry_layout||"true"!==rtmedia_masonry_layout||"undefined"==typeof rtmedia_masonry_layout_activity||"true"!==rtmedia_masonry_layout_activity?"activity_filter"!==a&&"post_update"!==a&&"get_single_activity_content"!==a&&"activity_get_older_updates"!==a||setTimeout(function(){apply_rtMagnificPopup(".rtmedia-list-media.rtm-gallery-list, .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, ul.rtm-comment-container"),rtmedia_activity_stream_comment_media()},1e3):setTimeout(function(){apply_rtMagnificPopup(".rtmedia-list-media.rtm-gallery-list, .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, ul.rtm-comment-container"),rtmedia_activity_masonry(),rtmedia_activity_stream_comment_media()},1e3)}}),jQuery(".rtmedia-uploader-div").css({opacity:"1",display:"block",visibility:"visible"}),jQuery(" #whats-new-options ").css({opacity:"1"}),void 0!==n.fn.rtTab&&n(".rtm-tabs").rtTab(),0<jQuery(".rtmedia-modal-link").length&&n(".rtmedia-modal-link").magnificPopup({type:"inline",midClick:!0,closeBtnInside:!0}),n("#rt_media_comment_form").submit(function(e){return""!=n.trim(n("#comment_content").val())||(0==jQuery("#rtmedia-single-media-container").length?rtmedia_gallery_action_alert_message(rtmedia_empty_comment_msg,"warning"):rtmedia_single_media_alert_message(rtmedia_empty_comment_msg,"warning"),!1)}),n("li.rtmedia-list-item p a").each(function(e){n(this).addClass("no-popup")}),n("li.rtmedia-list-item p a").each(function(e){n(this).addClass("no-popup")}),"undefined"!=typeof rtmedia_lightbox_enabled&&"1"==rtmedia_lightbox_enabled&&apply_rtMagnificPopup(".rtmedia-list-media.rtm-gallery-list, .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, ul.rtm-comment-container"),jQuery.ajaxPrefilter(function(e,t,i){try{if(null==t.data||void 0===t.data||void 0===t.data.action)return!0}catch(e){return!0}if("activity_get_older_updates"==t.data.action){var a=t.success;e.success=function(e){"function"==typeof a&&a(e),apply_rtMagnificPopup(".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"),rtMediaHook.call("rtmedia_js_after_activity_added",[])}}else if("get_single_activity_content"==t.data.action){a=t.success;e.success=function(e){"function"==typeof a&&a(e),setTimeout(function(){apply_rtMagnificPopup(".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"),jQuery("ul.activity-list li.rtmedia_update:first-child .wp-audio-shortcode, ul.activity-list li.rtmedia_update:first-child .wp-video-shortcode").mediaelementplayer({classPrefix:"mejs-",defaultVideoWidth:480,defaultVideoHeight:270})},900)}}}),jQuery.ajaxPrefilter(function(e,t,i){try{if(null==t.data||void 0===t.data||void 0===t.data.action)return!0}catch(e){return!0}if("activity_get_older_updates"==t.data.action){var a=t.success;e.success=function(e){"function"==typeof a&&a(e),apply_rtMagnificPopup(".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"),jQuery("ul.activity-list li.rtmedia_update div.rtmedia-item-thumbnail > audio.wp-audio-shortcode, ul.activity-list li.rtmedia_update div.rtmedia-item-thumbnail > video.wp-video-shortcode").mediaelementplayer({classPrefix:"mejs-",defaultVideoWidth:480,defaultVideoHeight:270}),setTimeout(function(){rtmedia_activity_stream_comment_media()},900),rtMediaHook.call("rtmedia_js_after_activity_added",[])}}}),jQuery(".rtmedia-container").on("click",".select-all",function(e){jQuery(this).toggleClass("unselect-all").toggleClass("select-all"),jQuery(this).attr("title",rtmedia_unselect_all_visible),jQuery(".rtmedia-list input").each(function(){jQuery(this).prop("checked",!0)}),jQuery(".rtmedia-list-item").addClass("bulk-selected")}),jQuery(".rtmedia-container").on("click",".unselect-all",function(e){jQuery(this).toggleClass("select-all").toggleClass("unselect-all"),jQuery(this).attr("title",rtmedia_select_all_visible),jQuery(".rtmedia-list input").each(function(){jQuery(this).prop("checked",!1)}),jQuery(".rtmedia-list-item").removeClass("bulk-selected")}),jQuery(".rtmedia-container").on("click",".rtmedia-move",function(e){jQuery(".rtmedia-delete-container").slideUp(),jQuery(".rtmedia-move-container").slideToggle()}),jQuery("#rtmedia-create-album-modal").on("click","#rtmedia_create_new_album",function(e){if($albumname=jQuery("<span/>").text(jQuery.trim(jQuery("#rtmedia_album_name").val())).html(),$album_description=jQuery("#rtmedia_album_description"),$context=jQuery.trim(jQuery("#rtmedia_album_context").val()),$context_id=jQuery.trim(jQuery("#rtmedia_album_context_id").val()),$privacy=jQuery.trim(jQuery("#rtmedia_select_album_privacy").val()),$create_album_nonce=jQuery.trim(jQuery("#rtmedia_create_album_nonce").val()),""!=$albumname){var t={action:"rtmedia_create_album",name:$albumname,description:$album_description.val(),context:$context,context_id:$context_id,create_album_nonce:$create_album_nonce};""!==$privacy&&(t.privacy=$privacy),n("#rtmedia_create_new_album").attr("disabled","disabled");var r=n("#rtmedia_create_new_album").html();n("#rtmedia_create_new_album").prepend("<img src='"+rMedia_loading_file+"' />"),jQuery.post(rtmedia_ajax_url,t,function(i){if(void 0!==i.album){i=jQuery.trim(i.album);var a=!0;$album_description.val(""),n("#rtmedia_album_name").focus(),jQuery(".rtmedia-user-album-list").each(function(){if(jQuery(this).children("optgroup").each(function(){if(jQuery(this).attr("value")===$context)return a=!1,void jQuery(this).append('<option value="'+i+'">'+$albumname+"</option>")}),a){var e=$context.charAt(0).toUpperCase()+$context.slice(1)+" "+rtmedia_main_js_strings.rtmedia_albums,t='<optgroup value="'+$context+'" label="'+e+'"><option value="'+i+'">'+$albumname+"</option></optgroup>";jQuery(this).append(t)}}),jQuery('select.rtmedia-user-album-list option[value="'+i+'"]').prop("selected",!0),jQuery(".rtmedia-create-new-album-container").slideToggle(),jQuery("#rtmedia_album_name").val(""),jQuery("#rtmedia-create-album-modal").append("<div class='rtmedia-success rtmedia-create-album-alert'><b>"+$albumname+"</b>"+rtmedia_album_created_msg+"</div>"),setTimeout(function(){jQuery(".rtmedia-create-album-alert").remove()},4e3),setTimeout(function(){galleryObj.reloadView(),jQuery(".close-reveal-modal").click()},2e3)}else void 0!==i.error?rtmedia_gallery_action_alert_message(i.error,"warning"):rtmedia_gallery_action_alert_message(rtmedia_something_wrong_msg,"warning");n("#rtmedia_create_new_album").removeAttr("disabled"),n("#rtmedia_create_new_album").html(r)})}else rtmedia_gallery_action_alert_message(rtmedia_empty_album_name_msg,"warning")}),jQuery(".rtmedia-container").on("click",".rtmedia-delete-selected",function(e){0<jQuery(".rtmedia-list :checkbox:checked").length?confirm(rtmedia_selected_media_delete_confirmation)&&jQuery(this).closest("form").attr("action","../../../"+rtmedia_media_slug+"/delete").submit():rtmedia_gallery_action_alert_message(rtmedia_no_media_selected,"warning")}),jQuery(".rtmedia-container").on("click",".rtmedia-move-selected",function(e){0<jQuery(".rtmedia-list :checkbox:checked").length?confirm(rtmedia_selected_media_move_confirmation)&&jQuery(this).closest("form").attr("action","").submit():rtmedia_gallery_action_alert_message(rtmedia_no_media_selected,"warning")}),jQuery("#buddypress").on("change",".rtm-activity-privacy-opt",function(){var e=jQuery(this).attr("id");e=(e=e.split("-"))[e.length-1];var a=this;data={activity_id:e,privacy:jQuery(this).val(),nonce:jQuery("#rtmedia_activity_privacy_nonce").val(),action:"rtm_change_activity_privacy"},jQuery.post(ajaxurl,data,function(e){var t="",i="";i="true"==e?(t=rtmedia_main_js_strings.privacy_update_success,"success"):(t=rtmedia_main_js_strings.privacy_update_error,"fail"),jQuery(a).after('<p class="rtm-ac-privacy-updated '+i+'">'+t+"</p>"),setTimeout(function(){jQuery(a).siblings(".rtm-ac-privacy-updated").remove()},2e3)})}),jQuery(".media_search_input").on("keyup",function(){rtm_search_media_text_validation()}),r(),rtMediaHook.register("rtmedia_js_popup_after_content_added",function(){r(),jQuery(".rtmedia-container").on("click",".rtmedia-delete-media",function(e){e.preventDefault(),confirm(rtmedia_media_delete_confirmation)&&jQuery(this).closest("form").submit()}),mfp=jQuery.magnificPopup.instance,1<jQuery(mfp.items).size()&&0==comment_media?function(){var n=jQuery.magnificPopup.instance,e=n.probablyMobile,t=function(e){for(var t=e+"=",i=document.cookie.split(";"),a=0;a<i.length;a++){for(var r=i[a];" "==r.charAt(0);)r=r.substring(1);if(0==r.indexOf(t))return r.substring(t.length,r.length)}return""}("rtmedia-touch-swipe-tooltip");e&&""===t?(jQuery("#mobile-swipe-overlay").show(),jQuery("#mobile-swipe-overlay").on("click",function(e){o("rtmedia-touch-swipe-tooltip",!0,365),jQuery(this).hide(),jQuery("#rtmedia-single-media-container .mejs-playpause-button").trigger("click")}),jQuery("#mobile-swipe-overlay").swipe({swipe:function(e,t,i,a,r,n){o("rtmedia-touch-swipe-tooltip",!0,365),jQuery("#mobile-swipe-overlay").hide(),jQuery("#rtmedia-single-media-container .mejs-playpause-button").trigger("click")},threshold:0})):jQuery("#rtmedia-single-media-container .mejs-playpause-button").trigger("click");jQuery(".mfp-arrow-right").on("click",function(e){n.next()}),jQuery(".mfp-arrow-left").on("click",function(e){n.prev()}),jQuery(".mfp-content .rtmedia-media").swipe({swipeLeft:function(e,t,i,a,r){n.next()},swipeRight:function(e,t,i,a,r){n.prev()},threshold:0})}():(jQuery(".mfp-arrow-right").hide(),jQuery(".mfp-arrow-left").hide(),jQuery(document).unbind("keydown")),rtmedia_disable_popup_navigation("#comment_content"),rtmedia_disable_popup_navigation_comment_media_focus();var e=n(window).height();jQuery(".rtm-lightbox-container .mejs-video").css({height:.8*e,"over-flow":"hidden"}),jQuery(".mfp-content .rtmedia-media").css({"max-height":.87*e,"over-flow":"hidden"}),rtmedia_init_action_dropdown(".rtm-lightbox-container .rtmedia-actions"),jQuery(".rtmedia-comment-link").on("click",function(e){e.preventDefault(),jQuery("#comment_content").focus()}),jQuery(".rtm-more").shorten({showChars:130});var t=n(".rtm-gallery-title"),i="";""!=(i=n.isEmptyObject(t)?n("#subnav.item-list-tabs li.selected ").html():t.html())&&n(".rtm-ltb-gallery-title .ltb-title").html(i);var a=n("#subnav.item-list-tabs li.selected span").html();return n("li.total").html(a),!0});var t=jQuery("#drag-drop-area"),i=jQuery("#whats-new");t.html();jQuery("#rtmedia-upload-container").after("<div id='rtm-drop-files-title'>"+rtmedia_drop_media_msg+"</div>"),"undefined"!=typeof rtmedia_bp_enable_activity&&"1"==rtmedia_bp_enable_activity&&jQuery("#whats-new-textarea").append("<div id='rtm-drop-files-title'>"+rtmedia_drop_media_msg+"</div>"),jQuery(document).on("dragover",function(e){e.preventDefault(),e.target!=this&&(jQuery("#rtm-media-gallery-uploader").show(),"undefined"!=typeof rtmedia_bp_enable_activity&&"1"==rtmedia_bp_enable_activity&&i.addClass("rtm-drag-drop-active"),t.addClass("rtm-drag-drop-active"),jQuery("#rtm-drop-files-title").show())}).on("dragleave",function(e){if(e.preventDefault(),0!=e.originalEvent.pageX&&0!=e.originalEvent.pageY)return!1;"undefined"!=typeof rtmedia_bp_enable_activity&&"1"==rtmedia_bp_enable_activity&&(i.removeClass("rtm-drag-drop-active"),i.removeAttr("style")),t.removeClass("rtm-drag-drop-active"),jQuery("#rtm-drop-files-title").hide()}).on("drop",function(e){e.preventDefault(),jQuery(".bp-suggestions").focus(),"undefined"!=typeof rtmedia_bp_enable_activity&&"1"==rtmedia_bp_enable_activity&&(i.removeClass("rtm-drag-drop-active"),i.removeAttr("style")),t.removeClass("rtm-drag-drop-active"),jQuery("#rtm-drop-files-title").hide()}),jQuery(".rtmedia-container").on("click",".rtmedia-delete-album",function(e){e.preventDefault(),confirm(rtmedia_album_delete_confirmation)&&jQuery(this).closest("form").submit()}),jQuery(".rtmedia-container").on("click",".rtmedia-delete-media",function(e){e.preventDefault(),confirm(rtmedia_media_delete_confirmation)&&jQuery(this).closest("form").submit()}),rtmedia_init_action_dropdown(""),n(document).click(function(){n(".click-nav ul").is(":visible")&&n(".click-nav ul",this).hide()}),jQuery(".rtmedia-comment-link").on("click",function(e){e.preventDefault(),jQuery("#comment_content").focus()}),0<jQuery(".rtm-more").length&&n(".rtm-more").shorten({showChars:200}),"undefined"!=typeof rtmedia_masonry_layout&&"true"==rtmedia_masonry_layout&&"undefined"!=typeof rtmedia_masonry_layout_activity&&"true"==rtmedia_masonry_layout_activity&&rtmedia_activity_masonry(),jQuery(document).ajaxComplete(function(e,t,i){var a=get_parameter("action",i.data);"post_update"!==a&&"get_single_activity_content"!==a&&"activity_get_older_updates"!==a||"undefined"==typeof rtmedia_masonry_layout||"true"!=rtmedia_masonry_layout||"undefined"==typeof rtmedia_masonry_layout_activity||"true"!=rtmedia_masonry_layout_activity||rtmedia_activity_masonry()}),"undefined"!=typeof rtmedia_masonry_layout&&"true"==rtmedia_masonry_layout&&0==jQuery(".rtmedia-container .rtmedia-list.rtm-no-masonry").length&&((rtm_masonry_container=jQuery(".rtmedia-container .rtmedia-list")).masonry({itemSelector:".rtmedia-list-item"}),setInterval(function(){jQuery.each(jQuery(".rtmedia-list.masonry .rtmedia-item-title"),function(e,t){jQuery(t).width(jQuery(t).siblings(".rtmedia-item-thumbnail").children("img").width())}),rtm_masonry_reload(rtm_masonry_container)},1e3),jQuery.each(jQuery(".rtmedia-list.masonry .rtmedia-item-title"),function(e,t){jQuery(t).width(jQuery(t).siblings(".rtmedia-item-thumbnail").children("img").width())})),0<jQuery(".rtm-uploader-tabs").length&&jQuery(".rtm-uploader-tabs li").click(function(e){jQuery(this).hasClass("active")||(jQuery(this).siblings().removeClass("active"),jQuery(this).parents(".rtm-uploader-tabs").siblings().hide(),class_name=jQuery(this).attr("class"),jQuery(this).parents(".rtm-uploader-tabs").siblings('[data-id="'+class_name+'"]').show(),jQuery(this).addClass("active"),"rtm-upload-tab"!=class_name?jQuery("div.moxie-shim").hide():jQuery("div.moxie-shim").show())}),jQuery(".rtmedia-container").on("click",".rtm-delete-media",function(e){e.preventDefault();var t=RTMedia_Main_JS.media_delete_confirmation;if(confirm(t)){var i=jQuery(this).closest("li"),a=jQuery("#rtmedia_media_delete_nonce").val(),r=jQuery(this).parents(".rtmedia-list-item").data("media_type"),n={action:"delete_uploaded_media",nonce:a,media_id:i.attr("id"),media_type:r};jQuery.ajax({url:RTMedia_Main_JS.rtmedia_ajaxurl,type:"POST",data:n,dataType:"JSON",success:function(e){"rtmedia-media-deleted"===e.data.code?(rtmedia_gallery_action_alert_message(RTMedia_Main_JS.media_delete_success,"success"),i.remove(),"undefined"!=typeof rtmedia_masonry_layout&&"true"===rtmedia_masonry_layout&&rtm_masonry_reload(rtm_masonry_container),jQuery("#user-media span, #media-groups-li #media span").text(e.data.all_media_count),jQuery("#rtmedia-nav-item-photo span").text(e.data.photos_count),jQuery("#rtmedia-nav-item-music span").text(e.data.music_count),jQuery("#rtmedia-nav-item-video span").text(e.data.videos_count)):rtmedia_gallery_action_alert_message(e.data.message,"warning")}})}})}),function(u){u.fn.shorten=function(e){"use strict";var m={showChars:100,minHideChars:10,ellipsesText:"...",moreText:rtmedia_read_more,lessText:rtmedia__show_less,onLess:function(){},onMore:function(){},errMsg:null,force:!1};return e&&u.extend(m,e),!(u(this).data("jquery.shorten")&&!m.force)&&(u(this).data("jquery.shorten",!0),u(document).off("click",".morelink"),u(document).on({click:function(){var e=u(this);return e.hasClass("less")?(e.removeClass("less"),e.html(m.moreText),e.parent().prev().hide(0,function(){e.parent().prev().prev().show()}).hide(0,function(){m.onLess()})):(e.addClass("less"),e.html(m.lessText),e.parent().prev().show(0,function(){e.parent().prev().prev().hide()}).show(0,function(){m.onMore()})),!1}},".morelink"),this.each(function(){var e=u(this),t=e.html();if(e.text().length>m.showChars+m.minHideChars){var i=t.substr(0,m.showChars);if(0<=i.indexOf("<")){for(var a=!1,r="",n=0,o=[],s=null,l=0,c=0;c<=m.showChars;l++)if("<"!=t[l]||a||(a=!0,"/"==(s=t.substring(l+1,t.indexOf(">",l)))[0]?s!="/"+o[0]?m.errMsg="ERROR en HTML: the top of the stack should be the tag that closes":o.shift():"br"!=s.toLowerCase()&&o.unshift(s)),a&&">"==t[l]&&(a=!1),a)r+=t.charAt(l);else if(c++,n<=m.showChars)r+=t.charAt(l),n++;else if(0<o.length){for(j=0;j<o.length;j++)r+="</"+o[j]+">";break}i=u("<div/>").html(r+'<span class="ellip">'+m.ellipsesText+"</span>").html()}else i+=m.ellipsesText;var d='<div class="shortcontent">'+i+'</div><div class="allcontent">'+t+'</div><span><a href="javascript://nop/" class="morelink">'+m.moreText+"</a></span>";e.html(d),e.find(".allcontent").hide(),u(".shortcontent p:last",e).css("margin-bottom",0)}}))}}(jQuery),window.onload=function(){"undefined"!=typeof rtmedia_masonry_layout&&"true"==rtmedia_masonry_layout&&0==jQuery(".rtmedia-container .rtmedia-list.rtm-no-masonry").length&&rtm_masonry_reload(rtm_masonry_container),rtm_search_media_text_validation(),check_condition("search")&&jQuery("#media_search_remove").show()},jQuery(document).ready(function(){rtm_upload_terms_activity(),jQuery("body").hasClass("has-sidebar")&&0===jQuery("#secondary").length&&(jQuery(".rtmedia-single-container").length||jQuery(".rtmedia-container").length)&&jQuery("body").removeClass("has-sidebar")});
|
app/helper/BPMediaBranding.php
CHANGED
@@ -1,18 +1,23 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
/**
|
4 |
-
*
|
5 |
*
|
6 |
* @package BuddyPressMedia
|
7 |
* @subpackage Admin
|
8 |
-
*
|
9 |
-
* @author Gagandeep Singh <gagandeep.singh@rtcamp.com>
|
10 |
-
* @author Joshua Abenazer <joshua.abenazer@rtcamp.com>
|
11 |
*/
|
|
|
12 |
if ( ! class_exists( 'BPMediaBranding' ) ) {
|
13 |
|
|
|
|
|
|
|
|
|
|
|
14 |
class BPMediaBranding {
|
15 |
|
|
|
|
|
|
|
16 |
public function __construct() {
|
17 |
|
18 |
}
|
1 |
<?php
|
|
|
2 |
/**
|
3 |
+
* BuddyPress Media Branding Class file.
|
4 |
*
|
5 |
* @package BuddyPressMedia
|
6 |
* @subpackage Admin
|
|
|
|
|
|
|
7 |
*/
|
8 |
+
|
9 |
if ( ! class_exists( 'BPMediaBranding' ) ) {
|
10 |
|
11 |
+
/**
|
12 |
+
* Class for BuddyPress Media Branding
|
13 |
+
*
|
14 |
+
* @author Gagandeep Singh <gagandeep.singh@rtcamp.com>, Joshua Abenazer <joshua.abenazer@rtcamp.com>
|
15 |
+
*/
|
16 |
class BPMediaBranding {
|
17 |
|
18 |
+
/**
|
19 |
+
* BPMediaBranding constructor.
|
20 |
+
*/
|
21 |
public function __construct() {
|
22 |
|
23 |
}
|
app/helper/RTMediaActivityModel.php
CHANGED
@@ -1,39 +1,79 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
-
*
|
4 |
* User: ritz <ritesh.patel@rtcamp.com>
|
5 |
* Date: 11/9/14
|
6 |
* Time: 2:32 PM
|
|
|
|
|
7 |
*/
|
8 |
|
9 |
if ( ! class_exists( 'RTDBModel' ) ) {
|
10 |
return;
|
11 |
}
|
12 |
|
|
|
|
|
|
|
13 |
class RTMediaActivityModel extends RTDBModel {
|
14 |
|
15 |
-
|
|
|
|
|
|
|
16 |
parent::__construct( 'rtm_activity', false, 10, true );
|
17 |
}
|
18 |
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
$columns['blog_id'] = get_current_blog_id();
|
21 |
|
22 |
return parent::get( $columns, $offset, $per_page, $order_by );
|
23 |
}
|
24 |
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
$row['blog_id'] = get_current_blog_id();
|
27 |
|
28 |
return parent::insert( $row );
|
29 |
}
|
30 |
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
$where['blog_id'] = get_current_blog_id();
|
33 |
|
34 |
return parent::update( $data, $where );
|
35 |
}
|
36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
public function check( $activity_id = '' ) {
|
38 |
if ( '' === $activity_id ) {
|
39 |
return false;
|
@@ -58,10 +98,11 @@ class RTMediaActivityModel extends RTDBModel {
|
|
58 |
*
|
59 |
* @since 4.3
|
60 |
*
|
61 |
-
* @param array
|
62 |
-
* @param int
|
|
|
63 |
*/
|
64 |
-
public function profile_activity_update( $media_ids_of_activity = array(), $privacy, $parent_activity_id = false ) {
|
65 |
|
66 |
// Check if activity stream is active or not.
|
67 |
if ( ! function_exists( 'bp_activity_get' ) ) {
|
@@ -80,12 +121,12 @@ class RTMediaActivityModel extends RTDBModel {
|
|
80 |
}
|
81 |
}
|
82 |
|
83 |
-
if ( ! empty
|
84 |
// Get all the activities from item_id.
|
85 |
$parent_activity_id = intval( $parent_activity_id );
|
86 |
-
$activity_parents
|
87 |
array(
|
88 |
-
'filter'
|
89 |
'display_comments' => true,
|
90 |
)
|
91 |
);
|
@@ -99,6 +140,13 @@ class RTMediaActivityModel extends RTDBModel {
|
|
99 |
}
|
100 |
}
|
101 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
public function set_privacy( $activity_id, $user_id, $privacy ) {
|
103 |
if ( function_exists( 'bp_activity_update_meta' ) ) {
|
104 |
bp_activity_update_meta( $activity_id, 'rtmedia_privacy', $privacy );
|
@@ -106,12 +154,27 @@ class RTMediaActivityModel extends RTDBModel {
|
|
106 |
|
107 |
/* check is value exits or not */
|
108 |
if ( ! $this->check( $activity_id ) ) {
|
109 |
-
$this->insert(
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
} else {
|
111 |
-
$this->update(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
}
|
113 |
|
114 |
-
// update privacy of corresponding media
|
115 |
$media_model = new RTMediaModel();
|
116 |
$activity_media = $media_model->get( array( 'activity_id' => $activity_id ) );
|
117 |
if ( ! empty( $activity_media ) && is_array( $activity_media ) ) {
|
@@ -122,23 +185,30 @@ class RTMediaActivityModel extends RTDBModel {
|
|
122 |
$where = array( 'id' => $single_media->id );
|
123 |
$columns = array( 'privacy' => $privacy );
|
124 |
|
125 |
-
// update media privacy
|
126 |
$media_model->update( $columns, $where );
|
127 |
}
|
128 |
}
|
129 |
}
|
130 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
131 |
public function set_privacy_for_rtmedia_activity( $parent_activity_id, $activity_id, $user_id ) {
|
132 |
-
|
133 |
$privacy = get_rtmedia_default_privacy();
|
134 |
|
135 |
-
|
136 |
$activity_privacy = $this->get( array( 'activity_id' => $parent_activity_id ) );
|
137 |
if ( isset( $activity_privacy[0] ) && isset( $activity_privacy[0]->privacy ) ) {
|
138 |
$privacy = $activity_privacy[0]->privacy;
|
139 |
}
|
140 |
|
141 |
-
|
142 |
$this->set_privacy( $activity_id, $user_id, $privacy );
|
143 |
}
|
144 |
}
|
1 |
<?php
|
2 |
/**
|
3 |
+
* Class RTMediaActivityModel file.
|
4 |
* User: ritz <ritesh.patel@rtcamp.com>
|
5 |
* Date: 11/9/14
|
6 |
* Time: 2:32 PM
|
7 |
+
*
|
8 |
+
* @package rtMedia
|
9 |
*/
|
10 |
|
11 |
if ( ! class_exists( 'RTDBModel' ) ) {
|
12 |
return;
|
13 |
}
|
14 |
|
15 |
+
/**
|
16 |
+
* Class to monitor media activity.
|
17 |
+
*/
|
18 |
class RTMediaActivityModel extends RTDBModel {
|
19 |
|
20 |
+
/**
|
21 |
+
* RTMediaActivityModel constructor.
|
22 |
+
*/
|
23 |
+
public function __construct() {
|
24 |
parent::__construct( 'rtm_activity', false, 10, true );
|
25 |
}
|
26 |
|
27 |
+
/**
|
28 |
+
* Get columns.
|
29 |
+
*
|
30 |
+
* @param array $columns Columns.
|
31 |
+
* @param bool|int $offset Offset.
|
32 |
+
* @param bool|int $per_page Per page.
|
33 |
+
* @param string $order_by Order by.
|
34 |
+
*
|
35 |
+
* @return array
|
36 |
+
*/
|
37 |
+
public function get( $columns, $offset = false, $per_page = false, $order_by = 'activity_id DESC' ) {
|
38 |
$columns['blog_id'] = get_current_blog_id();
|
39 |
|
40 |
return parent::get( $columns, $offset, $per_page, $order_by );
|
41 |
}
|
42 |
|
43 |
+
/**
|
44 |
+
* Insert row.
|
45 |
+
*
|
46 |
+
* @param array $row Row data.
|
47 |
+
*
|
48 |
+
* @return int
|
49 |
+
*/
|
50 |
+
public function insert( $row ) {
|
51 |
$row['blog_id'] = get_current_blog_id();
|
52 |
|
53 |
return parent::insert( $row );
|
54 |
}
|
55 |
|
56 |
+
/**
|
57 |
+
* Update data.
|
58 |
+
*
|
59 |
+
* @param array $data Data.
|
60 |
+
* @param array $where Where condition.
|
61 |
+
*
|
62 |
+
* @return mixed
|
63 |
+
*/
|
64 |
+
public function update( $data, $where ) {
|
65 |
$where['blog_id'] = get_current_blog_id();
|
66 |
|
67 |
return parent::update( $data, $where );
|
68 |
}
|
69 |
|
70 |
+
/**
|
71 |
+
* Check if activity exists.
|
72 |
+
*
|
73 |
+
* @param string $activity_id activity id.
|
74 |
+
*
|
75 |
+
* @return bool
|
76 |
+
*/
|
77 |
public function check( $activity_id = '' ) {
|
78 |
if ( '' === $activity_id ) {
|
79 |
return false;
|
98 |
*
|
99 |
* @since 4.3
|
100 |
*
|
101 |
+
* @param array $media_ids_of_activity List of all the Media Id that is being updated.
|
102 |
+
* @param int $privacy Privacy to set.
|
103 |
+
* @param int|bool $parent_activity_id Parent activity id.
|
104 |
*/
|
105 |
+
public function profile_activity_update( $media_ids_of_activity = array(), $privacy = 0, $parent_activity_id = false ) {
|
106 |
|
107 |
// Check if activity stream is active or not.
|
108 |
if ( ! function_exists( 'bp_activity_get' ) ) {
|
121 |
}
|
122 |
}
|
123 |
|
124 |
+
if ( ! empty( $parent_activity_id ) ) {
|
125 |
// Get all the activities from item_id.
|
126 |
$parent_activity_id = intval( $parent_activity_id );
|
127 |
+
$activity_parents = bp_activity_get(
|
128 |
array(
|
129 |
+
'filter' => array( 'primary_id' => $parent_activity_id ),
|
130 |
'display_comments' => true,
|
131 |
)
|
132 |
);
|
140 |
}
|
141 |
}
|
142 |
|
143 |
+
/**
|
144 |
+
* Set privacy for activity.
|
145 |
+
*
|
146 |
+
* @param int $activity_id activity id.
|
147 |
+
* @param int $user_id user id.
|
148 |
+
* @param string $privacy privacy.
|
149 |
+
*/
|
150 |
public function set_privacy( $activity_id, $user_id, $privacy ) {
|
151 |
if ( function_exists( 'bp_activity_update_meta' ) ) {
|
152 |
bp_activity_update_meta( $activity_id, 'rtmedia_privacy', $privacy );
|
154 |
|
155 |
/* check is value exits or not */
|
156 |
if ( ! $this->check( $activity_id ) ) {
|
157 |
+
$this->insert(
|
158 |
+
array(
|
159 |
+
'activity_id' => $activity_id,
|
160 |
+
'user_id' => $user_id,
|
161 |
+
'privacy' => $privacy,
|
162 |
+
)
|
163 |
+
);
|
164 |
} else {
|
165 |
+
$this->update(
|
166 |
+
array(
|
167 |
+
'activity_id' => $activity_id,
|
168 |
+
'user_id' => $user_id,
|
169 |
+
'privacy' => $privacy,
|
170 |
+
),
|
171 |
+
array(
|
172 |
+
'activity_id' => $activity_id,
|
173 |
+
)
|
174 |
+
);
|
175 |
}
|
176 |
|
177 |
+
// update privacy of corresponding media.
|
178 |
$media_model = new RTMediaModel();
|
179 |
$activity_media = $media_model->get( array( 'activity_id' => $activity_id ) );
|
180 |
if ( ! empty( $activity_media ) && is_array( $activity_media ) ) {
|
185 |
$where = array( 'id' => $single_media->id );
|
186 |
$columns = array( 'privacy' => $privacy );
|
187 |
|
188 |
+
// update media privacy.
|
189 |
$media_model->update( $columns, $where );
|
190 |
}
|
191 |
}
|
192 |
}
|
193 |
|
194 |
+
/**
|
195 |
+
* Set privacy for rtMedia activity.
|
196 |
+
*
|
197 |
+
* @param int $parent_activity_id parent activity id.
|
198 |
+
* @param int $activity_id activity id.
|
199 |
+
* @param int $user_id user id.
|
200 |
+
*/
|
201 |
public function set_privacy_for_rtmedia_activity( $parent_activity_id, $activity_id, $user_id ) {
|
202 |
+
// get default privacy.
|
203 |
$privacy = get_rtmedia_default_privacy();
|
204 |
|
205 |
+
// get parent privacy.
|
206 |
$activity_privacy = $this->get( array( 'activity_id' => $parent_activity_id ) );
|
207 |
if ( isset( $activity_privacy[0] ) && isset( $activity_privacy[0]->privacy ) ) {
|
208 |
$privacy = $activity_privacy[0]->privacy;
|
209 |
}
|
210 |
|
211 |
+
// add the privacy.
|
212 |
$this->set_privacy( $activity_id, $user_id, $privacy );
|
213 |
}
|
214 |
}
|
app/helper/RTMediaAddon.php
CHANGED
@@ -1,28 +1,40 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
-
*
|
|
|
4 |
*
|
5 |
* @package rtMedia
|
6 |
* @subpackage Admin
|
7 |
*
|
8 |
-
* @author Gagandeep Singh <gagandeep.singh@rtcamp.com>
|
9 |
-
* @author Joshua Abenazer <joshua.abenazer@rtcamp.com>
|
10 |
*/
|
|
|
11 |
if ( ! class_exists( 'RTMediaAddon' ) ) {
|
12 |
|
|
|
|
|
|
|
13 |
class RTMediaAddon {
|
14 |
|
|
|
|
|
|
|
|
|
|
|
15 |
public $enquiry_link = 'https://rtmedia.io/contact/?utm_source=dashboard&utm_medium=plugin&utm_campaign=buddypress-media';
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
17 |
public static $page;
|
18 |
|
19 |
/**
|
20 |
-
* Show
|
21 |
*
|
22 |
* @access public
|
23 |
*
|
24 |
-
* @param void
|
25 |
-
*
|
26 |
* @return string
|
27 |
*/
|
28 |
public function coming_soon_div() {
|
@@ -30,11 +42,11 @@ if ( ! class_exists( 'RTMediaAddon' ) ) {
|
|
30 |
}
|
31 |
|
32 |
/**
|
33 |
-
* Render
|
34 |
*
|
35 |
* @access public
|
36 |
*
|
37 |
-
* @param
|
38 |
*
|
39 |
* @return void
|
40 |
*/
|
@@ -68,8 +80,6 @@ if ( ! class_exists( 'RTMediaAddon' ) ) {
|
|
68 |
*
|
69 |
* @access public
|
70 |
*
|
71 |
-
* @param void
|
72 |
-
*
|
73 |
* @return void
|
74 |
*/
|
75 |
public function get_addons() {
|
@@ -94,7 +104,7 @@ if ( ! class_exists( 'RTMediaAddon' ) ) {
|
|
94 |
*
|
95 |
* @access public
|
96 |
*
|
97 |
-
* @param array $args
|
98 |
*
|
99 |
* @return void
|
100 |
*/
|
@@ -509,11 +519,11 @@ if ( ! class_exists( 'RTMediaAddon' ) ) {
|
|
509 |
}
|
510 |
|
511 |
/**
|
512 |
-
*
|
513 |
*
|
514 |
* @access public
|
515 |
*
|
516 |
-
* @param array $args
|
517 |
*
|
518 |
* @return void
|
519 |
*/
|
@@ -524,9 +534,9 @@ if ( ! class_exists( 'RTMediaAddon' ) ) {
|
|
524 |
/**
|
525 |
* Define addon.
|
526 |
*
|
527 |
-
* @global
|
528 |
*
|
529 |
-
* @param array $args
|
530 |
*
|
531 |
* @return void
|
532 |
*/
|
@@ -546,46 +556,51 @@ if ( ! class_exists( 'RTMediaAddon' ) ) {
|
|
546 |
'purchased' => false,
|
547 |
);
|
548 |
$args = wp_parse_args( $args, $defaults );
|
549 |
-
extract( $args );
|
550 |
|
551 |
-
|
552 |
-
|
553 |
-
if ( $purchased ) {
|
554 |
$purchase_link = '<span class="rtm-addon-purchased button-primary disabled alignright product_type_simple">' . esc_html__( 'Purchased', 'buddypress-media' ) . '</span>';
|
555 |
} else {
|
556 |
-
$purchase_link = '<a class="button-primary alignright product_type_simple" href="' . esc_url( $buy_now ) . '" target="_blank">' . esc_html__( 'Buy Now', 'buddypress-media' ) . '</a>';
|
557 |
}
|
558 |
|
559 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
560 |
?>
|
561 |
<div class="plugin-card clearfix rtm-plugin-card">
|
562 |
|
563 |
<div class="plugin-card-top">
|
564 |
-
<a class="rtm-logo" href="<?php echo esc_url( $product_link ); ?>"
|
565 |
-
|
566 |
-
<img width="240" height="184" title="<?php echo esc_attr( $title ); ?>"
|
567 |
-
alt="<?php echo esc_attr( $title ); ?>" src="<?php echo esc_url( $img_src ); ?>"/>
|
568 |
</a>
|
569 |
|
570 |
<div class="name column-name">
|
571 |
-
<h4><a href="<?php echo esc_url( $product_link ); ?>" title="<?php echo esc_attr( $title ); ?>"
|
572 |
-
target="_blank"><?php echo esc_html( $title ); ?></a></h4>
|
573 |
</div>
|
574 |
|
575 |
<div class="desc column-description">
|
576 |
-
<?php echo wp_kses_post( $desc ); ?>
|
577 |
</div>
|
578 |
</div>
|
579 |
|
580 |
<div class="plugin-card-bottom">
|
581 |
<span class="price alignleft">
|
582 |
-
<span class="amount"><?php echo esc_html( $price ); ?></span>
|
583 |
</span>
|
584 |
<?php
|
585 |
-
echo $purchase_link
|
586 |
|
587 |
-
if ( '' !== $demo_link ) {
|
588 |
-
echo '<a class="alignright rtm-live-demo button" href="' . esc_url( $demo_link ) . '" title="' . esc_attr( $title ) . '" target="_blank">' . esc_html__( 'Live Demo', 'buddypress-media' ) . '</a>';
|
589 |
}
|
590 |
?>
|
591 |
</div>
|
1 |
<?php
|
2 |
/**
|
3 |
+
* Contains class RTMediaAddon
|
4 |
+
* Shows Addons details
|
5 |
*
|
6 |
* @package rtMedia
|
7 |
* @subpackage Admin
|
8 |
*
|
9 |
+
* @author Gagandeep Singh <gagandeep.singh@rtcamp.com>, Joshua Abenazer <joshua.abenazer@rtcamp.com>
|
|
|
10 |
*/
|
11 |
+
|
12 |
if ( ! class_exists( 'RTMediaAddon' ) ) {
|
13 |
|
14 |
+
/**
|
15 |
+
* Class to display rtMedia addons.
|
16 |
+
*/
|
17 |
class RTMediaAddon {
|
18 |
|
19 |
+
/**
|
20 |
+
* Enquiry link.
|
21 |
+
*
|
22 |
+
* @var string
|
23 |
+
*/
|
24 |
public $enquiry_link = 'https://rtmedia.io/contact/?utm_source=dashboard&utm_medium=plugin&utm_campaign=buddypress-media';
|
25 |
+
|
26 |
+
/**
|
27 |
+
* Current page.
|
28 |
+
*
|
29 |
+
* @var string $page
|
30 |
+
*/
|
31 |
public static $page;
|
32 |
|
33 |
/**
|
34 |
+
* Show coming soon div.
|
35 |
*
|
36 |
* @access public
|
37 |
*
|
|
|
|
|
38 |
* @return string
|
39 |
*/
|
40 |
public function coming_soon_div() {
|
42 |
}
|
43 |
|
44 |
/**
|
45 |
+
* Render add-ons.
|
46 |
*
|
47 |
* @access public
|
48 |
*
|
49 |
+
* @param string $page Page name.
|
50 |
*
|
51 |
* @return void
|
52 |
*/
|
80 |
*
|
81 |
* @access public
|
82 |
*
|
|
|
|
|
83 |
* @return void
|
84 |
*/
|
85 |
public function get_addons() {
|
104 |
*
|
105 |
* @access public
|
106 |
*
|
107 |
+
* @param array|string $args Arguments.
|
108 |
*
|
109 |
* @return void
|
110 |
*/
|
519 |
}
|
520 |
|
521 |
/**
|
522 |
+
* Show themes content.
|
523 |
*
|
524 |
* @access public
|
525 |
*
|
526 |
+
* @param array|string $args Arguments.
|
527 |
*
|
528 |
* @return void
|
529 |
*/
|
534 |
/**
|
535 |
* Define addon.
|
536 |
*
|
537 |
+
* @global mixed $rtmedia
|
538 |
*
|
539 |
+
* @param array $args Arguments.
|
540 |
*
|
541 |
* @return void
|
542 |
*/
|
556 |
'purchased' => false,
|
557 |
);
|
558 |
$args = wp_parse_args( $args, $defaults );
|
|
|
559 |
|
560 |
+
if ( $args['purchased'] ) {
|
|
|
|
|
561 |
$purchase_link = '<span class="rtm-addon-purchased button-primary disabled alignright product_type_simple">' . esc_html__( 'Purchased', 'buddypress-media' ) . '</span>';
|
562 |
} else {
|
563 |
+
$purchase_link = '<a class="button-primary alignright product_type_simple" href="' . esc_url( $args['buy_now'] ) . '" target="_blank">' . esc_html__( 'Buy Now', 'buddypress-media' ) . '</a>';
|
564 |
}
|
565 |
|
566 |
+
$allowed_html = array(
|
567 |
+
'a' => array(
|
568 |
+
'href' => array(),
|
569 |
+
'target' => array(),
|
570 |
+
'class' => array(),
|
571 |
+
),
|
572 |
+
'span' => array(
|
573 |
+
'class' => array(),
|
574 |
+
),
|
575 |
+
);
|
576 |
+
|
577 |
+
$coming_soon_div = ( ! empty( $args['coming_soon'] ) ) ? $this->coming_soon_div() : '';
|
578 |
?>
|
579 |
<div class="plugin-card clearfix rtm-plugin-card">
|
580 |
|
581 |
<div class="plugin-card-top">
|
582 |
+
<a class="rtm-logo" href="<?php echo esc_url( $args['product_link'] ); ?>" title="<?php echo esc_attr( $args['title'] ); ?>" target="_blank">
|
583 |
+
<img width="240" height="184" title="<?php echo esc_attr( $args['title'] ); ?>" alt="<?php echo esc_attr( $args['title'] ); ?>" src="<?php echo esc_url( $args['img_src'] ); ?>"/>
|
|
|
|
|
584 |
</a>
|
585 |
|
586 |
<div class="name column-name">
|
587 |
+
<h4><a href="<?php echo esc_url( $args['product_link'] ); ?>" title="<?php echo esc_attr( $args['title'] ); ?>" target="_blank"><?php echo esc_html( $args['title'] ); ?></a></h4>
|
|
|
588 |
</div>
|
589 |
|
590 |
<div class="desc column-description">
|
591 |
+
<?php echo wp_kses_post( $args['desc'] ); ?>
|
592 |
</div>
|
593 |
</div>
|
594 |
|
595 |
<div class="plugin-card-bottom">
|
596 |
<span class="price alignleft">
|
597 |
+
<span class="amount"><?php echo esc_html( $args['price'] ); ?></span>
|
598 |
</span>
|
599 |
<?php
|
600 |
+
echo wp_kses( $purchase_link, $allowed_html );
|
601 |
|
602 |
+
if ( '' !== $args['demo_link'] ) {
|
603 |
+
echo '<a class="alignright rtm-live-demo button" href="' . esc_url( $args['demo_link'] ) . '" title="' . esc_attr( $args['title'] ) . '" target="_blank">' . esc_html__( 'Live Demo', 'buddypress-media' ) . '</a>';
|
604 |
}
|
605 |
?>
|
606 |
</div>
|
app/helper/RTMediaAdminWidget.php
CHANGED
@@ -1,36 +1,45 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
-
*
|
4 |
*
|
5 |
-
* @
|
6 |
-
*
|
|
|
7 |
*/
|
|
|
8 |
if ( ! class_exists( 'RTMediaAdminWidget' ) ) {
|
9 |
|
|
|
|
|
|
|
10 |
class RTMediaAdminWidget {
|
11 |
|
12 |
/**
|
13 |
* Constructs the RTMediaAdminWidget.
|
14 |
*
|
15 |
-
* @global
|
16 |
*
|
17 |
-
* @param
|
18 |
-
* @param
|
19 |
-
* @param
|
20 |
*/
|
21 |
public function __construct( $id = null, $title = null, $content = null ) {
|
|
|
22 |
if ( $id ) {
|
23 |
?>
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
31 |
} else {
|
32 |
-
trigger_error( esc_html__( 'Argument missing. id is required.', 'buddypress-media' ) );
|
33 |
}
|
|
|
34 |
}
|
35 |
}
|
36 |
|
1 |
<?php
|
2 |
/**
|
3 |
+
* File includes RTMediaWidget class
|
4 |
*
|
5 |
+
* @package rtMedia
|
6 |
+
*
|
7 |
+
* @author Gagandeep Singh <gagandeep.singh@rtcamp.com>, Joshua Abenazer <joshua.abenazer@rtcamp.com>
|
8 |
*/
|
9 |
+
|
10 |
if ( ! class_exists( 'RTMediaAdminWidget' ) ) {
|
11 |
|
12 |
+
/**
|
13 |
+
* Class to show rtMedia widget.
|
14 |
+
*/
|
15 |
class RTMediaAdminWidget {
|
16 |
|
17 |
/**
|
18 |
* Constructs the RTMediaAdminWidget.
|
19 |
*
|
20 |
+
* @global mixed $rtmedia
|
21 |
*
|
22 |
+
* @param int $id Id.
|
23 |
+
* @param string $title Title.
|
24 |
+
* @param string $content Content.
|
25 |
*/
|
26 |
public function __construct( $id = null, $title = null, $content = null ) {
|
27 |
+
add_action( 'safe_style_css', 'RTMedia::allow_display_in_style' );
|
28 |
if ( $id ) {
|
29 |
?>
|
30 |
+
<div class="postbox" id="<?php echo esc_attr( $id ); ?>">
|
31 |
+
<?php
|
32 |
+
if ( $title ) {
|
33 |
+
?>
|
34 |
+
<h3 class="hndle"><span><?php echo esc_html( $title ); ?></span></h3>
|
35 |
+
<?php } ?>
|
36 |
+
<div class="inside"><?php echo wp_kses( $content, RTMedia::expanded_allowed_tags() ); ?></div>
|
37 |
+
</div>
|
38 |
+
<?php
|
39 |
} else {
|
40 |
+
trigger_error( esc_html__( 'Argument missing. id is required.', 'buddypress-media' ) ); // phpcs:ignore
|
41 |
}
|
42 |
+
remove_action( 'safe_style_css', 'RTMedia::allow_display_in_style' );
|
43 |
}
|
44 |
}
|
45 |
|
app/helper/RTMediaCommentModel.php
CHANGED
@@ -1,12 +1,12 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
|
4 |
-
*
|
5 |
-
*
|
6 |
*/
|
7 |
|
8 |
/**
|
9 |
-
*
|
10 |
*
|
11 |
* @author Udit Desai <udit.desai@rtcamp.com>
|
12 |
*/
|
@@ -16,22 +16,23 @@ class RTMediaCommentModel {
|
|
16 |
* Constructor
|
17 |
*
|
18 |
* @access public
|
19 |
-
* @return void
|
20 |
*/
|
21 |
public function __construct() {
|
22 |
-
//initialization
|
23 |
}
|
24 |
|
25 |
/**
|
26 |
-
* Insert
|
27 |
*
|
28 |
* @access public
|
29 |
*
|
30 |
-
* @param array $
|
|
|
|
|
31 |
*/
|
32 |
-
public function insert( $
|
33 |
|
34 |
-
return wp_insert_comment( $
|
35 |
}
|
36 |
|
37 |
/**
|
@@ -39,11 +40,13 @@ class RTMediaCommentModel {
|
|
39 |
*
|
40 |
* @access public
|
41 |
*
|
42 |
-
* @param array $
|
|
|
|
|
43 |
*/
|
44 |
-
public function update( $
|
45 |
|
46 |
-
return wp_update_comment( $
|
47 |
}
|
48 |
|
49 |
/**
|
@@ -51,7 +54,9 @@ class RTMediaCommentModel {
|
|
51 |
*
|
52 |
* @access public
|
53 |
*
|
54 |
-
* @param string $where
|
|
|
|
|
55 |
*/
|
56 |
public function get( $where ) {
|
57 |
|
@@ -63,7 +68,9 @@ class RTMediaCommentModel {
|
|
63 |
*
|
64 |
* @access public
|
65 |
*
|
66 |
-
* @param int $id
|
|
|
|
|
67 |
*/
|
68 |
public function get_by_id( $id ) {
|
69 |
|
@@ -75,7 +82,9 @@ class RTMediaCommentModel {
|
|
75 |
*
|
76 |
* @access public
|
77 |
*
|
78 |
-
* @param int $id
|
|
|
|
|
79 |
*/
|
80 |
public function delete( $id ) {
|
81 |
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* Performs actions on comments
|
4 |
+
*
|
5 |
+
* @package rtMedia
|
6 |
*/
|
7 |
|
8 |
/**
|
9 |
+
* Class to perform actions on comments.
|
10 |
*
|
11 |
* @author Udit Desai <udit.desai@rtcamp.com>
|
12 |
*/
|
16 |
* Constructor
|
17 |
*
|
18 |
* @access public
|
|
|
19 |
*/
|
20 |
public function __construct() {
|
21 |
+
// initialization.
|
22 |
}
|
23 |
|
24 |
/**
|
25 |
+
* Insert comment
|
26 |
*
|
27 |
* @access public
|
28 |
*
|
29 |
+
* @param array $args Contains information on the comment.
|
30 |
+
*
|
31 |
+
* @return false|int
|
32 |
*/
|
33 |
+
public function insert( $args ) {
|
34 |
|
35 |
+
return wp_insert_comment( $args );
|
36 |
}
|
37 |
|
38 |
/**
|
40 |
*
|
41 |
* @access public
|
42 |
*
|
43 |
+
* @param array $args Contains information on the comment.
|
44 |
+
*
|
45 |
+
* @return int
|
46 |
*/
|
47 |
+
public function update( $args ) {
|
48 |
|
49 |
+
return wp_update_comment( $args, ARRAY_A );
|
50 |
}
|
51 |
|
52 |
/**
|
54 |
*
|
55 |
* @access public
|
56 |
*
|
57 |
+
* @param string $where where clause.
|
58 |
+
*
|
59 |
+
* @return array|int
|
60 |
*/
|
61 |
public function get( $where ) {
|
62 |
|
68 |
*
|
69 |
* @access public
|
70 |
*
|
71 |
+
* @param int $id Comment id.
|
72 |
+
*
|
73 |
+
* @return array|WP_Comment|null
|
74 |
*/
|
75 |
public function get_by_id( $id ) {
|
76 |
|
82 |
*
|
83 |
* @access public
|
84 |
*
|
85 |
+
* @param int $id comment id.
|
86 |
+
*
|
87 |
+
* @return bool
|
88 |
*/
|
89 |
public function delete( $id ) {
|
90 |
|
app/helper/RTMediaCommentNotification.php
CHANGED
@@ -1,16 +1,35 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
/**
|
4 |
-
*
|
5 |
*
|
6 |
* @author Jignesh Nakrani <jignesh.nakrani@rtcamp.com>
|
7 |
*/
|
8 |
class RTMediaCommentNotification extends RTMediaNotification {
|
9 |
|
|
|
|
|
|
|
|
|
|
|
10 |
public $component_id = 'rt_comment_notifier';
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
public $component_action = 'new_comment_to_media';
|
12 |
|
13 |
-
|
|
|
|
|
|
|
14 |
|
15 |
if ( class_exists( 'BuddyPress' ) ) {
|
16 |
$args = array(
|
@@ -29,7 +48,7 @@ class RTMediaCommentNotification extends RTMediaNotification {
|
|
29 |
/**
|
30 |
* Hooked to bp_init.
|
31 |
*/
|
32 |
-
function init() {
|
33 |
if ( bp_is_active( 'notifications' ) ) {
|
34 |
add_filter( 'rtmedia_comment_notifications', array( $this, 'format_comment_notifications' ) );
|
35 |
add_action( 'rtmedia_after_add_comment', array( $this, 'add_comment_notify' ) );
|
@@ -39,13 +58,13 @@ class RTMediaCommentNotification extends RTMediaNotification {
|
|
39 |
}
|
40 |
|
41 |
/**
|
42 |
-
*
|
43 |
*
|
44 |
-
* @param array $params
|
45 |
*
|
46 |
-
* @return array
|
47 |
*/
|
48 |
-
function format_comment_notifications( $params ) {
|
49 |
$action = $params['action'];
|
50 |
$post_id = intval( $params['post_id'] );
|
51 |
|
@@ -65,7 +84,8 @@ class RTMediaCommentNotification extends RTMediaNotification {
|
|
65 |
}
|
66 |
$link = esc_url( $media_url );
|
67 |
|
68 |
-
$return = apply_filters(
|
|
|
69 |
array(
|
70 |
'link' => $link,
|
71 |
'text' => $text,
|
@@ -82,12 +102,13 @@ class RTMediaCommentNotification extends RTMediaNotification {
|
|
82 |
}
|
83 |
|
84 |
/**
|
85 |
-
*
|
86 |
-
*
|
|
|
87 |
*
|
88 |
-
* @param array $args contains comment descriptions
|
89 |
*/
|
90 |
-
function add_comment_notify( $args ) {
|
91 |
|
92 |
$post_author_id = get_post( $args['comment_post_ID'] )->post_author;
|
93 |
$post_id = $args['comment_post_ID'];
|
@@ -105,10 +126,11 @@ class RTMediaCommentNotification extends RTMediaNotification {
|
|
105 |
}
|
106 |
|
107 |
/**
|
108 |
-
*
|
109 |
-
*
|
|
|
110 |
*/
|
111 |
-
function remove_comment_notification( $comment_id ) {
|
112 |
|
113 |
$comment_notification_id = (int) get_comment_meta( $comment_id, 'comment_notification_id', true );
|
114 |
|
@@ -121,13 +143,13 @@ class RTMediaCommentNotification extends RTMediaNotification {
|
|
121 |
}
|
122 |
|
123 |
/**
|
124 |
-
*
|
125 |
*
|
126 |
-
* @param
|
127 |
-
* @param
|
128 |
-
* @param
|
129 |
-
* @param
|
130 |
-
* @param String $format string or array
|
131 |
*
|
132 |
* @return String/Array formatted notification
|
133 |
*/
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* Media comment notification class.
|
4 |
+
*
|
5 |
+
* @package rtMedia
|
6 |
+
*/
|
7 |
|
8 |
/**
|
9 |
+
* Class to handle Media comment notifications
|
10 |
*
|
11 |
* @author Jignesh Nakrani <jignesh.nakrani@rtcamp.com>
|
12 |
*/
|
13 |
class RTMediaCommentNotification extends RTMediaNotification {
|
14 |
|
15 |
+
/**
|
16 |
+
* Component id.
|
17 |
+
*
|
18 |
+
* @var string
|
19 |
+
*/
|
20 |
public $component_id = 'rt_comment_notifier';
|
21 |
+
|
22 |
+
/**
|
23 |
+
* Component action.
|
24 |
+
*
|
25 |
+
* @var string
|
26 |
+
*/
|
27 |
public $component_action = 'new_comment_to_media';
|
28 |
|
29 |
+
/**
|
30 |
+
* RTMediaCommentNotification constructor.
|
31 |
+
*/
|
32 |
+
public function __construct() {
|
33 |
|
34 |
if ( class_exists( 'BuddyPress' ) ) {
|
35 |
$args = array(
|
48 |
/**
|
49 |
* Hooked to bp_init.
|
50 |
*/
|
51 |
+
public function init() {
|
52 |
if ( bp_is_active( 'notifications' ) ) {
|
53 |
add_filter( 'rtmedia_comment_notifications', array( $this, 'format_comment_notifications' ) );
|
54 |
add_action( 'rtmedia_after_add_comment', array( $this, 'add_comment_notify' ) );
|
58 |
}
|
59 |
|
60 |
/**
|
61 |
+
* Format the new notification in String or array
|
62 |
*
|
63 |
+
* @param array $params parameters.
|
64 |
*
|
65 |
+
* @return array|string As per $format
|
66 |
*/
|
67 |
+
public function format_comment_notifications( $params ) {
|
68 |
$action = $params['action'];
|
69 |
$post_id = intval( $params['post_id'] );
|
70 |
|
84 |
}
|
85 |
$link = esc_url( $media_url );
|
86 |
|
87 |
+
$return = apply_filters(
|
88 |
+
'rtmedia_before_comment_notification',
|
89 |
array(
|
90 |
'link' => $link,
|
91 |
'text' => $text,
|
102 |
}
|
103 |
|
104 |
/**
|
105 |
+
* Add a notification for a author of media on new comment on media
|
106 |
+
*
|
107 |
+
* @global mixed $bp
|
108 |
*
|
109 |
+
* @param array $args contains comment descriptions.
|
110 |
*/
|
111 |
+
public function add_comment_notify( $args ) {
|
112 |
|
113 |
$post_author_id = get_post( $args['comment_post_ID'] )->post_author;
|
114 |
$post_id = $args['comment_post_ID'];
|
126 |
}
|
127 |
|
128 |
/**
|
129 |
+
* Delete notification of a comment particular comment
|
130 |
+
*
|
131 |
+
* @param int $comment_id Comment id.
|
132 |
*/
|
133 |
+
public function remove_comment_notification( $comment_id ) {
|
134 |
|
135 |
$comment_notification_id = (int) get_comment_meta( $comment_id, 'comment_notification_id', true );
|
136 |
|
143 |
}
|
144 |
|
145 |
/**
|
146 |
+
* This is callback function for rt_like_notifier component dont call this callback method manually
|
147 |
*
|
148 |
+
* @param int $action action of component for notification.
|
149 |
+
* @param int $post_id ID of a post to notification.
|
150 |
+
* @param int $initiator_id secondary_item_id used in 'bp_notifications_add_notification'.
|
151 |
+
* @param int $total_items number of notification for same component.
|
152 |
+
* @param String $format string or array.
|
153 |
*
|
154 |
* @return String/Array formatted notification
|
155 |
*/
|
app/helper/RTMediaFeed.php
CHANGED
@@ -1,21 +1,31 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
/**
|
4 |
-
*
|
5 |
*
|
6 |
* @author Gagandeep Singh <gagandeep.singh@rtcamp.com>
|
7 |
* @author Joshua Abenazer <joshua.abenazer@rtcamp.com>
|
8 |
*/
|
9 |
class RTMediaFeed {
|
10 |
|
|
|
|
|
|
|
|
|
|
|
11 |
public $feed_url = '';
|
12 |
|
13 |
/**
|
14 |
-
* Constructor
|
15 |
*
|
16 |
* @access public
|
17 |
*
|
18 |
-
* @param string $feed_url
|
19 |
*/
|
20 |
public function __construct( $feed_url = '' ) {
|
21 |
if ( $feed_url ) {
|
@@ -26,12 +36,9 @@ class RTMediaFeed {
|
|
26 |
/**
|
27 |
* Get BuddyPress Media Feed from rtmedia.io
|
28 |
*/
|
29 |
-
|
30 |
-
/**
|
31 |
-
*/
|
32 |
public function fetch_feed() {
|
33 |
-
// Get RSS Feed(s)
|
34 |
-
require_once
|
35 |
$maxitems = 0;
|
36 |
$rss_items = array();
|
37 |
// Get a SimplePie feed object from the specified feed source.
|
@@ -43,7 +50,8 @@ class RTMediaFeed {
|
|
43 |
$rss_items = $rss->get_items( 0, $maxitems );
|
44 |
}
|
45 |
?>
|
46 |
-
<ul
|
|
|
47 |
if ( 0 === $maxitems ) {
|
48 |
echo '<li>' . esc_html__( 'No items', 'buddypress-media' ) . '.</li>';
|
49 |
} else {
|
@@ -52,12 +60,14 @@ class RTMediaFeed {
|
|
52 |
?>
|
53 |
<li>
|
54 |
<a href='<?php echo esc_url( $item->get_permalink() ); ?>?utm_source=dashboard&utm_medium=plugin&utm_campaign=buddypress-media'
|
55 |
-
|
56 |
-
</li
|
|
|
57 |
}
|
58 |
}
|
59 |
?>
|
60 |
-
</ul
|
|
|
61 |
if ( DOING_AJAX ) {
|
62 |
wp_die();
|
63 |
}
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* Media feed.
|
4 |
+
*
|
5 |
+
* @package rtMedia
|
6 |
+
*/
|
7 |
|
8 |
/**
|
9 |
+
* Class for rtMedia feed operations.
|
10 |
*
|
11 |
* @author Gagandeep Singh <gagandeep.singh@rtcamp.com>
|
12 |
* @author Joshua Abenazer <joshua.abenazer@rtcamp.com>
|
13 |
*/
|
14 |
class RTMediaFeed {
|
15 |
|
16 |
+
/**
|
17 |
+
* Feed url.
|
18 |
+
*
|
19 |
+
* @var string
|
20 |
+
*/
|
21 |
public $feed_url = '';
|
22 |
|
23 |
/**
|
24 |
+
* RTMediaFeed Constructor
|
25 |
*
|
26 |
* @access public
|
27 |
*
|
28 |
+
* @param string $feed_url Feed url.
|
29 |
*/
|
30 |
public function __construct( $feed_url = '' ) {
|
31 |
if ( $feed_url ) {
|
36 |
/**
|
37 |
* Get BuddyPress Media Feed from rtmedia.io
|
38 |
*/
|
|
|
|
|
|
|
39 |
public function fetch_feed() {
|
40 |
+
// Get RSS Feed(s).
|
41 |
+
require_once ABSPATH . WPINC . '/feed.php';
|
42 |
$maxitems = 0;
|
43 |
$rss_items = array();
|
44 |
// Get a SimplePie feed object from the specified feed source.
|
50 |
$rss_items = $rss->get_items( 0, $maxitems );
|
51 |
}
|
52 |
?>
|
53 |
+
<ul>
|
54 |
+
<?php
|
55 |
if ( 0 === $maxitems ) {
|
56 |
echo '<li>' . esc_html__( 'No items', 'buddypress-media' ) . '.</li>';
|
57 |
} else {
|
60 |
?>
|
61 |
<li>
|
62 |
<a href='<?php echo esc_url( $item->get_permalink() ); ?>?utm_source=dashboard&utm_medium=plugin&utm_campaign=buddypress-media'
|
63 |
+
title='<?php echo esc_attr__( 'Posted ', 'buddypress-media' ) . esc_attr( $item->get_date( 'j F Y | g:i a' ) ); ?>'><?php echo esc_html( $item->get_title() ); ?></a>
|
64 |
+
</li>
|
65 |
+
<?php
|
66 |
}
|
67 |
}
|
68 |
?>
|
69 |
+
</ul>
|
70 |
+
<?php
|
71 |
if ( DOING_AJAX ) {
|
72 |
wp_die();
|
73 |
}
|
app/helper/RTMediaInteractionModel.php
CHANGED
@@ -1,22 +1,21 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
|
4 |
-
*
|
5 |
-
*
|
6 |
*/
|
7 |
|
8 |
/**
|
9 |
-
*
|
10 |
*
|
11 |
* @author ritz
|
12 |
*/
|
13 |
class RTMediaInteractionModel extends RTDBModel {
|
14 |
|
15 |
/**
|
16 |
-
* Constructor
|
17 |
*
|
18 |
* @access public
|
19 |
-
* @return void
|
20 |
*/
|
21 |
public function __construct() {
|
22 |
parent::__construct( 'rtm_media_interaction', false, 10, true );
|
@@ -27,9 +26,9 @@ class RTMediaInteractionModel extends RTDBModel {
|
|
27 |
*
|
28 |
* @access public
|
29 |
*
|
30 |
-
* @param int $user_id
|
31 |
-
* @param int $media_id
|
32 |
-
* @param
|
33 |
*
|
34 |
* @return bool
|
35 |
*/
|
@@ -54,17 +53,17 @@ class RTMediaInteractionModel extends RTDBModel {
|
|
54 |
}
|
55 |
|
56 |
/**
|
57 |
-
*
|
58 |
*
|
59 |
* @access public
|
60 |
*
|
61 |
-
* @param int $user_id
|
62 |
-
* @param int $media_id
|
63 |
-
* @param
|
64 |
*
|
65 |
-
* @return
|
66 |
*/
|
67 |
-
function get_row( $user_id = '', $media_id = '', $action = '' ) {
|
68 |
if ( '' === $user_id && '' === $media_id && '' === $action ) {
|
69 |
return false;
|
70 |
}
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* Manages rtMedia interactions
|
4 |
+
*
|
5 |
+
* @package rtMedia
|
6 |
*/
|
7 |
|
8 |
/**
|
9 |
+
* Class to manage rtMedia interactions.
|
10 |
*
|
11 |
* @author ritz
|
12 |
*/
|
13 |
class RTMediaInteractionModel extends RTDBModel {
|
14 |
|
15 |
/**
|
16 |
+
* RTMediaInteractionModel Constructor
|
17 |
*
|
18 |
* @access public
|
|
|
19 |
*/
|
20 |
public function __construct() {
|
21 |
parent::__construct( 'rtm_media_interaction', false, 10, true );
|
26 |
*
|
27 |
* @access public
|
28 |
*
|
29 |
+
* @param int|string $user_id user id.
|
30 |
+
* @param int|string $media_id media id.
|
31 |
+
* @param string $action action name.
|
32 |
*
|
33 |
* @return bool
|
34 |
*/
|
53 |
}
|
54 |
|
55 |
/**
|
56 |
+
* Get a array of media details.
|
57 |
*
|
58 |
* @access public
|
59 |
*
|
60 |
+
* @param int|string $user_id user id.
|
61 |
+
* @param int|string $media_id media id.
|
62 |
+
* @param string $action action name.
|
63 |
*
|
64 |
+
* @return array|bool $results
|
65 |
*/
|
66 |
+
public function get_row( $user_id = '', $media_id = '', $action = '' ) {
|
67 |
if ( '' === $user_id && '' === $media_id && '' === $action ) {
|
68 |
return false;
|
69 |
}
|
app/helper/RTMediaLicense.php
CHANGED
@@ -1,15 +1,30 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
/**
|
4 |
-
*
|
5 |
* User: ritz
|
6 |
* Date: 18/9/14
|
7 |
* Time: 5:05 PM
|
|
|
|
|
8 |
*/
|
9 |
-
class RTMediaLicense {
|
10 |
-
static $page;
|
11 |
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
self::$page = $page;
|
14 |
|
15 |
$tabs = apply_filters( 'rtmedia_license_tabs', array() );
|
@@ -38,7 +53,7 @@ class RTMediaLicense {
|
|
38 |
<?php
|
39 |
}
|
40 |
|
41 |
-
// For add-on which aren't updated with the latest code
|
42 |
if ( did_action( 'rtmedia_addon_license_details' ) ) {
|
43 |
$addon_installed = true;
|
44 |
?>
|
@@ -55,15 +70,21 @@ class RTMediaLicense {
|
|
55 |
}
|
56 |
}
|
57 |
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
$license_status_id = $args['status_id'];
|
66 |
-
$license_data
|
67 |
?>
|
68 |
<div class="large-4 medium-6 small-12 license-column">
|
69 |
|
@@ -73,7 +94,7 @@ class RTMediaLicense {
|
|
73 |
</h4>
|
74 |
|
75 |
<div class="license-inner">
|
76 |
-
<input id="<?php echo esc_attr( $license_key_id ) ?>" name="<?php echo esc_attr( $license_key_id ) ?>" type="text" class="regular-text" value="<?php echo esc_attr( $license ); ?>" />
|
77 |
<?php
|
78 |
$nonce_action = 'edd_' . $el_id . '_nonce';
|
79 |
$nonce_name = 'edd_' . $el_id . '_nonce';
|
@@ -91,39 +112,45 @@ class RTMediaLicense {
|
|
91 |
|
92 |
<input type="submit" class="button-secondary" name="<?php echo esc_attr( $btn_name ); ?>" value="<?php echo esc_attr( $btn_val ); ?>" />
|
93 |
|
94 |
-
<?php
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
</div><!-- End of .license-inner -->
|
105 |
</div><!-- End of .rtm-addon-license -->
|
106 |
</div><!-- End of .license-column -->
|
107 |
<?php
|
108 |
}
|
109 |
|
110 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
|
112 |
$addon_name = isset( $license->item_name ) ? esc_html( $license->item_name ) : esc_html( $addon_name );
|
113 |
-
$messages
|
114 |
|
115 |
if ( ! empty( $license ) && is_object( $license ) ) {
|
116 |
|
117 |
-
// activate_license 'invalid' on anything other than valid, so if there was an error capture it
|
118 |
if ( false === $license->success ) {
|
119 |
|
120 |
switch ( $license->error ) {
|
121 |
|
122 |
-
case 'expired'
|
123 |
-
|
124 |
-
$class = 'alert';
|
125 |
$messages[] = sprintf(
|
126 |
-
|
|
|
127 |
date_i18n( get_option( 'date_format' ), strtotime( $license->expires, current_time( 'timestamp' ) ) )
|
128 |
);
|
129 |
|
@@ -131,31 +158,34 @@ class RTMediaLicense {
|
|
131 |
|
132 |
break;
|
133 |
|
134 |
-
case 'revoked'
|
135 |
-
|
136 |
-
$class = 'alert';
|
137 |
$messages[] = __( 'Your license key has been disabled. Please contact support for more information.', 'buddypress-media' );
|
138 |
|
139 |
$license_status = 'license-' . $class . '-notice';
|
140 |
|
141 |
break;
|
142 |
|
143 |
-
case 'missing'
|
144 |
-
|
145 |
-
$class = 'alert';
|
146 |
$messages[] = sprintf(
|
147 |
-
|
|
|
|
|
|
|
|
|
|
|
148 |
);
|
149 |
|
150 |
$license_status = 'license-' . $class . '-notice';
|
151 |
|
152 |
break;
|
153 |
|
154 |
-
case 'invalid'
|
155 |
-
case 'site_inactive'
|
156 |
-
|
157 |
-
$class = 'alert';
|
158 |
$messages[] = sprintf(
|
|
|
159 |
__( 'Your %1$s is not active for this URL. Please <a href="%2$s" target="_blank">visit your account page</a> to manage your license key URLs.', 'buddypress-media' ),
|
160 |
$addon_name,
|
161 |
'https://rtmedia.io/my-account/'
|
@@ -165,9 +195,10 @@ class RTMediaLicense {
|
|
165 |
|
166 |
break;
|
167 |
|
168 |
-
case 'item_name_mismatch'
|
169 |
-
|
170 |
$class = 'alert';
|
|
|
|
|
171 |
$messages[] = sprintf( __( 'This appears to be an invalid license key for %s.', 'buddypress-media' ), $addon_name );
|
172 |
|
173 |
$license_status = 'license-' . $class . '-notice';
|
@@ -175,8 +206,9 @@ class RTMediaLicense {
|
|
175 |
break;
|
176 |
|
177 |
case 'no_activations_left':
|
178 |
-
|
179 |
$class = 'alert';
|
|
|
|
|
180 |
$messages[] = sprintf( __( 'Your license key has reached its activation limit. <a href="%s">View possible upgrades</a> now.', 'buddypress-media' ), 'https://rtmedia.io/my-account/' );
|
181 |
|
182 |
$license_status = 'license-' . $class . '-notice';
|
@@ -184,17 +216,17 @@ class RTMediaLicense {
|
|
184 |
break;
|
185 |
|
186 |
case 'license_not_activable':
|
187 |
-
|
188 |
$class = 'alert';
|
|
|
|
|
189 |
$messages[] = sprintf( __( 'Your license is not activable, please visit <a href="%s">your account page</a>.', 'buddypress-media' ), 'https://rtmedia.io/my-account/' );
|
190 |
|
191 |
$license_status = 'license-' . $class . '-notice';
|
192 |
|
193 |
break;
|
194 |
|
195 |
-
default
|
196 |
-
|
197 |
-
$class = 'alert';
|
198 |
$messages[] = __( 'To receive updates, please enter your valid license key.', 'buddypress-media' );
|
199 |
|
200 |
$license_status = 'license-' . $class . '-notice';
|
@@ -204,9 +236,8 @@ class RTMediaLicense {
|
|
204 |
|
205 |
switch ( $license->license ) {
|
206 |
|
207 |
-
case 'valid'
|
208 |
default:
|
209 |
-
|
210 |
$class = 'success';
|
211 |
|
212 |
$now = current_time( 'timestamp' );
|
@@ -223,6 +254,7 @@ class RTMediaLicense {
|
|
223 |
$class = 'warning';
|
224 |
|
225 |
$messages[] = sprintf(
|
|
|
226 |
__( 'Your license key expires soon! It expires on %1$s. Renew your license key.', 'buddypress-media' ),
|
227 |
date_i18n( get_option( 'date_format' ), strtotime( $license->expires, current_time( 'timestamp' ) ) )
|
228 |
);
|
@@ -234,6 +266,7 @@ class RTMediaLicense {
|
|
234 |
$class = 'info';
|
235 |
|
236 |
$messages[] = sprintf(
|
|
|
237 |
__( 'Your license key expires on %s.', 'buddypress-media' ),
|
238 |
date_i18n( get_option( 'date_format' ), strtotime( $license->expires, current_time( 'timestamp' ) ) )
|
239 |
);
|
@@ -264,6 +297,6 @@ class RTMediaLicense {
|
|
264 |
}
|
265 |
}
|
266 |
|
267 |
-
echo $html
|
268 |
}
|
269 |
}
|
1 |
<?php
|
|
|
2 |
/**
|
3 |
+
* File for RTMediaLicense
|
4 |
* User: ritz
|
5 |
* Date: 18/9/14
|
6 |
* Time: 5:05 PM
|
7 |
+
*
|
8 |
+
* @package rtMedia
|
9 |
*/
|
|
|
|
|
10 |
|
11 |
+
/**
|
12 |
+
* Class to show rtMedia license details.
|
13 |
+
*/
|
14 |
+
class RTMediaLicense {
|
15 |
+
/**
|
16 |
+
* Page.
|
17 |
+
*
|
18 |
+
* @var $page
|
19 |
+
*/
|
20 |
+
public static $page;
|
21 |
+
|
22 |
+
/**
|
23 |
+
* Render license.
|
24 |
+
*
|
25 |
+
* @param string $page Page.
|
26 |
+
*/
|
27 |
+
public static function render_license( $page = '' ) {
|
28 |
self::$page = $page;
|
29 |
|
30 |
$tabs = apply_filters( 'rtmedia_license_tabs', array() );
|
53 |
<?php
|
54 |
}
|
55 |
|
56 |
+
// For add-on which aren't updated with the latest code.
|
57 |
if ( did_action( 'rtmedia_addon_license_details' ) ) {
|
58 |
$addon_installed = true;
|
59 |
?>
|
70 |
}
|
71 |
}
|
72 |
|
73 |
+
/**
|
74 |
+
* Render license section.
|
75 |
+
*
|
76 |
+
* @param string $page page.
|
77 |
+
* @param string $tab tab.
|
78 |
+
*/
|
79 |
+
public static function render_license_section( $page = '', $tab = '' ) {
|
80 |
+
|
81 |
+
$args = $tab['args'];
|
82 |
+
$license = ( isset( $args['license_key'] ) ) ? $args['license_key'] : false;
|
83 |
+
$status = ( isset( $args['status'] ) ) ? $args['status'] : false;
|
84 |
+
$el_id = $args['addon_id'];
|
85 |
+
$license_key_id = $args['key_id'];
|
86 |
$license_status_id = $args['status_id'];
|
87 |
+
$license_data = get_option( 'edd_' . $el_id . '_active', '' );
|
88 |
?>
|
89 |
<div class="large-4 medium-6 small-12 license-column">
|
90 |
|
94 |
</h4>
|
95 |
|
96 |
<div class="license-inner">
|
97 |
+
<input id="<?php echo esc_attr( $license_key_id ); ?>" name="<?php echo esc_attr( $license_key_id ); ?>" type="text" class="regular-text" value="<?php echo esc_attr( $license ); ?>" />
|
98 |
<?php
|
99 |
$nonce_action = 'edd_' . $el_id . '_nonce';
|
100 |
$nonce_name = 'edd_' . $el_id . '_nonce';
|
112 |
|
113 |
<input type="submit" class="button-secondary" name="<?php echo esc_attr( $btn_name ); ?>" value="<?php echo esc_attr( $btn_val ); ?>" />
|
114 |
|
115 |
+
<?php
|
116 |
+
/**
|
117 |
+
* Classes to be append with `license-message` ***
|
118 |
+
* warning
|
119 |
+
* success
|
120 |
+
* info
|
121 |
+
* alert
|
122 |
+
*/
|
123 |
+
self::render_license_message( $license_data, $tab['title'] );
|
124 |
+
?>
|
125 |
</div><!-- End of .license-inner -->
|
126 |
</div><!-- End of .rtm-addon-license -->
|
127 |
</div><!-- End of .license-column -->
|
128 |
<?php
|
129 |
}
|
130 |
|
131 |
+
/**
|
132 |
+
* Render license message.
|
133 |
+
*
|
134 |
+
* @param string $license license.
|
135 |
+
* @param string $addon_name add-on name.
|
136 |
+
*/
|
137 |
+
public static function render_license_message( $license = '', $addon_name = '' ) {
|
138 |
|
139 |
$addon_name = isset( $license->item_name ) ? esc_html( $license->item_name ) : esc_html( $addon_name );
|
140 |
+
$messages = array();
|
141 |
|
142 |
if ( ! empty( $license ) && is_object( $license ) ) {
|
143 |
|
144 |
+
// activate_license 'invalid' on anything other than valid, so if there was an error capture it.
|
145 |
if ( false === $license->success ) {
|
146 |
|
147 |
switch ( $license->error ) {
|
148 |
|
149 |
+
case 'expired':
|
150 |
+
$class = 'alert';
|
|
|
151 |
$messages[] = sprintf(
|
152 |
+
// translators: %s: Expiry date.
|
153 |
+
__( 'Your license key expired on %s. Please renew your license key.', 'buddypress-media' ),
|
154 |
date_i18n( get_option( 'date_format' ), strtotime( $license->expires, current_time( 'timestamp' ) ) )
|
155 |
);
|
156 |
|
158 |
|
159 |
break;
|
160 |
|
161 |
+
case 'revoked':
|
162 |
+
$class = 'alert';
|
|
|
163 |
$messages[] = __( 'Your license key has been disabled. Please contact support for more information.', 'buddypress-media' );
|
164 |
|
165 |
$license_status = 'license-' . $class . '-notice';
|
166 |
|
167 |
break;
|
168 |
|
169 |
+
case 'missing':
|
170 |
+
$class = 'alert';
|
|
|
171 |
$messages[] = sprintf(
|
172 |
+
// translators: %s: Account page link.
|
173 |
+
__(
|
174 |
+
'Invalid license. Please <a href="%s" target="_blank">visit your account page</a> and verify it.',
|
175 |
+
'buddypress-media'
|
176 |
+
),
|
177 |
+
'https://rtmedia.io/my-account/'
|
178 |
);
|
179 |
|
180 |
$license_status = 'license-' . $class . '-notice';
|
181 |
|
182 |
break;
|
183 |
|
184 |
+
case 'invalid':
|
185 |
+
case 'site_inactive':
|
186 |
+
$class = 'alert';
|
|
|
187 |
$messages[] = sprintf(
|
188 |
+
// translators: 1: Add-on name, 2:My account page link.
|
189 |
__( 'Your %1$s is not active for this URL. Please <a href="%2$s" target="_blank">visit your account page</a> to manage your license key URLs.', 'buddypress-media' ),
|
190 |
$addon_name,
|
191 |
'https://rtmedia.io/my-account/'
|
195 |
|
196 |
break;
|
197 |
|
198 |
+
case 'item_name_mismatch':
|
|
|
199 |
$class = 'alert';
|
200 |
+
|
201 |
+
// translators: %s: Add-on name.
|
202 |
$messages[] = sprintf( __( 'This appears to be an invalid license key for %s.', 'buddypress-media' ), $addon_name );
|
203 |
|
204 |
$license_status = 'license-' . $class . '-notice';
|
206 |
break;
|
207 |
|
208 |
case 'no_activations_left':
|
|
|
209 |
$class = 'alert';
|
210 |
+
|
211 |
+
// translators: %s: Account link.
|
212 |
$messages[] = sprintf( __( 'Your license key has reached its activation limit. <a href="%s">View possible upgrades</a> now.', 'buddypress-media' ), 'https://rtmedia.io/my-account/' );
|
213 |
|
214 |
$license_status = 'license-' . $class . '-notice';
|
216 |
break;
|
217 |
|
218 |
case 'license_not_activable':
|
|
|
219 |
$class = 'alert';
|
220 |
+
|
221 |
+
// translators: %s: Account link.
|
222 |
$messages[] = sprintf( __( 'Your license is not activable, please visit <a href="%s">your account page</a>.', 'buddypress-media' ), 'https://rtmedia.io/my-account/' );
|
223 |
|
224 |
$license_status = 'license-' . $class . '-notice';
|
225 |
|
226 |
break;
|
227 |
|
228 |
+
default:
|
229 |
+
$class = 'alert';
|
|
|
230 |
$messages[] = __( 'To receive updates, please enter your valid license key.', 'buddypress-media' );
|
231 |
|
232 |
$license_status = 'license-' . $class . '-notice';
|
236 |
|
237 |
switch ( $license->license ) {
|
238 |
|
239 |
+
case 'valid':
|
240 |
default:
|
|
|
241 |
$class = 'success';
|
242 |
|
243 |
$now = current_time( 'timestamp' );
|
254 |
$class = 'warning';
|
255 |
|
256 |
$messages[] = sprintf(
|
257 |
+
// translators: 1: Expiry date.
|
258 |
__( 'Your license key expires soon! It expires on %1$s. Renew your license key.', 'buddypress-media' ),
|
259 |
date_i18n( get_option( 'date_format' ), strtotime( $license->expires, current_time( 'timestamp' ) ) )
|
260 |
);
|
266 |
$class = 'info';
|
267 |
|
268 |
$messages[] = sprintf(
|
269 |
+
// translators: %s: Expiry date.
|
270 |
__( 'Your license key expires on %s.', 'buddypress-media' ),
|
271 |
date_i18n( get_option( 'date_format' ), strtotime( $license->expires, current_time( 'timestamp' ) ) )
|
272 |
);
|
297 |
}
|
298 |
}
|
299 |
|
300 |
+
echo wp_kses( $html, RTMedia::expanded_allowed_tags() );
|
301 |
}
|
302 |
}
|
app/helper/RTMediaLikeNotification.php
CHANGED
@@ -1,16 +1,35 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
/**
|
4 |
-
*
|
5 |
*
|
6 |
* @author Jignesh Nakrani <jignesh.nakrani@rtcamp.com>
|
7 |
*/
|
8 |
class RTMediaLikeNotification extends RTMediaNotification {
|
9 |
|
|
|
|
|
|
|
|
|
|
|
10 |
public $component_id = 'rt_like_notifier';
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
public $component_action = 'new_like_to_media';
|
12 |
|
13 |
-
|
|
|
|
|
|
|
14 |
|
15 |
if ( class_exists( 'BuddyPress' ) ) {
|
16 |
$args = array(
|
@@ -29,7 +48,7 @@ class RTMediaLikeNotification extends RTMediaNotification {
|
|
29 |
/**
|
30 |
* Hooked to bp_init.
|
31 |
*/
|
32 |
-
function init() {
|
33 |
if ( bp_is_active( 'notifications' ) ) {
|
34 |
add_filter( 'rtmedia_like_notifications', array( $this, 'format_like_notifications' ) );
|
35 |
add_action( 'rtmedia_after_like_media', array( $this, 'add_like_notify' ) );
|
@@ -38,17 +57,16 @@ class RTMediaLikeNotification extends RTMediaNotification {
|
|
38 |
}
|
39 |
|
40 |
/**
|
41 |
-
*
|
42 |
* delete and merge likes if already same notification exist on a media
|
43 |
*
|
44 |
-
* @param RTMediaLike $
|
45 |
-
*
|
46 |
*/
|
47 |
-
function add_like_notify( $
|
48 |
-
$action = $
|
49 |
-
$user_id = $
|
50 |
-
$post_author_id = $
|
51 |
-
$post_id = $
|
52 |
$like_count = intval( get_rtmedia_like( $post_id ) );
|
53 |
|
54 |
if ( intval( $post_author_id ) === intval( $user_id ) ) {
|
@@ -65,11 +83,11 @@ class RTMediaLikeNotification extends RTMediaNotification {
|
|
65 |
/**
|
66 |
* Format string and media url for notification
|
67 |
*
|
68 |
-
* @param array $params array ('action', 'post_id', 'initiator_id', 'total_items', 'format' )
|
69 |
*
|
70 |
-
* @return string
|
71 |
*/
|
72 |
-
function format_like_notifications( $params ) {
|
73 |
$action = $params['action'];
|
74 |
$post_id = intval( $params['post_id'] );
|
75 |
|
@@ -81,14 +99,16 @@ class RTMediaLikeNotification extends RTMediaNotification {
|
|
81 |
|
82 |
$rtmedia_id = rtmedia_id( $post_id );
|
83 |
$liked_list = $this->fetch_media_like_stats( $rtmedia_id );
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
|
|
|
|
88 |
$like_count = get_rtmedia_like( $post_id );
|
89 |
$link = esc_url( get_rtmedia_permalink( $rtmedia_id ) );
|
90 |
$media_type = rtmedia_type( $rtmedia_id );
|
91 |
-
$text
|
92 |
|
93 |
if ( 0 === intval( $like_count ) ) {
|
94 |
$this->delete_notification_by_item_id( $initiator_id, $post_id );
|
@@ -101,7 +121,8 @@ class RTMediaLikeNotification extends RTMediaNotification {
|
|
101 |
$text = $liked_by . ' ' . __( 'and', 'buddypress-media' ) . ' ' . $count . ' ' . __( 'other friends liked your', 'buddypress-media' ) . ' ' . $media_type;
|
102 |
}
|
103 |
|
104 |
-
$return = apply_filters(
|
|
|
105 |
array(
|
106 |
'link' => $link,
|
107 |
'text' => $text,
|
@@ -120,21 +141,25 @@ class RTMediaLikeNotification extends RTMediaNotification {
|
|
120 |
/**
|
121 |
* Get like count of a media
|
122 |
*
|
123 |
-
* @param int $media_id MediaID to count likes
|
124 |
*
|
125 |
-
* @return int
|
126 |
*/
|
127 |
-
function fetch_media_like_stats( $media_id ) {
|
|
|
128 |
if ( empty( $media_id ) ) {
|
129 |
return false;
|
130 |
}
|
131 |
-
|
132 |
-
$
|
|
|
|
|
133 |
'media_id' => $media_id,
|
134 |
'action' => 'like',
|
135 |
'value' => 1,
|
136 |
);
|
137 |
-
$media_likes
|
|
|
138 |
if ( 0 === count( $media_likes ) ) {
|
139 |
return false;
|
140 |
}
|
@@ -144,13 +169,13 @@ class RTMediaLikeNotification extends RTMediaNotification {
|
|
144 |
}
|
145 |
|
146 |
/**
|
147 |
-
*
|
148 |
*
|
149 |
-
* @param
|
150 |
-
* @param
|
151 |
-
* @param
|
152 |
-
* @param
|
153 |
-
* @param String $format string or array
|
154 |
*
|
155 |
* @return String/Array formatted notification
|
156 |
*/
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* File for RTMediaLikeNotification class.
|
4 |
+
*
|
5 |
+
* @package rtMedia
|
6 |
+
*/
|
7 |
|
8 |
/**
|
9 |
+
* Class to handle media liked notification
|
10 |
*
|
11 |
* @author Jignesh Nakrani <jignesh.nakrani@rtcamp.com>
|
12 |
*/
|
13 |
class RTMediaLikeNotification extends RTMediaNotification {
|
14 |
|
15 |
+
/**
|
16 |
+
* Component id.
|
17 |
+
*
|
18 |
+
* @var string
|
19 |
+
*/
|
20 |
public $component_id = 'rt_like_notifier';
|
21 |
+
|
22 |
+
/**
|
23 |
+
* Component action.
|
24 |
+
*
|
25 |
+
* @var string
|
26 |
+
*/
|
27 |
public $component_action = 'new_like_to_media';
|
28 |
|
29 |
+
/**
|
30 |
+
* RTMediaLikeNotification constructor.
|
31 |
+
*/
|
32 |
+
public function __construct() {
|
33 |
|
34 |
if ( class_exists( 'BuddyPress' ) ) {
|
35 |
$args = array(
|
48 |
/**
|
49 |
* Hooked to bp_init.
|
50 |
*/
|
51 |
+
public function init() {
|
52 |
if ( bp_is_active( 'notifications' ) ) {
|
53 |
add_filter( 'rtmedia_like_notifications', array( $this, 'format_like_notifications' ) );
|
54 |
add_action( 'rtmedia_after_like_media', array( $this, 'add_like_notify' ) );
|
57 |
}
|
58 |
|
59 |
/**
|
60 |
+
* Add notification using bp_notifications_add_notification function
|
61 |
* delete and merge likes if already same notification exist on a media
|
62 |
*
|
63 |
+
* @param RTMediaLike $like_args RTMediaLike class object.
|
|
|
64 |
*/
|
65 |
+
public function add_like_notify( $like_args ) {
|
66 |
+
$action = $like_args->increase;
|
67 |
+
$user_id = $like_args->interactor;
|
68 |
+
$post_author_id = $like_args->owner;
|
69 |
+
$post_id = $like_args->media->media_id;
|
70 |
$like_count = intval( get_rtmedia_like( $post_id ) );
|
71 |
|
72 |
if ( intval( $post_author_id ) === intval( $user_id ) ) {
|
83 |
/**
|
84 |
* Format string and media url for notification
|
85 |
*
|
86 |
+
* @param array $params array ('action', 'post_id', 'initiator_id', 'total_items', 'format' ).
|
87 |
*
|
88 |
+
* @return string|array format notification as $params['format'] request
|
89 |
*/
|
90 |
+
public function format_like_notifications( $params ) {
|
91 |
$action = $params['action'];
|
92 |
$post_id = intval( $params['post_id'] );
|
93 |
|
99 |
|
100 |
$rtmedia_id = rtmedia_id( $post_id );
|
101 |
$liked_list = $this->fetch_media_like_stats( $rtmedia_id );
|
102 |
+
$liked_by = '';
|
103 |
+
|
104 |
+
if ( isset( $liked_list[0]->user_id ) ) {
|
105 |
+
$liked_by = bp_core_get_username( $liked_list[0]->user_id );
|
106 |
+
}
|
107 |
+
|
108 |
$like_count = get_rtmedia_like( $post_id );
|
109 |
$link = esc_url( get_rtmedia_permalink( $rtmedia_id ) );
|
110 |
$media_type = rtmedia_type( $rtmedia_id );
|
111 |
+
$text = null;
|
112 |
|
113 |
if ( 0 === intval( $like_count ) ) {
|
114 |
$this->delete_notification_by_item_id( $initiator_id, $post_id );
|
121 |
$text = $liked_by . ' ' . __( 'and', 'buddypress-media' ) . ' ' . $count . ' ' . __( 'other friends liked your', 'buddypress-media' ) . ' ' . $media_type;
|
122 |
}
|
123 |
|
124 |
+
$return = apply_filters(
|
125 |
+
'rtmedia_before_like_notification',
|
126 |
array(
|
127 |
'link' => $link,
|
128 |
'text' => $text,
|
141 |
/**
|
142 |
* Get like count of a media
|
143 |
*
|
144 |
+
* @param int $media_id MediaID to count likes.
|
145 |
*
|
146 |
+
* @return array|int Total like count on success or false
|
147 |
*/
|
148 |
+
public function fetch_media_like_stats( $media_id ) {
|
149 |
+
|
150 |
if ( empty( $media_id ) ) {
|
151 |
return false;
|
152 |
}
|
153 |
+
|
154 |
+
$rtmedia_interaction_model = new RTMediaInteractionModel();
|
155 |
+
|
156 |
+
$media_like_cols = array(
|
157 |
'media_id' => $media_id,
|
158 |
'action' => 'like',
|
159 |
'value' => 1,
|
160 |
);
|
161 |
+
$media_likes = $rtmedia_interaction_model->get( $media_like_cols, false, false, 'action_date' );
|
162 |
+
|
163 |
if ( 0 === count( $media_likes ) ) {
|
164 |
return false;
|
165 |
}
|
169 |
}
|
170 |
|
171 |
/**
|
172 |
+
* This is callback function for rt_like_notifier component dont call this callback method manually
|
173 |
*
|
174 |
+
* @param int $action action of component for notification.
|
175 |
+
* @param int $post_id ID of a post to notification.
|
176 |
+
* @param int $initiator_id secondary_item_id used in 'bp_notifications_add_notification'.
|
177 |
+
* @param int $total_items number of notification for same component.
|
178 |
+
* @param String $format string or array.
|
179 |
*
|
180 |
* @return String/Array formatted notification
|
181 |
*/
|
app/helper/RTMediaModel.php
CHANGED
@@ -1,25 +1,41 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
/**
|
4 |
-
*
|
5 |
*
|
6 |
* @author joshua
|
7 |
*/
|
8 |
class RTMediaModel extends RTDBModel {
|
9 |
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
parent::__construct( 'rtm_media', false, 10, true );
|
12 |
$this->meta_table_name = 'rt_rtm_media_meta';
|
13 |
}
|
14 |
|
15 |
/**
|
|
|
16 |
*
|
17 |
-
* @param string $name
|
18 |
-
* @param array
|
19 |
*
|
20 |
* @return array
|
21 |
*/
|
22 |
-
function __call( $name, $arguments ) {
|
23 |
$result = parent::__call( $name, $arguments );
|
24 |
if ( ! $result['result'] ) {
|
25 |
$result['result'] = $this->populate_results_fallback( $name, $arguments );
|
@@ -29,20 +45,23 @@ class RTMediaModel extends RTDBModel {
|
|
29 |
}
|
30 |
|
31 |
/**
|
|
|
32 |
*
|
33 |
* @global object $wpdb
|
34 |
*
|
35 |
-
* @param array
|
36 |
-
* @param mixed
|
37 |
-
* @param mixed
|
38 |
-
* @param string $order_by
|
|
|
39 |
*
|
40 |
-
* @return array
|
41 |
*/
|
42 |
-
function get( $columns, $offset = false, $per_page = false, $order_by = 'media_id desc', $count_flag = false ) {
|
43 |
-
global $wpdb;
|
44 |
-
|
45 |
$select = 'SELECT ';
|
|
|
46 |
if ( $count_flag ) {
|
47 |
$select .= 'count(*) ';
|
48 |
} else {
|
@@ -53,11 +72,11 @@ class RTMediaModel extends RTDBModel {
|
|
53 |
$join = '';
|
54 |
$where = ' where 2=2 ';
|
55 |
if ( is_multisite() ) {
|
56 |
-
$where .= $wpdb->prepare( " AND {$this->table_name}.blog_id =%d ", get_current_blog_id() ); //
|
57 |
}
|
58 |
$temp = 65;
|
59 |
|
60 |
-
$columns = apply_filters( 'rtmedia-model-query-columns', $columns, $count_flag );
|
61 |
|
62 |
foreach ( (array) $columns as $colname => $colvalue ) {
|
63 |
$colname = esc_sql( $colname );
|
@@ -74,9 +93,9 @@ class RTMediaModel extends RTDBModel {
|
|
74 |
}
|
75 |
$meta_query['compare'] = esc_sql( $meta_query['compare'] );
|
76 |
if ( isset( $meta_query['value'] ) ) {
|
77 |
-
$where .= $wpdb->prepare( " AND ({$tbl_alias}.meta_key = %s and {$tbl_alias}.meta_value {$meta_query["compare"]} %s ) ", $meta_query['key'], $meta_query['value'] ); //
|
78 |
} else {
|
79 |
-
$where .= $wpdb->prepare( " AND {$tbl_alias}.meta_key = %s ", $meta_query['key'] )
|
80 |
}
|
81 |
}
|
82 |
} else {
|
@@ -87,31 +106,36 @@ class RTMediaModel extends RTDBModel {
|
|
87 |
$compare = $colvalue['compare'];
|
88 |
}
|
89 |
|
90 |
-
$
|
91 |
-
$col_val_comapare = ( is_array( $
|
|
|
92 |
if ( 'IS NOT' === $compare ) {
|
93 |
$col_val_comapare = ! empty( $colvalue['value'] ) ? $colvalue['value'] : $col_val_comapare;
|
94 |
}
|
|
|
95 |
$compare = esc_sql( $compare );
|
96 |
-
$where
|
97 |
} else {
|
98 |
-
$where .= $wpdb->prepare( " AND {$this->table_name}.{$colname} = %s", $colvalue ); //
|
99 |
}
|
100 |
}
|
101 |
}
|
102 |
$qgroup_by = ' ';
|
|
|
103 |
if ( $order_by ) {
|
104 |
-
$order_by
|
105 |
$qorder_by = " ORDER BY {$this->table_name}.{$order_by}";
|
106 |
} else {
|
107 |
$qorder_by = '';
|
108 |
}
|
109 |
|
|
|
110 |
$select = apply_filters( 'rtmedia-model-select-query', $select, $this->table_name );
|
111 |
$join = apply_filters( 'rtmedia-model-join-query', $join, $this->table_name );
|
112 |
-
$where = apply_filters( 'rtmedia-model-where-query', $where, $this->table_name
|
113 |
$qgroup_by = apply_filters( 'rtmedia-model-group-by-query', $qgroup_by, $this->table_name );
|
114 |
$qorder_by = apply_filters( 'rtmedia-model-order-by-query', $qorder_by, $this->table_name );
|
|
|
115 |
|
116 |
$sql = $select . $from . $join . $where . $qgroup_by . $qorder_by;
|
117 |
if ( false !== $offset ) {
|
@@ -131,28 +155,30 @@ class RTMediaModel extends RTDBModel {
|
|
131 |
$per_page = 1;
|
132 |
}
|
133 |
|
134 |
-
//filter added to change the LIMIT
|
135 |
-
$limit = apply_filters( 'rtmedia-model-limit-query', ' LIMIT ' . $offset . ',' . $per_page, $offset, $per_page );
|
136 |
|
137 |
$sql .= $limit;
|
138 |
}
|
139 |
|
140 |
if ( ! $count_flag ) {
|
141 |
-
return $wpdb->get_results( $sql ); //
|
142 |
} else {
|
143 |
-
return $wpdb->get_var( $sql ); //
|
144 |
}
|
145 |
}
|
146 |
|
147 |
/**
|
|
|
148 |
*
|
149 |
-
* @param string $name
|
150 |
-
* @param array
|
151 |
*
|
152 |
-
* @return array
|
153 |
*/
|
154 |
-
function populate_results_fallback( $name, $arguments ) {
|
155 |
$result['result'] = false;
|
|
|
156 |
if ( 'get_by_media_id' === $name && isset( $arguments[0] ) && $arguments[0] ) {
|
157 |
|
158 |
$result['result'][0]->media_id = $arguments[0];
|
@@ -183,15 +209,17 @@ class RTMediaModel extends RTDBModel {
|
|
183 |
}
|
184 |
|
185 |
/**
|
|
|
186 |
*
|
187 |
-
* @param array
|
188 |
-
* @param mixed
|
189 |
-
* @param mixed
|
190 |
-
* @param string $order_by
|
|
|
191 |
*
|
192 |
* @return array
|
193 |
*/
|
194 |
-
function get_media( $columns, $offset = false, $per_page = false, $order_by = 'media_id desc', $count_flag = false ) {
|
195 |
if ( is_multisite() ) {
|
196 |
$order_by = 'blog_id' . ( ( $order_by ) ? ',' . $order_by : '' );
|
197 |
}
|
@@ -202,39 +230,47 @@ class RTMediaModel extends RTDBModel {
|
|
202 |
}
|
203 |
|
204 |
/**
|
|
|
205 |
*
|
206 |
-
* @param integer $author_id
|
207 |
-
* @param mixed
|
208 |
-
* @param mixed
|
209 |
-
* @param string
|
210 |
*
|
211 |
* @return array $results
|
212 |
*/
|
213 |
-
function get_user_albums( $author_id, $offset, $per_page, $order_by = 'media_id desc' ) {
|
214 |
global $wpdb;
|
|
|
215 |
if ( is_multisite() ) {
|
216 |
$order_by = 'blog_id' . ( ( $order_by ) ? ',' . $order_by : '' );
|
217 |
}
|
218 |
|
219 |
$sql = "SELECT * FROM {$this->table_name} ";
|
220 |
-
|
221 |
if ( is_multisite() ) {
|
222 |
-
$sub_sql = $wpdb->prepare( "SELECT DISTINCT (album_id) FROM {$this->table_name} WHERE media_author = %d AND album_id IS NOT NULL AND media_type <> 'album' AND context <> 'group' AND blog_id = %d", $author_id, get_current_blog_id() );
|
223 |
} else {
|
224 |
-
$sub_sql = $wpdb->prepare( "SELECT DISTINCT (album_id) FROM {$this->table_name} WHERE media_author = %d AND album_id IS NOT NULL AND media_type <> 'album' AND context <> 'group'", $author_id );
|
225 |
}
|
226 |
-
|
227 |
-
$where = $wpdb->prepare(
|
|
|
228 |
AND media_type = 'album'
|
229 |
-
AND (context = 'profile' or context is NULL) ",
|
|
|
|
|
230 |
if ( is_multisite() ) {
|
231 |
-
$where .= $wpdb->prepare( " AND {$this->table_name}.blog_id = %d ", get_current_blog_id() );
|
232 |
}
|
233 |
-
$where = apply_filters( 'rtmedia-get-album-where-query', $where, $this->table_name );
|
234 |
|
235 |
-
$
|
|
|
|
|
|
|
236 |
$qorder_by = " ORDER BY {$this->table_name}.$order_by ";
|
237 |
-
$sql
|
|
|
238 |
if ( false !== $offset ) {
|
239 |
if ( ! is_integer( $offset ) ) {
|
240 |
$offset = 0;
|
@@ -253,38 +289,39 @@ class RTMediaModel extends RTDBModel {
|
|
253 |
$sql .= ' LIMIT ' . $offset . ',' . $per_page;
|
254 |
}
|
255 |
|
256 |
-
$results = $wpdb->get_results( $sql ); //
|
257 |
|
258 |
return $results;
|
259 |
}
|
260 |
|
261 |
/**
|
|
|
262 |
*
|
263 |
-
* @param integer $group_id
|
264 |
-
* @param mixed
|
265 |
-
* @param mixed
|
266 |
-
* @param string
|
267 |
*
|
268 |
* @return array $results
|
269 |
*/
|
270 |
-
function get_group_albums( $group_id, $offset, $per_page, $order_by = 'media_id desc' ) {
|
271 |
global $wpdb;
|
272 |
if ( is_multisite() ) {
|
273 |
$order_by = 'blog_id' . ( ( $order_by ) ? ',' . $order_by : '' );
|
274 |
}
|
275 |
|
276 |
if ( is_multisite() ) {
|
277 |
-
$sub_sql = $wpdb->prepare( "SELECT DISTINCT (album_id) FROM {$this->table_name} WHERE context_id = %d AND album_id IS NOT NULL AND media_type != 'album' AND context = 'group' AND blog_id = %d", $group_id, get_current_blog_id() );
|
278 |
} else {
|
279 |
-
$sub_sql = $wpdb->prepare( "SELECT DISTINCT (album_id) FROM {$this->table_name} WHERE context_id = %d AND album_id IS NOT NULL AND media_type != 'album' AND context = 'group'", $group_id );
|
280 |
}
|
281 |
-
$sql = $wpdb->prepare( "SELECT * FROM {$this->table_name} WHERE id IN( $sub_sql ) OR (media_type = 'album' AND context_id = %d AND context = 'group')", $group_id );
|
282 |
|
283 |
if ( is_multisite() ) {
|
284 |
-
$sql .= $wpdb->prepare( " AND {$this->table_name}.blog_id = %d ", get_current_blog_id() );
|
285 |
}
|
286 |
$order_by = esc_sql( $order_by );
|
287 |
-
$sql
|
288 |
|
289 |
if ( false !== $offset ) {
|
290 |
if ( ! is_integer( $offset ) ) {
|
@@ -303,19 +340,21 @@ class RTMediaModel extends RTDBModel {
|
|
303 |
|
304 |
$sql .= ' LIMIT ' . $offset . ',' . $per_page;
|
305 |
}
|
306 |
-
|
|
|
307 |
|
308 |
return $results;
|
309 |
}
|
310 |
|
311 |
/**
|
|
|
312 |
*
|
313 |
-
* @param mixed $user_id
|
314 |
-
* @param mixed $where_query
|
315 |
*
|
316 |
* @return string $result
|
317 |
*/
|
318 |
-
function get_counts( $user_id = false, $where_query = false ) {
|
319 |
if ( ! $user_id && ! $where_query ) {
|
320 |
return false;
|
321 |
}
|
@@ -324,16 +363,18 @@ class RTMediaModel extends RTDBModel {
|
|
324 |
$query = "SELECT {$this->table_name}.privacy, ";
|
325 |
foreach ( $rtmedia->allowed_types as $type ) {
|
326 |
$type['name'] = esc_sql( $type['name'] );
|
327 |
-
$query
|
328 |
}
|
329 |
$query .= "SUM(CASE WHEN {$this->table_name}.media_type LIKE 'album' THEN 1 ELSE 0 END) as album
|
330 |
FROM
|
331 |
{$this->table_name} WHERE 2=2 ";
|
332 |
|
333 |
if ( is_multisite() ) {
|
334 |
-
$query .= $wpdb->prepare( " AND {$this->table_name}.blog_id = %d ", get_current_blog_id() );
|
335 |
}
|
|
|
336 |
$where_query_sql = '';
|
|
|
337 |
if ( $where_query ) {
|
338 |
foreach ( $where_query as $colname => $colvalue ) {
|
339 |
$colname = esc_sql( $colname );
|
@@ -347,17 +388,18 @@ class RTMediaModel extends RTDBModel {
|
|
347 |
if ( ! isset( $colvalue['value'] ) ) {
|
348 |
$colvalue['value'] = $colvalue;
|
349 |
}
|
350 |
-
$compare
|
351 |
$where_query_sql .= " AND {$this->table_name}.{$colname} {$compare} ('" . implode( "','", esc_sql( $colvalue['value'] ) ) . "')";
|
352 |
} else {
|
353 |
-
$where_query_sql .= $wpdb->prepare( " AND {$this->table_name}.{$colname} = %s", $colvalue );
|
354 |
}
|
355 |
}
|
356 |
}
|
357 |
}
|
358 |
-
|
|
|
359 |
$query = $query . $where_query_sql . ' GROUP BY privacy limit 100';
|
360 |
-
$result = $wpdb->get_results( $query );
|
361 |
if ( ! is_array( $result ) ) {
|
362 |
return false;
|
363 |
}
|
@@ -366,28 +408,33 @@ class RTMediaModel extends RTDBModel {
|
|
366 |
}
|
367 |
|
368 |
/**
|
|
|
369 |
*
|
370 |
-
* @param integer $profile_id
|
371 |
-
* @param string
|
372 |
*
|
373 |
* @return int
|
374 |
*/
|
375 |
-
function get_other_album_count( $profile_id, $context = 'profile' ) {
|
376 |
global $wpdb;
|
|
|
377 |
$global = RTMediaAlbum::get_globals();
|
378 |
-
$sql = $wpdb->prepare( "select distinct album_id from {$this->table_name} where 2=2 AND context = %s ", $context );
|
|
|
379 |
if ( is_multisite() ) {
|
380 |
-
$sql .= $wpdb->prepare( " AND {$this->table_name}.blog_id = %d ", get_current_blog_id() );
|
381 |
}
|
|
|
382 |
if ( is_array( $global ) && count( $global ) > 0 ) {
|
383 |
$sql .= ' and album_id in (';
|
384 |
-
$sep
|
385 |
foreach ( $global as $id ) {
|
386 |
$sql .= $sep . esc_sql( $id );
|
387 |
-
$sep
|
388 |
}
|
389 |
$sql .= ')';
|
390 |
}
|
|
|
391 |
if ( 'profile' === $context ) {
|
392 |
$sql .= $wpdb->prepare( ' AND media_author=%d ', $profile_id );
|
393 |
} else {
|
@@ -395,8 +442,10 @@ class RTMediaModel extends RTDBModel {
|
|
395 |
$sql .= $wpdb->prepare( ' AND context_id=%d ', $profile_id );
|
396 |
}
|
397 |
}
|
398 |
-
|
399 |
-
$
|
|
|
|
|
400 |
if ( isset( $result ) ) {
|
401 |
return count( $result );
|
402 |
} else {
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* Handles rtMedia medias.
|
4 |
+
*
|
5 |
+
* @package rtMedia
|
6 |
+
*/
|
7 |
|
8 |
/**
|
9 |
+
* Class to handle rtMedia medias.
|
10 |
*
|
11 |
* @author joshua
|
12 |
*/
|
13 |
class RTMediaModel extends RTDBModel {
|
14 |
|
15 |
+
/**
|
16 |
+
* Meta table.
|
17 |
+
*
|
18 |
+
* @var string
|
19 |
+
*/
|
20 |
+
public $meta_table_name = '';
|
21 |
+
|
22 |
+
/**
|
23 |
+
* RTMediaModel constructor.
|
24 |
+
*/
|
25 |
+
public function __construct() {
|
26 |
parent::__construct( 'rtm_media', false, 10, true );
|
27 |
$this->meta_table_name = 'rt_rtm_media_meta';
|
28 |
}
|
29 |
|
30 |
/**
|
31 |
+
* Get DB rows by particular column
|
32 |
*
|
33 |
+
* @param string $name Column Name.
|
34 |
+
* @param array $arguments Arguments.
|
35 |
*
|
36 |
* @return array
|
37 |
*/
|
38 |
+
public function __call( $name, $arguments ) {
|
39 |
$result = parent::__call( $name, $arguments );
|
40 |
if ( ! $result['result'] ) {
|
41 |
$result['result'] = $this->populate_results_fallback( $name, $arguments );
|
45 |
}
|
46 |
|
47 |
/**
|
48 |
+
* Get column data.
|
49 |
*
|
50 |
* @global object $wpdb
|
51 |
*
|
52 |
+
* @param array $columns column names.
|
53 |
+
* @param mixed $offset Offset to get data.
|
54 |
+
* @param mixed $per_page Rows Per page.
|
55 |
+
* @param string $order_by Order by condition.
|
56 |
+
* @param bool $count_flag Count flag.
|
57 |
*
|
58 |
+
* @return array|int|string
|
59 |
*/
|
60 |
+
public function get( $columns, $offset = false, $per_page = false, $order_by = 'media_id desc', $count_flag = false ) {
|
61 |
+
global $wpdb, $rtmedia_interaction;
|
62 |
+
|
63 |
$select = 'SELECT ';
|
64 |
+
|
65 |
if ( $count_flag ) {
|
66 |
$select .= 'count(*) ';
|
67 |
} else {
|
72 |
$join = '';
|
73 |
$where = ' where 2=2 ';
|
74 |
if ( is_multisite() ) {
|
75 |
+
$where .= $wpdb->prepare( " AND {$this->table_name}.blog_id =%d ", get_current_blog_id() ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
76 |
}
|
77 |
$temp = 65;
|
78 |
|
79 |
+
$columns = apply_filters( 'rtmedia-model-query-columns', $columns, $count_flag ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
|
80 |
|
81 |
foreach ( (array) $columns as $colname => $colvalue ) {
|
82 |
$colname = esc_sql( $colname );
|
93 |
}
|
94 |
$meta_query['compare'] = esc_sql( $meta_query['compare'] );
|
95 |
if ( isset( $meta_query['value'] ) ) {
|
96 |
+
$where .= $wpdb->prepare( " AND ({$tbl_alias}.meta_key = %s and {$tbl_alias}.meta_value {$meta_query["compare"]} %s ) ", $meta_query['key'], $meta_query['value'] ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
97 |
} else {
|
98 |
+
$where .= $wpdb->prepare( " AND {$tbl_alias}.meta_key = %s ", $meta_query['key'] ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
99 |
}
|
100 |
}
|
101 |
} else {
|
106 |
$compare = $colvalue['compare'];
|
107 |
}
|
108 |
|
109 |
+
$tmp_val = isset( $colvalue['value'] ) ? $colvalue['value'] : $colvalue;
|
110 |
+
$col_val_comapare = ( is_array( $tmp_val ) ) ? implode( "','", esc_sql( $tmp_val ) ) : esc_sql( $tmp_val );
|
111 |
+
|
112 |
if ( 'IS NOT' === $compare ) {
|
113 |
$col_val_comapare = ! empty( $colvalue['value'] ) ? $colvalue['value'] : $col_val_comapare;
|
114 |
}
|
115 |
+
|
116 |
$compare = esc_sql( $compare );
|
117 |
+
$where .= " AND {$this->table_name}.{$colname} {$compare} ('{$col_val_comapare}')";
|
118 |
} else {
|
119 |
+
$where .= $wpdb->prepare( " AND {$this->table_name}.{$colname} = %s", $colvalue ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
120 |
}
|
121 |
}
|
122 |
}
|
123 |
$qgroup_by = ' ';
|
124 |
+
|
125 |
if ( $order_by ) {
|
126 |
+
$order_by = esc_sql( $order_by );
|
127 |
$qorder_by = " ORDER BY {$this->table_name}.{$order_by}";
|
128 |
} else {
|
129 |
$qorder_by = '';
|
130 |
}
|
131 |
|
132 |
+
// phpcs:disable WordPress.NamingConventions.ValidHookName.UseUnderscores
|
133 |
$select = apply_filters( 'rtmedia-model-select-query', $select, $this->table_name );
|
134 |
$join = apply_filters( 'rtmedia-model-join-query', $join, $this->table_name );
|
135 |
+
$where = apply_filters( 'rtmedia-model-where-query', $where, $this->table_name, $join );
|
136 |
$qgroup_by = apply_filters( 'rtmedia-model-group-by-query', $qgroup_by, $this->table_name );
|
137 |
$qorder_by = apply_filters( 'rtmedia-model-order-by-query', $qorder_by, $this->table_name );
|
138 |
+
// phpcs:enable WordPress.NamingConventions.ValidHookName.UseUnderscores
|
139 |
|
140 |
$sql = $select . $from . $join . $where . $qgroup_by . $qorder_by;
|
141 |
if ( false !== $offset ) {
|
155 |
$per_page = 1;
|
156 |
}
|
157 |
|
158 |
+
// filter added to change the LIMIT.
|
159 |
+
$limit = apply_filters( 'rtmedia-model-limit-query', ' LIMIT ' . $offset . ',' . $per_page, $offset, $per_page ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
|
160 |
|
161 |
$sql .= $limit;
|
162 |
}
|
163 |
|
164 |
if ( ! $count_flag ) {
|
165 |
+
return $wpdb->get_results( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
166 |
} else {
|
167 |
+
return $wpdb->get_var( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
168 |
}
|
169 |
}
|
170 |
|
171 |
/**
|
172 |
+
* Populate fallback results.
|
173 |
*
|
174 |
+
* @param string $name Name for fallback data.
|
175 |
+
* @param array $arguments Arguments to populate data.
|
176 |
*
|
177 |
+
* @return array|bool
|
178 |
*/
|
179 |
+
public function populate_results_fallback( $name, $arguments ) {
|
180 |
$result['result'] = false;
|
181 |
+
|
182 |
if ( 'get_by_media_id' === $name && isset( $arguments[0] ) && $arguments[0] ) {
|
183 |
|
184 |
$result['result'][0]->media_id = $arguments[0];
|
209 |
}
|
210 |
|
211 |
/**
|
212 |
+
* Get media.
|
213 |
*
|
214 |
+
* @param array $columns Columns names.
|
215 |
+
* @param mixed $offset Offset to get data.
|
216 |
+
* @param mixed $per_page Rows Per page.
|
217 |
+
* @param string $order_by Order by condition.
|
218 |
+
* @param bool $count_flag Count flag.
|
219 |
*
|
220 |
* @return array
|
221 |
*/
|
222 |
+
public function get_media( $columns, $offset = false, $per_page = false, $order_by = 'media_id desc', $count_flag = false ) {
|
223 |
if ( is_multisite() ) {
|
224 |
$order_by = 'blog_id' . ( ( $order_by ) ? ',' . $order_by : '' );
|
225 |
}
|
230 |
}
|
231 |
|
232 |
/**
|
233 |
+
* Get user albums.
|
234 |
*
|
235 |
+
* @param integer $author_id Author id.
|
236 |
+
* @param mixed $offset Offset to get data.
|
237 |
+
* @param mixed $per_page Rows Per page.
|
238 |
+
* @param string $order_by Order by condition.
|
239 |
*
|
240 |
* @return array $results
|
241 |
*/
|
242 |
+
public function get_user_albums( $author_id, $offset, $per_page, $order_by = 'media_id desc' ) {
|
243 |
global $wpdb;
|
244 |
+
|
245 |
if ( is_multisite() ) {
|
246 |
$order_by = 'blog_id' . ( ( $order_by ) ? ',' . $order_by : '' );
|
247 |
}
|
248 |
|
249 |
$sql = "SELECT * FROM {$this->table_name} ";
|
250 |
+
// phpcs:disable WordPress.DB.PreparedSQL.NotPrepared
|
251 |
if ( is_multisite() ) {
|
252 |
+
$sub_sql = $wpdb->prepare( "SELECT DISTINCT (album_id) FROM {$this->table_name} WHERE media_author = %d AND album_id IS NOT NULL AND media_type <> 'album' AND context <> 'group' AND blog_id = %d", $author_id, get_current_blog_id() );
|
253 |
} else {
|
254 |
+
$sub_sql = $wpdb->prepare( "SELECT DISTINCT (album_id) FROM {$this->table_name} WHERE media_author = %d AND album_id IS NOT NULL AND media_type <> 'album' AND context <> 'group'", $author_id );
|
255 |
}
|
256 |
+
|
257 |
+
$where = $wpdb->prepare(
|
258 |
+
" WHERE (id IN( $sub_sql ) OR (media_author = %d ))
|
259 |
AND media_type = 'album'
|
260 |
+
AND (context = 'profile' or context is NULL) ",
|
261 |
+
$author_id
|
262 |
+
);
|
263 |
if ( is_multisite() ) {
|
264 |
+
$where .= $wpdb->prepare( " AND {$this->table_name}.blog_id = %d ", get_current_blog_id() );
|
265 |
}
|
|
|
266 |
|
267 |
+
$where = apply_filters( 'rtmedia-get-album-where-query', $where, $this->table_name ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
|
268 |
+
|
269 |
+
// phpcs:enable WordPress.DB.PreparedSQL.NotPrepared
|
270 |
+
$order_by = esc_sql( $order_by );
|
271 |
$qorder_by = " ORDER BY {$this->table_name}.$order_by ";
|
272 |
+
$sql .= $where . $qorder_by;
|
273 |
+
|
274 |
if ( false !== $offset ) {
|
275 |
if ( ! is_integer( $offset ) ) {
|
276 |
$offset = 0;
|
289 |
$sql .= ' LIMIT ' . $offset . ',' . $per_page;
|
290 |
}
|
291 |
|
292 |
+
$results = $wpdb->get_results( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
293 |
|
294 |
return $results;
|
295 |
}
|
296 |
|
297 |
/**
|
298 |
+
* Get group Albums from group id.
|
299 |
*
|
300 |
+
* @param integer $group_id Group id.
|
301 |
+
* @param mixed $offset Offset for data.
|
302 |
+
* @param mixed $per_page Rows per page.
|
303 |
+
* @param string $order_by Order by condition.
|
304 |
*
|
305 |
* @return array $results
|
306 |
*/
|
307 |
+
public function get_group_albums( $group_id, $offset, $per_page, $order_by = 'media_id desc' ) {
|
308 |
global $wpdb;
|
309 |
if ( is_multisite() ) {
|
310 |
$order_by = 'blog_id' . ( ( $order_by ) ? ',' . $order_by : '' );
|
311 |
}
|
312 |
|
313 |
if ( is_multisite() ) {
|
314 |
+
$sub_sql = $wpdb->prepare( "SELECT DISTINCT (album_id) FROM {$this->table_name} WHERE context_id = %d AND album_id IS NOT NULL AND media_type != 'album' AND context = 'group' AND blog_id = %d", $group_id, get_current_blog_id() ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
315 |
} else {
|
316 |
+
$sub_sql = $wpdb->prepare( "SELECT DISTINCT (album_id) FROM {$this->table_name} WHERE context_id = %d AND album_id IS NOT NULL AND media_type != 'album' AND context = 'group'", $group_id ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
317 |
}
|
318 |
+
$sql = $wpdb->prepare( "SELECT * FROM {$this->table_name} WHERE id IN( $sub_sql ) OR (media_type = 'album' AND context_id = %d AND context = 'group')", $group_id ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
319 |
|
320 |
if ( is_multisite() ) {
|
321 |
+
$sql .= $wpdb->prepare( " AND {$this->table_name}.blog_id = %d ", get_current_blog_id() ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
322 |
}
|
323 |
$order_by = esc_sql( $order_by );
|
324 |
+
$sql .= " ORDER BY {$this->table_name}.$order_by";
|
325 |
|
326 |
if ( false !== $offset ) {
|
327 |
if ( ! is_integer( $offset ) ) {
|
340 |
|
341 |
$sql .= ' LIMIT ' . $offset . ',' . $per_page;
|
342 |
}
|
343 |
+
|
344 |
+
$results = $wpdb->get_results( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
345 |
|
346 |
return $results;
|
347 |
}
|
348 |
|
349 |
/**
|
350 |
+
* Get counts.
|
351 |
*
|
352 |
+
* @param mixed $user_id User id.
|
353 |
+
* @param mixed $where_query Where query.
|
354 |
*
|
355 |
* @return string $result
|
356 |
*/
|
357 |
+
public function get_counts( $user_id = false, $where_query = false ) {
|
358 |
if ( ! $user_id && ! $where_query ) {
|
359 |
return false;
|
360 |
}
|
363 |
$query = "SELECT {$this->table_name}.privacy, ";
|
364 |
foreach ( $rtmedia->allowed_types as $type ) {
|
365 |
$type['name'] = esc_sql( $type['name'] );
|
366 |
+
$query .= $wpdb->prepare( "SUM(CASE WHEN {$this->table_name}.media_type LIKE %s THEN 1 ELSE 0 END) as {$type['name']}, ", $type['name'] ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
367 |
}
|
368 |
$query .= "SUM(CASE WHEN {$this->table_name}.media_type LIKE 'album' THEN 1 ELSE 0 END) as album
|
369 |
FROM
|
370 |
{$this->table_name} WHERE 2=2 ";
|
371 |
|
372 |
if ( is_multisite() ) {
|
373 |
+
$query .= $wpdb->prepare( " AND {$this->table_name}.blog_id = %d ", get_current_blog_id() ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
374 |
}
|
375 |
+
|
376 |
$where_query_sql = '';
|
377 |
+
|
378 |
if ( $where_query ) {
|
379 |
foreach ( $where_query as $colname => $colvalue ) {
|
380 |
$colname = esc_sql( $colname );
|
388 |
if ( ! isset( $colvalue['value'] ) ) {
|
389 |
$colvalue['value'] = $colvalue;
|
390 |
}
|
391 |
+
$compare = esc_sql( $compare );
|
392 |
$where_query_sql .= " AND {$this->table_name}.{$colname} {$compare} ('" . implode( "','", esc_sql( $colvalue['value'] ) ) . "')";
|
393 |
} else {
|
394 |
+
$where_query_sql .= $wpdb->prepare( " AND {$this->table_name}.{$colname} = %s", $colvalue ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
395 |
}
|
396 |
}
|
397 |
}
|
398 |
}
|
399 |
+
|
400 |
+
$where_query_sql = apply_filters( 'rtmedia-get-counts-where-query', $where_query_sql ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
|
401 |
$query = $query . $where_query_sql . ' GROUP BY privacy limit 100';
|
402 |
+
$result = $wpdb->get_results( $query ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
403 |
if ( ! is_array( $result ) ) {
|
404 |
return false;
|
405 |
}
|
408 |
}
|
409 |
|
410 |
/**
|
411 |
+
* Get other album count.
|
412 |
*
|
413 |
+
* @param integer $profile_id Profile id.
|
414 |
+
* @param string $context Context.
|
415 |
*
|
416 |
* @return int
|
417 |
*/
|
418 |
+
public function get_other_album_count( $profile_id, $context = 'profile' ) {
|
419 |
global $wpdb;
|
420 |
+
|
421 |
$global = RTMediaAlbum::get_globals();
|
422 |
+
$sql = $wpdb->prepare( "select distinct album_id from {$this->table_name} where 2=2 AND context = %s ", $context ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
423 |
+
|
424 |
if ( is_multisite() ) {
|
425 |
+
$sql .= $wpdb->prepare( " AND {$this->table_name}.blog_id = %d ", get_current_blog_id() ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
426 |
}
|
427 |
+
|
428 |
if ( is_array( $global ) && count( $global ) > 0 ) {
|
429 |
$sql .= ' and album_id in (';
|
430 |
+
$sep = '';
|
431 |
foreach ( $global as $id ) {
|
432 |
$sql .= $sep . esc_sql( $id );
|
433 |
+
$sep = ',';
|
434 |
}
|
435 |
$sql .= ')';
|
436 |
}
|
437 |
+
|
438 |
if ( 'profile' === $context ) {
|
439 |
$sql .= $wpdb->prepare( ' AND media_author=%d ', $profile_id );
|
440 |
} else {
|
442 |
$sql .= $wpdb->prepare( ' AND context_id=%d ', $profile_id );
|
443 |
}
|
444 |
}
|
445 |
+
|
446 |
+
$sql .= 'limit 100';
|
447 |
+
$result = $wpdb->get_results( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
448 |
+
|
449 |
if ( isset( $result ) ) {
|
450 |
return count( $result );
|
451 |
} else {
|
app/helper/RTMediaNotification.php
CHANGED
@@ -1,23 +1,51 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
|
4 |
-
*
|
5 |
-
*
|
6 |
-
* and open the template in the editor.
|
7 |
*/
|
8 |
|
9 |
/**
|
|
|
10 |
*
|
11 |
* @author Jignesh Nakrani <jignesh.nakrani@rtcamp.com>
|
12 |
*/
|
13 |
class RTMediaNotification {
|
14 |
|
|
|
|
|
|
|
|
|
|
|
15 |
public $component_id;
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
public $component_slug;
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
public $component_callback;
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
public $component_action;
|
19 |
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
foreach ( $args as $key => $val ) {
|
23 |
$this->{$key} = $val;
|
@@ -27,10 +55,11 @@ class RTMediaNotification {
|
|
27 |
}
|
28 |
|
29 |
/**
|
30 |
-
*
|
31 |
-
*
|
|
|
32 |
*/
|
33 |
-
function notifier_setup_globals() {
|
34 |
global $bp;
|
35 |
$component = $this->component_id;
|
36 |
$bp->{$component} = new stdClass();
|
@@ -41,14 +70,15 @@ class RTMediaNotification {
|
|
41 |
}
|
42 |
|
43 |
/**
|
|
|
44 |
*
|
45 |
-
* @param int $post_id
|
46 |
-
* @param int $post_author_id
|
47 |
-
* @param int $user_id
|
48 |
*
|
49 |
* @return int|bool notification id on success or false
|
50 |
*/
|
51 |
-
function add_notification( $post_id, $post_author_id, $user_id ) {
|
52 |
global $rtmedia;
|
53 |
|
54 |
$args_add_noification = array(
|
@@ -68,23 +98,23 @@ class RTMediaNotification {
|
|
68 |
}
|
69 |
|
70 |
/**
|
71 |
-
*
|
72 |
*
|
73 |
-
* @param int $media_id ID of media to mark notification as read
|
74 |
*/
|
75 |
-
function mark_notification_unread( $media_id ) {
|
76 |
$post_id = rtmedia_media_id( $media_id );
|
77 |
$user_id = get_current_user_id();
|
78 |
-
bp_notifications_mark_notifications_by_type( $user_id, $this->component_id, $this->component_action . $post_id,
|
79 |
}
|
80 |
|
81 |
/**
|
82 |
-
*
|
83 |
*
|
84 |
-
* @param int $post_author_id Author of post
|
85 |
-
* @param int $post_id ID of a post to delete related notification
|
86 |
*/
|
87 |
-
function delete_notification_by_item_id( $post_author_id, $post_id ) {
|
88 |
bp_notifications_delete_notifications_by_item_id( $post_author_id, $post_id, $this->component_id, $this->component_action . $post_id );
|
89 |
}
|
90 |
}
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* File for RTMediaNotification class.
|
4 |
+
*
|
5 |
+
* @package rtMedia
|
|
|
6 |
*/
|
7 |
|
8 |
/**
|
9 |
+
* Media Notification class.
|
10 |
*
|
11 |
* @author Jignesh Nakrani <jignesh.nakrani@rtcamp.com>
|
12 |
*/
|
13 |
class RTMediaNotification {
|
14 |
|
15 |
+
/**
|
16 |
+
* Component ID.
|
17 |
+
*
|
18 |
+
* @var $component_id
|
19 |
+
*/
|
20 |
public $component_id;
|
21 |
+
|
22 |
+
/**
|
23 |
+
* Component slug.
|
24 |
+
*
|
25 |
+
* @var string$component_slug
|
26 |
+
*/
|
27 |
public $component_slug;
|
28 |
+
|
29 |
+
/**
|
30 |
+
* Component callback.
|
31 |
+
*
|
32 |
+
* @var string $component_callback
|
33 |
+
*/
|
34 |
public $component_callback;
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Component action.
|
38 |
+
*
|
39 |
+
* @var string $component_action
|
40 |
+
*/
|
41 |
public $component_action;
|
42 |
|
43 |
+
/**
|
44 |
+
* RTMediaNotification constructor.
|
45 |
+
*
|
46 |
+
* @param array $args Arguments.
|
47 |
+
*/
|
48 |
+
public function __construct( $args ) {
|
49 |
|
50 |
foreach ( $args as $key => $val ) {
|
51 |
$this->{$key} = $val;
|
55 |
}
|
56 |
|
57 |
/**
|
58 |
+
* Register a new component for notifications
|
59 |
+
*
|
60 |
+
* @global object $bp
|
61 |
*/
|
62 |
+
public function notifier_setup_globals() {
|
63 |
global $bp;
|
64 |
$component = $this->component_id;
|
65 |
$bp->{$component} = new stdClass();
|
70 |
}
|
71 |
|
72 |
/**
|
73 |
+
* Add notification.
|
74 |
*
|
75 |
+
* @param int $post_id Post Id.
|
76 |
+
* @param int $post_author_id Post author id.
|
77 |
+
* @param int $user_id User id.
|
78 |
*
|
79 |
* @return int|bool notification id on success or false
|
80 |
*/
|
81 |
+
public function add_notification( $post_id, $post_author_id, $user_id ) {
|
82 |
global $rtmedia;
|
83 |
|
84 |
$args_add_noification = array(
|
98 |
}
|
99 |
|
100 |
/**
|
101 |
+
* Mark related notification as read once media is visit by user
|
102 |
*
|
103 |
+
* @param int $media_id ID of media to mark notification as read.
|
104 |
*/
|
105 |
+
public function mark_notification_unread( $media_id ) {
|
106 |
$post_id = rtmedia_media_id( $media_id );
|
107 |
$user_id = get_current_user_id();
|
108 |
+
bp_notifications_mark_notifications_by_type( $user_id, $this->component_id, $this->component_action . $post_id, false );
|
109 |
}
|
110 |
|
111 |
/**
|
112 |
+
* Deletes existing media notification of a particular user
|
113 |
*
|
114 |
+
* @param int $post_author_id Author of post.
|
115 |
+
* @param int $post_id ID of a post to delete related notification.
|
116 |
*/
|
117 |
+
public function delete_notification_by_item_id( $post_author_id, $post_id ) {
|
118 |
bp_notifications_delete_notifications_by_item_id( $post_author_id, $post_id, $this->component_id, $this->component_action . $post_id );
|
119 |
}
|
120 |
}
|
app/helper/RTMediaSettings.php
CHANGED
@@ -1,23 +1,26 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
/**
|
4 |
-
*
|
|
|
|
|
5 |
*
|
6 |
-
* @
|
7 |
-
* @author Joshua Abenazer <joshua.abenazer@rtcamp.com>
|
8 |
*/
|
|
|
9 |
if ( ! class_exists( 'RTMediaSettings' ) ) {
|
10 |
|
|
|
|
|
|
|
11 |
class RTMediaSettings {
|
12 |
|
13 |
/**
|
14 |
* Constructor
|
15 |
*
|
16 |
* @access public
|
17 |
-
* @return void
|
18 |
*/
|
19 |
public function __construct() {
|
20 |
-
//todo: nonce required
|
21 |
if ( ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
|
22 |
add_action( 'admin_init', array( $this, 'settings' ) );
|
23 |
|
@@ -34,8 +37,6 @@ if ( ! class_exists( 'RTMediaSettings' ) ) {
|
|
34 |
* @access public
|
35 |
* @global string 'buddypress-media'
|
36 |
*
|
37 |
-
* @param void
|
38 |
-
*
|
39 |
* @return array $defaults
|
40 |
*/
|
41 |
public function get_default_options() {
|
@@ -43,28 +44,28 @@ if ( ! class_exists( 'RTMediaSettings' ) ) {
|
|
43 |
$options = $rtmedia->options;
|
44 |
|
45 |
$defaults = array(
|
46 |
-
'general_enableAlbums'
|
47 |
-
'general_enableAlbums_description'
|
48 |
-
'general_enableComments'
|
49 |
-
'general_enableGallerysearch'
|
50 |
-
'general_enableLikes'
|
51 |
-
'general_downloadButton'
|
52 |
-
'general_enableLightbox'
|
53 |
-
'general_perPageMedia'
|
54 |
-
'general_display_media'
|
55 |
-
'general_enableMediaEndPoint'
|
56 |
-
'general_showAdminMenu'
|
57 |
-
'general_videothumbs'
|
58 |
-
'general_jpeg_image_quality'
|
59 |
-
'general_uniqueviewcount'
|
60 |
-
'general_viewcount'
|
61 |
-
'general_AllowUserData'
|
62 |
-
'rtmedia_add_linkback'
|
63 |
-
'rtmedia_affiliate_id'
|
64 |
-
'rtmedia_enable_api'
|
65 |
-
'general_masonry_layout'
|
66 |
-
'general_masonry_layout_activity'
|
67 |
-
'general_direct_upload'
|
68 |
);
|
69 |
|
70 |
foreach ( $rtmedia->allowed_types as $type ) {
|
@@ -82,7 +83,7 @@ if ( ! class_exists( 'RTMediaSettings' ) ) {
|
|
82 |
}
|
83 |
}
|
84 |
|
85 |
-
|
86 |
$defaults['privacy_enabled'] = 0;
|
87 |
$defaults['privacy_default'] = 0;
|
88 |
$defaults['privacy_userOverride'] = 0;
|
@@ -98,8 +99,8 @@ if ( ! class_exists( 'RTMediaSettings' ) ) {
|
|
98 |
$defaults['styles_custom'] = '';
|
99 |
$defaults['styles_enabled'] = 1;
|
100 |
|
101 |
-
|
102 |
-
$defaults['rtmedia_disable_media_in_commented_media']
|
103 |
|
104 |
if ( isset( $options['general_videothumbs'] ) && is_numeric( $options['general_videothumbs'] ) && intval( $options['general_videothumbs'] ) > 10 ) {
|
105 |
$defaults['general_videothumbs'] = 10;
|
@@ -109,7 +110,7 @@ if ( ! class_exists( 'RTMediaSettings' ) ) {
|
|
109 |
if ( is_numeric( $options['general_jpeg_image_quality'] ) ) {
|
110 |
if ( $options['general_jpeg_image_quality'] > 100 ) {
|
111 |
$defaults['general_jpeg_image_quality'] = 100;
|
112 |
-
}
|
113 |
$defaults['general_jpeg_image_quality'] = 90;
|
114 |
}
|
115 |
} else {
|
@@ -127,9 +128,9 @@ if ( ! class_exists( 'RTMediaSettings' ) ) {
|
|
127 |
*
|
128 |
* @access public
|
129 |
*
|
130 |
-
* @param
|
131 |
*
|
132 |
-
* @return
|
133 |
*/
|
134 |
public function sanitize_options( $options ) {
|
135 |
$defaults = $this->get_default_options();
|
@@ -143,9 +144,9 @@ if ( ! class_exists( 'RTMediaSettings' ) ) {
|
|
143 |
*
|
144 |
* @access public
|
145 |
*
|
146 |
-
* @param
|
147 |
*
|
148 |
-
* @return
|
149 |
*/
|
150 |
public function sanitize_before_save_options( $options ) {
|
151 |
$defaults = $this->get_default_options();
|
@@ -156,7 +157,7 @@ if ( ! class_exists( 'RTMediaSettings' ) ) {
|
|
156 |
}
|
157 |
}
|
158 |
|
159 |
-
|
160 |
if ( isset( $options['styles_custom'] ) && ! empty( $options['styles_custom'] ) ) {
|
161 |
$css = $options['styles_custom'];
|
162 |
|
@@ -180,16 +181,16 @@ if ( ! class_exists( 'RTMediaSettings' ) ) {
|
|
180 |
$options['general_videothumbs'] = 10;
|
181 |
}
|
182 |
|
183 |
-
// Checking if video_thumbnails value is less then 0
|
184 |
if ( isset( $options['general_videothumbs'] ) && intval( $options['general_videothumbs'] ) <= 0 ) {
|
185 |
$options['general_videothumbs'] = 2;
|
186 |
}
|
187 |
|
188 |
-
// Checking if number of media perpage is integer or not
|
189 |
if ( isset( $options['general_perPageMedia'] ) ) {
|
190 |
if ( intval( $options['general_perPageMedia'] ) < 1 ) {
|
191 |
$options['general_perPageMedia'] = 10;
|
192 |
-
}
|
193 |
$options['general_perPageMedia'] = round( $options['general_perPageMedia'] );
|
194 |
}
|
195 |
}
|
@@ -198,17 +199,16 @@ if ( ! class_exists( 'RTMediaSettings' ) ) {
|
|
198 |
}
|
199 |
|
200 |
/**
|
201 |
-
* rtmedia settings.
|
202 |
*
|
203 |
* @access public
|
204 |
-
* @global BPMediaAddon $rtmedia_addon
|
205 |
*
|
206 |
-
* @
|
207 |
*
|
208 |
* @return void
|
209 |
*/
|
210 |
public function settings() {
|
211 |
-
//todo: nonce required
|
212 |
global $rtmedia, $rtmedia_addon, $rtmedia_save_setting_single;
|
213 |
$options = rtmedia_get_site_option( 'rtmedia-options' );
|
214 |
$options = $this->sanitize_options( $options );
|
@@ -226,14 +226,19 @@ if ( ! class_exists( 'RTMediaSettings' ) ) {
|
|
226 |
flush_rewrite_rules( false );
|
227 |
}
|
228 |
$settings_saved = '';
|
229 |
-
$setting_save
|
230 |
if ( ! isset( $setting_save ) ) {
|
231 |
$settings_saved = '&settings-saved=true';
|
232 |
}
|
233 |
|
234 |
$http_referer = rtm_get_server_var( 'HTTP_REFERER', 'FILTER_SANITIZE_URL' );
|
235 |
if ( isset( $http_referer ) ) {
|
236 |
-
|
|
|
|
|
|
|
|
|
|
|
237 |
}
|
238 |
global $rtmedia;
|
239 |
$rtmedia->options = $options;
|
@@ -241,20 +246,35 @@ if ( ! class_exists( 'RTMediaSettings' ) ) {
|
|
241 |
|
242 |
if ( function_exists( 'add_settings_section' ) ) {
|
243 |
$rtmedia_addon = new RTMediaAddon();
|
244 |
-
add_settings_section(
|
245 |
-
|
246 |
-
'
|
247 |
-
|
|
|
|
|
|
|
|
|
|
|
248 |
$rtmedia_support = new RTMediaSupport( false );
|
249 |
-
add_settings_section(
|
250 |
-
|
251 |
-
'
|
252 |
-
|
|
|
|
|
|
|
|
|
|
|
253 |
$rtmedia_themes = new RTMediaThemes();
|
254 |
-
add_settings_section(
|
255 |
-
|
256 |
-
'
|
257 |
-
|
|
|
|
|
|
|
|
|
|
|
258 |
}
|
259 |
|
260 |
if ( ! isset( $rtmedia_save_setting_single ) ) {
|
@@ -267,8 +287,6 @@ if ( ! class_exists( 'RTMediaSettings' ) ) {
|
|
267 |
*
|
268 |
* @access public
|
269 |
*
|
270 |
-
* @param void
|
271 |
-
*
|
272 |
* @return void
|
273 |
*/
|
274 |
public function network_notices() {
|
@@ -311,8 +329,6 @@ if ( ! class_exists( 'RTMediaSettings' ) ) {
|
|
311 |
*
|
312 |
* @access public
|
313 |
*
|
314 |
-
* @param void
|
315 |
-
*
|
316 |
* @return void
|
317 |
*/
|
318 |
public function allowed_types() {
|
@@ -321,6 +337,7 @@ if ( ! class_exists( 'RTMediaSettings' ) ) {
|
|
321 |
$allowed_types = implode( ', ', $allowed_types );
|
322 |
echo '<span class="description">' .
|
323 |
sprintf(
|
|
|
324 |
esc_html__( 'Currently your network allows uploading of the following file types. You can change the settings %s', 'buddypress-media' ),
|
325 |
'<a href="' . esc_url( network_admin_url( 'settings.php#upload_filetypes' ) ) . '">' . esc_html__( 'here', 'buddypress-media' ) . '</a><br /><code>' . esc_html( $allowed_types ) . '</code>'
|
326 |
) .
|
@@ -331,11 +348,10 @@ if ( ! class_exists( 'RTMediaSettings' ) ) {
|
|
331 |
* Sanitizes the settings
|
332 |
*
|
333 |
* @access public
|
334 |
-
* @global type $rtmedia_admin
|
335 |
*
|
336 |
-
* @param
|
337 |
*
|
338 |
-
* @return
|
339 |
*/
|
340 |
public function sanitize( $input ) {
|
341 |
$rtmedia_options = filter_input( INPUT_POST, 'rtmedia-options', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
|
@@ -359,10 +375,12 @@ if ( ! class_exists( 'RTMediaSettings' ) ) {
|
|
359 |
}
|
360 |
$input['default_count'] = 10;
|
361 |
}
|
|
|
362 |
if ( is_multisite() ) {
|
363 |
rtmedia_update_site_option( 'rtm-settings-saved', esc_html__( 'Settings saved.', 'buddypress-media' ) );
|
364 |
}
|
365 |
-
|
|
|
366 |
|
367 |
return $input;
|
368 |
}
|
@@ -372,18 +390,17 @@ if ( ! class_exists( 'RTMediaSettings' ) ) {
|
|
372 |
*
|
373 |
* @access public
|
374 |
*
|
375 |
-
* @param void
|
376 |
-
*
|
377 |
* @return void
|
378 |
*/
|
379 |
public function image_settings_intro() {
|
380 |
if ( is_plugin_active( 'regenerate-thumbnails/regenerate-thumbnails.php' ) ) {
|
381 |
$regenerate_link = admin_url( '/tools.php?page=regenerate-thumbnails' );
|
382 |
-
}
|
383 |
$regenerate_link = admin_url( '/plugins.php#regenerate-thumbnails' );
|
384 |
} else {
|
385 |
$regenerate_link = wp_nonce_url( admin_url( 'update.php?action=install-plugin&plugin=regenerate-thumbnails' ), 'install-plugin_regenerate-thumbnails' );
|
386 |
}
|
|
|
387 |
echo '<span class="description">' . esc_html__( 'If you make changes to width, height or crop settings, you must use ', 'buddypress-media' ) .
|
388 |
'<a href="' . esc_url( $regenerate_link ) . '">' . esc_html__( 'Regenerate Thumbnail Plugin', 'buddypress-media' ) . '</a>' .
|
389 |
esc_html__( ' to regenerate old images.', 'buddypress-media' ) .
|
@@ -392,13 +409,9 @@ if ( ! class_exists( 'RTMediaSettings' ) ) {
|
|
392 |
}
|
393 |
|
394 |
/**
|
395 |
-
* Output a checkbox for
|
396 |
*
|
397 |
* @access public
|
398 |
-
*
|
399 |
-
* @param void
|
400 |
-
*
|
401 |
-
* @return string $notice
|
402 |
*/
|
403 |
public function privacy_notice() {
|
404 |
if ( current_user_can( 'create_users' ) ) {
|
@@ -415,12 +428,10 @@ if ( ! class_exists( 'RTMediaSettings' ) ) {
|
|
415 |
}
|
416 |
|
417 |
/**
|
418 |
-
* Output
|
419 |
*
|
420 |
* @access public
|
421 |
*
|
422 |
-
* @param void
|
423 |
-
*
|
424 |
* @return void
|
425 |
*/
|
426 |
public function rtmedia_support_intro() {
|
1 |
<?php
|
|
|
2 |
/**
|
3 |
+
* File for handling rtMedia setting/options operations.
|
4 |
+
*
|
5 |
+
* @author Gagandeep Singh <gagandeep.singh@rtcamp.com>, Joshua Abenazer <joshua.abenazer@rtcamp.com>
|
6 |
*
|
7 |
+
* @package rtMedia
|
|
|
8 |
*/
|
9 |
+
|
10 |
if ( ! class_exists( 'RTMediaSettings' ) ) {
|
11 |
|
12 |
+
/**
|
13 |
+
* Class for rtMedia setting/options operations.
|
14 |
+
*/
|
15 |
class RTMediaSettings {
|
16 |
|
17 |
/**
|
18 |
* Constructor
|
19 |
*
|
20 |
* @access public
|
|
|
21 |
*/
|
22 |
public function __construct() {
|
23 |
+
// todo: nonce required.
|
24 |
if ( ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
|
25 |
add_action( 'admin_init', array( $this, 'settings' ) );
|
26 |
|
37 |
* @access public
|
38 |
* @global string 'buddypress-media'
|
39 |
*
|
|
|
|
|
40 |
* @return array $defaults
|
41 |
*/
|
42 |
public function get_default_options() {
|
44 |
$options = $rtmedia->options;
|
45 |
|
46 |
$defaults = array(
|
47 |
+
'general_enableAlbums' => 1,
|
48 |
+
'general_enableAlbums_description' => 0,
|
49 |
+
'general_enableComments' => 0,
|
50 |
+
'general_enableGallerysearch' => 0,
|
51 |
+
'general_enableLikes' => 1,
|
52 |
+
'general_downloadButton' => 0,
|
53 |
+
'general_enableLightbox' => 1,
|
54 |
+
'general_perPageMedia' => 10,
|
55 |
+
'general_display_media' => 'load_more',
|
56 |
+
'general_enableMediaEndPoint' => 0,
|
57 |
+
'general_showAdminMenu' => 0,
|
58 |
+
'general_videothumbs' => 2,
|
59 |
+
'general_jpeg_image_quality' => 90,
|
60 |
+
'general_uniqueviewcount' => 0,
|
61 |
+
'general_viewcount' => 0,
|
62 |
+
'general_AllowUserData' => 0,
|
63 |
+
'rtmedia_add_linkback' => 0,
|
64 |
+
'rtmedia_affiliate_id' => '',
|
65 |
+
'rtmedia_enable_api' => 0,
|
66 |
+
'general_masonry_layout' => 0,
|
67 |
+
'general_masonry_layout_activity' => 0,
|
68 |
+
'general_direct_upload' => 0,
|
69 |
);
|
70 |
|
71 |
foreach ( $rtmedia->allowed_types as $type ) {
|
83 |
}
|
84 |
}
|
85 |
|
86 |
+
// Privacy settings.
|
87 |
$defaults['privacy_enabled'] = 0;
|
88 |
$defaults['privacy_default'] = 0;
|
89 |
$defaults['privacy_userOverride'] = 0;
|
99 |
$defaults['styles_custom'] = '';
|
100 |
$defaults['styles_enabled'] = 1;
|
101 |
|
102 |
+
// default value for add media in comment media.
|
103 |
+
$defaults['rtmedia_disable_media_in_commented_media'] = 1;
|
104 |
|
105 |
if ( isset( $options['general_videothumbs'] ) && is_numeric( $options['general_videothumbs'] ) && intval( $options['general_videothumbs'] ) > 10 ) {
|
106 |
$defaults['general_videothumbs'] = 10;
|
110 |
if ( is_numeric( $options['general_jpeg_image_quality'] ) ) {
|
111 |
if ( $options['general_jpeg_image_quality'] > 100 ) {
|
112 |
$defaults['general_jpeg_image_quality'] = 100;
|
113 |
+
} elseif ( $options['general_jpeg_image_quality'] < 1 ) {
|
114 |
$defaults['general_jpeg_image_quality'] = 90;
|
115 |
}
|
116 |
} else {
|
128 |
*
|
129 |
* @access public
|
130 |
*
|
131 |
+
* @param array $options Options array.
|
132 |
*
|
133 |
+
* @return array $options
|
134 |
*/
|
135 |
public function sanitize_options( $options ) {
|
136 |
$defaults = $this->get_default_options();
|
144 |
*
|
145 |
* @access public
|
146 |
*
|
147 |
+
* @param array $options Options array to save.
|
148 |
*
|
149 |
+
* @return array $options
|
150 |
*/
|
151 |
public function sanitize_before_save_options( $options ) {
|
152 |
$defaults = $this->get_default_options();
|
157 |
}
|
158 |
}
|
159 |
|
160 |
+
// Check if @import is inserted into css or not. If yes then remove that line before save.
|
161 |
if ( isset( $options['styles_custom'] ) && ! empty( $options['styles_custom'] ) ) {
|
162 |
$css = $options['styles_custom'];
|
163 |
|
181 |
$options['general_videothumbs'] = 10;
|
182 |
}
|
183 |
|
184 |
+
// Checking if video_thumbnails value is less then 0.
|
185 |
if ( isset( $options['general_videothumbs'] ) && intval( $options['general_videothumbs'] ) <= 0 ) {
|
186 |
$options['general_videothumbs'] = 2;
|
187 |
}
|
188 |
|
189 |
+
// Checking if number of media perpage is integer or not.
|
190 |
if ( isset( $options['general_perPageMedia'] ) ) {
|
191 |
if ( intval( $options['general_perPageMedia'] ) < 1 ) {
|
192 |
$options['general_perPageMedia'] = 10;
|
193 |
+
} elseif ( ! is_int( $options['general_perPageMedia'] ) ) {
|
194 |
$options['general_perPageMedia'] = round( $options['general_perPageMedia'] );
|
195 |
}
|
196 |
}
|
199 |
}
|
200 |
|
201 |
/**
|
202 |
+
* The rtmedia settings.
|
203 |
*
|
204 |
* @access public
|
|
|
205 |
*
|
206 |
+
* @global BPMediaAddon $rtmedia_addon
|
207 |
*
|
208 |
* @return void
|
209 |
*/
|
210 |
public function settings() {
|
211 |
+
// todo: nonce required.
|
212 |
global $rtmedia, $rtmedia_addon, $rtmedia_save_setting_single;
|
213 |
$options = rtmedia_get_site_option( 'rtmedia-options' );
|
214 |
$options = $this->sanitize_options( $options );
|
226 |
flush_rewrite_rules( false );
|
227 |
}
|
228 |
$settings_saved = '';
|
229 |
+
$setting_save = filter_input( INPUT_GET, 'settings-saved', FILTER_SANITIZE_STRING );
|
230 |
if ( ! isset( $setting_save ) ) {
|
231 |
$settings_saved = '&settings-saved=true';
|
232 |
}
|
233 |
|
234 |
$http_referer = rtm_get_server_var( 'HTTP_REFERER', 'FILTER_SANITIZE_URL' );
|
235 |
if ( isset( $http_referer ) ) {
|
236 |
+
/**
|
237 |
+
* We're not adding exit() here because the functionality is breaking.
|
238 |
+
* I tried moving this code at the end of the function but it's still not working,
|
239 |
+
* maybe there is another function/code which is being executed after this function.
|
240 |
+
*/
|
241 |
+
wp_safe_redirect( $http_referer . $settings_saved );
|
242 |
}
|
243 |
global $rtmedia;
|
244 |
$rtmedia->options = $options;
|
246 |
|
247 |
if ( function_exists( 'add_settings_section' ) ) {
|
248 |
$rtmedia_addon = new RTMediaAddon();
|
249 |
+
add_settings_section(
|
250 |
+
'rtm-addons',
|
251 |
+
esc_html__( 'BuddyPress Media Addons for Photos', 'buddypress-media' ),
|
252 |
+
array(
|
253 |
+
$rtmedia_addon,
|
254 |
+
'get_addons',
|
255 |
+
),
|
256 |
+
'rtmedia-addons'
|
257 |
+
);
|
258 |
$rtmedia_support = new RTMediaSupport( false );
|
259 |
+
add_settings_section(
|
260 |
+
'rtm-support',
|
261 |
+
esc_html__( 'Support', 'buddypress-media' ),
|
262 |
+
array(
|
263 |
+
$rtmedia_support,
|
264 |
+
'get_support_content',
|
265 |
+
),
|
266 |
+
'rtmedia-support'
|
267 |
+
);
|
268 |
$rtmedia_themes = new RTMediaThemes();
|
269 |
+
add_settings_section(
|
270 |
+
'rtm-themes',
|
271 |
+
esc_html__( 'rtMedia Themes', 'buddypress-media' ),
|
272 |
+
array(
|
273 |
+
$rtmedia_themes,
|
274 |
+
'get_themes',
|
275 |
+
),
|
276 |
+
'rtmedia-themes'
|
277 |
+
);
|
278 |
}
|
279 |
|
280 |
if ( ! isset( $rtmedia_save_setting_single ) ) {
|
287 |
*
|
288 |
* @access public
|
289 |
*
|
|
|
|
|
290 |
* @return void
|
291 |
*/
|
292 |
public function network_notices() {
|
329 |
*
|
330 |
* @access public
|
331 |
*
|
|
|
|
|
332 |
* @return void
|
333 |
*/
|
334 |
public function allowed_types() {
|
337 |
$allowed_types = implode( ', ', $allowed_types );
|
338 |
echo '<span class="description">' .
|
339 |
sprintf(
|
340 |
+
// translators: %s: link.
|
341 |
esc_html__( 'Currently your network allows uploading of the following file types. You can change the settings %s', 'buddypress-media' ),
|
342 |
'<a href="' . esc_url( network_admin_url( 'settings.php#upload_filetypes' ) ) . '">' . esc_html__( 'here', 'buddypress-media' ) . '</a><br /><code>' . esc_html( $allowed_types ) . '</code>'
|
343 |
) .
|
348 |
* Sanitizes the settings
|
349 |
*
|
350 |
* @access public
|
|
|
351 |
*
|
352 |
+
* @param array $input Input array to sanitize.
|
353 |
*
|
354 |
+
* @return array $input
|
355 |
*/
|
356 |
public function sanitize( $input ) {
|
357 |
$rtmedia_options = filter_input( INPUT_POST, 'rtmedia-options', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
|
375 |
}
|
376 |
$input['default_count'] = 10;
|
377 |
}
|
378 |
+
|
379 |
if ( is_multisite() ) {
|
380 |
rtmedia_update_site_option( 'rtm-settings-saved', esc_html__( 'Settings saved.', 'buddypress-media' ) );
|
381 |
}
|
382 |
+
|
383 |
+
do_action( 'rtmedia_sanitize_settings', $_POST, $input ); // phpcs:ignore WordPress.Security.NonceVerification.NoNonceVerification
|
384 |
|
385 |
return $input;
|
386 |
}
|
390 |
*
|
391 |
* @access public
|
392 |
*
|
|
|
|
|
393 |
* @return void
|
394 |
*/
|
395 |
public function image_settings_intro() {
|
396 |
if ( is_plugin_active( 'regenerate-thumbnails/regenerate-thumbnails.php' ) ) {
|
397 |
$regenerate_link = admin_url( '/tools.php?page=regenerate-thumbnails' );
|
398 |
+
} elseif ( array_key_exists( 'regenerate-thumbnails/regenerate-thumbnails.php', get_plugins() ) ) {
|
399 |
$regenerate_link = admin_url( '/plugins.php#regenerate-thumbnails' );
|
400 |
} else {
|
401 |
$regenerate_link = wp_nonce_url( admin_url( 'update.php?action=install-plugin&plugin=regenerate-thumbnails' ), 'install-plugin_regenerate-thumbnails' );
|
402 |
}
|
403 |
+
|
404 |
echo '<span class="description">' . esc_html__( 'If you make changes to width, height or crop settings, you must use ', 'buddypress-media' ) .
|
405 |
'<a href="' . esc_url( $regenerate_link ) . '">' . esc_html__( 'Regenerate Thumbnail Plugin', 'buddypress-media' ) . '</a>' .
|
406 |
esc_html__( ' to regenerate old images.', 'buddypress-media' ) .
|
409 |
}
|
410 |
|
411 |
/**
|
412 |
+
* Output a checkbox for privacy notice.
|
413 |
*
|
414 |
* @access public
|
|
|
|
|
|
|
|
|
415 |
*/
|
416 |
public function privacy_notice() {
|
417 |
if ( current_user_can( 'create_users' ) ) {
|
428 |
}
|
429 |
|
430 |
/**
|
431 |
+
* Output rtMedia support.
|
432 |
*
|
433 |
* @access public
|
434 |
*
|
|
|
|
|
435 |
* @return void
|
436 |
*/
|
437 |
public function rtmedia_support_intro() {
|
app/helper/RTMediaSupport.php
CHANGED
@@ -1,27 +1,48 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
-
*
|
4 |
*
|
5 |
-
* @author Gagandeep Singh <gagandeep.singh@rtcamp.com>
|
6 |
-
*
|
|
|
7 |
*/
|
|
|
8 |
if ( ! class_exists( 'RTMediaSupport' ) ) {
|
9 |
|
|
|
|
|
|
|
10 |
class RTMediaSupport {
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
public static $page;
|
16 |
|
17 |
/**
|
18 |
-
* Constructor
|
19 |
*
|
20 |
* @access public
|
21 |
*
|
22 |
-
* @param bool $init
|
23 |
*
|
24 |
-
* @return
|
25 |
*/
|
26 |
public function __construct( $init = true ) {
|
27 |
|
@@ -30,24 +51,25 @@ if ( ! class_exists( 'RTMediaSupport' ) ) {
|
|
30 |
}
|
31 |
|
32 |
$this->curr_sub_tab = 'support';
|
33 |
-
$tab
|
34 |
if ( isset( $tab ) ) {
|
35 |
$this->curr_sub_tab = $tab;
|
36 |
}
|
37 |
|
38 |
-
|
39 |
$nonce = filter_input( INPUT_POST, 'download_debuginfo_wpnonce', FILTER_SANITIZE_STRING );
|
40 |
-
|
|
|
|
|
41 |
if ( empty( $nonce ) || ! wp_verify_nonce( $nonce, 'rtmedia-download-debuginfo' ) ) {
|
42 |
wp_die(
|
43 |
-
'<h1>' . esc_html__( 'Cheatin\' uh?','buddypress-media' ) . '</h1>' .
|
44 |
-
'<p>' . esc_html__( 'Can not verify request source.','buddypress-media' ) . '</p>'
|
45 |
);
|
46 |
} else {
|
47 |
-
|
48 |
$this->download_debuginfo_as_text();
|
49 |
}
|
50 |
-
|
51 |
}
|
52 |
}
|
53 |
|
@@ -56,8 +78,6 @@ if ( ! class_exists( 'RTMediaSupport' ) ) {
|
|
56 |
*
|
57 |
* @access public
|
58 |
*
|
59 |
-
* @param void
|
60 |
-
*
|
61 |
* @return void
|
62 |
*/
|
63 |
public function get_support_content() {
|
@@ -78,7 +98,7 @@ if ( ! class_exists( 'RTMediaSupport' ) ) {
|
|
78 |
'callback' => array( $this, 'debug_info_html' ),
|
79 |
);
|
80 |
|
81 |
-
//if any un-migrated media is there
|
82 |
if ( $this->is_migration_required() ) {
|
83 |
$tabs[] = array(
|
84 |
'title' => esc_html__( 'Migration', 'buddypress-media' ),
|
@@ -94,21 +114,29 @@ if ( ! class_exists( 'RTMediaSupport' ) ) {
|
|
94 |
<?php
|
95 |
}
|
96 |
|
|
|
|
|
|
|
97 |
public function rtmedia_cancel_request() {
|
98 |
-
|
99 |
-
|
100 |
}
|
101 |
|
|
|
|
|
|
|
|
|
|
|
102 |
public function rtmedia_mail_content_type() {
|
103 |
-
|
104 |
}
|
105 |
|
106 |
/**
|
107 |
-
* Render support.
|
108 |
*
|
109 |
* @access public
|
110 |
*
|
111 |
-
* @param
|
112 |
*
|
113 |
* @return void
|
114 |
*/
|
@@ -143,40 +171,44 @@ if ( ! class_exists( 'RTMediaSupport' ) ) {
|
|
143 |
*
|
144 |
* @access public
|
145 |
*
|
146 |
-
* @param void
|
147 |
-
*
|
148 |
* @return void
|
149 |
*/
|
150 |
public function service_selector() {
|
151 |
-
//todo: nonce required
|
152 |
-
$form = filter_input( INPUT_POST, 'form', FILTER_SANITIZE_STRING );
|
|
|
153 |
<div>
|
154 |
<form name="rtmedia_service_select_form" method="post">
|
155 |
<p>
|
156 |
<label class="bp-media-label"
|
157 |
-
|
158 |
<select name="rtmedia_service_select">
|
159 |
<option
|
160 |
-
value="premium_support"
|
|
|
161 |
if ( 'premium_support' === $form ) {
|
162 |
echo 'selected';
|
163 |
}
|
164 |
-
|
|
|
165 |
<option
|
166 |
-
value="bug_report"
|
|
|
167 |
if ( 'bug_report' === $form ) {
|
168 |
echo 'selected';
|
169 |
}
|
170 |
-
|
|
|
171 |
<option
|
172 |
-
value="new_feature"
|
|
|
173 |
if ( 'new_feature' === $form ) {
|
174 |
echo 'selected';
|
175 |
}
|
176 |
-
|
|
|
177 |
</select>
|
178 |
-
<input name="support_submit" value="<?php esc_attr_e( 'Submit', 'buddypress-media' ); ?>"
|
179 |
-
type="submit" class="button"/>
|
180 |
</p>
|
181 |
</form>
|
182 |
</div>
|
@@ -186,9 +218,9 @@ if ( ! class_exists( 'RTMediaSupport' ) ) {
|
|
186 |
/**
|
187 |
* Call rtmedia admin support form.
|
188 |
*
|
189 |
-
* @
|
190 |
*
|
191 |
-
* @
|
192 |
*
|
193 |
* @return void
|
194 |
*/
|
@@ -208,12 +240,10 @@ if ( ! class_exists( 'RTMediaSupport' ) ) {
|
|
208 |
*
|
209 |
* @access public
|
210 |
*
|
211 |
-
* @
|
212 |
-
*
|
213 |
-
* @return array $rtmedia_plugins
|
214 |
*/
|
215 |
public function get_plugin_info() {
|
216 |
-
include_once
|
217 |
$active_plugins = (array) get_option( 'active_plugins', array() );
|
218 |
if ( is_multisite() ) {
|
219 |
$active_plugins = array_merge( $active_plugins, rtmedia_get_site_option( 'active_sitewide_plugins', array() ) );
|
@@ -238,7 +268,7 @@ if ( ! class_exists( 'RTMediaSupport' ) ) {
|
|
238 |
*
|
239 |
* @access public
|
240 |
*
|
241 |
-
* @param string $template_path
|
242 |
*
|
243 |
* @return array $result
|
244 |
*/
|
@@ -251,9 +281,9 @@ if ( ! class_exists( 'RTMediaSupport' ) ) {
|
|
251 |
if ( is_dir( $template_path . DIRECTORY_SEPARATOR . $value ) ) {
|
252 |
$sub_files = $this->rtmedia_scan_template_files( $template_path . DIRECTORY_SEPARATOR . $value );
|
253 |
foreach ( $sub_files as $sub_file ) {
|
254 |
-
$rt_to_dir_paths
|
255 |
-
$rt_to_dir_path
|
256 |
-
$result[]
|
257 |
}
|
258 |
} else {
|
259 |
if ( 'main.php' !== $value ) {
|
@@ -268,12 +298,10 @@ if ( ! class_exists( 'RTMediaSupport' ) ) {
|
|
268 |
}
|
269 |
|
270 |
/**
|
271 |
-
* Show
|
272 |
*
|
273 |
* @access public
|
274 |
*
|
275 |
-
* @param void
|
276 |
-
*
|
277 |
* @return void
|
278 |
*/
|
279 |
public function debug_info() {
|
@@ -289,7 +317,8 @@ if ( ! class_exists( 'RTMediaSupport' ) ) {
|
|
289 |
$debug_info['OS'] = esc_html( PHP_OS );
|
290 |
if ( extension_loaded( 'imagick' ) ) {
|
291 |
$imagickobj = new Imagick();
|
292 |
-
$imagick =
|
|
|
293 |
} else {
|
294 |
$imagick['versionString'] = 'Not Installed';
|
295 |
}
|
@@ -305,21 +334,22 @@ if ( ! class_exists( 'RTMediaSupport' ) ) {
|
|
305 |
$debug_info['[php.ini] memory_limit'] = esc_html( ini_get( 'memory_limit' ) );
|
306 |
$debug_info['Installed Plugins'] = $this->get_plugin_info();
|
307 |
$active_theme = wp_get_theme();
|
308 |
-
$debug_info['Theme Name'] = esc_html( $active_theme->Name );
|
309 |
-
$debug_info['Theme Version'] = esc_html( $active_theme->Version );
|
310 |
$debug_info['Author URL'] = esc_url( $active_theme->{'Author URI'} );
|
311 |
$debug_info['Template Overrides'] = implode( ', <br/>', $this->rtmedia_scan_template_files( RTMEDIA_PATH . '/templates/' ) );
|
312 |
|
313 |
global $wpdb;
|
314 |
-
$
|
315 |
-
$results
|
|
|
316 |
if ( $results ) {
|
317 |
foreach ( $results as $media ) {
|
318 |
$debug_info[ 'Total ' . ucfirst( $media->media_type ) . 's' ] = $media->count;
|
319 |
}
|
320 |
}
|
321 |
|
322 |
-
|
323 |
$rtmedia_options = get_option( 'rtmedia-options' );
|
324 |
if ( is_array( $rtmedia_options ) ) {
|
325 |
foreach ( $rtmedia_options as $option => $value ) {
|
@@ -335,18 +365,18 @@ if ( ! class_exists( 'RTMediaSupport' ) ) {
|
|
335 |
*
|
336 |
* @access public
|
337 |
*
|
338 |
-
* @param
|
339 |
*
|
340 |
* @return void
|
341 |
*/
|
342 |
public function debug_info_html( $page = '' ) {
|
343 |
$this->debug_info();
|
344 |
$allowed_html = array(
|
345 |
-
'a'
|
346 |
'href' => array(),
|
347 |
-
|
348 |
'br' => array(),
|
349 |
-
|
350 |
?>
|
351 |
<div id="debug-info" class="rtm-option-wrapper">
|
352 |
<h3 class="rtm-option-title"><?php esc_html_e( 'Debug Info', 'buddypress-media' ); ?></h3>
|
@@ -359,20 +389,22 @@ if ( ! class_exists( 'RTMediaSupport' ) ) {
|
|
359 |
<tr>
|
360 |
<th scope="row"><?php echo esc_html( $configuration ); ?></th>
|
361 |
<td><?php echo wp_kses( $value, $allowed_html ); ?></td>
|
362 |
-
</tr
|
|
|
363 |
}
|
364 |
}
|
365 |
?>
|
366 |
</tbody>
|
367 |
</table>
|
368 |
<div class="rtm-download-debuginfo">
|
369 |
-
<form action="<?php echo admin_url( 'admin.php?page=rtmedia-support#debug' ); ?>" method="post">
|
370 |
-
<?php wp_nonce_field( 'rtmedia-download-debuginfo','download_debuginfo_wpnonce' ); ?>
|
371 |
<input type="hidden" name="download_debuginfo" id="download_debuginfo" value="1" />
|
372 |
<input type="submit" value="<?php esc_html_e( 'Download Debug Info', 'buddypress-media' ); ?>" class="button button-primary" />
|
373 |
</form>
|
374 |
</div>
|
375 |
-
</div
|
|
|
376 |
}
|
377 |
|
378 |
/**
|
@@ -380,8 +412,6 @@ if ( ! class_exists( 'RTMediaSupport' ) ) {
|
|
380 |
*
|
381 |
* @access public
|
382 |
*
|
383 |
-
* @param void
|
384 |
-
*
|
385 |
* @return bool
|
386 |
*/
|
387 |
public function is_migration_required() {
|
@@ -398,9 +428,7 @@ if ( ! class_exists( 'RTMediaSupport' ) ) {
|
|
398 |
*
|
399 |
* @access public
|
400 |
*
|
401 |
-
* @param
|
402 |
-
*
|
403 |
-
* @return bool
|
404 |
*/
|
405 |
public function migration_html( $page = '' ) {
|
406 |
$pending_rtmedia_migrate = rtmedia_get_site_option( 'rtMigration-pending-count' );
|
@@ -409,7 +437,7 @@ if ( ! class_exists( 'RTMediaSupport' ) ) {
|
|
409 |
$flag = true;
|
410 |
if ( ( false === $pending_rtmedia_migrate || 0 === intval( $pending_rtmedia_migrate ) ) ) {
|
411 |
$content .= esc_html__( 'There is no media found to migrate.', 'buddypress-media' );
|
412 |
-
$flag
|
413 |
}
|
414 |
$content = apply_filters( 'rtmedia_migration_content_filter', $content );
|
415 |
if ( $flag ) {
|
@@ -419,7 +447,7 @@ if ( ! class_exists( 'RTMediaSupport' ) ) {
|
|
419 |
}
|
420 |
?>
|
421 |
<div id="rtmedia-migration-html">
|
422 |
-
<?php echo $content
|
423 |
</div>
|
424 |
<?php
|
425 |
}
|
@@ -427,14 +455,12 @@ if ( ! class_exists( 'RTMediaSupport' ) ) {
|
|
427 |
/**
|
428 |
* Generate rtmedia admin form.
|
429 |
*
|
430 |
-
* @
|
431 |
-
*
|
432 |
-
* @param string $form
|
433 |
*
|
434 |
* @return void
|
435 |
*/
|
436 |
public function get_form( $form = '' ) {
|
437 |
-
//todo: nonce required
|
438 |
if ( empty( $form ) ) {
|
439 |
$form = filter_input( INPUT_POST, 'form' . FILTER_SANITIZE_STRING );
|
440 |
$form = isset( $form ) ? $form : 'premium_support';
|
@@ -454,9 +480,10 @@ if ( ! class_exists( 'RTMediaSupport' ) ) {
|
|
454 |
|
455 |
if ( 'premium_support' === $form ) {
|
456 |
if ( ! has_filter( 'rtmedia_license_tabs' ) && ! has_action( 'rtmedia_addon_license_details' ) ) {
|
457 |
-
$content
|
458 |
$content .= '<p>' .
|
459 |
sprintf(
|
|
|
460 |
esc_html__( 'If your site has some issues due to rtMedia and you want support, feel free to create a support topic on %s', 'buddypress-media' ),
|
461 |
'<a target="_blank" href="https://rtmedia.io/support/">' . esc_html__( 'rtMedia Support Page', 'buddypress-media' ) . '</a>.'
|
462 |
) .
|
@@ -464,18 +491,19 @@ if ( ! class_exists( 'RTMediaSupport' ) ) {
|
|
464 |
|
465 |
$content .= '<p>' .
|
466 |
sprintf(
|
|
|
467 |
esc_html__( 'If you have any suggestions, enhancements or bug reports, then you can open a new issue on %s', 'buddypress-media' ),
|
468 |
'<a target="_blank" href="https://github.com/rtMediaWP/rtmedia/issues/new">' . esc_html__( 'GitHub', 'buddypress-media' ) . '</a>.'
|
469 |
) .
|
470 |
'</p>';
|
471 |
|
472 |
-
echo $content
|
473 |
} else {
|
474 |
-
$website
|
475 |
-
$subject
|
476 |
-
$details
|
477 |
-
$server_addr
|
478 |
-
$remote_addr
|
479 |
$server_software = rtm_get_server_var( 'SERVER_SOFTWARE', 'FILTER_SANITIZE_STRING' );
|
480 |
$http_user_agent = rtm_get_server_var( 'HTTP_USER_AGENT', 'FILTER_SANITIZE_STRING' );
|
481 |
?>
|
@@ -484,7 +512,7 @@ if ( ! class_exists( 'RTMediaSupport' ) ) {
|
|
484 |
|
485 |
<div class="rtm-form-filed clearfix">
|
486 |
<label class="bp-media-label"
|
487 |
-
|
488 |
<input class="bp-media-input" id="name" type="text" name="name" value="" required/>
|
489 |
<span class="rtm-tooltip">
|
490 |
<i class="dashicons dashicons-info"></i>
|
@@ -496,7 +524,7 @@ if ( ! class_exists( 'RTMediaSupport' ) ) {
|
|
496 |
|
497 |
<div class="rtm-form-filed clearfix">
|
498 |
<label class="bp-media-label"
|
499 |
-
|
500 |
<input id="email" class="bp-media-input" type="text" name="email" value="" required/>
|
501 |
<span class="rtm-tooltip">
|
502 |
<i class="dashicons dashicons-info"></i>
|
@@ -508,29 +536,29 @@ if ( ! class_exists( 'RTMediaSupport' ) ) {
|
|
508 |
|
509 |
<div class="rtm-form-filed clearfix">
|
510 |
<label class="bp-media-label"
|
511 |
-
|
512 |
<input id="website" class="bp-media-input" type="text" name="website"
|
513 |
-
|
514 |
-
|
515 |
</div>
|
516 |
|
517 |
<div class="rtm-form-filed clearfix">
|
518 |
<label class="bp-media-label"
|
519 |
-
|
520 |
<input id="subject" class="bp-media-input" type="text" name="subject"
|
521 |
-
|
522 |
-
|
523 |
</div>
|
524 |
|
525 |
<div class="rtm-form-filed clearfix">
|
526 |
<label class="bp-media-label"
|
527 |
-
|
528 |
<textarea id="details" class="bp-media-textarea" name="details"
|
529 |
-
|
530 |
|
531 |
<input type="hidden" name="request_type" value="<?php echo esc_attr( $form ); ?>"/>
|
532 |
<input type="hidden" name="request_id"
|
533 |
-
|
534 |
<input type="hidden" name="server_address" value="<?php echo esc_attr( $server_addr ); ?>"/>
|
535 |
<input type="hidden" name="ip_address" value="<?php echo esc_attr( $remote_addr ); ?>"/>
|
536 |
<input type="hidden" name="server_type" value="<?php echo esc_attr( $server_software ); ?>"/>
|
@@ -540,7 +568,7 @@ if ( ! class_exists( 'RTMediaSupport' ) ) {
|
|
540 |
|
541 |
<div class="rtm-form-filed clearfix">
|
542 |
<label class="bp-media-label"
|
543 |
-
|
544 |
<input id="debuglog" class="bp-media-input" type="file" name="debuglog" />
|
545 |
<span class="rtm-tooltip">
|
546 |
<i class="dashicons dashicons-info"></i>
|
@@ -552,7 +580,7 @@ if ( ! class_exists( 'RTMediaSupport' ) ) {
|
|
552 |
</div><!-- .submit-bug-box -->
|
553 |
|
554 |
<div class="rtm-form-filed rtm-button-wrapper clearfix">
|
555 |
-
<?php wp_nonce_field( 'rtmedia-support-request','support_wpnonce' ); ?>
|
556 |
<?php submit_button( 'Submit', 'primary', 'rtmedia-submit-request', false ); ?>
|
557 |
<?php submit_button( 'Cancel', 'secondary', 'cancel-request', false ); ?>
|
558 |
</div>
|
@@ -565,18 +593,14 @@ if ( ! class_exists( 'RTMediaSupport' ) ) {
|
|
565 |
/**
|
566 |
* Now submit request.
|
567 |
*
|
568 |
-
* @global type $rtmedia
|
569 |
-
*
|
570 |
-
* @param void
|
571 |
-
*
|
572 |
* @return void
|
573 |
*/
|
574 |
public function submit_request() {
|
575 |
$nonce = filter_input( INPUT_POST, 'support_wpnonce', FILTER_SANITIZE_STRING );
|
576 |
if ( empty( $nonce ) || ! wp_verify_nonce( $nonce, 'rtmedia-support-request' ) ) {
|
577 |
wp_die(
|
578 |
-
'<h1>' . esc_html__( 'Cheatin\' uh?','buddypress-media' ) . '</h1>' .
|
579 |
-
'<p>' . esc_html__( 'Can not verify request source.','buddypress-media' ) . '</p>'
|
580 |
);
|
581 |
}
|
582 |
|
@@ -592,10 +616,10 @@ if ( ! class_exists( 'RTMediaSupport' ) ) {
|
|
592 |
if ( 'premium_support' === sanitize_text_field( $form_data['request_type'] ) ) {
|
593 |
$mail_type = 'Premium Support';
|
594 |
$title = esc_html__( 'rtMedia Premium Support Request from', 'buddypress-media' );
|
595 |
-
}
|
596 |
$mail_type = 'New Feature Request';
|
597 |
$title = esc_html__( 'rtMedia New Feature Request from', 'buddypress-media' );
|
598 |
-
}
|
599 |
$mail_type = 'Bug Report';
|
600 |
$title = esc_html__( 'rtMedia Bug Report from', 'buddypress-media' );
|
601 |
} else {
|
@@ -604,55 +628,55 @@ if ( ! class_exists( 'RTMediaSupport' ) ) {
|
|
604 |
}
|
605 |
$message = '<html>
|
606 |
<head>
|
607 |
-
<title>' .
|
608 |
</head>
|
609 |
<body>
|
610 |
<table>
|
611 |
<tr>
|
612 |
-
<td>Name</td><td>' .
|
613 |
</tr>
|
614 |
<tr>
|
615 |
-
<td>Email</td><td>' .
|
616 |
</tr>
|
617 |
<tr>
|
618 |
-
<td>Website</td><td>' .
|
619 |
</tr>
|
620 |
<tr>
|
621 |
-
<td>Subject</td><td>' .
|
622 |
</tr>
|
623 |
<tr>
|
624 |
-
<td>Details</td><td>' .
|
625 |
</tr>
|
626 |
<tr>
|
627 |
-
<td>Request ID</td><td>' .
|
628 |
</tr>
|
629 |
<tr>
|
630 |
-
<td>Server Address</td><td>' .
|
631 |
</tr>
|
632 |
<tr>
|
633 |
-
<td>IP Address</td><td>' .
|
634 |
</tr>
|
635 |
<tr>
|
636 |
-
<td>Server Type</td><td>' .
|
637 |
</tr>
|
638 |
<tr>
|
639 |
-
<td>User Agent</td><td>' .
|
640 |
</tr>';
|
641 |
if ( 'bug_report' === sanitize_text_field( $form_data['request_type'] ) ) {
|
642 |
$message .= '<tr>
|
643 |
-
<td>WordPress Admin Username</td><td>' .
|
644 |
</tr>
|
645 |
<tr>
|
646 |
-
<td>WordPress Admin Password</td><td>' .
|
647 |
</tr>
|
648 |
<tr>
|
649 |
-
<td>SSH FTP Host</td><td>' .
|
650 |
</tr>
|
651 |
<tr>
|
652 |
-
<td>SSH FTP Username</td><td>' .
|
653 |
</tr>
|
654 |
<tr>
|
655 |
-
<td>SSH FTP Password</td><td>' .
|
656 |
</tr>
|
657 |
';
|
658 |
}
|
@@ -663,17 +687,27 @@ if ( ! class_exists( 'RTMediaSupport' ) ) {
|
|
663 |
add_filter( 'wp_mail_content_type', array( $this, 'rtmedia_mail_content_type' ) );
|
664 |
|
665 |
$debuglog_temp_path = sanitize_text_field( $form_data['debuglog_temp_path'] );
|
666 |
-
|
667 |
-
$attachment_file = ( ! empty( $debuglog_temp_path ) ) ? $debuglog_temp_path : ''
|
668 |
-
$attachments
|
669 |
|
670 |
$headers = 'From: ' . $form_data['name'] . ' <' . $form_data['email'] . '>' . "\r\n";
|
671 |
$support_email = 'support@rtcamp.com';
|
672 |
-
if ( wp_mail(
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
677 |
if ( ! empty( $attachment_file ) ) {
|
678 |
unlink( $attachment_file );
|
679 |
}
|
@@ -691,6 +725,7 @@ if ( ! class_exists( 'RTMediaSupport' ) ) {
|
|
691 |
echo '<p>' . esc_html__( 'Kindly contact your server support to fix this.', 'buddypress-media' ) . '</p>';
|
692 |
echo '<p>' .
|
693 |
sprintf(
|
|
|
694 |
esc_html__( 'You can alternatively create a support request %s', 'buddypress-media' ),
|
695 |
'<a target="_blank" href="https://rtmedia.io/premium-support/">' . esc_html__( 'here', 'buddypress-media' ) . '</a>.'
|
696 |
) .
|
@@ -703,27 +738,28 @@ if ( ! class_exists( 'RTMediaSupport' ) ) {
|
|
703 |
/**
|
704 |
* Write debug info as a text file and download it.
|
705 |
*
|
706 |
-
* @param void
|
707 |
-
*
|
708 |
* @return void
|
709 |
*/
|
710 |
public function download_debuginfo_as_text() {
|
711 |
|
712 |
-
header('Content-disposition: attachment; filename=debuginfo.txt');
|
713 |
-
header('Content-type: text/plain');
|
|
|
714 |
global $wpdb, $wp_version, $bp;
|
715 |
-
|
716 |
-
$debug_info
|
717 |
-
$debug_info['
|
718 |
-
$debug_info['
|
719 |
-
$debug_info['
|
720 |
-
$debug_info['
|
|
|
721 |
$debug_info['BuddyPress'] = esc_html( ( isset( $bp->version ) ) ? $bp->version : '-NA-' );
|
722 |
-
$debug_info['rtMedia']
|
723 |
-
$debug_info['OS']
|
724 |
if ( extension_loaded( 'imagick' ) ) {
|
725 |
$imagickobj = new Imagick();
|
726 |
-
$imagick =
|
|
|
727 |
} else {
|
728 |
$imagick['versionString'] = 'Not Installed';
|
729 |
}
|
@@ -733,30 +769,30 @@ if ( ! class_exists( 'RTMediaSupport' ) ) {
|
|
733 |
} else {
|
734 |
$gd['GD Version'] = 'Not Installed';
|
735 |
}
|
736 |
-
$debug_info['GD']
|
737 |
-
$debug_info['[php.ini] post_max_size']
|
738 |
$debug_info['[php.ini] upload_max_filesize'] = esc_html( ini_get( 'upload_max_filesize' ) );
|
739 |
-
$debug_info['[php.ini] memory_limit']
|
740 |
-
$plugin_info
|
741 |
-
$debug_info['Installed Plugins']
|
742 |
-
$active_theme
|
743 |
-
$debug_info['Theme Name']
|
744 |
-
$debug_info['Theme Version']
|
745 |
-
$debug_info['Author URL']
|
746 |
-
$debug_info['Template Overrides']
|
747 |
-
$rtmedia_options
|
748 |
-
$rtmedia_options
|
749 |
-
|
750 |
-
if( ! empty( $rtmedia_options ) ) {
|
751 |
echo '==============================================================================' . PHP_EOL;
|
752 |
echo '================================== Debug Info ================================' . PHP_EOL;
|
753 |
echo '==============================================================================' . PHP_EOL . PHP_EOL . PHP_EOL;
|
754 |
|
755 |
foreach ( $rtmedia_options as $option => $value ) {
|
756 |
-
echo ucwords( str_replace( '_', ' ', $option ) ) . str_repeat( ' ', 50 - strlen($option) ) . wp_strip_all_tags( $value ) . PHP_EOL;
|
757 |
}
|
758 |
|
759 |
-
readfile(
|
760 |
exit();
|
761 |
}
|
762 |
|
1 |
<?php
|
2 |
/**
|
3 |
+
* Handles rtMedia support
|
4 |
*
|
5 |
+
* @author Gagandeep Singh <gagandeep.singh@rtcamp.com>, Joshua Abenazer <joshua.abenazer@rtcamp.com>
|
6 |
+
*
|
7 |
+
* @package rtMedia
|
8 |
*/
|
9 |
+
|
10 |
if ( ! class_exists( 'RTMediaSupport' ) ) {
|
11 |
|
12 |
+
/**
|
13 |
+
* Class to handle rtMedia support.
|
14 |
+
*/
|
15 |
class RTMediaSupport {
|
16 |
|
17 |
+
/**
|
18 |
+
* Debug info.
|
19 |
+
*
|
20 |
+
* @var $debug_info
|
21 |
+
*/
|
22 |
+
public $debug_info;
|
23 |
+
|
24 |
+
/**
|
25 |
+
* Current sub tab.
|
26 |
+
*
|
27 |
+
* @var mixed
|
28 |
+
*/
|
29 |
+
public $curr_sub_tab;
|
30 |
+
|
31 |
+
/**
|
32 |
+
* Current page
|
33 |
+
*
|
34 |
+
* @var string
|
35 |
+
*/
|
36 |
public static $page;
|
37 |
|
38 |
/**
|
39 |
+
* RTMediaSupport Constructor
|
40 |
*
|
41 |
* @access public
|
42 |
*
|
43 |
+
* @param bool $init init.
|
44 |
*
|
45 |
+
* @return mixed
|
46 |
*/
|
47 |
public function __construct( $init = true ) {
|
48 |
|
51 |
}
|
52 |
|
53 |
$this->curr_sub_tab = 'support';
|
54 |
+
$tab = filter_input( INPUT_GET, 'tab', FILTER_SANITIZE_STRING );
|
55 |
if ( isset( $tab ) ) {
|
56 |
$this->curr_sub_tab = $tab;
|
57 |
}
|
58 |
|
59 |
+
// Check if download debug info request is made or not.
|
60 |
$nonce = filter_input( INPUT_POST, 'download_debuginfo_wpnonce', FILTER_SANITIZE_STRING );
|
61 |
+
$info = filter_input( INPUT_POST, 'download_debuginfo', FILTER_SANITIZE_STRING );
|
62 |
+
|
63 |
+
if ( isset( $info ) && '1' === $info && is_admin() ) {
|
64 |
if ( empty( $nonce ) || ! wp_verify_nonce( $nonce, 'rtmedia-download-debuginfo' ) ) {
|
65 |
wp_die(
|
66 |
+
'<h1>' . esc_html__( 'Cheatin\' uh?', 'buddypress-media' ) . '</h1>' .
|
67 |
+
'<p>' . esc_html__( 'Can not verify request source.', 'buddypress-media' ) . '</p>'
|
68 |
);
|
69 |
} else {
|
70 |
+
// download the debug info.
|
71 |
$this->download_debuginfo_as_text();
|
72 |
}
|
|
|
73 |
}
|
74 |
}
|
75 |
|
78 |
*
|
79 |
* @access public
|
80 |
*
|
|
|
|
|
81 |
* @return void
|
82 |
*/
|
83 |
public function get_support_content() {
|
98 |
'callback' => array( $this, 'debug_info_html' ),
|
99 |
);
|
100 |
|
101 |
+
// if any un-migrated media is there.
|
102 |
if ( $this->is_migration_required() ) {
|
103 |
$tabs[] = array(
|
104 |
'title' => esc_html__( 'Migration', 'buddypress-media' ),
|
114 |
<?php
|
115 |
}
|
116 |
|
117 |
+
/**
|
118 |
+
* Cancel request.
|
119 |
+
*/
|
120 |
public function rtmedia_cancel_request() {
|
121 |
+
do_settings_sections( 'rtmedia-support' );
|
122 |
+
die();
|
123 |
}
|
124 |
|
125 |
+
/**
|
126 |
+
* Mail content type.
|
127 |
+
*
|
128 |
+
* @return string
|
129 |
+
*/
|
130 |
public function rtmedia_mail_content_type() {
|
131 |
+
return 'text/html';
|
132 |
}
|
133 |
|
134 |
/**
|
135 |
+
* Render support page.
|
136 |
*
|
137 |
* @access public
|
138 |
*
|
139 |
+
* @param string $page Page name.
|
140 |
*
|
141 |
* @return void
|
142 |
*/
|
171 |
*
|
172 |
* @access public
|
173 |
*
|
|
|
|
|
174 |
* @return void
|
175 |
*/
|
176 |
public function service_selector() {
|
177 |
+
// todo: nonce required.
|
178 |
+
$form = filter_input( INPUT_POST, 'form', FILTER_SANITIZE_STRING );
|
179 |
+
?>
|
180 |
<div>
|
181 |
<form name="rtmedia_service_select_form" method="post">
|
182 |
<p>
|
183 |
<label class="bp-media-label"
|
184 |
+
for="select_support"><?php esc_html_e( 'Service', 'buddypress-media' ); ?>:</label>
|
185 |
<select name="rtmedia_service_select">
|
186 |
<option
|
187 |
+
value="premium_support"
|
188 |
+
<?php
|
189 |
if ( 'premium_support' === $form ) {
|
190 |
echo 'selected';
|
191 |
}
|
192 |
+
?>
|
193 |
+
><?php esc_html_e( 'Premium Support', 'buddypress-media' ); ?></option>
|
194 |
<option
|
195 |
+
value="bug_report"
|
196 |
+
<?php
|
197 |
if ( 'bug_report' === $form ) {
|
198 |
echo 'selected';
|
199 |
}
|
200 |
+
?>
|
201 |
+
><?php esc_html_e( 'Bug Report', 'buddypress-media' ); ?></option>
|
202 |
<option
|
203 |
+
value="new_feature"
|
204 |
+
<?php
|
205 |
if ( 'new_feature' === $form ) {
|
206 |
echo 'selected';
|
207 |
}
|
208 |
+
?>
|
209 |
+
><?php esc_html_e( 'New Feature', 'buddypress-media' ); ?></option>
|
210 |
</select>
|
211 |
+
<input name="support_submit" value="<?php esc_attr_e( 'Submit', 'buddypress-media' ); ?>" type="submit" class="button"/>
|
|
|
212 |
</p>
|
213 |
</form>
|
214 |
</div>
|
218 |
/**
|
219 |
* Call rtmedia admin support form.
|
220 |
*
|
221 |
+
* @param string $page Page.
|
222 |
*
|
223 |
+
* @access public
|
224 |
*
|
225 |
* @return void
|
226 |
*/
|
240 |
*
|
241 |
* @access public
|
242 |
*
|
243 |
+
* @return array|bool $rtmedia_plugins
|
|
|
|
|
244 |
*/
|
245 |
public function get_plugin_info() {
|
246 |
+
include_once ABSPATH . '/wp-admin/includes/plugin.php';
|
247 |
$active_plugins = (array) get_option( 'active_plugins', array() );
|
248 |
if ( is_multisite() ) {
|
249 |
$active_plugins = array_merge( $active_plugins, rtmedia_get_site_option( 'active_sitewide_plugins', array() ) );
|
268 |
*
|
269 |
* @access public
|
270 |
*
|
271 |
+
* @param string $template_path Template path.
|
272 |
*
|
273 |
* @return array $result
|
274 |
*/
|
281 |
if ( is_dir( $template_path . DIRECTORY_SEPARATOR . $value ) ) {
|
282 |
$sub_files = $this->rtmedia_scan_template_files( $template_path . DIRECTORY_SEPARATOR . $value );
|
283 |
foreach ( $sub_files as $sub_file ) {
|
284 |
+
$rt_to_dir_paths = RTMediaTemplate::locate_template( str_replace( '.php', '', $sub_file ) );
|
285 |
+
$rt_to_dir_path = str_replace( '//', '/', $rt_to_dir_paths );
|
286 |
+
$result[] = str_replace( ABSPATH . 'wp-content/', '', $rt_to_dir_path );
|
287 |
}
|
288 |
} else {
|
289 |
if ( 'main.php' !== $value ) {
|
298 |
}
|
299 |
|
300 |
/**
|
301 |
+
* Show debug info.
|
302 |
*
|
303 |
* @access public
|
304 |
*
|
|
|
|
|
305 |
* @return void
|
306 |
*/
|
307 |
public function debug_info() {
|
317 |
$debug_info['OS'] = esc_html( PHP_OS );
|
318 |
if ( extension_loaded( 'imagick' ) ) {
|
319 |
$imagickobj = new Imagick();
|
320 |
+
$imagick = preg_replace( " #((http|https|ftp)://(\S*?\.\S*?))(\s|\;|\)|\]|\[|\{|\}|,|\"|'|:|\<|$|\.\s)#i", "'<a href=\"$1\" target=\"_blank\">$3</a>$4'", $imagickobj->getversion() );
|
321 |
+
$message = $imagick;
|
322 |
} else {
|
323 |
$imagick['versionString'] = 'Not Installed';
|
324 |
}
|
334 |
$debug_info['[php.ini] memory_limit'] = esc_html( ini_get( 'memory_limit' ) );
|
335 |
$debug_info['Installed Plugins'] = $this->get_plugin_info();
|
336 |
$active_theme = wp_get_theme();
|
337 |
+
$debug_info['Theme Name'] = esc_html( $active_theme->Name ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.NotSnakeCaseMemberVar
|
338 |
+
$debug_info['Theme Version'] = esc_html( $active_theme->Version ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.NotSnakeCaseMemberVar
|
339 |
$debug_info['Author URL'] = esc_url( $active_theme->{'Author URI'} );
|
340 |
$debug_info['Template Overrides'] = implode( ', <br/>', $this->rtmedia_scan_template_files( RTMEDIA_PATH . '/templates/' ) );
|
341 |
|
342 |
global $wpdb;
|
343 |
+
$rtmedia_model = new RTMediaModel();
|
344 |
+
$results = $wpdb->get_results( $wpdb->prepare( "select media_type, count(id) as count from {$rtmedia_model->table_name} where blog_id = %d group by media_type limit 100", get_current_blog_id() ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
345 |
+
|
346 |
if ( $results ) {
|
347 |
foreach ( $results as $media ) {
|
348 |
$debug_info[ 'Total ' . ucfirst( $media->media_type ) . 's' ] = $media->count;
|
349 |
}
|
350 |
}
|
351 |
|
352 |
+
// get all rtMedia Settings.
|
353 |
$rtmedia_options = get_option( 'rtmedia-options' );
|
354 |
if ( is_array( $rtmedia_options ) ) {
|
355 |
foreach ( $rtmedia_options as $option => $value ) {
|
365 |
*
|
366 |
* @access public
|
367 |
*
|
368 |
+
* @param string $page Page name.
|
369 |
*
|
370 |
* @return void
|
371 |
*/
|
372 |
public function debug_info_html( $page = '' ) {
|
373 |
$this->debug_info();
|
374 |
$allowed_html = array(
|
375 |
+
'a' => array(
|
376 |
'href' => array(),
|
377 |
+
),
|
378 |
'br' => array(),
|
379 |
+
);
|
380 |
?>
|
381 |
<div id="debug-info" class="rtm-option-wrapper">
|
382 |
<h3 class="rtm-option-title"><?php esc_html_e( 'Debug Info', 'buddypress-media' ); ?></h3>
|
389 |
<tr>
|
390 |
<th scope="row"><?php echo esc_html( $configuration ); ?></th>
|
391 |
<td><?php echo wp_kses( $value, $allowed_html ); ?></td>
|
392 |
+
</tr>
|
393 |
+
<?php
|
394 |
}
|
395 |
}
|
396 |
?>
|
397 |
</tbody>
|
398 |
</table>
|
399 |
<div class="rtm-download-debuginfo">
|
400 |
+
<form action="<?php echo esc_url( admin_url( 'admin.php?page=rtmedia-support#debug' ) ); ?>" method="post">
|
401 |
+
<?php wp_nonce_field( 'rtmedia-download-debuginfo', 'download_debuginfo_wpnonce' ); ?>
|
402 |
<input type="hidden" name="download_debuginfo" id="download_debuginfo" value="1" />
|
403 |
<input type="submit" value="<?php esc_html_e( 'Download Debug Info', 'buddypress-media' ); ?>" class="button button-primary" />
|
404 |
</form>
|
405 |
</div>
|
406 |
+
</div>
|
407 |
+
<?php
|
408 |
}
|
409 |
|
410 |
/**
|
412 |
*
|
413 |
* @access public
|
414 |
*
|
|
|
|
|
415 |
* @return bool
|
416 |
*/
|
417 |
public function is_migration_required() {
|
428 |
*
|
429 |
* @access public
|
430 |
*
|
431 |
+
* @param string $page Page.
|
|
|
|
|
432 |
*/
|
433 |
public function migration_html( $page = '' ) {
|
434 |
$pending_rtmedia_migrate = rtmedia_get_site_option( 'rtMigration-pending-count' );
|
437 |
$flag = true;
|
438 |
if ( ( false === $pending_rtmedia_migrate || 0 === intval( $pending_rtmedia_migrate ) ) ) {
|
439 |
$content .= esc_html__( 'There is no media found to migrate.', 'buddypress-media' );
|
440 |
+
$flag = false;
|
441 |
}
|
442 |
$content = apply_filters( 'rtmedia_migration_content_filter', $content );
|
443 |
if ( $flag ) {
|
447 |
}
|
448 |
?>
|
449 |
<div id="rtmedia-migration-html">
|
450 |
+
<?php echo wp_kses( $content, RTMedia::expanded_allowed_tags() ); ?>
|
451 |
</div>
|
452 |
<?php
|
453 |
}
|
455 |
/**
|
456 |
* Generate rtmedia admin form.
|
457 |
*
|
458 |
+
* @param string $form From.
|
|
|
|
|
459 |
*
|
460 |
* @return void
|
461 |
*/
|
462 |
public function get_form( $form = '' ) {
|
463 |
+
// todo: nonce required.
|
464 |
if ( empty( $form ) ) {
|
465 |
$form = filter_input( INPUT_POST, 'form' . FILTER_SANITIZE_STRING );
|
466 |
$form = isset( $form ) ? $form : 'premium_support';
|
480 |
|
481 |
if ( 'premium_support' === $form ) {
|
482 |
if ( ! has_filter( 'rtmedia_license_tabs' ) && ! has_action( 'rtmedia_addon_license_details' ) ) {
|
483 |
+
$content = '<h3 class="rtm-option-title">' . esc_html( $meta_title ) . '</h3>';
|
484 |
$content .= '<p>' .
|
485 |
sprintf(
|
486 |
+
// translators: %s: link.
|
487 |
esc_html__( 'If your site has some issues due to rtMedia and you want support, feel free to create a support topic on %s', 'buddypress-media' ),
|
488 |
'<a target="_blank" href="https://rtmedia.io/support/">' . esc_html__( 'rtMedia Support Page', 'buddypress-media' ) . '</a>.'
|
489 |
) .
|
491 |
|
492 |
$content .= '<p>' .
|
493 |
sprintf(
|
494 |
+
// translators: %s: Github link.
|
495 |
esc_html__( 'If you have any suggestions, enhancements or bug reports, then you can open a new issue on %s', 'buddypress-media' ),
|
496 |
'<a target="_blank" href="https://github.com/rtMediaWP/rtmedia/issues/new">' . esc_html__( 'GitHub', 'buddypress-media' ) . '</a>.'
|
497 |
) .
|
498 |
'</p>';
|
499 |
|
500 |
+
echo wp_kses( $content, RTMedia::expanded_allowed_tags() );
|
501 |
} else {
|
502 |
+
$website = filter_input( INPUT_POST, 'website', FILTER_SANITIZE_URL );
|
503 |
+
$subject = filter_input( INPUT_POST, 'subject', FILTER_SANITIZE_STRING );
|
504 |
+
$details = filter_input( INPUT_POST, 'details', FILTER_SANITIZE_STRING );
|
505 |
+
$server_addr = rtm_get_server_var( 'SERVER_ADDR', 'FILTER_VALIDATE_IP' );
|
506 |
+
$remote_addr = rtm_get_server_var( 'REMOTE_ADDR', 'FILTER_VALIDATE_IP' );
|
507 |
$server_software = rtm_get_server_var( 'SERVER_SOFTWARE', 'FILTER_SANITIZE_STRING' );
|
508 |
$http_user_agent = rtm_get_server_var( 'HTTP_USER_AGENT', 'FILTER_SANITIZE_STRING' );
|
509 |
?>
|
512 |
|
513 |
<div class="rtm-form-filed clearfix">
|
514 |
<label class="bp-media-label"
|
515 |
+
for="name"><?php esc_html_e( 'Name', 'buddypress-media' ); ?></label>
|
516 |
<input class="bp-media-input" id="name" type="text" name="name" value="" required/>
|
517 |
<span class="rtm-tooltip">
|
518 |
<i class="dashicons dashicons-info"></i>
|
524 |
|
525 |
<div class="rtm-form-filed clearfix">
|
526 |
<label class="bp-media-label"
|
527 |
+
for="email"><?php esc_html_e( 'Email', 'buddypress-media' ); ?></label>
|
528 |
<input id="email" class="bp-media-input" type="text" name="email" value="" required/>
|
529 |
<span class="rtm-tooltip">
|
530 |
<i class="dashicons dashicons-info"></i>
|
536 |
|
537 |
<div class="rtm-form-filed clearfix">
|
538 |
<label class="bp-media-label"
|
539 |
+
for="website"><?php esc_html_e( 'Website', 'buddypress-media' ); ?></label>
|
540 |
<input id="website" class="bp-media-input" type="text" name="website"
|
541 |
+
value="<?php echo esc_url( isset( $website ) ? $website : get_bloginfo( 'url' ) ); ?>"
|
542 |
+
required/>
|
543 |
</div>
|
544 |
|
545 |
<div class="rtm-form-filed clearfix">
|
546 |
<label class="bp-media-label"
|
547 |
+
for="subject"><?php esc_html_e( 'Subject', 'buddypress-media' ); ?></label>
|
548 |
<input id="subject" class="bp-media-input" type="text" name="subject"
|
549 |
+
value="<?php echo esc_attr( isset( $subject ) ? esc_attr( $subject ) : '' ); ?>"
|
550 |
+
required/>
|
551 |
</div>
|
552 |
|
553 |
<div class="rtm-form-filed clearfix">
|
554 |
<label class="bp-media-label"
|
555 |
+
for="details"><?php esc_html_e( 'Details', 'buddypress-media' ); ?></label>
|
556 |
<textarea id="details" class="bp-media-textarea" name="details"
|
557 |
+
required><?php echo esc_html( isset( $details ) ? esc_textarea( $details ) : '' ); ?></textarea>
|
558 |
|
559 |
<input type="hidden" name="request_type" value="<?php echo esc_attr( $form ); ?>"/>
|
560 |
<input type="hidden" name="request_id"
|
561 |
+
value="<?php echo esc_attr( wp_create_nonce( date( 'YmdHis' ) ) ); ?>"/>
|
562 |
<input type="hidden" name="server_address" value="<?php echo esc_attr( $server_addr ); ?>"/>
|
563 |
<input type="hidden" name="ip_address" value="<?php echo esc_attr( $remote_addr ); ?>"/>
|
564 |
<input type="hidden" name="server_type" value="<?php echo esc_attr( $server_software ); ?>"/>
|
568 |
|
569 |
<div class="rtm-form-filed clearfix">
|
570 |
<label class="bp-media-label"
|
571 |
+
for="subject"><?php esc_html_e( 'Attachment', 'buddypress-media' ); ?></label>
|
572 |
<input id="debuglog" class="bp-media-input" type="file" name="debuglog" />
|
573 |
<span class="rtm-tooltip">
|
574 |
<i class="dashicons dashicons-info"></i>
|
580 |
</div><!-- .submit-bug-box -->
|
581 |
|
582 |
<div class="rtm-form-filed rtm-button-wrapper clearfix">
|
583 |
+
<?php wp_nonce_field( 'rtmedia-support-request', 'support_wpnonce' ); ?>
|
584 |
<?php submit_button( 'Submit', 'primary', 'rtmedia-submit-request', false ); ?>
|
585 |
<?php submit_button( 'Cancel', 'secondary', 'cancel-request', false ); ?>
|
586 |
</div>
|
593 |
/**
|
594 |
* Now submit request.
|
595 |
*
|
|
|
|
|
|
|
|
|
596 |
* @return void
|
597 |
*/
|
598 |
public function submit_request() {
|
599 |
$nonce = filter_input( INPUT_POST, 'support_wpnonce', FILTER_SANITIZE_STRING );
|
600 |
if ( empty( $nonce ) || ! wp_verify_nonce( $nonce, 'rtmedia-support-request' ) ) {
|
601 |
wp_die(
|
602 |
+
'<h1>' . esc_html__( 'Cheatin\' uh?', 'buddypress-media' ) . '</h1>' .
|
603 |
+
'<p>' . esc_html__( 'Can not verify request source.', 'buddypress-media' ) . '</p>'
|
604 |
);
|
605 |
}
|
606 |
|
616 |
if ( 'premium_support' === sanitize_text_field( $form_data['request_type'] ) ) {
|
617 |
$mail_type = 'Premium Support';
|
618 |
$title = esc_html__( 'rtMedia Premium Support Request from', 'buddypress-media' );
|
619 |
+
} elseif ( 'new_feature' === sanitize_text_field( $form_data['request_type'] ) ) {
|
620 |
$mail_type = 'New Feature Request';
|
621 |
$title = esc_html__( 'rtMedia New Feature Request from', 'buddypress-media' );
|
622 |
+
} elseif ( 'bug_report' === sanitize_text_field( $form_data['request_type'] ) ) {
|
623 |
$mail_type = 'Bug Report';
|
624 |
$title = esc_html__( 'rtMedia Bug Report from', 'buddypress-media' );
|
625 |
} else {
|
628 |
}
|
629 |
$message = '<html>
|
630 |
<head>
|
631 |
+
<title>' . wp_strip_all_tags( $title . get_bloginfo( 'name' ) ) . '</title>
|
632 |
</head>
|
633 |
<body>
|
634 |
<table>
|
635 |
<tr>
|
636 |
+
<td>Name</td><td>' . wp_strip_all_tags( $form_data['name'] ) . '</td>
|
637 |
</tr>
|
638 |
<tr>
|
639 |
+
<td>Email</td><td>' . wp_strip_all_tags( $form_data['email'] ) . '</td>
|
640 |
</tr>
|
641 |
<tr>
|
642 |
+
<td>Website</td><td>' . wp_strip_all_tags( $form_data['website'] ) . '</td>
|
643 |
</tr>
|
644 |
<tr>
|
645 |
+
<td>Subject</td><td>' . wp_strip_all_tags( $form_data['subject'] ) . '</td>
|
646 |
</tr>
|
647 |
<tr>
|
648 |
+
<td>Details</td><td>' . wp_strip_all_tags( $form_data['details'] ) . '</td>
|
649 |
</tr>
|
650 |
<tr>
|
651 |
+
<td>Request ID</td><td>' . wp_strip_all_tags( $form_data['request_id'] ) . '</td>
|
652 |
</tr>
|
653 |
<tr>
|
654 |
+
<td>Server Address</td><td>' . wp_strip_all_tags( $form_data['server_address'] ) . '</td>
|
655 |
</tr>
|
656 |
<tr>
|
657 |
+
<td>IP Address</td><td>' . wp_strip_all_tags( $form_data['ip_address'] ) . '</td>
|
658 |
</tr>
|
659 |
<tr>
|
660 |
+
<td>Server Type</td><td>' . wp_strip_all_tags( $form_data['server_type'] ) . '</td>
|
661 |
</tr>
|
662 |
<tr>
|
663 |
+
<td>User Agent</td><td>' . wp_strip_all_tags( $form_data['user_agent'] ) . '</td>
|
664 |
</tr>';
|
665 |
if ( 'bug_report' === sanitize_text_field( $form_data['request_type'] ) ) {
|
666 |
$message .= '<tr>
|
667 |
+
<td>WordPress Admin Username</td><td>' . wp_strip_all_tags( $form_data['wp_admin_username'] ) . '</td>
|
668 |
</tr>
|
669 |
<tr>
|
670 |
+
<td>WordPress Admin Password</td><td>' . wp_strip_all_tags( $form_data['wp_admin_pwd'] ) . '</td>
|
671 |
</tr>
|
672 |
<tr>
|
673 |
+
<td>SSH FTP Host</td><td>' . wp_strip_all_tags( $form_data['ssh_ftp_host'] ) . '</td>
|
674 |
</tr>
|
675 |
<tr>
|
676 |
+
<td>SSH FTP Username</td><td>' . wp_strip_all_tags( $form_data['ssh_ftp_username'] ) . '</td>
|
677 |
</tr>
|
678 |
<tr>
|
679 |
+
<td>SSH FTP Password</td><td>' . wp_strip_all_tags( $form_data['ssh_ftp_pwd'] ) . '</td>
|
680 |
</tr>
|
681 |
';
|
682 |
}
|
687 |
add_filter( 'wp_mail_content_type', array( $this, 'rtmedia_mail_content_type' ) );
|
688 |
|
689 |
$debuglog_temp_path = sanitize_text_field( $form_data['debuglog_temp_path'] );
|
690 |
+
// set attachment path for sending into mail.
|
691 |
+
$attachment_file = ( ! empty( $debuglog_temp_path ) ) ? $debuglog_temp_path : '';
|
692 |
+
$attachments = array( $attachment_file );
|
693 |
|
694 |
$headers = 'From: ' . $form_data['name'] . ' <' . $form_data['email'] . '>' . "\r\n";
|
695 |
$support_email = 'support@rtcamp.com';
|
696 |
+
if ( wp_mail(
|
697 |
+
$support_email,
|
698 |
+
'[rtmedia] ' . $mail_type . ' from ' . str_replace(
|
699 |
+
array(
|
700 |
+
'http://',
|
701 |
+
'https://',
|
702 |
+
),
|
703 |
+
'',
|
704 |
+
$form_data['website']
|
705 |
+
),
|
706 |
+
stripslashes( $message ),
|
707 |
+
$headers,
|
708 |
+
$attachments
|
709 |
+
) ) {
|
710 |
+
// delete file after sending it to mail.
|
711 |
if ( ! empty( $attachment_file ) ) {
|
712 |
unlink( $attachment_file );
|
713 |
}
|
725 |
echo '<p>' . esc_html__( 'Kindly contact your server support to fix this.', 'buddypress-media' ) . '</p>';
|
726 |
echo '<p>' .
|
727 |
sprintf(
|
728 |
+
// translators: %s: rtmedia link.
|
729 |
esc_html__( 'You can alternatively create a support request %s', 'buddypress-media' ),
|
730 |
'<a target="_blank" href="https://rtmedia.io/premium-support/">' . esc_html__( 'here', 'buddypress-media' ) . '</a>.'
|
731 |
) .
|
738 |
/**
|
739 |
* Write debug info as a text file and download it.
|
740 |
*
|
|
|
|
|
741 |
* @return void
|
742 |
*/
|
743 |
public function download_debuginfo_as_text() {
|
744 |
|
745 |
+
header( 'Content-disposition: attachment; filename=debuginfo.txt' );
|
746 |
+
header( 'Content-type: text/plain' );
|
747 |
+
|
748 |
global $wpdb, $wp_version, $bp;
|
749 |
+
|
750 |
+
$debug_info = array();
|
751 |
+
$debug_info['Home URL'] = esc_url( home_url() );
|
752 |
+
$debug_info['Site URL'] = esc_url( site_url() );
|
753 |
+
$debug_info['PHP'] = esc_html( PHP_VERSION );
|
754 |
+
$debug_info['MYSQL'] = esc_html( $wpdb->db_version() );
|
755 |
+
$debug_info['WordPress'] = esc_html( $wp_version );
|
756 |
$debug_info['BuddyPress'] = esc_html( ( isset( $bp->version ) ) ? $bp->version : '-NA-' );
|
757 |
+
$debug_info['rtMedia'] = esc_html( RTMEDIA_VERSION );
|
758 |
+
$debug_info['OS'] = esc_html( PHP_OS );
|
759 |
if ( extension_loaded( 'imagick' ) ) {
|
760 |
$imagickobj = new Imagick();
|
761 |
+
$imagick = preg_replace( " #((http|https|ftp)://(\S*?\.\S*?))(\s|\;|\)|\]|\[|\{|\}|,|\"|'|:|\<|$|\.\s)#i", "'<a href=\"$1\" target=\"_blank\">$3</a>$4'", $imagickobj->getversion() );
|
762 |
+
$message = $imagick;
|
763 |
} else {
|
764 |
$imagick['versionString'] = 'Not Installed';
|
765 |
}
|
769 |
} else {
|
770 |
$gd['GD Version'] = 'Not Installed';
|
771 |
}
|
772 |
+
$debug_info['GD'] = esc_html( $gd['GD Version'] );
|
773 |
+
$debug_info['[php.ini] post_max_size'] = esc_html( ini_get( 'post_max_size' ) );
|
774 |
$debug_info['[php.ini] upload_max_filesize'] = esc_html( ini_get( 'upload_max_filesize' ) );
|
775 |
+
$debug_info['[php.ini] memory_limit'] = esc_html( ini_get( 'memory_limit' ) );
|
776 |
+
$plugin_info = explode( ',', $this->get_plugin_info() );
|
777 |
+
$debug_info['Installed Plugins'] = implode( ', ' . PHP_EOL . str_repeat( ' ', 49 ), $plugin_info );
|
778 |
+
$active_theme = wp_get_theme();
|
779 |
+
$debug_info['Theme Name'] = esc_html( $active_theme->Name ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.NotSnakeCaseMemberVar
|
780 |
+
$debug_info['Theme Version'] = esc_html( $active_theme->Version ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.NotSnakeCaseMemberVar
|
781 |
+
$debug_info['Author URL'] = esc_url( $active_theme->{'Author URI'} );
|
782 |
+
$debug_info['Template Overrides'] = implode( ', ' . PHP_EOL . str_repeat( ' ', 50 ), $this->rtmedia_scan_template_files( RTMEDIA_PATH . '/templates/' ) );
|
783 |
+
$rtmedia_options = get_option( 'rtmedia-options' );
|
784 |
+
$rtmedia_options = array_merge( $debug_info, $rtmedia_options );
|
785 |
+
|
786 |
+
if ( ! empty( $rtmedia_options ) ) {
|
787 |
echo '==============================================================================' . PHP_EOL;
|
788 |
echo '================================== Debug Info ================================' . PHP_EOL;
|
789 |
echo '==============================================================================' . PHP_EOL . PHP_EOL . PHP_EOL;
|
790 |
|
791 |
foreach ( $rtmedia_options as $option => $value ) {
|
792 |
+
echo wp_kses_post( ucwords( str_replace( '_', ' ', $option ) ) . str_repeat( ' ', 50 - strlen( $option ) ) . wp_strip_all_tags( $value ) . PHP_EOL );
|
793 |
}
|
794 |
|
795 |
+
readfile( 'debuginfo.txt' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_readfile
|
796 |
exit();
|
797 |
}
|
798 |
|
app/helper/RTMediaThemes.php
CHANGED
@@ -1,13 +1,22 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
/**
|
4 |
-
*
|
5 |
*
|
6 |
* @author ritz
|
7 |
*/
|
8 |
class RTMediaThemes {
|
9 |
|
10 |
-
|
|
|
|
|
|
|
|
|
11 |
public static $page;
|
12 |
|
13 |
/**
|
@@ -15,7 +24,7 @@ class RTMediaThemes {
|
|
15 |
*
|
16 |
* @access public
|
17 |
*
|
18 |
-
* @param $page
|
19 |
*
|
20 |
* @return void
|
21 |
*/
|
@@ -49,8 +58,6 @@ class RTMediaThemes {
|
|
49 |
*
|
50 |
* @access public
|
51 |
*
|
52 |
-
* @param void
|
53 |
-
*
|
54 |
* @return void
|
55 |
*/
|
56 |
public function get_themes() {
|
@@ -74,17 +81,14 @@ class RTMediaThemes {
|
|
74 |
}
|
75 |
|
76 |
/**
|
77 |
-
* Show
|
78 |
*
|
79 |
* @access public
|
80 |
*
|
81 |
-
* @param void
|
82 |
-
*
|
83 |
* @return void
|
84 |
*/
|
85 |
public function rtmedia_themes_content() {
|
86 |
|
87 |
-
|
88 |
$rtdating = wp_get_theme( 'rtdating' );
|
89 |
if ( $rtdating->exists() ) {
|
90 |
$rtdating_purchase = '';
|
@@ -100,7 +104,7 @@ class RTMediaThemes {
|
|
100 |
}
|
101 |
|
102 |
$rtmedia_demo_url = 'http://demo.rtmedia.io/';
|
103 |
-
$themes
|
104 |
'rtdating' => array(
|
105 |
'name' => esc_html__( 'rtDating', 'buddypress-media' ),
|
106 |
'image' => RTMEDIA_URL . 'app/assets/admin/img/rtDating.png',
|
@@ -152,9 +156,9 @@ class RTMediaThemes {
|
|
152 |
|
153 |
<div class="theme-actions">
|
154 |
<a class="button load-customize hide-if-no-customize"
|
155 |
-
|
156 |
<a class="button button-primary load-customize hide-if-no-customize"
|
157 |
-
|
158 |
</div>
|
159 |
|
160 |
<div class="rtm-theme-content hide">
|
@@ -196,9 +200,9 @@ class RTMediaThemes {
|
|
196 |
|
197 |
<div class="theme-actions">
|
198 |
<a class="button load-customize hide-if-no-customize"
|
199 |
-
|
200 |
<a class="button button-primary load-customize hide-if-no-customize"
|
201 |
-
|
202 |
</div>
|
203 |
</div>
|
204 |
</div>
|
@@ -212,12 +216,10 @@ class RTMediaThemes {
|
|
212 |
}
|
213 |
|
214 |
/**
|
215 |
-
* Show
|
216 |
*
|
217 |
* @access public
|
218 |
*
|
219 |
-
* @param void
|
220 |
-
*
|
221 |
* @return void
|
222 |
*/
|
223 |
public function rtmedia_3rd_party_themes_content() {
|
@@ -286,7 +288,6 @@ class RTMediaThemes {
|
|
286 |
);
|
287 |
?>
|
288 |
|
289 |
-
|
290 |
<div class="theme-browser rtm-theme-browser rendered">
|
291 |
<div class="themes rtm-themes clearfix">
|
292 |
|
@@ -305,9 +306,9 @@ class RTMediaThemes {
|
|
305 |
|
306 |
<div class="theme-actions">
|
307 |
<a class="button load-customize hide-if-no-customize"
|
308 |
-
|
309 |
<a class="button button-primary load-customize hide-if-no-customize"
|
310 |
-
|
311 |
</div>
|
312 |
|
313 |
<div class="rtm-theme-content hide">
|
@@ -349,9 +350,9 @@ class RTMediaThemes {
|
|
349 |
|
350 |
<div class="theme-actions">
|
351 |
<a class="button load-customize hide-if-no-customize"
|
352 |
-
|
353 |
<a class="button button-primary load-customize hide-if-no-customize"
|
354 |
-
|
355 |
</div>
|
356 |
</div>
|
357 |
</div>
|
@@ -368,10 +369,10 @@ class RTMediaThemes {
|
|
368 |
<h3 class="rtm-option-title"><?php esc_html_e( 'Are you a developer?', 'buddypress-media' ); ?></h3>
|
369 |
|
370 |
<p>
|
371 |
-
<?php esc_html_e( 'If you have developed a rtMedia compatible theme and would like it to list here, please email us at', 'buddypress-media' ) ?>
|
372 |
-
<a href="mailto:rtmedia@rtcamp.com"><?php esc_html_e( 'rtmedia@rtcamp.com', 'buddypress-media' ) ?></a>.
|
373 |
</p>
|
374 |
</div>
|
375 |
<?php
|
376 |
}
|
377 |
-
}
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* Class file for RTMediaThemes.
|
4 |
+
*
|
5 |
+
* @package rtMedia
|
6 |
+
*/
|
7 |
|
8 |
/**
|
9 |
+
* Class to show rtMedia themes.
|
10 |
*
|
11 |
* @author ritz
|
12 |
*/
|
13 |
class RTMediaThemes {
|
14 |
|
15 |
+
/**
|
16 |
+
* Current page.
|
17 |
+
*
|
18 |
+
* @var string
|
19 |
+
*/
|
20 |
public static $page;
|
21 |
|
22 |
/**
|
24 |
*
|
25 |
* @access public
|
26 |
*
|
27 |
+
* @param string $page page.
|
28 |
*
|
29 |
* @return void
|
30 |
*/
|
58 |
*
|
59 |
* @access public
|
60 |
*
|
|
|
|
|
61 |
* @return void
|
62 |
*/
|
63 |
public function get_themes() {
|
81 |
}
|
82 |
|
83 |
/**
|
84 |
+
* Show rtMedia details.
|
85 |
*
|
86 |
* @access public
|
87 |
*
|
|
|
|
|
88 |
* @return void
|
89 |
*/
|
90 |
public function rtmedia_themes_content() {
|
91 |
|
|
|
92 |
$rtdating = wp_get_theme( 'rtdating' );
|
93 |
if ( $rtdating->exists() ) {
|
94 |
$rtdating_purchase = '';
|
104 |
}
|
105 |
|
106 |
$rtmedia_demo_url = 'http://demo.rtmedia.io/';
|
107 |
+
$themes = array(
|
108 |
'rtdating' => array(
|
109 |
'name' => esc_html__( 'rtDating', 'buddypress-media' ),
|
110 |
'image' => RTMEDIA_URL . 'app/assets/admin/img/rtDating.png',
|
156 |
|
157 |
<div class="theme-actions">
|
158 |
<a class="button load-customize hide-if-no-customize"
|
159 |
+
href="<?php echo esc_url( $theme['demo_url'] ); ?>"><?php esc_html_e( 'Live Demo', 'buddypress-media' ); ?></a>
|
160 |
<a class="button button-primary load-customize hide-if-no-customize"
|
161 |
+
href="<?php echo esc_url( $theme['buy_url'] ); ?>"><?php esc_html_e( 'Buy Now', 'buddypress-media' ); ?></a>
|
162 |
</div>
|
163 |
|
164 |
<div class="rtm-theme-content hide">
|
200 |
|
201 |
<div class="theme-actions">
|
202 |
<a class="button load-customize hide-if-no-customize"
|
203 |
+
href="<?php echo esc_url( $theme['demo_url'] ); ?>"><?php esc_html_e( 'Live Demo', 'buddypress-media' ); ?></a>
|
204 |
<a class="button button-primary load-customize hide-if-no-customize"
|
205 |
+
href="<?php echo esc_url( $theme['buy_url'] ); ?>"><?php esc_html_e( 'Buy Now', 'buddypress-media' ); ?></a>
|
206 |
</div>
|
207 |
</div>
|
208 |
</div>
|
216 |
}
|
217 |
|
218 |
/**
|
219 |
+
* Show rtMMedia 3rd party themes details.
|
220 |
*
|
221 |
* @access public
|
222 |
*
|
|
|
|
|
223 |
* @return void
|
224 |
*/
|
225 |
public function rtmedia_3rd_party_themes_content() {
|
288 |
);
|
289 |
?>
|
290 |
|
|
|
291 |
<div class="theme-browser rtm-theme-browser rendered">
|
292 |
<div class="themes rtm-themes clearfix">
|
293 |
|
306 |
|
307 |
<div class="theme-actions">
|
308 |
<a class="button load-customize hide-if-no-customize"
|
309 |
+
href="<?php echo esc_url( $theme['demo_url'] ); ?>"><?php esc_html_e( 'Live Demo', 'buddypress-media' ); ?></a>
|
310 |
<a class="button button-primary load-customize hide-if-no-customize"
|
311 |
+
href="<?php echo esc_url( $theme['buy_url'] ); ?>"><?php esc_html_e( 'Buy Now', 'buddypress-media' ); ?></a>
|
312 |
</div>
|
313 |
|
314 |
<div class="rtm-theme-content hide">
|
350 |
|
351 |
<div class="theme-actions">
|
352 |
<a class="button load-customize hide-if-no-customize"
|
353 |
+
href="<?php echo esc_url( $theme['demo_url'] ); ?>"><?php esc_html_e( 'Live Demo', 'buddypress-media' ); ?></a>
|
354 |
<a class="button button-primary load-customize hide-if-no-customize"
|
355 |
+
href="<?php echo esc_url( $theme['buy_url'] ); ?>"><?php esc_html_e( 'Buy Now', 'buddypress-media' ); ?></a>
|
356 |
</div>
|
357 |
</div>
|
358 |
</div>
|
369 |
<h3 class="rtm-option-title"><?php esc_html_e( 'Are you a developer?', 'buddypress-media' ); ?></h3>
|
370 |
|
371 |
<p>
|
372 |
+
<?php esc_html_e( 'If you have developed a rtMedia compatible theme and would like it to list here, please email us at', 'buddypress-media' ); ?>
|
373 |
+
<a href="mailto:rtmedia@rtcamp.com"><?php esc_html_e( 'rtmedia@rtcamp.com', 'buddypress-media' ); ?></a>.
|
374 |
</p>
|
375 |
</div>
|
376 |
<?php
|
377 |
}
|
378 |
+
}
|
app/helper/RTMediaUploadException.php
CHANGED
@@ -1,24 +1,29 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
/**
|
4 |
-
*
|
5 |
*
|
6 |
* @author joshua
|
7 |
*/
|
8 |
class RTMediaUploadException extends Exception {
|
|
|
9 |
/**
|
10 |
-
*
|
11 |
-
* @var type
|
12 |
-
*
|
13 |
* Exception for Invalid context while uploading any media
|
|
|
|
|
14 |
*/
|
15 |
-
|
16 |
|
17 |
/**
|
18 |
* Constructs the class.
|
19 |
*
|
20 |
-
* @param
|
21 |
-
* @param
|
22 |
*/
|
23 |
public function __construct( $code, $msg = false ) {
|
24 |
$message = $this->codeToMessage( $code, $msg );
|
@@ -29,10 +34,10 @@ class RTMediaUploadException extends Exception {
|
|
29 |
* Error specific Message generated for the exception depending upon the code passed.
|
30 |
* Native Error Codes defined in PHP core module are used for uploading a standard file
|
31 |
*
|
32 |
-
* @param
|
33 |
-
* @param
|
34 |
*
|
35 |
-
* @return
|
36 |
*/
|
37 |
private function codeToMessage( $code, $msg ) {
|
38 |
switch ( $code ) {
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* Upload exception.
|
4 |
+
*
|
5 |
+
* @package rtMedia
|
6 |
+
*/
|
7 |
|
8 |
/**
|
9 |
+
* Class to handle media upload exceptions.
|
10 |
*
|
11 |
* @author joshua
|
12 |
*/
|
13 |
class RTMediaUploadException extends Exception {
|
14 |
+
|
15 |
/**
|
|
|
|
|
|
|
16 |
* Exception for Invalid context while uploading any media
|
17 |
+
*
|
18 |
+
* @var int
|
19 |
*/
|
20 |
+
public $upload_err_invalid_context = 9;
|
21 |
|
22 |
/**
|
23 |
* Constructs the class.
|
24 |
*
|
25 |
+
* @param string $code Code.
|
26 |
+
* @param string|bool $msg Message.
|
27 |
*/
|
28 |
public function __construct( $code, $msg = false ) {
|
29 |
$message = $this->codeToMessage( $code, $msg );
|
34 |
* Error specific Message generated for the exception depending upon the code passed.
|
35 |
* Native Error Codes defined in PHP core module are used for uploading a standard file
|
36 |
*
|
37 |
+
* @param string $code Code.
|
38 |
+
* @param string $msg Message.
|
39 |
*
|
40 |
+
* @return string
|
41 |
*/
|
42 |
private function codeToMessage( $code, $msg ) {
|
43 |
switch ( $code ) {
|
app/helper/db/RTDBModel.php
CHANGED
@@ -1,44 +1,61 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
/**
|
4 |
-
* Description of RTDBModel
|
5 |
* Base class for any Database Model like Media, Album etc.
|
6 |
*
|
|
|
|
|
7 |
* @author udit
|
8 |
*/
|
9 |
|
10 |
if ( ! class_exists( 'RTDBModel' ) ) {
|
|
|
|
|
|
|
11 |
class RTDBModel {
|
12 |
|
13 |
/**
|
|
|
|
|
14 |
*
|
15 |
-
* @var
|
16 |
-
*
|
17 |
-
* $table_name - database table linked to the model.
|
18 |
-
* All the queries will be fired on that table or with the join in this table.
|
19 |
-
* $per_page - number of rows per page to be displayed
|
20 |
*/
|
21 |
public $table_name;
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
public $per_page;
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
public $mu_single_table;
|
24 |
|
25 |
/**
|
|
|
26 |
*
|
27 |
-
* @param string
|
28 |
-
* @param boolean $withprefix Set true if $tablename is with prefix otherwise it will prepend
|
|
|
|
|
29 |
*/
|
30 |
-
function __construct( $table_name, $withprefix = false, $per_page = 10, $mu_single_table = false ) {
|
31 |
$this->mu_single_table = $mu_single_table;
|
32 |
$this->set_table_name( $table_name, $withprefix );
|
33 |
$this->set_per_page( $per_page );
|
34 |
}
|
35 |
|
36 |
/**
|
|
|
37 |
*
|
38 |
* @global object $wpdb
|
39 |
*
|
40 |
-
* @param string $table_name
|
41 |
-
* @param mixed
|
42 |
*/
|
43 |
public function set_table_name( $table_name, $withprefix = false ) {
|
44 |
global $wpdb;
|
@@ -49,9 +66,9 @@ if ( ! class_exists( 'RTDBModel' ) ) {
|
|
49 |
}
|
50 |
|
51 |
/**
|
52 |
-
*
|
53 |
*
|
54 |
-
* @param integer $per_page
|
55 |
*/
|
56 |
public function set_per_page( $per_page ) {
|
57 |
$this->per_page = $per_page;
|
@@ -63,12 +80,12 @@ if ( ! class_exists( 'RTDBModel' ) ) {
|
|
63 |
*
|
64 |
* @global object $wpdb
|
65 |
*
|
66 |
-
* @param string $name
|
67 |
-
* @param array
|
68 |
*
|
69 |
-
* @return array result array
|
70 |
*/
|
71 |
-
function __call( $name, $arguments ) {
|
72 |
$column_name = str_replace( 'get_by_', '', strtolower( $name ) );
|
73 |
$paging = false;
|
74 |
$page = 1;
|
@@ -88,8 +105,10 @@ if ( ! class_exists( 'RTDBModel' ) ) {
|
|
88 |
$this->per_page = apply_filters( 'rt_db_model_per_page', $this->per_page, $this->table_name );
|
89 |
$return_array = array();
|
90 |
$return_array['result'] = false;
|
|
|
91 |
global $wpdb;
|
92 |
-
$return_array[
|
|
|
93 |
if ( $return_array['total'] > 0 ) {
|
94 |
$other = '';
|
95 |
if ( $paging ) {
|
@@ -102,6 +121,7 @@ if ( ! class_exists( 'RTDBModel' ) ) {
|
|
102 |
if ( ! is_integer( $offset ) ) {
|
103 |
$offset = 0;
|
104 |
}
|
|
|
105 |
if ( intval( $offset ) < 0 ) {
|
106 |
$offset = 0;
|
107 |
}
|
@@ -112,8 +132,8 @@ if ( ! class_exists( 'RTDBModel' ) ) {
|
|
112 |
return false;
|
113 |
}
|
114 |
}
|
115 |
-
|
116 |
-
$return_array[
|
117 |
}
|
118 |
|
119 |
return $return_array;
|
@@ -123,14 +143,15 @@ if ( ! class_exists( 'RTDBModel' ) ) {
|
|
123 |
}
|
124 |
|
125 |
/**
|
|
|
126 |
*
|
127 |
* @global object $wpdb
|
128 |
*
|
129 |
-
* @param array $row
|
130 |
*
|
131 |
* @return integer
|
132 |
*/
|
133 |
-
function insert( $row ) {
|
134 |
global $wpdb;
|
135 |
$insertdata = array();
|
136 |
foreach ( $row as $key => $val ) {
|
@@ -145,13 +166,16 @@ if ( ! class_exists( 'RTDBModel' ) ) {
|
|
145 |
}
|
146 |
|
147 |
/**
|
|
|
148 |
*
|
149 |
* @global object $wpdb
|
150 |
*
|
151 |
-
* @param array $data
|
152 |
-
* @param array $where
|
|
|
|
|
153 |
*/
|
154 |
-
function update( $data, $where ) {
|
155 |
global $wpdb;
|
156 |
|
157 |
return $wpdb->update( $this->table_name, $data, $where );
|
@@ -161,13 +185,16 @@ if ( ! class_exists( 'RTDBModel' ) ) {
|
|
161 |
* Get all the rows according to the columns set in $columns parameter.
|
162 |
* offset and rows per page can also be passed for pagination.
|
163 |
*
|
164 |
-
* @global object
|
165 |
*
|
166 |
-
* @param array
|
|
|
|
|
|
|
167 |
*
|
168 |
* @return array
|
169 |
*/
|
170 |
-
function get( $columns, $offset = false, $per_page = false, $order_by = 'id desc' ) {
|
171 |
global $wpdb;
|
172 |
|
173 |
$select = "SELECT * FROM {$this->table_name}";
|
@@ -183,9 +210,9 @@ if ( ! class_exists( 'RTDBModel' ) ) {
|
|
183 |
$colvalue['value'] = esc_sql( $colvalue );
|
184 |
}
|
185 |
$col_val_comapare = ( is_array( $colvalue['value'] ) ) ? '(\'' . implode( "','", $colvalue['value'] ) . '\')' : '(\'' . $colvalue['value'] . '\')';
|
186 |
-
$where
|
187 |
} else {
|
188 |
-
$where .= $wpdb->prepare( " AND {$this->table_name}.{$colname} = %s", $colvalue ); //
|
189 |
}
|
190 |
}
|
191 |
$sql = $select . $where;
|
@@ -208,18 +235,19 @@ if ( ! class_exists( 'RTDBModel' ) ) {
|
|
208 |
$sql .= $wpdb->prepare( ' LIMIT %d, %d', $offset, $per_page );
|
209 |
|
210 |
}
|
211 |
-
return $wpdb->get_results( $sql ); //
|
212 |
}
|
213 |
|
214 |
/**
|
|
|
215 |
*
|
216 |
* @global object $wpdb
|
217 |
*
|
218 |
-
* @param array $where
|
219 |
*
|
220 |
-
* @return
|
221 |
*/
|
222 |
-
function delete( $where ) {
|
223 |
global $wpdb;
|
224 |
|
225 |
return $wpdb->delete( $this->table_name, $where );
|
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* Base class for any Database Model like Media, Album etc.
|
4 |
*
|
5 |
+
* @package rtMedia
|
6 |
+
*
|
7 |
* @author udit
|
8 |
*/
|
9 |
|
10 |
if ( ! class_exists( 'RTDBModel' ) ) {
|
11 |
+
/**
|
12 |
+
* Base class for any Database Model like Media, Album etc.
|
13 |
+
*/
|
14 |
class RTDBModel {
|
15 |
|
16 |
/**
|
17 |
+
* Database table linked to the model.
|
18 |
+
* All the queries will be fired on that table or with the join in this table.
|
19 |
*
|
20 |
+
* @var string $table_name
|
|
|
|
|
|
|
|
|
21 |
*/
|
22 |
public $table_name;
|
23 |
+
|
24 |
+
/**
|
25 |
+
* Number of rows per page to be displayed
|
26 |
+
*
|
27 |
+
* @var int $per_page
|
28 |
+
*/
|
29 |
public $per_page;
|
30 |
+
|
31 |
+
/**
|
32 |
+
* Var mu_single_table.
|
33 |
+
*
|
34 |
+
* @var string $mu_single_table
|
35 |
+
*/
|
36 |
public $mu_single_table;
|
37 |
|
38 |
/**
|
39 |
+
* RTDBModel class constructor.
|
40 |
*
|
41 |
+
* @param string $table_name Table name for model.
|
42 |
+
* @param boolean $withprefix Set true if $tablename is with prefix otherwise it will prepend WordPress prefix with "rt_".
|
43 |
+
* @param int $per_page Per Page.
|
44 |
+
* @param bool $mu_single_table single table.
|
45 |
*/
|
46 |
+
public function __construct( $table_name, $withprefix = false, $per_page = 10, $mu_single_table = false ) {
|
47 |
$this->mu_single_table = $mu_single_table;
|
48 |
$this->set_table_name( $table_name, $withprefix );
|
49 |
$this->set_per_page( $per_page );
|
50 |
}
|
51 |
|
52 |
/**
|
53 |
+
* Set table name for class.
|
54 |
*
|
55 |
* @global object $wpdb
|
56 |
*
|
57 |
+
* @param string $table_name Table name.
|
58 |
+
* @param mixed $withprefix With prefix or not.
|
59 |
*/
|
60 |
public function set_table_name( $table_name, $withprefix = false ) {
|
61 |
global $wpdb;
|
66 |
}
|
67 |
|
68 |
/**
|
69 |
+
* Set number of rows per page for pagination
|
70 |
*
|
71 |
+
* @param integer $per_page Rows per page.
|
72 |
*/
|
73 |
public function set_per_page( $per_page ) {
|
74 |
$this->per_page = $per_page;
|
80 |
*
|
81 |
* @global object $wpdb
|
82 |
*
|
83 |
+
* @param string $name Added get_by_<coulmname>(value,pagging=true,page_no=1).
|
84 |
+
* @param array $arguments Arguments.
|
85 |
*
|
86 |
+
* @return bool|array result array
|
87 |
*/
|
88 |
+
public function __call( $name, $arguments ) {
|
89 |
$column_name = str_replace( 'get_by_', '', strtolower( $name ) );
|
90 |
$paging = false;
|
91 |
$page = 1;
|
105 |
$this->per_page = apply_filters( 'rt_db_model_per_page', $this->per_page, $this->table_name );
|
106 |
$return_array = array();
|
107 |
$return_array['result'] = false;
|
108 |
+
|
109 |
global $wpdb;
|
110 |
+
$return_array['total'] = intval( $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$this->table_name} WHERE {$column_name} = %s", $arguments[0] ) ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
111 |
+
|
112 |
if ( $return_array['total'] > 0 ) {
|
113 |
$other = '';
|
114 |
if ( $paging ) {
|
121 |
if ( ! is_integer( $offset ) ) {
|
122 |
$offset = 0;
|
123 |
}
|
124 |
+
|
125 |
if ( intval( $offset ) < 0 ) {
|
126 |
$offset = 0;
|
127 |
}
|
132 |
return false;
|
133 |
}
|
134 |
}
|
135 |
+
|
136 |
+
$return_array['result'] = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$this->table_name} WHERE {$column_name} = %s {$other}", $arguments[0] ), ARRAY_A ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
137 |
}
|
138 |
|
139 |
return $return_array;
|
143 |
}
|
144 |
|
145 |
/**
|
146 |
+
* Insert.
|
147 |
*
|
148 |
* @global object $wpdb
|
149 |
*
|
150 |
+
* @param array $row Row array.
|
151 |
*
|
152 |
* @return integer
|
153 |
*/
|
154 |
+
public function insert( $row ) {
|
155 |
global $wpdb;
|
156 |
$insertdata = array();
|
157 |
foreach ( $row as $key => $val ) {
|
166 |
}
|
167 |
|
168 |
/**
|
169 |
+
* Update table.
|
170 |
*
|
171 |
* @global object $wpdb
|
172 |
*
|
173 |
+
* @param array $data Data to update.
|
174 |
+
* @param array $where Where clause.
|
175 |
+
*
|
176 |
+
* @return false|int
|
177 |
*/
|
178 |
+
public function update( $data, $where ) {
|
179 |
global $wpdb;
|
180 |
|
181 |
return $wpdb->update( $this->table_name, $data, $where );
|
185 |
* Get all the rows according to the columns set in $columns parameter.
|
186 |
* offset and rows per page can also be passed for pagination.
|
187 |
*
|
188 |
+
* @global object $wpdb
|
189 |
*
|
190 |
+
* @param array $columns Columns to get.
|
191 |
+
* @param int|bool $offset Offset for query.
|
192 |
+
* @param int|bool $per_page Per page data.
|
193 |
+
* @param string $order_by Order by.
|
194 |
*
|
195 |
* @return array
|
196 |
*/
|
197 |
+
public function get( $columns, $offset = false, $per_page = false, $order_by = 'id desc' ) {
|
198 |
global $wpdb;
|
199 |
|
200 |
$select = "SELECT * FROM {$this->table_name}";
|
210 |
$colvalue['value'] = esc_sql( $colvalue );
|
211 |
}
|
212 |
$col_val_comapare = ( is_array( $colvalue['value'] ) ) ? '(\'' . implode( "','", $colvalue['value'] ) . '\')' : '(\'' . $colvalue['value'] . '\')';
|
213 |
+
$where .= " AND {$this->table_name}.{$colname} {$compare} {$col_val_comapare}";
|
214 |
} else {
|
215 |
+
$where .= $wpdb->prepare( " AND {$this->table_name}.{$colname} = %s", $colvalue ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
216 |
}
|
217 |
}
|
218 |
$sql = $select . $where;
|
235 |
$sql .= $wpdb->prepare( ' LIMIT %d, %d', $offset, $per_page );
|
236 |
|
237 |
}
|
238 |
+
return $wpdb->get_results( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
239 |
}
|
240 |
|
241 |
/**
|
242 |
+
* Delete row.
|
243 |
*
|
244 |
* @global object $wpdb
|
245 |
*
|
246 |
+
* @param array $where Where clause.
|
247 |
*
|
248 |
+
* @return false|int
|
249 |
*/
|
250 |
+
public function delete( $where ) {
|
251 |
global $wpdb;
|
252 |
|
253 |
return $wpdb->delete( $this->table_name, $where );
|
app/helper/db/RTDBUpdate.php
CHANGED
@@ -1,31 +1,77 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
/**
|
4 |
-
*
|
5 |
* Required : rt_plugin_info.php
|
6 |
*
|
|
|
|
|
7 |
* @author udit
|
8 |
* version 1.1
|
9 |
*/
|
10 |
|
11 |
if ( ! class_exists( 'RTDBUpdate' ) ) {
|
|
|
|
|
|
|
12 |
class RTDBUpdate {
|
|
|
13 |
/**
|
|
|
14 |
*
|
15 |
-
* @var
|
16 |
*/
|
17 |
public $db_version;
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
public $install_db_version;
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
public $schema_path;
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
public $plugin_path;
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
public $db_version_option_name;
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
public $rt_plugin_info;
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
public $mu_single_table;
|
24 |
|
25 |
/**
|
|
|
26 |
* Set db current and installed version and also plugin info in rt_plugin_info variable.
|
27 |
*
|
28 |
-
* @param
|
|
|
|
|
|
|
29 |
*/
|
30 |
public function __construct( $current_version = false, $plugin_path = false, $schema_path = false, $mu_single_table = false ) {
|
31 |
|
@@ -57,12 +103,12 @@ if ( ! class_exists( 'RTDBUpdate' ) ) {
|
|
57 |
*
|
58 |
* @access public
|
59 |
*
|
60 |
-
* @param string $sql
|
61 |
*
|
62 |
* @return void
|
63 |
*/
|
64 |
public function create_table( $sql ) {
|
65 |
-
require_once
|
66 |
dbDelta( $sql );
|
67 |
}
|
68 |
|
@@ -71,8 +117,6 @@ if ( ! class_exists( 'RTDBUpdate' ) ) {
|
|
71 |
*
|
72 |
* @access public
|
73 |
*
|
74 |
-
* @param void
|
75 |
-
*
|
76 |
* @return string
|
77 |
*/
|
78 |
public function get_db_version_option_name() {
|
@@ -84,8 +128,6 @@ if ( ! class_exists( 'RTDBUpdate' ) ) {
|
|
84 |
*
|
85 |
* @access public
|
86 |
*
|
87 |
-
* @param void
|
88 |
-
*
|
89 |
* @return string
|
90 |
*/
|
91 |
public function get_install_db_version() {
|
@@ -97,8 +139,6 @@ if ( ! class_exists( 'RTDBUpdate' ) ) {
|
|
97 |
*
|
98 |
* @access public
|
99 |
*
|
100 |
-
* @param void
|
101 |
-
*
|
102 |
* @return bool
|
103 |
*/
|
104 |
public function check_upgrade() {
|
@@ -111,31 +151,35 @@ if ( ! class_exists( 'RTDBUpdate' ) ) {
|
|
111 |
*
|
112 |
* @access public
|
113 |
*
|
114 |
-
* @param void
|
115 |
-
*
|
116 |
* @return void
|
117 |
*/
|
118 |
public function do_upgrade() {
|
119 |
global $wpdb;
|
|
|
120 |
if ( version_compare( $this->db_version, $this->install_db_version, '>' ) ) {
|
|
|
121 |
$path = $this->schema_path;
|
122 |
-
|
123 |
-
|
|
|
|
|
|
|
124 |
if ( '.' !== $entry && '..' !== $entry ) {
|
|
|
125 |
if ( false !== strpos( $entry, '.schema' ) && file_exists( $path . '/' . $entry ) ) {
|
126 |
if ( is_multisite() ) {
|
127 |
-
$table_name
|
128 |
-
$check_res
|
129 |
if ( $check_res && count( $check_res ) > 0 && is_array( $check_res ) && isset( $check_res[0][0] ) ) {
|
130 |
$tb_name = $check_res[0][0];
|
131 |
$table_name = ( ( $this->mu_single_table ) ? $wpdb->base_prefix : $wpdb->prefix ) . 'rt_' . $table_name;
|
132 |
if ( $tb_name !== $table_name ) {
|
133 |
$alter_sql = 'ALTER TABLE ' . $tb_name . ' RENAME TO ' . $table_name;
|
134 |
-
$wpdb->query( $alter_sql ); //
|
135 |
}
|
136 |
}
|
137 |
}
|
138 |
-
$this->create_table( $this->genrate_sql( $entry, file_get_contents( $path . '/' . $entry ) ) );
|
139 |
}
|
140 |
}
|
141 |
}
|
@@ -151,15 +195,15 @@ if ( ! class_exists( 'RTDBUpdate' ) ) {
|
|
151 |
}
|
152 |
|
153 |
/**
|
154 |
-
* Check if
|
155 |
*
|
156 |
* @access static
|
157 |
*
|
158 |
-
* @param string $table
|
159 |
*
|
160 |
* @return bool
|
161 |
*/
|
162 |
-
static function table_exists( $table ) {
|
163 |
global $wpdb;
|
164 |
|
165 |
if ( 1 === intval( $wpdb->query( $wpdb->prepare( 'SHOW TABLES LIKE %s', $table ) ) ) ) {
|
@@ -170,25 +214,26 @@ if ( ! class_exists( 'RTDBUpdate' ) ) {
|
|
170 |
}
|
171 |
|
172 |
/**
|
173 |
-
*
|
174 |
*
|
175 |
* @access public
|
176 |
*
|
177 |
-
* @param string $file_name
|
178 |
-
* @param string $file_content
|
179 |
*
|
180 |
* @return string sql query
|
181 |
*/
|
182 |
public function genrate_sql( $file_name, $file_content ) {
|
|
|
183 |
return sprintf( $file_content, $this->genrate_table_name( $file_name ) );
|
184 |
}
|
185 |
|
186 |
/**
|
187 |
-
*
|
188 |
*
|
189 |
* @access public
|
190 |
*
|
191 |
-
* @param string $file_name
|
192 |
*
|
193 |
* @return string
|
194 |
*/
|
1 |
<?php
|
|
|
2 |
/**
|
3 |
+
* Class to update DB for rtMedia.
|
4 |
* Required : rt_plugin_info.php
|
5 |
*
|
6 |
+
* @package rtMedia
|
7 |
+
*
|
8 |
* @author udit
|
9 |
* version 1.1
|
10 |
*/
|
11 |
|
12 |
if ( ! class_exists( 'RTDBUpdate' ) ) {
|
13 |
+
/**
|
14 |
+
* Class to update DB for rtMedia.
|
15 |
+
*/
|
16 |
class RTDBUpdate {
|
17 |
+
|
18 |
/**
|
19 |
+
* DB version.
|
20 |
*
|
21 |
+
* @var $db_version
|
22 |
*/
|
23 |
public $db_version;
|
24 |
+
|
25 |
+
/**
|
26 |
+
* Install DB Version.
|
27 |
+
*
|
28 |
+
* @var $install_db_version
|
29 |
+
*/
|
30 |
public $install_db_version;
|
31 |
+
|
32 |
+
/**
|
33 |
+
* Schema path.
|
34 |
+
*
|
35 |
+
* @var string $schema_path
|
36 |
+
*/
|
37 |
public $schema_path;
|
38 |
+
|
39 |
+
/**
|
40 |
+
* Plugin path.
|
41 |
+
*
|
42 |
+
* @var string $plugin_path
|
43 |
+
*/
|
44 |
public $plugin_path;
|
45 |
+
|
46 |
+
/**
|
47 |
+
* DB version option.
|
48 |
+
*
|
49 |
+
* @var string $db_version_option_name
|
50 |
+
*/
|
51 |
public $db_version_option_name;
|
52 |
+
|
53 |
+
/**
|
54 |
+
* Plugin info.
|
55 |
+
*
|
56 |
+
* @var object $rt_plugin_info
|
57 |
+
*/
|
58 |
public $rt_plugin_info;
|
59 |
+
|
60 |
+
/**
|
61 |
+
* Single table.
|
62 |
+
*
|
63 |
+
* @var $mu_single_table
|
64 |
+
*/
|
65 |
public $mu_single_table;
|
66 |
|
67 |
/**
|
68 |
+
* RTDBUpdate constructor.
|
69 |
* Set db current and installed version and also plugin info in rt_plugin_info variable.
|
70 |
*
|
71 |
+
* @param string|bool $current_version Optional if not defined then will use plugin version.
|
72 |
+
* @param bool|string $plugin_path Plugin path.
|
73 |
+
* @param bool|string $schema_path Schema path.
|
74 |
+
* @param bool|string $mu_single_table mu single table.
|
75 |
*/
|
76 |
public function __construct( $current_version = false, $plugin_path = false, $schema_path = false, $mu_single_table = false ) {
|
77 |
|
103 |
*
|
104 |
* @access public
|
105 |
*
|
106 |
+
* @param string $sql SQL query string.
|
107 |
*
|
108 |
* @return void
|
109 |
*/
|
110 |
public function create_table( $sql ) {
|
111 |
+
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
|
112 |
dbDelta( $sql );
|
113 |
}
|
114 |
|
117 |
*
|
118 |
* @access public
|
119 |
*
|
|
|
|
|
120 |
* @return string
|
121 |
*/
|
122 |
public function get_db_version_option_name() {
|
128 |
*
|
129 |
* @access public
|
130 |
*
|
|
|
|
|
131 |
* @return string
|
132 |
*/
|
133 |
public function get_install_db_version() {
|
139 |
*
|
140 |
* @access public
|
141 |
*
|
|
|
|
|
142 |
* @return bool
|
143 |
*/
|
144 |
public function check_upgrade() {
|
151 |
*
|
152 |
* @access public
|
153 |
*
|
|
|
|
|
154 |
* @return void
|
155 |
*/
|
156 |
public function do_upgrade() {
|
157 |
global $wpdb;
|
158 |
+
|
159 |
if ( version_compare( $this->db_version, $this->install_db_version, '>' ) ) {
|
160 |
+
|
161 |
$path = $this->schema_path;
|
162 |
+
|
163 |
+
if ( $handle = opendir( $path ) ) { // phpcs:ignore
|
164 |
+
|
165 |
+
while ( false !== ( $entry = readdir( $handle ) ) ) { // phpcs:ignore
|
166 |
+
|
167 |
if ( '.' !== $entry && '..' !== $entry ) {
|
168 |
+
|
169 |
if ( false !== strpos( $entry, '.schema' ) && file_exists( $path . '/' . $entry ) ) {
|
170 |
if ( is_multisite() ) {
|
171 |
+
$table_name = str_replace( '.schema', '', strtolower( $entry ) );
|
172 |
+
$check_res = $wpdb->get_results( $wpdb->prepare( 'SHOW TABLES LIKE %s', '%rt_' . $table_name ), ARRAY_N );
|
173 |
if ( $check_res && count( $check_res ) > 0 && is_array( $check_res ) && isset( $check_res[0][0] ) ) {
|
174 |
$tb_name = $check_res[0][0];
|
175 |
$table_name = ( ( $this->mu_single_table ) ? $wpdb->base_prefix : $wpdb->prefix ) . 'rt_' . $table_name;
|
176 |
if ( $tb_name !== $table_name ) {
|
177 |
$alter_sql = 'ALTER TABLE ' . $tb_name . ' RENAME TO ' . $table_name;
|
178 |
+
$wpdb->query( $alter_sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
179 |
}
|
180 |
}
|
181 |
}
|
182 |
+
$this->create_table( $this->genrate_sql( $entry, file_get_contents( $path . '/' . $entry ) ) ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
|
183 |
}
|
184 |
}
|
185 |
}
|
195 |
}
|
196 |
|
197 |
/**
|
198 |
+
* Check if given table exists.
|
199 |
*
|
200 |
* @access static
|
201 |
*
|
202 |
+
* @param string $table Table name.
|
203 |
*
|
204 |
* @return bool
|
205 |
*/
|
206 |
+
public static function table_exists( $table ) {
|
207 |
global $wpdb;
|
208 |
|
209 |
if ( 1 === intval( $wpdb->query( $wpdb->prepare( 'SHOW TABLES LIKE %s', $table ) ) ) ) {
|
214 |
}
|
215 |
|
216 |
/**
|
217 |
+
* Generate sql query.
|
218 |
*
|
219 |
* @access public
|
220 |
*
|
221 |
+
* @param string $file_name File name.
|
222 |
+
* @param string $file_content File content.
|
223 |
*
|
224 |
* @return string sql query
|
225 |
*/
|
226 |
public function genrate_sql( $file_name, $file_content ) {
|
227 |
+
// TODO: change Function name.
|
228 |
return sprintf( $file_content, $this->genrate_table_name( $file_name ) );
|
229 |
}
|
230 |
|
231 |
/**
|
232 |
+
* Generate table name according to filename.
|
233 |
*
|
234 |
* @access public
|
235 |
*
|
236 |
+
* @param string $file_name File name.
|
237 |
*
|
238 |
* @return string
|
239 |
*/
|
app/helper/db/rt_plugin_info.php
CHANGED
@@ -1,35 +1,108 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
/**
|
4 |
-
*
|
|
|
|
|
5 |
*
|
6 |
* @author udit
|
7 |
*/
|
8 |
|
9 |
if ( ! class_exists( 'rt_plugin_info' ) ) {
|
10 |
-
|
|
|
|
|
|
|
11 |
|
12 |
-
|
|
|
|
|
|
|
|
|
13 |
public $plugin_path;
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
public $
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
public $plugin_data;
|
25 |
|
26 |
/**
|
27 |
-
*
|
28 |
*
|
29 |
* @access public
|
30 |
*
|
31 |
-
* @param
|
32 |
-
*
|
33 |
*/
|
34 |
public function __construct( $path = null ) {
|
35 |
$this->set_current_plugin_path( $path );
|
@@ -37,27 +110,22 @@ if ( ! class_exists( 'rt_plugin_info' ) ) {
|
|
37 |
}
|
38 |
|
39 |
/**
|
40 |
-
*
|
41 |
*
|
42 |
* @access public
|
43 |
*
|
44 |
-
* @param void
|
45 |
-
*
|
46 |
* @return array
|
47 |
*/
|
48 |
public function get_plugin_data() {
|
49 |
-
require_once
|
50 |
|
51 |
-
return @get_plugin_data( $this->plugin_path );
|
52 |
}
|
53 |
|
54 |
/**
|
55 |
-
*
|
56 |
*
|
57 |
* @access public
|
58 |
-
*
|
59 |
-
* @param void
|
60 |
-
*
|
61 |
*/
|
62 |
public function set_plugin_data() {
|
63 |
$this->plugin_data = $this->get_plugin_data();
|
@@ -74,12 +142,11 @@ if ( ! class_exists( 'rt_plugin_info' ) ) {
|
|
74 |
}
|
75 |
|
76 |
/**
|
77 |
-
*
|
78 |
*
|
79 |
* @access public
|
80 |
*
|
81 |
-
* @param
|
82 |
-
*
|
83 |
*/
|
84 |
public function set_current_plugin_path( $path ) {
|
85 |
if ( null !== $path ) {
|
1 |
<?php
|
|
|
2 |
/**
|
3 |
+
* Class to store rtMedia plugin info.
|
4 |
+
*
|
5 |
+
* @package rtMedia
|
6 |
*
|
7 |
* @author udit
|
8 |
*/
|
9 |
|
10 |
if ( ! class_exists( 'rt_plugin_info' ) ) {
|
11 |
+
/**
|
12 |
+
* Class to store rtMedia plugin info.
|
13 |
+
*/
|
14 |
+
class rt_plugin_info { // phpcs:ignore PEAR.NamingConventions.ValidClassName, Generic.Classes.OpeningBraceSameLine.ContentAfterBrace
|
15 |
|
16 |
+
/**
|
17 |
+
* Plugin path.
|
18 |
+
*
|
19 |
+
* @var string $plugin_path
|
20 |
+
*/
|
21 |
public $plugin_path;
|
22 |
+
|
23 |
+
/**
|
24 |
+
* 'Name' - Name of the plugin, must be unique.
|
25 |
+
*
|
26 |
+
* @var string $name
|
27 |
+
*/
|
28 |
+
public $name;
|
29 |
+
|
30 |
+
/**
|
31 |
+
* 'Title' - Title of the plugin and the link to the plugin's web site.
|
32 |
+
*
|
33 |
+
* @var string $title
|
34 |
+
*/
|
35 |
+
public $title;
|
36 |
+
|
37 |
+
/**
|
38 |
+
* 'Description' - Description of what the plugin does and/or notes from the author.
|
39 |
+
*
|
40 |
+
* @var string $desctipriton
|
41 |
+
*/
|
42 |
+
public $desctipriton; // TODO : Correct spelling error.
|
43 |
+
|
44 |
+
/**
|
45 |
+
* 'Author' - The author's name
|
46 |
+
*
|
47 |
+
* @var $author
|
48 |
+
*/
|
49 |
+
public $author;
|
50 |
+
|
51 |
+
/**
|
52 |
+
* 'AuthorURI' - The authors web site address.
|
53 |
+
*
|
54 |
+
* @var string $authoruri
|
55 |
+
*/
|
56 |
+
public $authoruri;
|
57 |
+
|
58 |
+
/**
|
59 |
+
* 'Version' - The plugin version number.
|
60 |
+
*
|
61 |
+
* @var $version
|
62 |
+
*/
|
63 |
+
public $version;
|
64 |
+
|
65 |
+
/**
|
66 |
+
* 'PluginURI' - Plugin web site address.
|
67 |
+
*
|
68 |
+
* @var string $pluginuri
|
69 |
+
*/
|
70 |
+
public $pluginuri;
|
71 |
+
|
72 |
+
/**
|
73 |
+
* 'TextDomain' - Plugin's text domain for localization.
|
74 |
+
*
|
75 |
+
* @var string $textdomain
|
76 |
+
*/
|
77 |
+
public $textdomain;
|
78 |
+
|
79 |
+
/**
|
80 |
+
* 'DomainPath' - Plugin's relative directory path to .mo files.
|
81 |
+
*
|
82 |
+
* @var string $domain_path
|
83 |
+
*/
|
84 |
+
public $domain_path;
|
85 |
+
|
86 |
+
/**
|
87 |
+
* 'Network' - Whether the plugin can only be activated network wide.
|
88 |
+
*
|
89 |
+
* @var bool $network
|
90 |
+
*/
|
91 |
+
public $network;
|
92 |
+
|
93 |
+
/**
|
94 |
+
* Plugin data.
|
95 |
+
*
|
96 |
+
* @var $plugin_data
|
97 |
+
*/
|
98 |
public $plugin_data;
|
99 |
|
100 |
/**
|
101 |
+
* Constructor for rt_plugin_info.
|
102 |
*
|
103 |
* @access public
|
104 |
*
|
105 |
+
* @param string $path Path.
|
|
|
106 |
*/
|
107 |
public function __construct( $path = null ) {
|
108 |
$this->set_current_plugin_path( $path );
|
110 |
}
|
111 |
|
112 |
/**
|
113 |
+
* Function to get plugin data.
|
114 |
*
|
115 |
* @access public
|
116 |
*
|
|
|
|
|
117 |
* @return array
|
118 |
*/
|
119 |
public function get_plugin_data() {
|
120 |
+
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
121 |
|
122 |
+
return @get_plugin_data( $this->plugin_path ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
|
123 |
}
|
124 |
|
125 |
/**
|
126 |
+
* Set plugin data.
|
127 |
*
|
128 |
* @access public
|
|
|
|
|
|
|
129 |
*/
|
130 |
public function set_plugin_data() {
|
131 |
$this->plugin_data = $this->get_plugin_data();
|
142 |
}
|
143 |
|
144 |
/**
|
145 |
+
* Set current plugin path.
|
146 |
*
|
147 |
* @access public
|
148 |
*
|
149 |
+
* @param string $path Path.
|
|
|
150 |
*/
|
151 |
public function set_current_plugin_path( $path ) {
|
152 |
if ( null !== $path ) {
|
app/helper/rtDimensions.php
CHANGED
@@ -1,19 +1,36 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
|
4 |
-
*
|
5 |
-
*
|
6 |
*/
|
7 |
|
8 |
/**
|
9 |
-
*
|
10 |
*
|
11 |
* @author udit
|
12 |
*/
|
13 |
-
class rtDimensions extends rtForm {
|
14 |
|
|
|
|
|
|
|
|
|
|
|
15 |
private $element_id;
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
private static $id_count = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
private static $default_class = 'rt-form-dimension';
|
18 |
|
19 |
/**
|
@@ -21,8 +38,6 @@ class rtDimensions extends rtForm {
|
|
21 |
*
|
22 |
* @access private
|
23 |
*
|
24 |
-
* @param void
|
25 |
-
*
|
26 |
* @return int $id_count
|
27 |
*/
|
28 |
private function get_default_id() {
|
@@ -33,10 +48,6 @@ class rtDimensions extends rtForm {
|
|
33 |
* Update default html id count.
|
34 |
*
|
35 |
* @access private
|
36 |
-
*
|
37 |
-
* @param void
|
38 |
-
*
|
39 |
-
* @return int $id_count
|
40 |
*/
|
41 |
private function update_default_id() {
|
42 |
self::$id_count ++;
|
@@ -47,8 +58,6 @@ class rtDimensions extends rtForm {
|
|
47 |
*
|
48 |
* @access private
|
49 |
*
|
50 |
-
* @param void
|
51 |
-
*
|
52 |
* @return string $default_class
|
53 |
*/
|
54 |
private function get_default_class() {
|
@@ -57,15 +66,16 @@ class rtDimensions extends rtForm {
|
|
57 |
|
58 |
|
59 |
/**
|
60 |
-
*
|
61 |
*
|
62 |
* @access private
|
63 |
*
|
64 |
-
* @param string $element
|
65 |
-
* @param null
|
66 |
*
|
67 |
* @return string
|
68 |
-
*
|
|
|
69 |
*/
|
70 |
private function embedd_class( $element, $class = null ) {
|
71 |
$html = 'class= "' . $this->get_default_class();
|
@@ -88,7 +98,7 @@ class rtDimensions extends rtForm {
|
|
88 |
*
|
89 |
* @access protected
|
90 |
*
|
91 |
-
* @param array $attributes
|
92 |
*
|
93 |
* @return string $html
|
94 |
*/
|
@@ -102,54 +112,53 @@ class rtDimensions extends rtForm {
|
|
102 |
);
|
103 |
|
104 |
$attributes = wp_parse_args( $attributes, $defaults );
|
105 |
-
extract( $attributes );
|
106 |
|
107 |
$html = '';
|
108 |
|
109 |
$html .= '<td>' .
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
if ( isset( $height ) ) {
|
121 |
$html .= '<td>' .
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
}
|
132 |
|
133 |
-
if ( isset( $crop ) ) {
|
134 |
$html .= '<td>' .
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
}
|
150 |
|
151 |
-
if ( $desc && $show_desc ) {
|
152 |
-
$html .= '<span class="clearfix large-offset-3 description">' . esc_html( $desc ) . '</span>';
|
153 |
}
|
154 |
|
155 |
if ( isset( $attributes['label'] ) ) {
|
@@ -164,16 +173,21 @@ class rtDimensions extends rtForm {
|
|
164 |
*
|
165 |
* @access public
|
166 |
*
|
167 |
-
* @param mixed $attributes
|
168 |
*
|
169 |
-
* @return
|
170 |
*/
|
171 |
public function get_dimensions( $attributes = '' ) {
|
172 |
return $this->generate_dimensions( $attributes );
|
173 |
}
|
174 |
|
|
|
|
|
|
|
|
|
|
|
175 |
public function display_dimensions( $args = '' ) {
|
176 |
-
echo $this->get_dimensions( $args );
|
177 |
}
|
178 |
|
179 |
}
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* File to include class rtDimensions
|
4 |
+
*
|
5 |
+
* @package rtMedia
|
6 |
*/
|
7 |
|
8 |
/**
|
9 |
+
* Class to handle rtMedia dimensions
|
10 |
*
|
11 |
* @author udit
|
12 |
*/
|
13 |
+
class rtDimensions extends rtForm { // phpcs:ignore PEAR.NamingConventions.ValidClassName.StartWithCapital, Generic.Classes.OpeningBraceSameLine.ContentAfterBrace
|
14 |
|
15 |
+
/**
|
16 |
+
* Element ID.
|
17 |
+
*
|
18 |
+
* @var $element_id
|
19 |
+
*/
|
20 |
private $element_id;
|
21 |
+
|
22 |
+
/**
|
23 |
+
* ID count.
|
24 |
+
*
|
25 |
+
* @var int $id_count
|
26 |
+
*/
|
27 |
private static $id_count = 0;
|
28 |
+
|
29 |
+
/**
|
30 |
+
* Default class.
|
31 |
+
*
|
32 |
+
* @var string $default_class
|
33 |
+
*/
|
34 |
private static $default_class = 'rt-form-dimension';
|
35 |
|
36 |
/**
|
38 |
*
|
39 |
* @access private
|
40 |
*
|
|
|
|
|
41 |
* @return int $id_count
|
42 |
*/
|
43 |
private function get_default_id() {
|
48 |
* Update default html id count.
|
49 |
*
|
50 |
* @access private
|
|
|
|
|
|
|
|
|
51 |
*/
|
52 |
private function update_default_id() {
|
53 |
self::$id_count ++;
|
58 |
*
|
59 |
* @access private
|
60 |
*
|
|
|
|
|
61 |
* @return string $default_class
|
62 |
*/
|
63 |
private function get_default_class() {
|
66 |
|
67 |
|
68 |
/**
|
69 |
+
* Embed html class to html output.
|
70 |
*
|
71 |
* @access private
|
72 |
*
|
73 |
+
* @param string $element element.
|
74 |
+
* @param null $class class.
|
75 |
*
|
76 |
* @return string
|
77 |
+
*
|
78 |
+
* @throws rtFormsInvalidArgumentsException Form invalid argument exception.
|
79 |
*/
|
80 |
private function embedd_class( $element, $class = null ) {
|
81 |
$html = 'class= "' . $this->get_default_class();
|
98 |
*
|
99 |
* @access protected
|
100 |
*
|
101 |
+
* @param array $attributes Attributes.
|
102 |
*
|
103 |
* @return string $html
|
104 |
*/
|
112 |
);
|
113 |
|
114 |
$attributes = wp_parse_args( $attributes, $defaults );
|
|
|
115 |
|
116 |
$html = '';
|
117 |
|
118 |
$html .= '<td>' .
|
119 |
+
parent::get_number(
|
120 |
+
array(
|
121 |
+
'name' => "rtmedia-options[{$attributes['key']}_width]",
|
122 |
+
'value' => $attributes['width'],
|
123 |
+
'class' => array( 'small-text large-offset-1' ),
|
124 |
+
'show_desc' => $attributes['show_desc'],
|
125 |
+
)
|
126 |
+
) .
|
127 |
+
'</td>';
|
128 |
+
|
129 |
+
if ( isset( $attributes['height'] ) ) {
|
130 |
$html .= '<td>' .
|
131 |
+
parent::get_number(
|
132 |
+
array(
|
133 |
+
'name' => "rtmedia-options[{$attributes['key']}_height]",
|
134 |
+
'value' => $attributes['height'],
|
135 |
+
'class' => array( 'small-text large-offset-1' ),
|
136 |
+
'show_desc' => $attributes['show_desc'],
|
137 |
+
)
|
138 |
+
) .
|
139 |
+
'</td>';
|
140 |
}
|
141 |
|
142 |
+
if ( isset( $attributes['crop'] ) ) {
|
143 |
$html .= '<td>' .
|
144 |
+
parent::get_switch(
|
145 |
+
array(
|
146 |
+
'name' => "rtmedia-options[{$attributes['key']}_crop]",
|
147 |
+
'rtForm_options' => array(
|
148 |
+
array(
|
149 |
+
'' => 1, // label would be blank.
|
150 |
+
'checked' => $attributes['crop'],
|
151 |
+
),
|
152 |
+
),
|
153 |
+
'value' => ( isset( $options[ "rtmedia-options[{$attributes['key']}_crop]" ] ) ) ? $options[ "rtmedia-options[{$attributes['key']}_crop]" ] : '0',
|
154 |
+
'show_desc' => $attributes['show_desc'],
|
155 |
+
)
|
156 |
+
) .
|
157 |
+
'</td>';
|
158 |
}
|
159 |
|
160 |
+
if ( $attributes['desc'] && $attributes['show_desc'] ) {
|
161 |
+
$html .= '<span class="clearfix large-offset-3 description">' . esc_html( $attributes['desc'] ) . '</span>';
|
162 |
}
|
163 |
|
164 |
if ( isset( $attributes['label'] ) ) {
|
173 |
*
|
174 |
* @access public
|
175 |
*
|
176 |
+
* @param mixed $attributes Attribute.
|
177 |
*
|
178 |
+
* @return string|null
|
179 |
*/
|
180 |
public function get_dimensions( $attributes = '' ) {
|
181 |
return $this->generate_dimensions( $attributes );
|
182 |
}
|
183 |
|
184 |
+
/**
|
185 |
+
* Display dimensions.
|
186 |
+
*
|
187 |
+
* @param string $args Arguments.
|
188 |
+
*/
|
189 |
public function display_dimensions( $args = '' ) {
|
190 |
+
echo wp_kses( $this->get_dimensions( $args ), RTMedia::expanded_allowed_tags() );
|
191 |
}
|
192 |
|
193 |
}
|
app/helper/rtForm.php
CHANGED
@@ -1,81 +1,88 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
/*
|
4 |
-
* To change this template, choose Tools | Templates
|
5 |
-
* and open the template in the editor.
|
6 |
-
*/
|
7 |
-
|
8 |
/**
|
9 |
-
*
|
10 |
-
*
|
11 |
-
* Usage Example :
|
12 |
-
*
|
13 |
-
* $obj = new rtForm();
|
14 |
-
*
|
15 |
-
* ----textbox test
|
16 |
-
* echo $obj->get_textbox(array(
|
17 |
-
* "id"=>"myid",
|
18 |
-
* "label" => "mylabel",
|
19 |
-
* "name"=>"myname",
|
20 |
-
* "value"=>"myval",
|
21 |
-
* "class"=> array("myclass")
|
22 |
-
* ))."\n";
|
23 |
-
*
|
24 |
-
*
|
25 |
-
* ----textarea test
|
26 |
-
* echo $obj->get_textarea(array(
|
27 |
-
* "id"=>"myid",
|
28 |
-
* "name"=>"myname",
|
29 |
-
* "value"=>"myval",
|
30 |
-
* "class"=> array("myclass")
|
31 |
-
* ))."\n";
|
32 |
-
*
|
33 |
-
*
|
34 |
-
* ----radio test
|
35 |
-
* echo $obj->get_radio(array(
|
36 |
-
* "id"=>"myid",
|
37 |
-
* "name"=>"myname",
|
38 |
-
* "class"=>array("myclass"),
|
39 |
-
* "rtForm_options"=>array(
|
40 |
-
* "op1"=>1,
|
41 |
-
* "op2"=>2,
|
42 |
-
* "op3"=>3
|
43 |
-
* )
|
44 |
-
* ))."\n";
|
45 |
-
* ----checkbox test
|
46 |
-
* echo $obj->get_checkbox(array(
|
47 |
-
* "id"=>"myid",
|
48 |
-
* "name"=>"myname",
|
49 |
-
* "class"=>array("myclass"),
|
50 |
-
* "rtForm_options"=>array(
|
51 |
-
* "op1"=>1,
|
52 |
-
* "op2"=>2,
|
53 |
-
* "op3"=>3
|
54 |
-
* )
|
55 |
-
* ))."\n";
|
56 |
-
* ----select test
|
57 |
-
* echo $obj->get_select(array(
|
58 |
-
* "id"=>"myid",
|
59 |
-
* "name"=>"myname",
|
60 |
-
* "class"=>array("myclass"),
|
61 |
-
* "rtForm_options"=>array(
|
62 |
-
* "op1"=>1,
|
63 |
-
* "op2"=>2,
|
64 |
-
* "op3"=>3
|
65 |
-
* )
|
66 |
-
* ))."\n";
|
67 |
*
|
68 |
-
* @
|
69 |
*/
|
|
|
70 |
if ( ! class_exists( 'rtForm' ) ) {
|
71 |
|
72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
|
|
|
|
|
|
|
|
|
|
|
74 |
private $element_id;
|
75 |
|
76 |
/**
|
77 |
-
*
|
78 |
* if id for any element is not given then these count will be used in id generation
|
|
|
|
|
79 |
*/
|
80 |
private static $id_counts = array(
|
81 |
'rtText' => 0,
|
@@ -92,6 +99,12 @@ if ( ! class_exists( 'rtForm' ) ) {
|
|
92 |
'rtFileInput' => 0,
|
93 |
'rtLink' => 0,
|
94 |
);
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
private static $default_classes = array(
|
96 |
'rtText' => 'rtm-form-text',
|
97 |
'rtFile' => 'rtm-form-file',
|
@@ -106,7 +119,6 @@ if ( ! class_exists( 'rtForm' ) ) {
|
|
106 |
'rtButton' => 'rtm-form-button',
|
107 |
'rtFileInput' => 'rtm-form-file-input',
|
108 |
'rtLink' => 'rtm-form-link',
|
109 |
-
|
110 |
);
|
111 |
|
112 |
/**
|
@@ -114,8 +126,9 @@ if ( ! class_exists( 'rtForm' ) ) {
|
|
114 |
*
|
115 |
* @access private
|
116 |
*
|
117 |
-
* @param string $element
|
118 |
*
|
|
|
119 |
*/
|
120 |
private function get_default_id( $element ) {
|
121 |
return self::$id_counts[ $element ];
|
@@ -126,8 +139,7 @@ if ( ! class_exists( 'rtForm' ) ) {
|
|
126 |
*
|
127 |
* @access private
|
128 |
*
|
129 |
-
* @param string $element
|
130 |
-
*
|
131 |
*/
|
132 |
private function update_default_id( $element ) {
|
133 |
self::$id_counts[ $element ] ++;
|
@@ -138,23 +150,25 @@ if ( ! class_exists( 'rtForm' ) ) {
|
|
138 |
*
|
139 |
* @access private
|
140 |
*
|
141 |
-
* @param string $element
|
142 |
*
|
|
|
143 |
*/
|
144 |
private function get_default_class( $element ) {
|
145 |
return self::$default_classes[ $element ];
|
146 |
}
|
147 |
|
148 |
/**
|
149 |
-
*
|
150 |
*
|
151 |
* @access private
|
152 |
*
|
153 |
-
* @param string $element
|
154 |
-
* @param array
|
155 |
*
|
156 |
* @return string $html
|
157 |
-
*
|
|
|
158 |
*/
|
159 |
private function embedd_class( $element, $class = null ) {
|
160 |
|
@@ -178,8 +192,8 @@ if ( ! class_exists( 'rtForm' ) ) {
|
|
178 |
*
|
179 |
* @access private
|
180 |
*
|
181 |
-
* @param string $element
|
182 |
-
* @param string $id
|
183 |
*
|
184 |
* @return string $html
|
185 |
*/
|
@@ -187,10 +201,10 @@ if ( ! class_exists( 'rtForm' ) ) {
|
|
187 |
|
188 |
$html = 'id="';
|
189 |
if ( isset( $id ) ) {
|
190 |
-
$html
|
191 |
$this->element_id = $id;
|
192 |
} else {
|
193 |
-
$html
|
194 |
$this->element_id = $this->get_default_class( $element ) . '-' . $this->get_default_id( $element );
|
195 |
$this->update_default_id( $element );
|
196 |
}
|
@@ -203,9 +217,9 @@ if ( ! class_exists( 'rtForm' ) ) {
|
|
203 |
*
|
204 |
* @access private
|
205 |
*
|
206 |
-
* @param string $element
|
207 |
-
* @param string $multiple
|
208 |
-
* @param string $name
|
209 |
*
|
210 |
* @return string $html
|
211 |
*/
|
@@ -216,7 +230,7 @@ if ( ! class_exists( 'rtForm' ) ) {
|
|
216 |
|
217 |
$html .= esc_attr( isset( $name ) ? $name . '[]' : $element . '[]' );
|
218 |
|
219 |
-
// for select - add multiple = multiple
|
220 |
if ( 'rtSelect' === $element ) {
|
221 |
$html .= 'multiple = "multiple"';
|
222 |
}
|
@@ -233,8 +247,8 @@ if ( ! class_exists( 'rtForm' ) ) {
|
|
233 |
*
|
234 |
* @access private
|
235 |
*
|
236 |
-
* @param string $element
|
237 |
-
* @param
|
238 |
*
|
239 |
* @return string $html
|
240 |
*/
|
@@ -242,10 +256,10 @@ if ( ! class_exists( 'rtForm' ) ) {
|
|
242 |
|
243 |
$html = '';
|
244 |
switch ( $element ) {
|
245 |
-
case 'rtHidden':
|
246 |
-
case 'rtNumber':
|
247 |
-
case 'rtText':
|
248 |
-
case 'rtButton':
|
249 |
case 'rtFile':
|
250 |
$html .= 'value="';
|
251 |
$html .= ( isset( $attributes['value'] ) ) ? esc_attr( $attributes['value'] ) : '';
|
@@ -253,17 +267,18 @@ if ( ! class_exists( 'rtForm' ) ) {
|
|
253 |
break;
|
254 |
|
255 |
case 'rtTextarea':
|
256 |
-
|
|
|
257 |
* no process --- handled in between the start tab and end tag.
|
258 |
* <textarea> value </textarea>
|
259 |
*/
|
260 |
break;
|
261 |
|
262 |
-
case 'rtCheckbox': //checkbox
|
263 |
-
case 'rtRadio': //radio
|
264 |
$html .= 'value = "' . esc_attr( $attributes['value'] ) . '">';
|
265 |
break;
|
266 |
-
case 'rtLink'
|
267 |
$html .= 'href = "' . esc_url( $attributes['href'] ) . '">';
|
268 |
break;
|
269 |
}
|
@@ -276,7 +291,7 @@ if ( ! class_exists( 'rtForm' ) ) {
|
|
276 |
*
|
277 |
* @access private
|
278 |
*
|
279 |
-
* @param
|
280 |
*
|
281 |
* @return string $html
|
282 |
*/
|
@@ -293,20 +308,20 @@ if ( ! class_exists( 'rtForm' ) ) {
|
|
293 |
}
|
294 |
|
295 |
/**
|
296 |
-
*
|
297 |
*
|
298 |
* @access private
|
299 |
*
|
300 |
-
* @param $misc
|
|
|
|
|
301 |
*
|
302 |
-
* @
|
303 |
-
* @throws rtFormInvalidArgumentsException
|
304 |
*/
|
305 |
private function embedd_misc_attributes( $misc ) {
|
306 |
|
307 |
if ( ! is_array( $misc ) ) {
|
308 |
throw new rtFormInvalidArgumentsException( 'attributes : misc' );
|
309 |
-
return;
|
310 |
}
|
311 |
|
312 |
$html = '';
|
@@ -323,28 +338,28 @@ if ( ! class_exists( 'rtForm' ) ) {
|
|
323 |
*
|
324 |
* @access private
|
325 |
*
|
326 |
-
* @param string $element
|
327 |
-
* @param mixed
|
328 |
-
* @param bool
|
329 |
*
|
330 |
* @return string $html
|
331 |
*/
|
332 |
-
private function
|
333 |
|
334 |
-
|
335 |
if ( isset( $attributes['id'] ) ) {
|
336 |
$html = $this->generate_element_id( $element, $attributes['id'] ) . ' ';
|
337 |
} else {
|
338 |
$html = $this->generate_element_id( $element ) . ' ';
|
339 |
}
|
340 |
|
341 |
-
|
342 |
$multiple = ( isset( $attributes['multiple'] ) && $attributes['multiple'] ) ? true : false;
|
343 |
$name = ( isset( $attributes['name'] ) ) ? $attributes['name'] : $element;
|
344 |
-
$html
|
345 |
|
346 |
-
|
347 |
-
*
|
348 |
* default class of rtForms will always be attached irrespective of the attributes provided.
|
349 |
*/
|
350 |
if ( ! $container ) {
|
@@ -366,25 +381,27 @@ if ( ! class_exists( 'rtForm' ) ) {
|
|
366 |
}
|
367 |
|
368 |
/**
|
369 |
-
*
|
370 |
*
|
371 |
* @access private
|
372 |
*
|
373 |
-
* @param string $element
|
374 |
-
* @param array
|
375 |
-
* @param array
|
376 |
*
|
377 |
* @return string $html
|
378 |
*/
|
379 |
-
private function container_enclosed_elements( $element, $attrib, $
|
|
|
|
|
|
|
|
|
380 |
|
381 |
-
$html = $id = '';
|
382 |
-
$size = count( $rtForm_options );
|
383 |
if ( isset( $attrib['id'] ) ) {
|
384 |
$id = $attrib['id'];
|
385 |
}
|
386 |
|
387 |
-
foreach ( $
|
388 |
|
389 |
if ( isset( $attrib['id'] ) && $size > 1 ) {
|
390 |
$attrib['id'] = $id . '-' . $this->get_default_id( $element );
|
@@ -422,22 +439,22 @@ if ( ! class_exists( 'rtForm' ) ) {
|
|
422 |
|
423 |
$data = '';
|
424 |
switch ( $element ) {
|
425 |
-
case 'rtRadio'
|
426 |
$data = '<input type="radio" ' . $checked . ' ';
|
427 |
break;
|
428 |
-
case 'rtCheckbox'
|
429 |
$data = '<input type="checkbox" ' . $checked . ' ' . $switch . ' ';
|
430 |
break;
|
431 |
-
case 'rtSelect'
|
432 |
$selected = ( $attrib['selected'] ) ? 'selected=selected' : '';
|
433 |
$data = '<option value="' . esc_attr( $attrib['value'] ) . '" ' . $selected . '>' . esc_html( $attrib['key'] ) . '</option>';
|
434 |
break;
|
435 |
}
|
436 |
|
437 |
if ( 'rtSelect' !== $element ) {
|
438 |
-
$data .= $this->
|
439 |
|
440 |
-
// span elements for checkbox on/off switch
|
441 |
if ( 'rtCheckbox' === $element ) {
|
442 |
$data .= '<span class="switch-label" data-on="On" data-off="Off"></span><span class="switch-handle"></span>';
|
443 |
}
|
@@ -473,15 +490,16 @@ if ( ! class_exists( 'rtForm' ) ) {
|
|
473 |
}
|
474 |
|
475 |
/**
|
476 |
-
*Parse multiple options in admin options.
|
477 |
*
|
478 |
* @access private
|
479 |
*
|
480 |
-
* @param $element
|
481 |
-
* @param $attributes
|
482 |
*
|
483 |
* @return array
|
484 |
-
*
|
|
|
485 |
*/
|
486 |
private function parse_multiple_options( $element, $attributes ) {
|
487 |
|
@@ -489,18 +507,21 @@ if ( ! class_exists( 'rtForm' ) ) {
|
|
489 |
|
490 |
if ( isset( $attributes['rtForm_options'] ) && is_array( $attributes['rtForm_options'] ) ) {
|
491 |
|
492 |
-
$
|
493 |
-
$attrib
|
494 |
|
495 |
-
foreach ( $
|
496 |
if ( 'rtForm_options' !== $key ) {
|
497 |
$attrib[ $key ] = $attributes[ $key ];
|
498 |
}
|
499 |
}
|
500 |
|
501 |
-
$
|
502 |
|
503 |
-
return array(
|
|
|
|
|
|
|
504 |
} else {
|
505 |
throw new rtFormInvalidArgumentsException( 'rtForm_options [' . $element . ']' );
|
506 |
}
|
@@ -514,21 +535,22 @@ if ( ! class_exists( 'rtForm' ) ) {
|
|
514 |
*
|
515 |
* @access protected
|
516 |
*
|
517 |
-
* @param $element
|
518 |
-
* @param $html
|
519 |
-
* @param $label
|
520 |
-
* @param bool $class
|
521 |
*
|
522 |
* @return string
|
523 |
*/
|
524 |
protected function enclose_label( $element, $html, $label, $class = false ) {
|
525 |
|
526 |
-
$
|
|
|
527 |
if ( ! empty( $class ) && is_array( $class ) ) {
|
528 |
-
$
|
529 |
}
|
530 |
|
531 |
-
$data = '<label for="' . esc_attr( $this->element_id ) . '" ' . $
|
532 |
|
533 |
if ( 'rtRadio' === $element || 'rtCheckbox' === $element ) {
|
534 |
$data .= $html . ' ' . $label;
|
@@ -546,23 +568,24 @@ if ( ! class_exists( 'rtForm' ) ) {
|
|
546 |
*
|
547 |
* @access protected
|
548 |
*
|
549 |
-
* @param $attributes
|
550 |
*
|
551 |
* @return string
|
552 |
-
*
|
|
|
553 |
*/
|
554 |
protected function generate_textbox( $attributes ) {
|
555 |
|
556 |
$element = 'rtText';
|
557 |
if ( is_array( $attributes ) ) {
|
558 |
|
559 |
-
|
560 |
$html = '<input type="text" ';
|
561 |
|
562 |
-
|
563 |
-
$html .= $this->
|
564 |
|
565 |
-
|
566 |
$html .= ' />';
|
567 |
|
568 |
if ( isset( $attributes['label'] ) ) {
|
@@ -601,17 +624,17 @@ if ( ! class_exists( 'rtForm' ) ) {
|
|
601 |
// Adding nonce for file upload.
|
602 |
$nonce = wp_create_nonce( 'rtmedia-admin-upload' );
|
603 |
|
604 |
-
|
605 |
$html = '<button class="rtm-form-button button button-primary button-small">Browse File</button>';
|
606 |
|
607 |
-
|
608 |
$html .= '<input type="hidden" id="rtmedia_admin_upload_nonce" value="' . esc_attr( $nonce ) . '" />';
|
609 |
$html .= '<input type="file" ';
|
610 |
|
611 |
-
|
612 |
-
$html .= $this->
|
613 |
|
614 |
-
|
615 |
$html .= ' />';
|
616 |
|
617 |
if ( ! empty( $attributes['name'] ) && ! empty( $attributes['value'] ) ) {
|
@@ -656,18 +679,24 @@ if ( ! class_exists( 'rtForm' ) ) {
|
|
656 |
*
|
657 |
* @access public
|
658 |
*
|
659 |
-
* @param string
|
660 |
*
|
661 |
* @return string
|
662 |
-
*
|
|
|
663 |
*/
|
664 |
public function get_textbox( $attributes = '' ) {
|
665 |
|
666 |
return $this->generate_textbox( $attributes );
|
667 |
}
|
668 |
|
|
|
|
|
|
|
|
|
|
|
669 |
public function display_textbox( $args = '' ) {
|
670 |
-
echo $this->get_textbox( $args );
|
671 |
}
|
672 |
|
673 |
/**
|
@@ -675,10 +704,11 @@ if ( ! class_exists( 'rtForm' ) ) {
|
|
675 |
*
|
676 |
* @access protected
|
677 |
*
|
678 |
-
* @param $attributes
|
679 |
*
|
680 |
* @return string
|
681 |
-
*
|
|
|
682 |
*/
|
683 |
protected function generate_link( $attributes ) {
|
684 |
|
@@ -689,7 +719,7 @@ if ( ! class_exists( 'rtForm' ) ) {
|
|
689 |
$html = '<a ';
|
690 |
|
691 |
// Generating attributes.
|
692 |
-
$html .= $this->
|
693 |
|
694 |
// Put text of link.
|
695 |
$html .= esc_html( ( isset( $attributes['text'] ) ) ? $attributes['text'] : '' );
|
@@ -720,18 +750,26 @@ if ( ! class_exists( 'rtForm' ) ) {
|
|
720 |
*
|
721 |
* @access public
|
722 |
*
|
723 |
-
* @param string
|
724 |
*
|
725 |
* @return string
|
726 |
-
*
|
|
|
727 |
*/
|
728 |
public function get_link( $attributes = '' ) {
|
729 |
|
730 |
return $this->generate_link( $attributes );
|
731 |
}
|
732 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
733 |
public function display_link( $args = '' ) {
|
734 |
-
echo $this->get_link( $args );
|
735 |
}
|
736 |
|
737 |
/**
|
@@ -742,6 +780,8 @@ if ( ! class_exists( 'rtForm' ) ) {
|
|
742 |
* @param string|array $attributes Arguments to create file input control.
|
743 |
*
|
744 |
* @return string
|
|
|
|
|
745 |
*/
|
746 |
public function get_inputfile( $attributes = '' ) {
|
747 |
return $this->generate_inputfile( $attributes );
|
@@ -753,11 +793,11 @@ if ( ! class_exists( 'rtForm' ) ) {
|
|
753 |
*
|
754 |
* @param string|array $args Arguments to create file input control.
|
755 |
*
|
756 |
-
* @throws rtFormInvalidArgumentsException Invalid
|
757 |
*/
|
758 |
public function display_inputfile( $args = '' ) {
|
759 |
// Previously escaped and sanitized so not required here.
|
760 |
-
echo $this->get_inputfile( $args )
|
761 |
}
|
762 |
|
763 |
/**
|
@@ -765,21 +805,22 @@ if ( ! class_exists( 'rtForm' ) ) {
|
|
765 |
*
|
766 |
* @access protected
|
767 |
*
|
768 |
-
* @param $attributes
|
769 |
*
|
770 |
* @return string
|
771 |
-
*
|
|
|
772 |
*/
|
773 |
protected function generate_number( $attributes ) {
|
774 |
|
775 |
$element = 'rtNumber';
|
776 |
if ( is_array( $attributes ) ) {
|
777 |
|
778 |
-
|
779 |
$html = '<input type="number" ';
|
780 |
|
781 |
-
|
782 |
-
$html .= $this->
|
783 |
if ( isset( $attributes['min'] ) ) {
|
784 |
$html .= " min='" . esc_attr( $attributes['min'] ) . "' ";
|
785 |
}
|
@@ -790,7 +831,7 @@ if ( ! class_exists( 'rtForm' ) ) {
|
|
790 |
$html .= " step='" . esc_attr( $attributes['step'] ) . "' ";
|
791 |
}
|
792 |
|
793 |
-
|
794 |
$html .= ' />';
|
795 |
|
796 |
if ( isset( $attributes['label'] ) ) {
|
@@ -816,17 +857,26 @@ if ( ! class_exists( 'rtForm' ) ) {
|
|
816 |
*
|
817 |
* @access public
|
818 |
*
|
819 |
-
* @param string
|
820 |
*
|
821 |
* @return string
|
|
|
|
|
822 |
*/
|
823 |
public function get_number( $attributes = '' ) {
|
824 |
|
825 |
return $this->generate_number( $attributes );
|
826 |
}
|
827 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
828 |
public function display_number( $args = '' ) {
|
829 |
-
echo $this->get_number( $args );
|
830 |
}
|
831 |
|
832 |
/**
|
@@ -834,10 +884,10 @@ if ( ! class_exists( 'rtForm' ) ) {
|
|
834 |
*
|
835 |
* @access protected
|
836 |
*
|
837 |
-
* @param $attributes
|
838 |
*
|
839 |
* @return string
|
840 |
-
* @throws rtFormInvalidArgumentsException
|
841 |
*/
|
842 |
protected function generate_date( $attributes ) {
|
843 |
|
@@ -845,7 +895,7 @@ if ( ! class_exists( 'rtForm' ) ) {
|
|
845 |
if ( is_array( $attributes ) ) {
|
846 |
$html = '<input type="date" ';
|
847 |
|
848 |
-
$html .= $this->
|
849 |
|
850 |
$html .= ' />';
|
851 |
|
@@ -872,9 +922,11 @@ if ( ! class_exists( 'rtForm' ) ) {
|
|
872 |
*
|
873 |
* @access public
|
874 |
*
|
875 |
-
* @param array $attributes
|
876 |
*
|
877 |
* @return string
|
|
|
|
|
878 |
*/
|
879 |
public function get_date( $attributes ) {
|
880 |
return $this->generate_date( $attributes );
|
@@ -885,23 +937,23 @@ if ( ! class_exists( 'rtForm' ) ) {
|
|
885 |
*
|
886 |
* @access protected
|
887 |
*
|
888 |
-
* @param $attributes
|
889 |
*
|
890 |
* @return string
|
891 |
-
* @throws rtFormInvalidArgumentsException
|
892 |
*/
|
893 |
protected function generate_hidden( $attributes ) {
|
894 |
|
895 |
$element = 'rtHidden';
|
896 |
if ( is_array( $attributes ) ) {
|
897 |
|
898 |
-
|
899 |
$html = '<input type="hidden" ';
|
900 |
|
901 |
-
|
902 |
-
$html .= $this->
|
903 |
|
904 |
-
|
905 |
$html .= ' />';
|
906 |
|
907 |
if ( isset( $attributes['label'] ) ) {
|
@@ -927,9 +979,10 @@ if ( ! class_exists( 'rtForm' ) ) {
|
|
927 |
*
|
928 |
* @access public
|
929 |
*
|
930 |
-
* @param string
|
931 |
*
|
932 |
* @return string
|
|
|
933 |
*/
|
934 |
public function get_hidden( $attributes = '' ) {
|
935 |
|
@@ -941,18 +994,18 @@ if ( ! class_exists( 'rtForm' ) ) {
|
|
941 |
*
|
942 |
* @access protected
|
943 |
*
|
944 |
-
* @param $attributes
|
945 |
*
|
946 |
* @return string
|
947 |
-
* @throws rtFormInvalidArgumentsException
|
948 |
*/
|
949 |
protected function generate_textarea( $attributes ) {
|
950 |
|
951 |
$element = 'rtTextarea';
|
952 |
if ( is_array( $attributes ) ) {
|
953 |
|
954 |
-
$html
|
955 |
-
$html .= $this->
|
956 |
$html .= '>';
|
957 |
|
958 |
$html .= esc_html( ( isset( $attributes['value'] ) ) ? $attributes['value'] : '' );
|
@@ -982,68 +1035,44 @@ if ( ! class_exists( 'rtForm' ) ) {
|
|
982 |
*
|
983 |
* @access public
|
984 |
*
|
985 |
-
* @param string
|
986 |
*
|
987 |
* @return string
|
|
|
988 |
*/
|
989 |
public function get_textarea( $attributes = '' ) {
|
990 |
|
991 |
return $this->generate_textarea( $attributes );
|
992 |
}
|
993 |
|
994 |
-
|
995 |
-
|
996 |
-
}
|
997 |
-
|
998 |
-
/* wysiwyg
|
999 |
-
*
|
1000 |
-
* pending as of now.
|
1001 |
*
|
1002 |
-
*
|
1003 |
*
|
1004 |
-
*
|
1005 |
-
|
1006 |
-
|
1007 |
-
$
|
1008 |
-
if( is_array($attributes) ) {
|
1009 |
-
|
1010 |
-
$id = isset( $attributes['id'] ) ? $attributes['id'] : $this->get_default_class($element) . "-" . $this->get_default_id($element);
|
1011 |
-
$name = isset( $attributes['name'] ) ? $attributes['name'] : $element;
|
1012 |
-
if(isset($attributes['class']))
|
1013 |
-
$class = $this->embedd_class($element, $attributes['class']);
|
1014 |
-
else
|
1015 |
-
$class = $this->embedd_class($element);
|
1016 |
-
$value = isset( $attributes['value'] ) ? $attributes['value'] : "";
|
1017 |
-
|
1018 |
-
echo '<label for="' . $id . '">';
|
1019 |
-
wp_editor( $value, $id, array('textarea_name' => $name, 'editor_class' => $class) );
|
1020 |
-
echo '</label>';
|
1021 |
-
} else
|
1022 |
-
throw new rtFormInvalidArgumentsException( "attributes" );
|
1023 |
}
|
1024 |
|
1025 |
-
public function get_wysiwyg( $attributes = '' ) {
|
1026 |
-
|
1027 |
-
ob_start();
|
1028 |
-
$this->generate_wysiwyg($attributes);
|
1029 |
-
return ob_get_clean();
|
1030 |
-
}*/
|
1031 |
-
|
1032 |
/**
|
1033 |
* Generate rtmedia html input type radio in admin options.
|
1034 |
*
|
1035 |
* @access protected
|
1036 |
*
|
1037 |
-
* @param array $attributes
|
1038 |
*
|
1039 |
* @return string $container
|
|
|
|
|
1040 |
*/
|
1041 |
protected function generate_radio( $attributes ) {
|
1042 |
|
1043 |
$element = 'rtRadio';
|
1044 |
$html = '';
|
1045 |
|
1046 |
-
$meta
|
1047 |
$html .= $this->container_enclosed_elements( $element, $meta['attrib'], $meta['rtForm_options'] );
|
1048 |
|
1049 |
if ( isset( $attributes['show_desc'] ) && $attributes['show_desc'] ) {
|
@@ -1070,17 +1099,26 @@ if ( ! class_exists( 'rtForm' ) ) {
|
|
1070 |
*
|
1071 |
* @access public
|
1072 |
*
|
1073 |
-
* @param string
|
1074 |
*
|
1075 |
* @return string
|
|
|
|
|
1076 |
*/
|
1077 |
public function get_radio( $attributes = '' ) {
|
1078 |
|
1079 |
return $this->generate_radio( $attributes );
|
1080 |
}
|
1081 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1082 |
public function display_radio( $args = '' ) {
|
1083 |
-
echo $this->get_radio( $args );
|
1084 |
}
|
1085 |
|
1086 |
/**
|
@@ -1088,16 +1126,18 @@ if ( ! class_exists( 'rtForm' ) ) {
|
|
1088 |
*
|
1089 |
* @access protected
|
1090 |
*
|
1091 |
-
* @param array $attributes
|
1092 |
*
|
1093 |
* @return string $container
|
|
|
|
|
1094 |
*/
|
1095 |
protected function generate_checkbox( $attributes ) {
|
1096 |
|
1097 |
$element = 'rtCheckbox';
|
1098 |
$html = '';
|
1099 |
|
1100 |
-
$meta
|
1101 |
$html .= $this->container_enclosed_elements( $element, $meta['attrib'], $meta['rtForm_options'] );
|
1102 |
|
1103 |
if ( isset( $attributes['show_desc'] ) && $attributes['show_desc'] ) {
|
@@ -1124,7 +1164,7 @@ if ( ! class_exists( 'rtForm' ) ) {
|
|
1124 |
*
|
1125 |
* @access public
|
1126 |
*
|
1127 |
-
* @param string
|
1128 |
*
|
1129 |
* @return string
|
1130 |
*/
|
@@ -1138,7 +1178,7 @@ if ( ! class_exists( 'rtForm' ) ) {
|
|
1138 |
*
|
1139 |
* @access public
|
1140 |
*
|
1141 |
-
* @param string
|
1142 |
*
|
1143 |
* @return string
|
1144 |
*/
|
@@ -1149,8 +1189,13 @@ if ( ! class_exists( 'rtForm' ) ) {
|
|
1149 |
return $this->generate_checkbox( $attributes );
|
1150 |
}
|
1151 |
|
|
|
|
|
|
|
|
|
|
|
1152 |
public function display_switch( $args = '' ) {
|
1153 |
-
echo $this->get_switch( $args );
|
1154 |
}
|
1155 |
|
1156 |
/**
|
@@ -1158,7 +1203,7 @@ if ( ! class_exists( 'rtForm' ) ) {
|
|
1158 |
*
|
1159 |
* @access public
|
1160 |
*
|
1161 |
-
* @param string
|
1162 |
*
|
1163 |
* @return string
|
1164 |
*/
|
@@ -1174,10 +1219,10 @@ if ( ! class_exists( 'rtForm' ) ) {
|
|
1174 |
*
|
1175 |
* @access protected
|
1176 |
*
|
1177 |
-
* @param $attributes
|
1178 |
*
|
1179 |
* @return string
|
1180 |
-
* @throws rtFormInvalidArgumentsException
|
1181 |
*/
|
1182 |
protected function generate_select( $attributes ) {
|
1183 |
|
@@ -1191,10 +1236,10 @@ if ( ! class_exists( 'rtForm' ) ) {
|
|
1191 |
$id = $element . $this->get_default_id( $element );
|
1192 |
$this->update_default_id( $element );
|
1193 |
}
|
1194 |
-
$html
|
1195 |
$multiple = ( isset( $attributes['multiple'] ) && $attributes['multiple'] ) ? true : false;
|
1196 |
$name = ( isset( $attributes['name'] ) ) ? $attributes['name'] : $element;
|
1197 |
-
$html
|
1198 |
if ( isset( $attributes['class'] ) ) {
|
1199 |
$html .= $this->embedd_class( $element, $attributes['class'] );
|
1200 |
} else {
|
@@ -1207,7 +1252,7 @@ if ( ! class_exists( 'rtForm' ) ) {
|
|
1207 |
|
1208 |
$html .= '>';
|
1209 |
|
1210 |
-
$meta
|
1211 |
$html .= $this->container_enclosed_elements( $element, $meta['attrib'], $meta['rtForm_options'] );
|
1212 |
|
1213 |
$html .= '</select>';
|
@@ -1235,17 +1280,26 @@ if ( ! class_exists( 'rtForm' ) ) {
|
|
1235 |
*
|
1236 |
* @access public
|
1237 |
*
|
1238 |
-
* @param string
|
1239 |
*
|
1240 |
* @return string
|
|
|
|
|
1241 |
*/
|
1242 |
public function get_select( $attributes = '' ) {
|
1243 |
|
1244 |
return $this->generate_select( $attributes );
|
1245 |
}
|
1246 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1247 |
public function display_select( $args = '' ) {
|
1248 |
-
echo $this->get_select( $args );
|
1249 |
}
|
1250 |
|
1251 |
/**
|
@@ -1253,10 +1307,10 @@ if ( ! class_exists( 'rtForm' ) ) {
|
|
1253 |
*
|
1254 |
* @access protected
|
1255 |
*
|
1256 |
-
* @param array $attributes attributes for button control in key => value
|
1257 |
*
|
1258 |
* @return string
|
1259 |
-
* @throws rtFormInvalidArgumentsException
|
1260 |
*/
|
1261 |
protected function generate_button( $attributes ) {
|
1262 |
|
@@ -1266,13 +1320,13 @@ if ( ! class_exists( 'rtForm' ) ) {
|
|
1266 |
|
1267 |
$element = 'rtButton';
|
1268 |
|
1269 |
-
|
1270 |
$html = '<input type="button" ';
|
1271 |
|
1272 |
-
|
1273 |
-
$html .= $this->
|
1274 |
|
1275 |
-
|
1276 |
$html .= ' />';
|
1277 |
|
1278 |
if ( isset( $attributes['label'] ) ) {
|
@@ -1295,10 +1349,10 @@ if ( ! class_exists( 'rtForm' ) ) {
|
|
1295 |
*
|
1296 |
* @access public
|
1297 |
*
|
1298 |
-
* @param string
|
1299 |
*
|
1300 |
* @return string
|
1301 |
-
* @throws rtFormInvalidArgumentsException
|
1302 |
*/
|
1303 |
public function get_button( $attributes ) {
|
1304 |
|
@@ -1308,13 +1362,12 @@ if ( ! class_exists( 'rtForm' ) ) {
|
|
1308 |
/**
|
1309 |
* Prints the HTML for button control based on arguments
|
1310 |
*
|
1311 |
-
* @param array $args arguments for button control
|
1312 |
*
|
1313 |
-
* @throws rtFormInvalidArgumentsException
|
1314 |
*/
|
1315 |
public function display_button( $args ) {
|
1316 |
-
|
1317 |
-
echo $this->get_button( $args ); // WPCS: XSS ok.
|
1318 |
}
|
1319 |
|
1320 |
/**
|
@@ -1322,10 +1375,10 @@ if ( ! class_exists( 'rtForm' ) ) {
|
|
1322 |
*
|
1323 |
* @access protected
|
1324 |
*
|
1325 |
-
* @param array $attributes arguments to create file input control
|
1326 |
*
|
1327 |
* @return string
|
1328 |
-
* @throws rtFormInvalidArgumentsException
|
1329 |
*/
|
1330 |
protected function generate_file_input( $attributes ) {
|
1331 |
|
@@ -1338,17 +1391,17 @@ if ( ! class_exists( 'rtForm' ) ) {
|
|
1338 |
// Adding nonce for file upload.
|
1339 |
$nonce = wp_create_nonce( 'rtmedia-admin-upload' );
|
1340 |
|
1341 |
-
|
1342 |
-
|
1343 |
|
1344 |
-
|
1345 |
$html .= '<input type="hidden" id="rtmedia_admin_upload_nonce" value="' . esc_attr( $nonce ) . '" />';
|
1346 |
$html .= '<input type="file" ';
|
1347 |
|
1348 |
-
|
1349 |
-
$html .= $this->
|
1350 |
|
1351 |
-
|
1352 |
$html .= ' />';
|
1353 |
|
1354 |
if ( isset( $attributes['label'] ) ) {
|
@@ -1371,10 +1424,10 @@ if ( ! class_exists( 'rtForm' ) ) {
|
|
1371 |
*
|
1372 |
* @access public
|
1373 |
*
|
1374 |
-
* @param string/array $attributes
|
1375 |
*
|
1376 |
* @return string
|
1377 |
-
* @throws rtFormInvalidArgumentsException
|
1378 |
*/
|
1379 |
public function get_file_input( $attributes ) {
|
1380 |
|
@@ -1382,13 +1435,14 @@ if ( ! class_exists( 'rtForm' ) ) {
|
|
1382 |
}
|
1383 |
|
1384 |
/**
|
1385 |
-
*
|
1386 |
*
|
1387 |
-
* @
|
|
|
|
|
1388 |
*/
|
1389 |
public function display_file_input( $args ) {
|
1390 |
-
|
1391 |
-
echo $this->get_file_input( $args ); // WPCS: XSS ok.
|
1392 |
}
|
1393 |
}
|
1394 |
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
+
* File to include rtForm class
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
*
|
5 |
+
* @package rtMedia
|
6 |
*/
|
7 |
+
|
8 |
if ( ! class_exists( 'rtForm' ) ) {
|
9 |
|
10 |
+
/**
|
11 |
+
* Class to handle rtMedia form elements
|
12 |
+
*
|
13 |
+
* Usage Example :
|
14 |
+
*
|
15 |
+
* $obj = new rtForm();
|
16 |
+
*
|
17 |
+
* ----textbox test
|
18 |
+
* echo $obj->get_textbox(array(
|
19 |
+
* "id"=>"myid",
|
20 |
+
* "label" => "mylabel",
|
21 |
+
* "name"=>"myname",
|
22 |
+
* "value"=>"myval",
|
23 |
+
* "class"=> array("myclass")
|
24 |
+
* ))."\n";
|
25 |
+
*
|
26 |
+
*
|
27 |
+
* ----textarea test
|
28 |
+
* echo $obj->get_textarea(array(
|
29 |
+
* "id"=>"myid",
|
30 |
+
* "name"=>"myname",
|
31 |
+
* "value"=>"myval",
|
32 |
+
* "class"=> array("myclass")
|
33 |
+
* ))."\n";
|
34 |
+
*
|
35 |
+
*
|
36 |
+
* ----radio test
|
37 |
+
* echo $obj->get_radio(array(
|
38 |
+
* "id"=>"myid",
|
39 |
+
* "name"=>"myname",
|
40 |
+
* "class"=>array("myclass"),
|
41 |
+
* "rtForm_options"=>array(
|
42 |
+
* "op1"=>1,
|
43 |
+
* "op2"=>2,
|
44 |
+
* "op3"=>3
|
45 |
+
* )
|
46 |
+
* ))."\n";
|
47 |
+
* ----checkbox test
|
48 |
+
* echo $obj->get_checkbox(array(
|
49 |
+
* "id"=>"myid",
|
50 |
+
* "name"=>"myname",
|
51 |
+
* "class"=>array("myclass"),
|
52 |
+
* "rtForm_options"=>array(
|
53 |
+
* "op1"=>1,
|
54 |
+
* "op2"=>2,
|
55 |
+
* "op3"=>3
|
56 |
+
* )
|
57 |
+
* ))."\n";
|
58 |
+
* ----select test
|
59 |
+
* echo $obj->get_select(array(
|
60 |
+
* "id"=>"myid",
|
61 |
+
* "name"=>"myname",
|
62 |
+
* "class"=>array("myclass"),
|
63 |
+
* "rtForm_options"=>array(
|
64 |
+
* "op1"=>1,
|
65 |
+
* "op2"=>2,
|
66 |
+
* "op3"=>3
|
67 |
+
* )
|
68 |
+
* ))."\n";
|
69 |
+
*
|
70 |
+
* @author udit
|
71 |
+
*/
|
72 |
+
class rtForm { // phpcs:ignore PEAR.NamingConventions.ValidClassName.StartWithCapital, Generic.Classes.OpeningBraceSameLine.ContentAfterBrace
|
73 |
|
74 |
+
/**
|
75 |
+
* Element ID.
|
76 |
+
*
|
77 |
+
* @var $element_id
|
78 |
+
*/
|
79 |
private $element_id;
|
80 |
|
81 |
/**
|
82 |
+
* Default id counts
|
83 |
* if id for any element is not given then these count will be used in id generation
|
84 |
+
*
|
85 |
+
* @var array $id_counts
|
86 |
*/
|
87 |
private static $id_counts = array(
|
88 |
'rtText' => 0,
|
99 |
'rtFileInput' => 0,
|
100 |
'rtLink' => 0,
|
101 |
);
|
102 |
+
|
103 |
+
/**
|
104 |
+
* Default classes.
|
105 |
+
*
|
106 |
+
* @var array $default_classes
|
107 |
+
*/
|
108 |
private static $default_classes = array(
|
109 |
'rtText' => 'rtm-form-text',
|
110 |
'rtFile' => 'rtm-form-file',
|
119 |
'rtButton' => 'rtm-form-button',
|
120 |
'rtFileInput' => 'rtm-form-file-input',
|
121 |
'rtLink' => 'rtm-form-link',
|
|
|
122 |
);
|
123 |
|
124 |
/**
|
126 |
*
|
127 |
* @access private
|
128 |
*
|
129 |
+
* @param string $element element.
|
130 |
*
|
131 |
+
* @return mixed
|
132 |
*/
|
133 |
private function get_default_id( $element ) {
|
134 |
return self::$id_counts[ $element ];
|
139 |
*
|
140 |
* @access private
|
141 |
*
|
142 |
+
* @param string $element element.
|
|
|
143 |
*/
|
144 |
private function update_default_id( $element ) {
|
145 |
self::$id_counts[ $element ] ++;
|
150 |
*
|
151 |
* @access private
|
152 |
*
|
153 |
+
* @param string $element element.
|
154 |
*
|
155 |
+
* @return mixed
|
156 |
*/
|
157 |
private function get_default_class( $element ) {
|
158 |
return self::$default_classes[ $element ];
|
159 |
}
|
160 |
|
161 |
/**
|
162 |
+
* Embed html class to html output.
|
163 |
*
|
164 |
* @access private
|
165 |
*
|
166 |
+
* @param string $element Element.
|
167 |
+
* @param array $class Class.
|
168 |
*
|
169 |
* @return string $html
|
170 |
+
*
|
171 |
+
* @throws rtFormInvalidArgumentsException Exception on invalid argument.
|
172 |
*/
|
173 |
private function embedd_class( $element, $class = null ) {
|
174 |
|
192 |
*
|
193 |
* @access private
|
194 |
*
|
195 |
+
* @param string $element Element.
|
196 |
+
* @param string $id Id.
|
197 |
*
|
198 |
* @return string $html
|
199 |
*/
|
201 |
|
202 |
$html = 'id="';
|
203 |
if ( isset( $id ) ) {
|
204 |
+
$html .= esc_attr( $id ) . '"';
|
205 |
$this->element_id = $id;
|
206 |
} else {
|
207 |
+
$html .= esc_attr( $this->get_default_class( $element ) . '-' . $this->get_default_id( $element ) ) . '"';
|
208 |
$this->element_id = $this->get_default_class( $element ) . '-' . $this->get_default_id( $element );
|
209 |
$this->update_default_id( $element );
|
210 |
}
|
217 |
*
|
218 |
* @access private
|
219 |
*
|
220 |
+
* @param string $element Element.
|
221 |
+
* @param string $multiple Multiple or not.
|
222 |
+
* @param string $name Name.
|
223 |
*
|
224 |
* @return string $html
|
225 |
*/
|
230 |
|
231 |
$html .= esc_attr( isset( $name ) ? $name . '[]' : $element . '[]' );
|
232 |
|
233 |
+
// for select - add multiple = multiple.
|
234 |
if ( 'rtSelect' === $element ) {
|
235 |
$html .= 'multiple = "multiple"';
|
236 |
}
|
247 |
*
|
248 |
* @access private
|
249 |
*
|
250 |
+
* @param string $element Elements.
|
251 |
+
* @param array $attributes Attributes.
|
252 |
*
|
253 |
* @return string $html
|
254 |
*/
|
256 |
|
257 |
$html = '';
|
258 |
switch ( $element ) {
|
259 |
+
case 'rtHidden': // hidden.
|
260 |
+
case 'rtNumber': // number.
|
261 |
+
case 'rtText': // text.
|
262 |
+
case 'rtButton': // button.
|
263 |
case 'rtFile':
|
264 |
$html .= 'value="';
|
265 |
$html .= ( isset( $attributes['value'] ) ) ? esc_attr( $attributes['value'] ) : '';
|
267 |
break;
|
268 |
|
269 |
case 'rtTextarea':
|
270 |
+
/**
|
271 |
+
* Textarea
|
272 |
* no process --- handled in between the start tab and end tag.
|
273 |
* <textarea> value </textarea>
|
274 |
*/
|
275 |
break;
|
276 |
|
277 |
+
case 'rtCheckbox': // checkbox.
|
278 |
+
case 'rtRadio': // radio.
|
279 |
$html .= 'value = "' . esc_attr( $attributes['value'] ) . '">';
|
280 |
break;
|
281 |
+
case 'rtLink': // radio.
|
282 |
$html .= 'href = "' . esc_url( $attributes['href'] ) . '">';
|
283 |
break;
|
284 |
}
|
291 |
*
|
292 |
* @access private
|
293 |
*
|
294 |
+
* @param array $attributes Attributes array.
|
295 |
*
|
296 |
* @return string $html
|
297 |
*/
|
308 |
}
|
309 |
|
310 |
/**
|
311 |
+
* Embed html misc attributes in admin options.
|
312 |
*
|
313 |
* @access private
|
314 |
*
|
315 |
+
* @param array $misc Misc.
|
316 |
+
*
|
317 |
+
* @return string|null
|
318 |
*
|
319 |
+
* @throws rtFormInvalidArgumentsException Throw invalid arguments exception.
|
|
|
320 |
*/
|
321 |
private function embedd_misc_attributes( $misc ) {
|
322 |
|
323 |
if ( ! is_array( $misc ) ) {
|
324 |
throw new rtFormInvalidArgumentsException( 'attributes : misc' );
|
|
|
325 |
}
|
326 |
|
327 |
$html = '';
|
338 |
*
|
339 |
* @access private
|
340 |
*
|
341 |
+
* @param string $element Element.
|
342 |
+
* @param mixed $attributes Attributes.
|
343 |
+
* @param bool $container Container.
|
344 |
*
|
345 |
* @return string $html
|
346 |
*/
|
347 |
+
private function process_attributes( $element, $attributes, $container = false ) {
|
348 |
|
349 |
+
// generating the id on its own if not provided otherwise taken from the parameter provided.
|
350 |
if ( isset( $attributes['id'] ) ) {
|
351 |
$html = $this->generate_element_id( $element, $attributes['id'] ) . ' ';
|
352 |
} else {
|
353 |
$html = $this->generate_element_id( $element ) . ' ';
|
354 |
}
|
355 |
|
356 |
+
// name attribute according to multiple flag.
|
357 |
$multiple = ( isset( $attributes['multiple'] ) && $attributes['multiple'] ) ? true : false;
|
358 |
$name = ( isset( $attributes['name'] ) ) ? $attributes['name'] : $element;
|
359 |
+
$html .= $this->generate_element_name( $element, $multiple, $name ) . ' ';
|
360 |
|
361 |
+
/**
|
362 |
+
* List down all the classes provided along with the default class of rtForms.
|
363 |
* default class of rtForms will always be attached irrespective of the attributes provided.
|
364 |
*/
|
365 |
if ( ! $container ) {
|
381 |
}
|
382 |
|
383 |
/**
|
384 |
+
* Container enclosed elements in admin options.
|
385 |
*
|
386 |
* @access private
|
387 |
*
|
388 |
+
* @param string $element Element.
|
389 |
+
* @param array $attrib Attributes.
|
390 |
+
* @param array $rtform_options Options.
|
391 |
*
|
392 |
* @return string $html
|
393 |
*/
|
394 |
+
private function container_enclosed_elements( $element, $attrib, $rtform_options ) {
|
395 |
+
|
396 |
+
$html = '';
|
397 |
+
$id = '';
|
398 |
+
$size = count( $rtform_options );
|
399 |
|
|
|
|
|
400 |
if ( isset( $attrib['id'] ) ) {
|
401 |
$id = $attrib['id'];
|
402 |
}
|
403 |
|
404 |
+
foreach ( $rtform_options as $opt ) {
|
405 |
|
406 |
if ( isset( $attrib['id'] ) && $size > 1 ) {
|
407 |
$attrib['id'] = $id . '-' . $this->get_default_id( $element );
|
439 |
|
440 |
$data = '';
|
441 |
switch ( $element ) {
|
442 |
+
case 'rtRadio':
|
443 |
$data = '<input type="radio" ' . $checked . ' ';
|
444 |
break;
|
445 |
+
case 'rtCheckbox':
|
446 |
$data = '<input type="checkbox" ' . $checked . ' ' . $switch . ' ';
|
447 |
break;
|
448 |
+
case 'rtSelect':
|
449 |
$selected = ( $attrib['selected'] ) ? 'selected=selected' : '';
|
450 |
$data = '<option value="' . esc_attr( $attrib['value'] ) . '" ' . $selected . '>' . esc_html( $attrib['key'] ) . '</option>';
|
451 |
break;
|
452 |
}
|
453 |
|
454 |
if ( 'rtSelect' !== $element ) {
|
455 |
+
$data .= $this->process_attributes( $element, $attrib, true );
|
456 |
|
457 |
+
// span elements for checkbox on/off switch.
|
458 |
if ( 'rtCheckbox' === $element ) {
|
459 |
$data .= '<span class="switch-label" data-on="On" data-off="Off"></span><span class="switch-handle"></span>';
|
460 |
}
|
490 |
}
|
491 |
|
492 |
/**
|
493 |
+
* Parse multiple options in admin options.
|
494 |
*
|
495 |
* @access private
|
496 |
*
|
497 |
+
* @param string $element Element.
|
498 |
+
* @param array $attributes Attributes.
|
499 |
*
|
500 |
* @return array
|
501 |
+
*
|
502 |
+
* @throws rtFormInvalidArgumentsException Exception.
|
503 |
*/
|
504 |
private function parse_multiple_options( $element, $attributes ) {
|
505 |
|
507 |
|
508 |
if ( isset( $attributes['rtForm_options'] ) && is_array( $attributes['rtForm_options'] ) ) {
|
509 |
|
510 |
+
$attrib_keys = array_keys( $attributes );
|
511 |
+
$attrib = array();
|
512 |
|
513 |
+
foreach ( $attrib_keys as $key ) {
|
514 |
if ( 'rtForm_options' !== $key ) {
|
515 |
$attrib[ $key ] = $attributes[ $key ];
|
516 |
}
|
517 |
}
|
518 |
|
519 |
+
$rtform_options = (array) $attributes['rtForm_options'];
|
520 |
|
521 |
+
return array(
|
522 |
+
'attrib' => $attrib,
|
523 |
+
'rtForm_options' => $rtform_options,
|
524 |
+
);
|
525 |
} else {
|
526 |
throw new rtFormInvalidArgumentsException( 'rtForm_options [' . $element . ']' );
|
527 |
}
|
535 |
*
|
536 |
* @access protected
|
537 |
*
|
538 |
+
* @param string $element Element.
|
539 |
+
* @param string $html HTML.
|
540 |
+
* @param string $label Label.
|
541 |
+
* @param array|bool $class Classes.
|
542 |
*
|
543 |
* @return string
|
544 |
*/
|
545 |
protected function enclose_label( $element, $html, $label, $class = false ) {
|
546 |
|
547 |
+
$label_class = '';
|
548 |
+
|
549 |
if ( ! empty( $class ) && is_array( $class ) ) {
|
550 |
+
$label_class = 'class="' . esc_attr( implode( ' ', $class ) ) . '"';
|
551 |
}
|
552 |
|
553 |
+
$data = '<label for="' . esc_attr( $this->element_id ) . '" ' . $label_class . '>';
|
554 |
|
555 |
if ( 'rtRadio' === $element || 'rtCheckbox' === $element ) {
|
556 |
$data .= $html . ' ' . $label;
|
568 |
*
|
569 |
* @access protected
|
570 |
*
|
571 |
+
* @param array $attributes attributes.
|
572 |
*
|
573 |
* @return string
|
574 |
+
*
|
575 |
+
* @throws rtFormInvalidArgumentsException Invalid argument Exception.
|
576 |
*/
|
577 |
protected function generate_textbox( $attributes ) {
|
578 |
|
579 |
$element = 'rtText';
|
580 |
if ( is_array( $attributes ) ) {
|
581 |
|
582 |
+
// Starting the input tag.
|
583 |
$html = '<input type="text" ';
|
584 |
|
585 |
+
// generating attributes.
|
586 |
+
$html .= $this->process_attributes( $element, $attributes );
|
587 |
|
588 |
+
// ending the tag.
|
589 |
$html .= ' />';
|
590 |
|
591 |
if ( isset( $attributes['label'] ) ) {
|
624 |
// Adding nonce for file upload.
|
625 |
$nonce = wp_create_nonce( 'rtmedia-admin-upload' );
|
626 |
|
627 |
+
// Keep customized button for file input.
|
628 |
$html = '<button class="rtm-form-button button button-primary button-small">Browse File</button>';
|
629 |
|
630 |
+
// Starting the input tag.
|
631 |
$html .= '<input type="hidden" id="rtmedia_admin_upload_nonce" value="' . esc_attr( $nonce ) . '" />';
|
632 |
$html .= '<input type="file" ';
|
633 |
|
634 |
+
// Generating attributes.
|
635 |
+
$html .= $this->process_attributes( $element, $attributes );
|
636 |
|
637 |
+
// Ending the tag.
|
638 |
$html .= ' />';
|
639 |
|
640 |
if ( ! empty( $attributes['name'] ) && ! empty( $attributes['value'] ) ) {
|
679 |
*
|
680 |
* @access public
|
681 |
*
|
682 |
+
* @param string|array $attributes Attributes.
|
683 |
*
|
684 |
* @return string
|
685 |
+
*
|
686 |
+
* @throws rtFormInvalidArgumentsException Invalid argument exception.
|
687 |
*/
|
688 |
public function get_textbox( $attributes = '' ) {
|
689 |
|
690 |
return $this->generate_textbox( $attributes );
|
691 |
}
|
692 |
|
693 |
+
/**
|
694 |
+
* Display textbox.
|
695 |
+
*
|
696 |
+
* @param string|array $args Arguments.
|
697 |
+
*/
|
698 |
public function display_textbox( $args = '' ) {
|
699 |
+
echo wp_kses( $this->get_textbox( $args ), RTMedia::expanded_allowed_tags() );
|
700 |
}
|
701 |
|
702 |
/**
|
704 |
*
|
705 |
* @access protected
|
706 |
*
|
707 |
+
* @param array $attributes Attributes.
|
708 |
*
|
709 |
* @return string
|
710 |
+
*
|
711 |
+
* @throws rtFormInvalidArgumentsException Invalid arguments exception.
|
712 |
*/
|
713 |
protected function generate_link( $attributes ) {
|
714 |
|
719 |
$html = '<a ';
|
720 |
|
721 |
// Generating attributes.
|
722 |
+
$html .= $this->process_attributes( $element, $attributes );
|
723 |
|
724 |
// Put text of link.
|
725 |
$html .= esc_html( ( isset( $attributes['text'] ) ) ? $attributes['text'] : '' );
|
750 |
*
|
751 |
* @access public
|
752 |
*
|
753 |
+
* @param string|array $attributes Attributes.
|
754 |
*
|
755 |
* @return string
|
756 |
+
*
|
757 |
+
* @throws rtFormInvalidArgumentsException Invalid arguments exception.
|
758 |
*/
|
759 |
public function get_link( $attributes = '' ) {
|
760 |
|
761 |
return $this->generate_link( $attributes );
|
762 |
}
|
763 |
|
764 |
+
/**
|
765 |
+
* Display link.
|
766 |
+
*
|
767 |
+
* @param string|array $args Arguments.
|
768 |
+
*
|
769 |
+
* @throws rtFormInvalidArgumentsException Invalid arguments exception.
|
770 |
+
*/
|
771 |
public function display_link( $args = '' ) {
|
772 |
+
echo wp_kses( $this->get_link( $args ), RTMedia::expanded_allowed_tags() );
|
773 |
}
|
774 |
|
775 |
/**
|
780 |
* @param string|array $attributes Arguments to create file input control.
|
781 |
*
|
782 |
* @return string
|
783 |
+
*
|
784 |
+
* @throws rtFormInvalidArgumentsException Invalid argument exception.
|
785 |
*/
|
786 |
public function get_inputfile( $attributes = '' ) {
|
787 |
return $this->generate_inputfile( $attributes );
|
793 |
*
|
794 |
* @param string|array $args Arguments to create file input control.
|
795 |
*
|
796 |
+
* @throws rtFormInvalidArgumentsException Invalid arguments exception.
|
797 |
*/
|
798 |
public function display_inputfile( $args = '' ) {
|
799 |
// Previously escaped and sanitized so not required here.
|
800 |
+
echo wp_kses( $this->get_inputfile( $args ), RTMedia::expanded_allowed_tags() );
|
801 |
}
|
802 |
|
803 |
/**
|
805 |
*
|
806 |
* @access protected
|
807 |
*
|
808 |
+
* @param array $attributes Attributes.
|
809 |
*
|
810 |
* @return string
|
811 |
+
*
|
812 |
+
* @throws rtFormInvalidArgumentsException Invalid arguments exception.
|
813 |
*/
|
814 |
protected function generate_number( $attributes ) {
|
815 |
|
816 |
$element = 'rtNumber';
|
817 |
if ( is_array( $attributes ) ) {
|
818 |
|
819 |
+
// Starting the input tag.
|
820 |
$html = '<input type="number" ';
|
821 |
|
822 |
+
// generating attributes.
|
823 |
+
$html .= $this->process_attributes( $element, $attributes );
|
824 |
if ( isset( $attributes['min'] ) ) {
|
825 |
$html .= " min='" . esc_attr( $attributes['min'] ) . "' ";
|
826 |
}
|
831 |
$html .= " step='" . esc_attr( $attributes['step'] ) . "' ";
|
832 |
}
|
833 |
|
834 |
+
// ending the tag.
|
835 |
$html .= ' />';
|
836 |
|
837 |
if ( isset( $attributes['label'] ) ) {
|
857 |
*
|
858 |
* @access public
|
859 |
*
|
860 |
+
* @param string|array $attributes Attributes.
|
861 |
*
|
862 |
* @return string
|
863 |
+
*
|
864 |
+
* @throws rtFormInvalidArgumentsException Invalid arguments exception.
|
865 |
*/
|
866 |
public function get_number( $attributes = '' ) {
|
867 |
|
868 |
return $this->generate_number( $attributes );
|
869 |
}
|
870 |
|
871 |
+
/**
|
872 |
+
* Display number.
|
873 |
+
*
|
874 |
+
* @param string|array $args Arguments.
|
875 |
+
*
|
876 |
+
* @throws rtFormInvalidArgumentsException Invalid arguments exception.
|
877 |
+
*/
|
878 |
public function display_number( $args = '' ) {
|
879 |
+
echo wp_kses( $this->get_number( $args ), RTMedia::expanded_allowed_tags() );
|
880 |
}
|
881 |
|
882 |
/**
|
884 |
*
|
885 |
* @access protected
|
886 |
*
|
887 |
+
* @param array $attributes Attributes.
|
888 |
*
|
889 |
* @return string
|
890 |
+
* @throws rtFormInvalidArgumentsException Invalid arguments exception.
|
891 |
*/
|
892 |
protected function generate_date( $attributes ) {
|
893 |
|
895 |
if ( is_array( $attributes ) ) {
|
896 |
$html = '<input type="date" ';
|
897 |
|
898 |
+
$html .= $this->process_attributes( $element, $attributes );
|
899 |
|
900 |
$html .= ' />';
|
901 |
|
922 |
*
|
923 |
* @access public
|
924 |
*
|
925 |
+
* @param array $attributes Attributes.
|
926 |
*
|
927 |
* @return string
|
928 |
+
*
|
929 |
+
* @throws rtFormInvalidArgumentsException Invalid arguments exception.
|
930 |
*/
|
931 |
public function get_date( $attributes ) {
|
932 |
return $this->generate_date( $attributes );
|
937 |
*
|
938 |
* @access protected
|
939 |
*
|
940 |
+
* @param array $attributes Attributes.
|
941 |
*
|
942 |
* @return string
|
943 |
+
* @throws rtFormInvalidArgumentsException Invalid arguments exception.
|
944 |
*/
|
945 |
protected function generate_hidden( $attributes ) {
|
946 |
|
947 |
$element = 'rtHidden';
|
948 |
if ( is_array( $attributes ) ) {
|
949 |
|
950 |
+
// Starting the input tag.
|
951 |
$html = '<input type="hidden" ';
|
952 |
|
953 |
+
// generating attributes.
|
954 |
+
$html .= $this->process_attributes( $element, $attributes );
|
955 |
|
956 |
+
// ending the tag.
|
957 |
$html .= ' />';
|
958 |
|
959 |
if ( isset( $attributes['label'] ) ) {
|
979 |
*
|
980 |
* @access public
|
981 |
*
|
982 |
+
* @param string|array $attributes Attributes.
|
983 |
*
|
984 |
* @return string
|
985 |
+
* @throws rtFormInvalidArgumentsException Invalid arguments exception.
|
986 |
*/
|
987 |
public function get_hidden( $attributes = '' ) {
|
988 |
|
994 |
*
|
995 |
* @access protected
|
996 |
*
|
997 |
+
* @param array $attributes Attributes.
|
998 |
*
|
999 |
* @return string
|
1000 |
+
* @throws rtFormInvalidArgumentsException Invalid arguments exception.
|
1001 |
*/
|
1002 |
protected function generate_textarea( $attributes ) {
|
1003 |
|
1004 |
$element = 'rtTextarea';
|
1005 |
if ( is_array( $attributes ) ) {
|
1006 |
|
1007 |
+
$html = '<textarea ';
|
1008 |
+
$html .= $this->process_attributes( $element, $attributes );
|
1009 |
$html .= '>';
|
1010 |
|
1011 |
$html .= esc_html( ( isset( $attributes['value'] ) ) ? $attributes['value'] : '' );
|
1035 |
*
|
1036 |
* @access public
|
1037 |
*
|
1038 |
+
* @param string|array $attributes Attributes.
|
1039 |
*
|
1040 |
* @return string
|
1041 |
+
* @throws rtFormInvalidArgumentsException Invalid arguments exception.
|
1042 |
*/
|
1043 |
public function get_textarea( $attributes = '' ) {
|
1044 |
|
1045 |
return $this->generate_textarea( $attributes );
|
1046 |
}
|
1047 |
|
1048 |
+
/**
|
1049 |
+
* Display textarea.
|
|
|
|
|
|
|
|
|
|
|
1050 |
*
|
1051 |
+
* @param string|array $args Arguments.
|
1052 |
*
|
1053 |
+
* @throws rtFormInvalidArgumentsException Invalid arguments exception.
|
1054 |
+
*/
|
1055 |
+
public function display_textarea( $args = '' ) {
|
1056 |
+
echo wp_kses( $this->get_textarea( $args ), RTMedia::expanded_allowed_tags() );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1057 |
}
|
1058 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1059 |
/**
|
1060 |
* Generate rtmedia html input type radio in admin options.
|
1061 |
*
|
1062 |
* @access protected
|
1063 |
*
|
1064 |
+
* @param array $attributes Attributes.
|
1065 |
*
|
1066 |
* @return string $container
|
1067 |
+
*
|
1068 |
+
* @throws rtFormInvalidArgumentsException Invalid arguments exception.
|
1069 |
*/
|
1070 |
protected function generate_radio( $attributes ) {
|
1071 |
|
1072 |
$element = 'rtRadio';
|
1073 |
$html = '';
|
1074 |
|
1075 |
+
$meta = $this->parse_multiple_options( $element, $attributes );
|
1076 |
$html .= $this->container_enclosed_elements( $element, $meta['attrib'], $meta['rtForm_options'] );
|
1077 |
|
1078 |
if ( isset( $attributes['show_desc'] ) && $attributes['show_desc'] ) {
|
1099 |
*
|
1100 |
* @access public
|
1101 |
*
|
1102 |
+
* @param string|array $attributes Attributes.
|
1103 |
*
|
1104 |
* @return string
|
1105 |
+
*
|
1106 |
+
* @throws rtFormInvalidArgumentsException Invalid arguments exception.
|
1107 |
*/
|
1108 |
public function get_radio( $attributes = '' ) {
|
1109 |
|
1110 |
return $this->generate_radio( $attributes );
|
1111 |
}
|
1112 |
|
1113 |
+
/**
|
1114 |
+
* Display radio button.
|
1115 |
+
*
|
1116 |
+
* @param array|string $args Arguments.
|
1117 |
+
*
|
1118 |
+
* @throws rtFormInvalidArgumentsException Invalid arguments exception.
|
1119 |
+
*/
|
1120 |
public function display_radio( $args = '' ) {
|
1121 |
+
echo wp_kses( $this->get_radio( $args ), RTMedia::expanded_allowed_tags() );
|
1122 |
}
|
1123 |
|
1124 |
/**
|
1126 |
*
|
1127 |
* @access protected
|
1128 |
*
|
1129 |
+
* @param array $attributes Attributes.
|
1130 |
*
|
1131 |
* @return string $container
|
1132 |
+
*
|
1133 |
+
* @throws rtFormInvalidArgumentsException Invalid arguments exception.
|
1134 |
*/
|
1135 |
protected function generate_checkbox( $attributes ) {
|
1136 |
|
1137 |
$element = 'rtCheckbox';
|
1138 |
$html = '';
|
1139 |
|
1140 |
+
$meta = $this->parse_multiple_options( $element, $attributes );
|
1141 |
$html .= $this->container_enclosed_elements( $element, $meta['attrib'], $meta['rtForm_options'] );
|
1142 |
|
1143 |
if ( isset( $attributes['show_desc'] ) && $attributes['show_desc'] ) {
|
1164 |
*
|
1165 |
* @access public
|
1166 |
*
|
1167 |
+
* @param string|array $attributes Attributes.
|
1168 |
*
|
1169 |
* @return string
|
1170 |
*/
|
1178 |
*
|
1179 |
* @access public
|
1180 |
*
|
1181 |
+
* @param string|array $attributes Attributes.
|
1182 |
*
|
1183 |
* @return string
|
1184 |
*/
|
1189 |
return $this->generate_checkbox( $attributes );
|
1190 |
}
|
1191 |
|
1192 |
+
/**
|
1193 |
+
* Display switch.
|
1194 |
+
*
|
1195 |
+
* @param string $args Arguments.
|
1196 |
+
*/
|
1197 |
public function display_switch( $args = '' ) {
|
1198 |
+
echo wp_kses( $this->get_switch( $args ), RTMedia::expanded_allowed_tags() );
|
1199 |
}
|
1200 |
|
1201 |
/**
|
1203 |
*
|
1204 |
* @access public
|
1205 |
*
|
1206 |
+
* @param string|array $attributes Attributes.
|
1207 |
*
|
1208 |
* @return string
|
1209 |
*/
|
1219 |
*
|
1220 |
* @access protected
|
1221 |
*
|
1222 |
+
* @param array $attributes Attributes.
|
1223 |
*
|
1224 |
* @return string
|
1225 |
+
* @throws rtFormInvalidArgumentsException Invalid arguments exception.
|
1226 |
*/
|
1227 |
protected function generate_select( $attributes ) {
|
1228 |
|
1236 |
$id = $element . $this->get_default_id( $element );
|
1237 |
$this->update_default_id( $element );
|
1238 |
}
|
1239 |
+
$html .= $this->generate_element_id( $element, $id ) . ' ';
|
1240 |
$multiple = ( isset( $attributes['multiple'] ) && $attributes['multiple'] ) ? true : false;
|
1241 |
$name = ( isset( $attributes['name'] ) ) ? $attributes['name'] : $element;
|
1242 |
+
$html .= $this->generate_element_name( $element, $multiple, $name ) . ' ';
|
1243 |
if ( isset( $attributes['class'] ) ) {
|
1244 |
$html .= $this->embedd_class( $element, $attributes['class'] );
|
1245 |
} else {
|
1252 |
|
1253 |
$html .= '>';
|
1254 |
|
1255 |
+
$meta = $this->parse_multiple_options( $element, $attributes );
|
1256 |
$html .= $this->container_enclosed_elements( $element, $meta['attrib'], $meta['rtForm_options'] );
|
1257 |
|
1258 |
$html .= '</select>';
|
1280 |
*
|
1281 |
* @access public
|
1282 |
*
|
1283 |
+
* @param string|array $attributes Attributes.
|
1284 |
*
|
1285 |
* @return string
|
1286 |
+
*
|
1287 |
+
* @throws rtFormInvalidArgumentsException Invalid arguments exception.
|
1288 |
*/
|
1289 |
public function get_select( $attributes = '' ) {
|
1290 |
|
1291 |
return $this->generate_select( $attributes );
|
1292 |
}
|
1293 |
|
1294 |
+
/**
|
1295 |
+
* Display select.
|
1296 |
+
*
|
1297 |
+
* @param string|array $args Arguments.
|
1298 |
+
*
|
1299 |
+
* @throws rtFormInvalidArgumentsException Invalid arguments exception.
|
1300 |
+
*/
|
1301 |
public function display_select( $args = '' ) {
|
1302 |
+
echo wp_kses( $this->get_select( $args ), RTMedia::expanded_allowed_tags() );
|
1303 |
}
|
1304 |
|
1305 |
/**
|
1307 |
*
|
1308 |
* @access protected
|
1309 |
*
|
1310 |
+
* @param array $attributes attributes for button control in key => value.
|
1311 |
*
|
1312 |
* @return string
|
1313 |
+
* @throws rtFormInvalidArgumentsException Invalid arguments exception.
|
1314 |
*/
|
1315 |
protected function generate_button( $attributes ) {
|
1316 |
|
1320 |
|
1321 |
$element = 'rtButton';
|
1322 |
|
1323 |
+
// Starting the input tag.
|
1324 |
$html = '<input type="button" ';
|
1325 |
|
1326 |
+
// generating attributes.
|
1327 |
+
$html .= $this->process_attributes( $element, $attributes );
|
1328 |
|
1329 |
+
// ending the tag.
|
1330 |
$html .= ' />';
|
1331 |
|
1332 |
if ( isset( $attributes['label'] ) ) {
|
1349 |
*
|
1350 |
* @access public
|
1351 |
*
|
1352 |
+
* @param string|array $attributes attributes for button control.
|
1353 |
*
|
1354 |
* @return string
|
1355 |
+
* @throws rtFormInvalidArgumentsException Invalid arguments exception.
|
1356 |
*/
|
1357 |
public function get_button( $attributes ) {
|
1358 |
|
1362 |
/**
|
1363 |
* Prints the HTML for button control based on arguments
|
1364 |
*
|
1365 |
+
* @param array $args arguments for button control.
|
1366 |
*
|
1367 |
+
* @throws rtFormInvalidArgumentsException Invalid arguments exception.
|
1368 |
*/
|
1369 |
public function display_button( $args ) {
|
1370 |
+
echo wp_kses( $this->get_button( $args ), RTMedia::expanded_allowed_tags() );
|
|
|
1371 |
}
|
1372 |
|
1373 |
/**
|
1375 |
*
|
1376 |
* @access protected
|
1377 |
*
|
1378 |
+
* @param array $attributes arguments to create file input control.
|
1379 |
*
|
1380 |
* @return string
|
1381 |
+
* @throws rtFormInvalidArgumentsException Invalid arguments exception.
|
1382 |
*/
|
1383 |
protected function generate_file_input( $attributes ) {
|
1384 |
|
1391 |
// Adding nonce for file upload.
|
1392 |
$nonce = wp_create_nonce( 'rtmedia-admin-upload' );
|
1393 |
|
1394 |
+
// Keep customized button for file input.
|
1395 |
+
$html = '<button class="rtm-form-button button button-primary button-small">Browse File</button>';
|
1396 |
|
1397 |
+
// Starting the input tag.
|
1398 |
$html .= '<input type="hidden" id="rtmedia_admin_upload_nonce" value="' . esc_attr( $nonce ) . '" />';
|
1399 |
$html .= '<input type="file" ';
|
1400 |
|
1401 |
+
// generating attributes.
|
1402 |
+
$html .= $this->process_attributes( $element, $attributes );
|
1403 |
|
1404 |
+
// ending the tag.
|
1405 |
$html .= ' />';
|
1406 |
|
1407 |
if ( isset( $attributes['label'] ) ) {
|
1424 |
*
|
1425 |
* @access public
|
1426 |
*
|
1427 |
+
* @param string/array $attributes Attributes.
|
1428 |
*
|
1429 |
* @return string
|
1430 |
+
* @throws rtFormInvalidArgumentsException Invalid arguments exception.
|
1431 |
*/
|
1432 |
public function get_file_input( $attributes ) {
|
1433 |
|
1435 |
}
|
1436 |
|
1437 |
/**
|
1438 |
+
* Display file input.
|
1439 |
*
|
1440 |
+
* @param array $args Arguments.
|
1441 |
+
*
|
1442 |
+
* @throws rtFormInvalidArgumentsException Invalid arguments exception.
|
1443 |
*/
|
1444 |
public function display_file_input( $args ) {
|
1445 |
+
echo wp_kses( $this->get_file_input( $args ), RTMedia::expanded_allowed_tags() );
|
|
|
1446 |
}
|
1447 |
}
|
1448 |
|
app/helper/rtFormInvalidArgumentsException.php
CHANGED
@@ -1,27 +1,40 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
/*
|
4 |
-
* To change this template, choose Tools | Templates
|
5 |
-
* and open the template in the editor.
|
6 |
-
*/
|
7 |
-
|
8 |
/**
|
9 |
-
*
|
10 |
*
|
11 |
-
* @
|
12 |
*/
|
13 |
|
14 |
if ( ! class_exists( 'rtFormsInvalidArgumentsException' ) ) {
|
15 |
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
17 |
|
|
|
|
|
|
|
|
|
|
|
18 |
public function __construct( $msg ) {
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
23 |
|
24 |
-
echo
|
|
|
|
|
|
|
|
|
|
|
25 |
}
|
26 |
}
|
27 |
}
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
+
* Handles invalid argument exception.
|
4 |
*
|
5 |
+
* @package rtMedia
|
6 |
*/
|
7 |
|
8 |
if ( ! class_exists( 'rtFormsInvalidArgumentsException' ) ) {
|
9 |
|
10 |
+
/**
|
11 |
+
* Class to throw invalid argument exception.
|
12 |
+
*
|
13 |
+
* @author udit
|
14 |
+
*/
|
15 |
+
class rtFormInvalidArgumentsException extends Exception { // phpcs:ignore PEAR.NamingConventions.ValidClassName.StartWithCapital, Generic.Classes.OpeningBraceSameLine.ContentAfterBrace
|
16 |
|
17 |
+
/**
|
18 |
+
* The rtFormInvalidArgumentsException constructor.
|
19 |
+
*
|
20 |
+
* @param string $msg Message.
|
21 |
+
*/
|
22 |
public function __construct( $msg ) {
|
23 |
|
24 |
+
parent::__construct( $msg );
|
25 |
+
|
26 |
+
// Error Message.
|
27 |
+
// translators: 1: Line number, 2: file.
|
28 |
+
$error_msg = sprintf( esc_html__( 'Error on line %1$s in %2$s : ', 'buddypress-media' ), $this->getLine(), $this->getFile() );
|
29 |
+
// translators: %s: message.
|
30 |
+
$error_msg .= '<b>' . sprintf( esc_html__( 'The method expects an array in arguments for %s provided.', 'buddypress-media' ), $msg ) . '</b>';
|
31 |
|
32 |
+
echo wp_kses(
|
33 |
+
$error_msg,
|
34 |
+
array(
|
35 |
+
'b' => array(),
|
36 |
+
)
|
37 |
+
);
|
38 |
}
|
39 |
}
|
40 |
}
|
app/helper/rtPluginUpdateChecker.php
CHANGED
@@ -1,9 +1,23 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
}
|
7 |
}
|
8 |
-
|
9 |
-
?>
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* Plugin update checker.
|
4 |
+
*
|
5 |
+
* @package rtMedia
|
6 |
+
*/
|
7 |
|
8 |
+
/**
|
9 |
+
* Class to check rtMedia plugin update
|
10 |
+
*/
|
11 |
+
class rtPluginUpdateChecker { // phpcs:ignore PEAR.NamingConventions.ValidClassName.StartWithCapital, Generic.Classes.OpeningBraceSameLine.ContentAfterBrace
|
12 |
+
/**
|
13 |
+
* A rtPluginUpdateChecker constructor.
|
14 |
+
*
|
15 |
+
* @param string $url URL.
|
16 |
+
* @param string $path Path.
|
17 |
+
* @param string $slug Slug.
|
18 |
+
* @param int $priority Priority.
|
19 |
+
*/
|
20 |
+
public function __construct( $url, $path, $slug, $priority ) {
|
21 |
+
// Code removed.
|
22 |
}
|
23 |
}
|
|
|
|
app/helper/rtProgress.php
CHANGED
@@ -1,34 +1,33 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
|
4 |
-
*
|
5 |
-
*
|
6 |
*/
|
7 |
|
8 |
/**
|
9 |
-
*
|
10 |
*
|
11 |
* @author saurabh
|
12 |
*/
|
13 |
-
class rtProgress {
|
14 |
|
15 |
/**
|
16 |
* Constructor
|
17 |
*
|
18 |
* @access public
|
19 |
-
* @return void
|
20 |
*/
|
21 |
-
function __construct() {
|
22 |
|
23 |
}
|
24 |
|
25 |
/**
|
26 |
-
* Show
|
27 |
*
|
28 |
* @access public
|
29 |
*
|
30 |
-
* @param float $progress
|
31 |
-
* @param bool
|
32 |
*
|
33 |
* @return string $progress_ui
|
34 |
*/
|
@@ -40,7 +39,7 @@ class rtProgress {
|
|
40 |
';
|
41 |
|
42 |
if ( $echo ) {
|
43 |
-
echo $progress_ui
|
44 |
} else {
|
45 |
return $progress_ui;
|
46 |
}
|
@@ -51,8 +50,8 @@ class rtProgress {
|
|
51 |
*
|
52 |
* @access public
|
53 |
*
|
54 |
-
* @param float $progress
|
55 |
-
* @param float $total
|
56 |
*
|
57 |
* @return float
|
58 |
*/
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* Adds class to Show progress-bar
|
4 |
+
*
|
5 |
+
* @package rtMedia
|
6 |
*/
|
7 |
|
8 |
/**
|
9 |
+
* Class to show progress-bar.
|
10 |
*
|
11 |
* @author saurabh
|
12 |
*/
|
13 |
+
class rtProgress { // phpcs:ignore PEAR.NamingConventions.ValidClassName.StartWithCapital, Generic.Classes.OpeningBraceSameLine.ContentAfterBrace
|
14 |
|
15 |
/**
|
16 |
* Constructor
|
17 |
*
|
18 |
* @access public
|
|
|
19 |
*/
|
20 |
+
public function __construct() {
|
21 |
|
22 |
}
|
23 |
|
24 |
/**
|
25 |
+
* Show progress-bar ui.
|
26 |
*
|
27 |
* @access public
|
28 |
*
|
29 |
+
* @param float $progress Current progress.
|
30 |
+
* @param bool $echo Echo.
|
31 |
*
|
32 |
* @return string $progress_ui
|
33 |
*/
|
39 |
';
|
40 |
|
41 |
if ( $echo ) {
|
42 |
+
echo wp_kses( $progress_ui, RTMedia::expanded_allowed_tags() );
|
43 |
} else {
|
44 |
return $progress_ui;
|
45 |
}
|
50 |
*
|
51 |
* @access public
|
52 |
*
|
53 |
+
* @param float $progress Current progress.
|
54 |
+
* @param float $total Total.
|
55 |
*
|
56 |
* @return float
|
57 |
*/
|
app/helper/rtUploadAttachment.php
CHANGED
@@ -21,14 +21,20 @@ if ( ! function_exists( 'rtmedia_admin_upload' ) ) {
|
|
21 |
* @return void.
|
22 |
*/
|
23 |
function rtmedia_admin_upload() {
|
|
|
24 |
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
|
|
|
25 |
$nonce = filter_input( INPUT_POST, 'rtmedia_admin_upload_nonce' );
|
26 |
if ( wp_verify_nonce( $nonce, 'rtmedia-admin-upload' ) ) {
|
|
|
27 |
if ( ! empty( $_FILES ) ) {
|
|
|
28 |
$error = false;
|
29 |
$files = array();
|
|
|
30 |
// Get WordPress's uploads directory paths and urls.
|
31 |
$wpuploaddir = wp_upload_dir();
|
|
|
32 |
// Folder for uploading temporary debug attachment. i.e SITE_ROOT/wp-content/uploads/rtMedia/tmp.
|
33 |
$uploaddir = $wpuploaddir['basedir'] . '/rtMedia/tmp/';
|
34 |
|
@@ -38,21 +44,25 @@ if ( ! function_exists( 'rtmedia_admin_upload' ) ) {
|
|
38 |
die( 'Failed to create folders...' );
|
39 |
}
|
40 |
}
|
41 |
-
|
|
|
42 |
|
43 |
// Code to check whether the uploaded file is settings json file.
|
44 |
$import_export = false;
|
45 |
$import_export_control = sanitize_text_field( filter_input( INPUT_POST, 'import_export_control' ) );
|
|
|
46 |
if ( 'rtFileInput' === $import_export_control ) {
|
47 |
$import_export = true;
|
48 |
}
|
49 |
|
50 |
// Move file to target folder.
|
51 |
foreach ( $_FILES as $name => $file ) {
|
|
|
52 |
if ( $file['size'] <= 2000000 ) {
|
53 |
$ext = pathinfo( basename( $file['name'] ), PATHINFO_EXTENSION );
|
54 |
|
55 |
if ( $import_export ) {
|
|
|
56 |
if ( 'json' === strtolower( $ext ) && move_uploaded_file( $file['tmp_name'], $uploaddir . basename( $file['name'] ) ) ) {
|
57 |
$uploaded_file = $uploaddir . $file['name'];
|
58 |
|
@@ -61,7 +71,7 @@ if ( ! function_exists( 'rtmedia_admin_upload' ) ) {
|
|
61 |
} else {
|
62 |
$error = true;
|
63 |
}
|
64 |
-
} elseif ( in_array( strtolower( $ext ), $
|
65 |
$files[] = $uploaddir . $file['name'];
|
66 |
} else {
|
67 |
$error = true;
|
21 |
* @return void.
|
22 |
*/
|
23 |
function rtmedia_admin_upload() {
|
24 |
+
|
25 |
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
|
26 |
+
|
27 |
$nonce = filter_input( INPUT_POST, 'rtmedia_admin_upload_nonce' );
|
28 |
if ( wp_verify_nonce( $nonce, 'rtmedia-admin-upload' ) ) {
|
29 |
+
|
30 |
if ( ! empty( $_FILES ) ) {
|
31 |
+
|
32 |
$error = false;
|
33 |
$files = array();
|
34 |
+
|
35 |
// Get WordPress's uploads directory paths and urls.
|
36 |
$wpuploaddir = wp_upload_dir();
|
37 |
+
|
38 |
// Folder for uploading temporary debug attachment. i.e SITE_ROOT/wp-content/uploads/rtMedia/tmp.
|
39 |
$uploaddir = $wpuploaddir['basedir'] . '/rtMedia/tmp/';
|
40 |
|
44 |
die( 'Failed to create folders...' );
|
45 |
}
|
46 |
}
|
47 |
+
|
48 |
+
$allowed_type = array( 'jpg', 'jpeg', 'png', 'gif', 'zip', 'doc', 'docx', 'pdf', 'txt' );
|
49 |
|
50 |
// Code to check whether the uploaded file is settings json file.
|
51 |
$import_export = false;
|
52 |
$import_export_control = sanitize_text_field( filter_input( INPUT_POST, 'import_export_control' ) );
|
53 |
+
|
54 |
if ( 'rtFileInput' === $import_export_control ) {
|
55 |
$import_export = true;
|
56 |
}
|
57 |
|
58 |
// Move file to target folder.
|
59 |
foreach ( $_FILES as $name => $file ) {
|
60 |
+
|
61 |
if ( $file['size'] <= 2000000 ) {
|
62 |
$ext = pathinfo( basename( $file['name'] ), PATHINFO_EXTENSION );
|
63 |
|
64 |
if ( $import_export ) {
|
65 |
+
|
66 |
if ( 'json' === strtolower( $ext ) && move_uploaded_file( $file['tmp_name'], $uploaddir . basename( $file['name'] ) ) ) {
|
67 |
$uploaded_file = $uploaddir . $file['name'];
|
68 |
|
71 |
} else {
|
72 |
$error = true;
|
73 |
}
|
74 |
+
} elseif ( in_array( strtolower( $ext ), $allowed_type, true ) && move_uploaded_file( $file['tmp_name'], $uploaddir . basename( $file['name'] ) ) ) {
|
75 |
$files[] = $uploaddir . $file['name'];
|
76 |
} else {
|
77 |
$error = true;
|
app/importers/BPMediaAlbumimporter.php
CHANGED
@@ -1,64 +1,86 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
|
4 |
-
*
|
5 |
-
*
|
6 |
*/
|
7 |
|
8 |
/**
|
9 |
-
*
|
10 |
*
|
11 |
* @author saurabh
|
12 |
*/
|
13 |
class BPMediaAlbumimporter extends BPMediaImporter {
|
14 |
|
15 |
-
|
|
|
|
|
|
|
16 |
global $wpdb;
|
17 |
parent::__construct();
|
18 |
$table = "{$wpdb->base_prefix}bp_album";
|
19 |
-
if ( BPMediaImporter::table_exists( $table ) &&
|
20 |
$this->update_table();
|
21 |
}
|
22 |
}
|
23 |
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
25 |
if ( $this->column_exists( 'import_status' ) ) {
|
26 |
return;
|
27 |
}
|
28 |
global $wpdb;
|
29 |
|
30 |
-
return $wpdb->query(
|
|
|
31 |
ADD COLUMN import_status BIGINT (20) NOT NULL DEFAULT 0,
|
32 |
ADD COLUMN old_activity_id BIGINT (20) NOT NULL DEFAULT 0,
|
33 |
ADD COLUMN new_activity_id BIGINT (20) NOT NULL DEFAULT 0,
|
34 |
-
ADD COLUMN favorites TINYINT (1) NOT NULL DEFAULT 0"
|
|
|
35 |
}
|
36 |
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
global $wpdb;
|
39 |
|
40 |
return $wpdb->query( $wpdb->prepare( "SHOW COLUMNS FROM {$wpdb->base_prefix}bp_album LIKE %s limit 1", $column ) );
|
41 |
}
|
42 |
|
43 |
-
|
|
|
|
|
|
|
44 |
global $wpdb;
|
45 |
$bp_album_active = BPMediaImporter::_active( 'bp-album/loader.php' );
|
46 |
$table = "{$wpdb->base_prefix}bp_album";
|
47 |
if ( BPMediaImporter::table_exists( $table ) ) {
|
48 |
|
49 |
-
$this->progress
|
50 |
-
$total
|
51 |
-
$remaining_comments
|
52 |
-
$finished
|
53 |
-
$finished_users
|
54 |
-
$finished_comments
|
55 |
-
$total_comments
|
56 |
$completed_users_favorites = (int) get_site_option( 'bp_media_bp_album_favorite_import_status', 0 );
|
57 |
-
$users
|
58 |
|
59 |
echo '<div id="bpmedia-bpalbumimporter">';
|
60 |
wp_nonce_field( 'bpmedia-bpalbumimporter', 'bpaimporter_wpnonce' );
|
|
|
61 |
if ( ( $finished[0]->media !== $total[0]->media ) || ( $users['total_users'] > $completed_users_favorites ) ) {
|
|
|
62 |
if ( 1 !== $bp_album_active ) {
|
63 |
echo '<div id="setting-error-bp-album-importer" class="error settings-error below-h2">
|
64 |
<p><strong>' . esc_html__( 'Warning!', 'buddypress-media' ) . '</strong> ' .
|
@@ -89,6 +111,7 @@ class BPMediaAlbumimporter extends BPMediaImporter {
|
|
89 |
echo esc_html__( 'Media', 'buddypress-media' ) . ': <span class="finished">' . esc_html( $finished[0]->media ) . '</span> / <span class="total">' . esc_html( $total[0]->media ) . '</span>';
|
90 |
echo '</strong>';
|
91 |
$progress = 100;
|
|
|
92 |
if ( 0 !== $total[0]->media ) {
|
93 |
$todo = $total[0]->media - $finished[0]->media;
|
94 |
$steps = ceil( $todo / 5 );
|
@@ -101,9 +124,11 @@ class BPMediaAlbumimporter extends BPMediaImporter {
|
|
101 |
echo '<input type="hidden" value="' . esc_attr( $laststep ) . '" name="laststep"/>';
|
102 |
$this->progress->progress_ui( $progress );
|
103 |
}
|
|
|
104 |
echo '</div>';
|
105 |
echo '<br>';
|
106 |
echo '<div class="bp-album-comments">';
|
|
|
107 |
if ( 0 !== $total_comments ) {
|
108 |
echo '<strong>';
|
109 |
echo esc_html__( 'Comments', 'buddypress-media' ) . ': <span class="finished">' . esc_html( $finished_comments ) . '</span> / <span class="total">' . esc_html( $total_comments ) . '</span>';
|
@@ -115,6 +140,7 @@ class BPMediaAlbumimporter extends BPMediaImporter {
|
|
115 |
echo '<p><strong>' . esc_html__( 'Comments: 0/0 (No comments to import)', 'buddypress-media' ) . '</strong></p>';
|
116 |
}
|
117 |
echo '</div>';
|
|
|
118 |
if ( 0 !== $completed_users_favorites ) {
|
119 |
echo '<br />';
|
120 |
echo '<div class="bp-album-favorites">';
|
@@ -127,15 +153,16 @@ class BPMediaAlbumimporter extends BPMediaImporter {
|
|
127 |
}
|
128 |
echo '</div>';
|
129 |
} else {
|
130 |
-
$deactivate_link = wp_nonce_url( admin_url( 'plugins.php?action=deactivate&plugin=' .
|
131 |
echo '<p>' . esc_html__( 'BP-Album is active on your site and will cause problems with the import.', 'buddypress-media' ) . '</p>';
|
132 |
echo '<p><a class="button button-primary deactivate-bp-album" href="' . esc_url( $deactivate_link ) . '">' . esc_html__( 'Click here to deactivate BP-Album and continue importing', 'buddypress-media' ) . '</a></p>';
|
133 |
}
|
134 |
} else {
|
135 |
-
$corrupt_media =
|
136 |
if ( $corrupt_media ) {
|
137 |
echo '<div class="error below-h2">';
|
138 |
echo '<p><strong>' . esc_html__( 'Some of the media failed to import. The file might be corrupt or deleted.', 'buddypress-media' ) . '</strong></p>';
|
|
|
139 |
echo '<p>' . sprintf( esc_html__( 'The following %d BP Album Media id\'s could not be imported', 'buddypress-media' ), count( $corrupt_media ) ) . ': </p>';
|
140 |
$corrupt_prefix_path = str_replace( '/wp-content', '', WP_CONTENT_URL );
|
141 |
foreach ( $corrupt_media as $corrupt ) {
|
@@ -145,6 +172,7 @@ class BPMediaAlbumimporter extends BPMediaImporter {
|
|
145 |
} else {
|
146 |
echo '<div class="bp-album-import-accept i-accept">';
|
147 |
echo '<p class="info">';
|
|
|
148 |
$message = sprintf( esc_html__( 'I just imported bp-album to @rtMediaWP http://rt.cx/rtmedia on %s', 'buddypress-media' ), home_url() );
|
149 |
echo '<strong>' . esc_html__( 'Congratulations!', 'buddypress-media' ) . '</strong> ' . esc_html__( 'All media from BP Album has been imported.', 'buddypress-media' );
|
150 |
echo ' <a href="http://twitter.com/home/?status=' . esc_url( $message ) . '" class="button button-import-tweet" target= "_blank">' . esc_html__( 'Tweet this', 'buddypress-media' ) . '</a>';
|
@@ -162,7 +190,7 @@ class BPMediaAlbumimporter extends BPMediaImporter {
|
|
162 |
echo '<br />';
|
163 |
echo '<br />';
|
164 |
echo '<br />';
|
165 |
-
echo '<strong>' . esc_html__( 'Why don\'t you try adding some
|
166 |
echo '<div class="bp-media-addon">
|
167 |
<a href="https://rtmedia.io/products/rtmedia-photo-filters/?utm_source=dashboard&utm_medium=plugin&utm_campaign=buddypress-media&utm_content=bp-album-importer" title="rtMedia Photo Filters" target="_blank">
|
168 |
<img width="240" height="184" title="rtMedia Photo Filters" alt="rtMedia Photo Filters" src="' . esc_url( $img_src ) . 'BuddyPressMedia-Instagram.png?ref=bp-album-importer">
|
@@ -181,12 +209,20 @@ class BPMediaAlbumimporter extends BPMediaImporter {
|
|
181 |
echo '</div>';
|
182 |
} else {
|
183 |
echo '<p>' . esc_html__( 'Looks like you don\'t use BP Album. Is there any other BuddyPress Plugin you want an importer for?', 'buddypress-media' ) . '</p>';
|
184 |
-
echo '<p
|
185 |
echo esc_html__( ' on GitHub requesting the same.', 'buddypress-media' ) . '</p>';
|
186 |
}
|
187 |
}
|
188 |
|
189 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
190 |
global $bp_media, $wpdb;
|
191 |
|
192 |
if ( array_key_exists( 'bp_album_import_name', $bp_media->options ) ) {
|
@@ -208,23 +244,34 @@ class BPMediaAlbumimporter extends BPMediaImporter {
|
|
208 |
return $album_id;
|
209 |
}
|
210 |
|
211 |
-
|
|
|
|
|
|
|
|
|
|
|
212 |
global $wpdb;
|
213 |
$table = $wpdb->base_prefix . 'bp_album';
|
214 |
-
if (
|
215 |
-
return $wpdb->get_results( "SELECT COUNT(DISTINCT owner_id) as users, COUNT(id) as media FROM {$table}" ); //
|
216 |
}
|
217 |
|
218 |
return 0;
|
219 |
}
|
220 |
|
221 |
-
|
|
|
|
|
|
|
|
|
|
|
222 |
global $wpdb;
|
223 |
$bp_album_table = $wpdb->base_prefix . 'bp_album';
|
224 |
$activity_table = $wpdb->base_prefix . 'bp_activity';
|
225 |
if ( $this->table_exists( $bp_album_table ) ) {
|
226 |
-
//
|
227 |
-
return $wpdb->get_var(
|
|
|
228 |
FROM (
|
229 |
SELECT (
|
230 |
SELECT COUNT( a.id )
|
@@ -238,90 +285,132 @@ class BPMediaAlbumimporter extends BPMediaImporter {
|
|
238 |
WHERE activity.component = 'album'
|
239 |
AND activity.type = 'bp_album_picture'
|
240 |
AND album.import_status =0
|
241 |
-
)b"
|
|
|
242 |
}
|
243 |
|
244 |
return 0;
|
245 |
}
|
246 |
|
247 |
-
|
|
|
|
|
|
|
|
|
|
|
248 |
global $wpdb;
|
249 |
$bp_album_table = $wpdb->base_prefix . 'bp_album';
|
250 |
-
|
251 |
if ( $this->table_exists( $bp_album_table ) ) {
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
|
|
258 |
}
|
259 |
|
260 |
return 0;
|
261 |
}
|
262 |
|
263 |
-
|
|
|
|
|
|
|
|
|
|
|
264 |
global $wpdb;
|
265 |
$table = $wpdb->base_prefix . 'bp_album';
|
266 |
-
if (
|
267 |
-
|
268 |
-
return $wpdb->get_results(
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
|
|
278 |
}
|
279 |
|
280 |
return 0;
|
281 |
}
|
282 |
|
283 |
-
|
|
|
|
|
|
|
|
|
|
|
284 |
global $wpdb;
|
285 |
$table = $wpdb->base_prefix . 'bp_album';
|
286 |
-
if (
|
287 |
-
return $wpdb->get_results( "SELECT COUNT(id) as media FROM $
|
288 |
}
|
289 |
|
290 |
return 0;
|
291 |
}
|
292 |
|
293 |
-
|
|
|
|
|
|
|
|
|
|
|
294 |
global $wpdb;
|
295 |
$table = $wpdb->base_prefix . 'bp_album';
|
296 |
-
if (
|
297 |
-
return $wpdb->get_results( "SELECT id,title,pic_org_url FROM $
|
298 |
}
|
299 |
|
300 |
return 0;
|
301 |
}
|
302 |
|
303 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
304 |
global $wpdb;
|
305 |
-
$table = $wpdb->base_prefix . 'bp_album';
|
306 |
-
$bp_album_data = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$table} WHERE import_status = 0 ORDER BY owner_id LIMIT %d", $count ) ); // @codingStandardsIgnoreLine
|
307 |
|
308 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
309 |
}
|
310 |
|
311 |
-
|
|
|
|
|
|
|
|
|
312 |
if ( ! check_ajax_referer( 'bpmedia-bpalbumimporter', 'rtm_wpnonce' ) ) {
|
313 |
wp_send_json( false );
|
314 |
}
|
315 |
-
|
316 |
-
$
|
|
|
317 |
$page = isset( $page ) ? $page : 1;
|
318 |
$count = isset( $count ) ? $count : 5;
|
319 |
-
$bp_album_data =
|
|
|
320 |
global $wpdb;
|
|
|
321 |
$table = $wpdb->base_prefix . 'bp_album';
|
322 |
$activity_table = $wpdb->base_prefix . 'bp_activity';
|
323 |
$activity_meta_table = $wpdb->base_prefix . 'bp_activity_meta';
|
324 |
$comments = 0;
|
|
|
325 |
foreach ( $bp_album_data as &$bp_album_item ) {
|
326 |
|
327 |
if ( get_site_option( 'bp_media_bp_album_importer_base_path' ) === '' ) {
|
@@ -330,65 +419,106 @@ class BPMediaAlbumimporter extends BPMediaImporter {
|
|
330 |
}
|
331 |
$bpm_host_wp = new BPMediaHostWordpress();
|
332 |
$bpm_host_wp->check_and_create_album( 0, 0, $bp_album_item->owner_id );
|
333 |
-
$album_id =
|
334 |
$imported_media_id = BPMediaImporter::add_media( $album_id, $bp_album_item->title, $bp_album_item->description, $bp_album_item->pic_org_path, $bp_album_item->privacy, $bp_album_item->owner_id, 'Imported Media' );
|
335 |
$wpdb->update( $table, array( 'import_status' => ( $imported_media_id ) ? $imported_media_id : - 1 ), array( 'id' => $bp_album_item->id ), array( '%d' ), array( '%d' ) );
|
336 |
if ( $imported_media_id ) {
|
337 |
-
$comments += (int)
|
338 |
|
339 |
-
$bp_album_media_id = $wpdb->get_var( "SELECT activity.id from $activity_table as activity INNER JOIN $table as album ON ( activity.item_id = album.id ) WHERE activity.item_id = $bp_album_item->id AND activity.component = 'album' AND activity.type='bp_album_picture'" ); //
|
340 |
$wpdb->update( $table, array( 'old_activity_id' => $bp_album_media_id ), array( 'id' => $bp_album_item->id ), array( '%d' ), array( '%d' ) );
|
341 |
-
$bp_new_activity_id = $wpdb->get_var( "SELECT id from $activity_table WHERE item_id = $imported_media_id AND component = 'activity' AND type='activity_update' AND secondary_item_id=0" ); //
|
342 |
$wpdb->update( $table, array( 'new_activity_id' => $bp_new_activity_id ), array( 'id' => $bp_album_item->id ), array( '%d' ), array( '%d' ) );
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
347 |
) {
|
348 |
$wpdb->update( $table, array( 'favorites' => 1 ), array( 'id' => $bp_album_item->id ), array( '%d' ), array( '%d' ) );
|
349 |
}
|
350 |
}
|
351 |
}
|
352 |
|
353 |
-
$finished_users =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
354 |
|
355 |
-
echo wp_json_encode( array( 'page' => $page, 'users' => $finished_users[0]->users, 'comments' => $comments ) );
|
356 |
die();
|
357 |
}
|
358 |
|
359 |
-
|
|
|
|
|
|
|
|
|
360 |
if ( ! check_ajax_referer( 'bpmedia-bpalbumimporter', 'rtm_wpnonce' ) ) {
|
361 |
wp_send_json( array( 'status' => false ) );
|
362 |
}
|
|
|
363 |
global $wpdb;
|
364 |
$table = $wpdb->base_prefix . 'bp_album';
|
365 |
$users = count_users();
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
|
|
|
|
|
|
|
|
371 |
die();
|
372 |
}
|
373 |
|
374 |
-
|
|
|
|
|
|
|
|
|
375 |
if ( ! check_ajax_referer( 'bpmedia-bpalbumimporter', 'rtm_wpnonce' ) ) {
|
376 |
wp_send_json( array( 'status' => false ) );
|
377 |
}
|
378 |
-
|
|
|
379 |
$redirect = filter_input( INPUT_GET, 'redirect', FILTER_SANITIZE_URL );
|
380 |
$offset = isset( $offset ) ? $offset : 0;
|
381 |
$redirect = isset( $redirect ) ? $redirect : false;
|
|
|
382 |
global $wpdb;
|
|
|
383 |
$table = $wpdb->base_prefix . 'bp_album';
|
384 |
-
$blogusers = get_users(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
385 |
if ( $blogusers ) {
|
386 |
foreach ( $blogusers as $user ) {
|
|
|
387 |
$favorite_activities = get_user_meta( $user->ID, 'bp_favorite_activities', true );
|
|
|
388 |
if ( $favorite_activities ) {
|
|
|
389 |
$new_favorite_activities = $favorite_activities;
|
390 |
foreach ( $favorite_activities as $key => $favorite ) {
|
391 |
-
|
|
|
392 |
$new_favorite_activities[ $key ] = $new_act;
|
393 |
}
|
394 |
}
|
@@ -398,22 +528,37 @@ class BPMediaAlbumimporter extends BPMediaImporter {
|
|
398 |
update_site_option( 'bp_media_bp_album_favorite_import_status', $completed_users_favorites );
|
399 |
}
|
400 |
}
|
|
|
401 |
echo esc_url( $redirect );
|
402 |
die();
|
403 |
}
|
404 |
|
405 |
-
|
|
|
|
|
|
|
406 |
global $wpdb;
|
|
|
407 |
if ( ! check_ajax_referer( 'bpmedia-bpalbumimporter', 'rtm_wpnonce' ) ) {
|
408 |
wp_send_json( array( 'status' => false ) );
|
409 |
}
|
|
|
410 |
$table = $wpdb->base_prefix . 'bp_album';
|
411 |
$dir = get_site_option( 'bp_media_bp_album_importer_base_path' );
|
412 |
BPMediaImporter::cleanup( $table, $dir );
|
413 |
die();
|
414 |
}
|
415 |
|
416 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
417 |
global $wpdb;
|
418 |
if ( function_exists( 'bp_activity_add' ) ) {
|
419 |
if ( ! is_object( $media ) ) {
|
@@ -423,9 +568,12 @@ class BPMediaAlbumimporter extends BPMediaImporter {
|
|
423 |
return false;
|
424 |
}
|
425 |
}
|
|
|
426 |
$activity_id = get_post_meta( $media->get_id(), 'bp_media_child_activity', true );
|
|
|
|
|
427 |
if ( $activity_id ) {
|
428 |
-
$date_uploaded = $wpdb->get_var( $wpdb->prepare( "SELECT date_uploaded from $table WHERE id = %d", $bp_album_id ) ); //
|
429 |
$old_activity_id = $wpdb->get_var( $wpdb->prepare( "SELECT id from {$wpdb->base_prefix}bp_activity WHERE component = 'album' AND type = 'bp_album_picture' AND item_id = %d", $bp_album_id ) );
|
430 |
if ( $old_activity_id ) {
|
431 |
$comments = $wpdb->get_results( $wpdb->prepare( "SELECT id,secondary_item_id from {$wpdb->base_prefix}bp_activity WHERE component = 'activity' AND type = 'activity_comment' AND item_id = %d", $old_activity_id ) );
|
@@ -447,7 +595,10 @@ class BPMediaAlbumimporter extends BPMediaImporter {
|
|
447 |
}
|
448 |
}
|
449 |
|
450 |
-
|
|
|
|
|
|
|
451 |
if ( ! check_ajax_referer( 'bpmedia-bpalbumimporter', 'rtm_wpnonce' ) ) {
|
452 |
deactivate_plugins( 'bp-album/loader.php' );
|
453 |
}
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* Handles BuddyPress media album import
|
4 |
+
*
|
5 |
+
* @package rtMedia
|
6 |
*/
|
7 |
|
8 |
/**
|
9 |
+
* Class for BuddyPress media album importer
|
10 |
*
|
11 |
* @author saurabh
|
12 |
*/
|
13 |
class BPMediaAlbumimporter extends BPMediaImporter {
|
14 |
|
15 |
+
/**
|
16 |
+
* BPMediaAlbumimporter constructor.
|
17 |
+
*/
|
18 |
+
public function __construct() {
|
19 |
global $wpdb;
|
20 |
parent::__construct();
|
21 |
$table = "{$wpdb->base_prefix}bp_album";
|
22 |
+
if ( BPMediaImporter::table_exists( $table ) && self::_active( 'bp-album/loader.php' ) !== - 1 && ! $this->column_exists( 'import_status' ) ) {
|
23 |
$this->update_table();
|
24 |
}
|
25 |
}
|
26 |
|
27 |
+
/**
|
28 |
+
* Update bp_album table.
|
29 |
+
*
|
30 |
+
* @return false|int|void
|
31 |
+
*/
|
32 |
+
public function update_table() {
|
33 |
if ( $this->column_exists( 'import_status' ) ) {
|
34 |
return;
|
35 |
}
|
36 |
global $wpdb;
|
37 |
|
38 |
+
return $wpdb->query(
|
39 |
+
"ALTER TABLE {$wpdb->base_prefix}bp_album
|
40 |
ADD COLUMN import_status BIGINT (20) NOT NULL DEFAULT 0,
|
41 |
ADD COLUMN old_activity_id BIGINT (20) NOT NULL DEFAULT 0,
|
42 |
ADD COLUMN new_activity_id BIGINT (20) NOT NULL DEFAULT 0,
|
43 |
+
ADD COLUMN favorites TINYINT (1) NOT NULL DEFAULT 0"
|
44 |
+
);
|
45 |
}
|
46 |
|
47 |
+
/**
|
48 |
+
* Function to check if column exists.
|
49 |
+
*
|
50 |
+
* @param string $column Column name to check.
|
51 |
+
*
|
52 |
+
* @return mixed
|
53 |
+
*/
|
54 |
+
public function column_exists( $column ) {
|
55 |
global $wpdb;
|
56 |
|
57 |
return $wpdb->query( $wpdb->prepare( "SHOW COLUMNS FROM {$wpdb->base_prefix}bp_album LIKE %s limit 1", $column ) );
|
58 |
}
|
59 |
|
60 |
+
/**
|
61 |
+
* UI for Media importer.
|
62 |
+
*/
|
63 |
+
public function ui() {
|
64 |
global $wpdb;
|
65 |
$bp_album_active = BPMediaImporter::_active( 'bp-album/loader.php' );
|
66 |
$table = "{$wpdb->base_prefix}bp_album";
|
67 |
if ( BPMediaImporter::table_exists( $table ) ) {
|
68 |
|
69 |
+
$this->progress = new rtProgress();
|
70 |
+
$total = self::get_total_count();
|
71 |
+
$remaining_comments = $this->get_remaining_comments();
|
72 |
+
$finished = self::get_completed_media( $total );
|
73 |
+
$finished_users = self::get_completed_users();
|
74 |
+
$finished_comments = $this->get_finished_comments();
|
75 |
+
$total_comments = (int) $finished_comments + (int) $remaining_comments;
|
76 |
$completed_users_favorites = (int) get_site_option( 'bp_media_bp_album_favorite_import_status', 0 );
|
77 |
+
$users = count_users();
|
78 |
|
79 |
echo '<div id="bpmedia-bpalbumimporter">';
|
80 |
wp_nonce_field( 'bpmedia-bpalbumimporter', 'bpaimporter_wpnonce' );
|
81 |
+
|
82 |
if ( ( $finished[0]->media !== $total[0]->media ) || ( $users['total_users'] > $completed_users_favorites ) ) {
|
83 |
+
|
84 |
if ( 1 !== $bp_album_active ) {
|
85 |
echo '<div id="setting-error-bp-album-importer" class="error settings-error below-h2">
|
86 |
<p><strong>' . esc_html__( 'Warning!', 'buddypress-media' ) . '</strong> ' .
|
111 |
echo esc_html__( 'Media', 'buddypress-media' ) . ': <span class="finished">' . esc_html( $finished[0]->media ) . '</span> / <span class="total">' . esc_html( $total[0]->media ) . '</span>';
|
112 |
echo '</strong>';
|
113 |
$progress = 100;
|
114 |
+
|
115 |
if ( 0 !== $total[0]->media ) {
|
116 |
$todo = $total[0]->media - $finished[0]->media;
|
117 |
$steps = ceil( $todo / 5 );
|
124 |
echo '<input type="hidden" value="' . esc_attr( $laststep ) . '" name="laststep"/>';
|
125 |
$this->progress->progress_ui( $progress );
|
126 |
}
|
127 |
+
|
128 |
echo '</div>';
|
129 |
echo '<br>';
|
130 |
echo '<div class="bp-album-comments">';
|
131 |
+
|
132 |
if ( 0 !== $total_comments ) {
|
133 |
echo '<strong>';
|
134 |
echo esc_html__( 'Comments', 'buddypress-media' ) . ': <span class="finished">' . esc_html( $finished_comments ) . '</span> / <span class="total">' . esc_html( $total_comments ) . '</span>';
|
140 |
echo '<p><strong>' . esc_html__( 'Comments: 0/0 (No comments to import)', 'buddypress-media' ) . '</strong></p>';
|
141 |
}
|
142 |
echo '</div>';
|
143 |
+
|
144 |
if ( 0 !== $completed_users_favorites ) {
|
145 |
echo '<br />';
|
146 |
echo '<div class="bp-album-favorites">';
|
153 |
}
|
154 |
echo '</div>';
|
155 |
} else {
|
156 |
+
$deactivate_link = wp_nonce_url( admin_url( 'plugins.php?action=deactivate&plugin=' . rawurlencode( $this->path ) ), 'deactivate-plugin_' . $this->path );
|
157 |
echo '<p>' . esc_html__( 'BP-Album is active on your site and will cause problems with the import.', 'buddypress-media' ) . '</p>';
|
158 |
echo '<p><a class="button button-primary deactivate-bp-album" href="' . esc_url( $deactivate_link ) . '">' . esc_html__( 'Click here to deactivate BP-Album and continue importing', 'buddypress-media' ) . '</a></p>';
|
159 |
}
|
160 |
} else {
|
161 |
+
$corrupt_media = self::get_corrupt_media();
|
162 |
if ( $corrupt_media ) {
|
163 |
echo '<div class="error below-h2">';
|
164 |
echo '<p><strong>' . esc_html__( 'Some of the media failed to import. The file might be corrupt or deleted.', 'buddypress-media' ) . '</strong></p>';
|
165 |
+
// translators: %d: Media.
|
166 |
echo '<p>' . sprintf( esc_html__( 'The following %d BP Album Media id\'s could not be imported', 'buddypress-media' ), count( $corrupt_media ) ) . ': </p>';
|
167 |
$corrupt_prefix_path = str_replace( '/wp-content', '', WP_CONTENT_URL );
|
168 |
foreach ( $corrupt_media as $corrupt ) {
|
172 |
} else {
|
173 |
echo '<div class="bp-album-import-accept i-accept">';
|
174 |
echo '<p class="info">';
|
175 |
+
// translators: %s: URL.
|
176 |
$message = sprintf( esc_html__( 'I just imported bp-album to @rtMediaWP http://rt.cx/rtmedia on %s', 'buddypress-media' ), home_url() );
|
177 |
echo '<strong>' . esc_html__( 'Congratulations!', 'buddypress-media' ) . '</strong> ' . esc_html__( 'All media from BP Album has been imported.', 'buddypress-media' );
|
178 |
echo ' <a href="http://twitter.com/home/?status=' . esc_url( $message ) . '" class="button button-import-tweet" target= "_blank">' . esc_html__( 'Tweet this', 'buddypress-media' ) . '</a>';
|
190 |
echo '<br />';
|
191 |
echo '<br />';
|
192 |
echo '<br />';
|
193 |
+
echo '<strong>' . esc_html__( 'Why don\'t you try adding some Instagram like effects to your images?', 'buddypress-media' ) . '</strong>';
|
194 |
echo '<div class="bp-media-addon">
|
195 |
<a href="https://rtmedia.io/products/rtmedia-photo-filters/?utm_source=dashboard&utm_medium=plugin&utm_campaign=buddypress-media&utm_content=bp-album-importer" title="rtMedia Photo Filters" target="_blank">
|
196 |
<img width="240" height="184" title="rtMedia Photo Filters" alt="rtMedia Photo Filters" src="' . esc_url( $img_src ) . 'BuddyPressMedia-Instagram.png?ref=bp-album-importer">
|
209 |
echo '</div>';
|
210 |
} else {
|
211 |
echo '<p>' . esc_html__( 'Looks like you don\'t use BP Album. Is there any other BuddyPress Plugin you want an importer for?', 'buddypress-media' ) . '</p>';
|
212 |
+
echo '<p><a href="https://github.com/rtCamp/rtMedia/issues/new">' . esc_html__( 'Create an issue', 'buddypress-media' ) . '</a>';
|
213 |
echo esc_html__( ' on GitHub requesting the same.', 'buddypress-media' ) . '</p>';
|
214 |
}
|
215 |
}
|
216 |
|
217 |
+
/**
|
218 |
+
* Create album.
|
219 |
+
*
|
220 |
+
* @param string $author_id Author id.
|
221 |
+
* @param string $album_name Album name.
|
222 |
+
*
|
223 |
+
* @return mixed
|
224 |
+
*/
|
225 |
+
public function create_album( $author_id, $album_name = 'Imported Media' ) {
|
226 |
global $bp_media, $wpdb;
|
227 |
|
228 |
if ( array_key_exists( 'bp_album_import_name', $bp_media->options ) ) {
|
244 |
return $album_id;
|
245 |
}
|
246 |
|
247 |
+
/**
|
248 |
+
* Get total count.
|
249 |
+
*
|
250 |
+
* @return int
|
251 |
+
*/
|
252 |
+
public static function get_total_count() {
|
253 |
global $wpdb;
|
254 |
$table = $wpdb->base_prefix . 'bp_album';
|
255 |
+
if ( self::table_exists( $table ) ) {
|
256 |
+
return $wpdb->get_results( "SELECT COUNT(DISTINCT owner_id) as users, COUNT(id) as media FROM {$table}" ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
257 |
}
|
258 |
|
259 |
return 0;
|
260 |
}
|
261 |
|
262 |
+
/**
|
263 |
+
* Get remaining comments count.
|
264 |
+
*
|
265 |
+
* @return int
|
266 |
+
*/
|
267 |
+
public function get_remaining_comments() {
|
268 |
global $wpdb;
|
269 |
$bp_album_table = $wpdb->base_prefix . 'bp_album';
|
270 |
$activity_table = $wpdb->base_prefix . 'bp_activity';
|
271 |
if ( $this->table_exists( $bp_album_table ) ) {
|
272 |
+
// phpcs:disable WordPress.DB.PreparedSQL.NotPrepared
|
273 |
+
return $wpdb->get_var(
|
274 |
+
"SELECT SUM( b.count ) AS total
|
275 |
FROM (
|
276 |
SELECT (
|
277 |
SELECT COUNT( a.id )
|
285 |
WHERE activity.component = 'album'
|
286 |
AND activity.type = 'bp_album_picture'
|
287 |
AND album.import_status =0
|
288 |
+
)b"
|
289 |
+
); // phpcs:enable WordPress.DB.PreparedSQL.NotPrepared
|
290 |
}
|
291 |
|
292 |
return 0;
|
293 |
}
|
294 |
|
295 |
+
/**
|
296 |
+
* Get finished comments count.
|
297 |
+
*
|
298 |
+
* @return int
|
299 |
+
*/
|
300 |
+
public function get_finished_comments() {
|
301 |
global $wpdb;
|
302 |
$bp_album_table = $wpdb->base_prefix . 'bp_album';
|
303 |
+
|
304 |
if ( $this->table_exists( $bp_album_table ) ) {
|
305 |
+
return $wpdb->get_var(
|
306 |
+
"SELECT COUNT( activity.id ) AS count
|
307 |
+
FROM {$wpdb->base_prefix}bp_activity AS activity
|
308 |
+
INNER JOIN {$wpdb->base_prefix}bp_album AS album ON ( activity.item_id = album.import_status )
|
309 |
+
WHERE activity.component = 'activity'
|
310 |
+
AND activity.type = 'activity_comment'"
|
311 |
+
);
|
312 |
}
|
313 |
|
314 |
return 0;
|
315 |
}
|
316 |
|
317 |
+
/**
|
318 |
+
* Get completed users count.
|
319 |
+
*
|
320 |
+
* @return int
|
321 |
+
*/
|
322 |
+
public static function get_completed_users() {
|
323 |
global $wpdb;
|
324 |
$table = $wpdb->base_prefix . 'bp_album';
|
325 |
+
if ( self::table_exists( $table ) ) {
|
326 |
+
|
327 |
+
return $wpdb->get_results(
|
328 |
+
"SELECT COUNT( DISTINCT owner_id ) AS users
|
329 |
+
FROM {$wpdb->base_prefix}bp_album
|
330 |
+
WHERE owner_id NOT
|
331 |
+
IN (
|
332 |
+
SELECT a.owner_id
|
333 |
+
FROM {$wpdb->base_prefix}bp_album a
|
334 |
+
WHERE a.import_status =0
|
335 |
+
)"
|
336 |
+
);
|
337 |
+
|
338 |
}
|
339 |
|
340 |
return 0;
|
341 |
}
|
342 |
|
343 |
+
/**
|
344 |
+
* Get completed media count.
|
345 |
+
*
|
346 |
+
* @return int
|
347 |
+
*/
|
348 |
+
public static function get_completed_media() {
|
349 |
global $wpdb;
|
350 |
$table = $wpdb->base_prefix . 'bp_album';
|
351 |
+
if ( self::table_exists( $table ) ) {
|
352 |
+
return $wpdb->get_results( "SELECT COUNT(id) as media FROM {$wpdb->base_prefix}bp_album WHERE import_status!=0" );
|
353 |
}
|
354 |
|
355 |
return 0;
|
356 |
}
|
357 |
|
358 |
+
/**
|
359 |
+
* Get corrupt media data.
|
360 |
+
*
|
361 |
+
* @return int
|
362 |
+
*/
|
363 |
+
public static function get_corrupt_media() {
|
364 |
global $wpdb;
|
365 |
$table = $wpdb->base_prefix . 'bp_album';
|
366 |
+
if ( self::table_exists( $table ) ) {
|
367 |
+
return $wpdb->get_results( "SELECT id,title,pic_org_url FROM {$wpdb->base_prefix}bp_album WHERE import_status=-1" );
|
368 |
}
|
369 |
|
370 |
return 0;
|
371 |
}
|
372 |
|
373 |
+
/**
|
374 |
+
* Batch import albums.
|
375 |
+
*
|
376 |
+
* @param int $count Count for albums to import.
|
377 |
+
*
|
378 |
+
* @return mixed
|
379 |
+
*/
|
380 |
+
public static function batch_import( $count = 5 ) {
|
381 |
global $wpdb;
|
|
|
|
|
382 |
|
383 |
+
$table = $wpdb->base_prefix . 'bp_album';
|
384 |
+
if ( self::table_exists( $table ) ) {
|
385 |
+
$bp_album_data = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->base_prefix}bp_album WHERE import_status = 0 ORDER BY owner_id LIMIT %d", $count ) );
|
386 |
+
return $bp_album_data;
|
387 |
+
}
|
388 |
+
|
389 |
+
return array();
|
390 |
}
|
391 |
|
392 |
+
/**
|
393 |
+
* Ajax import callback function.
|
394 |
+
*/
|
395 |
+
public static function bpmedia_ajax_import_callback() {
|
396 |
+
|
397 |
if ( ! check_ajax_referer( 'bpmedia-bpalbumimporter', 'rtm_wpnonce' ) ) {
|
398 |
wp_send_json( false );
|
399 |
}
|
400 |
+
|
401 |
+
$page = filter_input( INPUT_GET, 'page', FILTER_SANITIZE_NUMBER_INT );
|
402 |
+
$count = filter_input( INPUT_GET, 'count', FILTER_SANITIZE_NUMBER_INT );
|
403 |
$page = isset( $page ) ? $page : 1;
|
404 |
$count = isset( $count ) ? $count : 5;
|
405 |
+
$bp_album_data = self::batch_import( $count );
|
406 |
+
|
407 |
global $wpdb;
|
408 |
+
|
409 |
$table = $wpdb->base_prefix . 'bp_album';
|
410 |
$activity_table = $wpdb->base_prefix . 'bp_activity';
|
411 |
$activity_meta_table = $wpdb->base_prefix . 'bp_activity_meta';
|
412 |
$comments = 0;
|
413 |
+
|
414 |
foreach ( $bp_album_data as &$bp_album_item ) {
|
415 |
|
416 |
if ( get_site_option( 'bp_media_bp_album_importer_base_path' ) === '' ) {
|
419 |
}
|
420 |
$bpm_host_wp = new BPMediaHostWordpress();
|
421 |
$bpm_host_wp->check_and_create_album( 0, 0, $bp_album_item->owner_id );
|
422 |
+
$album_id = self::create_album( $bp_album_item->owner_id, 'Imported Media' );
|
423 |
$imported_media_id = BPMediaImporter::add_media( $album_id, $bp_album_item->title, $bp_album_item->description, $bp_album_item->pic_org_path, $bp_album_item->privacy, $bp_album_item->owner_id, 'Imported Media' );
|
424 |
$wpdb->update( $table, array( 'import_status' => ( $imported_media_id ) ? $imported_media_id : - 1 ), array( 'id' => $bp_album_item->id ), array( '%d' ), array( '%d' ) );
|
425 |
if ( $imported_media_id ) {
|
426 |
+
$comments += (int) self::update_recorded_time_and_comments( $imported_media_id, $bp_album_item->id, "{$wpdb->base_prefix}bp_album" );
|
427 |
|
428 |
+
$bp_album_media_id = $wpdb->get_var( "SELECT activity.id from $activity_table as activity INNER JOIN $table as album ON ( activity.item_id = album.id ) WHERE activity.item_id = $bp_album_item->id AND activity.component = 'album' AND activity.type='bp_album_picture'" ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
429 |
$wpdb->update( $table, array( 'old_activity_id' => $bp_album_media_id ), array( 'id' => $bp_album_item->id ), array( '%d' ), array( '%d' ) );
|
430 |
+
$bp_new_activity_id = $wpdb->get_var( "SELECT id from $activity_table WHERE item_id = $imported_media_id AND component = 'activity' AND type='activity_update' AND secondary_item_id=0" ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
431 |
$wpdb->update( $table, array( 'new_activity_id' => $bp_new_activity_id ), array( 'id' => $bp_album_item->id ), array( '%d' ), array( '%d' ) );
|
432 |
+
|
433 |
+
if ( $wpdb->update(
|
434 |
+
$activity_meta_table,
|
435 |
+
array( 'activity_id' => $bp_new_activity_id ),
|
436 |
+
array(
|
437 |
+
'activity_id' => $bp_album_media_id,
|
438 |
+
'meta_key' => 'favorite_count',
|
439 |
+
),
|
440 |
+
array( '%d' ),
|
441 |
+
array( '%d' )
|
442 |
+
)
|
443 |
) {
|
444 |
$wpdb->update( $table, array( 'favorites' => 1 ), array( 'id' => $bp_album_item->id ), array( '%d' ), array( '%d' ) );
|
445 |
}
|
446 |
}
|
447 |
}
|
448 |
|
449 |
+
$finished_users = self::get_completed_users();
|
450 |
+
|
451 |
+
echo wp_json_encode(
|
452 |
+
array(
|
453 |
+
'page' => $page,
|
454 |
+
'users' => $finished_users[0]->users,
|
455 |
+
'comments' => $comments,
|
456 |
+
)
|
457 |
+
);
|
458 |
|
|
|
459 |
die();
|
460 |
}
|
461 |
|
462 |
+
/**
|
463 |
+
* Ajax import favorites callback.
|
464 |
+
*/
|
465 |
+
public static function bpmedia_ajax_import_favorites() {
|
466 |
+
|
467 |
if ( ! check_ajax_referer( 'bpmedia-bpalbumimporter', 'rtm_wpnonce' ) ) {
|
468 |
wp_send_json( array( 'status' => false ) );
|
469 |
}
|
470 |
+
|
471 |
global $wpdb;
|
472 |
$table = $wpdb->base_prefix . 'bp_album';
|
473 |
$users = count_users();
|
474 |
+
|
475 |
+
echo wp_json_encode(
|
476 |
+
array(
|
477 |
+
'favorites' => $wpdb->get_var( "SELECT COUNT(id) from $table WHERE favorites != 0" ), // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
478 |
+
'users' => $users['total_users'],
|
479 |
+
'offset' => (int) get_site_option( 'bp_media_bp_album_favorite_import_status', 0 ),
|
480 |
+
)
|
481 |
+
);
|
482 |
+
|
483 |
die();
|
484 |
}
|
485 |
|
486 |
+
/**
|
487 |
+
* Ajax import step favorites callback.
|
488 |
+
*/
|
489 |
+
public static function bpmedia_ajax_import_step_favorites() {
|
490 |
+
|
491 |
if ( ! check_ajax_referer( 'bpmedia-bpalbumimporter', 'rtm_wpnonce' ) ) {
|
492 |
wp_send_json( array( 'status' => false ) );
|
493 |
}
|
494 |
+
|
495 |
+
$offset = filter_input( INPUT_GET, 'offset', FILTER_SANITIZE_NUMBER_INT );
|
496 |
$redirect = filter_input( INPUT_GET, 'redirect', FILTER_SANITIZE_URL );
|
497 |
$offset = isset( $offset ) ? $offset : 0;
|
498 |
$redirect = isset( $redirect ) ? $redirect : false;
|
499 |
+
|
500 |
global $wpdb;
|
501 |
+
|
502 |
$table = $wpdb->base_prefix . 'bp_album';
|
503 |
+
$blogusers = get_users(
|
504 |
+
array(
|
505 |
+
'meta_key' => 'bp_favorite_activities',
|
506 |
+
'offset' => $offset,
|
507 |
+
'number' => 1,
|
508 |
+
)
|
509 |
+
);
|
510 |
+
|
511 |
if ( $blogusers ) {
|
512 |
foreach ( $blogusers as $user ) {
|
513 |
+
|
514 |
$favorite_activities = get_user_meta( $user->ID, 'bp_favorite_activities', true );
|
515 |
+
|
516 |
if ( $favorite_activities ) {
|
517 |
+
|
518 |
$new_favorite_activities = $favorite_activities;
|
519 |
foreach ( $favorite_activities as $key => $favorite ) {
|
520 |
+
$new_act = $wpdb->get_var( $wpdb->prepare( "SELECT new_activity_id from $table WHERE old_activity_id = %d limit 1", $favorite ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
521 |
+
if ( ! empty( $new_act ) ) {
|
522 |
$new_favorite_activities[ $key ] = $new_act;
|
523 |
}
|
524 |
}
|
528 |
update_site_option( 'bp_media_bp_album_favorite_import_status', $completed_users_favorites );
|
529 |
}
|
530 |
}
|
531 |
+
|
532 |
echo esc_url( $redirect );
|
533 |
die();
|
534 |
}
|
535 |
|
536 |
+
/**
|
537 |
+
* Cleanup after install.
|
538 |
+
*/
|
539 |
+
public static function cleanup_after_install() {
|
540 |
global $wpdb;
|
541 |
+
|
542 |
if ( ! check_ajax_referer( 'bpmedia-bpalbumimporter', 'rtm_wpnonce' ) ) {
|
543 |
wp_send_json( array( 'status' => false ) );
|
544 |
}
|
545 |
+
|
546 |
$table = $wpdb->base_prefix . 'bp_album';
|
547 |
$dir = get_site_option( 'bp_media_bp_album_importer_base_path' );
|
548 |
BPMediaImporter::cleanup( $table, $dir );
|
549 |
die();
|
550 |
}
|
551 |
|
552 |
+
/**
|
553 |
+
* Update recorded time and comments.
|
554 |
+
*
|
555 |
+
* @param object $media Media.
|
556 |
+
* @param int $bp_album_id Album id.
|
557 |
+
* @param string $table Table.
|
558 |
+
*
|
559 |
+
* @return bool|int
|
560 |
+
*/
|
561 |
+
public static function update_recorded_time_and_comments( $media, $bp_album_id, $table ) {
|
562 |
global $wpdb;
|
563 |
if ( function_exists( 'bp_activity_add' ) ) {
|
564 |
if ( ! is_object( $media ) ) {
|
568 |
return false;
|
569 |
}
|
570 |
}
|
571 |
+
|
572 |
$activity_id = get_post_meta( $media->get_id(), 'bp_media_child_activity', true );
|
573 |
+
$comments = 0;
|
574 |
+
|
575 |
if ( $activity_id ) {
|
576 |
+
$date_uploaded = $wpdb->get_var( $wpdb->prepare( "SELECT date_uploaded from $table WHERE id = %d", $bp_album_id ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
577 |
$old_activity_id = $wpdb->get_var( $wpdb->prepare( "SELECT id from {$wpdb->base_prefix}bp_activity WHERE component = 'album' AND type = 'bp_album_picture' AND item_id = %d", $bp_album_id ) );
|
578 |
if ( $old_activity_id ) {
|
579 |
$comments = $wpdb->get_results( $wpdb->prepare( "SELECT id,secondary_item_id from {$wpdb->base_prefix}bp_activity WHERE component = 'activity' AND type = 'activity_comment' AND item_id = %d", $old_activity_id ) );
|
595 |
}
|
596 |
}
|
597 |
|
598 |
+
/**
|
599 |
+
* BPAlbum plugin deactivate.
|
600 |
+
*/
|
601 |
+
public static function bp_album_deactivate() {
|
602 |
if ( ! check_ajax_referer( 'bpmedia-bpalbumimporter', 'rtm_wpnonce' ) ) {
|
603 |
deactivate_plugins( 'bp-album/loader.php' );
|
604 |
}
|
app/importers/BPMediaBPActivityPlusImporter.php
CHANGED
@@ -1,22 +1,22 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
/*
|
4 |
* To change this template, choose Tools | Templates
|
5 |
* and open the template in the editor.
|
|
|
|
|
6 |
*/
|
7 |
|
8 |
/**
|
9 |
-
*
|
10 |
*
|
11 |
* @author saurabh
|
12 |
*/
|
13 |
class BPMediaBPActivityPlusImporter extends BPMediaImporter {
|
14 |
|
15 |
/**
|
16 |
-
*
|
17 |
*/
|
18 |
-
function __construct() {
|
19 |
parent::__construct();
|
20 |
-
|
21 |
}
|
22 |
}
|
1 |
<?php
|
2 |
+
/**
|
|
|
3 |
* To change this template, choose Tools | Templates
|
4 |
* and open the template in the editor.
|
5 |
+
*
|
6 |
+
* @package rtMedia
|
7 |
*/
|
8 |
|
9 |
/**
|
10 |
+
* Class for BPMedia import
|
11 |
*
|
12 |
* @author saurabh
|
13 |
*/
|
14 |
class BPMediaBPActivityPlusImporter extends BPMediaImporter {
|
15 |
|
16 |
/**
|
17 |
+
* BPMediaBPActivityPlusImporter constructor.
|
18 |
*/
|
19 |
+
public function __construct() { // phpcs:ignore Generic.CodeAnalysis.UselessOverridingMethod.Found
|
20 |
parent::__construct();
|
|
|
21 |
}
|
22 |
}
|
app/importers/BPMediaImporter.php
CHANGED
@@ -1,40 +1,65 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
|
4 |
-
*
|
5 |
-
*
|
6 |
*/
|
7 |
|
8 |
/**
|
9 |
-
*
|
10 |
*
|
11 |
* @author saurabh
|
12 |
*/
|
13 |
class BPMediaImporter {
|
14 |
|
15 |
/**
|
|
|
16 |
*
|
|
|
17 |
*/
|
18 |
-
|
19 |
-
var $import_steps;
|
20 |
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
}
|
24 |
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
global $wpdb;
|
27 |
|
28 |
-
if ( 1 === intval( $wpdb->query( $wpdb->prepare( 'SHOW TABLES LIKE %s', $table )
|
29 |
return true;
|
30 |
}
|
31 |
|
32 |
return false;
|
33 |
}
|
34 |
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
if ( ! function_exists( 'is_plugin_inactive' ) ) {
|
37 |
-
require_once
|
38 |
}
|
39 |
if ( is_plugin_active( $path ) ) {
|
40 |
return 1;
|
@@ -47,7 +72,14 @@ class BPMediaImporter {
|
|
47 |
}
|
48 |
}
|
49 |
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
$path_info = pathinfo( $filepath );
|
53 |
$filetype = wp_check_filetype( $filepath );
|
@@ -60,24 +92,42 @@ class BPMediaImporter {
|
|
60 |
return $file;
|
61 |
}
|
62 |
|
63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
$upload_dir = wp_upload_dir();
|
65 |
$path_info = pathinfo( $filepath );
|
66 |
$tmp_dir = trailingslashit( $upload_dir['basedir'] ) . 'bp-album-importer';
|
67 |
$newpath = trailingslashit( $tmp_dir ) . $path_info['basename'];
|
|
|
68 |
if ( ! is_dir( $tmp_dir ) ) {
|
69 |
wp_mkdir_p( $tmp_dir );
|
70 |
}
|
|
|
71 |
if ( file_exists( $filepath ) ) {
|
72 |
if ( copy( $filepath, $newpath ) ) {
|
73 |
-
return
|
74 |
}
|
75 |
}
|
76 |
|
77 |
return 0;
|
78 |
}
|
79 |
|
80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
|
82 |
global $bp_media;
|
83 |
|
@@ -99,14 +149,32 @@ class BPMediaImporter {
|
|
99 |
return $album_id;
|
100 |
}
|
101 |
|
102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
|
104 |
-
$files =
|
105 |
if ( $files ) {
|
106 |
$bp_imported_media = new BPMediaHostWordpress();
|
107 |
$imported_media_id = $bp_imported_media->insertmedia( $title, $description, $album_id, 0, false, false, $files, $author_id, $album_name );
|
108 |
|
109 |
-
|
|
|
|
|
|
|
|
|
|
|
110 |
|
111 |
$bp_album_privacy = $privacy;
|
112 |
if ( 10 === intval( $bp_album_privacy ) ) {
|
@@ -122,21 +190,34 @@ class BPMediaImporter {
|
|
122 |
return 0;
|
123 |
}
|
124 |
|
125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
global $wpdb;
|
127 |
-
$wpdb->query( "DROP TABLE IF EXISTS $table" ); //
|
128 |
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->base_prefix}bp_activity WHERE component = %s", 'album' ) );
|
129 |
if ( is_dir( $directory ) ) {
|
130 |
-
|
131 |
}
|
132 |
}
|
133 |
|
134 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
if ( true === is_dir( $path ) ) {
|
136 |
$files = array_diff( scandir( $path ), array( '.', '..' ) );
|
137 |
|
138 |
foreach ( $files as $file ) {
|
139 |
-
|
140 |
}
|
141 |
|
142 |
return rmdir( $path );
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* Handles BuddyPress media import
|
4 |
+
*
|
5 |
+
* @package rtMedia
|
6 |
*/
|
7 |
|
8 |
/**
|
9 |
+
* Class for BuddyPress media import
|
10 |
*
|
11 |
* @author saurabh
|
12 |
*/
|
13 |
class BPMediaImporter {
|
14 |
|
15 |
/**
|
16 |
+
* Active.
|
17 |
*
|
18 |
+
* @var $active
|
19 |
*/
|
20 |
+
public $active;
|
|
|
21 |
|
22 |
+
/**
|
23 |
+
* Import steps.
|
24 |
+
*
|
25 |
+
* @var $import_steps
|
26 |
+
*/
|
27 |
+
public $import_steps;
|
28 |
+
|
29 |
+
/**
|
30 |
+
* BPMediaImporter constructor.
|
31 |
+
*/
|
32 |
+
public function __construct() {
|
33 |
|
34 |
}
|
35 |
|
36 |
+
/**
|
37 |
+
* Check if table exists.
|
38 |
+
*
|
39 |
+
* @param string $table Table name.
|
40 |
+
*
|
41 |
+
* @return bool
|
42 |
+
*/
|
43 |
+
public static function table_exists( $table ) {
|
44 |
global $wpdb;
|
45 |
|
46 |
+
if ( 1 === intval( $wpdb->query( $wpdb->prepare( 'SHOW TABLES LIKE %s', $table ) ) ) ) {
|
47 |
return true;
|
48 |
}
|
49 |
|
50 |
return false;
|
51 |
}
|
52 |
|
53 |
+
/**
|
54 |
+
* Function to check if plugin is active.
|
55 |
+
*
|
56 |
+
* @param string $path Plugin path.
|
57 |
+
*
|
58 |
+
* @return int
|
59 |
+
*/
|
60 |
+
public static function _active( $path ) { // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore
|
61 |
if ( ! function_exists( 'is_plugin_inactive' ) ) {
|
62 |
+
require_once ABSPATH . '/wp-admin/includes/plugin.php';
|
63 |
}
|
64 |
if ( is_plugin_active( $path ) ) {
|
65 |
return 1;
|
72 |
}
|
73 |
}
|
74 |
|
75 |
+
/**
|
76 |
+
* Function get file information.
|
77 |
+
*
|
78 |
+
* @param string $filepath Filepath.
|
79 |
+
*
|
80 |
+
* @return mixed
|
81 |
+
*/
|
82 |
+
public static function file_array( $filepath ) {
|
83 |
|
84 |
$path_info = pathinfo( $filepath );
|
85 |
$filetype = wp_check_filetype( $filepath );
|
92 |
return $file;
|
93 |
}
|
94 |
|
95 |
+
/**
|
96 |
+
* Function to make copy of file.
|
97 |
+
*
|
98 |
+
* @param string $filepath Filepath.
|
99 |
+
*
|
100 |
+
* @return int|mixed
|
101 |
+
*/
|
102 |
+
public static function make_copy( $filepath ) {
|
103 |
+
|
104 |
$upload_dir = wp_upload_dir();
|
105 |
$path_info = pathinfo( $filepath );
|
106 |
$tmp_dir = trailingslashit( $upload_dir['basedir'] ) . 'bp-album-importer';
|
107 |
$newpath = trailingslashit( $tmp_dir ) . $path_info['basename'];
|
108 |
+
|
109 |
if ( ! is_dir( $tmp_dir ) ) {
|
110 |
wp_mkdir_p( $tmp_dir );
|
111 |
}
|
112 |
+
|
113 |
if ( file_exists( $filepath ) ) {
|
114 |
if ( copy( $filepath, $newpath ) ) {
|
115 |
+
return self::file_array( $newpath );
|
116 |
}
|
117 |
}
|
118 |
|
119 |
return 0;
|
120 |
}
|
121 |
|
122 |
+
/**
|
123 |
+
* Create Album.
|
124 |
+
*
|
125 |
+
* @param string $album_name Album name.
|
126 |
+
* @param int $author_id Author id.
|
127 |
+
*
|
128 |
+
* @return mixed
|
129 |
+
*/
|
130 |
+
public function create_album( $album_name = '', $author_id = 1 ) {
|
131 |
|
132 |
global $bp_media;
|
133 |
|
149 |
return $album_id;
|
150 |
}
|
151 |
|
152 |
+
/**
|
153 |
+
* Add media into album.
|
154 |
+
*
|
155 |
+
* @param int $album_id Album media.
|
156 |
+
* @param string $title Media title.
|
157 |
+
* @param string $description Media description.
|
158 |
+
* @param string $filepath File path.
|
159 |
+
* @param int $privacy Privacy.
|
160 |
+
* @param bool $author_id Author id.
|
161 |
+
* @param bool $album_name Album name.
|
162 |
+
*
|
163 |
+
* @return int
|
164 |
+
*/
|
165 |
+
public static function add_media( $album_id, $title = '', $description = '', $filepath = '', $privacy = 0, $author_id = false, $album_name = false ) {
|
166 |
|
167 |
+
$files = self::make_copy( $filepath );
|
168 |
if ( $files ) {
|
169 |
$bp_imported_media = new BPMediaHostWordpress();
|
170 |
$imported_media_id = $bp_imported_media->insertmedia( $title, $description, $album_id, 0, false, false, $files, $author_id, $album_name );
|
171 |
|
172 |
+
$args = array(
|
173 |
+
'ID' => $imported_media_id,
|
174 |
+
'post_author' => $author_id,
|
175 |
+
);
|
176 |
+
|
177 |
+
wp_update_post( $args );
|
178 |
|
179 |
$bp_album_privacy = $privacy;
|
180 |
if ( 10 === intval( $bp_album_privacy ) ) {
|
190 |
return 0;
|
191 |
}
|
192 |
|
193 |
+
/**
|
194 |
+
* Function to do cleanup(Delete tables and directories).
|
195 |
+
*
|
196 |
+
* @param string $table Table.
|
197 |
+
* @param string $directory Directory.
|
198 |
+
*/
|
199 |
+
public static function cleanup( $table, $directory ) {
|
200 |
global $wpdb;
|
201 |
+
$wpdb->query( "DROP TABLE IF EXISTS $table" ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
202 |
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->base_prefix}bp_activity WHERE component = %s", 'album' ) );
|
203 |
if ( is_dir( $directory ) ) {
|
204 |
+
self::delete( $directory );
|
205 |
}
|
206 |
}
|
207 |
|
208 |
+
/**
|
209 |
+
* Delete Directory.
|
210 |
+
*
|
211 |
+
* @param string $path Path.
|
212 |
+
*
|
213 |
+
* @return bool
|
214 |
+
*/
|
215 |
+
public static function delete( $path ) {
|
216 |
if ( true === is_dir( $path ) ) {
|
217 |
$files = array_diff( scandir( $path ), array( '.', '..' ) );
|
218 |
|
219 |
foreach ( $files as $file ) {
|
220 |
+
self::delete( realpath( $path ) . '/' . $file );
|
221 |
}
|
222 |
|
223 |
return rmdir( $path );
|
app/importers/RTMediaActivityUpgrade.php
CHANGED
@@ -1,14 +1,22 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
/**
|
4 |
-
*
|
5 |
* User: ritz <ritesh.patel@rtcamp.com>
|
6 |
* Date: 11/9/14
|
7 |
* Time: 1:56 PM
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
*/
|
9 |
class RTMediaActivityUpgrade {
|
10 |
|
11 |
-
|
|
|
|
|
|
|
12 |
add_filter( 'rtmedia_filter_admin_pages_array', array( $this, 'rtmedia_add_admin_page_array' ), 11, 1 );
|
13 |
add_action( 'admin_init', array( $this, 'add_admin_notice' ) );
|
14 |
add_action( 'admin_menu', array( $this, 'menu' ), 10 );
|
@@ -16,35 +24,62 @@ class RTMediaActivityUpgrade {
|
|
16 |
add_action( 'wp_ajax_rtmedia_activity_done_upgrade', array( $this, 'rtmedia_activity_done_upgrade' ) );
|
17 |
}
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
}
|
25 |
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
$admin_pages[] = 'rtmedia_page_rtmedia-activity-upgrade';
|
28 |
|
29 |
return $admin_pages;
|
30 |
}
|
31 |
|
32 |
-
|
|
|
|
|
|
|
33 |
rtmedia_update_site_option( 'rtmedia_activity_done_upgrade', true );
|
34 |
die();
|
35 |
}
|
36 |
|
37 |
-
|
|
|
|
|
|
|
38 |
$pending = $this->get_pending_count();
|
39 |
$upgrade_done = rtmedia_get_site_option( 'rtmedia_activity_done_upgrade' );
|
|
|
40 |
if ( $upgrade_done ) {
|
41 |
return;
|
42 |
}
|
|
|
43 |
if ( $pending < 0 ) {
|
44 |
$pending = 0;
|
45 |
}
|
|
|
46 |
rtmedia_update_site_option( 'rtmedia_media_activity_upgrade_pending', $pending );
|
47 |
$page = filter_input( INPUT_GET, 'page', FILTER_SANITIZE_STRING );
|
|
|
48 |
if ( $pending > 0 ) {
|
49 |
if ( ! ( isset( $page ) && 'rtmedia-activity-upgrade' === $page ) ) {
|
50 |
$site_option = get_site_option( 'rtmedia_activity_upgrade_notice' );
|
@@ -58,18 +93,27 @@ class RTMediaActivityUpgrade {
|
|
58 |
}
|
59 |
}
|
60 |
|
61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
global $wpdb;
|
63 |
if ( check_ajax_referer( 'rtmedia_media_activity_upgrade_nonce', 'nonce' ) ) {
|
64 |
$rtmedia_model = new RTMediaModel();
|
65 |
$rtmedia_activity_model = new RTMediaActivityModel();
|
66 |
-
$activity_sql = $wpdb->prepare( " SELECT *, max(privacy) as max_privacy FROM {$rtmedia_model->table_name} WHERE activity_id is NOT NULL GROUP BY activity_id ORDER BY id limit %d", $limit ); //
|
67 |
|
68 |
$lastid = filter_input( INPUT_POST, 'last_id', FILTER_SANITIZE_NUMBER_INT );
|
|
|
69 |
if ( ! empty( $lastid ) ) {
|
70 |
-
$activity_sql = $wpdb->prepare( " SELECT *, max(privacy) as max_privacy FROM {$rtmedia_model->table_name} WHERE activity_id > %d AND activity_id is NOT NULL GROUP BY activity_id ORDER BY id limit %d", $lastid, $limit ); //
|
71 |
}
|
72 |
-
|
|
|
|
|
73 |
if ( is_array( $activity_data ) && ! empty( $activity_data ) ) {
|
74 |
if ( $rtmedia_activity_model->check( $activity_data[0]->activity_id ) ) {
|
75 |
$rtmedia_activity_model->update(
|
@@ -77,7 +121,8 @@ class RTMediaActivityUpgrade {
|
|
77 |
'activity_id' => $activity_data[0]->activity_id,
|
78 |
'user_id' => $activity_data[0]->media_author,
|
79 |
'privacy' => $activity_data[0]->max_privacy,
|
80 |
-
),
|
|
|
81 |
);
|
82 |
} else {
|
83 |
$rtmedia_activity_model->insert(
|
@@ -97,37 +142,52 @@ class RTMediaActivityUpgrade {
|
|
97 |
|
98 |
}
|
99 |
|
100 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
$total = $this->get_total_count();
|
102 |
$pending = $this->get_pending_count( $activity_data->activity_id );
|
103 |
$done = $total - $pending;
|
|
|
104 |
if ( $pending < 0 ) {
|
105 |
$pending = 0;
|
106 |
$done = $total;
|
107 |
}
|
|
|
108 |
if ( $done > $total ) {
|
109 |
$done = $total;
|
110 |
}
|
|
|
111 |
rtmedia_update_site_option( 'rtmedia_media_activity_upgrade_pending', $pending );
|
112 |
$pending_time = rtmedia_migrate_formatseconds( $pending ) . ' (estimated)';
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
|
|
|
|
|
|
121 |
die();
|
122 |
}
|
123 |
|
124 |
-
|
|
|
|
|
|
|
125 |
if ( current_user_can( 'manage_options' ) ) {
|
126 |
?>
|
127 |
<div class='error rtmedia-activity-upgrade-notice'>
|
128 |
<p><strong><?php esc_html_e( 'rtMedia', 'buddypress-media' ); ?></strong>
|
129 |
<?php esc_html_e( ': Database table structure for rtMedia has been updated. Please ', 'buddypress-media' ); ?>
|
130 |
-
<a href='<?php echo esc_url( admin_url( 'admin.php?page=rtmedia-activity-upgrade' ) ); ?>'><?php esc_html_e( 'Click Here', 'buddypress-media' ) ?></a>
|
131 |
<?php esc_html_e( ' to upgrade rtMedia activities.', 'buddypress-media' ); ?>
|
132 |
</p>
|
133 |
</div>
|
@@ -135,16 +195,26 @@ class RTMediaActivityUpgrade {
|
|
135 |
}
|
136 |
}
|
137 |
|
138 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
139 |
global $wpdb;
|
140 |
$rtmedia_activity_model = new RTMediaActivityModel();
|
141 |
$rtmedia_model = new RTMediaModel();
|
142 |
-
$query_pending = $wpdb->prepare( " SELECT count( DISTINCT activity_id) as pending from {$rtmedia_model->table_name} where activity_id NOT IN( SELECT activity_id from {$rtmedia_activity_model->table_name} ) AND activity_id > %d ", 0 ); //
|
143 |
$last_imported = $this->get_last_imported();
|
|
|
144 |
if ( $last_imported ) {
|
145 |
$query_pending .= $wpdb->prepare( ' AND activity_id > %d', intval( $last_imported ) );
|
146 |
}
|
147 |
-
|
|
|
|
|
148 |
if ( $pending_count && count( $pending_count ) > 0 ) {
|
149 |
return $pending_count[0]->pending;
|
150 |
}
|
@@ -152,11 +222,16 @@ class RTMediaActivityUpgrade {
|
|
152 |
return 0;
|
153 |
}
|
154 |
|
155 |
-
|
|
|
|
|
|
|
|
|
|
|
156 |
global $wpdb;
|
157 |
$rtmedia_model = new RTMediaModel();
|
158 |
-
$
|
159 |
-
|
160 |
if ( $total_count && count( $total_count ) > 0 ) {
|
161 |
return $total_count[0]->total;
|
162 |
}
|
@@ -164,11 +239,16 @@ class RTMediaActivityUpgrade {
|
|
164 |
return 0;
|
165 |
}
|
166 |
|
167 |
-
|
|
|
|
|
|
|
|
|
|
|
168 |
global $wpdb;
|
169 |
$rtmedia_activity_model = new RTMediaActivityModel();
|
170 |
-
$
|
171 |
-
|
172 |
if ( $last_imported && count( $last_imported ) > 0 && isset( $last_imported[0] ) && isset( $last_imported[0]->activity_id ) ) {
|
173 |
return $last_imported[0]->activity_id;
|
174 |
}
|
@@ -176,7 +256,10 @@ class RTMediaActivityUpgrade {
|
|
176 |
return 0;
|
177 |
}
|
178 |
|
179 |
-
|
|
|
|
|
|
|
180 |
$prog = new rtProgress();
|
181 |
$pending = $this->get_pending_count();
|
182 |
$total = $this->get_total_count();
|
@@ -188,6 +271,7 @@ class RTMediaActivityUpgrade {
|
|
188 |
<h2><?php esc_html_e( 'rtMedia: Upgrade rtMedia activity', 'buddypress-media' ); ?></h2>
|
189 |
<?php
|
190 |
wp_nonce_field( 'rtmedia_media_activity_upgrade_nonce', 'rtmedia_media_activity_upgrade_nonce' );
|
|
|
191 |
echo '<span class="pending">' . sprintf( esc_html__( '%s (estimated)', 'buddypress-media' ), esc_html( rtmedia_migrate_formatseconds( $total - $done ) ) ) . '</span><br />';
|
192 |
echo '<span class="finished">' . esc_html( $done ) . '</span>/<span class="total">' . esc_html( $total ) . '</span>';
|
193 |
echo '<img src="images/loading.gif" alt="syncing" id="rtMediaSyncing" style="display:none" />';
|
1 |
<?php
|
|
|
2 |
/**
|
3 |
+
* Handles rtMedia activities
|
4 |
* User: ritz <ritesh.patel@rtcamp.com>
|
5 |
* Date: 11/9/14
|
6 |
* Time: 1:56 PM
|
7 |
+
*
|
8 |
+
* @package rtMedia
|
9 |
+
*/
|
10 |
+
|
11 |
+
/**
|
12 |
+
* Class to update rtMedia activities
|
13 |
*/
|
14 |
class RTMediaActivityUpgrade {
|
15 |
|
16 |
+
/**
|
17 |
+
* RTMediaActivityUpgrade constructor.
|
18 |
+
*/
|
19 |
+
public function __construct() {
|
20 |
add_filter( 'rtmedia_filter_admin_pages_array', array( $this, 'rtmedia_add_admin_page_array' ), 11, 1 );
|
21 |
add_action( 'admin_init', array( $this, 'add_admin_notice' ) );
|
22 |
add_action( 'admin_menu', array( $this, 'menu' ), 10 );
|
24 |
add_action( 'wp_ajax_rtmedia_activity_done_upgrade', array( $this, 'rtmedia_activity_done_upgrade' ) );
|
25 |
}
|
26 |
|
27 |
+
/**
|
28 |
+
* Add Media activity upgrade Menu.
|
29 |
+
*/
|
30 |
+
public function menu() {
|
31 |
+
add_submenu_page(
|
32 |
+
'rtmedia-setting',
|
33 |
+
esc_html__( 'Media activity upgrade', 'buddypress-media' ),
|
34 |
+
esc_html__( 'Media activity upgrade', 'buddypress-media' ),
|
35 |
+
'manage_options',
|
36 |
+
'rtmedia-activity-upgrade',
|
37 |
+
array(
|
38 |
+
$this,
|
39 |
+
'init',
|
40 |
+
)
|
41 |
+
);
|
42 |
}
|
43 |
|
44 |
+
/**
|
45 |
+
* Add admin page array.
|
46 |
+
*
|
47 |
+
* @param array $admin_pages Admin pages array.
|
48 |
+
*
|
49 |
+
* @return array
|
50 |
+
*/
|
51 |
+
public function rtmedia_add_admin_page_array( $admin_pages ) {
|
52 |
$admin_pages[] = 'rtmedia_page_rtmedia-activity-upgrade';
|
53 |
|
54 |
return $admin_pages;
|
55 |
}
|
56 |
|
57 |
+
/**
|
58 |
+
* Function to update option after activity upgrade is done.
|
59 |
+
*/
|
60 |
+
public function rtmedia_activity_done_upgrade() {
|
61 |
rtmedia_update_site_option( 'rtmedia_activity_done_upgrade', true );
|
62 |
die();
|
63 |
}
|
64 |
|
65 |
+
/**
|
66 |
+
* Add admin notice for activity upgrade.
|
67 |
+
*/
|
68 |
+
public function add_admin_notice() {
|
69 |
$pending = $this->get_pending_count();
|
70 |
$upgrade_done = rtmedia_get_site_option( 'rtmedia_activity_done_upgrade' );
|
71 |
+
|
72 |
if ( $upgrade_done ) {
|
73 |
return;
|
74 |
}
|
75 |
+
|
76 |
if ( $pending < 0 ) {
|
77 |
$pending = 0;
|
78 |
}
|
79 |
+
|
80 |
rtmedia_update_site_option( 'rtmedia_media_activity_upgrade_pending', $pending );
|
81 |
$page = filter_input( INPUT_GET, 'page', FILTER_SANITIZE_STRING );
|
82 |
+
|
83 |
if ( $pending > 0 ) {
|
84 |
if ( ! ( isset( $page ) && 'rtmedia-activity-upgrade' === $page ) ) {
|
85 |
$site_option = get_site_option( 'rtmedia_activity_upgrade_notice' );
|
93 |
}
|
94 |
}
|
95 |
|
96 |
+
/**
|
97 |
+
* Ajax callback for activity upgrade.
|
98 |
+
*
|
99 |
+
* @param int $lastid Last id.
|
100 |
+
* @param int $limit Limit for query.
|
101 |
+
*/
|
102 |
+
public function rtmedia_activity_upgrade( $lastid = 0, $limit = 1 ) {
|
103 |
global $wpdb;
|
104 |
if ( check_ajax_referer( 'rtmedia_media_activity_upgrade_nonce', 'nonce' ) ) {
|
105 |
$rtmedia_model = new RTMediaModel();
|
106 |
$rtmedia_activity_model = new RTMediaActivityModel();
|
107 |
+
$activity_sql = $wpdb->prepare( " SELECT *, max(privacy) as max_privacy FROM {$rtmedia_model->table_name} WHERE activity_id is NOT NULL GROUP BY activity_id ORDER BY id limit %d", $limit ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
108 |
|
109 |
$lastid = filter_input( INPUT_POST, 'last_id', FILTER_SANITIZE_NUMBER_INT );
|
110 |
+
|
111 |
if ( ! empty( $lastid ) ) {
|
112 |
+
$activity_sql = $wpdb->prepare( " SELECT *, max(privacy) as max_privacy FROM {$rtmedia_model->table_name} WHERE activity_id > %d AND activity_id is NOT NULL GROUP BY activity_id ORDER BY id limit %d", $lastid, $limit ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
113 |
}
|
114 |
+
|
115 |
+
$activity_data = $wpdb->get_results( $activity_sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
116 |
+
|
117 |
if ( is_array( $activity_data ) && ! empty( $activity_data ) ) {
|
118 |
if ( $rtmedia_activity_model->check( $activity_data[0]->activity_id ) ) {
|
119 |
$rtmedia_activity_model->update(
|
121 |
'activity_id' => $activity_data[0]->activity_id,
|
122 |
'user_id' => $activity_data[0]->media_author,
|
123 |
'privacy' => $activity_data[0]->max_privacy,
|
124 |
+
),
|
125 |
+
array( 'activity_id' => $activity_data[0]->activity_id )
|
126 |
);
|
127 |
} else {
|
128 |
$rtmedia_activity_model->insert(
|
142 |
|
143 |
}
|
144 |
|
145 |
+
/**
|
146 |
+
* Function to get upgraded activity details.
|
147 |
+
*
|
148 |
+
* @param object $activity_data Activity data object.
|
149 |
+
* @param bool $upgrade Upgrade done or not.
|
150 |
+
*/
|
151 |
+
public function return_upgrade( $activity_data, $upgrade = true ) {
|
152 |
$total = $this->get_total_count();
|
153 |
$pending = $this->get_pending_count( $activity_data->activity_id );
|
154 |
$done = $total - $pending;
|
155 |
+
|
156 |
if ( $pending < 0 ) {
|
157 |
$pending = 0;
|
158 |
$done = $total;
|
159 |
}
|
160 |
+
|
161 |
if ( $done > $total ) {
|
162 |
$done = $total;
|
163 |
}
|
164 |
+
|
165 |
rtmedia_update_site_option( 'rtmedia_media_activity_upgrade_pending', $pending );
|
166 |
$pending_time = rtmedia_migrate_formatseconds( $pending ) . ' (estimated)';
|
167 |
+
|
168 |
+
echo wp_json_encode(
|
169 |
+
array(
|
170 |
+
'status' => true,
|
171 |
+
'done' => $done,
|
172 |
+
'total' => $total,
|
173 |
+
'pending' => $pending_time,
|
174 |
+
'activity_id' => $activity_data->activity_id,
|
175 |
+
'imported' => $upgrade,
|
176 |
+
)
|
177 |
+
);
|
178 |
die();
|
179 |
}
|
180 |
|
181 |
+
/**
|
182 |
+
* Media activity upgrade notice.
|
183 |
+
*/
|
184 |
+
public function add_rtmedia_media_activity_upgrade_notice() {
|
185 |
if ( current_user_can( 'manage_options' ) ) {
|
186 |
?>
|
187 |
<div class='error rtmedia-activity-upgrade-notice'>
|
188 |
<p><strong><?php esc_html_e( 'rtMedia', 'buddypress-media' ); ?></strong>
|
189 |
<?php esc_html_e( ': Database table structure for rtMedia has been updated. Please ', 'buddypress-media' ); ?>
|
190 |
+
<a href='<?php echo esc_url( admin_url( 'admin.php?page=rtmedia-activity-upgrade' ) ); ?>'><?php esc_html_e( 'Click Here', 'buddypress-media' ); ?></a>
|
191 |
<?php esc_html_e( ' to upgrade rtMedia activities.', 'buddypress-media' ); ?>
|
192 |
</p>
|
193 |
</div>
|
195 |
}
|
196 |
}
|
197 |
|
198 |
+
/**
|
199 |
+
* Get pending count.
|
200 |
+
*
|
201 |
+
* @param bool|int $activity_id Activity id.
|
202 |
+
*
|
203 |
+
* @return int
|
204 |
+
*/
|
205 |
+
public function get_pending_count( $activity_id = false ) {
|
206 |
global $wpdb;
|
207 |
$rtmedia_activity_model = new RTMediaActivityModel();
|
208 |
$rtmedia_model = new RTMediaModel();
|
209 |
+
$query_pending = $wpdb->prepare( " SELECT count( DISTINCT activity_id) as pending from {$rtmedia_model->table_name} where activity_id NOT IN( SELECT activity_id from {$rtmedia_activity_model->table_name} ) AND activity_id > %d ", 0 ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
210 |
$last_imported = $this->get_last_imported();
|
211 |
+
|
212 |
if ( $last_imported ) {
|
213 |
$query_pending .= $wpdb->prepare( ' AND activity_id > %d', intval( $last_imported ) );
|
214 |
}
|
215 |
+
|
216 |
+
$pending_count = $wpdb->get_results( $query_pending ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
217 |
+
|
218 |
if ( $pending_count && count( $pending_count ) > 0 ) {
|
219 |
return $pending_count[0]->pending;
|
220 |
}
|
222 |
return 0;
|
223 |
}
|
224 |
|
225 |
+
/**
|
226 |
+
* Get total count.
|
227 |
+
*
|
228 |
+
* @return int
|
229 |
+
*/
|
230 |
+
public function get_total_count() {
|
231 |
global $wpdb;
|
232 |
$rtmedia_model = new RTMediaModel();
|
233 |
+
$total_count = $wpdb->get_results( $wpdb->prepare( " SELECT count( DISTINCT activity_id) as total FROM {$rtmedia_model->table_name} WHERE activity_id > %d ", 0 ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
234 |
+
|
235 |
if ( $total_count && count( $total_count ) > 0 ) {
|
236 |
return $total_count[0]->total;
|
237 |
}
|
239 |
return 0;
|
240 |
}
|
241 |
|
242 |
+
/**
|
243 |
+
* Get last imported.
|
244 |
+
*
|
245 |
+
* @return int
|
246 |
+
*/
|
247 |
+
public function get_last_imported() {
|
248 |
global $wpdb;
|
249 |
$rtmedia_activity_model = new RTMediaActivityModel();
|
250 |
+
$last_imported = $wpdb->get_results( $wpdb->prepare( " SELECT activity_id from {$rtmedia_activity_model->table_name} ORDER BY activity_id DESC limit %d ", 1 ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
251 |
+
|
252 |
if ( $last_imported && count( $last_imported ) > 0 && isset( $last_imported[0] ) && isset( $last_imported[0]->activity_id ) ) {
|
253 |
return $last_imported[0]->activity_id;
|
254 |
}
|
256 |
return 0;
|
257 |
}
|
258 |
|
259 |
+
/**
|
260 |
+
* Initialize activity upgrade.
|
261 |
+
*/
|
262 |
+
public function init() {
|
263 |
$prog = new rtProgress();
|
264 |
$pending = $this->get_pending_count();
|
265 |
$total = $this->get_total_count();
|
271 |
<h2><?php esc_html_e( 'rtMedia: Upgrade rtMedia activity', 'buddypress-media' ); ?></h2>
|
272 |
<?php
|
273 |
wp_nonce_field( 'rtmedia_media_activity_upgrade_nonce', 'rtmedia_media_activity_upgrade_nonce' );
|
274 |
+
// translators: %s: Estimated.
|
275 |
echo '<span class="pending">' . sprintf( esc_html__( '%s (estimated)', 'buddypress-media' ), esc_html( rtmedia_migrate_formatseconds( $total - $done ) ) ) . '</span><br />';
|
276 |
echo '<span class="finished">' . esc_html( $done ) . '</span>/<span class="total">' . esc_html( $total ) . '</span>';
|
277 |
echo '<img src="images/loading.gif" alt="syncing" id="rtMediaSyncing" style="display:none" />';
|
app/importers/RTMediaMediaSizeImporter.php
CHANGED
@@ -1,43 +1,68 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
|
4 |
-
*
|
5 |
-
*
|
6 |
-
* and open the template in the editor.
|
7 |
*/
|
8 |
|
9 |
/**
|
10 |
-
*
|
11 |
*
|
12 |
* @author ritz
|
13 |
*/
|
14 |
class RTMediaMediaSizeImporter {
|
15 |
|
16 |
-
|
|
|
|
|
|
|
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 |
-
add_action(
|
22 |
-
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
25 |
}
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
}
|
33 |
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
$admin_pages[] = 'rtmedia_page_rtmedia-media-size-import';
|
36 |
|
37 |
return $admin_pages;
|
38 |
}
|
39 |
|
40 |
-
|
|
|
|
|
|
|
41 |
if ( rtmedia_update_site_option( 'rtmedia_hide_media_size_import_notice', true ) ) {
|
42 |
echo '1';
|
43 |
} else {
|
@@ -46,7 +71,10 @@ class RTMediaMediaSizeImporter {
|
|
46 |
wp_die();
|
47 |
}
|
48 |
|
49 |
-
|
|
|
|
|
|
|
50 |
$pending = $this->get_pending_count();
|
51 |
if ( $pending < 0 ) {
|
52 |
$pending = 0;
|
@@ -68,7 +96,10 @@ class RTMediaMediaSizeImporter {
|
|
68 |
}
|
69 |
}
|
70 |
|
71 |
-
|
|
|
|
|
|
|
72 |
if ( current_user_can( 'manage_options' ) ) {
|
73 |
$this->create_notice( '<p><strong>rtMedia</strong>' . esc_html__( ': Database table structure for rtMedia has been updated. Please ', 'buddypress-media' ) . "<a href='" . esc_url( admin_url( 'admin.php?page=rtmedia-migration-media-size-import&force=true' ) ) . "'>" . esc_html__( 'Click Here', 'buddypress-media' ) . '</a>' . esc_html__( ' to import media sizes. ', 'buddypress-media' ) . "<a href='#' onclick='rtmedia_hide_media_size_import_notice()' style='float:right'>" . esc_html__( 'Hide', 'buddypress-media' ) . '</a> </p>' );
|
74 |
?>
|
@@ -86,26 +117,41 @@ class RTMediaMediaSizeImporter {
|
|
86 |
}
|
87 |
}
|
88 |
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
}
|
98 |
|
99 |
-
|
|
|
|
|
|
|
100 |
$prog = new rtProgress();
|
101 |
$pending = $this->get_pending_count();
|
102 |
$total = $this->get_total_count();
|
103 |
$done = $total - $pending;
|
104 |
?>
|
105 |
<div class="wrap">
|
106 |
-
<h2><?php esc_html_e( 'rtMedia: Import Media Size', 'buddypress-media' ) ?></h2>
|
107 |
<?php
|
108 |
wp_nonce_field( 'rtmedia_media_size_import_nonce', 'rtmedia_media_size_import_nonce' );
|
|
|
109 |
echo '<span class="pending">' . sprintf( esc_html__( '%s (estimated)', 'buddypress-media' ), esc_html( rtmedia_migrate_formatseconds( $total - $done ) ) ) . '</span><br />';
|
110 |
echo '<span class="finished">' . esc_html( $done ) . '</span>/<span class="total">' . esc_html( $total ) . '</span>';
|
111 |
echo '<img src="images/loading.gif" alt="syncing" id="rtMediaSyncing" style="display:none" />';
|
@@ -198,15 +244,24 @@ class RTMediaMediaSizeImporter {
|
|
198 |
<?php
|
199 |
}
|
200 |
|
201 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
202 |
global $wpdb;
|
203 |
$rtmedia_model = new RTMediaModel();
|
204 |
$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')";
|
|
|
205 |
if ( $media_id ) {
|
206 |
$media_id = intval( $media_id );
|
207 |
-
$query_pending = $wpdb->prepare( "SELECT COUNT(*) as pending from {$rtmedia_model->table_name} where file_size IS NULL AND media_type in ('photo','video','document','music','other') AND id > %d", $media_id ); //
|
208 |
}
|
209 |
-
|
|
|
210 |
if ( $pending_count && count( $pending_count ) > 0 ) {
|
211 |
return $pending_count[0]->pending;
|
212 |
}
|
@@ -214,11 +269,17 @@ class RTMediaMediaSizeImporter {
|
|
214 |
return 0;
|
215 |
}
|
216 |
|
217 |
-
|
|
|
|
|
|
|
|
|
|
|
218 |
global $wpdb;
|
219 |
$rtmedia_model = new RTMediaModel();
|
220 |
-
$query_total = "SELECT COUNT(*) as total from {$rtmedia_model->table_name} where media_type in ('photo','video','document','music','other') ";
|
221 |
-
$total_count = $wpdb->get_results( $query_total ); //
|
|
|
222 |
if ( $total_count && count( $total_count ) > 0 ) {
|
223 |
return $total_count[0]->total;
|
224 |
}
|
@@ -226,16 +287,22 @@ class RTMediaMediaSizeImporter {
|
|
226 |
return 0;
|
227 |
}
|
228 |
|
229 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
230 |
global $wpdb;
|
231 |
if ( check_ajax_referer( 'rtmedia_media_size_import_nonce', 'nonce' ) ) {
|
232 |
$rtmedia_model = new RTMediaModel();
|
233 |
-
$get_media_sql = $wpdb->prepare( "SELECT * from {$rtmedia_model->table_name} where file_size is NULL and media_type in ('photo','video','document','music','other') order by id limit %d", $limit ); //
|
234 |
-
$lastid
|
235 |
if ( ! empty( $lastid ) ) {
|
236 |
-
$get_media_sql = $wpdb->prepare( "SELECT * from {$rtmedia_model->table_name} where id > %d AND file_size is NULL and media_type in ('photo','video','document','music','other') order by id limit %d", $lastid, $limit ); //
|
237 |
}
|
238 |
-
$result = $wpdb->get_results( $get_media_sql ); //
|
239 |
if ( $result && count( $result ) > 0 ) {
|
240 |
$migrate = $this->migrate_single_media( $result[0] );
|
241 |
}
|
@@ -247,7 +314,14 @@ class RTMediaMediaSizeImporter {
|
|
247 |
|
248 |
}
|
249 |
|
250 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
251 |
global $wpdb;
|
252 |
$rtmedia_model = new RTMediaModel();
|
253 |
$attached_file = get_attached_file( $result->media_id );
|
@@ -255,40 +329,56 @@ class RTMediaMediaSizeImporter {
|
|
255 |
if ( file_exists( $attached_file ) ) {
|
256 |
$file_size = filesize( $attached_file );
|
257 |
} else {
|
258 |
-
error_log( 'rtMedia size importer: file not exist. Media ID: ' . esc_html( $result->id ) . ', File: ' . esc_html( $attached_file ) );
|
259 |
return false;
|
260 |
}
|
261 |
$post = get_post( $result->media_id );
|
262 |
$post_date = $post->post_date;
|
263 |
-
$rtmedia_model->update(
|
264 |
-
|
265 |
-
|
266 |
-
|
|
|
|
|
|
|
267 |
|
268 |
return $return;
|
269 |
}
|
270 |
|
271 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
272 |
$total = $this->get_total_count();
|
273 |
$pending = $this->get_pending_count( $media->id );
|
274 |
$done = $total - $pending;
|
|
|
275 |
if ( $pending < 0 ) {
|
276 |
$pending = 0;
|
277 |
$done = $total;
|
278 |
}
|
|
|
279 |
if ( $done > $total ) {
|
280 |
$done = $total;
|
281 |
}
|
|
|
282 |
rtmedia_update_site_option( 'rtmedia_media_size_import_pending_count', $pending );
|
283 |
$pending_time = rtmedia_migrate_formatseconds( $pending ) . ' (estimated)';
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
|
|
|
|
|
|
292 |
die();
|
293 |
}
|
294 |
}
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* Handles media size import
|
4 |
+
*
|
5 |
+
* @package rtMedia
|
|
|
6 |
*/
|
7 |
|
8 |
/**
|
9 |
+
* Class for Media size importer functions
|
10 |
*
|
11 |
* @author ritz
|
12 |
*/
|
13 |
class RTMediaMediaSizeImporter {
|
14 |
|
15 |
+
/**
|
16 |
+
* RTMediaMediaSizeImporter constructor.
|
17 |
+
*/
|
18 |
+
public function __construct() {
|
19 |
add_filter( 'rtmedia_filter_admin_pages_array', array( $this, 'rtmedia_add_admin_page_array' ), 11, 1 );
|
20 |
add_action( 'wp_ajax_rtmedia_media_size_import', array( $this, 'rtmedia_media_size_import' ) );
|
21 |
add_action( 'admin_init', array( $this, 'add_admin_notice' ) );
|
22 |
add_action( 'admin_menu', array( $this, 'menu' ), 10 );
|
23 |
+
add_action(
|
24 |
+
'wp_ajax_rtmedia_hide_media_size_import_notice',
|
25 |
+
array(
|
26 |
+
$this,
|
27 |
+
'rtmedia_hide_media_size_import_notice',
|
28 |
+
)
|
29 |
+
);
|
30 |
}
|
31 |
|
32 |
+
/**
|
33 |
+
* Register MMedia size import Menu.
|
34 |
+
*/
|
35 |
+
public function menu() {
|
36 |
+
add_submenu_page(
|
37 |
+
'rtmedia-setting',
|
38 |
+
esc_html__( 'Media Size Import', 'buddypress-media' ),
|
39 |
+
esc_html__( 'Media Size Import', 'buddypress-media' ),
|
40 |
+
'manage_options',
|
41 |
+
'rtmedia-migration-media-size-import',
|
42 |
+
array(
|
43 |
+
$this,
|
44 |
+
'init',
|
45 |
+
)
|
46 |
+
);
|
47 |
}
|
48 |
|
49 |
+
/**
|
50 |
+
* Add admin page array.
|
51 |
+
*
|
52 |
+
* @param array $admin_pages admin pages.
|
53 |
+
*
|
54 |
+
* @return array
|
55 |
+
*/
|
56 |
+
public function rtmedia_add_admin_page_array( $admin_pages ) {
|
57 |
$admin_pages[] = 'rtmedia_page_rtmedia-media-size-import';
|
58 |
|
59 |
return $admin_pages;
|
60 |
}
|
61 |
|
62 |
+
/**
|
63 |
+
* Hide media size import notice.
|
64 |
+
*/
|
65 |
+
public function rtmedia_hide_media_size_import_notice() {
|
66 |
if ( rtmedia_update_site_option( 'rtmedia_hide_media_size_import_notice', true ) ) {
|
67 |
echo '1';
|
68 |
} else {
|
71 |
wp_die();
|
72 |
}
|
73 |
|
74 |
+
/**
|
75 |
+
* Add admin notice.
|
76 |
+
*/
|
77 |
+
public function add_admin_notice() {
|
78 |
$pending = $this->get_pending_count();
|
79 |
if ( $pending < 0 ) {
|
80 |
$pending = 0;
|
96 |
}
|
97 |
}
|
98 |
|
99 |
+
/**
|
100 |
+
* Media size import notice.
|
101 |
+
*/
|
102 |
+
public function add_rtmedia_media_size_import_notice() {
|
103 |
if ( current_user_can( 'manage_options' ) ) {
|
104 |
$this->create_notice( '<p><strong>rtMedia</strong>' . esc_html__( ': Database table structure for rtMedia has been updated. Please ', 'buddypress-media' ) . "<a href='" . esc_url( admin_url( 'admin.php?page=rtmedia-migration-media-size-import&force=true' ) ) . "'>" . esc_html__( 'Click Here', 'buddypress-media' ) . '</a>' . esc_html__( ' to import media sizes. ', 'buddypress-media' ) . "<a href='#' onclick='rtmedia_hide_media_size_import_notice()' style='float:right'>" . esc_html__( 'Hide', 'buddypress-media' ) . '</a> </p>' );
|
105 |
?>
|
117 |
}
|
118 |
}
|
119 |
|
120 |
+
/**
|
121 |
+
* Create notice.
|
122 |
+
*
|
123 |
+
* @param string $message Message to show.
|
124 |
+
* @param string $type Type of message.
|
125 |
+
*/
|
126 |
+
public function create_notice( $message, $type = 'error' ) {
|
127 |
+
|
128 |
+
$allowed_html = array(
|
129 |
+
'p' => array(),
|
130 |
+
'a' => array(
|
131 |
+
'href' => array(),
|
132 |
+
'onclick' => array(),
|
133 |
+
'style' => array(),
|
134 |
+
),
|
135 |
+
'strong' => array(),
|
136 |
+
);
|
137 |
+
|
138 |
+
echo '<div class="' . esc_attr( $type ) . ' rtmedia-media-size-import-error">' . wp_kses( $message, $allowed_html ) . '</div>';
|
139 |
}
|
140 |
|
141 |
+
/**
|
142 |
+
* Initialize media size import.
|
143 |
+
*/
|
144 |
+
public function init() {
|
145 |
$prog = new rtProgress();
|
146 |
$pending = $this->get_pending_count();
|
147 |
$total = $this->get_total_count();
|
148 |
$done = $total - $pending;
|
149 |
?>
|
150 |
<div class="wrap">
|
151 |
+
<h2><?php esc_html_e( 'rtMedia: Import Media Size', 'buddypress-media' ); ?></h2>
|
152 |
<?php
|
153 |
wp_nonce_field( 'rtmedia_media_size_import_nonce', 'rtmedia_media_size_import_nonce' );
|
154 |
+
// translators: %s: Estimated.
|
155 |
echo '<span class="pending">' . sprintf( esc_html__( '%s (estimated)', 'buddypress-media' ), esc_html( rtmedia_migrate_formatseconds( $total - $done ) ) ) . '</span><br />';
|
156 |
echo '<span class="finished">' . esc_html( $done ) . '</span>/<span class="total">' . esc_html( $total ) . '</span>';
|
157 |
echo '<img src="images/loading.gif" alt="syncing" id="rtMediaSyncing" style="display:none" />';
|
244 |
<?php
|
245 |
}
|
246 |
|
247 |
+
/**
|
248 |
+
* Get pending import count.
|
249 |
+
*
|
250 |
+
* @param bool $media_id Media id.
|
251 |
+
*
|
252 |
+
* @return int
|
253 |
+
*/
|
254 |
+
public function get_pending_count( $media_id = false ) {
|
255 |
global $wpdb;
|
256 |
$rtmedia_model = new RTMediaModel();
|
257 |
$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')";
|
258 |
+
|
259 |
if ( $media_id ) {
|
260 |
$media_id = intval( $media_id );
|
261 |
+
$query_pending = $wpdb->prepare( "SELECT COUNT(*) as pending from {$rtmedia_model->table_name} where file_size IS NULL AND media_type in ('photo','video','document','music','other') AND id > %d", $media_id ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
262 |
}
|
263 |
+
|
264 |
+
$pending_count = $wpdb->get_results( $query_pending ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
265 |
if ( $pending_count && count( $pending_count ) > 0 ) {
|
266 |
return $pending_count[0]->pending;
|
267 |
}
|
269 |
return 0;
|
270 |
}
|
271 |
|
272 |
+
/**
|
273 |
+
* Get total count.
|
274 |
+
*
|
275 |
+
* @return int
|
276 |
+
*/
|
277 |
+
public function get_total_count() {
|
278 |
global $wpdb;
|
279 |
$rtmedia_model = new RTMediaModel();
|
280 |
+
$query_total = "SELECT COUNT(*) as total from {$rtmedia_model->table_name} where media_type in ('photo','video','document','music','other') ";
|
281 |
+
$total_count = $wpdb->get_results( $query_total ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
282 |
+
|
283 |
if ( $total_count && count( $total_count ) > 0 ) {
|
284 |
return $total_count[0]->total;
|
285 |
}
|
287 |
return 0;
|
288 |
}
|
289 |
|
290 |
+
/**
|
291 |
+
* Media size import.
|
292 |
+
*
|
293 |
+
* @param int $lastid Last id.
|
294 |
+
* @param int $limit Limit of rows.
|
295 |
+
*/
|
296 |
+
public function rtmedia_media_size_import( $lastid = 0, $limit = 1 ) {
|
297 |
global $wpdb;
|
298 |
if ( check_ajax_referer( 'rtmedia_media_size_import_nonce', 'nonce' ) ) {
|
299 |
$rtmedia_model = new RTMediaModel();
|
300 |
+
$get_media_sql = $wpdb->prepare( "SELECT * from {$rtmedia_model->table_name} where file_size is NULL and media_type in ('photo','video','document','music','other') order by id limit %d", $limit ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
301 |
+
$lastid = filter_input( INPUT_POST, 'last_id', FILTER_SANITIZE_NUMBER_INT );
|
302 |
if ( ! empty( $lastid ) ) {
|
303 |
+
$get_media_sql = $wpdb->prepare( "SELECT * from {$rtmedia_model->table_name} where id > %d AND file_size is NULL and media_type in ('photo','video','document','music','other') order by id limit %d", $lastid, $limit ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
304 |
}
|
305 |
+
$result = $wpdb->get_results( $get_media_sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
306 |
if ( $result && count( $result ) > 0 ) {
|
307 |
$migrate = $this->migrate_single_media( $result[0] );
|
308 |
}
|
314 |
|
315 |
}
|
316 |
|
317 |
+
/**
|
318 |
+
* Migrate single media.
|
319 |
+
*
|
320 |
+
* @param object $result Object of media.
|
321 |
+
*
|
322 |
+
* @return bool
|
323 |
+
*/
|
324 |
+
public function migrate_single_media( $result ) {
|
325 |
global $wpdb;
|
326 |
$rtmedia_model = new RTMediaModel();
|
327 |
$attached_file = get_attached_file( $result->media_id );
|
329 |
if ( file_exists( $attached_file ) ) {
|
330 |
$file_size = filesize( $attached_file );
|
331 |
} else {
|
332 |
+
error_log( 'rtMedia size importer: file not exist. Media ID: ' . esc_html( $result->id ) . ', File: ' . esc_html( $attached_file ) ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
|
333 |
return false;
|
334 |
}
|
335 |
$post = get_post( $result->media_id );
|
336 |
$post_date = $post->post_date;
|
337 |
+
$rtmedia_model->update(
|
338 |
+
array(
|
339 |
+
'upload_date' => $post_date,
|
340 |
+
'file_size' => $file_size,
|
341 |
+
),
|
342 |
+
array( 'id' => $result->id )
|
343 |
+
);
|
344 |
|
345 |
return $return;
|
346 |
}
|
347 |
|
348 |
+
/**
|
349 |
+
* Return migration data.
|
350 |
+
*
|
351 |
+
* @param bool|object $media Media object.
|
352 |
+
* @param bool $migrate Migrate done or not.
|
353 |
+
*/
|
354 |
+
public function return_migration( $media = false, $migrate = true ) {
|
355 |
+
|
356 |
$total = $this->get_total_count();
|
357 |
$pending = $this->get_pending_count( $media->id );
|
358 |
$done = $total - $pending;
|
359 |
+
|
360 |
if ( $pending < 0 ) {
|
361 |
$pending = 0;
|
362 |
$done = $total;
|
363 |
}
|
364 |
+
|
365 |
if ( $done > $total ) {
|
366 |
$done = $total;
|
367 |
}
|
368 |
+
|
369 |
rtmedia_update_site_option( 'rtmedia_media_size_import_pending_count', $pending );
|
370 |
$pending_time = rtmedia_migrate_formatseconds( $pending ) . ' (estimated)';
|
371 |
+
|
372 |
+
echo wp_json_encode(
|
373 |
+
array(
|
374 |
+
'status' => true,
|
375 |
+
'done' => $done,
|
376 |
+
'total' => $total,
|
377 |
+
'pending' => $pending_time,
|
378 |
+
'media_id' => $media->id,
|
379 |
+
'imported' => $migrate,
|
380 |
+
)
|
381 |
+
);
|
382 |
die();
|
383 |
}
|
384 |
}
|
app/importers/RTMediaMigration.php
CHANGED
@@ -1,15 +1,28 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
/**
|
4 |
-
*
|
5 |
*
|
6 |
* @author faishal
|
7 |
*/
|
8 |
class RTMediaMigration {
|
9 |
|
|
|
|
|
|
|
|
|
|
|
10 |
public $bmp_table = '';
|
11 |
|
12 |
-
|
|
|
|
|
|
|
13 |
global $wpdb;
|
14 |
$this->bmp_table = $wpdb->base_prefix . 'rt_rtm_media';
|
15 |
|
@@ -18,6 +31,7 @@ class RTMediaMigration {
|
|
18 |
|
19 |
$page = filter_input( INPUT_GET, 'page', FILTER_SANITIZE_STRING );
|
20 |
$hide = filter_input( INPUT_GET, 'hide', FILTER_SANITIZE_STRING );
|
|
|
21 |
if ( isset( $page ) && 'rtmedia-migration' === $page && isset( $hide ) && 'true' === $hide ) {
|
22 |
$this->hide_migration_notice();
|
23 |
$http_referer = rtm_get_server_var( 'HTTP_REFERER', 'FILTER_SANITIZE_URL' );
|
@@ -50,30 +64,55 @@ class RTMediaMigration {
|
|
50 |
}
|
51 |
}
|
52 |
|
53 |
-
|
|
|
|
|
|
|
54 |
rtmedia_update_site_option( 'rt_migration_hide_notice', true );
|
55 |
}
|
56 |
|
57 |
-
|
|
|
|
|
|
|
58 |
if ( '' === rtmedia_get_site_option( 'rt_image_size_migration_fix', '' ) ) {
|
59 |
global $wpdb;
|
60 |
-
|
61 |
-
$wpdb->get_row( $
|
|
|
62 |
update_option( 'rt_image_size_migration_fix', 'fix' );
|
63 |
}
|
64 |
}
|
65 |
|
66 |
-
|
|
|
|
|
|
|
67 |
if ( current_user_can( 'manage_options' ) ) {
|
68 |
$this->create_notice( '<p><strong>' . esc_html__( 'rtMedia', 'buddypress-media' ) . '</strong>: ' . esc_html__( 'Please Migrate your Database', 'buddypress-media' ) . " <a href='" . esc_url( admin_url( 'admin.php?page=rtmedia-migration&force=true' ) ) . "'>" . esc_html__( 'Click Here', 'buddypress-media' ) . "</a>. <a href='" . esc_url( admin_url( 'admin.php?page=rtmedia-migration&hide=true' ) ) . "' style='float:right'>" . esc_html__( 'Hide', 'buddypress-media' ) . '</a> </p>' );
|
69 |
}
|
70 |
}
|
71 |
|
72 |
-
|
73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
}
|
75 |
|
76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
global $wpdb;
|
78 |
|
79 |
if ( 1 === intval( $wpdb->query( $wpdb->prepare( 'SHOW TABLES LIKE %s', $table ) ) ) ) {
|
@@ -83,14 +122,29 @@ class RTMediaMigration {
|
|
83 |
return false;
|
84 |
}
|
85 |
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
}
|
92 |
|
93 |
-
|
|
|
|
|
|
|
|
|
|
|
94 |
global $wpdb;
|
95 |
if ( function_exists( 'bp_core_get_table_prefix' ) ) {
|
96 |
$bp_prefix = bp_core_get_table_prefix();
|
@@ -99,14 +153,15 @@ class RTMediaMigration {
|
|
99 |
}
|
100 |
$sql_album_usercount = "select count(*) FROM $wpdb->usermeta where meta_key ='bp-media-default-album' ";
|
101 |
|
102 |
-
$_SESSION['migration_user_album'] = $wpdb->get_var( $sql_album_usercount ); //
|
103 |
$count = intval( $_SESSION['migration_user_album'] );
|
104 |
|
105 |
if ( $this->table_exists( $bp_prefix . 'bp_groups_groupmeta' ) ) {
|
106 |
-
$sql_album_groupcount = $wpdb->prepare( "select count(*) FROM {$bp_prefix}bp_groups_groupmeta where meta_key
|
107 |
-
$_SESSION['migration_group_album'] = $wpdb->get_var( $sql_album_groupcount ); //
|
108 |
-
$count
|
109 |
}
|
|
|
110 |
if ( $this->table_exists( $bp_prefix . 'bp_activity' ) ) {
|
111 |
$sql_bpm_comment_count = "SELECT
|
112 |
count(id)
|
@@ -126,8 +181,8 @@ class RTMediaMigration {
|
|
126 |
and is_spam <>1 and
|
127 |
not p.meta_value is NULL";
|
128 |
|
129 |
-
$_SESSION['migration_activity'] = $wpdb->get_var( $sql_bpm_comment_count ); //
|
130 |
-
$count
|
131 |
}
|
132 |
|
133 |
$sql = "select count(*)
|
@@ -145,13 +200,18 @@ class RTMediaMigration {
|
|
145 |
a.post_id > 0 and (NOT p.ID IS NULL)
|
146 |
and a.meta_key = 'bp-media-key'";
|
147 |
|
148 |
-
$_SESSION['migration_media'] = $wpdb->get_var( $sql ); //
|
149 |
-
$count
|
150 |
|
151 |
return $count;
|
152 |
}
|
153 |
|
154 |
-
|
|
|
|
|
|
|
|
|
|
|
155 |
$album = rtmedia_get_site_option( 'rtmedia-global-albums' );
|
156 |
$album_id = $album[0];
|
157 |
|
@@ -163,8 +223,8 @@ class RTMediaMigration {
|
|
163 |
where
|
164 |
a.meta_key = 'bp-media-key' and (NOT p.ID IS NULL) and a.post_id not in (select media_id
|
165 |
from {$this->bmp_table} where blog_id = %d and media_id <> %d ) order by a.post_ID";
|
166 |
-
$sql = $wpdb->prepare( $sql, get_current_blog_id(), $album_id ); //
|
167 |
-
$row = $wpdb->get_row( $sql ); //
|
168 |
if ( $row ) {
|
169 |
return $row->post_ID;
|
170 |
} else {
|
@@ -172,7 +232,14 @@ class RTMediaMigration {
|
|
172 |
}
|
173 |
}
|
174 |
|
175 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
176 |
global $wpdb;
|
177 |
$sql = "select count(*)
|
178 |
from {$this->bmp_table} where blog_id = %d and media_id in (select a.post_id
|
@@ -190,13 +257,16 @@ class RTMediaMigration {
|
|
190 |
a.post_id > 0 and (NOT p.ID IS NULL)
|
191 |
and a.meta_key = 'bp-media-key')";
|
192 |
|
193 |
-
$media_count = $wpdb->get_var( $wpdb->prepare( $sql, get_current_blog_id() ) ); //
|
|
|
194 |
if ( $flag ) {
|
195 |
return $media_count - 1;
|
196 |
}
|
|
|
197 |
$state = intval( rtmedia_get_site_option( 'rtmedia-migration', '0' ) );
|
198 |
-
|
199 |
-
|
|
|
200 |
$album_count += ( isset( $_SESSION['migration_group_album'] ) ) ? intval( $_SESSION['migration_group_album'] ) : 0;
|
201 |
} else {
|
202 |
if ( $state > 0 ) {
|
@@ -210,30 +280,35 @@ class RTMediaMigration {
|
|
210 |
$pending_count .= " or ID in (select meta_value FROM {$bp_prefix}bp_groups_groupmeta where meta_key ='bp_media_default_album')";
|
211 |
}
|
212 |
$pending_count .= ')';
|
213 |
-
$pending_count
|
214 |
|
215 |
-
$album_count
|
216 |
$album_count += ( isset( $_SESSION['migration_group_album'] ) ) ? intval( $_SESSION['migration_group_album'] ) : 0;
|
217 |
-
$album_count
|
218 |
} else {
|
219 |
$album_count = 0;
|
220 |
}
|
221 |
}
|
222 |
-
|
|
|
223 |
$comment_sql = $_SESSION['migration_activity'];
|
224 |
} else {
|
225 |
-
//
|
226 |
-
$comment_sql = $wpdb->get_var(
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
|
|
231 |
}
|
232 |
|
233 |
return $media_count + $album_count + $comment_sql;
|
234 |
}
|
235 |
|
236 |
-
|
|
|
|
|
|
|
237 |
$total = $this->get_total_count();
|
238 |
$done = $this->get_done_count();
|
239 |
$pending = $total - $done;
|
@@ -241,22 +316,36 @@ class RTMediaMigration {
|
|
241 |
$pending = 0;
|
242 |
$done = $total;
|
243 |
}
|
|
|
244 |
if ( $done > $total ) {
|
245 |
$done = $total;
|
246 |
}
|
|
|
247 |
if ( $done === $total ) {
|
248 |
global $wp_rewrite;
|
249 |
-
//Call flush_rules() as a method of the $wp_rewrite object
|
250 |
$wp_rewrite->flush_rules( true );
|
251 |
}
|
252 |
rtmedia_update_site_option( 'rtMigration-pending-count', $pending );
|
253 |
$pending_time = $this->format_seconds( $pending );
|
254 |
|
255 |
-
echo wp_json_encode(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
256 |
die();
|
257 |
}
|
258 |
|
259 |
-
|
|
|
|
|
|
|
|
|
|
|
260 |
$album = rtmedia_get_site_option( 'rtmedia-global-albums' );
|
261 |
$stage = intval( rtmedia_get_site_option( 'rtmedia-migration', '0' ) );
|
262 |
|
@@ -266,7 +355,7 @@ class RTMediaMigration {
|
|
266 |
|
267 |
global $wpdb;
|
268 |
|
269 |
-
$album_id = $wpdb->get_var( $wpdb->prepare( "select media_id from $this->bmp_table where id = %d", $album_rt_id ) ); //
|
270 |
|
271 |
if ( function_exists( 'bp_core_get_table_prefix' ) ) {
|
272 |
$bp_prefix = bp_core_get_table_prefix();
|
@@ -275,63 +364,80 @@ class RTMediaMigration {
|
|
275 |
}
|
276 |
|
277 |
if ( $stage < 1 ) {
|
|
|
278 |
global $wpdb;
|
|
|
279 |
if ( function_exists( 'bp_core_get_table_prefix' ) ) {
|
280 |
$bp_prefix = bp_core_get_table_prefix();
|
281 |
} else {
|
282 |
$bp_prefix = '';
|
283 |
}
|
284 |
-
|
285 |
-
$wpdb->
|
286 |
-
$
|
287 |
-
$wpdb->
|
|
|
288 |
|
289 |
$sql_group = "update $wpdb->posts set post_parent='{$album_id}' where post_parent in (select meta_value FROM $wpdb->usermeta where meta_key ='bp-media-default-album') ";
|
|
|
290 |
if ( $this->table_exists( $bp_prefix . 'bp_groups_groupmeta' ) ) {
|
291 |
$sql_group .= " or post_parent in (select meta_value FROM {$bp_prefix}bp_groups_groupmeta where meta_key ='bp_media_default_album')";
|
292 |
}
|
293 |
-
|
|
|
294 |
$stage = 1;
|
295 |
rtmedia_update_site_option( 'rtmedia-migration', $stage );
|
296 |
$this->return_migration();
|
297 |
}
|
|
|
298 |
if ( $stage < 2 ) {
|
299 |
-
|
300 |
-
$results = $wpdb->get_results( $
|
301 |
$delete_ids = '';
|
302 |
$sep = '';
|
|
|
303 |
foreach ( $results as $result ) {
|
304 |
$this->search_and_replace( $result->guid, trailingslashit( get_rtmedia_user_link( $result->post_author ) ) . RTMEDIA_MEDIA_SLUG . '/' . $album_rt_id );
|
305 |
$delete_ids .= $sep . $result->ID;
|
306 |
-
$sep
|
307 |
}
|
|
|
308 |
if ( '' !== $delete_ids ) {
|
309 |
-
|
310 |
-
$wpdb->query( "delete from $wpdb->posts where ID in ({$delete_ids})" ); //
|
311 |
}
|
|
|
312 |
if ( count( $results ) < 10 ) {
|
313 |
$stage = 2;
|
314 |
}
|
|
|
315 |
rtmedia_update_site_option( 'rtmedia-migration', $stage );
|
316 |
$this->return_migration();
|
317 |
}
|
|
|
318 |
if ( $stage < 3 ) {
|
|
|
319 |
if ( $this->table_exists( $bp_prefix . 'bp_groups_groupmeta' ) ) {
|
|
|
320 |
$sql_delete = "select * from $wpdb->posts where post_type='bp_media_album' and ID in (select meta_value FROM {$bp_prefix}bp_groups_groupmeta where meta_key ='bp_media_default_album') limit 10";
|
321 |
-
$results = $wpdb->get_results( $sql_delete ); //
|
322 |
$delete_ids = '';
|
323 |
$sep = '';
|
|
|
324 |
if ( $results ) {
|
|
|
325 |
foreach ( $results as $result ) {
|
326 |
$group_id = abs( intval( get_post_meta( $result->ID, 'bp-media-key', true ) ) );
|
327 |
$this->search_and_replace( trailingslashit( get_rtmedia_group_link( $group_id ) ) . 'albums/' . $result->ID, trailingslashit( get_rtmedia_group_link( $group_id ) ) . RTMEDIA_MEDIA_SLUG . '/' . $album_rt_id );
|
328 |
$delete_ids .= $sep . $result->ID;
|
329 |
-
$sep
|
330 |
}
|
|
|
331 |
if ( '' !== $delete_ids ) {
|
332 |
-
|
333 |
-
$wpdb->query( "delete from $wpdb->posts where ID in ({$delete_ids})" ); //
|
334 |
}
|
|
|
335 |
if ( count( $results ) < 10 ) {
|
336 |
$stage = 3;
|
337 |
}
|
@@ -348,22 +454,29 @@ class RTMediaMigration {
|
|
348 |
}
|
349 |
|
350 |
$sql = "update $wpdb->posts set post_type='{$album_post_type}' where post_type='bp_media_album'";
|
351 |
-
if ( false !== $wpdb->query( $sql ) ) { // @codingStandardsIgnoreLine
|
352 |
-
rtmedia_update_site_option( 'rtmedia-migration', '5' );
|
353 |
|
|
|
|
|
|
|
354 |
return true;
|
|
|
355 |
}
|
356 |
|
357 |
return false;
|
358 |
}
|
359 |
|
360 |
-
|
|
|
|
|
|
|
361 |
if ( ! $this->table_exists( $this->bmp_table ) ) {
|
362 |
$obj = new RTDBUpdate( false, RTMEDIA_PATH . 'index.php', RTMEDIA_PATH . 'app/schema/', true );
|
363 |
$obj->install_db_version = '0';
|
364 |
$obj->do_upgrade( true );
|
365 |
}
|
|
|
366 |
global $rtmedia_error;
|
|
|
367 |
if ( isset( $rtmedia_error ) && true === $rtmedia_error ) {
|
368 |
?>
|
369 |
<div class="error"><p><?php echo esc_html__( 'Please Resolve create database error before migration.', 'buddypress-media' ); ?></p></div>
|
@@ -380,7 +493,7 @@ class RTMediaMigration {
|
|
380 |
<div class="error">
|
381 |
<p>
|
382 |
<?php
|
383 |
-
/* translators: %
|
384 |
printf( esc_html__( 'Please Backup your %1$sDATABASE%2$s and %1$sUPLOAD%2$s folder before Migration.', 'buddypress-media' ), '<strong>', '</strong>' );
|
385 |
?>
|
386 |
</p>
|
@@ -394,18 +507,30 @@ class RTMediaMigration {
|
|
394 |
<h2><?php esc_html_e( 'rtMedia Migration', 'buddypress-media' ); ?></h2>
|
395 |
|
396 |
<h3><?php esc_html_e( 'It will migrate following things', 'buddypress-media' ); ?> </h3>
|
397 |
-
<?php
|
398 |
-
|
399 |
-
|
|
|
|
|
|
|
|
|
400 |
esc_html_e( 'Groups Albums : ', 'buddypress-media' );
|
401 |
-
echo esc_html( $_SESSION['migration_group_album'] );
|
402 |
-
|
|
|
|
|
|
|
403 |
esc_html_e( 'Media : ', 'buddypress-media' );
|
404 |
-
echo esc_html( $_SESSION['migration_media'] );
|
405 |
?>
|
406 |
-
|
|
|
|
|
|
|
407 |
esc_html_e( 'Comments : ', 'buddypress-media' );
|
408 |
-
echo esc_html( $_SESSION['migration_activity'] );
|
|
|
|
|
409 |
<?php } ?>
|
410 |
<hr/>
|
411 |
|
@@ -485,15 +610,20 @@ class RTMediaMigration {
|
|
485 |
</script>
|
486 |
<hr/>
|
487 |
<?php if ( ! ( isset( $rtmedia_error ) && true === $rtmedia_error ) ) { ?>
|
488 |
-
<input type="button" id="submit" value="<?php esc_attr_e( 'Start', 'buddypress-media' ); ?>"
|
489 |
-
class="button button-primary"/>
|
490 |
<?php } ?>
|
491 |
|
492 |
</div>
|
493 |
<?php
|
494 |
}
|
495 |
|
496 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
497 |
|
498 |
if ( ! isset( $_SESSION['migration_media'] ) ) {
|
499 |
$this->get_total_count();
|
@@ -542,7 +672,7 @@ class RTMediaMigration {
|
|
542 |
order by a.post_id
|
543 |
limit %d";
|
544 |
|
545 |
-
$results = $wpdb->get_results( $wpdb->prepare( $sql, $lastid, $limit ) ); //
|
546 |
|
547 |
if ( function_exists( 'bp_core_get_table_prefix' ) ) {
|
548 |
$bp_prefix = bp_core_get_table_prefix();
|
@@ -557,14 +687,17 @@ class RTMediaMigration {
|
|
557 |
}
|
558 |
} else {
|
559 |
global $wp_rewrite;
|
560 |
-
//Call flush_rules() as a method of the $wp_rewrite object
|
561 |
$wp_rewrite->flush_rules( true );
|
562 |
}
|
563 |
$this->return_migration();
|
564 |
}
|
565 |
|
566 |
-
|
567 |
-
|
|
|
|
|
|
|
568 |
'bp-media-encoding-api-key' => 'rtmedia-encoding-api-key',
|
569 |
'bp-media-encoding-usage-limit-mail' => 'rtmedia-encoding-usage-limit-mail',
|
570 |
'bp-media-encoding-usage' => 'rtmedia-encoding-usage',
|
@@ -573,26 +706,42 @@ class RTMediaMigration {
|
|
573 |
'bp_media_ffmpeg_options' => 'rtmedia-ffmpeg-options',
|
574 |
'bp_media_kaltura_options' => 'rtmedia-kaltura-options',
|
575 |
);
|
576 |
-
|
577 |
-
|
|
|
|
|
|
|
578 |
rtmedia_update_site_option( $ma, $value );
|
579 |
}
|
580 |
}
|
581 |
}
|
582 |
|
583 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
584 |
$blog_id = get_current_blog_id();
|
585 |
$old = $result;
|
|
|
586 |
if ( function_exists( 'bp_core_get_table_prefix' ) ) {
|
587 |
$bp_prefix = bp_core_get_table_prefix();
|
588 |
} else {
|
589 |
$bp_prefix = '';
|
590 |
}
|
|
|
591 |
global $wpdb;
|
592 |
|
593 |
if ( false !== $album && ! ( is_object( $result ) ) ) {
|
594 |
-
|
595 |
-
|
|
|
|
|
596 |
$sql = "select
|
597 |
a.post_id as 'post_id',
|
598 |
a.meta_value as 'privacy',
|
@@ -616,7 +765,7 @@ class RTMediaMigration {
|
|
616 |
where
|
617 |
a.post_id = %d and (NOT p.ID IS NULL)
|
618 |
and a.meta_key = 'bp_media_privacy'";
|
619 |
-
$result = $wpdb->get_row( $wpdb->prepare( $sql, $result ) ); //
|
620 |
} else {
|
621 |
return $id;
|
622 |
}
|
@@ -635,7 +784,7 @@ class RTMediaMigration {
|
|
635 |
}
|
636 |
|
637 |
$old_type = '';
|
638 |
-
if ( 'attachment'
|
639 |
$media_type = 'album';
|
640 |
} else {
|
641 |
$mime_type = strtolower( $result->post_mime_type );
|
@@ -658,15 +807,16 @@ class RTMediaMigration {
|
|
658 |
}
|
659 |
}
|
660 |
|
661 |
-
$activity_data = $wpdb->get_row( $wpdb->prepare( "select * from {$bp_prefix}bp_activity where id= %d", $result->activity_id ) ); //
|
662 |
-
if ( 'album'
|
663 |
$this->importmedia( $media_id, $prefix );
|
664 |
}
|
665 |
|
666 |
if ( $this->table_exists( $bp_prefix . 'bp_activity' ) && class_exists( 'BP_Activity_Activity' ) ) {
|
667 |
-
$bp_activity
|
668 |
-
//
|
669 |
-
$activity_sql = $wpdb->prepare(
|
|
|
670 |
*
|
671 |
FROM
|
672 |
{$bp_prefix}bp_activity
|
@@ -679,9 +829,11 @@ class RTMediaMigration {
|
|
679 |
$wpdb->posts p ON (a.post_id = p.ID)
|
680 |
where
|
681 |
(NOT p.ID IS NULL) and p.ID = %d
|
682 |
-
and a.meta_key = 'bp_media_child_activity')",
|
|
|
|
|
683 |
$all_activity = $wpdb->get_results( $activity_sql );
|
684 |
-
//
|
685 |
remove_all_actions( 'wp_insert_comment' );
|
686 |
foreach ( $all_activity as $activity ) {
|
687 |
$comments = $bp_activity->get_activity_comments( $activity->id, $activity->mptt_left, $activity->mptt_right );
|
@@ -705,22 +857,27 @@ class RTMediaMigration {
|
|
705 |
$likes = 0;
|
706 |
}
|
707 |
|
708 |
-
$wpdb->insert(
|
709 |
-
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
-
|
714 |
-
|
715 |
-
|
716 |
-
|
717 |
-
|
718 |
-
|
719 |
-
|
720 |
-
|
|
|
|
|
|
|
|
|
|
|
721 |
$last_id = $wpdb->insert_id;
|
722 |
|
723 |
-
if ( 'album'
|
724 |
if ( function_exists( 'bp_core_get_table_prefix' ) ) {
|
725 |
$bp_prefix = bp_core_get_table_prefix();
|
726 |
} else {
|
@@ -740,13 +897,17 @@ class RTMediaMigration {
|
|
740 |
$activity_data->content = str_replace( $last_baseurl, $replace_img, $activity_data->content );
|
741 |
}
|
742 |
global $wpdb;
|
743 |
-
$wpdb->update(
|
744 |
-
'
|
745 |
-
|
746 |
-
|
747 |
-
|
|
|
|
|
|
|
|
|
748 |
} else {
|
749 |
-
if ( 'group'
|
750 |
$activity_data->old_primary_link = $activity_data->primary_link;
|
751 |
$parent_link = get_rtmedia_group_link( abs( intval( $result->context_id ) ) );
|
752 |
$parent_link = trailingslashit( $parent_link );
|
@@ -760,8 +921,8 @@ class RTMediaMigration {
|
|
760 |
$this->search_and_replace( $activity_data->old_primary_link, $activity_data->primary_link );
|
761 |
}
|
762 |
}
|
763 |
-
if ( ''
|
764 |
-
if ( 'group'
|
765 |
$parent_link = get_rtmedia_group_link( abs( intval( $result->context_id ) ) );
|
766 |
$parent_link = trailingslashit( $parent_link );
|
767 |
$this->search_and_replace( trailingslashit( $parent_link . $old_type . '/' . $media_id ), trailingslashit( $parent_link . RTMEDIA_MEDIA_SLUG . '/' . $last_id ) );
|
@@ -776,10 +937,12 @@ class RTMediaMigration {
|
|
776 |
}
|
777 |
|
778 |
/**
|
779 |
-
*
|
780 |
-
*
|
|
|
|
|
781 |
*/
|
782 |
-
function importmedia( $id, $prefix ) {
|
783 |
|
784 |
$delete = false;
|
785 |
$attached_file = get_attached_file( $id );
|
@@ -790,17 +953,19 @@ class RTMediaMigration {
|
|
790 |
$siteurl = get_option( 'siteurl' );
|
791 |
$upload_path = trim( get_option( 'upload_path' ) );
|
792 |
|
793 |
-
if ( empty( $upload_path ) || 'wp-content/uploads'
|
794 |
$dir = WP_CONTENT_DIR . '/uploads';
|
795 |
} elseif ( 0 !== strpos( $upload_path, ABSPATH ) ) {
|
796 |
-
// $dir is absolute, $upload_path is (maybe) relative to ABSPATH
|
797 |
$dir = path_join( ABSPATH, $upload_path );
|
798 |
} else {
|
799 |
$dir = $upload_path;
|
800 |
}
|
801 |
|
802 |
-
|
803 |
-
|
|
|
|
|
804 |
$url = WP_CONTENT_URL . '/uploads';
|
805 |
} else {
|
806 |
$url = trailingslashit( $siteurl ) . $upload_path;
|
@@ -814,7 +979,7 @@ class RTMediaMigration {
|
|
814 |
$url = trailingslashit( $siteurl ) . UPLOADS;
|
815 |
}
|
816 |
|
817 |
-
// If multisite (and if not the main site in a post-MU network)
|
818 |
if ( is_multisite() && ! ( is_main_site() && defined( 'MULTISITE' ) ) ) {
|
819 |
|
820 |
if ( ! rtmedia_get_site_option( 'ms_files_rewriting' ) ) {
|
@@ -822,8 +987,7 @@ class RTMediaMigration {
|
|
822 |
// Append sites/%d if we're not on the main site (for post-MU networks). (The extra directory
|
823 |
// prevents a four-digit ID from conflicting with a year-based directory for the main site.
|
824 |
// But if a MU-era network has disabled ms-files rewriting manually, they don't need the extra
|
825 |
-
// directory, as they never had wp-content/uploads for the main site.)
|
826 |
-
|
827 |
if ( defined( 'MULTISITE' ) ) {
|
828 |
$ms_dir = '/sites/' . get_current_blog_id();
|
829 |
} else {
|
@@ -835,16 +999,15 @@ class RTMediaMigration {
|
|
835 |
} elseif ( defined( 'UPLOADS' ) && ! ms_is_switched() ) {
|
836 |
// Handle the old-form ms-files.php rewriting if the network still has that enabled.
|
837 |
// When ms-files rewriting is enabled, then we only listen to UPLOADS when:
|
838 |
-
//
|
839 |
-
//
|
840 |
-
//
|
841 |
-
//
|
842 |
//
|
843 |
// Rather than UPLOADS, we actually use BLOGUPLOADDIR if it is set, as it is absolute.
|
844 |
// (And it will be set, see ms_upload_constants().) Otherwise, UPLOADS can be used, as
|
845 |
// as it is relative to ABSPATH. For the final piece: when UPLOADS is used with ms-files
|
846 |
-
// rewriting in multisite, the resulting URL is /files. (#WP22702 for background.)
|
847 |
-
|
848 |
if ( defined( 'BLOGUPLOADDIR' ) ) {
|
849 |
$dir = untrailingslashit( BLOGUPLOADDIR );
|
850 |
} else {
|
@@ -1009,18 +1172,33 @@ class RTMediaMigration {
|
|
1009 |
}
|
1010 |
}
|
1011 |
|
1012 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
1013 |
global $wpdb;
|
|
|
1014 |
if ( function_exists( 'bp_core_get_table_prefix' ) ) {
|
1015 |
$bp_prefix = bp_core_get_table_prefix();
|
1016 |
} else {
|
1017 |
$bp_prefix = $wpdb->prefix;
|
1018 |
}
|
1019 |
-
|
1020 |
-
$wpdb->
|
|
|
1021 |
}
|
1022 |
|
1023 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1024 |
|
1025 |
$minute_in_seconds = 60;
|
1026 |
$hour_in_seconds = $minute_in_seconds * 60;
|
@@ -1039,7 +1217,7 @@ class RTMediaMigration {
|
|
1039 |
$time_components = array();
|
1040 |
|
1041 |
if ( $days > 0 ) {
|
1042 |
-
$time_components[] = $days .esc_html__( ' day', 'buddypress-media' ) . ( $days > 1 ? 's' : '' );
|
1043 |
}
|
1044 |
|
1045 |
if ( $hours > 0 ) {
|
@@ -1063,7 +1241,15 @@ class RTMediaMigration {
|
|
1063 |
return $formatted_time_remaining;
|
1064 |
}
|
1065 |
|
1066 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1067 |
foreach ( $data as $cmnt ) {
|
1068 |
$comment_id = 0;
|
1069 |
if ( ! key_exists( strval( $cmnt->id ), $exclude ) ) {
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* Handles Media migration.
|
4 |
+
*
|
5 |
+
* @package rtMedia
|
6 |
+
*/
|
7 |
|
8 |
/**
|
9 |
+
* Class for rtMedia Media migration functions
|
10 |
*
|
11 |
* @author faishal
|
12 |
*/
|
13 |
class RTMediaMigration {
|
14 |
|
15 |
+
/**
|
16 |
+
* BMP Table.
|
17 |
+
*
|
18 |
+
* @var string $bmp_table
|
19 |
+
*/
|
20 |
public $bmp_table = '';
|
21 |
|
22 |
+
/**
|
23 |
+
* RTMediaMigration constructor.
|
24 |
+
*/
|
25 |
+
public function __construct() {
|
26 |
global $wpdb;
|
27 |
$this->bmp_table = $wpdb->base_prefix . 'rt_rtm_media';
|
28 |
|
31 |
|
32 |
$page = filter_input( INPUT_GET, 'page', FILTER_SANITIZE_STRING );
|
33 |
$hide = filter_input( INPUT_GET, 'hide', FILTER_SANITIZE_STRING );
|
34 |
+
|
35 |
if ( isset( $page ) && 'rtmedia-migration' === $page && isset( $hide ) && 'true' === $hide ) {
|
36 |
$this->hide_migration_notice();
|
37 |
$http_referer = rtm_get_server_var( 'HTTP_REFERER', 'FILTER_SANITIZE_URL' );
|
64 |
}
|
65 |
}
|
66 |
|
67 |
+
/**
|
68 |
+
* Hide migration notice.
|
69 |
+
*/
|
70 |
+
public function hide_migration_notice() {
|
71 |
rtmedia_update_site_option( 'rt_migration_hide_notice', true );
|
72 |
}
|
73 |
|
74 |
+
/**
|
75 |
+
* Migrate image size fix.
|
76 |
+
*/
|
77 |
+
public function migrate_image_size_fix() {
|
78 |
if ( '' === rtmedia_get_site_option( 'rt_image_size_migration_fix', '' ) ) {
|
79 |
global $wpdb;
|
80 |
+
|
81 |
+
$wpdb->get_row( $wpdb->prepare( "update $wpdb->postmeta set meta_value=replace(meta_value ,%s,%s) where meta_key = '_wp_attachment_metadata';", 'bp_media', 'rt_media' ) );
|
82 |
+
|
83 |
update_option( 'rt_image_size_migration_fix', 'fix' );
|
84 |
}
|
85 |
}
|
86 |
|
87 |
+
/**
|
88 |
+
* Add migration notice.
|
89 |
+
*/
|
90 |
+
public function add_migration_notice() {
|
91 |
if ( current_user_can( 'manage_options' ) ) {
|
92 |
$this->create_notice( '<p><strong>' . esc_html__( 'rtMedia', 'buddypress-media' ) . '</strong>: ' . esc_html__( 'Please Migrate your Database', 'buddypress-media' ) . " <a href='" . esc_url( admin_url( 'admin.php?page=rtmedia-migration&force=true' ) ) . "'>" . esc_html__( 'Click Here', 'buddypress-media' ) . "</a>. <a href='" . esc_url( admin_url( 'admin.php?page=rtmedia-migration&hide=true' ) ) . "' style='float:right'>" . esc_html__( 'Hide', 'buddypress-media' ) . '</a> </p>' );
|
93 |
}
|
94 |
}
|
95 |
|
96 |
+
/**
|
97 |
+
* Create notice.
|
98 |
+
*
|
99 |
+
* @param string $message Message text.
|
100 |
+
* @param string $type Message tpe.
|
101 |
+
*/
|
102 |
+
public function create_notice( $message, $type = 'error' ) {
|
103 |
+
?>
|
104 |
+
<div class="<?php echo esc_attr( $type ); ?>"><?php echo esc_html( $message ); ?></div>
|
105 |
+
<?php
|
106 |
}
|
107 |
|
108 |
+
/**
|
109 |
+
* Check if table exists.
|
110 |
+
*
|
111 |
+
* @param string $table Table name.
|
112 |
+
*
|
113 |
+
* @return bool
|
114 |
+
*/
|
115 |
+
public static function table_exists( $table ) {
|
116 |
global $wpdb;
|
117 |
|
118 |
if ( 1 === intval( $wpdb->query( $wpdb->prepare( 'SHOW TABLES LIKE %s', $table ) ) ) ) {
|
122 |
return false;
|
123 |
}
|
124 |
|
125 |
+
/**
|
126 |
+
* Add Menu page for migration.
|
127 |
+
*/
|
128 |
+
public function menu() {
|
129 |
+
add_submenu_page(
|
130 |
+
'rtmedia-setting',
|
131 |
+
esc_html__( 'Migration', 'buddypress-media' ),
|
132 |
+
esc_html__( 'Migration', 'buddypress-media' ),
|
133 |
+
'manage_options',
|
134 |
+
'rtmedia-migration',
|
135 |
+
array(
|
136 |
+
$this,
|
137 |
+
'test',
|
138 |
+
)
|
139 |
+
);
|
140 |
}
|
141 |
|
142 |
+
/**
|
143 |
+
* Get total count.
|
144 |
+
*
|
145 |
+
* @return int
|
146 |
+
*/
|
147 |
+
public function get_total_count() {
|
148 |
global $wpdb;
|
149 |
if ( function_exists( 'bp_core_get_table_prefix' ) ) {
|
150 |
$bp_prefix = bp_core_get_table_prefix();
|
153 |
}
|
154 |
$sql_album_usercount = "select count(*) FROM $wpdb->usermeta where meta_key ='bp-media-default-album' ";
|
155 |
|
156 |
+
$_SESSION['migration_user_album'] = $wpdb->get_var( $sql_album_usercount ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
157 |
$count = intval( $_SESSION['migration_user_album'] );
|
158 |
|
159 |
if ( $this->table_exists( $bp_prefix . 'bp_groups_groupmeta' ) ) {
|
160 |
+
$sql_album_groupcount = $wpdb->prepare( "select count(*) FROM {$bp_prefix}bp_groups_groupmeta where meta_key =%s", 'bp_media_default_album' ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
161 |
+
$_SESSION['migration_group_album'] = $wpdb->get_var( $sql_album_groupcount ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
162 |
+
$count += intval( $_SESSION['migration_group_album'] );
|
163 |
}
|
164 |
+
|
165 |
if ( $this->table_exists( $bp_prefix . 'bp_activity' ) ) {
|
166 |
$sql_bpm_comment_count = "SELECT
|
167 |
count(id)
|
181 |
and is_spam <>1 and
|
182 |
not p.meta_value is NULL";
|
183 |
|
184 |
+
$_SESSION['migration_activity'] = $wpdb->get_var( $sql_bpm_comment_count ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
185 |
+
$count += intval( $_SESSION['migration_activity'] );
|
186 |
}
|
187 |
|
188 |
$sql = "select count(*)
|
200 |
a.post_id > 0 and (NOT p.ID IS NULL)
|
201 |
and a.meta_key = 'bp-media-key'";
|
202 |
|
203 |
+
$_SESSION['migration_media'] = $wpdb->get_var( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
204 |
+
$count += intval( $_SESSION['migration_media'] );
|
205 |
|
206 |
return $count;
|
207 |
}
|
208 |
|
209 |
+
/**
|
210 |
+
* Get last imported media id.
|
211 |
+
*
|
212 |
+
* @return bool
|
213 |
+
*/
|
214 |
+
public function get_last_imported() {
|
215 |
$album = rtmedia_get_site_option( 'rtmedia-global-albums' );
|
216 |
$album_id = $album[0];
|
217 |
|
223 |
where
|
224 |
a.meta_key = 'bp-media-key' and (NOT p.ID IS NULL) and a.post_id not in (select media_id
|
225 |
from {$this->bmp_table} where blog_id = %d and media_id <> %d ) order by a.post_ID";
|
226 |
+
$sql = $wpdb->prepare( $sql, get_current_blog_id(), $album_id ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
227 |
+
$row = $wpdb->get_row( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
228 |
if ( $row ) {
|
229 |
return $row->post_ID;
|
230 |
} else {
|
232 |
}
|
233 |
}
|
234 |
|
235 |
+
/**
|
236 |
+
* Get count for migrated media.
|
237 |
+
*
|
238 |
+
* @param bool $flag Flag to get migrated media count.
|
239 |
+
*
|
240 |
+
* @return mixed
|
241 |
+
*/
|
242 |
+
public function get_done_count( $flag = false ) {
|
243 |
global $wpdb;
|
244 |
$sql = "select count(*)
|
245 |
from {$this->bmp_table} where blog_id = %d and media_id in (select a.post_id
|
257 |
a.post_id > 0 and (NOT p.ID IS NULL)
|
258 |
and a.meta_key = 'bp-media-key')";
|
259 |
|
260 |
+
$media_count = $wpdb->get_var( $wpdb->prepare( $sql, get_current_blog_id() ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
261 |
+
|
262 |
if ( $flag ) {
|
263 |
return $media_count - 1;
|
264 |
}
|
265 |
+
|
266 |
$state = intval( rtmedia_get_site_option( 'rtmedia-migration', '0' ) );
|
267 |
+
|
268 |
+
if ( 5 === $state ) {
|
269 |
+
$album_count = intval( $_SESSION['migration_user_album'] );
|
270 |
$album_count += ( isset( $_SESSION['migration_group_album'] ) ) ? intval( $_SESSION['migration_group_album'] ) : 0;
|
271 |
} else {
|
272 |
if ( $state > 0 ) {
|
280 |
$pending_count .= " or ID in (select meta_value FROM {$bp_prefix}bp_groups_groupmeta where meta_key ='bp_media_default_album')";
|
281 |
}
|
282 |
$pending_count .= ')';
|
283 |
+
$pending_count = $wpdb->get_var( $pending_count ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
284 |
|
285 |
+
$album_count = intval( $_SESSION['migration_user_album'] );
|
286 |
$album_count += ( isset( $_SESSION['migration_group_album'] ) ) ? intval( $_SESSION['migration_group_album'] ) : 0;
|
287 |
+
$album_count = $album_count - intval( $pending_count );
|
288 |
} else {
|
289 |
$album_count = 0;
|
290 |
}
|
291 |
}
|
292 |
+
|
293 |
+
if ( isset( $_SESSION['migration_activity'] ) && intval( $_SESSION['migration_media'] ) === intval( $media_count ) ) {
|
294 |
$comment_sql = $_SESSION['migration_activity'];
|
295 |
} else {
|
296 |
+
// phpcs:disable WordPress.DB.PreparedSQL.NotPrepared
|
297 |
+
$comment_sql = $wpdb->get_var(
|
298 |
+
"select count(*) from $wpdb->comments a
|
299 |
+
where a.comment_post_ID in (select b.media_id from $this->bmp_table b left join
|
300 |
+
{$wpdb->posts} p ON (b.media_id = p.ID) where (NOT p.ID IS NULL) ) and a.comment_agent=''"
|
301 |
+
);
|
302 |
+
// phpcs:enable WordPress.DB.PreparedSQL.NotPrepared
|
303 |
}
|
304 |
|
305 |
return $media_count + $album_count + $comment_sql;
|
306 |
}
|
307 |
|
308 |
+
/**
|
309 |
+
* Return migration data.
|
310 |
+
*/
|
311 |
+
public function return_migration() {
|
312 |
$total = $this->get_total_count();
|
313 |
$done = $this->get_done_count();
|
314 |
$pending = $total - $done;
|
316 |
$pending = 0;
|
317 |
$done = $total;
|
318 |
}
|
319 |
+
|
320 |
if ( $done > $total ) {
|
321 |
$done = $total;
|
322 |
}
|
323 |
+
|
324 |
if ( $done === $total ) {
|
325 |
global $wp_rewrite;
|
326 |
+
// Call flush_rules() as a method of the $wp_rewrite object.
|
327 |
$wp_rewrite->flush_rules( true );
|
328 |
}
|
329 |
rtmedia_update_site_option( 'rtMigration-pending-count', $pending );
|
330 |
$pending_time = $this->format_seconds( $pending );
|
331 |
|
332 |
+
echo wp_json_encode(
|
333 |
+
array(
|
334 |
+
'status' => true,
|
335 |
+
'done' => $done,
|
336 |
+
'total' => $total,
|
337 |
+
'pending' => $pending_time,
|
338 |
+
)
|
339 |
+
);
|
340 |
die();
|
341 |
}
|
342 |
|
343 |
+
/**
|
344 |
+
* Manage album migration.
|
345 |
+
*
|
346 |
+
* @return bool
|
347 |
+
*/
|
348 |
+
public function manage_album() {
|
349 |
$album = rtmedia_get_site_option( 'rtmedia-global-albums' );
|
350 |
$stage = intval( rtmedia_get_site_option( 'rtmedia-migration', '0' ) );
|
351 |
|
355 |
|
356 |
global $wpdb;
|
357 |
|
358 |
+
$album_id = $wpdb->get_var( $wpdb->prepare( "select media_id from $this->bmp_table where id = %d", $album_rt_id ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
359 |
|
360 |
if ( function_exists( 'bp_core_get_table_prefix' ) ) {
|
361 |
$bp_prefix = bp_core_get_table_prefix();
|
364 |
}
|
365 |
|
366 |
if ( $stage < 1 ) {
|
367 |
+
|
368 |
global $wpdb;
|
369 |
+
|
370 |
if ( function_exists( 'bp_core_get_table_prefix' ) ) {
|
371 |
$bp_prefix = bp_core_get_table_prefix();
|
372 |
} else {
|
373 |
$bp_prefix = '';
|
374 |
}
|
375 |
+
|
376 |
+
$sql = $wpdb->prepare( "update {$bp_prefix}bp_activity set content=replace(content,%s,%s) where id > 0;", '<ul class="bp-media-list-media">', '<div class="rtmedia-activity-container"><ul class="rtmedia-list large-block-grid-3">' ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
377 |
+
$wpdb->get_row( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
378 |
+
$sql = $wpdb->prepare( "update {$bp_prefix}bp_activity set content=replace(content,%s,%s) where id > 0;", '</ul>', '</ul></div>' ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
379 |
+
$wpdb->get_row( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
380 |
|
381 |
$sql_group = "update $wpdb->posts set post_parent='{$album_id}' where post_parent in (select meta_value FROM $wpdb->usermeta where meta_key ='bp-media-default-album') ";
|
382 |
+
|
383 |
if ( $this->table_exists( $bp_prefix . 'bp_groups_groupmeta' ) ) {
|
384 |
$sql_group .= " or post_parent in (select meta_value FROM {$bp_prefix}bp_groups_groupmeta where meta_key ='bp_media_default_album')";
|
385 |
}
|
386 |
+
|
387 |
+
$wpdb->query( $sql_group ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
388 |
$stage = 1;
|
389 |
rtmedia_update_site_option( 'rtmedia-migration', $stage );
|
390 |
$this->return_migration();
|
391 |
}
|
392 |
+
|
393 |
if ( $stage < 2 ) {
|
394 |
+
|
395 |
+
$results = $wpdb->get_results( "select * from $wpdb->posts where post_type='bp_media_album' and ID in (select meta_value FROM $wpdb->usermeta where meta_key ='bp-media-default-album') limit 10" );
|
396 |
$delete_ids = '';
|
397 |
$sep = '';
|
398 |
+
|
399 |
foreach ( $results as $result ) {
|
400 |
$this->search_and_replace( $result->guid, trailingslashit( get_rtmedia_user_link( $result->post_author ) ) . RTMEDIA_MEDIA_SLUG . '/' . $album_rt_id );
|
401 |
$delete_ids .= $sep . $result->ID;
|
402 |
+
$sep = ',';
|
403 |
}
|
404 |
+
|
405 |
if ( '' !== $delete_ids ) {
|
406 |
+
// @todo missing prepare
|
407 |
+
$wpdb->query( "delete from $wpdb->posts where ID in ({$delete_ids})" ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
408 |
}
|
409 |
+
|
410 |
if ( count( $results ) < 10 ) {
|
411 |
$stage = 2;
|
412 |
}
|
413 |
+
|
414 |
rtmedia_update_site_option( 'rtmedia-migration', $stage );
|
415 |
$this->return_migration();
|
416 |
}
|
417 |
+
|
418 |
if ( $stage < 3 ) {
|
419 |
+
|
420 |
if ( $this->table_exists( $bp_prefix . 'bp_groups_groupmeta' ) ) {
|
421 |
+
|
422 |
$sql_delete = "select * from $wpdb->posts where post_type='bp_media_album' and ID in (select meta_value FROM {$bp_prefix}bp_groups_groupmeta where meta_key ='bp_media_default_album') limit 10";
|
423 |
+
$results = $wpdb->get_results( $sql_delete ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
424 |
$delete_ids = '';
|
425 |
$sep = '';
|
426 |
+
|
427 |
if ( $results ) {
|
428 |
+
|
429 |
foreach ( $results as $result ) {
|
430 |
$group_id = abs( intval( get_post_meta( $result->ID, 'bp-media-key', true ) ) );
|
431 |
$this->search_and_replace( trailingslashit( get_rtmedia_group_link( $group_id ) ) . 'albums/' . $result->ID, trailingslashit( get_rtmedia_group_link( $group_id ) ) . RTMEDIA_MEDIA_SLUG . '/' . $album_rt_id );
|
432 |
$delete_ids .= $sep . $result->ID;
|
433 |
+
$sep = ',';
|
434 |
}
|
435 |
+
|
436 |
if ( '' !== $delete_ids ) {
|
437 |
+
// @todo prepare
|
438 |
+
$wpdb->query( "delete from $wpdb->posts where ID in ({$delete_ids})" ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
439 |
}
|
440 |
+
|
441 |
if ( count( $results ) < 10 ) {
|
442 |
$stage = 3;
|
443 |
}
|
454 |
}
|
455 |
|
456 |
$sql = "update $wpdb->posts set post_type='{$album_post_type}' where post_type='bp_media_album'";
|
|
|
|
|
457 |
|
458 |
+
if ( false !== $wpdb->query( $sql ) ) { // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
459 |
+
|
460 |
+
rtmedia_update_site_option( 'rtmedia-migration', '5' );
|
461 |
return true;
|
462 |
+
|
463 |
}
|
464 |
|
465 |
return false;
|
466 |
}
|
467 |
|
468 |
+
/**
|
469 |
+
* Test migration.
|
470 |
+
*/
|
471 |
+
public function test() {
|
472 |
if ( ! $this->table_exists( $this->bmp_table ) ) {
|
473 |
$obj = new RTDBUpdate( false, RTMEDIA_PATH . 'index.php', RTMEDIA_PATH . 'app/schema/', true );
|
474 |
$obj->install_db_version = '0';
|
475 |
$obj->do_upgrade( true );
|
476 |
}
|
477 |
+
|
478 |
global $rtmedia_error;
|
479 |
+
|
480 |
if ( isset( $rtmedia_error ) && true === $rtmedia_error ) {
|
481 |
?>
|
482 |
<div class="error"><p><?php echo esc_html__( 'Please Resolve create database error before migration.', 'buddypress-media' ); ?></p></div>
|
493 |
<div class="error">
|
494 |
<p>
|
495 |
<?php
|
496 |
+
/* translators: 1: %s gets replaced by '<strong>', 2: %s by '</strong>' */
|
497 |
printf( esc_html__( 'Please Backup your %1$sDATABASE%2$s and %1$sUPLOAD%2$s folder before Migration.', 'buddypress-media' ), '<strong>', '</strong>' );
|
498 |
?>
|
499 |
</p>
|
507 |
<h2><?php esc_html_e( 'rtMedia Migration', 'buddypress-media' ); ?></h2>
|
508 |
|
509 |
<h3><?php esc_html_e( 'It will migrate following things', 'buddypress-media' ); ?> </h3>
|
510 |
+
<?php
|
511 |
+
esc_html_e( 'User Albums : ', 'buddypress-media' );
|
512 |
+
echo esc_html( $_SESSION['migration_user_album'] );
|
513 |
+
?>
|
514 |
+
<br/>
|
515 |
+
<?php
|
516 |
+
if ( isset( $_SESSION['migration_group_album'] ) ) {
|
517 |
esc_html_e( 'Groups Albums : ', 'buddypress-media' );
|
518 |
+
echo esc_html( $_SESSION['migration_group_album'] );
|
519 |
+
?>
|
520 |
+
<br/>
|
521 |
+
<?php
|
522 |
+
}
|
523 |
esc_html_e( 'Media : ', 'buddypress-media' );
|
524 |
+
echo esc_html( $_SESSION['migration_media'] );
|
525 |
?>
|
526 |
+
<br/>
|
527 |
+
?>
|
528 |
+
<?php
|
529 |
+
if ( isset( $_SESSION['migration_activity'] ) ) {
|
530 |
esc_html_e( 'Comments : ', 'buddypress-media' );
|
531 |
+
echo esc_html( $_SESSION['migration_activity'] );
|
532 |
+
?>
|
533 |
+
<br/>
|
534 |
<?php } ?>
|
535 |
<hr/>
|
536 |
|
610 |
</script>
|
611 |
<hr/>
|
612 |
<?php if ( ! ( isset( $rtmedia_error ) && true === $rtmedia_error ) ) { ?>
|
613 |
+
<input type="button" id="submit" value="<?php esc_attr_e( 'Start', 'buddypress-media' ); ?>" class="button button-primary"/>
|
|
|
614 |
<?php } ?>
|
615 |
|
616 |
</div>
|
617 |
<?php
|
618 |
}
|
619 |
|
620 |
+
/**
|
621 |
+
* Migrate media to new DB.
|
622 |
+
*
|
623 |
+
* @param int $lastid Last id.
|
624 |
+
* @param int $limit Limit of rows.
|
625 |
+
*/
|
626 |
+
public function migrate_to_new_db( $lastid = 0, $limit = 1 ) {
|
627 |
|
628 |
if ( ! isset( $_SESSION['migration_media'] ) ) {
|
629 |
$this->get_total_count();
|
672 |
order by a.post_id
|
673 |
limit %d";
|
674 |
|
675 |
+
$results = $wpdb->get_results( $wpdb->prepare( $sql, $lastid, $limit ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
676 |
|
677 |
if ( function_exists( 'bp_core_get_table_prefix' ) ) {
|
678 |
$bp_prefix = bp_core_get_table_prefix();
|
687 |
}
|
688 |
} else {
|
689 |
global $wp_rewrite;
|
690 |
+
// Call flush_rules() as a method of the $wp_rewrite object.
|
691 |
$wp_rewrite->flush_rules( true );
|
692 |
}
|
693 |
$this->return_migration();
|
694 |
}
|
695 |
|
696 |
+
/**
|
697 |
+
* Update migrate encoding options.
|
698 |
+
*/
|
699 |
+
public function migrate_encoding_options() {
|
700 |
+
$encoding_migration_array = array(
|
701 |
'bp-media-encoding-api-key' => 'rtmedia-encoding-api-key',
|
702 |
'bp-media-encoding-usage-limit-mail' => 'rtmedia-encoding-usage-limit-mail',
|
703 |
'bp-media-encoding-usage' => 'rtmedia-encoding-usage',
|
706 |
'bp_media_ffmpeg_options' => 'rtmedia-ffmpeg-options',
|
707 |
'bp_media_kaltura_options' => 'rtmedia-kaltura-options',
|
708 |
);
|
709 |
+
|
710 |
+
foreach ( $encoding_migration_array as $key => $ma ) {
|
711 |
+
$value = rtmedia_get_site_option( $key );
|
712 |
+
|
713 |
+
if ( false !== $value ) {
|
714 |
rtmedia_update_site_option( $ma, $value );
|
715 |
}
|
716 |
}
|
717 |
}
|
718 |
|
719 |
+
/**
|
720 |
+
* Migrate single media.
|
721 |
+
*
|
722 |
+
* @param string $result Media id.
|
723 |
+
* @param bool|string $album Album name.
|
724 |
+
*
|
725 |
+
* @return mixed
|
726 |
+
*/
|
727 |
+
public function migrate_single_media( $result, $album = false ) {
|
728 |
+
|
729 |
$blog_id = get_current_blog_id();
|
730 |
$old = $result;
|
731 |
+
|
732 |
if ( function_exists( 'bp_core_get_table_prefix' ) ) {
|
733 |
$bp_prefix = bp_core_get_table_prefix();
|
734 |
} else {
|
735 |
$bp_prefix = '';
|
736 |
}
|
737 |
+
|
738 |
global $wpdb;
|
739 |
|
740 |
if ( false !== $album && ! ( is_object( $result ) ) ) {
|
741 |
+
|
742 |
+
$id = $wpdb->get_var( $wpdb->prepare( "select ID from {$this->bmp_table} where media_id = %d", $result ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
743 |
+
|
744 |
+
if ( null === $id ) {
|
745 |
$sql = "select
|
746 |
a.post_id as 'post_id',
|
747 |
a.meta_value as 'privacy',
|
765 |
where
|
766 |
a.post_id = %d and (NOT p.ID IS NULL)
|
767 |
and a.meta_key = 'bp_media_privacy'";
|
768 |
+
$result = $wpdb->get_row( $wpdb->prepare( $sql, $result ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
769 |
} else {
|
770 |
return $id;
|
771 |
}
|
784 |
}
|
785 |
|
786 |
$old_type = '';
|
787 |
+
if ( 'attachment' !== $result->post_type ) {
|
788 |
$media_type = 'album';
|
789 |
} else {
|
790 |
$mime_type = strtolower( $result->post_mime_type );
|
807 |
}
|
808 |
}
|
809 |
|
810 |
+
$activity_data = $wpdb->get_row( $wpdb->prepare( "select * from {$bp_prefix}bp_activity where id= %d", $result->activity_id ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
811 |
+
if ( 'album' !== $media_type ) {
|
812 |
$this->importmedia( $media_id, $prefix );
|
813 |
}
|
814 |
|
815 |
if ( $this->table_exists( $bp_prefix . 'bp_activity' ) && class_exists( 'BP_Activity_Activity' ) ) {
|
816 |
+
$bp_activity = new BP_Activity_Activity();
|
817 |
+
// phpcs:disable WordPress.DB.PreparedSQL.NotPrepared
|
818 |
+
$activity_sql = $wpdb->prepare(
|
819 |
+
"SELECT
|
820 |
*
|
821 |
FROM
|
822 |
{$bp_prefix}bp_activity
|
829 |
$wpdb->posts p ON (a.post_id = p.ID)
|
830 |
where
|
831 |
(NOT p.ID IS NULL) and p.ID = %d
|
832 |
+
and a.meta_key = 'bp_media_child_activity')",
|
833 |
+
$media_id
|
834 |
+
);
|
835 |
$all_activity = $wpdb->get_results( $activity_sql );
|
836 |
+
// phpcs:enable WordPress.DB.PreparedSQL.NotPrepared
|
837 |
remove_all_actions( 'wp_insert_comment' );
|
838 |
foreach ( $all_activity as $activity ) {
|
839 |
$comments = $bp_activity->get_activity_comments( $activity->id, $activity->mptt_left, $activity->mptt_right );
|
857 |
$likes = 0;
|
858 |
}
|
859 |
|
860 |
+
$wpdb->insert(
|
861 |
+
$this->bmp_table,
|
862 |
+
array(
|
863 |
+
'blog_id' => $blog_id,
|
864 |
+
'media_id' => $media_id,
|
865 |
+
'media_type' => $media_type,
|
866 |
+
'context' => $media_context,
|
867 |
+
'context_id' => abs( intval( $result->context_id ) ),
|
868 |
+
'activity_id' => $result->activity_id,
|
869 |
+
'privacy' => intval( $result->privacy ) * 10,
|
870 |
+
'media_author' => $result->media_author,
|
871 |
+
'media_title' => $result->media_title,
|
872 |
+
'album_id' => $album_id,
|
873 |
+
'likes' => $likes,
|
874 |
+
),
|
875 |
+
array( '%d', '%d', '%s', '%s', '%d', '%d', '%d', '%d', '%s', '%d', '%d' )
|
876 |
+
);
|
877 |
+
|
878 |
$last_id = $wpdb->insert_id;
|
879 |
|
880 |
+
if ( 'album' !== $media_type && function_exists( 'bp_core_get_user_domain' ) && $activity_data ) {
|
881 |
if ( function_exists( 'bp_core_get_table_prefix' ) ) {
|
882 |
$bp_prefix = bp_core_get_table_prefix();
|
883 |
} else {
|
897 |
$activity_data->content = str_replace( $last_baseurl, $replace_img, $activity_data->content );
|
898 |
}
|
899 |
global $wpdb;
|
900 |
+
$wpdb->update(
|
901 |
+
$bp_prefix . 'bp_activity',
|
902 |
+
array(
|
903 |
+
'primary_link' => $activity_data->primary_link,
|
904 |
+
'action' => $activity_data->action,
|
905 |
+
'content' => $activity_data->content,
|
906 |
+
),
|
907 |
+
array( 'id' => $activity_data->id )
|
908 |
+
);
|
909 |
} else {
|
910 |
+
if ( 'group' === $media_context ) {
|
911 |
$activity_data->old_primary_link = $activity_data->primary_link;
|
912 |
$parent_link = get_rtmedia_group_link( abs( intval( $result->context_id ) ) );
|
913 |
$parent_link = trailingslashit( $parent_link );
|
921 |
$this->search_and_replace( $activity_data->old_primary_link, $activity_data->primary_link );
|
922 |
}
|
923 |
}
|
924 |
+
if ( '' !== $old_type ) {
|
925 |
+
if ( 'group' === $media_context ) {
|
926 |
$parent_link = get_rtmedia_group_link( abs( intval( $result->context_id ) ) );
|
927 |
$parent_link = trailingslashit( $parent_link );
|
928 |
$this->search_and_replace( trailingslashit( $parent_link . $old_type . '/' . $media_id ), trailingslashit( $parent_link . RTMEDIA_MEDIA_SLUG . '/' . $last_id ) );
|
937 |
}
|
938 |
|
939 |
/**
|
940 |
+
* Import media.
|
941 |
+
*
|
942 |
+
* @param int $id Media id.
|
943 |
+
* @param string $prefix Prefix.
|
944 |
*/
|
945 |
+
public function importmedia( $id, $prefix ) {
|
946 |
|
947 |
$delete = false;
|
948 |
$attached_file = get_attached_file( $id );
|
953 |
$siteurl = get_option( 'siteurl' );
|
954 |
$upload_path = trim( get_option( 'upload_path' ) );
|
955 |
|
956 |
+
if ( empty( $upload_path ) || 'wp-content/uploads' === $upload_path ) {
|
957 |
$dir = WP_CONTENT_DIR . '/uploads';
|
958 |
} elseif ( 0 !== strpos( $upload_path, ABSPATH ) ) {
|
959 |
+
// $dir is absolute, $upload_path is (maybe) relative to ABSPATH.
|
960 |
$dir = path_join( ABSPATH, $upload_path );
|
961 |
} else {
|
962 |
$dir = $upload_path;
|
963 |
}
|
964 |
|
965 |
+
$url = get_option( 'upload_url_path' );
|
966 |
+
|
967 |
+
if ( ! empty( $url ) ) {
|
968 |
+
if ( empty( $upload_path ) || ( 'wp-content/uploads' === $upload_path ) || ( $upload_path === $dir ) ) {
|
969 |
$url = WP_CONTENT_URL . '/uploads';
|
970 |
} else {
|
971 |
$url = trailingslashit( $siteurl ) . $upload_path;
|
979 |
$url = trailingslashit( $siteurl ) . UPLOADS;
|
980 |
}
|
981 |
|
982 |
+
// If multisite (and if not the main site in a post-MU network).
|
983 |
if ( is_multisite() && ! ( is_main_site() && defined( 'MULTISITE' ) ) ) {
|
984 |
|
985 |
if ( ! rtmedia_get_site_option( 'ms_files_rewriting' ) ) {
|
987 |
// Append sites/%d if we're not on the main site (for post-MU networks). (The extra directory
|
988 |
// prevents a four-digit ID from conflicting with a year-based directory for the main site.
|
989 |
// But if a MU-era network has disabled ms-files rewriting manually, they don't need the extra
|
990 |
+
// directory, as they never had wp-content/uploads for the main site.).
|
|
|
991 |
if ( defined( 'MULTISITE' ) ) {
|
992 |
$ms_dir = '/sites/' . get_current_blog_id();
|
993 |
} else {
|
999 |
} elseif ( defined( 'UPLOADS' ) && ! ms_is_switched() ) {
|
1000 |
// Handle the old-form ms-files.php rewriting if the network still has that enabled.
|
1001 |
// When ms-files rewriting is enabled, then we only listen to UPLOADS when:
|
1002 |
+
// 1) we are not on the main site in a post-MU network,
|
1003 |
+
// as wp-content/uploads is used there, and
|
1004 |
+
// 2) we are not switched, as ms_upload_constants() hardcodes
|
1005 |
+
// these constants to reflect the original blog ID.
|
1006 |
//
|
1007 |
// Rather than UPLOADS, we actually use BLOGUPLOADDIR if it is set, as it is absolute.
|
1008 |
// (And it will be set, see ms_upload_constants().) Otherwise, UPLOADS can be used, as
|
1009 |
// as it is relative to ABSPATH. For the final piece: when UPLOADS is used with ms-files
|
1010 |
+
// rewriting in multisite, the resulting URL is /files. (#WP22702 for background.).
|
|
|
1011 |
if ( defined( 'BLOGUPLOADDIR' ) ) {
|
1012 |
$dir = untrailingslashit( BLOGUPLOADDIR );
|
1013 |
} else {
|
1172 |
}
|
1173 |
}
|
1174 |
|
1175 |
+
/**
|
1176 |
+
* Search and replace in activity table.
|
1177 |
+
*
|
1178 |
+
* @param string $old Old string.
|
1179 |
+
* @param string $new New string.
|
1180 |
+
*/
|
1181 |
+
public function search_and_replace( $old, $new ) {
|
1182 |
global $wpdb;
|
1183 |
+
|
1184 |
if ( function_exists( 'bp_core_get_table_prefix' ) ) {
|
1185 |
$bp_prefix = bp_core_get_table_prefix();
|
1186 |
} else {
|
1187 |
$bp_prefix = $wpdb->prefix;
|
1188 |
}
|
1189 |
+
|
1190 |
+
$sql = $wpdb->prepare( "update {$bp_prefix}bp_activity set action=replace(action,%s,%s) ,content=replace(content,%s,%s), primary_link=replace(primary_link,%s,%s) where id > 0;", $old, $new, $old, $new, $old, $new ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
1191 |
+
$wpdb->get_row( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
1192 |
}
|
1193 |
|
1194 |
+
/**
|
1195 |
+
* Format seconds into time.
|
1196 |
+
*
|
1197 |
+
* @param float $seconds_left Seconds to format.
|
1198 |
+
*
|
1199 |
+
* @return string
|
1200 |
+
*/
|
1201 |
+
public function format_seconds( $seconds_left ) {
|
1202 |
|
1203 |
$minute_in_seconds = 60;
|
1204 |
$hour_in_seconds = $minute_in_seconds * 60;
|
1217 |
$time_components = array();
|
1218 |
|
1219 |
if ( $days > 0 ) {
|
1220 |
+
$time_components[] = $days . esc_html__( ' day', 'buddypress-media' ) . ( $days > 1 ? 's' : '' );
|
1221 |
}
|
1222 |
|
1223 |
if ( $hours > 0 ) {
|
1241 |
return $formatted_time_remaining;
|
1242 |
}
|
1243 |
|
1244 |
+
/**
|
1245 |
+
* Insert comment.
|
1246 |
+
*
|
1247 |
+
* @param int $media_id media id.
|
1248 |
+
* @param array $data Media data.
|
1249 |
+
* @param string $exclude Exclude.
|
1250 |
+
* @param int $parent_commnet_id parent comment id.
|
1251 |
+
*/
|
1252 |
+
public function insert_comment( $media_id, $data, $exclude, $parent_commnet_id = 0 ) {
|
1253 |
foreach ( $data as $cmnt ) {
|
1254 |
$comment_id = 0;
|
1255 |
if ( ! key_exists( strval( $cmnt->id ), $exclude ) ) {
|
app/main/RTMedia.php
CHANGED
@@ -1,46 +1,54 @@
|
|
1 |
<?php
|
2 |
-
if ( ! defined( 'ABSPATH' ) ) {
|
3 |
-
exit;
|
4 |
-
}
|
5 |
-
|
6 |
/**
|
7 |
-
* rtMedia
|
8 |
-
*
|
9 |
-
* The main rtMedia Class. This is where everything starts.
|
10 |
*
|
11 |
* @package rtMedia
|
12 |
* @subpackage Main
|
13 |
*
|
14 |
* @author Faishal <faishal.saiyed@rtcamp.com>
|
15 |
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
class RTMedia {
|
17 |
|
18 |
/**
|
19 |
-
*
|
|
|
|
|
20 |
*/
|
21 |
private $default_thumbnail;
|
22 |
|
23 |
/**
|
|
|
24 |
*
|
25 |
-
* @var array
|
26 |
*/
|
27 |
public $allowed_types;
|
28 |
|
29 |
/**
|
|
|
30 |
*
|
31 |
-
* @var array
|
32 |
*/
|
33 |
public $privacy_settings;
|
34 |
|
35 |
/**
|
|
|
36 |
*
|
37 |
-
* @var array
|
38 |
*/
|
39 |
public $default_sizes;
|
40 |
|
41 |
/**
|
|
|
42 |
*
|
43 |
-
* @var
|
44 |
*/
|
45 |
public $default_privacy = array(
|
46 |
'0' => 'Public',
|
@@ -50,28 +58,43 @@ class RTMedia {
|
|
50 |
);
|
51 |
|
52 |
/**
|
|
|
53 |
*
|
54 |
-
* @var string
|
55 |
*/
|
56 |
public $support_url = 'https://rtmedia.io/support/';
|
57 |
|
58 |
/**
|
|
|
59 |
*
|
60 |
-
* @var int
|
61 |
*/
|
62 |
public $posts_per_page = 10;
|
63 |
|
64 |
/**
|
|
|
65 |
*
|
66 |
-
* @var array
|
67 |
*/
|
68 |
public $activity_types = array(
|
69 |
'media_upload',
|
70 |
'album_updated',
|
71 |
'album_created',
|
72 |
);
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
public $options;
|
74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
|
76 |
/**
|
77 |
* Constructs the class
|
@@ -94,11 +117,11 @@ class RTMedia {
|
|
94 |
add_action( 'groups_settings_updated', array( $this, 'group_status_reset_cache' ) );
|
95 |
add_action( 'groups_delete_group', array( $this, 'group_status_reset_cache' ) );
|
96 |
|
97 |
-
// Including core functions, actions & filters
|
98 |
-
include
|
99 |
-
include
|
100 |
-
include
|
101 |
-
include
|
102 |
|
103 |
add_filter( 'intermediate_image_sizes_advanced', array( $this, 'filter_image_sizes_details' ) );
|
104 |
add_filter( 'intermediate_image_sizes', array( $this, 'filter_image_sizes' ) );
|
@@ -115,7 +138,14 @@ class RTMedia {
|
|
115 |
delete_transient( 'group_status_' . $group_id );
|
116 |
}
|
117 |
|
118 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
$allowed_types = array();
|
120 |
$this->allowed_types = apply_filters( 'rtmedia_allowed_types', $this->allowed_types );
|
121 |
foreach ( $this->allowed_types as $type ) {
|
@@ -125,12 +155,15 @@ class RTMedia {
|
|
125 |
}
|
126 |
}
|
127 |
}
|
128 |
-
$ext = apply_filters(
|
|
|
129 |
array(
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
|
|
|
|
134 |
$ext_arr = explode( ',', $ext[0]['extensions'] );
|
135 |
$options = trim( $options );
|
136 |
foreach ( $ext_arr as $f_ext ) {
|
@@ -142,7 +175,10 @@ class RTMedia {
|
|
142 |
return $options;
|
143 |
}
|
144 |
|
145 |
-
|
|
|
|
|
|
|
146 |
$site_global = rtmedia_get_site_option( 'rtmedia-global-albums' );
|
147 |
if ( $site_global && is_array( $site_global ) && isset( $site_global[0] ) ) {
|
148 |
$model = new RTMediaModel();
|
@@ -151,8 +187,9 @@ class RTMedia {
|
|
151 |
global $wpdb;
|
152 |
$row = $album_row['result'][0];
|
153 |
if ( isset( $row['media_id'] ) ) {
|
154 |
-
//
|
155 |
-
$sql = $wpdb->prepare(
|
|
|
156 |
left join
|
157 |
$model->table_name r ON ( p.ID = r.media_id and blog_id = %d )
|
158 |
set
|
@@ -161,28 +198,34 @@ class RTMedia {
|
|
161 |
p.guid like %s
|
162 |
and (p.post_parent = 0 or p.post_parent is NULL)
|
163 |
and not r.id is NULL
|
164 |
-
and r.media_type <> 'album'",
|
|
|
|
|
|
|
|
|
165 |
$wpdb->query( $sql );
|
166 |
-
//
|
167 |
}
|
168 |
}
|
169 |
}
|
170 |
}
|
171 |
|
172 |
-
|
|
|
|
|
|
|
173 |
global $wpdb;
|
174 |
$model = new RTMediaModel();
|
175 |
$update_sql = "UPDATE {$model->table_name} SET privacy = '80' where privacy = '-1' ";
|
176 |
-
$wpdb->query( $update_sql ); //
|
177 |
}
|
178 |
|
179 |
-
|
180 |
* Update media privacy of the medias having context=group
|
181 |
* update privacy of groups medias according to the privacy of the group 0->public, 20-> private/hidden
|
182 |
*/
|
183 |
-
|
184 |
-
|
185 |
-
//if buddypress is active and groups are enabled
|
186 |
global $wpdb;
|
187 |
$table_exist = false;
|
188 |
if ( $wpdb->query( "SHOW TABLES LIKE '{$wpdb->prefix}bp_groups'" ) ) {
|
@@ -191,25 +234,31 @@ class RTMedia {
|
|
191 |
if ( class_exists( 'BuddyPress' ) && $table_exist ) {
|
192 |
$model = new RTMediaModel();
|
193 |
$sql_group = " UPDATE $model->table_name m join {$wpdb->prefix}bp_groups bp on m.context_id = bp.id SET m.privacy = 0 where m.context = 'group' and bp.status = 'public' and m.privacy <> 80 ";
|
194 |
-
$wpdb->query( $sql_group ); //
|
195 |
$sql_group = " UPDATE $model->table_name m join {$wpdb->prefix}bp_groups bp on m.context_id = bp.id SET m.privacy = 20 where m.context = 'group' and ( bp.status = 'private' OR bp.status = 'hidden' ) and m.privacy <> 80 ";
|
196 |
-
$wpdb->query( $sql_group ); //
|
197 |
}
|
198 |
}
|
199 |
|
200 |
-
|
|
|
|
|
|
|
201 |
global $wpdb;
|
202 |
$model = new RTMediaModel();
|
203 |
$interaction_model = new RTMediaInteractionModel();
|
204 |
$update_media_sql = 'ALTER TABLE ' . $model->table_name . ' CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci';
|
205 |
-
$wpdb->query( $update_media_sql ); //
|
206 |
$update_media_meta_sql = 'ALTER TABLE ' . $wpdb->base_prefix . $model->meta_table_name . ' CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci';
|
207 |
-
$wpdb->query( $update_media_meta_sql ); //
|
208 |
$update_media_interaction_sql = 'ALTER TABLE ' . $interaction_model->table_name . ' CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci';
|
209 |
-
$wpdb->query( $update_media_interaction_sql ); //
|
210 |
}
|
211 |
|
212 |
-
|
|
|
|
|
|
|
213 |
|
214 |
$rtmedia_options = rtmedia_get_site_option( 'rtmedia-options' );
|
215 |
$bp_media_options = rtmedia_get_site_option( 'bp_media_options' );
|
@@ -217,7 +266,7 @@ class RTMedia {
|
|
217 |
if ( false === $rtmedia_options ) {
|
218 |
$this->init_site_options();
|
219 |
} else {
|
220 |
-
|
221 |
$this->options = $rtmedia_options;
|
222 |
}
|
223 |
$this->add_image_sizes();
|
@@ -226,20 +275,22 @@ class RTMedia {
|
|
226 |
}
|
227 |
|
228 |
/**
|
229 |
-
*
|
|
|
|
|
230 |
*
|
231 |
-
*
|
|
|
232 |
*/
|
233 |
public function comment_auto_complete( $rtmedia_options = false, $bp_media_options = false ) {
|
234 |
add_filter( 'bp_activity_maybe_load_mentions_scripts', array( $this, 'rtmedia_bp_activity_maybe_load_mentions_scripts_callback' ), 10001, 2 );
|
235 |
}
|
236 |
|
237 |
-
|
238 |
/**
|
239 |
* Always set to true when call on any of the Buddypress Pages
|
240 |
*
|
241 |
-
* @param
|
242 |
-
* @param
|
243 |
*
|
244 |
* @return bool true
|
245 |
*/
|
@@ -248,17 +299,31 @@ class RTMedia {
|
|
248 |
return $load_mentions;
|
249 |
}
|
250 |
|
251 |
-
|
|
|
|
|
252 |
public function set_image_quality() {
|
253 |
add_filter( 'jpeg_quality', array( $this, 'rtmedia_jpeg_quality' ) );
|
254 |
}
|
255 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
256 |
public function rtmedia_jpeg_quality( $quality ) {
|
257 |
$quality = isset( $this->options['general_jpeg_image_quality'] ) ? $this->options['general_jpeg_image_quality'] : 90;
|
258 |
|
259 |
return $quality;
|
260 |
}
|
261 |
|
|
|
|
|
|
|
|
|
|
|
262 |
public function image_sizes() {
|
263 |
$image_sizes = array();
|
264 |
$image_sizes['thumbnail'] = array(
|
@@ -285,6 +350,9 @@ class RTMedia {
|
|
285 |
return $image_sizes;
|
286 |
}
|
287 |
|
|
|
|
|
|
|
288 |
public function add_image_sizes() {
|
289 |
$bp_media_sizes = $this->image_sizes();
|
290 |
add_image_size( 'rt_media_thumbnail', $bp_media_sizes['thumbnail']['width'], $bp_media_sizes['thumbnail']['height'], $bp_media_sizes['thumbnail']['crop'] );
|
@@ -294,7 +362,10 @@ class RTMedia {
|
|
294 |
add_action( 'wp_head', array( &$this, 'custom_style_for_image_size' ) );
|
295 |
}
|
296 |
|
297 |
-
|
|
|
|
|
|
|
298 |
if ( apply_filters( 'rtmedia_custom_image_style', true ) ) {
|
299 |
?>
|
300 |
<style type="text/css">
|
@@ -313,10 +384,13 @@ class RTMedia {
|
|
313 |
}
|
314 |
}
|
315 |
|
316 |
-
|
|
|
|
|
|
|
317 |
|
318 |
// Get width from rtMedia settings.
|
319 |
-
$width
|
320 |
// Get height from rtMedia settings.
|
321 |
$height = ( isset( $this->options['defaultSizes_photo_medium_height'] ) ) ? $this->options['defaultSizes_photo_medium_height'] : '0';
|
322 |
|
@@ -350,72 +424,76 @@ class RTMedia {
|
|
350 |
}
|
351 |
|
352 |
?>
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
<?php
|
407 |
global $rtmedia;
|
408 |
-
if ( rtmedia_check_comment_media_allow() && ! rtmedia_check_comment_in_commented_media_allow() ) {
|
|
|
409 |
#buddypress ul.activity-list li.activity-item .activity-comments ul li form.ac-form .rtmedia-comment-media-upload,#buddypress ul.activity-list li.activity-item .activity-comments ul li form.ac-form .rtmedia-container {
|
410 |
-
|
411 |
}
|
412 |
<?php
|
413 |
}
|
414 |
}
|
415 |
|
416 |
-
|
|
|
|
|
|
|
417 |
// Get width from rtMedia settings.
|
418 |
-
$width
|
419 |
// Get height from rtMedia settings.
|
420 |
$height = ( isset( $this->options['defaultSizes_photo_thumbnail_height'] ) ) ? $this->options['defaultSizes_photo_thumbnail_height'] : '0';
|
421 |
|
@@ -441,12 +519,15 @@ class RTMedia {
|
|
441 |
max-height: <?php echo esc_attr( $media_height ); ?>;
|
442 |
}
|
443 |
.rtmedia-container .rtmedia-list .rtmedia-list-item {
|
444 |
-
width: <?php echo $media_width; ?>;
|
445 |
}
|
446 |
<?php
|
447 |
}
|
448 |
|
449 |
-
|
|
|
|
|
|
|
450 |
if ( intval( $this->options['defaultSizes_photo_thumbnail_height'] ) > 0 ) {
|
451 |
?>
|
452 |
.rtmedia-container .rtmedia-list .rtmedia-list-item .rtmedia-item-thumbnail {
|
@@ -466,7 +547,7 @@ class RTMedia {
|
|
466 |
/**
|
467 |
* Default allowed media types array
|
468 |
*/
|
469 |
-
function set_allowed_types() {
|
470 |
$allowed_types = array(
|
471 |
'photo' => array(
|
472 |
'name' => 'photo',
|
@@ -497,39 +578,39 @@ class RTMedia {
|
|
497 |
),
|
498 |
);
|
499 |
|
500 |
-
// filter for hooking additional media types
|
501 |
$allowed_types = apply_filters( 'rtmedia_allowed_types', $allowed_types );
|
502 |
|
503 |
-
// sanitize all the types
|
504 |
$allowed_types = $this->sanitize_allowed_types( $allowed_types );
|
505 |
|
506 |
-
// set the allowed types property
|
507 |
$this->allowed_types = $allowed_types;
|
508 |
}
|
509 |
|
510 |
/**
|
511 |
* Sanitize all media sizes after hooking custom media types
|
512 |
*
|
513 |
-
* @param array $allowed_types allowed media types after hooking custom types
|
514 |
*
|
515 |
* @return array $allowed_types sanitized media types
|
516 |
*/
|
517 |
-
function sanitize_allowed_types( $allowed_types ) {
|
518 |
-
// check if the array is formatted properly
|
519 |
if ( ! is_array( $allowed_types ) && count( $allowed_types ) < 1 ) {
|
520 |
return;
|
521 |
}
|
522 |
|
523 |
-
//loop through each type
|
524 |
foreach ( $allowed_types as $key => &$type ) {
|
525 |
|
526 |
-
if ( ! isset( $type['name'] ) || // check if a name is set
|
527 |
empty( $type['name'] ) ||
|
528 |
-
//commented this section for playlist // !isset($type['extn']) || // check if file extensions are set
|
529 |
-
//commented this section for playlist // empty($type['extn'])
|
530 |
strstr( $type['name'], ' ' ) || strstr( $type['name'], '_' )
|
531 |
) {
|
532 |
-
unset( $allowed_types[ $key ] ); // if not unset this type
|
533 |
continue;
|
534 |
}
|
535 |
$slug = strtoupper( $type['name'] );
|
@@ -539,7 +620,7 @@ class RTMedia {
|
|
539 |
if ( defined( 'RTMEDIA_' . $slug . '_PLURAL_LABEL' ) ) {
|
540 |
$type['plural_label'] = constant( 'RTMEDIA_' . $slug . '_PLURAL_LABEL' );
|
541 |
}
|
542 |
-
// if thumbnail is not supplied, use the default thumbnail
|
543 |
if ( ! isset( $type['thumbnail'] ) || empty( $type['thumbnail'] ) ) {
|
544 |
$type['thumbnail'] = $this->default_thumbnail;
|
545 |
}
|
@@ -551,23 +632,45 @@ class RTMedia {
|
|
551 |
/**
|
552 |
* Set the default sizes
|
553 |
*/
|
554 |
-
function set_default_sizes() {
|
555 |
$this->default_sizes = array(
|
556 |
'photo' => array(
|
557 |
-
'thumbnail' => array(
|
558 |
-
|
559 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
560 |
),
|
561 |
'video' => array(
|
562 |
-
'activityPlayer' => array(
|
563 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
564 |
),
|
565 |
'music' => array(
|
566 |
'activityPlayer' => array( 'width' => 320 ),
|
567 |
'singlePlayer' => array( 'width' => 640 ),
|
568 |
),
|
569 |
'featured' => array(
|
570 |
-
'default' => array(
|
|
|
|
|
|
|
|
|
571 |
),
|
572 |
);
|
573 |
|
@@ -577,7 +680,7 @@ class RTMedia {
|
|
577 |
/**
|
578 |
* Set privacy options
|
579 |
*/
|
580 |
-
function set_privacy() {
|
581 |
|
582 |
$this->privacy_settings = array(
|
583 |
'levels' => array(
|
@@ -599,16 +702,27 @@ class RTMedia {
|
|
599 |
*
|
600 |
* @global RTMediaAdmin $rtmedia_admin Class for loading admin screen
|
601 |
*/
|
602 |
-
function admin_init() {
|
603 |
global $rtmedia_admin;
|
604 |
$rtmedia_admin = new RTMediaAdmin();
|
605 |
}
|
606 |
|
607 |
-
|
608 |
-
|
|
|
|
|
|
|
|
|
609 |
}
|
610 |
|
611 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
612 |
|
613 |
if ( function_exists( 'bp_core_get_user_domain' ) ) {
|
614 |
$parent_link = bp_core_get_user_domain( $user );
|
@@ -619,6 +733,9 @@ class RTMedia {
|
|
619 |
return $parent_link;
|
620 |
}
|
621 |
|
|
|
|
|
|
|
622 |
public function init_buddypress_options() {
|
623 |
/**
|
624 |
* BuddyPress Settings
|
@@ -628,7 +745,7 @@ class RTMedia {
|
|
628 |
$group = 0;
|
629 |
if ( isset( $bp_media_options['enable_on_group'] ) && ! empty( $bp_media_options['enable_on_group'] ) ) {
|
630 |
$group = $bp_media_options['enable_on_group'];
|
631 |
-
}
|
632 |
$group = bp_is_active( 'groups' );
|
633 |
}
|
634 |
$this->options['buddypress_enableOnGroup'] = $group;
|
@@ -636,23 +753,24 @@ class RTMedia {
|
|
636 |
$activity = 0;
|
637 |
if ( isset( $bp_media_options['activity_upload'] ) && ! empty( $bp_media_options['activity_upload'] ) ) {
|
638 |
$activity = $bp_media_options['activity_upload'];
|
639 |
-
}
|
640 |
$activity = bp_is_active( 'activity' );
|
641 |
}
|
642 |
$this->options['buddypress_enableOnActivity'] = $activity;
|
643 |
|
644 |
$this->options['buddypress_enableOnProfile'] = 1;
|
645 |
|
646 |
-
|
647 |
rtmedia_update_site_option( 'rtmedia-options', $this->options );
|
648 |
}
|
649 |
|
|
|
|
|
|
|
650 |
public function init_site_options() {
|
651 |
|
652 |
$bp_media_options = rtmedia_get_site_option( 'bp_media_options' );
|
653 |
|
654 |
-
|
655 |
-
|
656 |
$defaults = array(
|
657 |
'general_enableAlbums' => 1,
|
658 |
'general_enableComments' => 0,
|
@@ -667,12 +785,12 @@ class RTMedia {
|
|
667 |
);
|
668 |
|
669 |
foreach ( $this->allowed_types as $type ) {
|
670 |
-
// invalid keys handled in sanitize method
|
671 |
$defaults[ 'allowedTypes_' . $type['name'] . '_enabled' ] = 1;
|
672 |
$defaults[ 'allowedTypes_' . $type['name'] . '_featured' ] = 0;
|
673 |
}
|
674 |
|
675 |
-
|
676 |
foreach ( $this->default_sizes as $type => $type_value ) {
|
677 |
foreach ( $type_value as $size => $size_value ) {
|
678 |
foreach ( $size_value as $dimension => $value ) {
|
@@ -704,7 +822,7 @@ class RTMedia {
|
|
704 |
}
|
705 |
}
|
706 |
|
707 |
-
|
708 |
$defaults['privacy_enabled'] = ( isset( $bp_media_options['privacy_enabled'] ) ) ? $bp_media_options['privacy_enabled'] : 0;
|
709 |
$defaults['privacy_default'] = ( isset( $bp_media_options['default_privacy_level'] ) ) ? $bp_media_options['default_privacy_level'] : 0;
|
710 |
$defaults['privacy_userOverride'] = ( isset( $bp_media_options['privacy_override_enabled'] ) ) ? $bp_media_options['privacy_override_enabled'] : 0;
|
@@ -723,20 +841,19 @@ class RTMedia {
|
|
723 |
*/
|
724 |
public function constants() {
|
725 |
|
726 |
-
|
727 |
if ( ! defined( 'RTMEDIA_IS_INSTALLED' ) ) {
|
728 |
define( 'RTMEDIA_IS_INSTALLED', 1 );
|
729 |
}
|
730 |
|
731 |
-
|
732 |
if ( ! defined( 'RTMEDIA_REQUIRED_BP' ) ) {
|
733 |
define( 'RTMEDIA_REQUIRED_BP', '1.7' );
|
734 |
}
|
735 |
|
736 |
/* Slug Constants for building urls */
|
737 |
|
738 |
-
|
739 |
-
|
740 |
if ( ! defined( 'RTMEDIA_MEDIA_SLUG' ) ) {
|
741 |
define( 'RTMEDIA_MEDIA_SLUG', 'media' );
|
742 |
}
|
@@ -769,17 +886,17 @@ class RTMedia {
|
|
769 |
define( 'RTMEDIA_ALBUM_PLURAL_LABEL', esc_html__( 'Albums', 'buddypress-media' ) );
|
770 |
}
|
771 |
|
772 |
-
|
773 |
if ( ! defined( 'RTMEDIA_UPLOAD_SLUG' ) ) {
|
774 |
define( 'RTMEDIA_UPLOAD_SLUG', 'upload' );
|
775 |
}
|
776 |
|
777 |
-
|
778 |
if ( ! defined( 'RTMEDIA_UPLOAD_LABEL' ) ) {
|
779 |
define( 'RTMEDIA_UPLOAD_LABEL', esc_html__( 'Upload', 'buddypress-media' ) );
|
780 |
}
|
781 |
|
782 |
-
|
783 |
if ( ! defined( 'RTMEDIA_GLOBAL_ALBUM_LABEL' ) ) {
|
784 |
define( 'RTMEDIA_GLOBAL_ALBUM_LABEL', esc_html__( 'Wall Post', 'buddypress-media' ) );
|
785 |
}
|
@@ -787,7 +904,10 @@ class RTMedia {
|
|
787 |
$this->define_type_constants();
|
788 |
}
|
789 |
|
790 |
-
|
|
|
|
|
|
|
791 |
|
792 |
if ( ! isset( $this->allowed_types ) ) {
|
793 |
return;
|
@@ -837,18 +957,18 @@ class RTMedia {
|
|
837 |
|
838 |
/**
|
839 |
* Hooks the plugin into BuddyPress via 'bp_include' action.
|
840 |
-
* Initialises the plugin's
|
841 |
* loads media for Profiles and Groups.
|
842 |
* Creates Admin panels
|
843 |
* Loads accessory functions
|
844 |
*
|
845 |
* @global BPMediaAdmin $bp_media_admin
|
846 |
*/
|
847 |
-
function init() {
|
848 |
-
// set
|
849 |
$this->set_rtmedia_meta_wpdbfix();
|
850 |
|
851 |
-
// rtMedia db upgrade
|
852 |
add_action( 'rt_db_upgrade', array( $this, 'fix_parent_id' ) );
|
853 |
add_action( 'rt_db_upgrade', array( $this, 'fix_privacy' ) );
|
854 |
add_action( 'rt_db_upgrade', array( $this, 'fix_group_media_privacy' ) );
|
@@ -859,11 +979,11 @@ class RTMedia {
|
|
859 |
remove_action( 'rt_db_upgrade', array( $this, 'fix_group_media_privacy' ) );
|
860 |
remove_action( 'rt_db_upgrade', array( $this, 'fix_db_collation' ) );
|
861 |
|
862 |
-
$this->set_allowed_types(); // Define allowed types
|
863 |
-
$this->constants(); // Define constants
|
864 |
$this->redirect_on_change_slug();
|
865 |
-
$this->set_default_sizes(); // set default sizes
|
866 |
-
$this->set_privacy(); // set privacy
|
867 |
|
868 |
/**
|
869 |
* Load options/settings
|
@@ -872,12 +992,10 @@ class RTMedia {
|
|
872 |
|
873 |
/**
|
874 |
* BuddyPress - Media Navigation Tab Inject
|
875 |
-
*
|
876 |
*/
|
877 |
/**
|
878 |
* Load accessory functions
|
879 |
*/
|
880 |
-
|
881 |
$class_construct = array(
|
882 |
'deprecated' => true,
|
883 |
'interaction' => true,
|
@@ -903,7 +1021,7 @@ class RTMedia {
|
|
903 |
$class = 'BPMedia' . ucfirst( $classname );
|
904 |
if ( class_exists( $class ) ) {
|
905 |
if ( true === $global_scope ) {
|
906 |
-
global ${'bp_media_' . $classname};
|
907 |
${'bp_media_' . $classname} = new $class();
|
908 |
} else {
|
909 |
new $class();
|
@@ -927,7 +1045,7 @@ class RTMedia {
|
|
927 |
|
928 |
if ( class_exists( $class ) ) {
|
929 |
if ( true === $global_scope ) {
|
930 |
-
global ${'rtmedia_' . $key};
|
931 |
${'rtmedia_' . $key} = new $class();
|
932 |
} else {
|
933 |
new $class();
|
@@ -935,7 +1053,7 @@ class RTMedia {
|
|
935 |
}
|
936 |
}
|
937 |
|
938 |
-
$this->set_allowed_types(); // Define allowed types
|
939 |
|
940 |
global $rtmedia_buddypress_activity;
|
941 |
$rtmedia_buddypress_activity = new RTMediaBuddyPressActivity();
|
@@ -944,25 +1062,31 @@ class RTMedia {
|
|
944 |
|
945 |
global $rtmedia_ajax;
|
946 |
$rtmedia_ajax = new RTMediaAJAX();
|
947 |
-
//API Classes
|
948 |
global $rtmediajsonapi;
|
949 |
$rtmediajsonapi = new RTMediaJsonApi();
|
950 |
|
951 |
-
if( function_exists( 'rtmedia_enable_comment_media_uplaod' ) ){
|
952 |
rtmedia_enable_comment_media_uplaod();
|
953 |
}
|
954 |
|
955 |
-
do_action( 'bp_media_init' ); // legacy For plugin using this actions
|
956 |
do_action( 'rtmedia_init' );
|
957 |
}
|
958 |
|
959 |
-
|
|
|
|
|
|
|
960 |
global $wpdb;
|
961 |
$media_meta = new RTMediaMeta();
|
962 |
$wpdb->mediameta = $media_meta->model->table_name;
|
963 |
}
|
964 |
|
965 |
-
|
|
|
|
|
|
|
966 |
$old_slugs = rtmedia_get_site_option( 'rtmedia_old_media_slug', false, true );
|
967 |
$current_slugs = rtmedia_get_site_option( 'rtmedia_current_media_slug', false, false );
|
968 |
if ( false === $current_slugs ) {
|
@@ -981,24 +1105,30 @@ class RTMedia {
|
|
981 |
}
|
982 |
|
983 |
/**
|
984 |
-
* Loads translations
|
985 |
*/
|
986 |
-
static
|
987 |
-
function load_translation() {
|
988 |
load_plugin_textdomain( 'buddypress-media', false, basename( RTMEDIA_PATH ) . '/languages/' );
|
989 |
}
|
990 |
|
991 |
-
|
992 |
-
|
|
|
|
|
|
|
|
|
|
|
993 |
$album = new RTMediaAlbum();
|
994 |
$global_album = $album->get_default();
|
995 |
-
|
996 |
-
|
997 |
-
|
998 |
-
|
|
|
|
|
|
|
999 |
}
|
1000 |
-
|
1001 |
-
//**
|
1002 |
global $rtmedia_error;
|
1003 |
if ( isset( $rtmedia_error ) && true === $rtmedia_error ) {
|
1004 |
return false;
|
@@ -1019,7 +1149,12 @@ class RTMedia {
|
|
1019 |
}
|
1020 |
}
|
1021 |
|
1022 |
-
|
|
|
|
|
|
|
|
|
|
|
1023 |
$count = $this->posts_per_page;
|
1024 |
if ( array_key_exists( 'default_count', $this->options ) ) {
|
1025 |
$count = $this->options['default_count'];
|
@@ -1029,8 +1164,15 @@ class RTMedia {
|
|
1029 |
return ( ! $count ) ? 10 : $count;
|
1030 |
}
|
1031 |
|
1032 |
-
|
1033 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1034 |
$path = ( $path ) ? $path : RTMEDIA_PATH . 'index.php';
|
1035 |
$plugin_data = get_plugin_data( $path );
|
1036 |
$plugin_version = $plugin_data['Version'];
|
@@ -1038,9 +1180,12 @@ class RTMedia {
|
|
1038 |
return $plugin_version;
|
1039 |
}
|
1040 |
|
1041 |
-
|
|
|
|
|
|
|
1042 |
$update = new RTDBUpdate( false, RTMEDIA_PATH . 'index.php', RTMEDIA_PATH . 'app/schema/', true );
|
1043 |
-
|
1044 |
if ( ! defined( 'RTMEDIA_VERSION' ) ) {
|
1045 |
define( 'RTMEDIA_VERSION', $update->db_version );
|
1046 |
}
|
@@ -1054,26 +1199,32 @@ class RTMedia {
|
|
1054 |
}
|
1055 |
}
|
1056 |
|
1057 |
-
|
|
|
|
|
|
|
1058 |
global $rtmedia_error;
|
1059 |
$rtmedia_error = true;
|
1060 |
echo "<div class='error'><p><strong>" . esc_html__( 'rtMedia', 'buddypress-media' ) . '</strong>' . esc_html__( ": Can't Create Database table. Please check create table permission.", 'buddypress-media' ) . '</p></div>';
|
1061 |
}
|
1062 |
|
1063 |
-
|
|
|
|
|
|
|
1064 |
global $rtmedia, $bp, $rtmedia_interaction;
|
1065 |
|
1066 |
$bp_template = get_option( '_bp_theme_package_id' );
|
1067 |
|
1068 |
-
wp_enqueue_script( 'rt-mediaelement', RTMEDIA_URL . 'lib/media-element/mediaelement-and-player.min.js', '', RTMEDIA_VERSION );
|
1069 |
wp_enqueue_style( 'rt-mediaelement', RTMEDIA_URL . 'lib/media-element/mediaelementplayer-legacy.min.css', '', RTMEDIA_VERSION );
|
1070 |
wp_enqueue_style( 'rt-mediaelement-wp', RTMEDIA_URL . 'lib/media-element/wp-mediaelement.min.css', '', RTMEDIA_VERSION );
|
1071 |
wp_enqueue_script( 'rt-mediaelement-wp', RTMEDIA_URL . 'lib/media-element/wp-mediaelement.min.js', 'rt-mediaelement', RTMEDIA_VERSION, true );
|
1072 |
|
1073 |
-
// Dashicons: Needs if not loaded by WP
|
1074 |
wp_enqueue_style( 'dashicons' );
|
1075 |
|
1076 |
-
// Dont enqueue rtmedia.min.css if default styles is checked false in rtmedia settings
|
1077 |
$suffix = ( function_exists( 'rtm_get_script_style_suffix' ) ) ? rtm_get_script_style_suffix() : '.min';
|
1078 |
|
1079 |
if ( ! ( isset( $rtmedia->options ) && isset( $rtmedia->options['styles_enabled'] ) && 0 === $rtmedia->options['styles_enabled'] ) ) {
|
@@ -1081,27 +1232,82 @@ class RTMedia {
|
|
1081 |
}
|
1082 |
|
1083 |
if ( '' === $suffix ) {
|
1084 |
-
wp_enqueue_script(
|
1085 |
-
'
|
1086 |
-
'
|
1087 |
-
|
1088 |
-
|
1089 |
-
|
1090 |
-
|
1091 |
-
|
1092 |
-
|
1093 |
-
|
1094 |
-
|
1095 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1096 |
} else {
|
1097 |
-
wp_enqueue_script(
|
1098 |
-
'
|
1099 |
-
'
|
1100 |
-
|
1101 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
1102 |
wp_localize_script( 'rtmedia-main', 'bp_template_pack', $bp_template );
|
1103 |
}
|
1104 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1105 |
wp_localize_script( 'rtmedia-main', 'rtmedia_ajax_url', admin_url( 'admin-ajax.php' ) );
|
1106 |
wp_localize_script( 'rtmedia-main', 'rtmedia_media_slug', RTMEDIA_MEDIA_SLUG );
|
1107 |
wp_localize_script( 'rtmedia-main', 'rtmedia_lightbox_enabled', strval( $this->options['general_enableLightbox'] ) );
|
@@ -1109,44 +1315,43 @@ class RTMedia {
|
|
1109 |
$direct_upload = ( isset( $this->options['general_direct_upload'] ) ? $this->options['general_direct_upload'] : '0' );
|
1110 |
|
1111 |
wp_localize_script( 'rtmedia-main', 'rtmedia_direct_upload_enabled', $direct_upload );
|
1112 |
-
//gallery reload after media upload, by default true
|
1113 |
wp_localize_script( 'rtmedia-main', 'rtmedia_gallery_reload_on_upload', '1' );
|
1114 |
|
1115 |
-
//javascript messages
|
1116 |
-
wp_localize_script( 'rtmedia-magnific', 'rtmedia_load_more',
|
1117 |
-
wp_localize_script( 'rtmedia-main', 'rtmedia_empty_activity_msg',
|
1118 |
-
wp_localize_script( 'rtmedia-main', 'rtmedia_empty_comment_msg',
|
1119 |
-
wp_localize_script( 'rtmedia-main', '
|
1120 |
-
wp_localize_script( 'rtmedia-main', '
|
1121 |
-
wp_localize_script( 'rtmedia-main', '
|
1122 |
-
wp_localize_script( 'rtmedia-main', '
|
1123 |
-
wp_localize_script( 'rtmedia-main', '
|
1124 |
-
wp_localize_script( 'rtmedia-main', '
|
1125 |
-
wp_localize_script( 'rtmedia-main', '
|
1126 |
-
wp_localize_script( 'rtmedia-main', '
|
1127 |
-
wp_localize_script( 'rtmedia-main', '
|
1128 |
-
wp_localize_script( 'rtmedia-main', '
|
1129 |
-
wp_localize_script( 'rtmedia-main', '
|
1130 |
-
wp_localize_script( 'rtmedia-main', '
|
1131 |
-
wp_localize_script( 'rtmedia-main', '
|
1132 |
-
wp_localize_script( 'rtmedia-main', '
|
1133 |
-
wp_localize_script( 'rtmedia-main', '
|
1134 |
-
wp_localize_script( 'rtmedia-main', '
|
1135 |
-
wp_localize_script( 'rtmedia-main', '
|
1136 |
-
wp_localize_script( 'rtmedia-main', '
|
1137 |
-
wp_localize_script( 'rtmedia-main', '
|
1138 |
-
wp_localize_script( 'rtmedia-main', '
|
1139 |
-
wp_localize_script( 'rtmedia-main', '
|
1140 |
-
wp_localize_script( 'rtmedia-main', '
|
1141 |
-
wp_localize_script( 'rtmedia-main', '
|
1142 |
-
wp_localize_script( 'rtmedia-main', '
|
1143 |
-
wp_localize_script( 'rtmedia-main', '
|
1144 |
-
wp_localize_script( 'rtmedia-main', '
|
1145 |
-
wp_localize_script( 'rtmedia-main', '
|
1146 |
-
wp_localize_script( 'rtmedia-main', '
|
1147 |
-
wp_localize_script( 'rtmedia-main', 'rtmedia__show_less', esc_html__( 'Show less', 'buddypress-media' ) );
|
1148 |
wp_localize_script( 'rtmedia-main', 'rtmedia_activity_text_with_attachment', apply_filters( 'rtmedia_required_activity_text_with_attachment', 'disable' ) );
|
1149 |
-
wp_localize_script( 'rtmedia-main', 'rtmedia_delete_uploaded_media',
|
1150 |
wp_localize_script( 'rtmedia-main', 'rtm_wp_version', get_bloginfo( 'version' ) );
|
1151 |
wp_localize_script( 'rtmedia-backbone', 'rMedia_loading_media', RTMEDIA_URL . 'app/assets/admin/img/boxspinner.gif' );
|
1152 |
$rtmedia_media_thumbs = array();
|
@@ -1162,35 +1367,38 @@ class RTMedia {
|
|
1162 |
$rtmedia_media_thumbs = apply_filters( 'rtmedia_add_docs_thumbs', $rtmedia_media_thumbs );
|
1163 |
|
1164 |
wp_localize_script( 'rtmedia-backbone', 'rtmedia_media_thumbs', $rtmedia_media_thumbs );
|
1165 |
-
wp_localize_script( 'rtmedia-backbone', 'rtmedia_set_featured_image_msg',
|
1166 |
-
wp_localize_script( 'rtmedia-backbone', 'rtmedia_unset_featured_image_msg',
|
1167 |
-
wp_localize_script(
|
1168 |
-
'
|
1169 |
-
'
|
1170 |
-
|
1171 |
-
|
1172 |
-
|
1173 |
-
|
|
|
|
|
|
|
|
|
1174 |
$rtmedia_backbone_strings = array(
|
1175 |
'rtm_edit_file_name' => esc_html__( 'Edit File Name', 'buddypress-media' ),
|
1176 |
);
|
1177 |
|
1178 |
-
// Localise fot rtmedia-backcone js
|
1179 |
wp_localize_script( 'rtmedia-backbone', 'bp_template_pack', $bp_template );
|
1180 |
|
1181 |
wp_localize_script( 'rtmedia-backbone', 'rtmedia_backbone_strings', $rtmedia_backbone_strings );
|
1182 |
|
1183 |
-
// Localizing strings for rtMedia.js
|
1184 |
$rtmedia_main_js_strings = array(
|
1185 |
-
'rtmedia_albums'
|
1186 |
'privacy_update_success' => esc_html__( 'Privacy updated successfully.', 'buddypress-media' ),
|
1187 |
-
'privacy_update_error'
|
1188 |
-
'file_delete_success' => esc_html__( 'file deleted successfully.', 'buddypress-media' ),
|
1189 |
);
|
1190 |
|
1191 |
wp_localize_script( 'rtmedia-main', 'rtmedia_main_js_strings', $rtmedia_main_js_strings );
|
1192 |
|
1193 |
-
// Enqueue touchswipe
|
1194 |
wp_enqueue_script( 'rtmedia-touchswipe', RTMEDIA_URL . 'lib/touchswipe/jquery.touchSwipe.min.js', array( 'jquery' ), RTMEDIA_VERSION, true );
|
1195 |
|
1196 |
if ( isset( $rtmedia->options ) && isset( $rtmedia->options['general_masonry_layout'] ) && 1 === intval( $rtmedia->options['general_masonry_layout'] ) ) {
|
@@ -1222,11 +1430,11 @@ class RTMedia {
|
|
1222 |
wp_localize_script( 'rtmedia-backbone', 'rtmedia_bp_enable_activity', '0' );
|
1223 |
}
|
1224 |
|
1225 |
-
wp_localize_script( 'rtmedia-backbone', 'rtmedia_upload_progress_error_message',
|
1226 |
// Added to display error message when all media types upload are disabled.
|
1227 |
-
wp_localize_script( 'rtmedia-backbone', 'rtmedia_media_disabled_error_message',
|
1228 |
|
1229 |
-
// localise media size config
|
1230 |
$media_size_config = array(
|
1231 |
'photo' => array(
|
1232 |
'thumb' => array(
|
@@ -1273,8 +1481,7 @@ class RTMedia {
|
|
1273 |
);
|
1274 |
wp_localize_script( 'rtmedia-main', 'rtmedia_media_size_config', $media_size_config );
|
1275 |
|
1276 |
-
|
1277 |
-
/* rtMedia fot comment media script localize*/
|
1278 |
$request_uri = rtm_get_server_var( 'REQUEST_URI', 'FILTER_SANITIZE_URL' );
|
1279 |
$url = rtmedia_get_upload_url( $request_uri );
|
1280 |
|
@@ -1283,12 +1490,15 @@ class RTMedia {
|
|
1283 |
'runtimes' => 'html5,flash,html4',
|
1284 |
'browse_button' => 'rtmedia-comment-media-upload',
|
1285 |
'container' => 'rtmedia-comment-media-upload-container',
|
1286 |
-
'filters' => apply_filters(
|
|
|
1287 |
array(
|
1288 |
-
|
1289 |
-
|
1290 |
-
|
1291 |
-
|
|
|
|
|
1292 |
'max_file_size' => ( wp_max_upload_size() ) / ( 1024 * 1024 ) . 'M',
|
1293 |
'multipart' => true,
|
1294 |
'urlstream_upload' => true,
|
@@ -1296,37 +1506,44 @@ class RTMedia {
|
|
1296 |
'silverlight_xap_url' => includes_url( 'js/plupload/plupload.silverlight.xap' ),
|
1297 |
'file_data_name' => 'rtmedia_file', // key passed to $_FILE.
|
1298 |
'multi_selection' => false,
|
1299 |
-
'multipart_params' => apply_filters(
|
1300 |
-
'
|
1301 |
-
|
1302 |
-
|
1303 |
-
|
1304 |
-
|
1305 |
-
|
1306 |
-
|
1307 |
-
|
1308 |
-
|
1309 |
-
|
1310 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1311 |
);
|
1312 |
|
1313 |
$params = apply_filters( 'rtmedia_modify_upload_params', $params );
|
1314 |
|
1315 |
-
|
1316 |
global $rtmedia;
|
1317 |
$rtmedia_extns = array();
|
1318 |
foreach ( $rtmedia->allowed_types as $allowed_types_key => $allowed_types_value ) {
|
1319 |
$rtmedia_extns[ $allowed_types_key ] = $allowed_types_value['extn'];
|
1320 |
}
|
1321 |
|
1322 |
-
$rtmedia_disable_media =
|
1323 |
-
|
1324 |
-
if( isset( $rtmedia->options['rtmedia_disable_media_in_commented_media'] ) ){
|
1325 |
$rtmedia_disable_media = $rtmedia->options['rtmedia_disable_media_in_commented_media'];
|
1326 |
}
|
1327 |
wp_localize_script( 'rtmedia-main', 'rtmedia_disable_media_in_commented_media', $rtmedia_disable_media );
|
1328 |
|
1329 |
-
wp_localize_script( 'rtmedia-main', 'rtmedia_disable_media_in_commented_media_text',
|
1330 |
|
1331 |
wp_localize_script( 'rtmedia-backbone', 'rtmedia_exteansions', $rtmedia_extns );
|
1332 |
wp_localize_script( 'rtmedia-backbone', 'rtMedia_update_plupload_comment', $params );
|
@@ -1339,12 +1556,18 @@ class RTMedia {
|
|
1339 |
}
|
1340 |
}
|
1341 |
|
1342 |
-
|
|
|
|
|
|
|
1343 |
remove_action( 'bp_adminbar_menus', 'bp_adminbar_account_menu', 4 );
|
1344 |
}
|
1345 |
|
1346 |
-
|
1347 |
-
|
|
|
|
|
|
|
1348 |
if ( is_user_logged_in() ) {
|
1349 |
$user = get_current_user_id();
|
1350 |
$friends = friends_get_friend_user_ids( $user );
|
@@ -1353,12 +1576,26 @@ class RTMedia {
|
|
1353 |
}
|
1354 |
}
|
1355 |
|
1356 |
-
|
1357 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1358 |
$sizes = $this->unset_bp_media_image_sizes_details( $sizes );
|
1359 |
-
} elseif ( isset( $
|
|
|
|
|
1360 |
$model = new RTMediaModel();
|
1361 |
-
$result = $model->get( array( 'media_id' => intval( wp_unslash( $
|
|
|
1362 |
if ( ! empty( $result ) ) {
|
1363 |
$bp_media_sizes = $this->image_sizes();
|
1364 |
$sizes = array(
|
@@ -1375,7 +1612,14 @@ class RTMedia {
|
|
1375 |
return $sizes;
|
1376 |
}
|
1377 |
|
1378 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1379 |
$custom_sizes = array(
|
1380 |
'rt_media_thumbnail' => 'rtMedia Thumbnail',
|
1381 |
'rt_media_activity_image' => 'rtMedia Activity Image',
|
@@ -1386,10 +1630,23 @@ class RTMedia {
|
|
1386 |
return array_merge( $sizes, $custom_sizes );
|
1387 |
}
|
1388 |
|
1389 |
-
|
1390 |
-
|
1391 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1392 |
$post_type = get_post_field( 'post_type', $parent_id );
|
|
|
1393 |
if ( 'rtmedia_album' === $post_type ) {
|
1394 |
$sizes = array(
|
1395 |
'rt_media_thumbnail',
|
@@ -1408,7 +1665,14 @@ class RTMedia {
|
|
1408 |
return $sizes;
|
1409 |
}
|
1410 |
|
1411 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1412 |
if ( isset( $sizes['rt_media_thumbnail'] ) ) {
|
1413 |
unset( $sizes['rt_media_thumbnail'] );
|
1414 |
}
|
@@ -1425,32 +1689,163 @@ class RTMedia {
|
|
1425 |
return $sizes;
|
1426 |
}
|
1427 |
|
1428 |
-
|
1429 |
-
|
1430 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1431 |
}
|
1432 |
-
|
1433 |
-
|
|
|
|
|
1434 |
}
|
1435 |
-
|
1436 |
-
|
|
|
|
|
1437 |
}
|
1438 |
-
|
1439 |
-
|
|
|
|
|
1440 |
}
|
1441 |
|
1442 |
return $sizes;
|
1443 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1444 |
}
|
1445 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1446 |
function parentlink_global_album( $id ) {
|
1447 |
$global_albums = RTMediaAlbum::get_globals();
|
1448 |
$parent_link = '';
|
|
|
1449 |
if ( is_array( $global_albums ) && '' !== $global_albums ) {
|
1450 |
-
if ( in_array( $id, $global_albums ) && function_exists( 'bp_displayed_user_id' ) ) {
|
1451 |
$disp_user = bp_displayed_user_id();
|
1452 |
$curr_user = get_current_user_id();
|
1453 |
-
if ( $disp_user
|
1454 |
$parent_link = get_rtmedia_user_link( $curr_user );
|
1455 |
} else {
|
1456 |
$parent_link = get_rtmedia_user_link( $disp_user );
|
@@ -1465,39 +1860,47 @@ function parentlink_global_album( $id ) {
|
|
1465 |
return $parent_link;
|
1466 |
}
|
1467 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1468 |
function get_rtmedia_permalink( $id ) {
|
|
|
1469 |
$media_model = new RTMediaModel();
|
1470 |
-
$media
|
1471 |
global $rtmedia_query;
|
1472 |
|
1473 |
-
// Adding filter to get permalink for current blog
|
1474 |
add_filter( 'bp_get_root_domain', 'rtmedia_get_current_blog_url' );
|
1475 |
|
1476 |
if ( ! empty( $media ) && is_object( $media[0] ) && ! isset( $media[0]->context ) ) {
|
1477 |
if ( function_exists( 'bp_get_groups_root_slug' ) && isset( $rtmedia_query->query ) && isset( $rtmedia_query->query['context'] ) && 'group' === $rtmedia_query->query['context'] ) {
|
1478 |
$parent_link = get_rtmedia_group_link( $rtmedia_query->query['context_id'] );
|
1479 |
} else {
|
1480 |
-
// check for global album
|
1481 |
$parent_link = parentlink_global_album( $id );
|
1482 |
if ( '' === $parent_link ) {
|
1483 |
$parent_link = get_rtmedia_user_link( $media[0]->media_author );
|
1484 |
}
|
1485 |
}
|
1486 |
} else {
|
1487 |
-
if ( isset( $media[0]->context )
|
1488 |
$parent_link = get_rtmedia_group_link( $media[0]->context_id );
|
1489 |
} else {
|
1490 |
-
// check for global album
|
1491 |
$parent_link = parentlink_global_album( $id );
|
1492 |
if ( '' === $parent_link && isset( $media[0]->media_author ) ) {
|
1493 |
-
|
1494 |
}
|
1495 |
}
|
1496 |
}
|
1497 |
|
1498 |
$parent_link = trailingslashit( $parent_link );
|
1499 |
|
1500 |
-
// Removing filter so that doesn't affect other calls to this function
|
1501 |
remove_filter( 'bp_get_root_domain', 'rtmedia_get_current_blog_url' );
|
1502 |
|
1503 |
$permalink = trailingslashit( $parent_link . RTMEDIA_MEDIA_SLUG . '/' . $id );
|
@@ -1509,12 +1912,19 @@ function get_rtmedia_permalink( $id ) {
|
|
1509 |
*
|
1510 |
* @param string $permalink The rtmedia's permalink.
|
1511 |
* @param object $media The media in question.
|
1512 |
-
* @param int $id
|
1513 |
*/
|
1514 |
|
1515 |
return apply_filters( 'get_rtmedia_permalink', $permalink, $media, $id );
|
1516 |
}
|
1517 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1518 |
function get_rtmedia_user_link( $id ) {
|
1519 |
if ( function_exists( 'bp_core_get_user_domain' ) ) {
|
1520 |
$parent_link = bp_core_get_user_domain( $id );
|
@@ -1525,6 +1935,14 @@ function get_rtmedia_user_link( $id ) {
|
|
1525 |
return $parent_link;
|
1526 |
}
|
1527 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1528 |
function rtmedia_update_site_option( $option_name, $option_value ) {
|
1529 |
if ( is_multisite() ) {
|
1530 |
return update_option( $option_name, $option_value );
|
@@ -1533,12 +1951,27 @@ function rtmedia_update_site_option( $option_name, $option_value ) {
|
|
1533 |
}
|
1534 |
}
|
1535 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1536 |
function get_rtmedia_group_link( $group_id ) {
|
1537 |
$group = groups_get_group( array( 'group_id' => $group_id ) );
|
1538 |
|
1539 |
return apply_filters( 'rtmedia_get_group_link', bp_get_group_permalink( $group ) );
|
1540 |
}
|
1541 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1542 |
function rtmedia_get_site_option( $option_name, $default = false ) {
|
1543 |
if ( is_multisite() ) {
|
1544 |
$return_val = get_option( $option_name, $default );
|
@@ -1577,25 +2010,30 @@ function rtm_privacy_message_on_website() {
|
|
1577 |
$rtm_privacy_message_options = array(
|
1578 |
'background-color' => 'rgba(0,0,0,0.95)',
|
1579 |
'color' => '#fff',
|
1580 |
-
'position' => 'bottom'
|
1581 |
);
|
1582 |
|
1583 |
$rtm_privacy_message_options = apply_filters( 'rtm_privacy_bar_position', $rtm_privacy_message_options );
|
1584 |
|
1585 |
include_once ABSPATH . 'wp-admin/includes/plugin.php';
|
1586 |
|
1587 |
-
|
1588 |
-
if( ! empty( $options['general_upload_terms_show_pricacy_message'] ) &&
|
1589 |
-
$
|
1590 |
-
$rtm_privacy_message_position = ! empty
|
1591 |
-
$rtm_privacy_message_bgcolor = ! empty
|
1592 |
-
$rtm_privacy_message_color = ! empty
|
1593 |
|
1594 |
$rtm_privacy_style = $rtm_privacy_message_position . '; ' . $rtm_privacy_message_bgcolor . '; ' . $rtm_privacy_message_color . ';';
|
1595 |
|
1596 |
-
|
1597 |
-
|
1598 |
-
|
|
|
|
|
|
|
|
|
|
|
1599 |
}
|
1600 |
add_action( 'wp_footer', 'rtm_privacy_message_on_website' );
|
1601 |
|
@@ -1603,7 +2041,7 @@ add_action( 'wp_footer', 'rtm_privacy_message_on_website' );
|
|
1603 |
* Function to add privacy policy information in WordPress policy section.
|
1604 |
*/
|
1605 |
function rtm_plugin_privacy_information() {
|
1606 |
-
|
1607 |
if ( function_exists( 'wp_add_privacy_policy_content' ) ) {
|
1608 |
ob_start();
|
1609 |
?>
|
@@ -1636,5 +2074,4 @@ add_action( 'admin_init', 'rtm_plugin_privacy_information' );
|
|
1636 |
* using 'bpmedia_media_sizes' hook
|
1637 |
* 3. The excerpts and string sizes can be filtered
|
1638 |
* using 'bpmedia_excerpt_lengths' hook
|
1639 |
-
*
|
1640 |
*/
|
1 |
<?php
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
+
* The main rtMedia Class file.
|
|
|
|
|
4 |
*
|
5 |
* @package rtMedia
|
6 |
* @subpackage Main
|
7 |
*
|
8 |
* @author Faishal <faishal.saiyed@rtcamp.com>
|
9 |
*/
|
10 |
+
|
11 |
+
if ( ! defined( 'ABSPATH' ) ) {
|
12 |
+
exit;
|
13 |
+
}
|
14 |
+
|
15 |
+
/**
|
16 |
+
* The main rtMedia Class. This is where everything starts.
|
17 |
+
*/
|
18 |
class RTMedia {
|
19 |
|
20 |
/**
|
21 |
+
* Default thumbnail url fallback for all media types
|
22 |
+
*
|
23 |
+
* @var string $default_thumbnail
|
24 |
*/
|
25 |
private $default_thumbnail;
|
26 |
|
27 |
/**
|
28 |
+
* Allowed media types array
|
29 |
*
|
30 |
+
* @var array $allowed_types
|
31 |
*/
|
32 |
public $allowed_types;
|
33 |
|
34 |
/**
|
35 |
+
* Array of privacy settings
|
36 |
*
|
37 |
+
* @var array $privacy_settings
|
38 |
*/
|
39 |
public $privacy_settings;
|
40 |
|
41 |
/**
|
42 |
+
* Default media sizes
|
43 |
*
|
44 |
+
* @var array $default_sizes
|
45 |
*/
|
46 |
public $default_sizes;
|
47 |
|
48 |
/**
|
49 |
+
* Default application wide privacy levels
|
50 |
*
|
51 |
+
* @var array $default_privacy
|
52 |
*/
|
53 |
public $default_privacy = array(
|
54 |
'0' => 'Public',
|
58 |
);
|
59 |
|
60 |
/**
|
61 |
+
* Support forum url
|
62 |
*
|
63 |
+
* @var string $support_url
|
64 |
*/
|
65 |
public $support_url = 'https://rtmedia.io/support/';
|
66 |
|
67 |
/**
|
68 |
+
* Number of media items to show in one view.
|
69 |
*
|
70 |
+
* @var int $posts_per_page
|
71 |
*/
|
72 |
public $posts_per_page = 10;
|
73 |
|
74 |
/**
|
75 |
+
* The types of activity BuddyPress Media creates
|
76 |
*
|
77 |
+
* @var array $activity_types
|
78 |
*/
|
79 |
public $activity_types = array(
|
80 |
'media_upload',
|
81 |
'album_updated',
|
82 |
'album_created',
|
83 |
);
|
84 |
+
|
85 |
+
/**
|
86 |
+
* Array of site options.
|
87 |
+
*
|
88 |
+
* @var array $options
|
89 |
+
*/
|
90 |
public $options;
|
91 |
+
|
92 |
+
/**
|
93 |
+
* Render site options.
|
94 |
+
*
|
95 |
+
* @var array $render_options
|
96 |
+
*/
|
97 |
+
public $render_options; // todo:remove if unused.
|
98 |
|
99 |
/**
|
100 |
* Constructs the class
|
117 |
add_action( 'groups_settings_updated', array( $this, 'group_status_reset_cache' ) );
|
118 |
add_action( 'groups_delete_group', array( $this, 'group_status_reset_cache' ) );
|
119 |
|
120 |
+
// Including core functions, actions & filters.
|
121 |
+
include RTMEDIA_PATH . 'app/main/controllers/template/rtmedia-functions.php';
|
122 |
+
include RTMEDIA_PATH . 'app/main/controllers/template/rtmedia-actions.php';
|
123 |
+
include RTMEDIA_PATH . 'app/main/controllers/template/rtmedia-ajax-actions.php';
|
124 |
+
include RTMEDIA_PATH . 'app/main/controllers/template/rtmedia-filters.php';
|
125 |
|
126 |
add_filter( 'intermediate_image_sizes_advanced', array( $this, 'filter_image_sizes_details' ) );
|
127 |
add_filter( 'intermediate_image_sizes', array( $this, 'filter_image_sizes' ) );
|
138 |
delete_transient( 'group_status_' . $group_id );
|
139 |
}
|
140 |
|
141 |
+
/**
|
142 |
+
* Change allowed types for media.
|
143 |
+
*
|
144 |
+
* @param array $options Array of options.
|
145 |
+
*
|
146 |
+
* @return string
|
147 |
+
*/
|
148 |
+
public function filter_allow_mime_type_mu( $options ) {
|
149 |
$allowed_types = array();
|
150 |
$this->allowed_types = apply_filters( 'rtmedia_allowed_types', $this->allowed_types );
|
151 |
foreach ( $this->allowed_types as $type ) {
|
155 |
}
|
156 |
}
|
157 |
}
|
158 |
+
$ext = apply_filters(
|
159 |
+
'rtmedia_plupload_files_filter',
|
160 |
array(
|
161 |
+
array(
|
162 |
+
'title' => esc_html__( 'Media Files', 'buddypress-media' ),
|
163 |
+
'extensions' => implode( ',', $allowed_types ),
|
164 |
+
),
|
165 |
+
)
|
166 |
+
);
|
167 |
$ext_arr = explode( ',', $ext[0]['extensions'] );
|
168 |
$options = trim( $options );
|
169 |
foreach ( $ext_arr as $f_ext ) {
|
175 |
return $options;
|
176 |
}
|
177 |
|
178 |
+
/**
|
179 |
+
* Fix parents ids for global albums.
|
180 |
+
*/
|
181 |
+
public function fix_parent_id() {
|
182 |
$site_global = rtmedia_get_site_option( 'rtmedia-global-albums' );
|
183 |
if ( $site_global && is_array( $site_global ) && isset( $site_global[0] ) ) {
|
184 |
$model = new RTMediaModel();
|
187 |
global $wpdb;
|
188 |
$row = $album_row['result'][0];
|
189 |
if ( isset( $row['media_id'] ) ) {
|
190 |
+
// phpcs:disable WordPress.DB.PreparedSQL.NotPrepared
|
191 |
+
$sql = $wpdb->prepare(
|
192 |
+
"update $wpdb->posts p
|
193 |
left join
|
194 |
$model->table_name r ON ( p.ID = r.media_id and blog_id = %d )
|
195 |
set
|
198 |
p.guid like %s
|
199 |
and (p.post_parent = 0 or p.post_parent is NULL)
|
200 |
and not r.id is NULL
|
201 |
+
and r.media_type <> 'album'",
|
202 |
+
get_current_blog_id(),
|
203 |
+
$row['media_id'],
|
204 |
+
'%/rtMedia/%'
|
205 |
+
);
|
206 |
$wpdb->query( $sql );
|
207 |
+
// phpcs:enable WordPress.DB.PreparedSQL.NotPrepared
|
208 |
}
|
209 |
}
|
210 |
}
|
211 |
}
|
212 |
|
213 |
+
/**
|
214 |
+
* Function to change privacy in rtm_media table.
|
215 |
+
*/
|
216 |
+
public function fix_privacy() {
|
217 |
global $wpdb;
|
218 |
$model = new RTMediaModel();
|
219 |
$update_sql = "UPDATE {$model->table_name} SET privacy = '80' where privacy = '-1' ";
|
220 |
+
$wpdb->query( $update_sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
221 |
}
|
222 |
|
223 |
+
/**
|
224 |
* Update media privacy of the medias having context=group
|
225 |
* update privacy of groups medias according to the privacy of the group 0->public, 20-> private/hidden
|
226 |
*/
|
227 |
+
public function fix_group_media_privacy() {
|
228 |
+
// if buddypress is active and groups are enabled.
|
|
|
229 |
global $wpdb;
|
230 |
$table_exist = false;
|
231 |
if ( $wpdb->query( "SHOW TABLES LIKE '{$wpdb->prefix}bp_groups'" ) ) {
|
234 |
if ( class_exists( 'BuddyPress' ) && $table_exist ) {
|
235 |
$model = new RTMediaModel();
|
236 |
$sql_group = " UPDATE $model->table_name m join {$wpdb->prefix}bp_groups bp on m.context_id = bp.id SET m.privacy = 0 where m.context = 'group' and bp.status = 'public' and m.privacy <> 80 ";
|
237 |
+
$wpdb->query( $sql_group ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
238 |
$sql_group = " UPDATE $model->table_name m join {$wpdb->prefix}bp_groups bp on m.context_id = bp.id SET m.privacy = 20 where m.context = 'group' and ( bp.status = 'private' OR bp.status = 'hidden' ) and m.privacy <> 80 ";
|
239 |
+
$wpdb->query( $sql_group ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
240 |
}
|
241 |
}
|
242 |
|
243 |
+
/**
|
244 |
+
* Function to fix DB collection by altering DB tables character set.
|
245 |
+
*/
|
246 |
+
public function fix_db_collation() {
|
247 |
global $wpdb;
|
248 |
$model = new RTMediaModel();
|
249 |
$interaction_model = new RTMediaInteractionModel();
|
250 |
$update_media_sql = 'ALTER TABLE ' . $model->table_name . ' CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci';
|
251 |
+
$wpdb->query( $update_media_sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
252 |
$update_media_meta_sql = 'ALTER TABLE ' . $wpdb->base_prefix . $model->meta_table_name . ' CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci';
|
253 |
+
$wpdb->query( $update_media_meta_sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
254 |
$update_media_interaction_sql = 'ALTER TABLE ' . $interaction_model->table_name . ' CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci';
|
255 |
+
$wpdb->query( $update_media_interaction_sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
256 |
}
|
257 |
|
258 |
+
/**
|
259 |
+
* Set site options for rtMedia.
|
260 |
+
*/
|
261 |
+
public function set_site_options() {
|
262 |
|
263 |
$rtmedia_options = rtmedia_get_site_option( 'rtmedia-options' );
|
264 |
$bp_media_options = rtmedia_get_site_option( 'bp_media_options' );
|
266 |
if ( false === $rtmedia_options ) {
|
267 |
$this->init_site_options();
|
268 |
} else {
|
269 |
+
// if new options added via filter then it needs to be updated.
|
270 |
$this->options = $rtmedia_options;
|
271 |
}
|
272 |
$this->add_image_sizes();
|
275 |
}
|
276 |
|
277 |
/**
|
278 |
+
* Add filter that is being given in the buddypress plugin which add the JS and CSS for autocomplete
|
279 |
+
*
|
280 |
+
* More details on: http://hookr.io/functions/bp_activity_maybe_load_mentions_scripts/
|
281 |
*
|
282 |
+
* @param bool $rtmedia_options RTMedia options.
|
283 |
+
* @param bool $bp_media_options BuddyPress media options.
|
284 |
*/
|
285 |
public function comment_auto_complete( $rtmedia_options = false, $bp_media_options = false ) {
|
286 |
add_filter( 'bp_activity_maybe_load_mentions_scripts', array( $this, 'rtmedia_bp_activity_maybe_load_mentions_scripts_callback' ), 10001, 2 );
|
287 |
}
|
288 |
|
|
|
289 |
/**
|
290 |
* Always set to true when call on any of the Buddypress Pages
|
291 |
*
|
292 |
+
* @param bool $load_mentions Load mentions script callback.
|
293 |
+
* @param bool $mentions_enabled Weather mentions enabled or not.
|
294 |
*
|
295 |
* @return bool true
|
296 |
*/
|
299 |
return $load_mentions;
|
300 |
}
|
301 |
|
302 |
+
/**
|
303 |
+
* Function to set JPEG image quality.
|
304 |
+
*/
|
305 |
public function set_image_quality() {
|
306 |
add_filter( 'jpeg_quality', array( $this, 'rtmedia_jpeg_quality' ) );
|
307 |
}
|
308 |
|
309 |
+
/**
|
310 |
+
* Function to get JPEG image quality.
|
311 |
+
*
|
312 |
+
* @param int $quality Image quality.
|
313 |
+
*
|
314 |
+
* @return int
|
315 |
+
*/
|
316 |
public function rtmedia_jpeg_quality( $quality ) {
|
317 |
$quality = isset( $this->options['general_jpeg_image_quality'] ) ? $this->options['general_jpeg_image_quality'] : 90;
|
318 |
|
319 |
return $quality;
|
320 |
}
|
321 |
|
322 |
+
/**
|
323 |
+
* Get image sizes for different purposes.
|
324 |
+
*
|
325 |
+
* @return array
|
326 |
+
*/
|
327 |
public function image_sizes() {
|
328 |
$image_sizes = array();
|
329 |
$image_sizes['thumbnail'] = array(
|
350 |
return $image_sizes;
|
351 |
}
|
352 |
|
353 |
+
/**
|
354 |
+
* Add different image sizes.
|
355 |
+
*/
|
356 |
public function add_image_sizes() {
|
357 |
$bp_media_sizes = $this->image_sizes();
|
358 |
add_image_size( 'rt_media_thumbnail', $bp_media_sizes['thumbnail']['width'], $bp_media_sizes['thumbnail']['height'], $bp_media_sizes['thumbnail']['crop'] );
|
362 |
add_action( 'wp_head', array( &$this, 'custom_style_for_image_size' ) );
|
363 |
}
|
364 |
|
365 |
+
/**
|
366 |
+
* Add custom style for image size.
|
367 |
+
*/
|
368 |
+
public function custom_style_for_image_size() {
|
369 |
if ( apply_filters( 'rtmedia_custom_image_style', true ) ) {
|
370 |
?>
|
371 |
<style type="text/css">
|
384 |
}
|
385 |
}
|
386 |
|
387 |
+
/**
|
388 |
+
* Add custom style for activity image size.
|
389 |
+
*/
|
390 |
+
public function custom_style_for_activity_image_size() {
|
391 |
|
392 |
// Get width from rtMedia settings.
|
393 |
+
$width = ( isset( $this->options['defaultSizes_photo_medium_width'] ) ) ? $this->options['defaultSizes_photo_medium_width'] : '0';
|
394 |
// Get height from rtMedia settings.
|
395 |
$height = ( isset( $this->options['defaultSizes_photo_medium_height'] ) ) ? $this->options['defaultSizes_photo_medium_height'] : '0';
|
396 |
|
424 |
}
|
425 |
|
426 |
?>
|
427 |
+
.rtmedia-activity-container ul.rtm-activity-media-list{
|
428 |
+
overflow: auto;
|
429 |
+
}
|
430 |
+
|
431 |
+
div.rtmedia-activity-container ul.rtm-activity-media-list li.media-type-document,
|
432 |
+
div.rtmedia-activity-container ul.rtm-activity-media-list li.media-type-other{
|
433 |
+
margin-left: 0.6em !important;
|
434 |
+
}
|
435 |
+
|
436 |
+
.rtmedia-activity-container li.media-type-video{
|
437 |
+
height: <?php echo esc_attr( $video_height ); ?>px !important;
|
438 |
+
width: <?php echo esc_attr( $video_width ); ?>px !important;
|
439 |
+
}
|
440 |
+
|
441 |
+
.rtmedia-activity-container li.media-type-video div.rtmedia-item-thumbnail,
|
442 |
+
.rtmedia-activity-container li.media-type-photo a{
|
443 |
+
width: 100% !important;
|
444 |
+
height: 98% !important;
|
445 |
+
}
|
446 |
+
|
447 |
+
.rtmedia-activity-container li.media-type-video div.rtmedia-item-thumbnail video{
|
448 |
+
width: 100% !important;
|
449 |
+
height: 100% !important;
|
450 |
+
}
|
451 |
+
|
452 |
+
.rtmedia-activity-container li.media-type-video div.rtmedia-item-thumbnail .mejs-video,
|
453 |
+
.rtmedia-activity-container li.media-type-video div.rtmedia-item-thumbnail .mejs-video video,
|
454 |
+
.rtmedia-activity-container li.media-type-video div.rtmedia-item-thumbnail .mejs-video .mejs-overlay-play{
|
455 |
+
width: 100% !important;
|
456 |
+
height: 100% !important;
|
457 |
+
}
|
458 |
+
|
459 |
+
.rtmedia-activity-container li.media-type-music{
|
460 |
+
width: <?php echo esc_attr( $music_width ); ?>px !important;
|
461 |
+
}
|
462 |
+
|
463 |
+
.rtmedia-activity-container li.media-type-music .rtmedia-item-thumbnail,
|
464 |
+
.rtmedia-activity-container li.media-type-music .rtmedia-item-thumbnail .mejs-audio,
|
465 |
+
.rtmedia-activity-container li.media-type-music .rtmedia-item-thumbnail audio{
|
466 |
+
width: 100% !important;
|
467 |
+
}
|
468 |
+
|
469 |
+
.rtmedia-activity-container li.media-type-photo{
|
470 |
+
width: <?php echo esc_attr( $media_width ); ?> !important;
|
471 |
+
height: <?php echo esc_attr( $media_height ); ?> !important;
|
472 |
+
}
|
473 |
+
|
474 |
+
.rtmedia-activity-container .media-type-photo .rtmedia-item-thumbnail,
|
475 |
+
.rtmedia-activity-container .media-type-photo .rtmedia-item-thumbnail img {
|
476 |
+
width: 100% !important;
|
477 |
+
height: 100% !important;
|
478 |
+
overflow: hidden;
|
479 |
+
}
|
480 |
<?php
|
481 |
global $rtmedia;
|
482 |
+
if ( rtmedia_check_comment_media_allow() && ! rtmedia_check_comment_in_commented_media_allow() ) {
|
483 |
+
?>
|
484 |
#buddypress ul.activity-list li.activity-item .activity-comments ul li form.ac-form .rtmedia-comment-media-upload,#buddypress ul.activity-list li.activity-item .activity-comments ul li form.ac-form .rtmedia-container {
|
485 |
+
display: none !important
|
486 |
}
|
487 |
<?php
|
488 |
}
|
489 |
}
|
490 |
|
491 |
+
/**
|
492 |
+
* Add custom style for gallery image size.
|
493 |
+
*/
|
494 |
+
public function custom_style_for_gallery_image_size() {
|
495 |
// Get width from rtMedia settings.
|
496 |
+
$width = ( isset( $this->options['defaultSizes_photo_thumbnail_width'] ) ) ? $this->options['defaultSizes_photo_thumbnail_width'] : '0';
|
497 |
// Get height from rtMedia settings.
|
498 |
$height = ( isset( $this->options['defaultSizes_photo_thumbnail_height'] ) ) ? $this->options['defaultSizes_photo_thumbnail_height'] : '0';
|
499 |
|
519 |
max-height: <?php echo esc_attr( $media_height ); ?>;
|
520 |
}
|
521 |
.rtmedia-container .rtmedia-list .rtmedia-list-item {
|
522 |
+
width: <?php echo esc_attr( $media_width ); ?>;
|
523 |
}
|
524 |
<?php
|
525 |
}
|
526 |
|
527 |
+
/**
|
528 |
+
* Add custom style for gallery image size masonry.
|
529 |
+
*/
|
530 |
+
public function custom_style_for_gallery_image_size_masonry() {
|
531 |
if ( intval( $this->options['defaultSizes_photo_thumbnail_height'] ) > 0 ) {
|
532 |
?>
|
533 |
.rtmedia-container .rtmedia-list .rtmedia-list-item .rtmedia-item-thumbnail {
|
547 |
/**
|
548 |
* Default allowed media types array
|
549 |
*/
|
550 |
+
public function set_allowed_types() {
|
551 |
$allowed_types = array(
|
552 |
'photo' => array(
|
553 |
'name' => 'photo',
|
578 |
),
|
579 |
);
|
580 |
|
581 |
+
// filter for hooking additional media types.
|
582 |
$allowed_types = apply_filters( 'rtmedia_allowed_types', $allowed_types );
|
583 |
|
584 |
+
// sanitize all the types.
|
585 |
$allowed_types = $this->sanitize_allowed_types( $allowed_types );
|
586 |
|
587 |
+
// set the allowed types property.
|
588 |
$this->allowed_types = $allowed_types;
|
589 |
}
|
590 |
|
591 |
/**
|
592 |
* Sanitize all media sizes after hooking custom media types
|
593 |
*
|
594 |
+
* @param array $allowed_types allowed media types after hooking custom types.
|
595 |
*
|
596 |
* @return array $allowed_types sanitized media types
|
597 |
*/
|
598 |
+
public function sanitize_allowed_types( $allowed_types ) {
|
599 |
+
// check if the array is formatted properly.
|
600 |
if ( ! is_array( $allowed_types ) && count( $allowed_types ) < 1 ) {
|
601 |
return;
|
602 |
}
|
603 |
|
604 |
+
// loop through each type.
|
605 |
foreach ( $allowed_types as $key => &$type ) {
|
606 |
|
607 |
+
if ( ! isset( $type['name'] ) || // check if a name is set.
|
608 |
empty( $type['name'] ) ||
|
609 |
+
// commented this section for playlist // !isset($type['extn']) || // check if file extensions are set.
|
610 |
+
// commented this section for playlist // empty($type['extn']) ||.
|
611 |
strstr( $type['name'], ' ' ) || strstr( $type['name'], '_' )
|
612 |
) {
|
613 |
+
unset( $allowed_types[ $key ] ); // if not unset this type.
|
614 |
continue;
|
615 |
}
|
616 |
$slug = strtoupper( $type['name'] );
|
620 |
if ( defined( 'RTMEDIA_' . $slug . '_PLURAL_LABEL' ) ) {
|
621 |
$type['plural_label'] = constant( 'RTMEDIA_' . $slug . '_PLURAL_LABEL' );
|
622 |
}
|
623 |
+
// if thumbnail is not supplied, use the default thumbnail.
|
624 |
if ( ! isset( $type['thumbnail'] ) || empty( $type['thumbnail'] ) ) {
|
625 |
$type['thumbnail'] = $this->default_thumbnail;
|
626 |
}
|
632 |
/**
|
633 |
* Set the default sizes
|
634 |
*/
|
635 |
+
public function set_default_sizes() {
|
636 |
$this->default_sizes = array(
|
637 |
'photo' => array(
|
638 |
+
'thumbnail' => array(
|
639 |
+
'width' => 150,
|
640 |
+
'height' => 150,
|
641 |
+
'crop' => 1,
|
642 |
+
),
|
643 |
+
'medium' => array(
|
644 |
+
'width' => 320,
|
645 |
+
'height' => 240,
|
646 |
+
'crop' => 1,
|
647 |
+
),
|
648 |
+
'large' => array(
|
649 |
+
'width' => 800,
|
650 |
+
'height' => 0,
|
651 |
+
'crop' => 1,
|
652 |
+
),
|
653 |
),
|
654 |
'video' => array(
|
655 |
+
'activityPlayer' => array(
|
656 |
+
'width' => 320,
|
657 |
+
'height' => 240,
|
658 |
+
),
|
659 |
+
'singlePlayer' => array(
|
660 |
+
'width' => 640,
|
661 |
+
'height' => 480,
|
662 |
+
),
|
663 |
),
|
664 |
'music' => array(
|
665 |
'activityPlayer' => array( 'width' => 320 ),
|
666 |
'singlePlayer' => array( 'width' => 640 ),
|
667 |
),
|
668 |
'featured' => array(
|
669 |
+
'default' => array(
|
670 |
+
'width' => 100,
|
671 |
+
'height' => 100,
|
672 |
+
'crop' => 1,
|
673 |
+
),
|
674 |
),
|
675 |
);
|
676 |
|
680 |
/**
|
681 |
* Set privacy options
|
682 |
*/
|
683 |
+
public function set_privacy() {
|
684 |
|
685 |
$this->privacy_settings = array(
|
686 |
'levels' => array(
|
702 |
*
|
703 |
* @global RTMediaAdmin $rtmedia_admin Class for loading admin screen
|
704 |
*/
|
705 |
+
public function admin_init() {
|
706 |
global $rtmedia_admin;
|
707 |
$rtmedia_admin = new RTMediaAdmin();
|
708 |
}
|
709 |
|
710 |
+
/**
|
711 |
+
* Media screen.
|
712 |
+
*/
|
713 |
+
public function media_screen() {
|
714 |
+
// todo: check if function required.
|
715 |
+
return '';
|
716 |
}
|
717 |
|
718 |
+
/**
|
719 |
+
* Function to get user posts link from given ID.
|
720 |
+
*
|
721 |
+
* @param int $user User id to get link.
|
722 |
+
*
|
723 |
+
* @return string
|
724 |
+
*/
|
725 |
+
public function get_user_link( $user ) {
|
726 |
|
727 |
if ( function_exists( 'bp_core_get_user_domain' ) ) {
|
728 |
$parent_link = bp_core_get_user_domain( $user );
|
733 |
return $parent_link;
|
734 |
}
|
735 |
|
736 |
+
/**
|
737 |
+
* Generate buddypress options.
|
738 |
+
*/
|
739 |
public function init_buddypress_options() {
|
740 |
/**
|
741 |
* BuddyPress Settings
|
745 |
$group = 0;
|
746 |
if ( isset( $bp_media_options['enable_on_group'] ) && ! empty( $bp_media_options['enable_on_group'] ) ) {
|
747 |
$group = $bp_media_options['enable_on_group'];
|
748 |
+
} elseif ( function_exists( 'bp_is_active' ) ) {
|
749 |
$group = bp_is_active( 'groups' );
|
750 |
}
|
751 |
$this->options['buddypress_enableOnGroup'] = $group;
|
753 |
$activity = 0;
|
754 |
if ( isset( $bp_media_options['activity_upload'] ) && ! empty( $bp_media_options['activity_upload'] ) ) {
|
755 |
$activity = $bp_media_options['activity_upload'];
|
756 |
+
} elseif ( function_exists( 'bp_is_active' ) ) {
|
757 |
$activity = bp_is_active( 'activity' );
|
758 |
}
|
759 |
$this->options['buddypress_enableOnActivity'] = $activity;
|
760 |
|
761 |
$this->options['buddypress_enableOnProfile'] = 1;
|
762 |
|
763 |
+
// Last settings updated in options. Update them in DB & after this no other option would be saved in db.
|
764 |
rtmedia_update_site_option( 'rtmedia-options', $this->options );
|
765 |
}
|
766 |
|
767 |
+
/**
|
768 |
+
* Generate rtMedia site options.
|
769 |
+
*/
|
770 |
public function init_site_options() {
|
771 |
|
772 |
$bp_media_options = rtmedia_get_site_option( 'bp_media_options' );
|
773 |
|
|
|
|
|
774 |
$defaults = array(
|
775 |
'general_enableAlbums' => 1,
|
776 |
'general_enableComments' => 0,
|
785 |
);
|
786 |
|
787 |
foreach ( $this->allowed_types as $type ) {
|
788 |
+
// invalid keys handled in sanitize method.
|
789 |
$defaults[ 'allowedTypes_' . $type['name'] . '_enabled' ] = 1;
|
790 |
$defaults[ 'allowedTypes_' . $type['name'] . '_featured' ] = 0;
|
791 |
}
|
792 |
|
793 |
+
// Previous Sizes values from buddypress is migrated.
|
794 |
foreach ( $this->default_sizes as $type => $type_value ) {
|
795 |
foreach ( $type_value as $size => $size_value ) {
|
796 |
foreach ( $size_value as $dimension => $value ) {
|
822 |
}
|
823 |
}
|
824 |
|
825 |
+
// Privacy options.
|
826 |
$defaults['privacy_enabled'] = ( isset( $bp_media_options['privacy_enabled'] ) ) ? $bp_media_options['privacy_enabled'] : 0;
|
827 |
$defaults['privacy_default'] = ( isset( $bp_media_options['default_privacy_level'] ) ) ? $bp_media_options['default_privacy_level'] : 0;
|
828 |
$defaults['privacy_userOverride'] = ( isset( $bp_media_options['privacy_override_enabled'] ) ) ? $bp_media_options['privacy_override_enabled'] : 0;
|
841 |
*/
|
842 |
public function constants() {
|
843 |
|
844 |
+
// If the plugin is installed.
|
845 |
if ( ! defined( 'RTMEDIA_IS_INSTALLED' ) ) {
|
846 |
define( 'RTMEDIA_IS_INSTALLED', 1 );
|
847 |
}
|
848 |
|
849 |
+
// Required Version.
|
850 |
if ( ! defined( 'RTMEDIA_REQUIRED_BP' ) ) {
|
851 |
define( 'RTMEDIA_REQUIRED_BP', '1.7' );
|
852 |
}
|
853 |
|
854 |
/* Slug Constants for building urls */
|
855 |
|
856 |
+
// Media slugs.
|
|
|
857 |
if ( ! defined( 'RTMEDIA_MEDIA_SLUG' ) ) {
|
858 |
define( 'RTMEDIA_MEDIA_SLUG', 'media' );
|
859 |
}
|
886 |
define( 'RTMEDIA_ALBUM_PLURAL_LABEL', esc_html__( 'Albums', 'buddypress-media' ) );
|
887 |
}
|
888 |
|
889 |
+
// Upload slug.
|
890 |
if ( ! defined( 'RTMEDIA_UPLOAD_SLUG' ) ) {
|
891 |
define( 'RTMEDIA_UPLOAD_SLUG', 'upload' );
|
892 |
}
|
893 |
|
894 |
+
// Upload slug.
|
895 |
if ( ! defined( 'RTMEDIA_UPLOAD_LABEL' ) ) {
|
896 |
define( 'RTMEDIA_UPLOAD_LABEL', esc_html__( 'Upload', 'buddypress-media' ) );
|
897 |
}
|
898 |
|
899 |
+
// Global Album/Wall Post.
|
900 |
if ( ! defined( 'RTMEDIA_GLOBAL_ALBUM_LABEL' ) ) {
|
901 |
define( 'RTMEDIA_GLOBAL_ALBUM_LABEL', esc_html__( 'Wall Post', 'buddypress-media' ) );
|
902 |
}
|
904 |
$this->define_type_constants();
|
905 |
}
|
906 |
|
907 |
+
/**
|
908 |
+
* Define rtMedia allowed media type constants.
|
909 |
+
*/
|
910 |
+
public function define_type_constants() {
|
911 |
|
912 |
if ( ! isset( $this->allowed_types ) ) {
|
913 |
return;
|
957 |
|
958 |
/**
|
959 |
* Hooks the plugin into BuddyPress via 'bp_include' action.
|
960 |
+
* Initialises the plugin's functionality, options,
|
961 |
* loads media for Profiles and Groups.
|
962 |
* Creates Admin panels
|
963 |
* Loads accessory functions
|
964 |
*
|
965 |
* @global BPMediaAdmin $bp_media_admin
|
966 |
*/
|
967 |
+
public function init() {
|
968 |
+
// set meta table in $wpdb.
|
969 |
$this->set_rtmedia_meta_wpdbfix();
|
970 |
|
971 |
+
// rtMedia db upgrade.
|
972 |
add_action( 'rt_db_upgrade', array( $this, 'fix_parent_id' ) );
|
973 |
add_action( 'rt_db_upgrade', array( $this, 'fix_privacy' ) );
|
974 |
add_action( 'rt_db_upgrade', array( $this, 'fix_group_media_privacy' ) );
|
979 |
remove_action( 'rt_db_upgrade', array( $this, 'fix_group_media_privacy' ) );
|
980 |
remove_action( 'rt_db_upgrade', array( $this, 'fix_db_collation' ) );
|
981 |
|
982 |
+
$this->set_allowed_types(); // Define allowed types.
|
983 |
+
$this->constants(); // Define constants.
|
984 |
$this->redirect_on_change_slug();
|
985 |
+
$this->set_default_sizes(); // set default sizes.
|
986 |
+
$this->set_privacy(); // set privacy.
|
987 |
|
988 |
/**
|
989 |
* Load options/settings
|
992 |
|
993 |
/**
|
994 |
* BuddyPress - Media Navigation Tab Inject
|
|
|
995 |
*/
|
996 |
/**
|
997 |
* Load accessory functions
|
998 |
*/
|
|
|
999 |
$class_construct = array(
|
1000 |
'deprecated' => true,
|
1001 |
'interaction' => true,
|
1021 |
$class = 'BPMedia' . ucfirst( $classname );
|
1022 |
if ( class_exists( $class ) ) {
|
1023 |
if ( true === $global_scope ) {
|
1024 |
+
global ${'bp_media_' . $classname}; // phpcs:ignore PHPCompatibility.Variables.ForbiddenGlobalVariableVariable.NonBareVariableFound
|
1025 |
${'bp_media_' . $classname} = new $class();
|
1026 |
} else {
|
1027 |
new $class();
|
1045 |
|
1046 |
if ( class_exists( $class ) ) {
|
1047 |
if ( true === $global_scope ) {
|
1048 |
+
global ${'rtmedia_' . $key}; // phpcs:ignore PHPCompatibility.Variables.ForbiddenGlobalVariableVariable.NonBareVariableFound
|
1049 |
${'rtmedia_' . $key} = new $class();
|
1050 |
} else {
|
1051 |
new $class();
|
1053 |
}
|
1054 |
}
|
1055 |
|
1056 |
+
$this->set_allowed_types(); // Define allowed types.
|
1057 |
|
1058 |
global $rtmedia_buddypress_activity;
|
1059 |
$rtmedia_buddypress_activity = new RTMediaBuddyPressActivity();
|
1062 |
|
1063 |
global $rtmedia_ajax;
|
1064 |
$rtmedia_ajax = new RTMediaAJAX();
|
1065 |
+
// API Classes.
|
1066 |
global $rtmediajsonapi;
|
1067 |
$rtmediajsonapi = new RTMediaJsonApi();
|
1068 |
|
1069 |
+
if ( function_exists( 'rtmedia_enable_comment_media_uplaod' ) ) {
|
1070 |
rtmedia_enable_comment_media_uplaod();
|
1071 |
}
|
1072 |
|
1073 |
+
do_action( 'bp_media_init' ); // legacy For plugin using this actions.
|
1074 |
do_action( 'rtmedia_init' );
|
1075 |
}
|
1076 |
|
1077 |
+
/**
|
1078 |
+
* Set rtMedia meta as mediameta for wpdb query.
|
1079 |
+
*/
|
1080 |
+
public function set_rtmedia_meta_wpdbfix() {
|
1081 |
global $wpdb;
|
1082 |
$media_meta = new RTMediaMeta();
|
1083 |
$wpdb->mediameta = $media_meta->model->table_name;
|
1084 |
}
|
1085 |
|
1086 |
+
/**
|
1087 |
+
* Update option for rtMedia slug change.
|
1088 |
+
*/
|
1089 |
+
public function redirect_on_change_slug() {
|
1090 |
$old_slugs = rtmedia_get_site_option( 'rtmedia_old_media_slug', false, true );
|
1091 |
$current_slugs = rtmedia_get_site_option( 'rtmedia_current_media_slug', false, false );
|
1092 |
if ( false === $current_slugs ) {
|
1105 |
}
|
1106 |
|
1107 |
/**
|
1108 |
+
* Loads translations.
|
1109 |
*/
|
1110 |
+
public static function load_translation() {
|
|
|
1111 |
load_plugin_textdomain( 'buddypress-media', false, basename( RTMEDIA_PATH ) . '/languages/' );
|
1112 |
}
|
1113 |
|
1114 |
+
/**
|
1115 |
+
* Check default global album,.
|
1116 |
+
*
|
1117 |
+
* @return bool
|
1118 |
+
*/
|
1119 |
+
public function check_global_album() {
|
1120 |
+
// todo: Nonce required.
|
1121 |
$album = new RTMediaAlbum();
|
1122 |
$global_album = $album->get_default();
|
1123 |
+
|
1124 |
+
$action = sanitize_text_field( filter_input( INPUT_POST, 'action', FILTER_SANITIZE_STRING ) );
|
1125 |
+
$mode = sanitize_text_field( filter_input( INPUT_POST, 'mode', FILTER_SANITIZE_STRING ) );
|
1126 |
+
|
1127 |
+
// Hack for plupload default name.
|
1128 |
+
if ( ! empty( $action ) && ! empty( $mode ) && 'file_upload' === $mode ) {
|
1129 |
+
unset( $_POST['name'] ); // phpcs:ignore WordPress.Security.NonceVerification.NoNonceVerification
|
1130 |
}
|
1131 |
+
|
|
|
1132 |
global $rtmedia_error;
|
1133 |
if ( isset( $rtmedia_error ) && true === $rtmedia_error ) {
|
1134 |
return false;
|
1149 |
}
|
1150 |
}
|
1151 |
|
1152 |
+
/**
|
1153 |
+
* Get default post per page count.
|
1154 |
+
*
|
1155 |
+
* @return int
|
1156 |
+
*/
|
1157 |
+
public function default_count() {
|
1158 |
$count = $this->posts_per_page;
|
1159 |
if ( array_key_exists( 'default_count', $this->options ) ) {
|
1160 |
$count = $this->options['default_count'];
|
1164 |
return ( ! $count ) ? 10 : $count;
|
1165 |
}
|
1166 |
|
1167 |
+
/**
|
1168 |
+
* Function to get plugin version.
|
1169 |
+
*
|
1170 |
+
* @param string $path Plugin path.
|
1171 |
+
*
|
1172 |
+
* @return mixed
|
1173 |
+
*/
|
1174 |
+
public static function plugin_get_version( $path = null ) {
|
1175 |
+
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
1176 |
$path = ( $path ) ? $path : RTMEDIA_PATH . 'index.php';
|
1177 |
$plugin_data = get_plugin_data( $path );
|
1178 |
$plugin_version = $plugin_data['Version'];
|
1180 |
return $plugin_version;
|
1181 |
}
|
1182 |
|
1183 |
+
/**
|
1184 |
+
* Function to update DB for rtMedia update.
|
1185 |
+
*/
|
1186 |
+
public function update_db() {
|
1187 |
$update = new RTDBUpdate( false, RTMEDIA_PATH . 'index.php', RTMEDIA_PATH . 'app/schema/', true );
|
1188 |
+
// Current Version.
|
1189 |
if ( ! defined( 'RTMEDIA_VERSION' ) ) {
|
1190 |
define( 'RTMEDIA_VERSION', $update->db_version );
|
1191 |
}
|
1199 |
}
|
1200 |
}
|
1201 |
|
1202 |
+
/**
|
1203 |
+
* Display error notice for DB table creation failure.
|
1204 |
+
*/
|
1205 |
+
public function create_table_error_notice() {
|
1206 |
global $rtmedia_error;
|
1207 |
$rtmedia_error = true;
|
1208 |
echo "<div class='error'><p><strong>" . esc_html__( 'rtMedia', 'buddypress-media' ) . '</strong>' . esc_html__( ": Can't Create Database table. Please check create table permission.", 'buddypress-media' ) . '</p></div>';
|
1209 |
}
|
1210 |
|
1211 |
+
/**
|
1212 |
+
* Enqueue scripts and styles for rtMedia.
|
1213 |
+
*/
|
1214 |
+
public function enqueue_scripts_styles() {
|
1215 |
global $rtmedia, $bp, $rtmedia_interaction;
|
1216 |
|
1217 |
$bp_template = get_option( '_bp_theme_package_id' );
|
1218 |
|
1219 |
+
wp_enqueue_script( 'rt-mediaelement', RTMEDIA_URL . 'lib/media-element/mediaelement-and-player.min.js', '', RTMEDIA_VERSION, true );
|
1220 |
wp_enqueue_style( 'rt-mediaelement', RTMEDIA_URL . 'lib/media-element/mediaelementplayer-legacy.min.css', '', RTMEDIA_VERSION );
|
1221 |
wp_enqueue_style( 'rt-mediaelement-wp', RTMEDIA_URL . 'lib/media-element/wp-mediaelement.min.css', '', RTMEDIA_VERSION );
|
1222 |
wp_enqueue_script( 'rt-mediaelement-wp', RTMEDIA_URL . 'lib/media-element/wp-mediaelement.min.js', 'rt-mediaelement', RTMEDIA_VERSION, true );
|
1223 |
|
1224 |
+
// Dashicons: Needs if not loaded by WP.
|
1225 |
wp_enqueue_style( 'dashicons' );
|
1226 |
|
1227 |
+
// Dont enqueue rtmedia.min.css if default styles is checked false in rtmedia settings.
|
1228 |
$suffix = ( function_exists( 'rtm_get_script_style_suffix' ) ) ? rtm_get_script_style_suffix() : '.min';
|
1229 |
|
1230 |
if ( ! ( isset( $rtmedia->options ) && isset( $rtmedia->options['styles_enabled'] ) && 0 === $rtmedia->options['styles_enabled'] ) ) {
|
1232 |
}
|
1233 |
|
1234 |
if ( '' === $suffix ) {
|
1235 |
+
wp_enqueue_script(
|
1236 |
+
'rtmedia-magnific-popup',
|
1237 |
+
RTMEDIA_URL . 'app/assets/js/vendors/magnific-popup.js',
|
1238 |
+
array(
|
1239 |
+
'jquery',
|
1240 |
+
'rt-mediaelement-wp',
|
1241 |
+
),
|
1242 |
+
RTMEDIA_VERSION,
|
1243 |
+
true
|
1244 |
+
);
|
1245 |
+
wp_enqueue_script(
|
1246 |
+
'rtmedia-admin-tabs',
|
1247 |
+
RTMEDIA_URL . 'app/assets/admin/js/vendors/tabs.js',
|
1248 |
+
array(
|
1249 |
+
'jquery',
|
1250 |
+
'rt-mediaelement-wp',
|
1251 |
+
),
|
1252 |
+
RTMEDIA_VERSION,
|
1253 |
+
true
|
1254 |
+
);
|
1255 |
+
wp_enqueue_script(
|
1256 |
+
'rtmedia-main',
|
1257 |
+
RTMEDIA_URL . 'app/assets/js/rtMedia.js',
|
1258 |
+
array(
|
1259 |
+
'jquery',
|
1260 |
+
'rt-mediaelement-wp',
|
1261 |
+
),
|
1262 |
+
RTMEDIA_VERSION,
|
1263 |
+
true
|
1264 |
+
);
|
1265 |
} else {
|
1266 |
+
wp_enqueue_script(
|
1267 |
+
'rtmedia-main',
|
1268 |
+
RTMEDIA_URL . 'app/assets/js/rtmedia.min.js',
|
1269 |
+
array(
|
1270 |
+
'jquery',
|
1271 |
+
'rt-mediaelement-wp',
|
1272 |
+
),
|
1273 |
+
RTMEDIA_VERSION,
|
1274 |
+
true
|
1275 |
+
);
|
1276 |
+
// localize for rtmedia js.
|
1277 |
wp_localize_script( 'rtmedia-main', 'bp_template_pack', $bp_template );
|
1278 |
}
|
1279 |
|
1280 |
+
$media_delete_confirmation_msg = __( 'Are you sure you want to delete this media?', 'buddypress-media' );
|
1281 |
+
$media_delete_success_msg = __( 'Media file deleted successfully.', 'buddypress-media' );
|
1282 |
+
|
1283 |
+
/**
|
1284 |
+
* Media deletion confirmation message.
|
1285 |
+
*
|
1286 |
+
* The added filter `rtmedia_delete_prompt_message` helps in modifying the user consent message before proceeding towards deleting the media.
|
1287 |
+
*
|
1288 |
+
* @param string $media_delete_confirmation_msg Holds the actual confirmation message.
|
1289 |
+
*/
|
1290 |
+
$media_delete_confirmation = apply_filters( 'rtmedia_delete_prompt_message', $media_delete_confirmation_msg );
|
1291 |
+
|
1292 |
+
/**
|
1293 |
+
* Media deletion success message.
|
1294 |
+
*
|
1295 |
+
* The added filter `rtmedia_media_delete_success_message` helps in modifying the success message that pops us after the media is deleted.
|
1296 |
+
*
|
1297 |
+
* @param string $media_delete_success_msg Holds the actual success message.
|
1298 |
+
*/
|
1299 |
+
$media_delete_success = apply_filters( 'rtmedia_media_delete_success_message', $media_delete_success_msg );
|
1300 |
+
|
1301 |
+
wp_localize_script(
|
1302 |
+
'rtmedia-main',
|
1303 |
+
'RTMedia_Main_JS',
|
1304 |
+
array(
|
1305 |
+
'media_delete_confirmation' => $media_delete_confirmation,
|
1306 |
+
'rtmedia_ajaxurl' => admin_url( 'admin-ajax.php' ),
|
1307 |
+
'media_delete_success' => $media_delete_success,
|
1308 |
+
)
|
1309 |
+
);
|
1310 |
+
|
1311 |
wp_localize_script( 'rtmedia-main', 'rtmedia_ajax_url', admin_url( 'admin-ajax.php' ) );
|
1312 |
wp_localize_script( 'rtmedia-main', 'rtmedia_media_slug', RTMEDIA_MEDIA_SLUG );
|
1313 |
wp_localize_script( 'rtmedia-main', 'rtmedia_lightbox_enabled', strval( $this->options['general_enableLightbox'] ) );
|
1315 |
$direct_upload = ( isset( $this->options['general_direct_upload'] ) ? $this->options['general_direct_upload'] : '0' );
|
1316 |
|
1317 |
wp_localize_script( 'rtmedia-main', 'rtmedia_direct_upload_enabled', $direct_upload );
|
1318 |
+
// gallery reload after media upload, by default true.
|
1319 |
wp_localize_script( 'rtmedia-main', 'rtmedia_gallery_reload_on_upload', '1' );
|
1320 |
|
1321 |
+
// javascript messages.
|
1322 |
+
wp_localize_script( 'rtmedia-magnific', 'rtmedia_load_more', __( 'Loading media', 'buddypress-media' ) );
|
1323 |
+
wp_localize_script( 'rtmedia-main', 'rtmedia_empty_activity_msg', __( 'Please enter some content to post.', 'buddypress-media' ) );
|
1324 |
+
wp_localize_script( 'rtmedia-main', 'rtmedia_empty_comment_msg', __( 'Empty comment is not allowed.', 'buddypress-media' ) );
|
1325 |
+
wp_localize_script( 'rtmedia-main', 'rtmedia_media_comment_delete_confirmation', __( 'Are you sure you want to delete this comment?', 'buddypress-media' ) );
|
1326 |
+
wp_localize_script( 'rtmedia-main', 'rtmedia_album_delete_confirmation', __( 'Are you sure you want to delete this Album?', 'buddypress-media' ) );
|
1327 |
+
wp_localize_script( 'rtmedia-main', 'rtmedia_drop_media_msg', __( 'Drop files here', 'buddypress-media' ) );
|
1328 |
+
wp_localize_script( 'rtmedia-main', 'rtmedia_album_created_msg', ' ' . __( 'album created successfully.', 'buddypress-media' ) );
|
1329 |
+
wp_localize_script( 'rtmedia-main', 'rtmedia_something_wrong_msg', __( 'Something went wrong. Please try again.', 'buddypress-media' ) );
|
1330 |
+
wp_localize_script( 'rtmedia-main', 'rtmedia_empty_album_name_msg', __( 'Enter an album name.', 'buddypress-media' ) );
|
1331 |
+
wp_localize_script( 'rtmedia-main', 'rtmedia_max_file_msg', __( 'Max file Size Limit : ', 'buddypress-media' ) );
|
1332 |
+
wp_localize_script( 'rtmedia-main', 'rtmedia_allowed_file_formats', __( 'Allowed File Formats', 'buddypress-media' ) );
|
1333 |
+
wp_localize_script( 'rtmedia-main', 'rtmedia_select_all_visible', __( 'Select All Visible', 'buddypress-media' ) );
|
1334 |
+
wp_localize_script( 'rtmedia-main', 'rtmedia_unselect_all_visible', __( 'Unselect All Visible', 'buddypress-media' ) );
|
1335 |
+
wp_localize_script( 'rtmedia-main', 'rtmedia_no_media_selected', __( 'Please select some media.', 'buddypress-media' ) );
|
1336 |
+
wp_localize_script( 'rtmedia-main', 'rtmedia_selected_media_delete_confirmation', __( 'Are you sure you want to delete the selected media?', 'buddypress-media' ) );
|
1337 |
+
wp_localize_script( 'rtmedia-main', 'rtmedia_selected_media_move_confirmation', __( 'Are you sure you want to move the selected media?', 'buddypress-media' ) );
|
1338 |
+
wp_localize_script( 'rtmedia-main', 'rtmedia_waiting_msg', __( 'Waiting', 'buddypress-media' ) );
|
1339 |
+
wp_localize_script( 'rtmedia-main', 'rtmedia_uploaded_msg', __( 'Uploaded', 'buddypress-media' ) );
|
1340 |
+
wp_localize_script( 'rtmedia-main', 'rtmedia_uploading_msg', __( 'Uploading', 'buddypress-media' ) );
|
1341 |
+
wp_localize_script( 'rtmedia-main', 'rtmedia_upload_failed_msg', __( 'Failed', 'buddypress-media' ) );
|
1342 |
+
wp_localize_script( 'rtmedia-main', 'rtmedia_close', __( 'Close', 'buddypress-media' ) );
|
1343 |
+
wp_localize_script( 'rtmedia-main', 'rtmedia_edit', __( 'Edit', 'buddypress-media' ) );
|
1344 |
+
wp_localize_script( 'rtmedia-main', 'rtmedia_delete', __( 'Delete', 'buddypress-media' ) );
|
1345 |
+
wp_localize_script( 'rtmedia-main', 'rtmedia_edit_media', __( 'Edit Media', 'buddypress-media' ) );
|
1346 |
+
wp_localize_script( 'rtmedia-main', 'rtmedia_remove_from_queue', __( 'Remove from queue', 'buddypress-media' ) );
|
1347 |
+
wp_localize_script( 'rtmedia-main', 'rtmedia_add_more_files_msg', __( 'Add more files', 'buddypress-media' ) );
|
1348 |
+
wp_localize_script( 'rtmedia-main', 'rtmedia_file_extension_error_msg', __( 'File not supported', 'buddypress-media' ) );
|
1349 |
+
wp_localize_script( 'rtmedia-main', 'rtmedia_more', __( 'more', 'buddypress-media' ) );
|
1350 |
+
wp_localize_script( 'rtmedia-main', 'rtmedia_less', __( 'less', 'buddypress-media' ) );
|
1351 |
+
wp_localize_script( 'rtmedia-main', 'rtmedia_read_more', __( 'Read more', 'buddypress-media' ) );
|
1352 |
+
wp_localize_script( 'rtmedia-main', 'rtmedia__show_less', __( 'Show less', 'buddypress-media' ) );
|
|
|
1353 |
wp_localize_script( 'rtmedia-main', 'rtmedia_activity_text_with_attachment', apply_filters( 'rtmedia_required_activity_text_with_attachment', 'disable' ) );
|
1354 |
+
wp_localize_script( 'rtmedia-main', 'rtmedia_delete_uploaded_media', __( 'This media is uploaded. Are you sure you want to delete this media?', 'buddypress-media' ) );
|
1355 |
wp_localize_script( 'rtmedia-main', 'rtm_wp_version', get_bloginfo( 'version' ) );
|
1356 |
wp_localize_script( 'rtmedia-backbone', 'rMedia_loading_media', RTMEDIA_URL . 'app/assets/admin/img/boxspinner.gif' );
|
1357 |
$rtmedia_media_thumbs = array();
|
1367 |
$rtmedia_media_thumbs = apply_filters( 'rtmedia_add_docs_thumbs', $rtmedia_media_thumbs );
|
1368 |
|
1369 |
wp_localize_script( 'rtmedia-backbone', 'rtmedia_media_thumbs', $rtmedia_media_thumbs );
|
1370 |
+
wp_localize_script( 'rtmedia-backbone', 'rtmedia_set_featured_image_msg', __( 'Featured media set successfully.', 'buddypress-media' ) );
|
1371 |
+
wp_localize_script( 'rtmedia-backbone', 'rtmedia_unset_featured_image_msg', __( 'Featured media removed successfully.', 'buddypress-media' ) );
|
1372 |
+
wp_localize_script(
|
1373 |
+
'rtmedia-backbone',
|
1374 |
+
'rtmedia_edit_media_info_upload',
|
1375 |
+
array(
|
1376 |
+
'title' => esc_html__( 'Title:', 'buddypress-media' ),
|
1377 |
+
'description' => esc_html__( 'Description:', 'buddypress-media' ),
|
1378 |
+
)
|
1379 |
+
);
|
1380 |
+
wp_localize_script( 'rtmedia-backbone', 'rtmedia_no_media_found', __( 'Oops !! There\'s no media found for the request !!', 'buddypress-media' ) );
|
1381 |
+
|
1382 |
+
// Localizing strings for rtMedia.backbone.js.
|
1383 |
$rtmedia_backbone_strings = array(
|
1384 |
'rtm_edit_file_name' => esc_html__( 'Edit File Name', 'buddypress-media' ),
|
1385 |
);
|
1386 |
|
1387 |
+
// Localise fot rtmedia-backcone js.
|
1388 |
wp_localize_script( 'rtmedia-backbone', 'bp_template_pack', $bp_template );
|
1389 |
|
1390 |
wp_localize_script( 'rtmedia-backbone', 'rtmedia_backbone_strings', $rtmedia_backbone_strings );
|
1391 |
|
1392 |
+
// Localizing strings for rtMedia.js.
|
1393 |
$rtmedia_main_js_strings = array(
|
1394 |
+
'rtmedia_albums' => esc_html__( 'Albums', 'buddypress-media' ),
|
1395 |
'privacy_update_success' => esc_html__( 'Privacy updated successfully.', 'buddypress-media' ),
|
1396 |
+
'privacy_update_error' => esc_html__( 'Couldn\'t change privacy, please try again.', 'buddypress-media' ),
|
|
|
1397 |
);
|
1398 |
|
1399 |
wp_localize_script( 'rtmedia-main', 'rtmedia_main_js_strings', $rtmedia_main_js_strings );
|
1400 |
|
1401 |
+
// Enqueue touchswipe.
|
1402 |
wp_enqueue_script( 'rtmedia-touchswipe', RTMEDIA_URL . 'lib/touchswipe/jquery.touchSwipe.min.js', array( 'jquery' ), RTMEDIA_VERSION, true );
|
1403 |
|
1404 |
if ( isset( $rtmedia->options ) && isset( $rtmedia->options['general_masonry_layout'] ) && 1 === intval( $rtmedia->options['general_masonry_layout'] ) ) {
|
1430 |
wp_localize_script( 'rtmedia-backbone', 'rtmedia_bp_enable_activity', '0' );
|
1431 |
}
|
1432 |
|
1433 |
+
wp_localize_script( 'rtmedia-backbone', 'rtmedia_upload_progress_error_message', __( 'There are some uploads in progress. Do you want to cancel them?', 'buddypress-media' ) );
|
1434 |
// Added to display error message when all media types upload are disabled.
|
1435 |
+
wp_localize_script( 'rtmedia-backbone', 'rtmedia_media_disabled_error_message', __( 'Media upload is disabled. Please Enable at least one media type to proceed.', 'buddypress-media' ) );
|
1436 |
|
1437 |
+
// localise media size config.
|
1438 |
$media_size_config = array(
|
1439 |
'photo' => array(
|
1440 |
'thumb' => array(
|
1481 |
);
|
1482 |
wp_localize_script( 'rtmedia-main', 'rtmedia_media_size_config', $media_size_config );
|
1483 |
|
1484 |
+
// rtMedia fot comment media script localize.
|
|
|
1485 |
$request_uri = rtm_get_server_var( 'REQUEST_URI', 'FILTER_SANITIZE_URL' );
|
1486 |
$url = rtmedia_get_upload_url( $request_uri );
|
1487 |
|
1490 |
'runtimes' => 'html5,flash,html4',
|
1491 |
'browse_button' => 'rtmedia-comment-media-upload',
|
1492 |
'container' => 'rtmedia-comment-media-upload-container',
|
1493 |
+
'filters' => apply_filters(
|
1494 |
+
'rtmedia_plupload_files_filter',
|
1495 |
array(
|
1496 |
+
array(
|
1497 |
+
'title' => esc_html__( 'Media Files', 'buddypress-media' ),
|
1498 |
+
'extensions' => get_rtmedia_allowed_upload_type(),
|
1499 |
+
),
|
1500 |
+
)
|
1501 |
+
),
|
1502 |
'max_file_size' => ( wp_max_upload_size() ) / ( 1024 * 1024 ) . 'M',
|
1503 |
'multipart' => true,
|
1504 |
'urlstream_upload' => true,
|
1506 |
'silverlight_xap_url' => includes_url( 'js/plupload/plupload.silverlight.xap' ),
|
1507 |
'file_data_name' => 'rtmedia_file', // key passed to $_FILE.
|
1508 |
'multi_selection' => false,
|
1509 |
+
'multipart_params' => apply_filters( // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
|
1510 |
+
'rtmedia-multi-params',
|
1511 |
+
array(
|
1512 |
+
'redirect' => 'no',
|
1513 |
+
'redirection' => 'false',
|
1514 |
+
'action' => 'wp_handle_upload',
|
1515 |
+
'_wp_http_referer' => $request_uri,
|
1516 |
+
'mode' => 'file_upload',
|
1517 |
+
'rtmedia_upload_nonce' => RTMediaUploadView::upload_nonce_generator( false, true ),
|
1518 |
+
)
|
1519 |
+
),
|
1520 |
+
'max_file_size_msg' => apply_filters(
|
1521 |
+
'rtmedia_plupload_file_size_msg',
|
1522 |
+
min(
|
1523 |
+
array(
|
1524 |
+
ini_get( 'upload_max_filesize' ),
|
1525 |
+
ini_get( 'post_max_size' ),
|
1526 |
+
)
|
1527 |
+
)
|
1528 |
+
),
|
1529 |
);
|
1530 |
|
1531 |
$params = apply_filters( 'rtmedia_modify_upload_params', $params );
|
1532 |
|
|
|
1533 |
global $rtmedia;
|
1534 |
$rtmedia_extns = array();
|
1535 |
foreach ( $rtmedia->allowed_types as $allowed_types_key => $allowed_types_value ) {
|
1536 |
$rtmedia_extns[ $allowed_types_key ] = $allowed_types_value['extn'];
|
1537 |
}
|
1538 |
|
1539 |
+
$rtmedia_disable_media = '1';
|
1540 |
+
// if the rtmedia option does have value pick from there.
|
1541 |
+
if ( isset( $rtmedia->options['rtmedia_disable_media_in_commented_media'] ) ) {
|
1542 |
$rtmedia_disable_media = $rtmedia->options['rtmedia_disable_media_in_commented_media'];
|
1543 |
}
|
1544 |
wp_localize_script( 'rtmedia-main', 'rtmedia_disable_media_in_commented_media', $rtmedia_disable_media );
|
1545 |
|
1546 |
+
wp_localize_script( 'rtmedia-main', 'rtmedia_disable_media_in_commented_media_text', __( 'Adding media in Comments is not allowed', 'buddypress-media' ) );
|
1547 |
|
1548 |
wp_localize_script( 'rtmedia-backbone', 'rtmedia_exteansions', $rtmedia_extns );
|
1549 |
wp_localize_script( 'rtmedia-backbone', 'rtMedia_update_plupload_comment', $params );
|
1556 |
}
|
1557 |
}
|
1558 |
|
1559 |
+
/**
|
1560 |
+
* Function to remove BuddyPress account menu from admin bar.
|
1561 |
+
*/
|
1562 |
+
public function set_bp_bar() {
|
1563 |
remove_action( 'bp_adminbar_menus', 'bp_adminbar_account_menu', 4 );
|
1564 |
}
|
1565 |
|
1566 |
+
/**
|
1567 |
+
* Function to set friends Object.
|
1568 |
+
*/
|
1569 |
+
public function set_friends_object() {
|
1570 |
+
// todo: This function should return value or pass argument.
|
1571 |
if ( is_user_logged_in() ) {
|
1572 |
$user = get_current_user_id();
|
1573 |
$friends = friends_get_friend_user_ids( $user );
|
1576 |
}
|
1577 |
}
|
1578 |
|
1579 |
+
/**
|
1580 |
+
* Function to change image size details array.
|
1581 |
+
*
|
1582 |
+
* @param array $sizes Image sizes array.
|
1583 |
+
*
|
1584 |
+
* @return array|mixed
|
1585 |
+
*/
|
1586 |
+
public function filter_image_sizes_details( $sizes ) {
|
1587 |
+
|
1588 |
+
$post_id = filter_input( INPUT_POST, 'post_id', FILTER_VALIDATE_INT );
|
1589 |
+
$id = filter_input( INPUT_POST, 'id', FILTER_VALIDATE_INT );
|
1590 |
+
|
1591 |
+
if ( isset( $post_id ) ) {
|
1592 |
$sizes = $this->unset_bp_media_image_sizes_details( $sizes );
|
1593 |
+
} elseif ( isset( $id ) ) {
|
1594 |
+
|
1595 |
+
// For Regenerate Thumbnails Plugin.
|
1596 |
$model = new RTMediaModel();
|
1597 |
+
$result = $model->get( array( 'media_id' => intval( wp_unslash( $id ) ) ) );
|
1598 |
+
|
1599 |
if ( ! empty( $result ) ) {
|
1600 |
$bp_media_sizes = $this->image_sizes();
|
1601 |
$sizes = array(
|
1612 |
return $sizes;
|
1613 |
}
|
1614 |
|
1615 |
+
/**
|
1616 |
+
* Add custom image sizes for size choose options.
|
1617 |
+
*
|
1618 |
+
* @param array $sizes Image sizes array.
|
1619 |
+
*
|
1620 |
+
* @return array
|
1621 |
+
*/
|
1622 |
+
public function rtmedia_custom_image_sizes_choose( $sizes ) {
|
1623 |
$custom_sizes = array(
|
1624 |
'rt_media_thumbnail' => 'rtMedia Thumbnail',
|
1625 |
'rt_media_activity_image' => 'rtMedia Activity Image',
|
1630 |
return array_merge( $sizes, $custom_sizes );
|
1631 |
}
|
1632 |
|
1633 |
+
/**
|
1634 |
+
* Filter BuddyPress media image sizes to unset sizes.
|
1635 |
+
*
|
1636 |
+
* @param array $sizes Image sizes array.
|
1637 |
+
*
|
1638 |
+
* @return array|mixed
|
1639 |
+
*/
|
1640 |
+
public function filter_image_sizes( $sizes ) {
|
1641 |
+
$post_id = filter_input( INPUT_POST, 'postid', FILTER_VALIDATE_INT );
|
1642 |
+
|
1643 |
+
// For Regenerate Thumbnails Plugin.
|
1644 |
+
if ( ! empty( $post_id ) ) {
|
1645 |
+
|
1646 |
+
$parent_id = get_post_field( 'post_parent', $post_id );
|
1647 |
+
if ( ! empty( $parent_id ) ) {
|
1648 |
$post_type = get_post_field( 'post_type', $parent_id );
|
1649 |
+
|
1650 |
if ( 'rtmedia_album' === $post_type ) {
|
1651 |
$sizes = array(
|
1652 |
'rt_media_thumbnail',
|
1665 |
return $sizes;
|
1666 |
}
|
1667 |
|
1668 |
+
/**
|
1669 |
+
* Unset BuddyPress media image sizes details.
|
1670 |
+
*
|
1671 |
+
* @param array $sizes Image sizes array to unset.
|
1672 |
+
*
|
1673 |
+
* @return mixed
|
1674 |
+
*/
|
1675 |
+
public function unset_bp_media_image_sizes_details( $sizes ) {
|
1676 |
if ( isset( $sizes['rt_media_thumbnail'] ) ) {
|
1677 |
unset( $sizes['rt_media_thumbnail'] );
|
1678 |
}
|
1689 |
return $sizes;
|
1690 |
}
|
1691 |
|
1692 |
+
/**
|
1693 |
+
* Unset BuddyPress media image sizes.
|
1694 |
+
*
|
1695 |
+
* @param array $sizes Image sizes array to unset.
|
1696 |
+
*
|
1697 |
+
* @return mixed
|
1698 |
+
*/
|
1699 |
+
public function unset_bp_media_image_sizes( $sizes ) {
|
1700 |
+
|
1701 |
+
$rt_media_thumbnail_key = array_search( 'rt_media_thumbnail', $sizes, true );
|
1702 |
+
if ( false !== $rt_media_thumbnail_key ) {
|
1703 |
+
unset( $sizes[ $rt_media_thumbnail_key ] );
|
1704 |
}
|
1705 |
+
|
1706 |
+
$rt_media_activity_image_key = array_search( 'rt_media_activity_image', $sizes, true );
|
1707 |
+
if ( false !== $rt_media_activity_image_key ) {
|
1708 |
+
unset( $sizes[ $rt_media_activity_image_key ] );
|
1709 |
}
|
1710 |
+
|
1711 |
+
$rt_media_single_image_key = array_search( 'rt_media_single_image', $sizes, true );
|
1712 |
+
if ( false !== $rt_media_single_image_key ) {
|
1713 |
+
unset( $sizes[ $rt_media_single_image_key ] );
|
1714 |
}
|
1715 |
+
|
1716 |
+
$rt_media_featured_image_key = array_search( 'rt_media_featured_image', $sizes, true );
|
1717 |
+
if ( false !== $rt_media_featured_image_key ) {
|
1718 |
+
unset( $sizes[ $rt_media_featured_image_key ] );
|
1719 |
}
|
1720 |
|
1721 |
return $sizes;
|
1722 |
}
|
1723 |
+
|
1724 |
+
/**
|
1725 |
+
* Function to expand allowed html in wp_kses_allowed_html.
|
1726 |
+
*
|
1727 |
+
* @return array
|
1728 |
+
*/
|
1729 |
+
public static function expanded_allowed_tags() {
|
1730 |
+
$new_allowed = wp_kses_allowed_html( 'post' );
|
1731 |
+
|
1732 |
+
// form input.
|
1733 |
+
$new_allowed['form'] = array(
|
1734 |
+
'action' => array(),
|
1735 |
+
'id' => array(),
|
1736 |
+
'name' => array(),
|
1737 |
+
'class' => array(),
|
1738 |
+
'method' => array(),
|
1739 |
+
);
|
1740 |
+
|
1741 |
+
// form fields - input.
|
1742 |
+
$new_allowed['input'] = array(
|
1743 |
+
'class' => array(),
|
1744 |
+
'id' => array(),
|
1745 |
+
'name' => array(),
|
1746 |
+
'value' => array(),
|
1747 |
+
'type' => array(),
|
1748 |
+
'onclick' => array(),
|
1749 |
+
'min' => array(),
|
1750 |
+
'max' => array(),
|
1751 |
+
'step' => array(),
|
1752 |
+
'style' => array(),
|
1753 |
+
'placeholder' => array(),
|
1754 |
+
'checked' => array(),
|
1755 |
+
'data-*' => true,
|
1756 |
+
);
|
1757 |
+
|
1758 |
+
// select.
|
1759 |
+
$new_allowed['select'] = array(
|
1760 |
+
'class' => array(),
|
1761 |
+
'id' => array(),
|
1762 |
+
'name' => array(),
|
1763 |
+
'value' => array(),
|
1764 |
+
'type' => array(),
|
1765 |
+
);
|
1766 |
+
|
1767 |
+
// select options.
|
1768 |
+
$new_allowed['option'] = array(
|
1769 |
+
'selected' => array(),
|
1770 |
+
'value' => array(),
|
1771 |
+
'class' => array(),
|
1772 |
+
'id' => array(),
|
1773 |
+
'name' => array(),
|
1774 |
+
);
|
1775 |
+
|
1776 |
+
// select optgroup.
|
1777 |
+
$new_allowed['optgroup'] = array(
|
1778 |
+
'label' => array(),
|
1779 |
+
'value' => array(),
|
1780 |
+
);
|
1781 |
+
|
1782 |
+
// audio.
|
1783 |
+
$new_allowed['audio'] = array_merge(
|
1784 |
+
$new_allowed['audio'],
|
1785 |
+
array(
|
1786 |
+
'width' => array(),
|
1787 |
+
'height' => array(),
|
1788 |
+
'type' => array(),
|
1789 |
+
)
|
1790 |
+
);
|
1791 |
+
|
1792 |
+
// video.
|
1793 |
+
$new_allowed['video'] = array_merge(
|
1794 |
+
$new_allowed['video'],
|
1795 |
+
array(
|
1796 |
+
'type' => array(),
|
1797 |
+
)
|
1798 |
+
);
|
1799 |
+
|
1800 |
+
// h2.
|
1801 |
+
$new_allowed['h2'] = array_merge(
|
1802 |
+
$new_allowed['h2'],
|
1803 |
+
array(
|
1804 |
+
'name' => array(),
|
1805 |
+
)
|
1806 |
+
);
|
1807 |
+
|
1808 |
+
// div.
|
1809 |
+
$new_allowed['div'] = array_merge(
|
1810 |
+
$new_allowed['div'],
|
1811 |
+
array(
|
1812 |
+
'name' => array(),
|
1813 |
+
)
|
1814 |
+
);
|
1815 |
+
|
1816 |
+
return $new_allowed;
|
1817 |
+
}
|
1818 |
+
|
1819 |
+
/**
|
1820 |
+
* Add extra inline allowed style.
|
1821 |
+
*
|
1822 |
+
* @param array $styles Allowed styles.
|
1823 |
+
*
|
1824 |
+
* @return array
|
1825 |
+
*/
|
1826 |
+
public static function allow_display_in_style( $styles ) {
|
1827 |
+
$styles[] = 'display';
|
1828 |
+
|
1829 |
+
return $styles;
|
1830 |
+
}
|
1831 |
}
|
1832 |
|
1833 |
+
/**
|
1834 |
+
* Function to get parent link of global album.
|
1835 |
+
*
|
1836 |
+
* @param int $id Id to get permalink.
|
1837 |
+
*
|
1838 |
+
* @return string
|
1839 |
+
*/
|
1840 |
function parentlink_global_album( $id ) {
|
1841 |
$global_albums = RTMediaAlbum::get_globals();
|
1842 |
$parent_link = '';
|
1843 |
+
|
1844 |
if ( is_array( $global_albums ) && '' !== $global_albums ) {
|
1845 |
+
if ( in_array( $id, $global_albums, true ) && function_exists( 'bp_displayed_user_id' ) ) {
|
1846 |
$disp_user = bp_displayed_user_id();
|
1847 |
$curr_user = get_current_user_id();
|
1848 |
+
if ( $disp_user === $curr_user ) {
|
1849 |
$parent_link = get_rtmedia_user_link( $curr_user );
|
1850 |
} else {
|
1851 |
$parent_link = get_rtmedia_user_link( $disp_user );
|
1860 |
return $parent_link;
|
1861 |
}
|
1862 |
|
1863 |
+
/**
|
1864 |
+
* Get media permalink.
|
1865 |
+
*
|
1866 |
+
* @param int $id Id to get permalink.
|
1867 |
+
*
|
1868 |
+
* @return mixed|void
|
1869 |
+
*/
|
1870 |
function get_rtmedia_permalink( $id ) {
|
1871 |
+
|
1872 |
$media_model = new RTMediaModel();
|
1873 |
+
$media = $media_model->get( array( 'id' => intval( $id ) ) );
|
1874 |
global $rtmedia_query;
|
1875 |
|
1876 |
+
// Adding filter to get permalink for current blog.
|
1877 |
add_filter( 'bp_get_root_domain', 'rtmedia_get_current_blog_url' );
|
1878 |
|
1879 |
if ( ! empty( $media ) && is_object( $media[0] ) && ! isset( $media[0]->context ) ) {
|
1880 |
if ( function_exists( 'bp_get_groups_root_slug' ) && isset( $rtmedia_query->query ) && isset( $rtmedia_query->query['context'] ) && 'group' === $rtmedia_query->query['context'] ) {
|
1881 |
$parent_link = get_rtmedia_group_link( $rtmedia_query->query['context_id'] );
|
1882 |
} else {
|
1883 |
+
// check for global album.
|
1884 |
$parent_link = parentlink_global_album( $id );
|
1885 |
if ( '' === $parent_link ) {
|
1886 |
$parent_link = get_rtmedia_user_link( $media[0]->media_author );
|
1887 |
}
|
1888 |
}
|
1889 |
} else {
|
1890 |
+
if ( isset( $media[0]->context ) && function_exists( 'bp_get_groups_root_slug' ) && 'group' === $media[0]->context ) {
|
1891 |
$parent_link = get_rtmedia_group_link( $media[0]->context_id );
|
1892 |
} else {
|
1893 |
+
// check for global album.
|
1894 |
$parent_link = parentlink_global_album( $id );
|
1895 |
if ( '' === $parent_link && isset( $media[0]->media_author ) ) {
|
1896 |
+
$parent_link = get_rtmedia_user_link( $media[0]->media_author );
|
1897 |
}
|
1898 |
}
|
1899 |
}
|
1900 |
|
1901 |
$parent_link = trailingslashit( $parent_link );
|
1902 |
|
1903 |
+
// Removing filter so that doesn't affect other calls to this function.
|
1904 |
remove_filter( 'bp_get_root_domain', 'rtmedia_get_current_blog_url' );
|
1905 |
|
1906 |
$permalink = trailingslashit( $parent_link . RTMEDIA_MEDIA_SLUG . '/' . $id );
|
1912 |
*
|
1913 |
* @param string $permalink The rtmedia's permalink.
|
1914 |
* @param object $media The media in question.
|
1915 |
+
* @param int $id ID of the media.
|
1916 |
*/
|
1917 |
|
1918 |
return apply_filters( 'get_rtmedia_permalink', $permalink, $media, $id );
|
1919 |
}
|
1920 |
|
1921 |
+
/**
|
1922 |
+
* Function to get user posts link from given ID.
|
1923 |
+
*
|
1924 |
+
* @param int $id User id to get link.
|
1925 |
+
*
|
1926 |
+
* @return string
|
1927 |
+
*/
|
1928 |
function get_rtmedia_user_link( $id ) {
|
1929 |
if ( function_exists( 'bp_core_get_user_domain' ) ) {
|
1930 |
$parent_link = bp_core_get_user_domain( $id );
|
1935 |
return $parent_link;
|
1936 |
}
|
1937 |
|
1938 |
+
/**
|
1939 |
+
* Function to update site option based on site type.
|
1940 |
+
*
|
1941 |
+
* @param string $option_name Option name to update.
|
1942 |
+
* @param mixed $option_value Option value to update option with.
|
1943 |
+
*
|
1944 |
+
* @return bool
|
1945 |
+
*/
|
1946 |
function rtmedia_update_site_option( $option_name, $option_value ) {
|
1947 |
if ( is_multisite() ) {
|
1948 |
return update_option( $option_name, $option_value );
|
1951 |
}
|
1952 |
}
|
1953 |
|
1954 |
+
/**
|
1955 |
+
* Function to get permalink for specified group id.
|
1956 |
+
*
|
1957 |
+
* @param int $group_id Group to id to get link.
|
1958 |
+
*
|
1959 |
+
* @return mixed|void
|
1960 |
+
*/
|
1961 |
function get_rtmedia_group_link( $group_id ) {
|
1962 |
$group = groups_get_group( array( 'group_id' => $group_id ) );
|
1963 |
|
1964 |
return apply_filters( 'rtmedia_get_group_link', bp_get_group_permalink( $group ) );
|
1965 |
}
|
1966 |
|
1967 |
+
/**
|
1968 |
+
* Function to get options value for rtMedia.
|
1969 |
+
*
|
1970 |
+
* @param string $option_name Name of option to retrieve.
|
1971 |
+
* @param bool|string $default Default value to return if the option does not exist.
|
1972 |
+
*
|
1973 |
+
* @return bool|mixed|void
|
1974 |
+
*/
|
1975 |
function rtmedia_get_site_option( $option_name, $default = false ) {
|
1976 |
if ( is_multisite() ) {
|
1977 |
$return_val = get_option( $option_name, $default );
|
2010 |
$rtm_privacy_message_options = array(
|
2011 |
'background-color' => 'rgba(0,0,0,0.95)',
|
2012 |
'color' => '#fff',
|
2013 |
+
'position' => 'bottom',
|
2014 |
);
|
2015 |
|
2016 |
$rtm_privacy_message_options = apply_filters( 'rtm_privacy_bar_position', $rtm_privacy_message_options );
|
2017 |
|
2018 |
include_once ABSPATH . 'wp-admin/includes/plugin.php';
|
2019 |
|
2020 |
+
if ( ! is_plugin_active( 'rtmedia-upload-terms/index.php' ) ) {
|
2021 |
+
if ( ! empty( $options['general_upload_terms_show_pricacy_message'] ) && '1' === $options['general_upload_terms_show_pricacy_message'] && empty( $_COOKIE['rtm_show_privacy_message'] ) ) {
|
2022 |
+
$rtm_privacy_allowed_position = array( 'top', 'bottom' );
|
2023 |
+
$rtm_privacy_message_position = ! empty( $rtm_privacy_message_options['position'] ) && ( in_array( $rtm_privacy_message_options['background-color'], $rtm_privacy_allowed_position, true ) ) ? $rtm_privacy_message_options['position'] . ':0' : 'bottom: 0';
|
2024 |
+
$rtm_privacy_message_bgcolor = ! empty( $rtm_privacy_message_options['background-color'] ) ? 'background-color: ' . $rtm_privacy_message_options['background-color'] : 'background-color: rgba(0,0,0,0.95)';
|
2025 |
+
$rtm_privacy_message_color = ! empty( $rtm_privacy_message_options['color'] ) ? 'color: ' . $rtm_privacy_message_options['color'] : 'color: #fff';
|
2026 |
|
2027 |
$rtm_privacy_style = $rtm_privacy_message_position . '; ' . $rtm_privacy_message_bgcolor . '; ' . $rtm_privacy_message_color . ';';
|
2028 |
|
2029 |
+
?>
|
2030 |
+
<div class='privacy_message_wrapper' style='<?php echo esc_attr( $rtm_privacy_style ); ?>' >
|
2031 |
+
<p><?php echo wp_kses_post( $options['general_upload_terms_privacy_message'] ); ?></p>
|
2032 |
+
<span class='dashicons dashicons-no' id='close_rtm_privacy_message'></span>
|
2033 |
+
</div>
|
2034 |
+
<?php
|
2035 |
+
}
|
2036 |
+
}
|
2037 |
}
|
2038 |
add_action( 'wp_footer', 'rtm_privacy_message_on_website' );
|
2039 |
|
2041 |
* Function to add privacy policy information in WordPress policy section.
|
2042 |
*/
|
2043 |
function rtm_plugin_privacy_information() {
|
2044 |
+
|
2045 |
if ( function_exists( 'wp_add_privacy_policy_content' ) ) {
|
2046 |
ob_start();
|
2047 |
?>
|
2074 |
* using 'bpmedia_media_sizes' hook
|
2075 |
* 3. The excerpts and string sizes can be filtered
|
2076 |
* using 'bpmedia_excerpt_lengths' hook
|
|
|
2077 |
*/
|
app/main/RTMediaUploadTerms.php
CHANGED
@@ -19,7 +19,7 @@ if ( ! class_exists( 'RTMediaUploadTerms' ) && ! is_plugin_active( 'rtmedia-uplo
|
|
19 |
class RTMediaUploadTerms {
|
20 |
|
21 |
/**
|
22 |
-
*
|
23 |
*/
|
24 |
public function __construct() {
|
25 |
$this->load_translation();
|
@@ -28,18 +28,57 @@ if ( ! class_exists( 'RTMediaUploadTerms' ) && ! is_plugin_active( 'rtmedia-uplo
|
|
28 |
|
29 |
// Filter into uploader to show checkbox.
|
30 |
add_filter(
|
31 |
-
'rtmedia_uploader_before_start_upload_button',
|
|
|
32 |
$this,
|
33 |
'show_terms_and_service_checkbox',
|
34 |
-
),
|
|
|
|
|
35 |
);
|
36 |
// Filter into activity uploader to show checkbox.
|
37 |
add_filter(
|
38 |
-
'rtmedia_uploader_after_activity_upload_button',
|
|
|
39 |
$this,
|
40 |
'show_terms_and_service_checkbox_activity',
|
41 |
-
),
|
|
|
|
|
42 |
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
}
|
44 |
|
45 |
/**
|
@@ -76,7 +115,7 @@ if ( ! class_exists( 'RTMediaUploadTerms' ) && ! is_plugin_active( 'rtmedia-uplo
|
|
76 |
)
|
77 |
);
|
78 |
|
79 |
-
wp_localize_script( 'rtmedia-main', 'rtmedia_upload_terms_check_terms_message',
|
80 |
}
|
81 |
}
|
82 |
|
@@ -127,14 +166,23 @@ if ( ! class_exists( 'RTMediaUploadTerms' ) && ! is_plugin_active( 'rtmedia-uplo
|
|
127 |
* @return string
|
128 |
*/
|
129 |
public function terms_and_service_checkbox_html( $options ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
$general_upload_terms_page_link = $options['general_upload_terms_page_link'];
|
131 |
$general_upload_terms_message = $options['general_upload_terms_message'];
|
132 |
-
$content = '';
|
133 |
ob_start();
|
134 |
?>
|
135 |
<div class="rtmedia-upload-terms">
|
136 |
-
<input type="checkbox" name="rtmedia_upload_terms_conditions" id="
|
137 |
-
<label for="
|
138 |
<?php echo esc_html( apply_filters( 'rtmedia_upload_terms_service_agree_label', __( 'I agree to', 'buddypress-media' ) ) ); ?>
|
139 |
<a href='<?php echo esc_url( $general_upload_terms_page_link ); ?>' target='_blank'>
|
140 |
<?php echo esc_html( apply_filters( 'rtmedia_upload_terms_service_link_label', $general_upload_terms_message ) ); ?>
|
19 |
class RTMediaUploadTerms {
|
20 |
|
21 |
/**
|
22 |
+
* Enqueuing scripts and styles along with data to be rendered in user side.
|
23 |
*/
|
24 |
public function __construct() {
|
25 |
$this->load_translation();
|
28 |
|
29 |
// Filter into uploader to show checkbox.
|
30 |
add_filter(
|
31 |
+
'rtmedia_uploader_before_start_upload_button',
|
32 |
+
array(
|
33 |
$this,
|
34 |
'show_terms_and_service_checkbox',
|
35 |
+
),
|
36 |
+
199,
|
37 |
+
1
|
38 |
);
|
39 |
// Filter into activity uploader to show checkbox.
|
40 |
add_filter(
|
41 |
+
'rtmedia_uploader_after_activity_upload_button',
|
42 |
+
array(
|
43 |
$this,
|
44 |
'show_terms_and_service_checkbox_activity',
|
45 |
+
),
|
46 |
+
199,
|
47 |
+
1
|
48 |
);
|
49 |
+
// Detect whether terms condition checkbox is displayed in a widget.
|
50 |
+
add_filter(
|
51 |
+
'dynamic_sidebar_params',
|
52 |
+
array(
|
53 |
+
$this,
|
54 |
+
'dynamic_sidebar_params',
|
55 |
+
),
|
56 |
+
199,
|
57 |
+
1
|
58 |
+
);
|
59 |
+
}
|
60 |
+
|
61 |
+
/**
|
62 |
+
* Set global var whether it's inside rtMedia Sidebar Uploader Widget widget.
|
63 |
+
*
|
64 |
+
* @param array $params Widget display arguments.
|
65 |
+
* @return array Modified Widget display arguments.
|
66 |
+
*/
|
67 |
+
public function dynamic_sidebar_params( $params ) {
|
68 |
+
if ( ! empty( $params ) && is_array( $params ) ) {
|
69 |
+
// Iterate params and find widget_name.
|
70 |
+
foreach ( $params as $key => $value ) {
|
71 |
+
// If widget is sidebar uploader widget, set global.
|
72 |
+
if ( ! empty( $value['widget_name'] ) && 'rtMedia Sidebar Uploader Widget' === $value['widget_name'] ) {
|
73 |
+
global $rtmedia_uploader_widget;
|
74 |
+
$rtmedia_uploader_widget = true;
|
75 |
+
|
76 |
+
break;
|
77 |
+
}
|
78 |
+
}
|
79 |
+
}
|
80 |
+
|
81 |
+
return $params;
|
82 |
}
|
83 |
|
84 |
/**
|
115 |
)
|
116 |
);
|
117 |
|
118 |
+
wp_localize_script( 'rtmedia-main', 'rtmedia_upload_terms_check_terms_message', $general_upload_terms_error_message );
|
119 |
}
|
120 |
}
|
121 |
|
166 |
* @return string
|
167 |
*/
|
168 |
public function terms_and_service_checkbox_html( $options ) {
|
169 |
+
$id = 'rtmedia_upload_terms_conditions';
|
170 |
+
|
171 |
+
global $rtmedia_uploader_widget;
|
172 |
+
// Set different terms condition checkbox ID if this is in a widget.
|
173 |
+
if ( $rtmedia_uploader_widget ) {
|
174 |
+
$id = 'rtmedia_widget_upload_terms_conditions';
|
175 |
+
// Set global to false to stop this change for checkboxes on other place.
|
176 |
+
$rtmedia_uploader_widget = false;
|
177 |
+
}
|
178 |
+
|
179 |
$general_upload_terms_page_link = $options['general_upload_terms_page_link'];
|
180 |
$general_upload_terms_message = $options['general_upload_terms_message'];
|
|
|
181 |
ob_start();
|
182 |
?>
|
183 |
<div class="rtmedia-upload-terms">
|
184 |
+
<input type="checkbox" name="rtmedia_upload_terms_conditions" id="<?php echo esc_attr( $id ); ?>" />
|
185 |
+
<label for="<?php echo esc_attr( $id ); ?>">
|
186 |
<?php echo esc_html( apply_filters( 'rtmedia_upload_terms_service_agree_label', __( 'I agree to', 'buddypress-media' ) ) ); ?>
|
187 |
<a href='<?php echo esc_url( $general_upload_terms_page_link ); ?>' target='_blank'>
|
188 |
<?php echo esc_html( apply_filters( 'rtmedia_upload_terms_service_link_label', $general_upload_terms_message ) ); ?>
|
app/main/contexts/RTMediaContext.php
CHANGED
@@ -1,12 +1,12 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
|
4 |
-
*
|
5 |
-
*
|
6 |
*/
|
7 |
|
8 |
/**
|
9 |
-
*
|
10 |
*
|
11 |
* Default Context - The page on from which the request is generating will be taken
|
12 |
* as the default context; if any context/context_id is not passed while uploading any media
|
@@ -17,19 +17,26 @@
|
|
17 |
class RTMediaContext {
|
18 |
|
19 |
/**
|
|
|
20 |
*
|
21 |
-
* @var
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
*
|
23 |
-
*
|
24 |
-
* $id - context id of the context
|
25 |
*/
|
26 |
-
public $
|
27 |
|
28 |
/**
|
|
|
29 |
*
|
30 |
-
* @return
|
31 |
*/
|
32 |
-
function __construct() {
|
33 |
$this->set_context();
|
34 |
|
35 |
return $this;
|
@@ -38,7 +45,7 @@ class RTMediaContext {
|
|
38 |
/**
|
39 |
* Set current request context
|
40 |
*/
|
41 |
-
function set_context() {
|
42 |
if ( class_exists( 'BuddyPress' ) ) {
|
43 |
$this->set_bp_context();
|
44 |
} else {
|
@@ -48,11 +55,13 @@ class RTMediaContext {
|
|
48 |
|
49 |
/**
|
50 |
* Set WordPress context
|
51 |
-
*
|
|
|
52 |
*/
|
53 |
-
function set_wp_context() {
|
|
|
54 |
global $post;
|
55 |
-
|
56 |
if ( is_author() ) {
|
57 |
$this->type = 'profile';
|
58 |
$this->id = get_query_var( 'author' );
|
@@ -60,10 +69,14 @@ class RTMediaContext {
|
|
60 |
$this->type = $post->post_type;
|
61 |
$this->id = $post->ID;
|
62 |
} else {
|
|
|
63 |
$wp_default_context = array( 'page', 'post' );
|
64 |
-
|
65 |
-
|
66 |
-
|
|
|
|
|
|
|
67 |
} else {
|
68 |
$this->type = 'profile';
|
69 |
$this->id = get_current_user_id();
|
@@ -76,7 +89,7 @@ class RTMediaContext {
|
|
76 |
/**
|
77 |
* Set BuddyPress context
|
78 |
*/
|
79 |
-
function set_bp_context() {
|
80 |
if ( bp_is_blog_page() && ! is_home() ) {
|
81 |
$this->set_wp_context();
|
82 |
} else {
|
@@ -87,7 +100,7 @@ class RTMediaContext {
|
|
87 |
/**
|
88 |
* Set BuddyPress component context
|
89 |
*/
|
90 |
-
function set_bp_component_context() {
|
91 |
if ( bp_displayed_user_id() && ! bp_is_group() ) {
|
92 |
$this->type = 'profile';
|
93 |
} else {
|
@@ -106,9 +119,10 @@ class RTMediaContext {
|
|
106 |
|
107 |
/**
|
108 |
* Get current bp component id
|
|
|
109 |
* @return int/null
|
110 |
*/
|
111 |
-
function get_current_bp_component_id() {
|
112 |
switch ( bp_current_component() ) {
|
113 |
case 'groups':
|
114 |
if ( function_exists( 'bp_get_current_group_id' ) ) {
|
@@ -116,10 +130,8 @@ class RTMediaContext {
|
|
116 |
}
|
117 |
|
118 |
return null;
|
119 |
-
break;
|
120 |
default:
|
121 |
return bp_displayed_user_id();
|
122 |
-
break;
|
123 |
}
|
124 |
}
|
125 |
}
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* Manages context for rtMedia
|
4 |
+
*
|
5 |
+
* @package rtMedia
|
6 |
*/
|
7 |
|
8 |
/**
|
9 |
+
* Class to manage context for rtMedia
|
10 |
*
|
11 |
* Default Context - The page on from which the request is generating will be taken
|
12 |
* as the default context; if any context/context_id is not passed while uploading any media
|
17 |
class RTMediaContext {
|
18 |
|
19 |
/**
|
20 |
+
* Context Type. It can be any type among these. (post, page, custom_post, home_page, archive etc.)
|
21 |
*
|
22 |
+
* @var string
|
23 |
+
*/
|
24 |
+
|
25 |
+
public $type;
|
26 |
+
|
27 |
+
/**
|
28 |
+
* Context id of the context
|
29 |
*
|
30 |
+
* @var int
|
|
|
31 |
*/
|
32 |
+
public $id;
|
33 |
|
34 |
/**
|
35 |
+
* RTMediaContext constructor.
|
36 |
*
|
37 |
+
* @return RTMediaContext
|
38 |
*/
|
39 |
+
public function __construct() {
|
40 |
$this->set_context();
|
41 |
|
42 |
return $this;
|
45 |
/**
|
46 |
* Set current request context
|
47 |
*/
|
48 |
+
public function set_context() {
|
49 |
if ( class_exists( 'BuddyPress' ) ) {
|
50 |
$this->set_bp_context();
|
51 |
} else {
|
55 |
|
56 |
/**
|
57 |
* Set WordPress context
|
58 |
+
*
|
59 |
+
* @global object $post
|
60 |
*/
|
61 |
+
public function set_wp_context() {
|
62 |
+
|
63 |
global $post;
|
64 |
+
|
65 |
if ( is_author() ) {
|
66 |
$this->type = 'profile';
|
67 |
$this->id = get_query_var( 'author' );
|
69 |
$this->type = $post->post_type;
|
70 |
$this->id = $post->ID;
|
71 |
} else {
|
72 |
+
|
73 |
$wp_default_context = array( 'page', 'post' );
|
74 |
+
|
75 |
+
$context = sanitize_text_field( filter_input( INPUT_POST, 'context', FILTER_SANITIZE_STRING ) );
|
76 |
+
|
77 |
+
if ( ! empty( $context ) && in_array( $context, $wp_default_context, true ) ) {
|
78 |
+
$this->type = $context;
|
79 |
+
$this->id = filter_input( INPUT_POST, 'context_id', FILTER_VALIDATE_INT );
|
80 |
} else {
|
81 |
$this->type = 'profile';
|
82 |
$this->id = get_current_user_id();
|
89 |
/**
|
90 |
* Set BuddyPress context
|
91 |
*/
|
92 |
+
public function set_bp_context() {
|
93 |
if ( bp_is_blog_page() && ! is_home() ) {
|
94 |
$this->set_wp_context();
|
95 |
} else {
|
100 |
/**
|
101 |
* Set BuddyPress component context
|
102 |
*/
|
103 |
+
public function set_bp_component_context() {
|
104 |
if ( bp_displayed_user_id() && ! bp_is_group() ) {
|
105 |
$this->type = 'profile';
|
106 |
} else {
|
119 |
|
120 |
/**
|
121 |
* Get current bp component id
|
122 |
+
*
|
123 |
* @return int/null
|
124 |
*/
|
125 |
+
public function get_current_bp_component_id() {
|
126 |
switch ( bp_current_component() ) {
|
127 |
case 'groups':
|
128 |
if ( function_exists( 'bp_get_current_group_id' ) ) {
|
130 |
}
|
131 |
|
132 |
return null;
|
|
|
133 |
default:
|
134 |
return bp_displayed_user_id();
|
|
|
135 |
}
|
136 |
}
|
137 |
}
|
app/main/controllers/activity/RTMediaActivity.php
CHANGED
@@ -1,27 +1,46 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
|
4 |
-
*
|
5 |
-
*
|
6 |
*/
|
7 |
|
8 |
/**
|
9 |
-
*
|
10 |
*
|
11 |
* @author saurabh
|
12 |
*/
|
13 |
class RTMediaActivity {
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
18 |
|
19 |
/**
|
20 |
-
*
|
21 |
-
*
|
22 |
-
* @
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
*/
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
if ( ! isset( $media ) ) {
|
26 |
return false;
|
27 |
}
|
@@ -76,13 +95,15 @@ class RTMediaActivity {
|
|
76 |
}
|
77 |
$rtmedia_activity_ul_class = apply_filters( 'rtmedia_' . $type . '_ul_class', 'rtm-activity-media-list' );
|
78 |
|
79 |
-
$uploaded_media_types = [];
|
80 |
$rtmedia_activity_ul_list_class = 'rtm-activity-mixed-list';
|
81 |
|
82 |
// Loop through each media and check media type.
|
83 |
-
$uploaded_media_types = array_map(
|
84 |
-
|
85 |
-
|
|
|
|
|
|
|
86 |
|
87 |
// Remove empty values from media type list.
|
88 |
$media_type_list = array_filter( $uploaded_media_types, 'strlen' );
|
@@ -137,7 +158,7 @@ class RTMediaActivity {
|
|
137 |
esc_html( $media->media_title )
|
138 |
);
|
139 |
} else {
|
140 |
-
// Markup for all the other media
|
141 |
$media_content .= sprintf(
|
142 |
'<div class="rtmedia-item-thumbnail">
|
143 |
%s
|
@@ -179,7 +200,7 @@ class RTMediaActivity {
|
|
179 |
/**
|
180 |
* Filters the output of the activity contents before save.
|
181 |
*
|
182 |
-
* @param string $activity_content
|
183 |
* @param string $activity_text HTML markup of activity text.
|
184 |
* @param string $media_list HTML markup of media in ul.
|
185 |
*/
|
@@ -209,13 +230,21 @@ class RTMediaActivity {
|
|
209 |
}
|
210 |
|
211 |
/**
|
212 |
-
*
|
213 |
*/
|
214 |
-
function actions() {
|
215 |
-
|
216 |
}
|
217 |
|
218 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
219 |
$html = false;
|
220 |
|
221 |
if ( isset( $media->media_type ) ) {
|
@@ -224,10 +253,10 @@ class RTMediaActivity {
|
|
224 |
$thumbnail_id = $media->media_id;
|
225 |
if ( $thumbnail_id ) {
|
226 |
list( $src, $width, $height ) = wp_get_attachment_image_src( $thumbnail_id, apply_filters( 'rtmedia_activity_image_size', 'rt_media_activity_image' ) );
|
227 |
-
$html
|
228 |
}
|
229 |
} elseif ( 'video' === $media->media_type ) {
|
230 |
-
$cover_art
|
231 |
$video_class = 'wp-video-shortcode';
|
232 |
$youtube_url = get_rtmedia_meta( $media->id, 'video_url_uploaded_from' );
|
233 |
if ( $cover_art ) {
|
@@ -240,7 +269,6 @@ class RTMediaActivity {
|
|
240 |
$html = sprintf( $html, $poster, esc_url( wp_get_attachment_url( $media->media_id ) ), esc_attr( $rtmedia->options['defaultSizes_video_activityPlayer_width'] ), esc_attr( $rtmedia->options['defaultSizes_video_activityPlayer_height'] ), $video_class, esc_attr( $media->id ) );
|
241 |
}
|
242 |
} elseif ( 'music' === $media->media_type ) {
|
243 |
-
//$html = '<audio src="' . esc_url( wp_get_attachment_url( $media->media_id ) ) . '" width="' . esc_attr( $rtmedia->options['defaultSizes_music_activityPlayer_width'] ) . '" height="0" type="audio/mp3" class="wp-audio-shortcode" id="rt_media_audio_' . esc_attr( $media->id ) . '" controls="controls" preload="none"></audio>';
|
244 |
$html = '<audio src="%s" width="%d" height="0" type="audio/mp3" class="wp-audio-shortcode" id="rt_media_audio_%s" controls="controls" preload="none"></audio>';
|
245 |
$html = sprintf( $html, esc_url( wp_get_attachment_url( $media->media_id ) ), esc_attr( $rtmedia->options['defaultSizes_music_activityPlayer_width'] ), esc_attr( $media->id ) );
|
246 |
}
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* Handle rtMedia activities.
|
4 |
+
*
|
5 |
+
* @package rtMedia
|
6 |
*/
|
7 |
|
8 |
/**
|
9 |
+
* Class to handle rtMedia activities.
|
10 |
*
|
11 |
* @author saurabh
|
12 |
*/
|
13 |
class RTMediaActivity {
|
14 |
|
15 |
+
/**
|
16 |
+
* Media.
|
17 |
+
*
|
18 |
+
* @var array
|
19 |
+
*/
|
20 |
+
public $media = array();
|
21 |
|
22 |
/**
|
23 |
+
* Activity text.
|
24 |
+
*
|
25 |
+
* @var string
|
26 |
+
*/
|
27 |
+
public $activity_text = '';
|
28 |
+
|
29 |
+
/**
|
30 |
+
* Privacy setting.
|
31 |
+
*
|
32 |
+
* @var int
|
33 |
*/
|
34 |
+
public $privacy;
|
35 |
+
|
36 |
+
/**
|
37 |
+
* RTMediaActivity Constructor.
|
38 |
+
*
|
39 |
+
* @param array $media Media array.
|
40 |
+
* @param int $privacy Privacy.
|
41 |
+
* @param bool|string $activity_text Activity text.
|
42 |
+
*/
|
43 |
+
public function __construct( $media, $privacy = 0, $activity_text = false ) {
|
44 |
if ( ! isset( $media ) ) {
|
45 |
return false;
|
46 |
}
|
95 |
}
|
96 |
$rtmedia_activity_ul_class = apply_filters( 'rtmedia_' . $type . '_ul_class', 'rtm-activity-media-list' );
|
97 |
|
|
|
98 |
$rtmedia_activity_ul_list_class = 'rtm-activity-mixed-list';
|
99 |
|
100 |
// Loop through each media and check media type.
|
101 |
+
$uploaded_media_types = array_map(
|
102 |
+
function ( $current_media ) {
|
103 |
+
return is_object( $current_media ) ? $current_media->media_type : '';
|
104 |
+
},
|
105 |
+
$media_details
|
106 |
+
);
|
107 |
|
108 |
// Remove empty values from media type list.
|
109 |
$media_type_list = array_filter( $uploaded_media_types, 'strlen' );
|
158 |
esc_html( $media->media_title )
|
159 |
);
|
160 |
} else {
|
161 |
+
// Markup for all the other media link docs and other files where anchor tag the markup is coming from add-on itself.
|
162 |
$media_content .= sprintf(
|
163 |
'<div class="rtmedia-item-thumbnail">
|
164 |
%s
|
200 |
/**
|
201 |
* Filters the output of the activity contents before save.
|
202 |
*
|
203 |
+
* @param string $activity_content Concatenations of $activity_text and $media_list.
|
204 |
* @param string $activity_text HTML markup of activity text.
|
205 |
* @param string $media_list HTML markup of media in ul.
|
206 |
*/
|
230 |
}
|
231 |
|
232 |
/**
|
233 |
+
* Actions.
|
234 |
*/
|
235 |
+
public function actions() {
|
236 |
+
// todo Why this function is required ?
|
237 |
}
|
238 |
|
239 |
+
/**
|
240 |
+
* Show Media.
|
241 |
+
*
|
242 |
+
* @param object $media Media.
|
243 |
+
* @param string $type Type.
|
244 |
+
*
|
245 |
+
* @return mixed
|
246 |
+
*/
|
247 |
+
public function media( $media, $type = 'activity' ) {
|
248 |
$html = false;
|
249 |
|
250 |
if ( isset( $media->media_type ) ) {
|
253 |
$thumbnail_id = $media->media_id;
|
254 |
if ( $thumbnail_id ) {
|
255 |
list( $src, $width, $height ) = wp_get_attachment_image_src( $thumbnail_id, apply_filters( 'rtmedia_activity_image_size', 'rt_media_activity_image' ) );
|
256 |
+
$html = '<img alt="' . esc_attr( $media->media_title ) . '" src="' . set_url_scheme( $src ) . '" />';
|
257 |
}
|
258 |
} elseif ( 'video' === $media->media_type ) {
|
259 |
+
$cover_art = rtmedia_get_cover_art_src( $media->id );
|
260 |
$video_class = 'wp-video-shortcode';
|
261 |
$youtube_url = get_rtmedia_meta( $media->id, 'video_url_uploaded_from' );
|
262 |
if ( $cover_art ) {
|
269 |
$html = sprintf( $html, $poster, esc_url( wp_get_attachment_url( $media->media_id ) ), esc_attr( $rtmedia->options['defaultSizes_video_activityPlayer_width'] ), esc_attr( $rtmedia->options['defaultSizes_video_activityPlayer_height'] ), $video_class, esc_attr( $media->id ) );
|
270 |
}
|
271 |
} elseif ( 'music' === $media->media_type ) {
|
|
|
272 |
$html = '<audio src="%s" width="%d" height="0" type="audio/mp3" class="wp-audio-shortcode" id="rt_media_audio_%s" controls="controls" preload="none"></audio>';
|
273 |
$html = sprintf( $html, esc_url( wp_get_attachment_url( $media->media_id ) ), esc_attr( $rtmedia->options['defaultSizes_music_activityPlayer_width'] ), esc_attr( $media->id ) );
|
274 |
}
|
app/main/controllers/activity/RTMediaBuddyPressActivity.php
CHANGED
@@ -1,18 +1,21 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
|
4 |
-
*
|
5 |
-
*
|
6 |
*/
|
7 |
|
8 |
/**
|
9 |
-
*
|
10 |
*
|
11 |
* @author faishal
|
12 |
*/
|
13 |
class RTMediaBuddyPressActivity {
|
14 |
|
15 |
-
|
|
|
|
|
|
|
16 |
global $rtmedia;
|
17 |
if ( 0 !== intval( $rtmedia->options['buddypress_enableOnActivity'] ) ) {
|
18 |
add_action( 'bp_after_activity_post_form', array( &$this, 'bp_after_activity_post_form' ) );
|
@@ -37,21 +40,21 @@ class RTMediaBuddyPressActivity {
|
|
37 |
add_action( 'bp_activity_delete_comment', array( $this, 'delete_comment_sync' ), 10, 2 );
|
38 |
add_filter( 'bp_activity_allowed_tags', array( &$this, 'override_allowed_tags' ) );
|
39 |
add_filter( 'bp_get_activity_parent_content', array( &$this, 'bp_get_activity_parent_content' ) );
|
40 |
-
add_filter( 'bp_activity_content_before_save', array( $this, 'bp_activity_content_before_save' ) );
|
41 |
add_filter( 'bp_activity_type_before_save', array( $this, 'bp_activity_type_before_save' ) );
|
42 |
add_action( 'bp_activity_deleted_activities', array( &$this, 'bp_activity_deleted_activities' ) );
|
43 |
|
44 |
-
// Filter bp_activity_prefetch_object_data for translatable activity actions
|
45 |
add_filter( 'bp_activity_prefetch_object_data', array( $this, 'bp_prefetch_activity_object_data' ), 10, 1 );
|
46 |
|
47 |
add_filter( 'bp_get_activity_action_pre_meta', array( $this, 'bp_get_activity_action_pre_meta' ), 11, 2 );
|
48 |
|
49 |
-
// BuddyPress activity for media like action
|
50 |
if ( isset( $rtmedia->options['buddypress_mediaLikeActivity'] ) && 0 !== intval( $rtmedia->options['buddypress_mediaLikeActivity'] ) ) {
|
51 |
add_action( 'rtmedia_after_like_media', array( $this, 'activity_after_media_like' ) );
|
52 |
}
|
53 |
|
54 |
-
// BuddyPress activity for media comment action
|
55 |
if ( isset( $rtmedia->options['buddypress_mediaCommentActivity'] ) && 0 !== intval( $rtmedia->options['buddypress_mediaCommentActivity'] ) ) {
|
56 |
add_action( 'rtmedia_after_add_comment', array( $this, 'activity_after_media_comment' ) );
|
57 |
add_action( 'rtmedia_before_remove_comment', array( $this, 'remove_activity_after_media_comment_delete' ) );
|
@@ -105,7 +108,8 @@ class RTMediaBuddyPressActivity {
|
|
105 |
$dom = new DOMDocument();
|
106 |
// DOMDocument gives error on html5 tags, so we need to disable errors.
|
107 |
libxml_use_internal_errors( true );
|
108 |
-
|
|
|
109 |
// DOMDocument gives error on html5 tags, so we need to disable errors.
|
110 |
libxml_clear_errors();
|
111 |
// We need to find div having rtmedia-activity-text class, but no direct method for it.
|
@@ -238,11 +242,11 @@ class RTMediaBuddyPressActivity {
|
|
238 |
* For adding secondary avatar in the activity header.
|
239 |
*
|
240 |
* @param String $action Has the markup for activity header.
|
241 |
-
* @param array $activity Contains values
|
242 |
*
|
243 |
* @return String $action.
|
244 |
*/
|
245 |
-
function bp_get_activity_action_pre_meta( $action, $activity ) {
|
246 |
|
247 |
if ( 'rtmedia_update' === $activity->type && 'groups' === $activity->component ) {
|
248 |
|
@@ -310,7 +314,7 @@ class RTMediaBuddyPressActivity {
|
|
310 |
private static function reset_multisite_transient() {
|
311 |
$sites = get_sites( array( 'fields' => 'ids' ) );
|
312 |
foreach ( $sites as $site ) {
|
313 |
-
if (
|
314 |
continue;
|
315 |
}
|
316 |
|
@@ -349,13 +353,13 @@ class RTMediaBuddyPressActivity {
|
|
349 |
*/
|
350 |
public function filter_activity_with_blog( $query_string ) {
|
351 |
global $wpdb;
|
352 |
-
|
353 |
$blog_id = get_current_blog_id();
|
354 |
|
355 |
$transient_name = 'rtm_filter_blog_activity_' . $blog_id;
|
356 |
$activity_ids = get_site_transient( $transient_name );
|
357 |
if ( empty( $activity_ids ) ) {
|
358 |
-
$activities = $wpdb->get_col( $wpdb->prepare(
|
359 |
$activity_ids = implode( ',', $activities );
|
360 |
|
361 |
set_site_transient( $transient_name, $activity_ids );
|
@@ -377,7 +381,7 @@ class RTMediaBuddyPressActivity {
|
|
377 |
*
|
378 |
* @param array $activity_ids_deleted Array of affected activity item IDs.
|
379 |
*/
|
380 |
-
function bp_activity_deleted_activities( $activity_ids_deleted ) {
|
381 |
$rt_model = new RTMediaModel();
|
382 |
$all_media = $rt_model->get( array( 'activity_id' => $activity_ids_deleted ) );
|
383 |
if ( $all_media ) {
|
@@ -389,33 +393,42 @@ class RTMediaBuddyPressActivity {
|
|
389 |
}
|
390 |
}
|
391 |
|
392 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
393 |
global $activities_template;
|
394 |
|
395 |
-
// Get the ID of the parent activity content
|
396 |
-
|
|
|
|
|
397 |
return false;
|
398 |
}
|
399 |
|
400 |
-
// Bail if no parent content
|
401 |
if ( empty( $activities_template->activity_parents[ $parent_id ] ) ) {
|
402 |
return false;
|
403 |
}
|
404 |
|
405 |
-
// Bail if no action
|
406 |
if ( empty( $activities_template->activity_parents[ $parent_id ]->action ) ) {
|
407 |
return false;
|
408 |
}
|
409 |
|
410 |
-
// Content always includes action
|
411 |
$content = $activities_template->activity_parents[ $parent_id ]->action;
|
412 |
|
413 |
-
// Maybe append activity content, if it exists
|
414 |
if ( ! empty( $activities_template->activity_parents[ $parent_id ]->content ) ) {
|
415 |
$content .= ' ' . $activities_template->activity_parents[ $parent_id ]->content;
|
416 |
}
|
417 |
|
418 |
-
// Remove the time since content for backwards compatibility
|
419 |
$content = str_replace( '<span class="time-since">%s</span>', '', $content );
|
420 |
|
421 |
return $content;
|
@@ -424,11 +437,36 @@ class RTMediaBuddyPressActivity {
|
|
424 |
/**
|
425 |
* This function will check for the media file attached to the activity and accordingly will set content.
|
426 |
*
|
427 |
-
* @param string $content
|
|
|
428 |
*
|
429 |
* @return string Filtered value of the activity content.
|
430 |
*/
|
431 |
-
public function bp_activity_content_before_save( $content ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
432 |
|
433 |
$rtmedia_attached_files = filter_input( INPUT_POST, 'rtMedia_attached_files', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
|
434 |
if ( ( ! empty( $rtmedia_attached_files ) ) && is_array( $rtmedia_attached_files ) ) {
|
@@ -457,7 +495,13 @@ class RTMediaBuddyPressActivity {
|
|
457 |
return $type;
|
458 |
}
|
459 |
|
460 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
461 |
global $wpdb;
|
462 |
$comment_id = $wpdb->get_var( $wpdb->prepare( "select comment_id from {$wpdb->commentmeta} where meta_key = 'activity_id' and meta_value = %s", $comment_id ) );
|
463 |
if ( $comment_id ) {
|
@@ -465,81 +509,116 @@ class RTMediaBuddyPressActivity {
|
|
465 |
}
|
466 |
}
|
467 |
|
468 |
-
|
469 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
470 |
$param = wp_parse_args( $param, $default_args );
|
471 |
$user_id = $param['user_id'];
|
472 |
$comment_author = $param['comment_author'];
|
|
|
473 |
if ( ! empty( $user_id ) ) {
|
474 |
$user_data = get_userdata( $user_id );
|
475 |
$comment_author = $user_data->data->user_login;
|
476 |
}
|
477 |
$mediamodel = new RTMediaModel();
|
478 |
$media = $mediamodel->get( array( 'activity_id' => $param['activity_id'] ) );
|
479 |
-
|
|
|
480 |
if ( 1 === count( $media ) && isset( $media[0]->media_id ) ) {
|
481 |
|
482 |
-
|
483 |
-
$
|
484 |
-
|
485 |
-
if ( is_array( $
|
486 |
-
|
487 |
-
$obj_comment
|
488 |
$param['content'] = $obj_comment->create_activity_html( 'comment-media' );
|
489 |
}
|
490 |
|
491 |
$media_id = $media[0]->media_id;
|
492 |
$comment = new RTMediaComment();
|
493 |
-
$id = $comment->add(
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
|
|
|
|
499 |
update_comment_meta( $id, 'activity_id', $comment_id );
|
500 |
}
|
501 |
}
|
502 |
|
503 |
-
|
504 |
-
|
|
|
|
|
|
|
505 |
if ( 'new_activity_comment' === $action ) {
|
506 |
-
$activity_id
|
507 |
-
$
|
|
|
508 |
|
509 |
-
if ( 'rtmedia_update' === $act->type &&
|
510 |
$_POST['comment_id'] = $activity_id;
|
511 |
}
|
512 |
}
|
513 |
}
|
514 |
|
515 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
516 |
$this->bp_activity_posted_update( $content, $user_id, $activity_id );
|
517 |
}
|
518 |
|
519 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
520 |
global $wpdb, $bp;
|
521 |
$updated_content = '';
|
522 |
|
523 |
-
// hook for rtmedia buddypress before activity posted
|
524 |
do_action( 'rtmedia_bp_before_activity_posted', $content, $user_id, $activity_id );
|
525 |
|
526 |
$rtmedia_attached_files = filter_input( INPUT_POST, 'rtMedia_attached_files', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
|
527 |
if ( is_array( $rtmedia_attached_files ) ) {
|
528 |
bp_activity_update_meta( $activity_id, 'bp_activity_text', bp_activity_filter_kses( $content ) );
|
529 |
$media_obj = new RTMediaModel();
|
530 |
-
//Credit faisal : https://gist.github.com/faishal/c4306ae7267fff976465
|
531 |
-
$in_str_arr
|
532 |
-
$in_str
|
533 |
-
$sql
|
534 |
-
$form_id_where = $wpdb->prepare( "id IN ($in_str)", $rtmedia_attached_files );
|
535 |
-
$sql
|
536 |
-
$wpdb->query( $sql )
|
537 |
}
|
538 |
-
|
|
|
539 |
do_action( 'rtmedia_bp_activity_posted', $updated_content, $user_id, $activity_id );
|
540 |
$rtmedia_privacy = filter_input( INPUT_POST, 'rtmedia-privacy', FILTER_SANITIZE_NUMBER_INT );
|
|
|
541 |
if ( null !== $rtmedia_privacy ) {
|
542 |
-
$privacy = -
|
|
|
543 |
if ( is_rtmedia_privacy_enable() ) {
|
544 |
if ( is_rtmedia_privacy_user_overide() ) {
|
545 |
$privacy = $rtmedia_privacy;
|
@@ -547,21 +626,28 @@ class RTMediaBuddyPressActivity {
|
|
547 |
$privacy = get_rtmedia_default_privacy();
|
548 |
}
|
549 |
}
|
|
|
550 |
bp_activity_update_meta( $activity_id, 'rtmedia_privacy', $privacy );
|
551 |
-
// insert/update activity details in rtmedia activity table
|
552 |
$rtmedia_activity_model = new RTMediaActivityModel();
|
|
|
553 |
if ( ! $rtmedia_activity_model->check( $activity_id ) ) {
|
554 |
-
$rtmedia_activity_model->insert(
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
|
|
|
|
559 |
} else {
|
560 |
-
$rtmedia_activity_model->update(
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
|
|
|
|
|
|
565 |
}
|
566 |
}
|
567 |
}
|
@@ -569,14 +655,14 @@ class RTMediaBuddyPressActivity {
|
|
569 |
/**
|
570 |
* Update `bp_latest_update` user meta with lasted public update.
|
571 |
*
|
572 |
-
* @param $content
|
573 |
-
* @param $user_id
|
574 |
-
* @param $activity_id
|
575 |
*/
|
576 |
-
function manage_user_last_activity_update( $content, $user_id, $activity_id ) {
|
577 |
global $wpdb, $bp;
|
578 |
|
579 |
-
// do not proceed if not allowed
|
580 |
if ( ! apply_filters( 'rtm_manage_user_last_activity_update', true, $activity_id ) ) {
|
581 |
return;
|
582 |
}
|
@@ -599,31 +685,38 @@ class RTMediaBuddyPressActivity {
|
|
599 |
),
|
600 |
);
|
601 |
|
602 |
-
// get user's latest public activity update
|
603 |
$new_last_activity_obj = $rtm_activity_model->get( $get_columns, 0, 1 );
|
604 |
|
605 |
if ( ! empty( $new_last_activity_obj ) ) {
|
606 |
-
// latest public activity id
|
607 |
$public_activity_id = $new_last_activity_obj[0]->activity_id;
|
608 |
|
609 |
-
// latest public activity content
|
610 |
$activity_content = bp_activity_get_meta( $public_activity_id, 'bp_activity_text' );
|
611 |
if ( empty( $activity_content ) ) {
|
612 |
-
$activity_content = $wpdb->get_var( $wpdb->prepare( "SELECT content FROM {$bp->activity->table_name} WHERE id = %d", $public_activity_id ) ); //
|
613 |
}
|
614 |
$activity_content = apply_filters( 'bp_activity_latest_update_content', $activity_content, $activity_content );
|
615 |
|
616 |
-
// update user's latest update
|
617 |
-
bp_update_user_meta(
|
618 |
-
|
619 |
-
'
|
620 |
-
|
|
|
|
|
|
|
|
|
621 |
}
|
622 |
}
|
623 |
}
|
624 |
}
|
625 |
|
626 |
-
|
|
|
|
|
|
|
627 |
|
628 |
/**
|
629 |
* Filter to enable/disable media upload from the activity.
|
@@ -643,13 +736,16 @@ class RTMediaBuddyPressActivity {
|
|
643 |
// browse button assigned to "Attach Files" Button.
|
644 |
'container' => 'rtmedia-whts-new-upload-container',
|
645 |
'drop_element' => 'whats-new-textarea',
|
646 |
-
// drag-drop area assigned to activity update textarea
|
647 |
-
'filters' => apply_filters(
|
|
|
648 |
array(
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
|
|
|
|
|
653 |
'max_file_size' => ( wp_max_upload_size() ) / ( 1024 * 1024 ) . 'M',
|
654 |
'multipart' => true,
|
655 |
'urlstream_upload' => true,
|
@@ -658,23 +754,31 @@ class RTMediaBuddyPressActivity {
|
|
658 |
'file_data_name' => 'rtmedia_file',
|
659 |
// key passed to $_FILE.
|
660 |
'multi_selection' => true,
|
661 |
-
'multipart_params' => apply_filters(
|
662 |
-
'
|
663 |
-
|
664 |
-
|
665 |
-
|
666 |
-
|
667 |
-
|
668 |
-
|
669 |
-
|
670 |
-
|
671 |
-
|
672 |
-
|
673 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
674 |
);
|
675 |
|
676 |
$params = apply_filters( 'rtmedia_modify_upload_params', $params );
|
677 |
-
wp_enqueue_script( 'rtmedia-backbone', false, '',
|
678 |
$is_album = is_rtmedia_album() ? true : false;
|
679 |
$is_edit_allowed = is_rtmedia_edit_allowed() ? true : false;
|
680 |
wp_localize_script( 'rtmedia-backbone', 'is_album', $is_album );
|
@@ -688,32 +792,39 @@ class RTMediaBuddyPressActivity {
|
|
688 |
}
|
689 |
}
|
690 |
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
-
|
695 |
-
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
-
|
700 |
-
$activity_allowedtags['video']
|
701 |
-
$activity_allowedtags['video']['
|
702 |
-
$activity_allowedtags['video']['
|
703 |
-
$activity_allowedtags['video']['
|
704 |
-
$activity_allowedtags['
|
705 |
-
$activity_allowedtags['
|
706 |
-
$activity_allowedtags['
|
707 |
-
$activity_allowedtags['
|
708 |
-
$activity_allowedtags['
|
709 |
-
$activity_allowedtags['
|
710 |
-
$activity_allowedtags['
|
711 |
-
$activity_allowedtags['
|
712 |
-
$activity_allowedtags['
|
713 |
-
$activity_allowedtags['
|
714 |
-
$activity_allowedtags['audio']
|
715 |
-
$activity_allowedtags['audio']['
|
716 |
-
$activity_allowedtags['audio']['
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
717 |
|
718 |
if ( ! isset( $activity_allowedtags['div'] ) ) {
|
719 |
$activity_allowedtags['div'] = array();
|
@@ -746,33 +857,35 @@ class RTMediaBuddyPressActivity {
|
|
746 |
/**
|
747 |
* To add dynamic activity actions for translation of activity items
|
748 |
*
|
749 |
-
* @param $activities
|
|
|
|
|
750 |
*/
|
751 |
-
function bp_prefetch_activity_object_data( $activities ) {
|
752 |
-
// If activities array is empty then return
|
753 |
if ( empty( $activities ) ) {
|
754 |
return;
|
755 |
}
|
756 |
|
757 |
-
// To store activity_id
|
758 |
$activity_ids = array();
|
759 |
$activity_index_array = array();
|
760 |
|
761 |
foreach ( $activities as $i => $activity ) {
|
762 |
-
// Checking if activity_type is of rtmedia and component must be profile
|
763 |
if ( 'rtmedia_update' === $activity->type && 'profile' === $activity->component ) {
|
764 |
-
// Storing activity_id
|
765 |
$activity_ids[] = $activity->id;
|
766 |
-
// Storing index of activity from activities array
|
767 |
$activity_index_array[] = $i;
|
768 |
}
|
769 |
}
|
770 |
|
771 |
-
// Checking if media is linked with any of activity
|
772 |
if ( ! empty( $activity_ids ) ) {
|
773 |
$rtmedia_model = new RTMediaModel();
|
774 |
|
775 |
-
// Where condition array to get media using activity_id from rtm_media table
|
776 |
$rtmedia_media_where_array = array();
|
777 |
$rtmedia_media_where_array['activity_id'] = array(
|
778 |
'compare' => 'IN',
|
@@ -780,11 +893,12 @@ class RTMediaBuddyPressActivity {
|
|
780 |
);
|
781 |
$rtmedia_media_query = $rtmedia_model->get( $rtmedia_media_where_array );
|
782 |
|
783 |
-
// Array to store media_type in simplified manner with activity_id as key
|
784 |
$rtmedia_media_type_array = array();
|
785 |
-
|
|
|
786 |
// Storing media_type of uploaded media to check whether all media are of same type or different and key is activity_id
|
787 |
-
// Making activity_id array because there might be more then 1 media linked with activity
|
788 |
if ( ! isset( $rtmedia_media_type_array[ $rtmedia_media_query[ $i ]->activity_id ] ) || ! is_array( $rtmedia_media_type_array[ $rtmedia_media_query[ $i ]->activity_id ] ) ) {
|
789 |
$rtmedia_media_type_array[ $rtmedia_media_query[ $i ]->activity_id ] = array();
|
790 |
}
|
@@ -792,18 +906,19 @@ class RTMediaBuddyPressActivity {
|
|
792 |
array_push( $rtmedia_media_type_array[ $rtmedia_media_query[ $i ]->activity_id ], $rtmedia_media_query[ $i ]->media_type );
|
793 |
}
|
794 |
|
795 |
-
// Updating action
|
796 |
-
|
797 |
-
|
|
|
798 |
$index = $activity_index_array[ $a ];
|
799 |
|
800 |
// Generating user_link with display name.
|
801 |
$user_link = '<a href="' . esc_url( $activities[ $index ]->primary_link ) . '">' . esc_html( $activities[ $index ]->display_name ) . '</a>';
|
802 |
|
803 |
if ( isset( $rtmedia_media_type_array[ $activities[ $index ]->id ] ) ) {
|
804 |
-
// Counting media linked with activity
|
805 |
$count = count( $rtmedia_media_type_array[ $activities[ $index ]->id ] );
|
806 |
-
// Getting constant with single label or plural label
|
807 |
$media_const = 'RTMEDIA_' . strtoupper( $rtmedia_media_type_array[ $activities[ $index ]->id ][0] );
|
808 |
if ( $count > 1 ) {
|
809 |
$media_const .= '_PLURAL';
|
@@ -817,18 +932,21 @@ class RTMediaBuddyPressActivity {
|
|
817 |
|
818 |
$action = '';
|
819 |
$user = get_userdata( $activities[ $index ]->user_id );
|
820 |
-
// Updating activity based on count
|
821 |
if ( 1 === $count ) {
|
822 |
-
|
|
|
823 |
} else {
|
824 |
-
// Checking all the media linked with activity are of same type
|
825 |
if ( isset( $rtmedia_media_type_array[ $activities[ $index ]->id ] )
|
826 |
&& ! empty( $rtmedia_media_type_array[ $activities[ $index ]->id ] )
|
827 |
&& count( array_unique( $rtmedia_media_type_array[ $activities[ $index ]->id ] ) ) === 1
|
828 |
) {
|
829 |
-
|
|
|
830 |
} else {
|
831 |
-
|
|
|
832 |
}
|
833 |
}
|
834 |
|
@@ -844,9 +962,9 @@ class RTMediaBuddyPressActivity {
|
|
844 |
/**
|
845 |
* Create BP activity when user like and delete associated activity when user remove like.
|
846 |
*
|
847 |
-
* @param $obj
|
848 |
*/
|
849 |
-
function activity_after_media_like( $obj ) {
|
850 |
if ( class_exists( 'BuddyPress' ) ) {
|
851 |
global $rtmedia_points_media_id;
|
852 |
if ( is_a( $obj, 'RTMediaLike' ) && isset( $obj->action_query->id ) ) {
|
@@ -867,7 +985,7 @@ class RTMediaBuddyPressActivity {
|
|
867 |
// If $obj->increase is true than request is to like the media.
|
868 |
if ( $obj->increase ) {
|
869 |
|
870 |
-
// Create activity on media like
|
871 |
$user = get_userdata( $user_id );
|
872 |
$username = '<a href="' . esc_url( get_rtmedia_user_link( $user_id ) ) . '">' . esc_html( $user->display_name ) . '</a>';
|
873 |
|
@@ -881,14 +999,17 @@ class RTMediaBuddyPressActivity {
|
|
881 |
if ( 'group' === $media_obj->context ) {
|
882 |
$group_data = groups_get_group( array( 'group_id' => $media_obj->context_id ) );
|
883 |
$group_name = '<a href="' . esc_url( bp_get_group_permalink( $group_data ) ) . '">' . esc_html( $group_data->name ) . '</a>';
|
884 |
-
|
|
|
885 |
} else {
|
886 |
if ( $user_id === $media_author ) {
|
|
|
887 |
$action = sprintf( esc_html__( '%1$s liked their %2$s', 'buddypress-media' ), $username, $media_str );
|
888 |
} else {
|
889 |
$media_author_data = get_userdata( $media_author );
|
890 |
$media_author_name = '<a href="' . esc_url( get_rtmedia_user_link( $media_author ) ) . '">' . esc_html( $media_author_data->display_name ) . '</a>';
|
891 |
-
|
|
|
892 |
}
|
893 |
}
|
894 |
|
@@ -897,15 +1018,15 @@ class RTMediaBuddyPressActivity {
|
|
897 |
|
898 |
// generate activity arguments.
|
899 |
$activity_args = array(
|
900 |
-
|
901 |
-
|
902 |
-
|
903 |
-
|
904 |
-
|
905 |
-
|
906 |
);
|
907 |
|
908 |
-
// set activity component
|
909 |
if ( 'group' === $media_obj->context || 'profile' === $media_obj->context ) {
|
910 |
$activity_args['component'] = $media_obj->context;
|
911 |
if ( 'group' === $media_obj->context ) {
|
@@ -914,29 +1035,28 @@ class RTMediaBuddyPressActivity {
|
|
914 |
}
|
915 |
}
|
916 |
|
917 |
-
// add BP activity
|
918 |
$activity_id = bp_activity_add( $activity_args );
|
919 |
|
920 |
-
// add privacy for like activity
|
921 |
-
if( class_exists( 'RTMediaActivityModel' ) && is_rtmedia_privacy_enable() && isset( $media_obj->activity_id ) ){
|
922 |
$rtmedia_activity_model = new RTMediaActivityModel();
|
923 |
-
$rtmedia_activity_model->set_privacy_for_rtmedia_activity( $media_obj->activity_id, $activity_id
|
924 |
}
|
925 |
|
926 |
-
|
927 |
-
//
|
928 |
-
//todo user_attribute
|
929 |
update_user_meta( $user_id, 'rtm-bp-media-like-activity-' . $media_id, $activity_id );
|
930 |
} else {
|
931 |
|
932 |
$meta_key = 'rtm-bp-media-like-activity-' . $media_id;
|
933 |
// Delete activity when user remove his like.
|
934 |
-
//todo user_attribute
|
935 |
$activity_id = get_user_meta( $user_id, $meta_key, true );
|
936 |
|
937 |
if ( ! empty( $activity_id ) ) {
|
938 |
if ( bp_activity_delete( array( 'id' => $activity_id ) ) ) {
|
939 |
-
//todo user_attribute
|
940 |
delete_user_meta( $user_id, $meta_key );
|
941 |
}
|
942 |
}
|
@@ -948,13 +1068,13 @@ class RTMediaBuddyPressActivity {
|
|
948 |
/**
|
949 |
* Create BuddyPress activity when user comment on media
|
950 |
*
|
951 |
-
* @param $params array
|
952 |
*/
|
953 |
-
function activity_after_media_comment( $params ) {
|
954 |
if ( class_exists( 'BuddyPress' ) && function_exists( 'bp_activity_add' ) ) {
|
955 |
if ( isset( $params['comment_post_ID'] ) ) {
|
956 |
|
957 |
-
// get media details
|
958 |
$media_model = new RTMediaModel();
|
959 |
$media_obj = $media_model->get( array( 'media_id' => $params['comment_post_ID'] ) );
|
960 |
$media_obj = $media_obj[0];
|
@@ -978,71 +1098,76 @@ class RTMediaBuddyPressActivity {
|
|
978 |
if ( 'group' === $media_obj->context ) {
|
979 |
$group_data = groups_get_group( array( 'group_id' => $media_obj->context_id ) );
|
980 |
$group_name = '<a href="' . esc_url( bp_get_group_permalink( $group_data ) ) . '">' . esc_html( $group_data->name ) . '</a>';
|
981 |
-
|
|
|
982 |
} else {
|
|
|
983 |
if ( $user_id === $media_author ) {
|
|
|
984 |
$action = sprintf( esc_html__( '%1$s commented on their %2$s', 'buddypress-media' ), $username, $media_str );
|
985 |
} else {
|
986 |
$media_author_data = get_userdata( $media_author );
|
987 |
$media_author_name = '<a href="' . esc_url( get_rtmedia_user_link( $media_author ) ) . '">' . esc_html( $media_author_data->display_name ) . '</a>';
|
988 |
-
|
|
|
989 |
}
|
990 |
}
|
991 |
|
992 |
$activity_content = $params['comment_content'];
|
993 |
-
$comment_media
|
994 |
$comment_media_id = false;
|
995 |
|
996 |
-
|
997 |
-
|
998 |
-
|
|
|
|
|
999 |
|
1000 |
-
|
1001 |
-
/* comment content */
|
1002 |
-
$comment_content = $_REQUEST['content'];
|
1003 |
-
}elseif ( isset( $_REQUEST['comment_content'] ) ) {
|
1004 |
-
/* comment content */
|
1005 |
-
$comment_content = $_REQUEST['comment_content'];
|
1006 |
-
}
|
1007 |
|
1008 |
-
|
1009 |
-
if( strstr($comment_content, 'nbsp') ){
|
1010 |
-
$comment_content = " ";
|
1011 |
-
}
|
1012 |
|
|
|
|
|
|
|
|
|
|
|
|
|
1013 |
|
1014 |
-
|
1015 |
-
|
1016 |
-
|
|
|
1017 |
|
1018 |
-
|
1019 |
-
|
1020 |
-
$comment_media = true;
|
1021 |
-
$comment_media_id = $rtMedia_attached_files[0];
|
1022 |
-
$obj_comment = new RTMediaActivity( $rtMedia_attached_files[0], 0, $comment_content );
|
1023 |
-
$comment_content = $obj_comment->create_activity_html();
|
1024 |
-
}
|
1025 |
-
}
|
1026 |
|
1027 |
-
|
1028 |
-
|
1029 |
-
|
|
|
|
|
|
|
|
|
1030 |
|
|
|
|
|
|
|
1031 |
|
1032 |
-
$wp_comment_id
|
1033 |
|
1034 |
-
// prepare activity arguments
|
1035 |
$activity_args = array(
|
1036 |
-
|
1037 |
-
|
1038 |
-
|
1039 |
-
|
1040 |
-
|
1041 |
-
|
1042 |
-
|
1043 |
);
|
1044 |
|
1045 |
-
// set activity component
|
1046 |
if ( 'group' === $media_obj->context || 'profile' === $media_obj->context ) {
|
1047 |
$activity_args['component'] = $media_obj->context;
|
1048 |
if ( 'group' === $media_obj->context ) {
|
@@ -1051,31 +1176,30 @@ class RTMediaBuddyPressActivity {
|
|
1051 |
}
|
1052 |
}
|
1053 |
|
1054 |
-
// create BuddyPress activity
|
1055 |
remove_filter( 'bp_activity_content_before_save', array( $this, 'bp_activity_content_before_save' ) );
|
1056 |
$activity_id = bp_activity_add( $activity_args );
|
1057 |
|
1058 |
-
|
1059 |
-
if( ! empty( $comment_media ) && ! empty( $comment_media_id ) && ! empty( $activity_id ) ){
|
1060 |
add_rtmedia_meta( $comment_media_id, 'rtmedia_comment_media_profile_id', $activity_id );
|
1061 |
}
|
1062 |
|
1063 |
-
// add privacy for like activity
|
1064 |
-
if( class_exists( 'RTMediaActivityModel' ) && is_rtmedia_privacy_enable() && isset( $media_obj->activity_id ) ){
|
1065 |
$rtmedia_activity_model = new RTMediaActivityModel();
|
1066 |
-
$rtmedia_activity_model->set_privacy_for_rtmedia_activity( $media_obj->activity_id, $activity_id
|
1067 |
}
|
1068 |
|
1069 |
-
// Store activity id into user meta for reference
|
1070 |
-
//todo user_attribute
|
1071 |
update_user_meta( $user_id, 'rtm-bp-media-comment-activity-' . $media_id . '-' . $wp_comment_id, $activity_id );
|
1072 |
|
1073 |
-
if( function_exists( 'rtmedia_get_original_comment_media_content' ) ){
|
1074 |
-
|
1075 |
$original_content = rtmedia_get_original_comment_media_content();
|
1076 |
-
|
1077 |
bp_activity_update_meta( $activity_id, 'bp_activity_text', $original_content );
|
1078 |
-
// bp_activity_update_meta( $activity_id, 'bp_old_activity_content', $original_content );
|
1079 |
}
|
1080 |
}
|
1081 |
}
|
@@ -1085,12 +1209,12 @@ class RTMediaBuddyPressActivity {
|
|
1085 |
/**
|
1086 |
* Remove activity when comment on media is deleted
|
1087 |
*
|
1088 |
-
* @param $comment_id
|
1089 |
*/
|
1090 |
-
function remove_activity_after_media_comment_delete( $comment_id ) {
|
1091 |
if ( ! empty( $comment_id ) && function_exists( 'bp_activity_delete' ) ) {
|
1092 |
|
1093 |
-
// get comment details from comment id
|
1094 |
$comment = get_comment( $comment_id );
|
1095 |
$user_id = $comment->user_id;
|
1096 |
|
@@ -1103,12 +1227,12 @@ class RTMediaBuddyPressActivity {
|
|
1103 |
$meta_key = 'rtm-bp-media-comment-activity-' . $media_obj->id . '-' . $comment_id;
|
1104 |
|
1105 |
// Delete activity when user remove his comment.
|
1106 |
-
//todo user_attribute
|
1107 |
$activity_id = get_user_meta( $user_id, $meta_key, true );
|
1108 |
|
1109 |
if ( ! empty( $activity_id ) ) {
|
1110 |
if ( bp_activity_delete( array( 'id' => $activity_id ) ) ) {
|
1111 |
-
//todo user_attribute
|
1112 |
delete_user_meta( $user_id, $meta_key );
|
1113 |
}
|
1114 |
}
|
@@ -1120,14 +1244,14 @@ class RTMediaBuddyPressActivity {
|
|
1120 |
/**
|
1121 |
* To check whether user can delete the activity or not
|
1122 |
*
|
1123 |
-
* @access
|
1124 |
*
|
1125 |
-
* @since
|
1126 |
*
|
1127 |
-
* @param
|
1128 |
-
* @param
|
1129 |
*
|
1130 |
-
* @return
|
1131 |
*/
|
1132 |
public function rtm_bp_activity_user_can_delete( $can_delete, $activity ) {
|
1133 |
|
@@ -1142,20 +1266,26 @@ class RTMediaBuddyPressActivity {
|
|
1142 |
/**
|
1143 |
* To check user has access to view single activity
|
1144 |
*
|
1145 |
-
* @access
|
1146 |
*
|
1147 |
-
* @since
|
1148 |
*
|
1149 |
-
* @param
|
1150 |
*
|
1151 |
-
* @return
|
1152 |
*/
|
1153 |
public function rtm_bp_activity_permalink_access( $args ) {
|
1154 |
|
1155 |
$bp = buddypress();
|
1156 |
|
1157 |
// Get the activity details.
|
1158 |
-
$activity = bp_activity_get_specific(
|
|
|
|
|
|
|
|
|
|
|
|
|
1159 |
|
1160 |
// 404 if activity does not exist
|
1161 |
if ( empty( $activity['activities'][0] ) || bp_action_variables() ) {
|
@@ -1170,7 +1300,7 @@ class RTMediaBuddyPressActivity {
|
|
1170 |
$has_access = true;
|
1171 |
|
1172 |
// If activity is from a group, do an extra cap check.
|
1173 |
-
if ( isset( $bp->groups->id ) && $activity->component
|
1174 |
// Activity is from a group, but groups is currently disabled.
|
1175 |
if ( ! bp_is_active( 'groups' ) ) {
|
1176 |
bp_do_404();
|
@@ -1178,11 +1308,12 @@ class RTMediaBuddyPressActivity {
|
|
1178 |
return;
|
1179 |
}
|
1180 |
|
|
|
1181 |
// Check to see if the group is not public, if so, check the
|
1182 |
// user has access to see this activity.
|
1183 |
-
if (
|
1184 |
// Group is not public.
|
1185 |
-
if ( 'public'
|
1186 |
// User is not a member of group.
|
1187 |
if ( ! groups_is_user_member( bp_loggedin_user_id(), $group->id ) ) {
|
1188 |
$has_access = false;
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* Handle/change BuddyPress activities behaviour.
|
4 |
+
*
|
5 |
+
* @package rtMedia
|
6 |
*/
|
7 |
|
8 |
/**
|
9 |
+
* Class to handle/change BuddyPress activities behaviour.
|
10 |
*
|
11 |
* @author faishal
|
12 |
*/
|
13 |
class RTMediaBuddyPressActivity {
|
14 |
|
15 |
+
/**
|
16 |
+
* RTMediaBuddyPressActivity constructor.
|
17 |
+
*/
|
18 |
+
public function __construct() {
|
19 |
global $rtmedia;
|
20 |
if ( 0 !== intval( $rtmedia->options['buddypress_enableOnActivity'] ) ) {
|
21 |
add_action( 'bp_after_activity_post_form', array( &$this, 'bp_after_activity_post_form' ) );
|
40 |
add_action( 'bp_activity_delete_comment', array( $this, 'delete_comment_sync' ), 10, 2 );
|
41 |
add_filter( 'bp_activity_allowed_tags', array( &$this, 'override_allowed_tags' ) );
|
42 |
add_filter( 'bp_get_activity_parent_content', array( &$this, 'bp_get_activity_parent_content' ) );
|
43 |
+
add_filter( 'bp_activity_content_before_save', array( $this, 'bp_activity_content_before_save' ), 10, 2 );
|
44 |
add_filter( 'bp_activity_type_before_save', array( $this, 'bp_activity_type_before_save' ) );
|
45 |
add_action( 'bp_activity_deleted_activities', array( &$this, 'bp_activity_deleted_activities' ) );
|
46 |
|
47 |
+
// Filter bp_activity_prefetch_object_data for translatable activity actions.
|
48 |
add_filter( 'bp_activity_prefetch_object_data', array( $this, 'bp_prefetch_activity_object_data' ), 10, 1 );
|
49 |
|
50 |
add_filter( 'bp_get_activity_action_pre_meta', array( $this, 'bp_get_activity_action_pre_meta' ), 11, 2 );
|
51 |
|
52 |
+
// BuddyPress activity for media like action.
|
53 |
if ( isset( $rtmedia->options['buddypress_mediaLikeActivity'] ) && 0 !== intval( $rtmedia->options['buddypress_mediaLikeActivity'] ) ) {
|
54 |
add_action( 'rtmedia_after_like_media', array( $this, 'activity_after_media_like' ) );
|
55 |
}
|
56 |
|
57 |
+
// BuddyPress activity for media comment action.
|
58 |
if ( isset( $rtmedia->options['buddypress_mediaCommentActivity'] ) && 0 !== intval( $rtmedia->options['buddypress_mediaCommentActivity'] ) ) {
|
59 |
add_action( 'rtmedia_after_add_comment', array( $this, 'activity_after_media_comment' ) );
|
60 |
add_action( 'rtmedia_before_remove_comment', array( $this, 'remove_activity_after_media_comment_delete' ) );
|
108 |
$dom = new DOMDocument();
|
109 |
// DOMDocument gives error on html5 tags, so we need to disable errors.
|
110 |
libxml_use_internal_errors( true );
|
111 |
+
// Use utf-8 encoding for different languages.
|
112 |
+
$dom->loadHTML( '<?xml encoding="utf-8" ?>' . $text );
|
113 |
// DOMDocument gives error on html5 tags, so we need to disable errors.
|
114 |
libxml_clear_errors();
|
115 |
// We need to find div having rtmedia-activity-text class, but no direct method for it.
|
242 |
* For adding secondary avatar in the activity header.
|
243 |
*
|
244 |
* @param String $action Has the markup for activity header.
|
245 |
+
* @param array $activity Contains values related to the activity.
|
246 |
*
|
247 |
* @return String $action.
|
248 |
*/
|
249 |
+
public function bp_get_activity_action_pre_meta( $action, $activity ) {
|
250 |
|
251 |
if ( 'rtmedia_update' === $activity->type && 'groups' === $activity->component ) {
|
252 |
|
314 |
private static function reset_multisite_transient() {
|
315 |
$sites = get_sites( array( 'fields' => 'ids' ) );
|
316 |
foreach ( $sites as $site ) {
|
317 |
+
if ( get_current_blog_id() === $site ) {
|
318 |
continue;
|
319 |
}
|
320 |
|
353 |
*/
|
354 |
public function filter_activity_with_blog( $query_string ) {
|
355 |
global $wpdb;
|
356 |
+
|
357 |
$blog_id = get_current_blog_id();
|
358 |
|
359 |
$transient_name = 'rtm_filter_blog_activity_' . $blog_id;
|
360 |
$activity_ids = get_site_transient( $transient_name );
|
361 |
if ( empty( $activity_ids ) ) {
|
362 |
+
$activities = $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT activity_id FROM { $wpdb->base_prefix }rt_rtm_activity WHERE blog_id!=%d", $blog_id ) );
|
363 |
$activity_ids = implode( ',', $activities );
|
364 |
|
365 |
set_site_transient( $transient_name, $activity_ids );
|
381 |
*
|
382 |
* @param array $activity_ids_deleted Array of affected activity item IDs.
|
383 |
*/
|
384 |
+
public function bp_activity_deleted_activities( $activity_ids_deleted ) {
|
385 |
$rt_model = new RTMediaModel();
|
386 |
$all_media = $rt_model->get( array( 'activity_id' => $activity_ids_deleted ) );
|
387 |
if ( $all_media ) {
|
393 |
}
|
394 |
}
|
395 |
|
396 |
+
/**
|
397 |
+
* Get activity parent content.
|
398 |
+
*
|
399 |
+
* @param string $content Content.
|
400 |
+
*
|
401 |
+
* @return bool|mixed|string
|
402 |
+
*/
|
403 |
+
public function bp_get_activity_parent_content( $content ) {
|
404 |
global $activities_template;
|
405 |
|
406 |
+
// Get the ID of the parent activity content.
|
407 |
+
$parent_id = $activities_template->activity->item_id;
|
408 |
+
|
409 |
+
if ( empty( $parent_id ) ) {
|
410 |
return false;
|
411 |
}
|
412 |
|
413 |
+
// Bail if no parent content.
|
414 |
if ( empty( $activities_template->activity_parents[ $parent_id ] ) ) {
|
415 |
return false;
|
416 |
}
|
417 |
|
418 |
+
// Bail if no action.
|
419 |
if ( empty( $activities_template->activity_parents[ $parent_id ]->action ) ) {
|
420 |
return false;
|
421 |
}
|
422 |
|
423 |
+
// Content always includes action.
|
424 |
$content = $activities_template->activity_parents[ $parent_id ]->action;
|
425 |
|
426 |
+
// Maybe append activity content, if it exists.
|
427 |
if ( ! empty( $activities_template->activity_parents[ $parent_id ]->content ) ) {
|
428 |
$content .= ' ' . $activities_template->activity_parents[ $parent_id ]->content;
|
429 |
}
|
430 |
|
431 |
+
// Remove the time since content for backwards compatibility.
|
432 |
$content = str_replace( '<span class="time-since">%s</span>', '', $content );
|
433 |
|
434 |
return $content;
|
437 |
/**
|
438 |
* This function will check for the media file attached to the activity and accordingly will set content.
|
439 |
*
|
440 |
+
* @param string $content Content of the Activity.
|
441 |
+
* @param object $class_obj BP_Activity_Activity class object.
|
442 |
*
|
443 |
* @return string Filtered value of the activity content.
|
444 |
*/
|
445 |
+
public function bp_activity_content_before_save( $content, $class_obj ) {
|
446 |
+
global $rtmedia;
|
447 |
+
|
448 |
+
// Check if this is not a comment.
|
449 |
+
$action = wp_unslash( filter_input( INPUT_POST, 'action', FILTER_SANITIZE_STRING ) );
|
450 |
+
// When activity upload terms are enabled on activity page, we check whether someone has removed the html element or not.
|
451 |
+
if ( 'post_update' === $action && ! empty( $rtmedia->options['activity_enable_upload_terms'] ) ) {
|
452 |
+
$term = wp_unslash( filter_input( INPUT_POST, 'rtmedia_upload_terms_conditions', FILTER_SANITIZE_STRING ) );
|
453 |
+
if ( empty( $term ) ) {
|
454 |
+
|
455 |
+
// We set error object in buddypress, so it'll show error on activity page.
|
456 |
+
if ( isset( $class_obj->errors ) && is_wp_error( $class_obj->errors ) ) {
|
457 |
+
$class_obj->errors->add( 400, esc_html__( 'Terms and Conditions checkbox not found!', 'buddypress-media' ) );
|
458 |
+
} elseif ( isset( $class_obj->component ) ) {
|
459 |
+
// If error object is not found, we set component to null so it'll show error.
|
460 |
+
$class_obj->component = null;
|
461 |
+
}
|
462 |
+
|
463 |
+
if ( isset( $class_obj->error_type ) ) {
|
464 |
+
$class_obj->error_type = 'wp_error';
|
465 |
+
}
|
466 |
+
|
467 |
+
return '';
|
468 |
+
}
|
469 |
+
}
|
470 |
|
471 |
$rtmedia_attached_files = filter_input( INPUT_POST, 'rtMedia_attached_files', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
|
472 |
if ( ( ! empty( $rtmedia_attached_files ) ) && is_array( $rtmedia_attached_files ) ) {
|
495 |
return $type;
|
496 |
}
|
497 |
|
498 |
+
/**
|
499 |
+
* Delete comment for activity.
|
500 |
+
*
|
501 |
+
* @param int $activity_id Activity id.
|
502 |
+
* @param int $comment_id Comment id.
|
503 |
+
*/
|
504 |
+
public function delete_comment_sync( $activity_id, $comment_id ) {
|
505 |
global $wpdb;
|
506 |
$comment_id = $wpdb->get_var( $wpdb->prepare( "select comment_id from {$wpdb->commentmeta} where meta_key = 'activity_id' and meta_value = %s", $comment_id ) );
|
507 |
if ( $comment_id ) {
|
509 |
}
|
510 |
}
|
511 |
|
512 |
+
/**
|
513 |
+
* Comment sync.
|
514 |
+
*
|
515 |
+
* @param int $comment_id Comment id.
|
516 |
+
* @param array $param Parameters.
|
517 |
+
*/
|
518 |
+
public function comment_sync( $comment_id, $param ) {
|
519 |
+
$default_args = array(
|
520 |
+
'user_id' => '',
|
521 |
+
'comment_author' => '',
|
522 |
+
);
|
523 |
$param = wp_parse_args( $param, $default_args );
|
524 |
$user_id = $param['user_id'];
|
525 |
$comment_author = $param['comment_author'];
|
526 |
+
|
527 |
if ( ! empty( $user_id ) ) {
|
528 |
$user_data = get_userdata( $user_id );
|
529 |
$comment_author = $user_data->data->user_login;
|
530 |
}
|
531 |
$mediamodel = new RTMediaModel();
|
532 |
$media = $mediamodel->get( array( 'activity_id' => $param['activity_id'] ) );
|
533 |
+
|
534 |
+
// if there is only single media in activity.
|
535 |
if ( 1 === count( $media ) && isset( $media[0]->media_id ) ) {
|
536 |
|
537 |
+
// has media in comment.
|
538 |
+
$rtmedia_attached_files = filter_input( INPUT_POST, 'rtMedia_attached_files', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
|
539 |
+
// if the media is not empty.
|
540 |
+
if ( is_array( $rtmedia_attached_files ) && ! empty( $rtmedia_attached_files[0] ) && class_exists( 'RTMediaActivity' ) ) {
|
541 |
+
// create new html for comment content.
|
542 |
+
$obj_comment = new RTMediaActivity( $rtmedia_attached_files[0], 0, $param['content'] );
|
543 |
$param['content'] = $obj_comment->create_activity_html( 'comment-media' );
|
544 |
}
|
545 |
|
546 |
$media_id = $media[0]->media_id;
|
547 |
$comment = new RTMediaComment();
|
548 |
+
$id = $comment->add(
|
549 |
+
array(
|
550 |
+
'comment_content' => $param['content'],
|
551 |
+
'comment_post_ID' => $media_id,
|
552 |
+
'user_id' => $user_id,
|
553 |
+
'comment_author' => $comment_author,
|
554 |
+
)
|
555 |
+
);
|
556 |
update_comment_meta( $id, 'activity_id', $comment_id );
|
557 |
}
|
558 |
}
|
559 |
|
560 |
+
/**
|
561 |
+
* Save Non-threaded comments.
|
562 |
+
*/
|
563 |
+
public function non_threaded_comments() {
|
564 |
+
$action = sanitize_text_field( filter_input( INPUT_POST, 'action', FILTER_SANITIZE_STRING ) );
|
565 |
if ( 'new_activity_comment' === $action ) {
|
566 |
+
$activity_id = filter_input( INPUT_POST, 'form_id', FILTER_SANITIZE_NUMBER_INT );
|
567 |
+
$disable_media = filter_input( INPUT_POST, 'rtmedia_disable_media_in_commented_media', FILTER_SANITIZE_STRING );
|
568 |
+
$act = new BP_Activity_Activity( $activity_id );
|
569 |
|
570 |
+
if ( 'rtmedia_update' === $act->type && ! empty( $disable_media ) ) {
|
571 |
$_POST['comment_id'] = $activity_id;
|
572 |
}
|
573 |
}
|
574 |
}
|
575 |
|
576 |
+
/**
|
577 |
+
* Groups posted update.
|
578 |
+
*
|
579 |
+
* @param string $content Content to update.
|
580 |
+
* @param int $user_id User id.
|
581 |
+
* @param int $group_id Group id.
|
582 |
+
* @param int $activity_id Activity id.
|
583 |
+
*/
|
584 |
+
public function bp_groups_posted_update( $content, $user_id, $group_id, $activity_id ) {
|
585 |
$this->bp_activity_posted_update( $content, $user_id, $activity_id );
|
586 |
}
|
587 |
|
588 |
+
/**
|
589 |
+
* Activity posted update.
|
590 |
+
*
|
591 |
+
* @param string $content Content to update.
|
592 |
+
* @param int $user_id User id.
|
593 |
+
* @param int $activity_id Activity id.
|
594 |
+
*/
|
595 |
+
public function bp_activity_posted_update( $content, $user_id, $activity_id ) {
|
596 |
global $wpdb, $bp;
|
597 |
$updated_content = '';
|
598 |
|
599 |
+
// hook for rtmedia buddypress before activity posted.
|
600 |
do_action( 'rtmedia_bp_before_activity_posted', $content, $user_id, $activity_id );
|
601 |
|
602 |
$rtmedia_attached_files = filter_input( INPUT_POST, 'rtMedia_attached_files', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
|
603 |
if ( is_array( $rtmedia_attached_files ) ) {
|
604 |
bp_activity_update_meta( $activity_id, 'bp_activity_text', bp_activity_filter_kses( $content ) );
|
605 |
$media_obj = new RTMediaModel();
|
606 |
+
// Credit faisal : https://gist.github.com/faishal/c4306ae7267fff976465.
|
607 |
+
$in_str_arr = array_fill( 0, count( $rtmedia_attached_files ), '%d' );
|
608 |
+
$in_str = join( ',', $in_str_arr );
|
609 |
+
$sql = $wpdb->prepare( "update {$media_obj->table_name} set activity_id = %d where blog_id = %d and ", $activity_id, get_current_blog_id() ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
610 |
+
$form_id_where = $wpdb->prepare( "id IN ($in_str)", $rtmedia_attached_files ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
|
611 |
+
$sql .= $form_id_where;
|
612 |
+
$wpdb->query( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
613 |
}
|
614 |
+
|
615 |
+
// hook for rtmedia buddypress after activity posted.
|
616 |
do_action( 'rtmedia_bp_activity_posted', $updated_content, $user_id, $activity_id );
|
617 |
$rtmedia_privacy = filter_input( INPUT_POST, 'rtmedia-privacy', FILTER_SANITIZE_NUMBER_INT );
|
618 |
+
|
619 |
if ( null !== $rtmedia_privacy ) {
|
620 |
+
$privacy = -1;
|
621 |
+
|
622 |
if ( is_rtmedia_privacy_enable() ) {
|
623 |
if ( is_rtmedia_privacy_user_overide() ) {
|
624 |
$privacy = $rtmedia_privacy;
|
626 |
$privacy = get_rtmedia_default_privacy();
|
627 |
}
|
628 |
}
|
629 |
+
|
630 |
bp_activity_update_meta( $activity_id, 'rtmedia_privacy', $privacy );
|
631 |
+
// insert/update activity details in rtmedia activity table.
|
632 |
$rtmedia_activity_model = new RTMediaActivityModel();
|
633 |
+
|
634 |
if ( ! $rtmedia_activity_model->check( $activity_id ) ) {
|
635 |
+
$rtmedia_activity_model->insert(
|
636 |
+
array(
|
637 |
+
'activity_id' => $activity_id,
|
638 |
+
'user_id' => $user_id,
|
639 |
+
'privacy' => $privacy,
|
640 |
+
)
|
641 |
+
);
|
642 |
} else {
|
643 |
+
$rtmedia_activity_model->update(
|
644 |
+
array(
|
645 |
+
'activity_id' => $activity_id,
|
646 |
+
'user_id' => $user_id,
|
647 |
+
'privacy' => $privacy,
|
648 |
+
),
|
649 |
+
array( 'activity_id' => $activity_id )
|
650 |
+
);
|
651 |
}
|
652 |
}
|
653 |
}
|
655 |
/**
|
656 |
* Update `bp_latest_update` user meta with lasted public update.
|
657 |
*
|
658 |
+
* @param string $content Content to update.
|
659 |
+
* @param int $user_id User id.
|
660 |
+
* @param int $activity_id Activity id.
|
661 |
*/
|
662 |
+
public function manage_user_last_activity_update( $content, $user_id, $activity_id ) {
|
663 |
global $wpdb, $bp;
|
664 |
|
665 |
+
// do not proceed if not allowed.
|
666 |
if ( ! apply_filters( 'rtm_manage_user_last_activity_update', true, $activity_id ) ) {
|
667 |
return;
|
668 |
}
|
685 |
),
|
686 |
);
|
687 |
|
688 |
+
// get user's latest public activity update.
|
689 |
$new_last_activity_obj = $rtm_activity_model->get( $get_columns, 0, 1 );
|
690 |
|
691 |
if ( ! empty( $new_last_activity_obj ) ) {
|
692 |
+
// latest public activity id.
|
693 |
$public_activity_id = $new_last_activity_obj[0]->activity_id;
|
694 |
|
695 |
+
// latest public activity content.
|
696 |
$activity_content = bp_activity_get_meta( $public_activity_id, 'bp_activity_text' );
|
697 |
if ( empty( $activity_content ) ) {
|
698 |
+
$activity_content = $wpdb->get_var( $wpdb->prepare( "SELECT content FROM {$bp->activity->table_name} WHERE id = %d", $public_activity_id ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
699 |
}
|
700 |
$activity_content = apply_filters( 'bp_activity_latest_update_content', $activity_content, $activity_content );
|
701 |
|
702 |
+
// update user's latest update.
|
703 |
+
bp_update_user_meta(
|
704 |
+
$user_id,
|
705 |
+
'bp_latest_update',
|
706 |
+
array(
|
707 |
+
'id' => $public_activity_id,
|
708 |
+
'content' => $activity_content,
|
709 |
+
)
|
710 |
+
);
|
711 |
}
|
712 |
}
|
713 |
}
|
714 |
}
|
715 |
|
716 |
+
/**
|
717 |
+
* After activity post form.
|
718 |
+
*/
|
719 |
+
public function bp_after_activity_post_form() {
|
720 |
|
721 |
/**
|
722 |
* Filter to enable/disable media upload from the activity.
|
736 |
// browse button assigned to "Attach Files" Button.
|
737 |
'container' => 'rtmedia-whts-new-upload-container',
|
738 |
'drop_element' => 'whats-new-textarea',
|
739 |
+
// drag-drop area assigned to activity update textarea.
|
740 |
+
'filters' => apply_filters(
|
741 |
+
'rtmedia_plupload_files_filter',
|
742 |
array(
|
743 |
+
array(
|
744 |
+
'title' => esc_html__( 'Media Files', 'buddypress-media' ),
|
745 |
+
'extensions' => get_rtmedia_allowed_upload_type(),
|
746 |
+
),
|
747 |
+
)
|
748 |
+
),
|
749 |
'max_file_size' => ( wp_max_upload_size() ) / ( 1024 * 1024 ) . 'M',
|
750 |
'multipart' => true,
|
751 |
'urlstream_upload' => true,
|
754 |
'file_data_name' => 'rtmedia_file',
|
755 |
// key passed to $_FILE.
|
756 |
'multi_selection' => true,
|
757 |
+
'multipart_params' => apply_filters( // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
|
758 |
+
'rtmedia-multi-params',
|
759 |
+
array(
|
760 |
+
'redirect' => 'no',
|
761 |
+
'redirection' => 'false',
|
762 |
+
'rtmedia_update' => 'true',
|
763 |
+
'action' => 'wp_handle_upload',
|
764 |
+
'_wp_http_referer' => $request_uri,
|
765 |
+
'mode' => 'file_upload',
|
766 |
+
'rtmedia_upload_nonce' => RTMediaUploadView::upload_nonce_generator( false, true ),
|
767 |
+
)
|
768 |
+
),
|
769 |
+
'max_file_size_msg' => apply_filters(
|
770 |
+
'rtmedia_plupload_file_size_msg',
|
771 |
+
min(
|
772 |
+
array(
|
773 |
+
ini_get( 'upload_max_filesize' ),
|
774 |
+
ini_get( 'post_max_size' ),
|
775 |
+
)
|
776 |
+
)
|
777 |
+
),
|
778 |
);
|
779 |
|
780 |
$params = apply_filters( 'rtmedia_modify_upload_params', $params );
|
781 |
+
wp_enqueue_script( 'rtmedia-backbone', false, '', RTMEDIA_VERSION, true );
|
782 |
$is_album = is_rtmedia_album() ? true : false;
|
783 |
$is_edit_allowed = is_rtmedia_edit_allowed() ? true : false;
|
784 |
wp_localize_script( 'rtmedia-backbone', 'is_album', $is_album );
|
792 |
}
|
793 |
}
|
794 |
|
795 |
+
/**
|
796 |
+
* Override allowed tags.
|
797 |
+
*
|
798 |
+
* @param array $activity_allowedtags Tags.
|
799 |
+
*
|
800 |
+
* @return mixed
|
801 |
+
*/
|
802 |
+
public function override_allowed_tags( $activity_allowedtags ) {
|
803 |
+
|
804 |
+
$activity_allowedtags['video'] = array();
|
805 |
+
$activity_allowedtags['video']['id'] = array();
|
806 |
+
$activity_allowedtags['video']['class'] = array();
|
807 |
+
$activity_allowedtags['video']['src'] = array();
|
808 |
+
$activity_allowedtags['video']['controls'] = array();
|
809 |
+
$activity_allowedtags['video']['preload'] = array();
|
810 |
+
$activity_allowedtags['video']['alt'] = array();
|
811 |
+
$activity_allowedtags['video']['title'] = array();
|
812 |
+
$activity_allowedtags['video']['width'] = array();
|
813 |
+
$activity_allowedtags['video']['height'] = array();
|
814 |
+
$activity_allowedtags['video']['poster'] = array();
|
815 |
+
$activity_allowedtags['source'] = array();
|
816 |
+
$activity_allowedtags['source']['type'] = array();
|
817 |
+
$activity_allowedtags['source']['src'] = array();
|
818 |
+
$activity_allowedtags['audio'] = array();
|
819 |
+
$activity_allowedtags['audio']['id'] = array();
|
820 |
+
$activity_allowedtags['audio']['class'] = array();
|
821 |
+
$activity_allowedtags['audio']['src'] = array();
|
822 |
+
$activity_allowedtags['audio']['controls'] = array();
|
823 |
+
$activity_allowedtags['audio']['preload'] = array();
|
824 |
+
$activity_allowedtags['audio']['alt'] = array();
|
825 |
+
$activity_allowedtags['audio']['title'] = array();
|
826 |
+
$activity_allowedtags['audio']['width'] = array();
|
827 |
+
$activity_allowedtags['audio']['poster'] = array();
|
828 |
|
829 |
if ( ! isset( $activity_allowedtags['div'] ) ) {
|
830 |
$activity_allowedtags['div'] = array();
|
857 |
/**
|
858 |
* To add dynamic activity actions for translation of activity items
|
859 |
*
|
860 |
+
* @param array $activities Activities.
|
861 |
+
*
|
862 |
+
* @return null
|
863 |
*/
|
864 |
+
public function bp_prefetch_activity_object_data( $activities ) {
|
865 |
+
// If activities array is empty then return.
|
866 |
if ( empty( $activities ) ) {
|
867 |
return;
|
868 |
}
|
869 |
|
870 |
+
// To store activity_id.
|
871 |
$activity_ids = array();
|
872 |
$activity_index_array = array();
|
873 |
|
874 |
foreach ( $activities as $i => $activity ) {
|
875 |
+
// Checking if activity_type is of rtmedia and component must be profile.
|
876 |
if ( 'rtmedia_update' === $activity->type && 'profile' === $activity->component ) {
|
877 |
+
// Storing activity_id.
|
878 |
$activity_ids[] = $activity->id;
|
879 |
+
// Storing index of activity from activities array.
|
880 |
$activity_index_array[] = $i;
|
881 |
}
|
882 |
}
|
883 |
|
884 |
+
// Checking if media is linked with any of activity.
|
885 |
if ( ! empty( $activity_ids ) ) {
|
886 |
$rtmedia_model = new RTMediaModel();
|
887 |
|
888 |
+
// Where condition array to get media using activity_id from rtm_media table.
|
889 |
$rtmedia_media_where_array = array();
|
890 |
$rtmedia_media_where_array['activity_id'] = array(
|
891 |
'compare' => 'IN',
|
893 |
);
|
894 |
$rtmedia_media_query = $rtmedia_model->get( $rtmedia_media_where_array );
|
895 |
|
896 |
+
// Array to store media_type in simplified manner with activity_id as key.
|
897 |
$rtmedia_media_type_array = array();
|
898 |
+
$media_count = count( $rtmedia_media_query );
|
899 |
+
for ( $i = 0; $i < $media_count; $i ++ ) {
|
900 |
// Storing media_type of uploaded media to check whether all media are of same type or different and key is activity_id
|
901 |
+
// Making activity_id array because there might be more then 1 media linked with activity.
|
902 |
if ( ! isset( $rtmedia_media_type_array[ $rtmedia_media_query[ $i ]->activity_id ] ) || ! is_array( $rtmedia_media_type_array[ $rtmedia_media_query[ $i ]->activity_id ] ) ) {
|
903 |
$rtmedia_media_type_array[ $rtmedia_media_query[ $i ]->activity_id ] = array();
|
904 |
}
|
906 |
array_push( $rtmedia_media_type_array[ $rtmedia_media_query[ $i ]->activity_id ], $rtmedia_media_query[ $i ]->media_type );
|
907 |
}
|
908 |
|
909 |
+
// Updating action.
|
910 |
+
$activity_count = count( $activity_ids );
|
911 |
+
for ( $a = 0; $a < $activity_count; $a ++ ) {
|
912 |
+
// Getting index of activity which is being updated.
|
913 |
$index = $activity_index_array[ $a ];
|
914 |
|
915 |
// Generating user_link with display name.
|
916 |
$user_link = '<a href="' . esc_url( $activities[ $index ]->primary_link ) . '">' . esc_html( $activities[ $index ]->display_name ) . '</a>';
|
917 |
|
918 |
if ( isset( $rtmedia_media_type_array[ $activities[ $index ]->id ] ) ) {
|
919 |
+
// Counting media linked with activity.
|
920 |
$count = count( $rtmedia_media_type_array[ $activities[ $index ]->id ] );
|
921 |
+
// Getting constant with single label or plural label.
|
922 |
$media_const = 'RTMEDIA_' . strtoupper( $rtmedia_media_type_array[ $activities[ $index ]->id ][0] );
|
923 |
if ( $count > 1 ) {
|
924 |
$media_const .= '_PLURAL';
|
932 |
|
933 |
$action = '';
|
934 |
$user = get_userdata( $activities[ $index ]->user_id );
|
935 |
+
// Updating activity based on count.
|
936 |
if ( 1 === $count ) {
|
937 |
+
// translators: 1: user link, 2: media.
|
938 |
+
$action = sprintf( esc_html__( '%1$s added a %2$s', 'buddypress-media' ), $user_link, $media_str );
|
939 |
} else {
|
940 |
+
// Checking all the media linked with activity are of same type.
|
941 |
if ( isset( $rtmedia_media_type_array[ $activities[ $index ]->id ] )
|
942 |
&& ! empty( $rtmedia_media_type_array[ $activities[ $index ]->id ] )
|
943 |
&& count( array_unique( $rtmedia_media_type_array[ $activities[ $index ]->id ] ) ) === 1
|
944 |
) {
|
945 |
+
// translators: 1: user link, 2: media count, 3: media.
|
946 |
+
$action = sprintf( esc_html__( '%1$s added %2$d %3$s', 'buddypress-media' ), $user_link, $count, $media_str );
|
947 |
} else {
|
948 |
+
// translators: 1: user link, 2: media count, 3: rtMedia slug.
|
949 |
+
$action = sprintf( esc_html__( '%1$s added %2$d %3$s', 'buddypress-media' ), $user_link, $count, RTMEDIA_MEDIA_SLUG );
|
950 |
}
|
951 |
}
|
952 |
|
962 |
/**
|
963 |
* Create BP activity when user like and delete associated activity when user remove like.
|
964 |
*
|
965 |
+
* @param RTMediaLike $obj Media liked object to perform activities.
|
966 |
*/
|
967 |
+
public function activity_after_media_like( $obj ) {
|
968 |
if ( class_exists( 'BuddyPress' ) ) {
|
969 |
global $rtmedia_points_media_id;
|
970 |
if ( is_a( $obj, 'RTMediaLike' ) && isset( $obj->action_query->id ) ) {
|
985 |
// If $obj->increase is true than request is to like the media.
|
986 |
if ( $obj->increase ) {
|
987 |
|
988 |
+
// Create activity on media like.
|
989 |
$user = get_userdata( $user_id );
|
990 |
$username = '<a href="' . esc_url( get_rtmedia_user_link( $user_id ) ) . '">' . esc_html( $user->display_name ) . '</a>';
|
991 |
|
999 |
if ( 'group' === $media_obj->context ) {
|
1000 |
$group_data = groups_get_group( array( 'group_id' => $media_obj->context_id ) );
|
1001 |
$group_name = '<a href="' . esc_url( bp_get_group_permalink( $group_data ) ) . '">' . esc_html( $group_data->name ) . '</a>';
|
1002 |
+
// translators: 1: username, 2: media, 3: group name.
|
1003 |
+
$action = sprintf( esc_html__( '%1$s liked a %2$s in the group %3$s', 'buddypress-media' ), $username, $media_str, $group_name );
|
1004 |
} else {
|
1005 |
if ( $user_id === $media_author ) {
|
1006 |
+
// translators: 1: username, 2: media.
|
1007 |
$action = sprintf( esc_html__( '%1$s liked their %2$s', 'buddypress-media' ), $username, $media_str );
|
1008 |
} else {
|
1009 |
$media_author_data = get_userdata( $media_author );
|
1010 |
$media_author_name = '<a href="' . esc_url( get_rtmedia_user_link( $media_author ) ) . '">' . esc_html( $media_author_data->display_name ) . '</a>';
|
1011 |
+
// translators: 1: username, 2: author, 3: media.
|
1012 |
+
$action = sprintf( esc_html__( '%1$s liked %2$s\'s %3$s', 'buddypress-media' ), $username, $media_author_name, $media_str );
|
1013 |
}
|
1014 |
}
|
1015 |
|
1018 |
|
1019 |
// generate activity arguments.
|
1020 |
$activity_args = array(
|
1021 |
+
'user_id' => $user_id,
|
1022 |
+
'action' => $action,
|
1023 |
+
'type' => 'rtmedia_like_activity',
|
1024 |
+
'primary_link' => $primary_link,
|
1025 |
+
'item_id' => $media_id,
|
1026 |
+
'secondary_item_id' => $media_id, // Used for when deleting media when it's enter in group not used when media is add in the main activity.
|
1027 |
);
|
1028 |
|
1029 |
+
// set activity component.
|
1030 |
if ( 'group' === $media_obj->context || 'profile' === $media_obj->context ) {
|
1031 |
$activity_args['component'] = $media_obj->context;
|
1032 |
if ( 'group' === $media_obj->context ) {
|
1035 |
}
|
1036 |
}
|
1037 |
|
1038 |
+
// add BP activity.
|
1039 |
$activity_id = bp_activity_add( $activity_args );
|
1040 |
|
1041 |
+
// add privacy for like activity.
|
1042 |
+
if ( class_exists( 'RTMediaActivityModel' ) && is_rtmedia_privacy_enable() && isset( $media_obj->activity_id ) ) {
|
1043 |
$rtmedia_activity_model = new RTMediaActivityModel();
|
1044 |
+
$rtmedia_activity_model->set_privacy_for_rtmedia_activity( $media_obj->activity_id, $activity_id, $user_id );
|
1045 |
}
|
1046 |
|
1047 |
+
// Store activity id into user meta for reference.
|
1048 |
+
// todo user_attribute.
|
|
|
1049 |
update_user_meta( $user_id, 'rtm-bp-media-like-activity-' . $media_id, $activity_id );
|
1050 |
} else {
|
1051 |
|
1052 |
$meta_key = 'rtm-bp-media-like-activity-' . $media_id;
|
1053 |
// Delete activity when user remove his like.
|
1054 |
+
// todo user_attribute.
|
1055 |
$activity_id = get_user_meta( $user_id, $meta_key, true );
|
1056 |
|
1057 |
if ( ! empty( $activity_id ) ) {
|
1058 |
if ( bp_activity_delete( array( 'id' => $activity_id ) ) ) {
|
1059 |
+
// todo user_attribute.
|
1060 |
delete_user_meta( $user_id, $meta_key );
|
1061 |
}
|
1062 |
}
|
1068 |
/**
|
1069 |
* Create BuddyPress activity when user comment on media
|
1070 |
*
|
1071 |
+
* @param array $params array of parameters.
|
1072 |
*/
|
1073 |
+
public function activity_after_media_comment( $params ) {
|
1074 |
if ( class_exists( 'BuddyPress' ) && function_exists( 'bp_activity_add' ) ) {
|
1075 |
if ( isset( $params['comment_post_ID'] ) ) {
|
1076 |
|
1077 |
+
// get media details.
|
1078 |
$media_model = new RTMediaModel();
|
1079 |
$media_obj = $media_model->get( array( 'media_id' => $params['comment_post_ID'] ) );
|
1080 |
$media_obj = $media_obj[0];
|
1098 |
if ( 'group' === $media_obj->context ) {
|
1099 |
$group_data = groups_get_group( array( 'group_id' => $media_obj->context_id ) );
|
1100 |
$group_name = '<a href="' . esc_url( bp_get_group_permalink( $group_data ) ) . '">' . esc_html( $group_data->name ) . '</a>';
|
1101 |
+
// translators: 1: username, 2: media, 3: group name.
|
1102 |
+
$action = sprintf( esc_html__( '%1$s commented on a %2$s in the group %3$s', 'buddypress-media' ), $username, $media_str, $group_name );
|
1103 |
} else {
|
1104 |
+
|
1105 |
if ( $user_id === $media_author ) {
|
1106 |
+
// translators: 1: username, 2: media.
|
1107 |
$action = sprintf( esc_html__( '%1$s commented on their %2$s', 'buddypress-media' ), $username, $media_str );
|
1108 |
} else {
|
1109 |
$media_author_data = get_userdata( $media_author );
|
1110 |
$media_author_name = '<a href="' . esc_url( get_rtmedia_user_link( $media_author ) ) . '">' . esc_html( $media_author_data->display_name ) . '</a>';
|
1111 |
+
// translators: 1: username, 2: author, 3: media.
|
1112 |
+
$action = sprintf( esc_html__( '%1$s commented on %2$s\'s %3$s', 'buddypress-media' ), $username, $media_author_name, $media_str );
|
1113 |
}
|
1114 |
}
|
1115 |
|
1116 |
$activity_content = $params['comment_content'];
|
1117 |
+
$comment_media = false;
|
1118 |
$comment_media_id = false;
|
1119 |
|
1120 |
+
$post_action = sanitize_text_field( filter_input( INPUT_POST, 'action', FILTER_SANITIZE_STRING ) );
|
1121 |
+
$post_comment_content = sanitize_text_field( filter_input( INPUT_POST, 'comment_content', FILTER_SANITIZE_STRING ) );
|
1122 |
+
|
1123 |
+
// if activity is add from comment media.
|
1124 |
+
if ( ! empty( $post_comment_content ) || ! empty( $post_action ) ) {
|
1125 |
|
1126 |
+
if ( ! empty( $post_action ) && 'new_activity_comment' === $post_action ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
1127 |
|
1128 |
+
remove_action( 'bp_activity_content_before_save', 'rtmedia_bp_activity_comment_content_callback', 1001, 1 );
|
|
|
|
|
|
|
1129 |
|
1130 |
+
// comment content.
|
1131 |
+
$comment_content = sanitize_text_field( filter_input( INPUT_POST, 'content', FILTER_SANITIZE_STRING ) );
|
1132 |
+
} elseif ( ! empty( $post_comment_content ) ) {
|
1133 |
+
// comment content.
|
1134 |
+
$comment_content = $post_comment_content;
|
1135 |
+
}
|
1136 |
|
1137 |
+
// is comment is empty then add content content space.
|
1138 |
+
if ( strstr( $comment_content, 'nbsp' ) ) {
|
1139 |
+
$comment_content = ' ';
|
1140 |
+
}
|
1141 |
|
1142 |
+
// if comment has comment media then create new html for it.
|
1143 |
+
$rtmedia_attached_files = filter_input( INPUT_POST, 'rtMedia_attached_files', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
|
|
|
|
|
|
|
|
|
|
|
|
|
1144 |
|
1145 |
+
// check media should be in array format and is not empty to.
|
1146 |
+
if ( ! empty( $rtmedia_attached_files ) && class_exists( 'RTMediaActivity' ) && is_array( $rtmedia_attached_files ) ) {
|
1147 |
+
$comment_media = true;
|
1148 |
+
$comment_media_id = $rtmedia_attached_files[0];
|
1149 |
+
$obj_comment = new RTMediaActivity( $rtmedia_attached_files[0], 0, $comment_content );
|
1150 |
+
$comment_content = $obj_comment->create_activity_html();
|
1151 |
+
}
|
1152 |
|
1153 |
+
// add the new content to the activity.
|
1154 |
+
$activity_content = $comment_content;
|
1155 |
+
}
|
1156 |
|
1157 |
+
$wp_comment_id = $params['comment_id'];
|
1158 |
|
1159 |
+
// prepare activity arguments.
|
1160 |
$activity_args = array(
|
1161 |
+
'user_id' => $user_id,
|
1162 |
+
'action' => $action,
|
1163 |
+
'content' => $activity_content,
|
1164 |
+
'type' => 'rtmedia_comment_activity',
|
1165 |
+
'primary_link' => $primary_link,
|
1166 |
+
'item_id' => $media_id,
|
1167 |
+
'secondary_item_id' => $wp_comment_id,
|
1168 |
);
|
1169 |
|
1170 |
+
// set activity component.
|
1171 |
if ( 'group' === $media_obj->context || 'profile' === $media_obj->context ) {
|
1172 |
$activity_args['component'] = $media_obj->context;
|
1173 |
if ( 'group' === $media_obj->context ) {
|
1176 |
}
|
1177 |
}
|
1178 |
|
1179 |
+
// create BuddyPress activity.
|
1180 |
remove_filter( 'bp_activity_content_before_save', array( $this, 'bp_activity_content_before_save' ) );
|
1181 |
$activity_id = bp_activity_add( $activity_args );
|
1182 |
|
1183 |
+
// save the profile activity id in the media meta.
|
1184 |
+
if ( ! empty( $comment_media ) && ! empty( $comment_media_id ) && ! empty( $activity_id ) ) {
|
1185 |
add_rtmedia_meta( $comment_media_id, 'rtmedia_comment_media_profile_id', $activity_id );
|
1186 |
}
|
1187 |
|
1188 |
+
// add privacy for like activity.
|
1189 |
+
if ( class_exists( 'RTMediaActivityModel' ) && is_rtmedia_privacy_enable() && isset( $media_obj->activity_id ) ) {
|
1190 |
$rtmedia_activity_model = new RTMediaActivityModel();
|
1191 |
+
$rtmedia_activity_model->set_privacy_for_rtmedia_activity( $media_obj->activity_id, $activity_id, $user_id );
|
1192 |
}
|
1193 |
|
1194 |
+
// Store activity id into user meta for reference.
|
1195 |
+
// todo user_attribute.
|
1196 |
update_user_meta( $user_id, 'rtm-bp-media-comment-activity-' . $media_id . '-' . $wp_comment_id, $activity_id );
|
1197 |
|
1198 |
+
if ( function_exists( 'rtmedia_get_original_comment_media_content' ) ) {
|
1199 |
+
// get the original content of media.
|
1200 |
$original_content = rtmedia_get_original_comment_media_content();
|
1201 |
+
// save the original content in the meta fields.
|
1202 |
bp_activity_update_meta( $activity_id, 'bp_activity_text', $original_content );
|
|
|
1203 |
}
|
1204 |
}
|
1205 |
}
|
1209 |
/**
|
1210 |
* Remove activity when comment on media is deleted
|
1211 |
*
|
1212 |
+
* @param int $comment_id comment id to delete activity.
|
1213 |
*/
|
1214 |
+
public function remove_activity_after_media_comment_delete( $comment_id ) {
|
1215 |
if ( ! empty( $comment_id ) && function_exists( 'bp_activity_delete' ) ) {
|
1216 |
|
1217 |
+
// get comment details from comment id.
|
1218 |
$comment = get_comment( $comment_id );
|
1219 |
$user_id = $comment->user_id;
|
1220 |
|
1227 |
$meta_key = 'rtm-bp-media-comment-activity-' . $media_obj->id . '-' . $comment_id;
|
1228 |
|
1229 |
// Delete activity when user remove his comment.
|
1230 |
+
// todo user_attribute.
|
1231 |
$activity_id = get_user_meta( $user_id, $meta_key, true );
|
1232 |
|
1233 |
if ( ! empty( $activity_id ) ) {
|
1234 |
if ( bp_activity_delete( array( 'id' => $activity_id ) ) ) {
|
1235 |
+
// todo user_attribute.
|
1236 |
delete_user_meta( $user_id, $meta_key );
|
1237 |
}
|
1238 |
}
|
1244 |
/**
|
1245 |
* To check whether user can delete the activity or not
|
1246 |
*
|
1247 |
+
* @access public
|
1248 |
*
|
1249 |
+
* @since 4.0.2
|
1250 |
*
|
1251 |
+
* @param bool $can_delete Whether the user can delete the item.
|
1252 |
+
* @param object $activity Current activity item object.
|
1253 |
*
|
1254 |
+
* @return bool $can_delete
|
1255 |
*/
|
1256 |
public function rtm_bp_activity_user_can_delete( $can_delete, $activity ) {
|
1257 |
|
1266 |
/**
|
1267 |
* To check user has access to view single activity
|
1268 |
*
|
1269 |
+
* @access public
|
1270 |
*
|
1271 |
+
* @since 4.0.2
|
1272 |
*
|
1273 |
+
* @param bool|array $args array of arguments.
|
1274 |
*
|
1275 |
+
* @return bool $has_access
|
1276 |
*/
|
1277 |
public function rtm_bp_activity_permalink_access( $args ) {
|
1278 |
|
1279 |
$bp = buddypress();
|
1280 |
|
1281 |
// Get the activity details.
|
1282 |
+
$activity = bp_activity_get_specific(
|
1283 |
+
array(
|
1284 |
+
'activity_ids' => bp_current_action(),
|
1285 |
+
'show_hidden' => true,
|
1286 |
+
'spam' => 'ham_only',
|
1287 |
+
)
|
1288 |
+
);
|
1289 |
|
1290 |
// 404 if activity does not exist
|
1291 |
if ( empty( $activity['activities'][0] ) || bp_action_variables() ) {
|
1300 |
$has_access = true;
|
1301 |
|
1302 |
// If activity is from a group, do an extra cap check.
|
1303 |
+
if ( isset( $bp->groups->id ) && $activity->component === $bp->groups->id ) {
|
1304 |
// Activity is from a group, but groups is currently disabled.
|
1305 |
if ( ! bp_is_active( 'groups' ) ) {
|
1306 |
bp_do_404();
|
1308 |
return;
|
1309 |
}
|
1310 |
|
1311 |
+
$group = groups_get_group( array( 'group_id' => $activity->item_id ) );
|
1312 |
// Check to see if the group is not public, if so, check the
|
1313 |
// user has access to see this activity.
|
1314 |
+
if ( ! empty( $group ) ) {
|
1315 |
// Group is not public.
|
1316 |
+
if ( 'public' !== $group->status ) {
|
1317 |
// User is not a member of group.
|
1318 |
if ( ! groups_is_user_member( bp_loggedin_user_id(), $group->id ) ) {
|
1319 |
$has_access = false;
|
app/main/controllers/api/RTMediaApiLogin.php
CHANGED
@@ -1,14 +1,24 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
/**
|
|
|
|
|
|
|
4 |
* @author Umesh Kumar<umeshsingla05@gmail.com>
|
5 |
*/
|
|
|
6 |
if ( ! class_exists( 'RTDBModel' ) ) {
|
7 |
return;
|
8 |
}
|
|
|
|
|
|
|
|
|
9 |
class RTMediaApiLogin extends RTDBModel {
|
10 |
|
11 |
-
|
|
|
|
|
|
|
12 |
parent::__construct( 'rtm_api' );
|
13 |
}
|
14 |
}
|
1 |
<?php
|
|
|
2 |
/**
|
3 |
+
* Initialize RTDBModel with rtm_api table.
|
4 |
+
*
|
5 |
+
* @package rtMedia
|
6 |
* @author Umesh Kumar<umeshsingla05@gmail.com>
|
7 |
*/
|
8 |
+
|
9 |
if ( ! class_exists( 'RTDBModel' ) ) {
|
10 |
return;
|
11 |
}
|
12 |
+
|
13 |
+
/**
|
14 |
+
* Class to initialize RTDBModel with rtm_api table.
|
15 |
+
*/
|
16 |
class RTMediaApiLogin extends RTDBModel {
|
17 |
|
18 |
+
/**
|
19 |
+
* RTMediaApiLogin constructor.
|
20 |
+
*/
|
21 |
+
public function __construct() {
|
22 |
parent::__construct( 'rtm_api' );
|
23 |
}
|
24 |
}
|
app/main/controllers/api/RTMediaJsonApi.php
CHANGED
@@ -1,33 +1,160 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
/**
|
4 |
-
*
|
|
|
|
|
5 |
* @author Umesh Kumar <umeshsingla05@gmail.com>
|
6 |
*/
|
|
|
|
|
|
|
|
|
7 |
class RTMediaJsonApi {
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
if ( ! class_exists( 'RTMediaApiLogin' ) || ! class_exists( 'RTMediaJsonApiFunctions' ) ) {
|
32 |
return;
|
33 |
}
|
@@ -36,8 +163,12 @@ class RTMediaJsonApi {
|
|
36 |
add_action( 'wp_ajax_rtmedia_api', array( $this, 'rtmedia_api_process_request' ) );
|
37 |
}
|
38 |
|
39 |
-
|
|
|
|
|
|
|
40 |
$rtmedia_enable_json_api = false;
|
|
|
41 |
if ( function_exists( 'rtmedia_get_site_option' ) ) {
|
42 |
$rtmedia_options = rtmedia_get_site_option( 'rtmedia-options' );
|
43 |
if ( ! empty( $rtmedia_options ) ) {
|
@@ -46,35 +177,37 @@ class RTMediaJsonApi {
|
|
46 |
}
|
47 |
}
|
48 |
}
|
|
|
49 |
if ( ! $rtmedia_enable_json_api ) {
|
50 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $this->ec_api_disabled, $this->msg_api_disabled ) );
|
51 |
}
|
52 |
-
|
|
|
53 |
if ( empty( $method ) ) {
|
54 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $this->ec_method_missing, $this->msg_method_missing ) );
|
55 |
}
|
|
|
56 |
if ( ! class_exists( 'BuddyPress' ) ) {
|
57 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $this->ec_bp_missing, $this->msg_bp_missing ) );
|
58 |
}
|
59 |
$this->rtmediajsonapifunction = new RTMediaJsonApiFunctions();
|
60 |
-
$token = filter_input( INPUT_POST, 'token', FILTER_SANITIZE_STRING );
|
61 |
|
62 |
if ( ! empty( $token ) ) {
|
63 |
$this->rtmediajsonapifunction->rtmedia_api_verfiy_token();
|
64 |
$this->user_id = $this->rtmediajsonapifunction->rtmedia_api_get_user_id_from_token( $token );
|
65 |
-
//add filter
|
66 |
add_filter( 'rtmedia_current_user', array( $this->rtmediajsonapifunction, 'rtmedia_api_set_user_id' ) );
|
67 |
}
|
68 |
-
//Process Request
|
69 |
|
|
|
70 |
switch ( $method ) {
|
71 |
-
|
72 |
case 'wp_login':
|
73 |
$this->rtmedia_api_process_wp_login_request();
|
74 |
break;
|
75 |
case 'wp_logout':
|
76 |
-
//todo implement this function rtmedia_api_process_wp_logout_request if needed
|
77 |
-
|
78 |
break;
|
79 |
case 'wp_register':
|
80 |
$this->rtmedia_api_process_wp_register_request();
|
@@ -123,16 +256,16 @@ class RTMediaJsonApi {
|
|
123 |
}
|
124 |
|
125 |
/**
|
126 |
-
* Returns a json object
|
127 |
*
|
128 |
-
* @param string
|
129 |
-
* @param int
|
130 |
-
* @param string
|
131 |
-
* @param bool|array $data
|
132 |
*
|
133 |
-
* @return bool
|
134 |
*/
|
135 |
-
function rtmedia_api_response_object( $status, $status_code, $message, $data = false ) {
|
136 |
if ( '' === $status || empty( $status_code ) || empty( $message ) ) {
|
137 |
return false;
|
138 |
}
|
@@ -140,16 +273,22 @@ class RTMediaJsonApi {
|
|
140 |
if ( ob_get_contents() ) {
|
141 |
ob_end_clean();
|
142 |
}
|
143 |
-
|
144 |
$rtmapilogin = new RTMediaApiLogin();
|
145 |
-
$token = filter_input( INPUT_POST, 'token', FILTER_SANITIZE_STRING );
|
146 |
$login_details = array( 'last_access' => current_time( 'mysql' ) );
|
|
|
147 |
if ( ! empty( $token ) ) {
|
148 |
-
$where = array(
|
|
|
|
|
|
|
149 |
}
|
|
|
150 |
if ( ! empty( $where ) ) {
|
151 |
$rtmapilogin->update( $login_details, $where );
|
152 |
}
|
|
|
153 |
$response_object = array();
|
154 |
$response_object['status'] = $status;
|
155 |
$response_object['status_code'] = $status_code;
|
@@ -160,10 +299,10 @@ class RTMediaJsonApi {
|
|
160 |
}
|
161 |
|
162 |
/**
|
163 |
-
* Takes username and password, if
|
164 |
*/
|
165 |
-
function rtmedia_api_process_wp_login_request() {
|
166 |
-
//Login Errors and Messages
|
167 |
$ec_user_pass_missing = 200001;
|
168 |
$msg_user_pass_missing = esc_html__( 'username/password empty', 'buddypress-media' );
|
169 |
|
@@ -175,30 +314,33 @@ class RTMediaJsonApi {
|
|
175 |
|
176 |
$ec_login_success = 200004;
|
177 |
$msg_login_success = esc_html__( 'login success', 'buddypress-media' );
|
178 |
-
$username = filter_input( INPUT_POST, 'username', FILTER_SANITIZE_STRING );
|
179 |
-
$password = filter_input( INPUT_POST, 'password', FILTER_SANITIZE_STRING );
|
180 |
|
181 |
if ( empty( $username ) || empty( $password ) ) {
|
182 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $ec_user_pass_missing, $msg_user_pass_missing ) );
|
183 |
} else {
|
184 |
$user_login = wp_authenticate( trim( $username ), trim( $password ) );
|
|
|
185 |
if ( is_wp_error( $user_login ) ) {
|
186 |
|
187 |
$incorrect_password = ! empty( $user_login->errors['incorrect_password'] ) ? true : false;
|
188 |
$incorrect_username = ! empty( $user_login->errors['invalid_username'] ) ? true : false;
|
|
|
189 |
if ( $incorrect_password ) {
|
190 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $ec_incorrect_pass, $msg_incorrect_pass ) );
|
191 |
} elseif ( $incorrect_username ) {
|
192 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $ec_incorrect_username, $msg_incorrect_username ) );
|
193 |
}
|
194 |
} else {
|
|
|
195 |
$access_token = $this->rtmediajsonapifunction->rtmedia_api_get_user_token( $user_login->ID, $user_login->data->user_login );
|
196 |
$data = array(
|
197 |
'access_token' => $access_token,
|
198 |
);
|
199 |
$rtmapilogin = new RTMediaApiLogin();
|
200 |
|
201 |
-
//update all tokens for user to
|
202 |
$rtmapilogin->update( array( 'status' => 'FALSE' ), array( 'user_id' => $user_login->ID ) );
|
203 |
$remote_addr = rtm_get_server_var( 'REMOTE_ADDR', 'FILTER_VALIDATE_IP' );
|
204 |
$login_details = array(
|
@@ -214,11 +356,11 @@ class RTMediaJsonApi {
|
|
214 |
}
|
215 |
|
216 |
/**
|
217 |
-
*
|
218 |
* requires signup_* => display_name, username, password, confirm password, location,
|
219 |
*/
|
220 |
-
function rtmedia_api_process_wp_register_request() {
|
221 |
-
//Registration errors and messages
|
222 |
$ec_register_fields_missing = 300001;
|
223 |
$msg_register_fields_missing = esc_html__( 'fields empty', 'buddypress-media' );
|
224 |
|
@@ -231,42 +373,41 @@ class RTMediaJsonApi {
|
|
231 |
$ec_username_exists = 300004;
|
232 |
$msg_username_exists = esc_html__( 'username already registered', 'buddypress-media' );
|
233 |
|
234 |
-
$ec_email_exists
|
235 |
-
$
|
236 |
|
237 |
$ec_user_insert_success = 300007;
|
238 |
$msg_user_insert_success = esc_html__( 'new user created', 'buddypress-media' );
|
239 |
|
240 |
$registration_fields = array( 'username', 'email', 'password', 'password_confirm' );
|
241 |
-
//fields empty field_1, field_4
|
242 |
-
$field_1 = filter_input( INPUT_POST, 'field_1', FILTER_SANITIZE_STRING );
|
243 |
|
244 |
if ( empty( $field_1 ) ) {
|
245 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $ec_register_fields_missing, $msg_register_fields_missing ) );
|
246 |
}
|
|
|
247 |
foreach ( $registration_fields as $field_name ) {
|
248 |
-
$field_signup = filter_input( INPUT_POST, 'signup_' . $field_name, FILTER_SANITIZE_STRING );
|
249 |
if ( empty( $field_signup ) ) {
|
250 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $ec_register_fields_missing, $msg_register_fields_missing ) );
|
251 |
}
|
252 |
}
|
|
|
253 |
$signup_email = filter_input( INPUT_POST, 'signup_email', FILTER_VALIDATE_EMAIL );
|
254 |
-
$signup_username = filter_input( INPUT_POST, 'signup_username', FILTER_SANITIZE_STRING );
|
255 |
-
$signup_password = filter_input( INPUT_POST, 'signup_password', FILTER_SANITIZE_STRING );
|
256 |
-
$signup_password_confirm = filter_input( INPUT_POST, 'signup_password_confirm', FILTER_SANITIZE_STRING );
|
257 |
|
258 |
-
//incorrect email
|
259 |
if ( ! is_email( $signup_email ) ) {
|
260 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $ec_invalid_email, $msg_invalid_email ) );
|
261 |
-
} //Passwords do not match
|
262 |
-
elseif ( $signup_password !== $signup_password_confirm ) {
|
263 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $ec_pass_do_not_match, $msg_pass_do_not_match ) );
|
264 |
-
} //Username already registered
|
265 |
-
elseif ( username_exists( $signup_username ) ) {
|
266 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $ec_username_exists, $msg_username_exists ) );
|
267 |
-
} //email already registered
|
268 |
-
|
269 |
-
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $ec_email_exists, $msg_email_existsh ) );
|
270 |
} else {
|
271 |
$userdata = array(
|
272 |
'user_login' => sanitize_user( $signup_username ),
|
@@ -278,7 +419,7 @@ class RTMediaJsonApi {
|
|
278 |
if ( ! is_wp_error( $user_id ) ) {
|
279 |
echo esc_html( xprofile_get_field_id_from_name( 'field_1' ) );
|
280 |
xprofile_set_field_data( 1, $user_id, sanitize_text_field( $field_1 ) );
|
281 |
-
//todo user attr
|
282 |
update_user_meta( $user_id, 'register_source', 'site_api' );
|
283 |
echo wp_json_encode( $this->rtmedia_api_response_object( 'TRUE', $ec_user_insert_success, $msg_user_insert_success ) );
|
284 |
wp_die();
|
@@ -290,11 +431,12 @@ class RTMediaJsonApi {
|
|
290 |
|
291 |
/**
|
292 |
* Sends a reset link to user email
|
|
|
293 |
* @global type $wpdb
|
294 |
*/
|
295 |
-
function rtmedia_api_process_wp_forgot_password_request() {
|
296 |
global $wpdb;
|
297 |
-
//Registration errors and messages
|
298 |
$ec_email_missing = 500001;
|
299 |
$msg_email_missing = esc_html__( 'email empty', 'buddypress-media' );
|
300 |
|
@@ -303,44 +445,48 @@ class RTMediaJsonApi {
|
|
303 |
|
304 |
$ec_email_sent = 500003;
|
305 |
$msg_email_sent = esc_html__( 'reset link sent', 'buddypress-media' );
|
306 |
-
$user_login = filter_input( INPUT_POST, 'user_login', FILTER_SANITIZE_STRING );
|
307 |
|
308 |
if ( empty( $user_login ) ) {
|
309 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $ec_email_missing, $msg_email_missing ) );
|
310 |
}
|
311 |
|
312 |
if ( username_exists( $user_login ) ) {
|
313 |
-
$
|
314 |
-
|
315 |
-
|
316 |
-
elseif ( email_exists( $user_login ) ) {
|
317 |
-
$user_exists = true;
|
318 |
-
$user = get_user_by( 'email', sanitize_email( $user_login ) );
|
319 |
} else {
|
320 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $ec_username_email_not_registered, $msg_username_email_not_registered ) );
|
321 |
}
|
|
|
322 |
$user_login = $user->data->user_login;
|
323 |
$user_email = $user->data->user_email;
|
324 |
|
325 |
// Generate something random for a key...
|
326 |
$key = wp_generate_password( 20, false );
|
327 |
do_action( 'retrieve_password_key', $user_login, $key );
|
328 |
-
|
|
|
329 |
// Now insert the key, hashed, into the DB.
|
330 |
if ( empty( $wp_hasher ) ) {
|
331 |
require_once ABSPATH . 'wp-includes/class-phpass.php';
|
332 |
$wp_hasher = new PasswordHash( 8, true );
|
333 |
}
|
|
|
334 |
$hashed = $wp_hasher->HashPassword( $key );
|
335 |
$wpdb->update( $wpdb->users, array( 'user_activation_key' => $hashed ), array( 'user_login' => sanitize_user( $user_login ) ) );
|
336 |
|
337 |
-
//create email message
|
338 |
-
$message
|
339 |
$message .= esc_url( get_option( 'siteurl' ) ) . "\r\n\r\n";
|
|
|
|
|
340 |
$message .= sprintf( esc_html__( 'Username: %s', 'buddypress-media' ), $user_login ) . "\r\n\r\n";
|
341 |
$message .= esc_html__( 'To reset your password visit the following address, otherwise just ignore this email and nothing will happen.', 'buddypress-media' ) . "\r\n\r\n";
|
342 |
$message .= '<' . esc_url( network_site_url( "wp-login.php?action=rp&key=$key&login=" . rawurlencode( $user_login ), 'login' ) ) . ">\r\n";
|
343 |
-
|
|
|
|
|
344 |
if ( false === wp_mail( $user_email, sprintf( esc_html__( '[%s] Password Reset', 'buddypress-media' ), get_option( 'blogname' ) ), $message ) ) {
|
345 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $this->ec_server_error, $this->msg_server_error ) );
|
346 |
} else {
|
@@ -350,18 +496,19 @@ class RTMediaJsonApi {
|
|
350 |
|
351 |
/**
|
352 |
* Sends a reset link to user email
|
|
|
353 |
* @global type $wpdb
|
354 |
*/
|
355 |
-
function rtmedia_api_process_bp_get_activities_request() {
|
356 |
$this->rtmediajsonapifunction->rtmedia_api_verfiy_token();
|
357 |
-
//Feed Errors
|
358 |
$ec_latest_feed = 700001;
|
359 |
$msg_latest_feed = esc_html__( 'bp activities', 'buddypress-media' );
|
360 |
|
361 |
$ec_my_looks = 700002;
|
362 |
$msg_my_looks = esc_html__( 'user activities', 'buddypress-media' );
|
363 |
|
364 |
-
//Fetch user id from token
|
365 |
$activity_user_id = filter_input( INPUT_POST, 'activity_user_id', FILTER_VALIDATE_INT );
|
366 |
$per_page = filter_input( INPUT_POST, 'per_page', FILTER_VALIDATE_INT );
|
367 |
|
@@ -379,26 +526,24 @@ class RTMediaJsonApi {
|
|
379 |
|
380 |
/**
|
381 |
* Post comment on activity_id or media_id
|
|
|
382 |
* @global type $this ->msg_server_error
|
383 |
* @global int $this ->ec_server_error
|
384 |
* @global int $this ->ec_invalid_media_id
|
385 |
* @global type $this ->msg_invalid_media_id
|
386 |
*/
|
387 |
-
function rtmedia_api_process_add_rtmedia_comment_request() {
|
388 |
|
389 |
$this->rtmediajsonapifunction->rtmedia_api_verfiy_token();
|
390 |
$this->rtmediajsonapifunction->rtmedia_api_media_activity_id_missing();
|
391 |
-
//Post comment errors
|
392 |
$ec_comment_content_missing = 800001;
|
393 |
$msg_comment_content_missing = esc_html__( 'comment content missing', 'buddypress-media' );
|
394 |
|
395 |
$ec_comment_posted = 800002;
|
396 |
$msg_comment_posted = esc_html__( 'comment posted', 'buddypress-media' );
|
397 |
|
398 |
-
|
399 |
-
$user_data = get_userdata( $this->user_id );
|
400 |
-
|
401 |
-
$content = filter_input( INPUT_POST, 'content', FILTER_SANITIZE_STRING );
|
402 |
|
403 |
if ( empty( $content ) ) {
|
404 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $ec_comment_content_missing, $msg_comment_content_missing ) );
|
@@ -407,18 +552,22 @@ class RTMediaJsonApi {
|
|
407 |
if ( empty( $activity_id ) && ! empty( $media_id ) ) {
|
408 |
$activity_id = $this->rtmediajsonapifunction->rtmedia_api_activityid_from_mediaid( $media_id );
|
409 |
}
|
|
|
410 |
if ( empty( $activity_id ) ) {
|
411 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $this->ec_invalid_media_id, $this->msg_invalid_media_id ) );
|
412 |
}
|
|
|
413 |
$args = array(
|
414 |
'content' => $content,
|
415 |
'activity_id' => intval( $activity_id ),
|
416 |
'user_id' => intval( $this->user_id ),
|
417 |
'parent_id' => false,
|
418 |
);
|
|
|
419 |
if ( function_exists( 'bp_activity_new_comment' ) ) {
|
420 |
$comment_id = bp_activity_new_comment( $args );
|
421 |
}
|
|
|
422 |
if ( isset( $comment_id ) ) {
|
423 |
wp_send_json( $this->rtmedia_api_response_object( 'TRUE', $ec_comment_posted, $msg_comment_posted ) );
|
424 |
} else {
|
@@ -428,16 +577,17 @@ class RTMediaJsonApi {
|
|
428 |
|
429 |
/**
|
430 |
* Like/Unlike by media_id or activity_id
|
|
|
431 |
* @global int $this ->ec_server_error
|
432 |
* @global type $this ->msg_server_error
|
433 |
* @global int $this ->ec_invalid_media_id
|
434 |
* @global type $this ->msg_invalid_media_id
|
435 |
*/
|
436 |
-
function rtmedia_api_process_like_media_request() {
|
437 |
$this->rtmediajsonapifunction->rtmedia_api_verfiy_token();
|
438 |
$this->rtmediajsonapifunction->rtmedia_api_media_activity_id_missing();
|
439 |
|
440 |
-
//Like errors
|
441 |
$ec_already_liked = 900001;
|
442 |
$msg_already_liked = esc_html__( 'unliked media', 'buddypress-media' );
|
443 |
|
@@ -454,7 +604,7 @@ class RTMediaJsonApi {
|
|
454 |
}
|
455 |
|
456 |
$action = 'like';
|
457 |
-
// Like or Unlike
|
458 |
if ( ! rtmedia_media_id( $media_id ) ) {
|
459 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $this->ec_invalid_media_id, $this->msg_invalid_media_id ) );
|
460 |
}
|
@@ -490,14 +640,17 @@ class RTMediaJsonApi {
|
|
490 |
$insert_id = $rtmediainteraction->insert( $columns );
|
491 |
$increase = true;
|
492 |
}
|
|
|
493 |
if ( $increase ) {
|
494 |
$like_count_old ++;
|
495 |
} elseif ( ! $increase ) {
|
496 |
$like_count_old --;
|
497 |
}
|
|
|
498 |
if ( $like_count_old < 0 ) {
|
499 |
$like_count_old = 0;
|
500 |
}
|
|
|
501 |
$data = array( 'like_count' => $like_count_old );
|
502 |
if ( ! empty( $insert_id ) && isset( $rtmedialike ) ) {
|
503 |
$rtmedialike->model->update( array( 'likes' => $like_count_old ), array( 'id' => $media_id ) );
|
@@ -517,20 +670,18 @@ class RTMediaJsonApi {
|
|
517 |
|
518 |
/**
|
519 |
* Fetch Comments by media id
|
|
|
520 |
* @global type $wpdb
|
521 |
*/
|
522 |
-
function rtmedia_api_process_get_rtmedia_comments_request() {
|
523 |
$this->rtmediajsonapifunction->rtmedia_api_verfiy_token();
|
524 |
-
//Errors Fetching comment
|
525 |
$ec_no_comments = 800003;
|
526 |
$msg_no_comments = esc_html__( 'no comments', 'buddypress-media' );
|
527 |
|
528 |
$ec_media_comments = 800004;
|
529 |
$msg_media_comments = esc_html__( 'media comments', 'buddypress-media' );
|
530 |
|
531 |
-
$ec_my_comments = 800005;
|
532 |
-
$msg_my_comments = esc_html__( 'my comments', 'buddypress-media' );
|
533 |
-
|
534 |
$media_id = filter_input( INPUT_POST, 'media_id', FILTER_SANITIZE_NUMBER_INT );
|
535 |
|
536 |
global $wpdb;
|
@@ -562,19 +713,21 @@ class RTMediaJsonApi {
|
|
562 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $ec_no_comments, $msg_no_comments ) );
|
563 |
}
|
564 |
}
|
565 |
-
|
|
|
566 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $ec_no_comments, $msg_no_comments ) );
|
567 |
}
|
568 |
|
569 |
/**
|
570 |
* Fetch Likes by media id
|
|
|
571 |
* @global type $wpdb
|
572 |
*/
|
573 |
-
function rtmedia_api_process_get_likes_rtmedia_request() {
|
574 |
$this->rtmediajsonapifunction->rtmedia_api_verfiy_token();
|
575 |
$this->rtmediajsonapifunction->rtmedia_api_media_activity_id_missing();
|
576 |
-
|
577 |
-
//Errors Fetching Likes
|
578 |
$ec_no_likes = 900003;
|
579 |
$msg_no_likes = esc_html__( 'no likes', 'buddypress-media' );
|
580 |
|
@@ -582,13 +735,16 @@ class RTMediaJsonApi {
|
|
582 |
$msg_media_likes = esc_html__( 'media likes', 'buddypress-media' );
|
583 |
$media_id = filter_input( INPUT_POST, 'media_id', FILTER_SANITIZE_NUMBER_INT );
|
584 |
$media_likes = filter_input( INPUT_POST, 'media_likes', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
|
585 |
-
$media_like_users = filter_input( INPUT_POST, 'media_like_users',FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
|
|
|
586 |
if ( isset( $media_likes['user'] ) && ! is_array( $media_likes['user'] ) ) {
|
587 |
$media_likes['user'] = array();
|
588 |
}
|
|
|
589 |
if ( empty( $media_likes ) || ! is_array( $media_likes ) ) {
|
590 |
$media_likes = array();
|
591 |
}
|
|
|
592 |
if ( empty( $media_like_users ) || ! is_array( $media_like_users ) ) {
|
593 |
$media_like_users = array();
|
594 |
}
|
@@ -622,12 +778,13 @@ class RTMediaJsonApi {
|
|
622 |
/**
|
623 |
* Delete comment by activity id or media id
|
624 |
*/
|
625 |
-
function rtmedia_api_process_remove_comment_request() {
|
|
|
626 |
global $wpdb;
|
627 |
$this->rtmediajsonapifunction->rtmedia_api_verfiy_token();
|
628 |
$this->rtmediajsonapifunction->rtmedia_api_media_activity_id_missing();
|
629 |
-
//Errors Deleting comment
|
630 |
|
|
|
631 |
$ec_comment_not_found = 800007;
|
632 |
$msg_comment_not_found = esc_html__( 'invalid comment/media id', 'buddypress-media' );
|
633 |
|
@@ -643,11 +800,11 @@ class RTMediaJsonApi {
|
|
643 |
if ( empty( $comment_id ) ) {
|
644 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $ec_no_comment_id, $msg_no_comment_id ) );
|
645 |
}
|
646 |
-
$id = rtmedia_media_id( $media_id );
|
647 |
-
$sql = $wpdb->prepare( "SELECT * FROM {$wpdb->comments} WHERE comment_ID = %d AND comment_post_ID = %d AND user_id = %d limit 100", $comment_id, $id, $this->user_id );
|
648 |
|
649 |
-
$
|
650 |
-
|
|
|
|
|
651 |
if ( ! empty( $comments ) ) {
|
652 |
$comment = new RTMediaComment();
|
653 |
|
@@ -656,7 +813,12 @@ class RTMediaJsonApi {
|
|
656 |
if ( ! empty( $activity_id ) ) {
|
657 |
$activity_deleted = bp_activity_delete_comment( $activity_id, $comment_id );
|
658 |
|
659 |
-
$delete = bp_activity_delete(
|
|
|
|
|
|
|
|
|
|
|
660 |
|
661 |
}
|
662 |
$comment_deleted = $comment->rtmedia_comment_model->delete( $comment_id );
|
@@ -671,18 +833,19 @@ class RTMediaJsonApi {
|
|
671 |
}
|
672 |
}
|
673 |
|
674 |
-
|
|
|
|
|
|
|
675 |
$this->rtmediajsonapifunction->rtmedia_api_verfiy_token();
|
676 |
-
//Errors
|
677 |
$ec_no_fields = 400001;
|
678 |
$msg_no_fields = esc_html__( 'no profile found', 'buddypress-media' );
|
679 |
|
680 |
$ec_profile_fields = 400002;
|
681 |
$msg_profile_fields = esc_html__( 'profile fields', 'buddypress-media' );
|
682 |
|
683 |
-
$profile_fields
|
684 |
-
$user_id = $loggedin_user_id = '';
|
685 |
-
|
686 |
$user_id = filter_input( INPUT_POST, 'user_id', FILTER_SANITIZE_NUMBER_INT );
|
687 |
$loggedin_user_id = filter_input( INPUT_POST, 'loggedin_user_id', FILTER_SANITIZE_NUMBER_INT );
|
688 |
|
@@ -691,10 +854,12 @@ class RTMediaJsonApi {
|
|
691 |
} else {
|
692 |
$loggedin_user_id = $this->user_id;
|
693 |
}
|
|
|
694 |
$user = get_userdata( $user_id );
|
695 |
if ( empty( $user ) ) {
|
696 |
wp_send_json( $this->rtmedia_api_response_object( 'TRUE', $ec_no_fields, $msg_no_fields ) );
|
697 |
}
|
|
|
698 |
$user_data = $this->rtmediajsonapifunction->rtmedia_api_user_data_from_id( $user_id, 250, 250, 'full' );
|
699 |
$profile_fields['id'] = $user_id;
|
700 |
$profile_fields['avatar']['src'] = esc_url( $user_data['avatar'] );
|
@@ -702,16 +867,18 @@ class RTMediaJsonApi {
|
|
702 |
$profile_fields['avatar']['height'] = 250;
|
703 |
|
704 |
if ( bp_has_profile( array( 'user_id' => $user_id ) ) ) :
|
705 |
-
while ( bp_profile_groups() ) :
|
|
|
706 |
|
707 |
if ( bp_profile_group_has_fields() ) :
|
708 |
|
709 |
-
while ( bp_profile_fields() ) :
|
|
|
710 |
|
711 |
if ( bp_field_has_data() ) :
|
712 |
|
713 |
$profile_fields['fields'][ bp_get_the_profile_field_name() ] = array(
|
714 |
-
'value' =>
|
715 |
'privacy' => bp_get_the_profile_field_visibility_level(),
|
716 |
);
|
717 |
endif;
|
@@ -722,7 +889,8 @@ class RTMediaJsonApi {
|
|
722 |
else :
|
723 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $ec_no_fields, $msg_no_fields ) );
|
724 |
endif;
|
725 |
-
|
|
|
726 |
if ( function_exists( 'rtmedia_api_followers' ) ) {
|
727 |
$followers = rtmedia_api_followers( $user_id );
|
728 |
$following = $this->rtmediajsonapifunction->rtmedia_api_following( $user_id );
|
@@ -745,11 +913,13 @@ class RTMediaJsonApi {
|
|
745 |
);
|
746 |
}
|
747 |
}
|
|
|
748 |
if ( ! empty( $user_id ) && intval( $loggedin_user_id ) !== intval( $user_id ) ) {
|
749 |
$args = array(
|
750 |
'leader_id' => $user_id,
|
751 |
'follower_id' => $loggedin_user_id,
|
752 |
);
|
|
|
753 |
if ( function_exists( 'bp_follow_is_following' ) ) {
|
754 |
$profile_fields['loggedin_user']['following'] = 'FALSE';
|
755 |
if ( bp_follow_is_following( $args ) ) {
|
@@ -769,7 +939,10 @@ class RTMediaJsonApi {
|
|
769 |
wp_send_json( $this->rtmedia_api_response_object( 'TRUE', $ec_profile_fields, $msg_profile_fields, $profile_fields ) );
|
770 |
}
|
771 |
|
772 |
-
|
|
|
|
|
|
|
773 |
$this->rtmediajsonapifunction->rtmedia_api_verfiy_token();
|
774 |
$ec_empty_follow_id = 400003;
|
775 |
$msg_empty_follow_id = esc_html__( 'follow user id missing', 'buddypress-media' );
|
@@ -785,11 +958,13 @@ class RTMediaJsonApi {
|
|
785 |
if ( empty( $follow_id ) ) {
|
786 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $ec_empty_follow_id, $msg_empty_follow_id ) );
|
787 |
}
|
|
|
788 |
$args = array(
|
789 |
'leader_id' => $follow_id,
|
790 |
'follower_id' => $this->user_id,
|
791 |
);
|
792 |
$already_following = bp_follow_is_following( $args );
|
|
|
793 |
if ( ! $already_following ) {
|
794 |
$follow_user = bp_follow_start_following( $args );
|
795 |
if ( $follow_user ) {
|
@@ -802,7 +977,10 @@ class RTMediaJsonApi {
|
|
802 |
}
|
803 |
}
|
804 |
|
805 |
-
|
|
|
|
|
|
|
806 |
$this->rtmediajsonapifunction->rtmedia_api_verfiy_token();
|
807 |
|
808 |
$ec_empty_unfollow_id = 400006;
|
@@ -820,11 +998,13 @@ class RTMediaJsonApi {
|
|
820 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $ec_empty_unfollow_id, $msg_empty_unfollow_id ) );
|
821 |
}
|
822 |
|
823 |
-
$args
|
824 |
'leader_id' => $unfollow_id,
|
825 |
'follower_id' => $this->user_id,
|
826 |
);
|
|
|
827 |
$following = bp_follow_is_following( $args );
|
|
|
828 |
if ( $following ) {
|
829 |
$unfollow_user = bp_follow_stop_following( $args );
|
830 |
if ( $unfollow_user ) {
|
@@ -837,7 +1017,10 @@ class RTMediaJsonApi {
|
|
837 |
}
|
838 |
}
|
839 |
|
840 |
-
|
|
|
|
|
|
|
841 |
$this->rtmediajsonapifunction->rtmedia_api_verfiy_token();
|
842 |
$ec_empty_name_location = 120001;
|
843 |
$msg_empty_name_location = esc_html__( 'name/location empty', 'buddypress-media' );
|
@@ -846,11 +1029,11 @@ class RTMediaJsonApi {
|
|
846 |
$msg_profile_updated = esc_html__( 'profile updated', 'buddypress-media' );
|
847 |
|
848 |
for ( $i = 1; $i <= 12; $i ++ ) {
|
849 |
-
$field_str
|
850 |
-
$field_str
|
851 |
$field_str_privacy = $field_str . '_privacy';
|
852 |
-
$$field_str = filter_input( INPUT_POST, $field_str, FILTER_SANITIZE_STRING );
|
853 |
-
$$field_str_privacy = filter_input( INPUT_POST, $field_str_privacy, FILTER_SANITIZE_STRING );
|
854 |
! empty( $$field_str ) ? $$field_str : '';
|
855 |
! empty( $$field_str_privacy ) ? $$field_str_privacy : 'public';
|
856 |
if ( 1 === $i || 4 === $i ) {
|
@@ -865,7 +1048,10 @@ class RTMediaJsonApi {
|
|
865 |
wp_send_json( $this->rtmedia_api_response_object( 'TRUE', $ec_profile_updated, $msg_profile_updated ) );
|
866 |
}
|
867 |
|
868 |
-
|
|
|
|
|
|
|
869 |
|
870 |
$this->rtmediajsonapifunction->rtmedia_api_verfiy_token();
|
871 |
$ec_no_file = 130001;
|
@@ -876,9 +1062,11 @@ class RTMediaJsonApi {
|
|
876 |
|
877 |
$ec_avatar_updated = 130003;
|
878 |
$msg_avatar_updated = esc_html__( 'avatar updated', 'buddypress-media' );
|
|
|
879 |
if ( empty( $_FILES['file'] ) ) {
|
880 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $ec_no_file, $msg_no_file ) );
|
881 |
}
|
|
|
882 |
$uploaded = bp_core_avatar_handle_upload( $_FILES, 'xprofile_avatar_upload_dir' );
|
883 |
if ( ! $uploaded ) {
|
884 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $ec_invalid_image, $msg_invalid_image ) );
|
@@ -887,10 +1075,13 @@ class RTMediaJsonApi {
|
|
887 |
}
|
888 |
}
|
889 |
|
890 |
-
|
|
|
|
|
|
|
891 |
|
892 |
$this->rtmediajsonapifunction->rtmedia_api_verfiy_token();
|
893 |
-
//Error Codes for new look
|
894 |
$ec_no_file = 140001;
|
895 |
$msg_no_file = esc_html__( 'no file', 'buddypress-media' );
|
896 |
|
@@ -909,16 +1100,18 @@ class RTMediaJsonApi {
|
|
909 |
$ec_look_updated = 140004;
|
910 |
$msg_look_updated = esc_html__( 'media updated', 'buddypress-media' );
|
911 |
|
912 |
-
$rtmedia_file = filter_input( INPUT_POST, 'rtmedia_file', FILTER_SANITIZE_STRING );
|
913 |
-
$image_type = filter_input( INPUT_POST, 'image_type', FILTER_SANITIZE_STRING );
|
914 |
-
$title = filter_input( INPUT_POST, 'title', FILTER_SANITIZE_STRING );
|
915 |
-
$description = filter_input( INPUT_POST, 'description', FILTER_SANITIZE_STRING );
|
916 |
|
917 |
$updated = false;
|
918 |
$uploaded_look = false;
|
|
|
919 |
if ( empty( $rtmedia_file ) && empty( $_FILES['rtmedia_file'] ) ) {
|
920 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $ec_no_file, $msg_no_file ) );
|
921 |
}
|
|
|
922 |
if ( ! empty( $rtmedia_file ) ) {
|
923 |
if ( empty( $image_type ) ) {
|
924 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $ec_image_type_missing, $msg_image_type_missing ) );
|
@@ -927,7 +1120,9 @@ class RTMediaJsonApi {
|
|
927 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $ec_no_file_title, $msg_no_file_title ) );
|
928 |
}
|
929 |
}
|
|
|
930 |
if ( ! empty( $_FILES['rtmedia_file'] ) ) {
|
|
|
931 |
$_POST['rtmedia_upload_nonce'] = $_REQUEST['rtmedia_upload_nonce'] = wp_create_nonce( 'rtmedia_upload_nonce' );
|
932 |
$_POST['rtmedia_simple_file_upload'] = $_REQUEST['rtmedia_simple_file_upload'] = 1;
|
933 |
$_POST['context'] = $_REQUEST['context'] = ! empty( $_REQUEST['context'] ) ? wp_unslash( $_REQUEST['context'] ) : 'profile';
|
@@ -935,39 +1130,46 @@ class RTMediaJsonApi {
|
|
935 |
$_POST['mode'] = $_REQUEST['mode'] = 'file_upload';
|
936 |
$_POST['media_author'] = $_REQUEST['media_author'] = $this->user_id;
|
937 |
$upload = new RTMediaUploadEndpoint();
|
938 |
-
//
|
|
|
939 |
$uploaded_look = $upload->template_redirect();
|
940 |
} else {
|
941 |
-
|
|
|
942 |
$img = $rtmedia_file;
|
943 |
$str_replace = 'data:image/' . $image_type . ';base64,';
|
944 |
$img = str_replace( $str_replace, '', $img );
|
945 |
-
$rtmedia_file = base64_decode( $img );
|
|
|
946 |
if ( ! $rtmedia_file ) {
|
947 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $ec_invalid_file_string, $msg_invalid_file_string ) );
|
948 |
}
|
|
|
949 |
define( 'UPLOAD_DIR_LOOK', sys_get_temp_dir() . '/' );
|
|
|
950 |
$tmp_name = UPLOAD_DIR_LOOK . $title;
|
951 |
$file = $tmp_name . '.' . $image_type;
|
952 |
-
$success = file_put_contents( $file, $rtmedia_file );
|
|
|
953 |
add_filter( 'upload_dir', array( $this, 'api_new_media_upload_dir' ) );
|
954 |
-
$new_look = wp_upload_bits( $title . '.' . $image_type,
|
955 |
$new_look['type'] = 'image/' . $image_type;
|
956 |
remove_filter( 'upload_dir', array( $this, 'api_new_media_upload_dir' ) );
|
|
|
957 |
foreach ( $new_look as $key => $value ) {
|
958 |
$new_look[0][ $key ] = $value;
|
959 |
unset( $new_look[ $key ] );
|
960 |
}
|
961 |
-
|
962 |
if ( ! empty( $tags ) ) {
|
963 |
$tags = explode( ',', $tags );
|
964 |
}
|
965 |
|
966 |
$album_id = filter_input( INPUT_POST, 'album_id', FILTER_SANITIZE_NUMBER_INT );
|
967 |
$context_id = filter_input( INPUT_POST, 'context_id', FILTER_SANITIZE_NUMBER_INT );
|
968 |
-
$context = filter_input( INPUT_POST, 'context', FILTER_SANITIZE_STRING );
|
969 |
-
$privacy = filter_input( INPUT_POST, 'privacy', FILTER_SANITIZE_STRING );
|
970 |
-
$tags = filter_input( INPUT_POST, 'tags', FILTER_SANITIZE_STRING );
|
971 |
|
972 |
$uploaded['rtmedia_upload_nonce'] = wp_create_nonce( 'rtmedia_upload_nonce' );
|
973 |
$uploaded['rtmedia_simple_file_upload'] = 1;
|
@@ -984,35 +1186,36 @@ class RTMediaJsonApi {
|
|
984 |
$rtmedia = new RTMediaMedia();
|
985 |
$rtupload = $rtmedia->add( $uploaded, $new_look );
|
986 |
$id = rtmedia_media_id( $rtupload[0] );
|
|
|
987 |
if ( ! empty( $tags ) ) {
|
988 |
wp_set_post_terms( $id, $tags, 'media-category', true );
|
989 |
}
|
|
|
990 |
$media = $rtmedia->model->get( array( 'id' => $rtupload[0] ) );
|
991 |
$rtmedia_nav = new RTMediaNav();
|
|
|
992 |
if ( isset( $media ) && count( $media ) > 0 ) {
|
993 |
-
$perma_link = get_rtmedia_permalink( $media[0]->id );
|
994 |
-
if ( 'photo' === $media[0]->media_type ) {
|
995 |
-
$thumb_image = rtmedia_image( 'rt_media_thumbnail', $rtupload[0], false );
|
996 |
-
} elseif ( 'music' === $media[0]->media_type ) {
|
997 |
-
$thumb_image = $media[0]->cover_art;
|
998 |
-
} else {
|
999 |
-
$thumb_image = '';
|
1000 |
-
}
|
1001 |
|
1002 |
if ( 'group' === $media[0]->context ) {
|
1003 |
-
$rtmedia_nav->refresh_counts(
|
1004 |
-
|
1005 |
-
|
1006 |
-
|
|
|
|
|
|
|
1007 |
} else {
|
1008 |
-
$rtmedia_nav->refresh_counts(
|
1009 |
-
|
1010 |
-
|
1011 |
-
|
|
|
|
|
|
|
1012 |
}
|
|
|
1013 |
$activity_id = $rtmedia->insert_activity( $media[0]->media_id, $media[0] );
|
1014 |
$rtmedia->model->update( array( 'activity_id' => $activity_id ), array( 'id' => intval( $rtupload[0] ) ) );
|
1015 |
-
//
|
1016 |
$same_medias = $rtmedia->model->get( array( 'activity_id' => $activity_id ) );
|
1017 |
|
1018 |
$update_activity_media = array();
|
@@ -1023,13 +1226,17 @@ class RTMediaJsonApi {
|
|
1023 |
$obj_activity = new RTMediaActivity( $update_activity_media, $privacy, false );
|
1024 |
|
1025 |
global $wpdb, $bp;
|
1026 |
-
$updated = $wpdb->update(
|
1027 |
-
|
1028 |
-
|
1029 |
-
|
|
|
|
|
|
|
|
|
1030 |
|
1031 |
// if there is only single media the $updated value will be false even if the value we are passing to check is correct.
|
1032 |
-
// So we need to hardcode the $updated to true if there is only single media for same activity
|
1033 |
if ( 1 === count( $same_medias ) && $activity_id ) {
|
1034 |
$updated = true;
|
1035 |
}
|
@@ -1043,22 +1250,24 @@ class RTMediaJsonApi {
|
|
1043 |
}
|
1044 |
}
|
1045 |
|
1046 |
-
|
|
|
|
|
|
|
|
|
1047 |
$this->rtmediajsonapifunction->rtmedia_api_verfiy_token();
|
1048 |
-
//Errors
|
1049 |
$ec_media = 160002;
|
1050 |
$msg_media = esc_html__( 'media list', 'buddypress-media' );
|
1051 |
|
1052 |
$ec_no_media = 160003;
|
1053 |
$msg_no_media = esc_html__( 'no media found for requested media type', 'buddypress-media' );
|
1054 |
|
1055 |
-
$ec_invalid_media_type = 160004;
|
1056 |
-
$msg_invalid_media_type = esc_html__( 'media_type not allowed', 'buddypress-media' );
|
1057 |
-
|
1058 |
global $rtmedia;
|
1059 |
$rtmediamodel = new RTMediaModel();
|
1060 |
-
//Media type to fetch
|
1061 |
-
$media_type =
|
|
|
1062 |
$media_type[] = 'album';
|
1063 |
$allowed_types[] = 'album';
|
1064 |
|
@@ -1066,23 +1275,23 @@ class RTMediaJsonApi {
|
|
1066 |
$media_type_array = filter_input( INPUT_POST, 'media_type', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
|
1067 |
|
1068 |
if ( ! empty( $media_type_temp ) ) {
|
1069 |
-
// Explode by , when string found
|
1070 |
$media_type = explode( ',', $media_type_temp );
|
1071 |
} elseif ( ! empty( $media_type_array ) && is_array( $media_type_array ) ) {
|
1072 |
-
// Set media_type to passed array
|
1073 |
$media_type = $media_type_array;
|
1074 |
}
|
1075 |
-
// Check array for currently allowed media types
|
1076 |
-
$media_type = array_intersect( $media_type, $allowed_types );
|
1077 |
|
|
|
|
|
1078 |
|
1079 |
-
//Args for fetching media
|
1080 |
$args = array(
|
1081 |
'media_type' => $media_type,
|
1082 |
);
|
1083 |
|
1084 |
-
//global
|
1085 |
-
$global = filter_input( INPUT_POST, 'global', FILTER_SANITIZE_STRING );
|
1086 |
if ( isset( $global ) ) {
|
1087 |
if ( 'false' === $global ) {
|
1088 |
$args['context'] = array(
|
@@ -1091,39 +1300,43 @@ class RTMediaJsonApi {
|
|
1091 |
);
|
1092 |
}
|
1093 |
}
|
1094 |
-
|
1095 |
-
|
|
|
1096 |
if ( isset( $context ) ) {
|
1097 |
$args['context'] = $context;
|
1098 |
}
|
1099 |
-
|
|
|
1100 |
$context_id = filter_input( INPUT_POST, 'context_id', FILTER_SANITIZE_NUMBER_INT );
|
1101 |
if ( isset( $context_id ) ) {
|
1102 |
$args['context_id'] = $context_id;
|
1103 |
}
|
1104 |
|
1105 |
-
//album id
|
1106 |
$album_id = filter_input( INPUT_POST, 'album_id', FILTER_SANITIZE_NUMBER_INT );
|
1107 |
if ( ! empty( $album_id ) ) {
|
1108 |
$args['album_id'] = $album_id;
|
1109 |
}
|
1110 |
-
|
|
|
1111 |
if ( ! is_super_admin() ) {
|
1112 |
$media_author = $this->user_id;
|
1113 |
$args['media_author'] = $media_author;
|
1114 |
}
|
|
|
1115 |
$media_author = filter_input( INPUT_POST, 'media_author', FILTER_SANITIZE_NUMBER_INT );
|
1116 |
if ( ! empty( $media_author ) ) {
|
1117 |
if ( is_super_admin( $this->user_id ) ) {
|
1118 |
$args['media_author'] = (int) $media_author;
|
1119 |
}
|
1120 |
}
|
1121 |
-
|
1122 |
$page = sanitize_text_field( filter_input( INPUT_POST, 'page', FILTER_SANITIZE_NUMBER_INT ) );
|
1123 |
$per_page = sanitize_text_field( filter_input( INPUT_POST, 'per_page', FILTER_SANITIZE_NUMBER_INT ) );
|
1124 |
$order_by = sanitize_text_field( filter_input( INPUT_POST, 'order_by', FILTER_SANITIZE_STRING ) );
|
1125 |
|
1126 |
-
$offset
|
1127 |
|
1128 |
// Removed is_null check, because it won't be null.
|
1129 |
$per_page = ( ! empty( $per_page ) ) ? (int) $per_page : 10;
|
@@ -1131,6 +1344,7 @@ class RTMediaJsonApi {
|
|
1131 |
|
1132 |
$media_list = $rtmediamodel->get( $args, $offset, $per_page, $order_by );
|
1133 |
$media_result = array();
|
|
|
1134 |
foreach ( $media_list as $media ) {
|
1135 |
$data = array(
|
1136 |
'id' => $media->id,
|
@@ -1141,12 +1355,14 @@ class RTMediaJsonApi {
|
|
1141 |
'url' => esc_url( get_rtmedia_permalink( $media->id ) ),
|
1142 |
'cover' => rtmedia_image( 'rt_media_thumbnail', $media->media_id, false ),
|
1143 |
);
|
1144 |
-
|
|
|
1145 |
if ( 'album' === $media->media_type ) {
|
1146 |
$data['media'] = $this->rtmediajsonapifunction->rtmedia_api_album_media( $media->id );
|
1147 |
}
|
1148 |
$media_result[] = $data;
|
1149 |
}
|
|
|
1150 |
if ( ! empty( $media_result ) ) {
|
1151 |
wp_send_json( $this->rtmedia_api_response_object( 'TRUE', $ec_media, $msg_media, $media_result ) );
|
1152 |
} else {
|
@@ -1154,19 +1370,24 @@ class RTMediaJsonApi {
|
|
1154 |
}
|
1155 |
}
|
1156 |
|
1157 |
-
|
|
|
|
|
|
|
1158 |
|
1159 |
$this->rtmediajsonapifunction->rtmedia_api_verfiy_token();
|
1160 |
$this->rtmediajsonapifunction->rtmedia_api_media_activity_id_missing();
|
1161 |
-
//Errors
|
1162 |
$ec_single_media = 150002;
|
1163 |
$msg_single_media = esc_html__( 'single media', 'buddypress-media' );
|
1164 |
|
1165 |
$media_id = filter_input( INPUT_POST, 'media_id', FILTER_SANITIZE_NUMBER_INT );
|
1166 |
-
$id
|
|
|
1167 |
if ( empty( $id ) ) {
|
1168 |
wp_send_json( $this->rtmedia_api_response_object( 'TRUE', $this->ec_invalid_media_id, $this->msg_invalid_media_id ) );
|
1169 |
}
|
|
|
1170 |
if ( class_exists( 'RTMediaModel' ) ) {
|
1171 |
$rtmediamodel = new RTMediaModel();
|
1172 |
$args = array(
|
@@ -1176,6 +1397,7 @@ class RTMediaJsonApi {
|
|
1176 |
$media = $rtmediamodel->get( $args );
|
1177 |
}
|
1178 |
$activity_id = ! empty( $media ) ? $media[0]->activity_id : '';
|
|
|
1179 |
if ( empty( $activity_id ) ) {
|
1180 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $this->ec_invalid_media_id, $this->msg_invalid_media_id ) );
|
1181 |
}
|
@@ -1186,13 +1408,17 @@ class RTMediaJsonApi {
|
|
1186 |
}
|
1187 |
}
|
1188 |
|
1189 |
-
|
|
|
|
|
|
|
1190 |
$this->rtmediajsonapifunction->rtmedia_api_verfiy_token();
|
1191 |
-
//Errors
|
1192 |
$ec_logged_out = 200005;
|
1193 |
$msg_logged_out = 'logged out';
|
1194 |
$rtmapilogin = new RTMediaApiLogin();
|
1195 |
$updated = $rtmapilogin->update( array( 'status' => 'FALSE' ), array( 'user_id' => $this->user_id ) );
|
|
|
1196 |
if ( $updated ) {
|
1197 |
wp_send_json( $this->rtmedia_api_response_object( 'TRUE', $ec_logged_out, $msg_logged_out ) );
|
1198 |
} else {
|
@@ -1201,8 +1427,15 @@ class RTMediaJsonApi {
|
|
1201 |
|
1202 |
}
|
1203 |
|
1204 |
-
|
1205 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1206 |
|
1207 |
if ( ! empty( $args ) || ! is_array( $args ) || empty( $token ) ) {
|
1208 |
foreach ( $args as $key => $arg ) {
|
1 |
<?php
|
|
|
2 |
/**
|
3 |
+
* Handle rtMedia API requests and send responses according to request
|
4 |
+
*
|
5 |
+
* @package rtMedia
|
6 |
* @author Umesh Kumar <umeshsingla05@gmail.com>
|
7 |
*/
|
8 |
+
|
9 |
+
/**
|
10 |
+
* Class to handle rtMedia API requests and send responses according to request.
|
11 |
+
*/
|
12 |
class RTMediaJsonApi {
|
13 |
|
14 |
+
/**
|
15 |
+
* Error code for missing method error.
|
16 |
+
*
|
17 |
+
* @var int
|
18 |
+
*/
|
19 |
+
public $ec_method_missing = 600001;
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Error message for missing method.
|
23 |
+
*
|
24 |
+
* @var string
|
25 |
+
*/
|
26 |
+
public $msg_method_missing = 'no method specified';
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Error code for token missing.
|
30 |
+
*
|
31 |
+
* @var int
|
32 |
+
*/
|
33 |
+
public $ec_token_missing = 600002;
|
34 |
+
|
35 |
+
/**
|
36 |
+
* Error message for missing token.
|
37 |
+
*
|
38 |
+
* @var string
|
39 |
+
*/
|
40 |
+
public $msg_token_missing = 'token empty';
|
41 |
+
|
42 |
+
/**
|
43 |
+
* Error code for invalid token.
|
44 |
+
*
|
45 |
+
* @var int
|
46 |
+
*/
|
47 |
+
public $ec_token_invalid = 600003;
|
48 |
+
|
49 |
+
/**
|
50 |
+
* Error message for invalid token.
|
51 |
+
*
|
52 |
+
* @var string
|
53 |
+
*/
|
54 |
+
public $msg_token_invalid = 'token invalid';
|
55 |
+
|
56 |
+
/**
|
57 |
+
* Error code for server error.
|
58 |
+
*
|
59 |
+
* @var int
|
60 |
+
*/
|
61 |
+
public $ec_server_error = 600004;
|
62 |
+
|
63 |
+
/**
|
64 |
+
* Error message for server error.
|
65 |
+
*
|
66 |
+
* @var string
|
67 |
+
*/
|
68 |
+
public $msg_server_error = 'server error';
|
69 |
+
|
70 |
+
/**
|
71 |
+
* Error code media or activity id missing.
|
72 |
+
*
|
73 |
+
* @var int
|
74 |
+
*/
|
75 |
+
public $ec_media_activity_id_missing = 600005;
|
76 |
+
|
77 |
+
/**
|
78 |
+
* Error message for media or activity id missing.
|
79 |
+
*
|
80 |
+
* @var string
|
81 |
+
*/
|
82 |
+
public $msg_media_activity_id_missing = 'media/activity id missing';
|
83 |
+
|
84 |
+
/**
|
85 |
+
* Error code for invalid media id.
|
86 |
+
*
|
87 |
+
* @var int
|
88 |
+
*/
|
89 |
+
public $ec_invalid_media_id = 600006;
|
90 |
+
|
91 |
+
/**
|
92 |
+
* Error message for invalid media id.
|
93 |
+
*
|
94 |
+
* @var string
|
95 |
+
*/
|
96 |
+
public $msg_invalid_media_id = 'invalid media id';
|
97 |
+
|
98 |
+
/**
|
99 |
+
* Error code for invalid api request type.
|
100 |
+
*
|
101 |
+
* @var int
|
102 |
+
*/
|
103 |
+
public $ec_invalid_request_type = 600007;
|
104 |
+
|
105 |
+
/**
|
106 |
+
* Error message for invalid request type.
|
107 |
+
*
|
108 |
+
* @var string
|
109 |
+
*/
|
110 |
+
public $msg_invalid_request_type = 'invalid request type';
|
111 |
+
|
112 |
+
/**
|
113 |
+
* Error code for Buddypress missing.
|
114 |
+
*
|
115 |
+
* @var int
|
116 |
+
*/
|
117 |
+
public $ec_bp_missing = 600008;
|
118 |
+
|
119 |
+
/**
|
120 |
+
* Error message for buddypress missing error.
|
121 |
+
*
|
122 |
+
* @var string
|
123 |
+
*/
|
124 |
+
public $msg_bp_missing = 'buddypress not found';
|
125 |
+
|
126 |
+
/**
|
127 |
+
* Error code for disabled API.
|
128 |
+
*
|
129 |
+
* @var int
|
130 |
+
*/
|
131 |
+
public $ec_api_disabled = 600009;
|
132 |
+
|
133 |
+
/**
|
134 |
+
* Error message when site API is disabled.
|
135 |
+
*
|
136 |
+
* @var string
|
137 |
+
*/
|
138 |
+
public $msg_api_disabled = 'API disabled by site administrator';
|
139 |
+
|
140 |
+
/**
|
141 |
+
* Object of RTMediaJsonApiFunctions class to handle api requests.
|
142 |
+
*
|
143 |
+
* @var object
|
144 |
+
*/
|
145 |
+
public $rtmediajsonapifunction;
|
146 |
+
|
147 |
+
/**
|
148 |
+
* User id for API request.
|
149 |
+
*
|
150 |
+
* @var string|int
|
151 |
+
*/
|
152 |
+
public $user_id = '';
|
153 |
+
|
154 |
+
/**
|
155 |
+
* RTMediaJsonApi constructor.
|
156 |
+
*/
|
157 |
+
public function __construct() {
|
158 |
if ( ! class_exists( 'RTMediaApiLogin' ) || ! class_exists( 'RTMediaJsonApiFunctions' ) ) {
|
159 |
return;
|
160 |
}
|
163 |
add_action( 'wp_ajax_rtmedia_api', array( $this, 'rtmedia_api_process_request' ) );
|
164 |
}
|
165 |
|
166 |
+
/**
|
167 |
+
* Function to process API requests.
|
168 |
+
*/
|
169 |
+
public function rtmedia_api_process_request() {
|
170 |
$rtmedia_enable_json_api = false;
|
171 |
+
|
172 |
if ( function_exists( 'rtmedia_get_site_option' ) ) {
|
173 |
$rtmedia_options = rtmedia_get_site_option( 'rtmedia-options' );
|
174 |
if ( ! empty( $rtmedia_options ) ) {
|
177 |
}
|
178 |
}
|
179 |
}
|
180 |
+
|
181 |
if ( ! $rtmedia_enable_json_api ) {
|
182 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $this->ec_api_disabled, $this->msg_api_disabled ) );
|
183 |
}
|
184 |
+
|
185 |
+
$method = sanitize_text_field( filter_input( INPUT_POST, 'method', FILTER_SANITIZE_STRING ) );
|
186 |
if ( empty( $method ) ) {
|
187 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $this->ec_method_missing, $this->msg_method_missing ) );
|
188 |
}
|
189 |
+
|
190 |
if ( ! class_exists( 'BuddyPress' ) ) {
|
191 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $this->ec_bp_missing, $this->msg_bp_missing ) );
|
192 |
}
|
193 |
$this->rtmediajsonapifunction = new RTMediaJsonApiFunctions();
|
194 |
+
$token = sanitize_text_field( filter_input( INPUT_POST, 'token', FILTER_SANITIZE_STRING ) );
|
195 |
|
196 |
if ( ! empty( $token ) ) {
|
197 |
$this->rtmediajsonapifunction->rtmedia_api_verfiy_token();
|
198 |
$this->user_id = $this->rtmediajsonapifunction->rtmedia_api_get_user_id_from_token( $token );
|
199 |
+
// add filter.
|
200 |
add_filter( 'rtmedia_current_user', array( $this->rtmediajsonapifunction, 'rtmedia_api_set_user_id' ) );
|
201 |
}
|
|
|
202 |
|
203 |
+
// Process Request.
|
204 |
switch ( $method ) {
|
|
|
205 |
case 'wp_login':
|
206 |
$this->rtmedia_api_process_wp_login_request();
|
207 |
break;
|
208 |
case 'wp_logout':
|
209 |
+
// todo implement this function rtmedia_api_process_wp_logout_request if needed.
|
210 |
+
// $this->rtmedia_api_process_wp_logout_request();.
|
211 |
break;
|
212 |
case 'wp_register':
|
213 |
$this->rtmedia_api_process_wp_register_request();
|
256 |
}
|
257 |
|
258 |
/**
|
259 |
+
* Returns a json object as API request response.
|
260 |
*
|
261 |
+
* @param string $status Response status.
|
262 |
+
* @param int $status_code Status code for response.
|
263 |
+
* @param string $message Response message to send.
|
264 |
+
* @param bool|array $data Response data to send.
|
265 |
*
|
266 |
+
* @return bool|array
|
267 |
*/
|
268 |
+
public function rtmedia_api_response_object( $status, $status_code, $message, $data = false ) {
|
269 |
if ( '' === $status || empty( $status_code ) || empty( $message ) ) {
|
270 |
return false;
|
271 |
}
|
273 |
if ( ob_get_contents() ) {
|
274 |
ob_end_clean();
|
275 |
}
|
276 |
+
|
277 |
$rtmapilogin = new RTMediaApiLogin();
|
278 |
+
$token = sanitize_text_field( filter_input( INPUT_POST, 'token', FILTER_SANITIZE_STRING ) );
|
279 |
$login_details = array( 'last_access' => current_time( 'mysql' ) );
|
280 |
+
|
281 |
if ( ! empty( $token ) ) {
|
282 |
+
$where = array(
|
283 |
+
'user_id' => $this->user_id,
|
284 |
+
'token' => $token,
|
285 |
+
);
|
286 |
}
|
287 |
+
|
288 |
if ( ! empty( $where ) ) {
|
289 |
$rtmapilogin->update( $login_details, $where );
|
290 |
}
|
291 |
+
|
292 |
$response_object = array();
|
293 |
$response_object['status'] = $status;
|
294 |
$response_object['status_code'] = $status_code;
|
299 |
}
|
300 |
|
301 |
/**
|
302 |
+
* Takes username and password, if successful returns a access token
|
303 |
*/
|
304 |
+
public function rtmedia_api_process_wp_login_request() {
|
305 |
+
// Login Errors and Messages.
|
306 |
$ec_user_pass_missing = 200001;
|
307 |
$msg_user_pass_missing = esc_html__( 'username/password empty', 'buddypress-media' );
|
308 |
|
314 |
|
315 |
$ec_login_success = 200004;
|
316 |
$msg_login_success = esc_html__( 'login success', 'buddypress-media' );
|
317 |
+
$username = sanitize_text_field( filter_input( INPUT_POST, 'username', FILTER_SANITIZE_STRING ) );
|
318 |
+
$password = sanitize_text_field( filter_input( INPUT_POST, 'password', FILTER_SANITIZE_STRING ) );
|
319 |
|
320 |
if ( empty( $username ) || empty( $password ) ) {
|
321 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $ec_user_pass_missing, $msg_user_pass_missing ) );
|
322 |
} else {
|
323 |
$user_login = wp_authenticate( trim( $username ), trim( $password ) );
|
324 |
+
|
325 |
if ( is_wp_error( $user_login ) ) {
|
326 |
|
327 |
$incorrect_password = ! empty( $user_login->errors['incorrect_password'] ) ? true : false;
|
328 |
$incorrect_username = ! empty( $user_login->errors['invalid_username'] ) ? true : false;
|
329 |
+
|
330 |
if ( $incorrect_password ) {
|
331 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $ec_incorrect_pass, $msg_incorrect_pass ) );
|
332 |
} elseif ( $incorrect_username ) {
|
333 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $ec_incorrect_username, $msg_incorrect_username ) );
|
334 |
}
|
335 |
} else {
|
336 |
+
|
337 |
$access_token = $this->rtmediajsonapifunction->rtmedia_api_get_user_token( $user_login->ID, $user_login->data->user_login );
|
338 |
$data = array(
|
339 |
'access_token' => $access_token,
|
340 |
);
|
341 |
$rtmapilogin = new RTMediaApiLogin();
|
342 |
|
343 |
+
// update all tokens for user to expired on each login.
|
344 |
$rtmapilogin->update( array( 'status' => 'FALSE' ), array( 'user_id' => $user_login->ID ) );
|
345 |
$remote_addr = rtm_get_server_var( 'REMOTE_ADDR', 'FILTER_VALIDATE_IP' );
|
346 |
$login_details = array(
|
356 |
}
|
357 |
|
358 |
/**
|
359 |
+
* Register a user through api request
|
360 |
* requires signup_* => display_name, username, password, confirm password, location,
|
361 |
*/
|
362 |
+
public function rtmedia_api_process_wp_register_request() {
|
363 |
+
// Registration errors and messages.
|
364 |
$ec_register_fields_missing = 300001;
|
365 |
$msg_register_fields_missing = esc_html__( 'fields empty', 'buddypress-media' );
|
366 |
|
373 |
$ec_username_exists = 300004;
|
374 |
$msg_username_exists = esc_html__( 'username already registered', 'buddypress-media' );
|
375 |
|
376 |
+
$ec_email_exists = 300005;
|
377 |
+
$msg_email_exists = esc_html__( 'email already exists', 'buddypress-media' );
|
378 |
|
379 |
$ec_user_insert_success = 300007;
|
380 |
$msg_user_insert_success = esc_html__( 'new user created', 'buddypress-media' );
|
381 |
|
382 |
$registration_fields = array( 'username', 'email', 'password', 'password_confirm' );
|
383 |
+
// fields empty field_1, field_4.
|
384 |
+
$field_1 = sanitize_text_field( filter_input( INPUT_POST, 'field_1', FILTER_SANITIZE_STRING ) );
|
385 |
|
386 |
if ( empty( $field_1 ) ) {
|
387 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $ec_register_fields_missing, $msg_register_fields_missing ) );
|
388 |
}
|
389 |
+
|
390 |
foreach ( $registration_fields as $field_name ) {
|
391 |
+
$field_signup = sanitize_text_field( filter_input( INPUT_POST, 'signup_' . $field_name, FILTER_SANITIZE_STRING ) );
|
392 |
if ( empty( $field_signup ) ) {
|
393 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $ec_register_fields_missing, $msg_register_fields_missing ) );
|
394 |
}
|
395 |
}
|
396 |
+
|
397 |
$signup_email = filter_input( INPUT_POST, 'signup_email', FILTER_VALIDATE_EMAIL );
|
398 |
+
$signup_username = sanitize_text_field( filter_input( INPUT_POST, 'signup_username', FILTER_SANITIZE_STRING ) );
|
399 |
+
$signup_password = sanitize_text_field( filter_input( INPUT_POST, 'signup_password', FILTER_SANITIZE_STRING ) );
|
400 |
+
$signup_password_confirm = sanitize_text_field( filter_input( INPUT_POST, 'signup_password_confirm', FILTER_SANITIZE_STRING ) );
|
401 |
|
402 |
+
// incorrect email.
|
403 |
if ( ! is_email( $signup_email ) ) {
|
404 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $ec_invalid_email, $msg_invalid_email ) );
|
405 |
+
} elseif ( $signup_password !== $signup_password_confirm ) { // Passwords do not match.
|
|
|
406 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $ec_pass_do_not_match, $msg_pass_do_not_match ) );
|
407 |
+
} elseif ( username_exists( $signup_username ) ) { // Username already registered.
|
|
|
408 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $ec_username_exists, $msg_username_exists ) );
|
409 |
+
} elseif ( email_exists( $signup_email ) ) { // email already registered.
|
410 |
+
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $ec_email_exists, $msg_email_exists ) );
|
|
|
411 |
} else {
|
412 |
$userdata = array(
|
413 |
'user_login' => sanitize_user( $signup_username ),
|
419 |
if ( ! is_wp_error( $user_id ) ) {
|
420 |
echo esc_html( xprofile_get_field_id_from_name( 'field_1' ) );
|
421 |
xprofile_set_field_data( 1, $user_id, sanitize_text_field( $field_1 ) );
|
422 |
+
// todo user attr.
|
423 |
update_user_meta( $user_id, 'register_source', 'site_api' );
|
424 |
echo wp_json_encode( $this->rtmedia_api_response_object( 'TRUE', $ec_user_insert_success, $msg_user_insert_success ) );
|
425 |
wp_die();
|
431 |
|
432 |
/**
|
433 |
* Sends a reset link to user email
|
434 |
+
*
|
435 |
* @global type $wpdb
|
436 |
*/
|
437 |
+
public function rtmedia_api_process_wp_forgot_password_request() {
|
438 |
global $wpdb;
|
439 |
+
// Registration errors and messages.
|
440 |
$ec_email_missing = 500001;
|
441 |
$msg_email_missing = esc_html__( 'email empty', 'buddypress-media' );
|
442 |
|
445 |
|
446 |
$ec_email_sent = 500003;
|
447 |
$msg_email_sent = esc_html__( 'reset link sent', 'buddypress-media' );
|
448 |
+
$user_login = sanitize_text_field( filter_input( INPUT_POST, 'user_login', FILTER_SANITIZE_STRING ) );
|
449 |
|
450 |
if ( empty( $user_login ) ) {
|
451 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $ec_email_missing, $msg_email_missing ) );
|
452 |
}
|
453 |
|
454 |
if ( username_exists( $user_login ) ) {
|
455 |
+
$user = get_user_by( 'login', sanitize_user( $user_login ) );
|
456 |
+
} elseif ( email_exists( $user_login ) ) { // Then, by e-mail address.
|
457 |
+
$user = get_user_by( 'email', sanitize_email( $user_login ) );
|
|
|
|
|
|
|
458 |
} else {
|
459 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $ec_username_email_not_registered, $msg_username_email_not_registered ) );
|
460 |
}
|
461 |
+
|
462 |
$user_login = $user->data->user_login;
|
463 |
$user_email = $user->data->user_email;
|
464 |
|
465 |
// Generate something random for a key...
|
466 |
$key = wp_generate_password( 20, false );
|
467 |
do_action( 'retrieve_password_key', $user_login, $key );
|
468 |
+
|
469 |
+
// Now insert the new md5 key into the db.
|
470 |
// Now insert the key, hashed, into the DB.
|
471 |
if ( empty( $wp_hasher ) ) {
|
472 |
require_once ABSPATH . 'wp-includes/class-phpass.php';
|
473 |
$wp_hasher = new PasswordHash( 8, true );
|
474 |
}
|
475 |
+
|
476 |
$hashed = $wp_hasher->HashPassword( $key );
|
477 |
$wpdb->update( $wpdb->users, array( 'user_activation_key' => $hashed ), array( 'user_login' => sanitize_user( $user_login ) ) );
|
478 |
|
479 |
+
// create email message.
|
480 |
+
$message = esc_html__( 'Someone has asked to reset the password for the following site and username.', 'buddypress-media' ) . "\r\n\r\n";
|
481 |
$message .= esc_url( get_option( 'siteurl' ) ) . "\r\n\r\n";
|
482 |
+
|
483 |
+
// translators: 1: Username.
|
484 |
$message .= sprintf( esc_html__( 'Username: %s', 'buddypress-media' ), $user_login ) . "\r\n\r\n";
|
485 |
$message .= esc_html__( 'To reset your password visit the following address, otherwise just ignore this email and nothing will happen.', 'buddypress-media' ) . "\r\n\r\n";
|
486 |
$message .= '<' . esc_url( network_site_url( "wp-login.php?action=rp&key=$key&login=" . rawurlencode( $user_login ), 'login' ) ) . ">\r\n";
|
487 |
+
|
488 |
+
// send email message.
|
489 |
+
// translators: 1: Blog name.
|
490 |
if ( false === wp_mail( $user_email, sprintf( esc_html__( '[%s] Password Reset', 'buddypress-media' ), get_option( 'blogname' ) ), $message ) ) {
|
491 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $this->ec_server_error, $this->msg_server_error ) );
|
492 |
} else {
|
496 |
|
497 |
/**
|
498 |
* Sends a reset link to user email
|
499 |
+
*
|
500 |
* @global type $wpdb
|
501 |
*/
|
502 |
+
public function rtmedia_api_process_bp_get_activities_request() {
|
503 |
$this->rtmediajsonapifunction->rtmedia_api_verfiy_token();
|
504 |
+
// Feed Errors.
|
505 |
$ec_latest_feed = 700001;
|
506 |
$msg_latest_feed = esc_html__( 'bp activities', 'buddypress-media' );
|
507 |
|
508 |
$ec_my_looks = 700002;
|
509 |
$msg_my_looks = esc_html__( 'user activities', 'buddypress-media' );
|
510 |
|
511 |
+
// Fetch user id from token.
|
512 |
$activity_user_id = filter_input( INPUT_POST, 'activity_user_id', FILTER_VALIDATE_INT );
|
513 |
$per_page = filter_input( INPUT_POST, 'per_page', FILTER_VALIDATE_INT );
|
514 |
|
526 |
|
527 |
/**
|
528 |
* Post comment on activity_id or media_id
|
529 |
+
*
|
530 |
* @global type $this ->msg_server_error
|
531 |
* @global int $this ->ec_server_error
|
532 |
* @global int $this ->ec_invalid_media_id
|
533 |
* @global type $this ->msg_invalid_media_id
|
534 |
*/
|
535 |
+
public function rtmedia_api_process_add_rtmedia_comment_request() {
|
536 |
|
537 |
$this->rtmediajsonapifunction->rtmedia_api_verfiy_token();
|
538 |
$this->rtmediajsonapifunction->rtmedia_api_media_activity_id_missing();
|
539 |
+
// Post comment errors.
|
540 |
$ec_comment_content_missing = 800001;
|
541 |
$msg_comment_content_missing = esc_html__( 'comment content missing', 'buddypress-media' );
|
542 |
|
543 |
$ec_comment_posted = 800002;
|
544 |
$msg_comment_posted = esc_html__( 'comment posted', 'buddypress-media' );
|
545 |
|
546 |
+
$content = sanitize_text_field( filter_input( INPUT_POST, 'content', FILTER_SANITIZE_STRING ) );
|
|
|
|
|
|
|
547 |
|
548 |
if ( empty( $content ) ) {
|
549 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $ec_comment_content_missing, $msg_comment_content_missing ) );
|
552 |
if ( empty( $activity_id ) && ! empty( $media_id ) ) {
|
553 |
$activity_id = $this->rtmediajsonapifunction->rtmedia_api_activityid_from_mediaid( $media_id );
|
554 |
}
|
555 |
+
|
556 |
if ( empty( $activity_id ) ) {
|
557 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $this->ec_invalid_media_id, $this->msg_invalid_media_id ) );
|
558 |
}
|
559 |
+
|
560 |
$args = array(
|
561 |
'content' => $content,
|
562 |
'activity_id' => intval( $activity_id ),
|
563 |
'user_id' => intval( $this->user_id ),
|
564 |
'parent_id' => false,
|
565 |
);
|
566 |
+
|
567 |
if ( function_exists( 'bp_activity_new_comment' ) ) {
|
568 |
$comment_id = bp_activity_new_comment( $args );
|
569 |
}
|
570 |
+
|
571 |
if ( isset( $comment_id ) ) {
|
572 |
wp_send_json( $this->rtmedia_api_response_object( 'TRUE', $ec_comment_posted, $msg_comment_posted ) );
|
573 |
} else {
|
577 |
|
578 |
/**
|
579 |
* Like/Unlike by media_id or activity_id
|
580 |
+
*
|
581 |
* @global int $this ->ec_server_error
|
582 |
* @global type $this ->msg_server_error
|
583 |
* @global int $this ->ec_invalid_media_id
|
584 |
* @global type $this ->msg_invalid_media_id
|
585 |
*/
|
586 |
+
public function rtmedia_api_process_like_media_request() {
|
587 |
$this->rtmediajsonapifunction->rtmedia_api_verfiy_token();
|
588 |
$this->rtmediajsonapifunction->rtmedia_api_media_activity_id_missing();
|
589 |
|
590 |
+
// Like errors.
|
591 |
$ec_already_liked = 900001;
|
592 |
$msg_already_liked = esc_html__( 'unliked media', 'buddypress-media' );
|
593 |
|
604 |
}
|
605 |
|
606 |
$action = 'like';
|
607 |
+
// Like or Unlike.
|
608 |
if ( ! rtmedia_media_id( $media_id ) ) {
|
609 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $this->ec_invalid_media_id, $this->msg_invalid_media_id ) );
|
610 |
}
|
640 |
$insert_id = $rtmediainteraction->insert( $columns );
|
641 |
$increase = true;
|
642 |
}
|
643 |
+
|
644 |
if ( $increase ) {
|
645 |
$like_count_old ++;
|
646 |
} elseif ( ! $increase ) {
|
647 |
$like_count_old --;
|
648 |
}
|
649 |
+
|
650 |
if ( $like_count_old < 0 ) {
|
651 |
$like_count_old = 0;
|
652 |
}
|
653 |
+
|
654 |
$data = array( 'like_count' => $like_count_old );
|
655 |
if ( ! empty( $insert_id ) && isset( $rtmedialike ) ) {
|
656 |
$rtmedialike->model->update( array( 'likes' => $like_count_old ), array( 'id' => $media_id ) );
|
670 |
|
671 |
/**
|
672 |
* Fetch Comments by media id
|
673 |
+
*
|
674 |
* @global type $wpdb
|
675 |
*/
|
676 |
+
public function rtmedia_api_process_get_rtmedia_comments_request() {
|
677 |
$this->rtmediajsonapifunction->rtmedia_api_verfiy_token();
|
678 |
+
// Errors Fetching comment.
|
679 |
$ec_no_comments = 800003;
|
680 |
$msg_no_comments = esc_html__( 'no comments', 'buddypress-media' );
|
681 |
|
682 |
$ec_media_comments = 800004;
|
683 |
$msg_media_comments = esc_html__( 'media comments', 'buddypress-media' );
|
684 |
|
|
|
|
|
|
|
685 |
$media_id = filter_input( INPUT_POST, 'media_id', FILTER_SANITIZE_NUMBER_INT );
|
686 |
|
687 |
global $wpdb;
|
713 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $ec_no_comments, $msg_no_comments ) );
|
714 |
}
|
715 |
}
|
716 |
+
|
717 |
+
// If no comments.
|
718 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $ec_no_comments, $msg_no_comments ) );
|
719 |
}
|
720 |
|
721 |
/**
|
722 |
* Fetch Likes by media id
|
723 |
+
*
|
724 |
* @global type $wpdb
|
725 |
*/
|
726 |
+
public function rtmedia_api_process_get_likes_rtmedia_request() {
|
727 |
$this->rtmediajsonapifunction->rtmedia_api_verfiy_token();
|
728 |
$this->rtmediajsonapifunction->rtmedia_api_media_activity_id_missing();
|
729 |
+
|
730 |
+
// Errors Fetching Likes.
|
731 |
$ec_no_likes = 900003;
|
732 |
$msg_no_likes = esc_html__( 'no likes', 'buddypress-media' );
|
733 |
|
735 |
$msg_media_likes = esc_html__( 'media likes', 'buddypress-media' );
|
736 |
$media_id = filter_input( INPUT_POST, 'media_id', FILTER_SANITIZE_NUMBER_INT );
|
737 |
$media_likes = filter_input( INPUT_POST, 'media_likes', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
|
738 |
+
$media_like_users = filter_input( INPUT_POST, 'media_like_users', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
|
739 |
+
|
740 |
if ( isset( $media_likes['user'] ) && ! is_array( $media_likes['user'] ) ) {
|
741 |
$media_likes['user'] = array();
|
742 |
}
|
743 |
+
|
744 |
if ( empty( $media_likes ) || ! is_array( $media_likes ) ) {
|
745 |
$media_likes = array();
|
746 |
}
|
747 |
+
|
748 |
if ( empty( $media_like_users ) || ! is_array( $media_like_users ) ) {
|
749 |
$media_like_users = array();
|
750 |
}
|
778 |
/**
|
779 |
* Delete comment by activity id or media id
|
780 |
*/
|
781 |
+
public function rtmedia_api_process_remove_comment_request() {
|
782 |
+
|
783 |
global $wpdb;
|
784 |
$this->rtmediajsonapifunction->rtmedia_api_verfiy_token();
|
785 |
$this->rtmediajsonapifunction->rtmedia_api_media_activity_id_missing();
|
|
|
786 |
|
787 |
+
// Errors Deleting comment.
|
788 |
$ec_comment_not_found = 800007;
|
789 |
$msg_comment_not_found = esc_html__( 'invalid comment/media id', 'buddypress-media' );
|
790 |
|
800 |
if ( empty( $comment_id ) ) {
|
801 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $ec_no_comment_id, $msg_no_comment_id ) );
|
802 |
}
|
|
|
|
|
803 |
|
804 |
+
$id = rtmedia_media_id( $media_id );
|
805 |
+
$comments = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->comments} WHERE comment_ID = %d AND comment_post_ID = %d AND user_id = %d limit 100", $comment_id, $id, $this->user_id ), ARRAY_A );
|
806 |
+
|
807 |
+
// Delete Comment.
|
808 |
if ( ! empty( $comments ) ) {
|
809 |
$comment = new RTMediaComment();
|
810 |
|
813 |
if ( ! empty( $activity_id ) ) {
|
814 |
$activity_deleted = bp_activity_delete_comment( $activity_id, $comment_id );
|
815 |
|
816 |
+
$delete = bp_activity_delete(
|
817 |
+
array(
|
818 |
+
'id' => $activity_id,
|
819 |
+
'type' => 'activity_comment',
|
820 |
+
)
|
821 |
+
);
|
822 |
|
823 |
}
|
824 |
$comment_deleted = $comment->rtmedia_comment_model->delete( $comment_id );
|
833 |
}
|
834 |
}
|
835 |
|
836 |
+
/**
|
837 |
+
* Function to handle API request to get user profile.
|
838 |
+
*/
|
839 |
+
public function rtmedia_api_process_bp_get_profile_request() {
|
840 |
$this->rtmediajsonapifunction->rtmedia_api_verfiy_token();
|
841 |
+
// Errors.
|
842 |
$ec_no_fields = 400001;
|
843 |
$msg_no_fields = esc_html__( 'no profile found', 'buddypress-media' );
|
844 |
|
845 |
$ec_profile_fields = 400002;
|
846 |
$msg_profile_fields = esc_html__( 'profile fields', 'buddypress-media' );
|
847 |
|
848 |
+
$profile_fields = array();
|
|
|
|
|
849 |
$user_id = filter_input( INPUT_POST, 'user_id', FILTER_SANITIZE_NUMBER_INT );
|
850 |
$loggedin_user_id = filter_input( INPUT_POST, 'loggedin_user_id', FILTER_SANITIZE_NUMBER_INT );
|
851 |
|
854 |
} else {
|
855 |
$loggedin_user_id = $this->user_id;
|
856 |
}
|
857 |
+
|
858 |
$user = get_userdata( $user_id );
|
859 |
if ( empty( $user ) ) {
|
860 |
wp_send_json( $this->rtmedia_api_response_object( 'TRUE', $ec_no_fields, $msg_no_fields ) );
|
861 |
}
|
862 |
+
|
863 |
$user_data = $this->rtmediajsonapifunction->rtmedia_api_user_data_from_id( $user_id, 250, 250, 'full' );
|
864 |
$profile_fields['id'] = $user_id;
|
865 |
$profile_fields['avatar']['src'] = esc_url( $user_data['avatar'] );
|
867 |
$profile_fields['avatar']['height'] = 250;
|
868 |
|
869 |
if ( bp_has_profile( array( 'user_id' => $user_id ) ) ) :
|
870 |
+
while ( bp_profile_groups() ) :
|
871 |
+
bp_the_profile_group();
|
872 |
|
873 |
if ( bp_profile_group_has_fields() ) :
|
874 |
|
875 |
+
while ( bp_profile_fields() ) :
|
876 |
+
bp_the_profile_field();
|
877 |
|
878 |
if ( bp_field_has_data() ) :
|
879 |
|
880 |
$profile_fields['fields'][ bp_get_the_profile_field_name() ] = array(
|
881 |
+
'value' => wp_strip_all_tags( bp_get_the_profile_field_value() ),
|
882 |
'privacy' => bp_get_the_profile_field_visibility_level(),
|
883 |
);
|
884 |
endif;
|
889 |
else :
|
890 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $ec_no_fields, $msg_no_fields ) );
|
891 |
endif;
|
892 |
+
|
893 |
+
// If followers plugin exists.
|
894 |
if ( function_exists( 'rtmedia_api_followers' ) ) {
|
895 |
$followers = rtmedia_api_followers( $user_id );
|
896 |
$following = $this->rtmediajsonapifunction->rtmedia_api_following( $user_id );
|
913 |
);
|
914 |
}
|
915 |
}
|
916 |
+
|
917 |
if ( ! empty( $user_id ) && intval( $loggedin_user_id ) !== intval( $user_id ) ) {
|
918 |
$args = array(
|
919 |
'leader_id' => $user_id,
|
920 |
'follower_id' => $loggedin_user_id,
|
921 |
);
|
922 |
+
|
923 |
if ( function_exists( 'bp_follow_is_following' ) ) {
|
924 |
$profile_fields['loggedin_user']['following'] = 'FALSE';
|
925 |
if ( bp_follow_is_following( $args ) ) {
|
939 |
wp_send_json( $this->rtmedia_api_response_object( 'TRUE', $ec_profile_fields, $msg_profile_fields, $profile_fields ) );
|
940 |
}
|
941 |
|
942 |
+
/**
|
943 |
+
* Function to handle follow api request for user.
|
944 |
+
*/
|
945 |
+
public function rtmedia_api_process_follow_request() {
|
946 |
$this->rtmediajsonapifunction->rtmedia_api_verfiy_token();
|
947 |
$ec_empty_follow_id = 400003;
|
948 |
$msg_empty_follow_id = esc_html__( 'follow user id missing', 'buddypress-media' );
|
958 |
if ( empty( $follow_id ) ) {
|
959 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $ec_empty_follow_id, $msg_empty_follow_id ) );
|
960 |
}
|
961 |
+
|
962 |
$args = array(
|
963 |
'leader_id' => $follow_id,
|
964 |
'follower_id' => $this->user_id,
|
965 |
);
|
966 |
$already_following = bp_follow_is_following( $args );
|
967 |
+
|
968 |
if ( ! $already_following ) {
|
969 |
$follow_user = bp_follow_start_following( $args );
|
970 |
if ( $follow_user ) {
|
977 |
}
|
978 |
}
|
979 |
|
980 |
+
/**
|
981 |
+
* Function to handle unfollow api request for user.
|
982 |
+
*/
|
983 |
+
public function rtmedia_api_process_unfollow_request() {
|
984 |
$this->rtmediajsonapifunction->rtmedia_api_verfiy_token();
|
985 |
|
986 |
$ec_empty_unfollow_id = 400006;
|
998 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $ec_empty_unfollow_id, $msg_empty_unfollow_id ) );
|
999 |
}
|
1000 |
|
1001 |
+
$args = array(
|
1002 |
'leader_id' => $unfollow_id,
|
1003 |
'follower_id' => $this->user_id,
|
1004 |
);
|
1005 |
+
|
1006 |
$following = bp_follow_is_following( $args );
|
1007 |
+
|
1008 |
if ( $following ) {
|
1009 |
$unfollow_user = bp_follow_stop_following( $args );
|
1010 |
if ( $unfollow_user ) {
|
1017 |
}
|
1018 |
}
|
1019 |
|
1020 |
+
/**
|
1021 |
+
* Function to handle api request for update profile.
|
1022 |
+
*/
|
1023 |
+
public function rtmedia_api_process_update_profile_request() {
|
1024 |
$this->rtmediajsonapifunction->rtmedia_api_verfiy_token();
|
1025 |
$ec_empty_name_location = 120001;
|
1026 |
$msg_empty_name_location = esc_html__( 'name/location empty', 'buddypress-media' );
|
1029 |
$msg_profile_updated = esc_html__( 'profile updated', 'buddypress-media' );
|
1030 |
|
1031 |
for ( $i = 1; $i <= 12; $i ++ ) {
|
1032 |
+
$field_str = 'field_';
|
1033 |
+
$field_str .= $i;
|
1034 |
$field_str_privacy = $field_str . '_privacy';
|
1035 |
+
$$field_str = sanitize_text_field( filter_input( INPUT_POST, $field_str, FILTER_SANITIZE_STRING ) );
|
1036 |
+
$$field_str_privacy = sanitize_text_field( filter_input( INPUT_POST, $field_str_privacy, FILTER_SANITIZE_STRING ) );
|
1037 |
! empty( $$field_str ) ? $$field_str : '';
|
1038 |
! empty( $$field_str_privacy ) ? $$field_str_privacy : 'public';
|
1039 |
if ( 1 === $i || 4 === $i ) {
|
1048 |
wp_send_json( $this->rtmedia_api_response_object( 'TRUE', $ec_profile_updated, $msg_profile_updated ) );
|
1049 |
}
|
1050 |
|
1051 |
+
/**
|
1052 |
+
* Function to handle api request to update user avatar.
|
1053 |
+
*/
|
1054 |
+
public function rtmedia_api_process_update_avatar_request() {
|
1055 |
|
1056 |
$this->rtmediajsonapifunction->rtmedia_api_verfiy_token();
|
1057 |
$ec_no_file = 130001;
|
1062 |
|
1063 |
$ec_avatar_updated = 130003;
|
1064 |
$msg_avatar_updated = esc_html__( 'avatar updated', 'buddypress-media' );
|
1065 |
+
|
1066 |
if ( empty( $_FILES['file'] ) ) {
|
1067 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $ec_no_file, $msg_no_file ) );
|
1068 |
}
|
1069 |
+
|
1070 |
$uploaded = bp_core_avatar_handle_upload( $_FILES, 'xprofile_avatar_upload_dir' );
|
1071 |
if ( ! $uploaded ) {
|
1072 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $ec_invalid_image, $msg_invalid_image ) );
|
1075 |
}
|
1076 |
}
|
1077 |
|
1078 |
+
/**
|
1079 |
+
* Function to handle media upload request.
|
1080 |
+
*/
|
1081 |
+
public function rtmedia_api_process_rtmedia_upload_media_request() {
|
1082 |
|
1083 |
$this->rtmediajsonapifunction->rtmedia_api_verfiy_token();
|
1084 |
+
// Error Codes for new look.
|
1085 |
$ec_no_file = 140001;
|
1086 |
$msg_no_file = esc_html__( 'no file', 'buddypress-media' );
|
1087 |
|
1100 |
$ec_look_updated = 140004;
|
1101 |
$msg_look_updated = esc_html__( 'media updated', 'buddypress-media' );
|
1102 |
|
1103 |
+
$rtmedia_file = sanitize_text_field( filter_input( INPUT_POST, 'rtmedia_file', FILTER_SANITIZE_STRING ) );
|
1104 |
+
$image_type = sanitize_text_field( filter_input( INPUT_POST, 'image_type', FILTER_SANITIZE_STRING ) );
|
1105 |
+
$title = sanitize_text_field( filter_input( INPUT_POST, 'title', FILTER_SANITIZE_STRING ) );
|
1106 |
+
$description = sanitize_text_field( filter_input( INPUT_POST, 'description', FILTER_SANITIZE_STRING ) );
|
1107 |
|
1108 |
$updated = false;
|
1109 |
$uploaded_look = false;
|
1110 |
+
|
1111 |
if ( empty( $rtmedia_file ) && empty( $_FILES['rtmedia_file'] ) ) {
|
1112 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $ec_no_file, $msg_no_file ) );
|
1113 |
}
|
1114 |
+
|
1115 |
if ( ! empty( $rtmedia_file ) ) {
|
1116 |
if ( empty( $image_type ) ) {
|
1117 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $ec_image_type_missing, $msg_image_type_missing ) );
|
1120 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $ec_no_file_title, $msg_no_file_title ) );
|
1121 |
}
|
1122 |
}
|
1123 |
+
|
1124 |
if ( ! empty( $_FILES['rtmedia_file'] ) ) {
|
1125 |
+
// phpcs:disable Squiz.PHP.DisallowMultipleAssignments.Found, WordPress.Security.NonceVerification.NoNonceVerification
|
1126 |
$_POST['rtmedia_upload_nonce'] = $_REQUEST['rtmedia_upload_nonce'] = wp_create_nonce( 'rtmedia_upload_nonce' );
|
1127 |
$_POST['rtmedia_simple_file_upload'] = $_REQUEST['rtmedia_simple_file_upload'] = 1;
|
1128 |
$_POST['context'] = $_REQUEST['context'] = ! empty( $_REQUEST['context'] ) ? wp_unslash( $_REQUEST['context'] ) : 'profile';
|
1130 |
$_POST['mode'] = $_REQUEST['mode'] = 'file_upload';
|
1131 |
$_POST['media_author'] = $_REQUEST['media_author'] = $this->user_id;
|
1132 |
$upload = new RTMediaUploadEndpoint();
|
1133 |
+
// phpcs:enable Squiz.PHP.DisallowMultipleAssignments.Found, WordPress.Security.NonceVerification.NoNonceVerification
|
1134 |
+
// todo refactor below function so it takes param also and use if passed else use POST request.
|
1135 |
$uploaded_look = $upload->template_redirect();
|
1136 |
} else {
|
1137 |
+
|
1138 |
+
// Process rtmedia_file.
|
1139 |
$img = $rtmedia_file;
|
1140 |
$str_replace = 'data:image/' . $image_type . ';base64,';
|
1141 |
$img = str_replace( $str_replace, '', $img );
|
1142 |
+
$rtmedia_file = base64_decode( $img ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode
|
1143 |
+
|
1144 |
if ( ! $rtmedia_file ) {
|
1145 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $ec_invalid_file_string, $msg_invalid_file_string ) );
|
1146 |
}
|
1147 |
+
|
1148 |
define( 'UPLOAD_DIR_LOOK', sys_get_temp_dir() . '/' );
|
1149 |
+
|
1150 |
$tmp_name = UPLOAD_DIR_LOOK . $title;
|
1151 |
$file = $tmp_name . '.' . $image_type;
|
1152 |
+
$success = file_put_contents( $file, $rtmedia_file ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_file_put_contents
|
1153 |
+
|
1154 |
add_filter( 'upload_dir', array( $this, 'api_new_media_upload_dir' ) );
|
1155 |
+
$new_look = wp_upload_bits( $title . '.' . $image_type, null, $rtmedia_file );
|
1156 |
$new_look['type'] = 'image/' . $image_type;
|
1157 |
remove_filter( 'upload_dir', array( $this, 'api_new_media_upload_dir' ) );
|
1158 |
+
|
1159 |
foreach ( $new_look as $key => $value ) {
|
1160 |
$new_look[0][ $key ] = $value;
|
1161 |
unset( $new_look[ $key ] );
|
1162 |
}
|
1163 |
+
|
1164 |
if ( ! empty( $tags ) ) {
|
1165 |
$tags = explode( ',', $tags );
|
1166 |
}
|
1167 |
|
1168 |
$album_id = filter_input( INPUT_POST, 'album_id', FILTER_SANITIZE_NUMBER_INT );
|
1169 |
$context_id = filter_input( INPUT_POST, 'context_id', FILTER_SANITIZE_NUMBER_INT );
|
1170 |
+
$context = sanitize_text_field( filter_input( INPUT_POST, 'context', FILTER_SANITIZE_STRING ) );
|
1171 |
+
$privacy = sanitize_text_field( filter_input( INPUT_POST, 'privacy', FILTER_SANITIZE_STRING ) );
|
1172 |
+
$tags = sanitize_text_field( filter_input( INPUT_POST, 'tags', FILTER_SANITIZE_STRING ) );
|
1173 |
|
1174 |
$uploaded['rtmedia_upload_nonce'] = wp_create_nonce( 'rtmedia_upload_nonce' );
|
1175 |
$uploaded['rtmedia_simple_file_upload'] = 1;
|
1186 |
$rtmedia = new RTMediaMedia();
|
1187 |
$rtupload = $rtmedia->add( $uploaded, $new_look );
|
1188 |
$id = rtmedia_media_id( $rtupload[0] );
|
1189 |
+
|
1190 |
if ( ! empty( $tags ) ) {
|
1191 |
wp_set_post_terms( $id, $tags, 'media-category', true );
|
1192 |
}
|
1193 |
+
|
1194 |
$media = $rtmedia->model->get( array( 'id' => $rtupload[0] ) );
|
1195 |
$rtmedia_nav = new RTMediaNav();
|
1196 |
+
|
1197 |
if ( isset( $media ) && count( $media ) > 0 ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1198 |
|
1199 |
if ( 'group' === $media[0]->context ) {
|
1200 |
+
$rtmedia_nav->refresh_counts(
|
1201 |
+
$media[0]->context_id,
|
1202 |
+
array(
|
1203 |
+
'context' => sanitize_text_field( $media[0]->context ),
|
1204 |
+
'context_id' => intval( $media[0]->context_id ),
|
1205 |
+
)
|
1206 |
+
);
|
1207 |
} else {
|
1208 |
+
$rtmedia_nav->refresh_counts(
|
1209 |
+
$media[0]->media_author,
|
1210 |
+
array(
|
1211 |
+
'context' => 'profile',
|
1212 |
+
'media_author' => sanitize_text_field( $media[0]->media_author ),
|
1213 |
+
)
|
1214 |
+
);
|
1215 |
}
|
1216 |
+
|
1217 |
$activity_id = $rtmedia->insert_activity( $media[0]->media_id, $media[0] );
|
1218 |
$rtmedia->model->update( array( 'activity_id' => $activity_id ), array( 'id' => intval( $rtupload[0] ) ) );
|
|
|
1219 |
$same_medias = $rtmedia->model->get( array( 'activity_id' => $activity_id ) );
|
1220 |
|
1221 |
$update_activity_media = array();
|
1226 |
$obj_activity = new RTMediaActivity( $update_activity_media, $privacy, false );
|
1227 |
|
1228 |
global $wpdb, $bp;
|
1229 |
+
$updated = $wpdb->update(
|
1230 |
+
$bp->activity->table_name,
|
1231 |
+
array(
|
1232 |
+
'type' => 'rtmedia_update',
|
1233 |
+
'content' => $obj_activity->create_activity_html(),
|
1234 |
+
),
|
1235 |
+
array( 'id' => $activity_id )
|
1236 |
+
);
|
1237 |
|
1238 |
// if there is only single media the $updated value will be false even if the value we are passing to check is correct.
|
1239 |
+
// So we need to hardcode the $updated to true if there is only single media for same activity.
|
1240 |
if ( 1 === count( $same_medias ) && $activity_id ) {
|
1241 |
$updated = true;
|
1242 |
}
|
1250 |
}
|
1251 |
}
|
1252 |
|
1253 |
+
/**
|
1254 |
+
* Function to get gallery as per requested in API.
|
1255 |
+
*/
|
1256 |
+
public function rtmedia_api_process_rtmedia_gallery_request() {
|
1257 |
+
|
1258 |
$this->rtmediajsonapifunction->rtmedia_api_verfiy_token();
|
1259 |
+
// Errors.
|
1260 |
$ec_media = 160002;
|
1261 |
$msg_media = esc_html__( 'media list', 'buddypress-media' );
|
1262 |
|
1263 |
$ec_no_media = 160003;
|
1264 |
$msg_no_media = esc_html__( 'no media found for requested media type', 'buddypress-media' );
|
1265 |
|
|
|
|
|
|
|
1266 |
global $rtmedia;
|
1267 |
$rtmediamodel = new RTMediaModel();
|
1268 |
+
// Media type to fetch.
|
1269 |
+
$media_type = array_keys( $rtmedia->allowed_types );
|
1270 |
+
$allowed_types = $media_type;
|
1271 |
$media_type[] = 'album';
|
1272 |
$allowed_types[] = 'album';
|
1273 |
|
1275 |
$media_type_array = filter_input( INPUT_POST, 'media_type', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
|
1276 |
|
1277 |
if ( ! empty( $media_type_temp ) ) {
|
1278 |
+
// Explode by , when string found.
|
1279 |
$media_type = explode( ',', $media_type_temp );
|
1280 |
} elseif ( ! empty( $media_type_array ) && is_array( $media_type_array ) ) {
|
1281 |
+
// Set media_type to passed array.
|
1282 |
$media_type = $media_type_array;
|
1283 |
}
|
|
|
|
|
1284 |
|
1285 |
+
// Check array for currently allowed media types.
|
1286 |
+
$media_type = array_intersect( $media_type, $allowed_types );
|
1287 |
|
1288 |
+
// Args for fetching media.
|
1289 |
$args = array(
|
1290 |
'media_type' => $media_type,
|
1291 |
);
|
1292 |
|
1293 |
+
// global.
|
1294 |
+
$global = sanitize_text_field( filter_input( INPUT_POST, 'global', FILTER_SANITIZE_STRING ) );
|
1295 |
if ( isset( $global ) ) {
|
1296 |
if ( 'false' === $global ) {
|
1297 |
$args['context'] = array(
|
1300 |
);
|
1301 |
}
|
1302 |
}
|
1303 |
+
|
1304 |
+
// context.
|
1305 |
+
$context = sanitize_text_field( filter_input( INPUT_POST, 'context', FILTER_SANITIZE_STRING ) );
|
1306 |
if ( isset( $context ) ) {
|
1307 |
$args['context'] = $context;
|
1308 |
}
|
1309 |
+
|
1310 |
+
// context Id.
|
1311 |
$context_id = filter_input( INPUT_POST, 'context_id', FILTER_SANITIZE_NUMBER_INT );
|
1312 |
if ( isset( $context_id ) ) {
|
1313 |
$args['context_id'] = $context_id;
|
1314 |
}
|
1315 |
|
1316 |
+
// album id.
|
1317 |
$album_id = filter_input( INPUT_POST, 'album_id', FILTER_SANITIZE_NUMBER_INT );
|
1318 |
if ( ! empty( $album_id ) ) {
|
1319 |
$args['album_id'] = $album_id;
|
1320 |
}
|
1321 |
+
|
1322 |
+
// Media Author.
|
1323 |
if ( ! is_super_admin() ) {
|
1324 |
$media_author = $this->user_id;
|
1325 |
$args['media_author'] = $media_author;
|
1326 |
}
|
1327 |
+
|
1328 |
$media_author = filter_input( INPUT_POST, 'media_author', FILTER_SANITIZE_NUMBER_INT );
|
1329 |
if ( ! empty( $media_author ) ) {
|
1330 |
if ( is_super_admin( $this->user_id ) ) {
|
1331 |
$args['media_author'] = (int) $media_author;
|
1332 |
}
|
1333 |
}
|
1334 |
+
|
1335 |
$page = sanitize_text_field( filter_input( INPUT_POST, 'page', FILTER_SANITIZE_NUMBER_INT ) );
|
1336 |
$per_page = sanitize_text_field( filter_input( INPUT_POST, 'per_page', FILTER_SANITIZE_NUMBER_INT ) );
|
1337 |
$order_by = sanitize_text_field( filter_input( INPUT_POST, 'order_by', FILTER_SANITIZE_STRING ) );
|
1338 |
|
1339 |
+
$offset = ( ! empty( $page ) ) ? (int) $page : 0;
|
1340 |
|
1341 |
// Removed is_null check, because it won't be null.
|
1342 |
$per_page = ( ! empty( $per_page ) ) ? (int) $per_page : 10;
|
1344 |
|
1345 |
$media_list = $rtmediamodel->get( $args, $offset, $per_page, $order_by );
|
1346 |
$media_result = array();
|
1347 |
+
|
1348 |
foreach ( $media_list as $media ) {
|
1349 |
$data = array(
|
1350 |
'id' => $media->id,
|
1355 |
'url' => esc_url( get_rtmedia_permalink( $media->id ) ),
|
1356 |
'cover' => rtmedia_image( 'rt_media_thumbnail', $media->media_id, false ),
|
1357 |
);
|
1358 |
+
|
1359 |
+
// for album list all medias.
|
1360 |
if ( 'album' === $media->media_type ) {
|
1361 |
$data['media'] = $this->rtmediajsonapifunction->rtmedia_api_album_media( $media->id );
|
1362 |
}
|
1363 |
$media_result[] = $data;
|
1364 |
}
|
1365 |
+
|
1366 |
if ( ! empty( $media_result ) ) {
|
1367 |
wp_send_json( $this->rtmedia_api_response_object( 'TRUE', $ec_media, $msg_media, $media_result ) );
|
1368 |
} else {
|
1370 |
}
|
1371 |
}
|
1372 |
|
1373 |
+
/**
|
1374 |
+
* Send media details from requested media id to API.
|
1375 |
+
*/
|
1376 |
+
public function rtmedia_api_process_rtmedia_get_media_details_request() {
|
1377 |
|
1378 |
$this->rtmediajsonapifunction->rtmedia_api_verfiy_token();
|
1379 |
$this->rtmediajsonapifunction->rtmedia_api_media_activity_id_missing();
|
1380 |
+
// Errors.
|
1381 |
$ec_single_media = 150002;
|
1382 |
$msg_single_media = esc_html__( 'single media', 'buddypress-media' );
|
1383 |
|
1384 |
$media_id = filter_input( INPUT_POST, 'media_id', FILTER_SANITIZE_NUMBER_INT );
|
1385 |
+
$id = rtmedia_media_id( $media_id );
|
1386 |
+
|
1387 |
if ( empty( $id ) ) {
|
1388 |
wp_send_json( $this->rtmedia_api_response_object( 'TRUE', $this->ec_invalid_media_id, $this->msg_invalid_media_id ) );
|
1389 |
}
|
1390 |
+
|
1391 |
if ( class_exists( 'RTMediaModel' ) ) {
|
1392 |
$rtmediamodel = new RTMediaModel();
|
1393 |
$args = array(
|
1397 |
$media = $rtmediamodel->get( $args );
|
1398 |
}
|
1399 |
$activity_id = ! empty( $media ) ? $media[0]->activity_id : '';
|
1400 |
+
|
1401 |
if ( empty( $activity_id ) ) {
|
1402 |
wp_send_json( $this->rtmedia_api_response_object( 'FALSE', $this->ec_invalid_media_id, $this->msg_invalid_media_id ) );
|
1403 |
}
|
1408 |
}
|
1409 |
}
|
1410 |
|
1411 |
+
/**
|
1412 |
+
* Function to log out user from api.
|
1413 |
+
*/
|
1414 |
+
public function rtmedia_api_process_logout_request() {
|
1415 |
$this->rtmediajsonapifunction->rtmedia_api_verfiy_token();
|
1416 |
+
// Errors.
|
1417 |
$ec_logged_out = 200005;
|
1418 |
$msg_logged_out = 'logged out';
|
1419 |
$rtmapilogin = new RTMediaApiLogin();
|
1420 |
$updated = $rtmapilogin->update( array( 'status' => 'FALSE' ), array( 'user_id' => $this->user_id ) );
|
1421 |
+
|
1422 |
if ( $updated ) {
|
1423 |
wp_send_json( $this->rtmedia_api_response_object( 'TRUE', $ec_logged_out, $msg_logged_out ) );
|
1424 |
} else {
|
1427 |
|
1428 |
}
|
1429 |
|
1430 |
+
/**
|
1431 |
+
* Change uploads directory for new media.
|
1432 |
+
*
|
1433 |
+
* @param array $args Array of arguments.
|
1434 |
+
*
|
1435 |
+
* @return array
|
1436 |
+
*/
|
1437 |
+
public function api_new_media_upload_dir( $args ) {
|
1438 |
+
$token = sanitize_text_field( filter_input( INPUT_POST, 'token', FILTER_SANITIZE_STRING ) );
|
1439 |
|
1440 |
if ( ! empty( $args ) || ! is_array( $args ) || empty( $token ) ) {
|
1441 |
foreach ( $args as $key => $arg ) {
|
app/main/controllers/api/RTMediaJsonApiFunctions.php
CHANGED
@@ -1,35 +1,49 @@
|
|
1 |
<?php
|
2 |
-
//use MongoDB\BSON\Type;
|
3 |
-
|
4 |
/**
|
|
|
|
|
|
|
5 |
* @author Umesh Kumar<umeshsingla05@gmail.com>
|
6 |
*/
|
|
|
|
|
|
|
|
|
7 |
class RTMediaJsonApiFunctions {
|
8 |
|
9 |
-
|
10 |
-
|
|
|
|
|
11 |
|
12 |
/**
|
13 |
* Generates a user token for user login
|
14 |
*
|
15 |
-
* @param
|
16 |
-
* @param
|
17 |
*
|
18 |
-
* @return
|
19 |
*/
|
20 |
-
|
21 |
-
function rtmedia_api_get_user_token( $user_id, $user_login ) {
|
22 |
if ( empty( $user_id ) || empty( $user_login ) ) {
|
23 |
return false;
|
24 |
}
|
25 |
$string = '08~' . $user_id . '~' . $user_login . '~kumar';
|
26 |
|
27 |
-
return sha1( $string . current_time( 'timestamp' ) .
|
28 |
}
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
if ( empty( $user_id ) ) {
|
34 |
return false;
|
35 |
}
|
@@ -50,8 +64,14 @@ class RTMediaJsonApiFunctions {
|
|
50 |
return $user_data;
|
51 |
}
|
52 |
|
53 |
-
|
54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
if ( empty( $media ) ) {
|
56 |
return false;
|
57 |
}
|
@@ -64,11 +84,18 @@ class RTMediaJsonApiFunctions {
|
|
64 |
return $media_data;
|
65 |
}
|
66 |
|
67 |
-
|
68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
if ( empty( $token ) ) {
|
70 |
return false;
|
71 |
}
|
|
|
72 |
if ( class_exists( 'RTMediaApiLogin' ) ) {
|
73 |
$rtmediaapilogin = new RTMediaApiLogin();
|
74 |
$columns = array(
|
@@ -85,8 +112,14 @@ class RTMediaJsonApiFunctions {
|
|
85 |
}
|
86 |
}
|
87 |
|
88 |
-
|
89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
if ( empty( $token ) ) {
|
91 |
return false;
|
92 |
}
|
@@ -95,16 +128,18 @@ class RTMediaJsonApiFunctions {
|
|
95 |
return $token_data[0]->user_id;
|
96 |
}
|
97 |
|
98 |
-
|
99 |
-
|
100 |
-
|
|
|
101 |
$rtmjsonapi = new RTMediaJsonApi();
|
102 |
-
$token = filter_input( INPUT_POST, 'token', FILTER_SANITIZE_STRING );
|
|
|
103 |
if ( empty( $token ) ) {
|
104 |
wp_send_json( $rtmjsonapi->rtmedia_api_response_object( 'FALSE', $rtmjsonapi->ec_token_missing, $rtmjsonapi->msg_token_missing ) );
|
105 |
}
|
106 |
-
//Validate token
|
107 |
|
|
|
108 |
$token_valid = $this->rtmedia_api_validate_token( $token );
|
109 |
|
110 |
if ( ! $token_valid ) {
|
@@ -112,7 +147,10 @@ class RTMediaJsonApiFunctions {
|
|
112 |
}
|
113 |
}
|
114 |
|
115 |
-
|
|
|
|
|
|
|
116 |
$rtmjsonapi = new RTMediaJsonApi();
|
117 |
$activity_id = filter_input( INPUT_POST, 'activity_id', FILTER_SANITIZE_NUMBER_INT );
|
118 |
$media_id = filter_input( INPUT_POST, 'media_id', FILTER_SANITIZE_NUMBER_INT );
|
@@ -122,11 +160,20 @@ class RTMediaJsonApiFunctions {
|
|
122 |
}
|
123 |
}
|
124 |
|
125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
$rtmjsonapi = new RTMediaJsonApi();
|
|
|
127 |
if ( empty( $media_id ) ) {
|
128 |
return false;
|
129 |
}
|
|
|
130 |
$media_model = new RTMediaModel();
|
131 |
$result = $media_model->get( array( 'id' => $media_id ) );
|
132 |
|
@@ -137,16 +184,31 @@ class RTMediaJsonApiFunctions {
|
|
137 |
return $result[0]->activity_id;
|
138 |
}
|
139 |
|
140 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
if ( empty( $user_id ) ) {
|
142 |
return false;
|
143 |
}
|
|
|
144 |
$followers = bp_follow_get_followers( array( 'user_id' => $user_id ) );
|
145 |
|
146 |
return $followers;
|
147 |
}
|
148 |
|
149 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
150 |
if ( empty( $user_id ) ) {
|
151 |
return false;
|
152 |
}
|
@@ -157,16 +219,23 @@ class RTMediaJsonApiFunctions {
|
|
157 |
|
158 |
/**
|
159 |
* Accepts a rtmedia media object and returns a array of media details
|
|
|
|
|
|
|
|
|
160 |
*/
|
161 |
-
function rtmedia_api_media_details( $media_list ) {
|
162 |
global $rtmediajsonapi;
|
|
|
163 |
if ( empty( $media_list ) ) {
|
164 |
return false;
|
165 |
}
|
|
|
166 |
$result = array();
|
|
|
167 |
if ( is_array( $media_list ) ) {
|
168 |
foreach ( $media_list as $media ) {
|
169 |
-
//Media likes
|
170 |
$rtmediainteraction = new RTMediaInteractionModel();
|
171 |
$action = 'like';
|
172 |
$results = $rtmediainteraction->get_row( $rtmediajsonapi->user_id, $media['id'], $action );
|
@@ -189,15 +258,18 @@ class RTMediaJsonApiFunctions {
|
|
189 |
|
190 |
/**
|
191 |
* Fetches Activity for rtmedia updates, if user id for activity is provided fetches the user specific rtmedia updates
|
|
|
192 |
* @global type $activities_template
|
193 |
*
|
194 |
-
* @param
|
195 |
-
* @param
|
|
|
196 |
*
|
197 |
-
* @return array
|
198 |
*/
|
199 |
-
function rtmedia_api_get_feed( $activity_user_id = false, $activity_id = false, $per_page = 10 ) {
|
200 |
global $activities_template, $rtmediajsonapi;
|
|
|
201 |
$activity_feed = array();
|
202 |
$page = filter_input( INPUT_POST, 'page', FILTER_SANITIZE_NUMBER_INT, FILTER_NULL_ON_FAILURE );
|
203 |
$i = 0;
|
@@ -208,68 +280,84 @@ class RTMediaJsonApiFunctions {
|
|
208 |
'per_page' => $per_page,
|
209 |
'in' => $activity_id,
|
210 |
);
|
|
|
211 |
if ( bp_has_activities( $args ) ) :
|
|
|
212 |
$activity_feed['total_activity_count'] = $activities_template->total_activity_count;
|
213 |
$activity_feed['total'] = ceil( (int) $activities_template->total_activity_count / (int) $activities_template->pag_num );
|
214 |
$activity_feed['current'] = $activities_template->pag_page;
|
215 |
-
|
216 |
-
|
|
|
|
|
|
|
217 |
$activity_feed[ $i ]['id'] = $activities_template->activity->id;
|
218 |
$activity_feed[ $i ]['activity_type'] = $activities_template->activity->type;
|
219 |
$activity_feed[ $i ]['activity_time'] = bp_get_activity_date_recorded();
|
220 |
-
$activity_feed[ $i ]['activity_time_human'] =
|
221 |
$activity_feed[ $i ]['activity_content'] = $activities_template->activity->content;
|
222 |
|
223 |
-
//activity User
|
224 |
if ( ! $activity_user_id ) {
|
225 |
-
//Activity User data
|
226 |
$activity_feed[ $i ]['user'] = $this->rtmedia_api_user_data_from_id( bp_get_activity_user_id() );
|
227 |
}
|
228 |
|
229 |
-
//Media Details
|
230 |
if ( class_exists( 'RTMediaModel' ) ) {
|
231 |
$model = new RTMediaModel();
|
232 |
$media = $model->get_by_activity_id( $activities_template->activity->id );
|
233 |
|
234 |
if ( isset( $media['result'] ) && count( $media['result'] ) > 0 ) {
|
235 |
-
//Create media array
|
236 |
$media = $this->rtmedia_api_media_details( $media['result'] );
|
237 |
} else {
|
238 |
$media = false;
|
239 |
}
|
240 |
}
|
|
|
241 |
if ( $activity_id ) {
|
242 |
-
|
243 |
-
//Activity Comment Count
|
244 |
$id = $media[0]['id'];
|
245 |
$activity_feed[ $i ]['comments'] = $this->rtmedia_api_get_media_comments( $id );
|
246 |
}
|
247 |
-
//Activity Image
|
248 |
$activity_feed[ $i ]['media'] = $media;
|
249 |
-
$i
|
250 |
endwhile;
|
251 |
endif;
|
252 |
|
253 |
return $activity_feed;
|
254 |
}
|
255 |
|
256 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
257 |
global $wpdb;
|
258 |
$rtmjsonapi = new RTMediaJsonApi();
|
259 |
$id = rtmedia_media_id( $media_id );
|
|
|
260 |
if ( empty( $id ) ) {
|
261 |
wp_send_json( $rtmjsonapi->rtmedia_api_response_object( 'FALSE', $rtmjsonapi->ec_invalid_media_id, $rtmjsonapi->msg_invalid_media_id ) );
|
262 |
}
|
|
|
263 |
$comments = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->comments} WHERE comment_post_ID = %d limit 100", $id ), ARRAY_A );
|
264 |
|
265 |
$media_comments = array();
|
266 |
if ( ! empty( $comments ) ) {
|
|
|
267 |
foreach ( $comments as $comment ) {
|
268 |
$media_comments['comments'][] = array(
|
269 |
'comment_ID' => $comment['comment_ID'],
|
270 |
'comment_content' => $comment['comment_content'],
|
271 |
'user_id' => $comment['user_id'],
|
272 |
);
|
|
|
273 |
if ( ! array_key_exists( $comment['user_id'], $media_comments['user'] ) ) {
|
274 |
|
275 |
$user_data = $this->rtmedia_api_user_data_from_id( $comment['user_id'] );
|
@@ -285,29 +373,47 @@ class RTMediaJsonApiFunctions {
|
|
285 |
return $media_comments;
|
286 |
}
|
287 |
|
288 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
289 |
$rtmedia_interaction_model = new RTMediaInteractionModel();
|
290 |
-
$media_like_cols
|
291 |
'media_id' => $media_id,
|
292 |
'action' => 'like',
|
293 |
'value' => 1,
|
294 |
);
|
295 |
-
$likers = $rtmedia_interaction_model->get( $media_like_cols, false, false, 'action_date' );
|
296 |
|
297 |
-
|
|
|
|
|
298 |
}
|
299 |
|
300 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
301 |
if ( empty( $album_id ) ) {
|
302 |
return false;
|
303 |
}
|
|
|
304 |
$rtmediamodel = new RTMediaModel();
|
305 |
$args = array(
|
306 |
'album_id' => $album_id,
|
307 |
);
|
308 |
$media_list = $rtmediamodel->get( $args );
|
309 |
$media_data = array();
|
|
|
310 |
if ( ! empty( $media_list ) && is_array( $media_list ) ) {
|
|
|
311 |
foreach ( $media_list as $media ) {
|
312 |
$media_data[] = array(
|
313 |
'id' => $media->id,
|
@@ -322,7 +428,12 @@ class RTMediaJsonApiFunctions {
|
|
322 |
return $media_data;
|
323 |
}
|
324 |
|
325 |
-
|
|
|
|
|
|
|
|
|
|
|
326 |
global $rtmediajsonapi;
|
327 |
|
328 |
return $rtmediajsonapi->user_id;
|
1 |
<?php
|
|
|
|
|
2 |
/**
|
3 |
+
* API function to handle API requests for data.
|
4 |
+
*
|
5 |
+
* @package rtMedia
|
6 |
* @author Umesh Kumar<umeshsingla05@gmail.com>
|
7 |
*/
|
8 |
+
|
9 |
+
/**
|
10 |
+
* Class to handle API requests for data.
|
11 |
+
*/
|
12 |
class RTMediaJsonApiFunctions {
|
13 |
|
14 |
+
/**
|
15 |
+
* RTMediaJsonApiFunctions constructor.
|
16 |
+
*/
|
17 |
+
public function __construct() {}
|
18 |
|
19 |
/**
|
20 |
* Generates a user token for user login
|
21 |
*
|
22 |
+
* @param int $user_id User id to generate token.
|
23 |
+
* @param string $user_login User login to generate token.
|
24 |
*
|
25 |
+
* @return bool|string
|
26 |
*/
|
27 |
+
public function rtmedia_api_get_user_token( $user_id, $user_login ) {
|
|
|
28 |
if ( empty( $user_id ) || empty( $user_login ) ) {
|
29 |
return false;
|
30 |
}
|
31 |
$string = '08~' . $user_id . '~' . $user_login . '~kumar';
|
32 |
|
33 |
+
return sha1( $string . current_time( 'timestamp' ) . wp_rand( 1, 9 ) );
|
34 |
}
|
35 |
|
36 |
+
/**
|
37 |
+
* User data from user id
|
38 |
+
*
|
39 |
+
* @param int $user_id User id to get details.
|
40 |
+
* @param int $width Width of avatar.
|
41 |
+
* @param int $height Height of avatar.
|
42 |
+
* @param string $type Avatar type.
|
43 |
+
*
|
44 |
+
* @return array|bool
|
45 |
+
*/
|
46 |
+
public function rtmedia_api_user_data_from_id( $user_id, $width = 80, $height = 80, $type = 'thumb' ) {
|
47 |
if ( empty( $user_id ) ) {
|
48 |
return false;
|
49 |
}
|
64 |
return $user_data;
|
65 |
}
|
66 |
|
67 |
+
/**
|
68 |
+
* Media details from media id
|
69 |
+
*
|
70 |
+
* @param array $media Array consisting media id to get details.
|
71 |
+
*
|
72 |
+
* @return array|bool
|
73 |
+
*/
|
74 |
+
public function rtmedia_api_media_data_from_object( $media ) {
|
75 |
if ( empty( $media ) ) {
|
76 |
return false;
|
77 |
}
|
84 |
return $media_data;
|
85 |
}
|
86 |
|
87 |
+
/**
|
88 |
+
* Function to Validate token
|
89 |
+
*
|
90 |
+
* @param string $token Token to get validated.
|
91 |
+
*
|
92 |
+
* @return array|bool
|
93 |
+
*/
|
94 |
+
public function rtmedia_api_validate_token( $token ) {
|
95 |
if ( empty( $token ) ) {
|
96 |
return false;
|
97 |
}
|
98 |
+
|
99 |
if ( class_exists( 'RTMediaApiLogin' ) ) {
|
100 |
$rtmediaapilogin = new RTMediaApiLogin();
|
101 |
$columns = array(
|
112 |
}
|
113 |
}
|
114 |
|
115 |
+
/**
|
116 |
+
* Get user id from token
|
117 |
+
*
|
118 |
+
* @param string $token Token to get user.
|
119 |
+
*
|
120 |
+
* @return bool
|
121 |
+
*/
|
122 |
+
public function rtmedia_api_get_user_id_from_token( $token ) {
|
123 |
if ( empty( $token ) ) {
|
124 |
return false;
|
125 |
}
|
128 |
return $token_data[0]->user_id;
|
129 |
}
|
130 |
|
131 |
+
/**
|
132 |
+
* Token processing for all data fetch/post requests
|
133 |
+
*/
|
134 |
+
public function rtmedia_api_verfiy_token() {
|
135 |
$rtmjsonapi = new RTMediaJsonApi();
|
136 |
+
$token = sanitize_text_field( filter_input( INPUT_POST, 'token', FILTER_SANITIZE_STRING ) );
|
137 |
+
|
138 |
if ( empty( $token ) ) {
|
139 |
wp_send_json( $rtmjsonapi->rtmedia_api_response_object( 'FALSE', $rtmjsonapi->ec_token_missing, $rtmjsonapi->msg_token_missing ) );
|
140 |
}
|
|
|
141 |
|
142 |
+
// Validate token.
|
143 |
$token_valid = $this->rtmedia_api_validate_token( $token );
|
144 |
|
145 |
if ( ! $token_valid ) {
|
147 |
}
|
148 |
}
|
149 |
|
150 |
+
/**
|
151 |
+
* Function to send response when activity and media id is missing.
|
152 |
+
*/
|
153 |
+
public function rtmedia_api_media_activity_id_missing() {
|
154 |
$rtmjsonapi = new RTMediaJsonApi();
|
155 |
$activity_id = filter_input( INPUT_POST, 'activity_id', FILTER_SANITIZE_NUMBER_INT );
|
156 |
$media_id = filter_input( INPUT_POST, 'media_id', FILTER_SANITIZE_NUMBER_INT );
|
160 |
}
|
161 |
}
|
162 |
|
163 |
+
/**
|
164 |
+
* Function to get activity from media.
|
165 |
+
*
|
166 |
+
* @param int $media_id Media id to get activity.
|
167 |
+
*
|
168 |
+
* @return bool
|
169 |
+
*/
|
170 |
+
public function rtmedia_api_activityid_from_mediaid( $media_id ) {
|
171 |
$rtmjsonapi = new RTMediaJsonApi();
|
172 |
+
|
173 |
if ( empty( $media_id ) ) {
|
174 |
return false;
|
175 |
}
|
176 |
+
|
177 |
$media_model = new RTMediaModel();
|
178 |
$result = $media_model->get( array( 'id' => $media_id ) );
|
179 |
|
184 |
return $result[0]->activity_id;
|
185 |
}
|
186 |
|
187 |
+
/**
|
188 |
+
* Get followers of the user.
|
189 |
+
*
|
190 |
+
* @param int $user_id User ID to get followers of user.
|
191 |
+
*
|
192 |
+
* @return bool
|
193 |
+
*/
|
194 |
+
public function rtmedia_api_followers( $user_id ) {
|
195 |
if ( empty( $user_id ) ) {
|
196 |
return false;
|
197 |
}
|
198 |
+
|
199 |
$followers = bp_follow_get_followers( array( 'user_id' => $user_id ) );
|
200 |
|
201 |
return $followers;
|
202 |
}
|
203 |
|
204 |
+
/**
|
205 |
+
* Get users which provided user follows.
|
206 |
+
*
|
207 |
+
* @param int $user_id User ID to get following users.
|
208 |
+
*
|
209 |
+
* @return bool
|
210 |
+
*/
|
211 |
+
public function rtmedia_api_following( $user_id ) {
|
212 |
if ( empty( $user_id ) ) {
|
213 |
return false;
|
214 |
}
|
219 |
|
220 |
/**
|
221 |
* Accepts a rtmedia media object and returns a array of media details
|
222 |
+
*
|
223 |
+
* @param array $media_list Media array to get details.
|
224 |
+
*
|
225 |
+
* @return array|bool
|
226 |
*/
|
227 |
+
public function rtmedia_api_media_details( $media_list ) {
|
228 |
global $rtmediajsonapi;
|
229 |
+
|
230 |
if ( empty( $media_list ) ) {
|
231 |
return false;
|
232 |
}
|
233 |
+
|
234 |
$result = array();
|
235 |
+
|
236 |
if ( is_array( $media_list ) ) {
|
237 |
foreach ( $media_list as $media ) {
|
238 |
+
// Media likes.
|
239 |
$rtmediainteraction = new RTMediaInteractionModel();
|
240 |
$action = 'like';
|
241 |
$results = $rtmediainteraction->get_row( $rtmediajsonapi->user_id, $media['id'], $action );
|
258 |
|
259 |
/**
|
260 |
* Fetches Activity for rtmedia updates, if user id for activity is provided fetches the user specific rtmedia updates
|
261 |
+
*
|
262 |
* @global type $activities_template
|
263 |
*
|
264 |
+
* @param bool $activity_user_id User id to get activity.
|
265 |
+
* @param bool $activity_id Activity ID to get updates.
|
266 |
+
* @param int $per_page Per page count for activity update feed.
|
267 |
*
|
268 |
+
* @return array
|
269 |
*/
|
270 |
+
public function rtmedia_api_get_feed( $activity_user_id = false, $activity_id = false, $per_page = 10 ) {
|
271 |
global $activities_template, $rtmediajsonapi;
|
272 |
+
|
273 |
$activity_feed = array();
|
274 |
$page = filter_input( INPUT_POST, 'page', FILTER_SANITIZE_NUMBER_INT, FILTER_NULL_ON_FAILURE );
|
275 |
$i = 0;
|
280 |
'per_page' => $per_page,
|
281 |
'in' => $activity_id,
|
282 |
);
|
283 |
+
|
284 |
if ( bp_has_activities( $args ) ) :
|
285 |
+
|
286 |
$activity_feed['total_activity_count'] = $activities_template->total_activity_count;
|
287 |
$activity_feed['total'] = ceil( (int) $activities_template->total_activity_count / (int) $activities_template->pag_num );
|
288 |
$activity_feed['current'] = $activities_template->pag_page;
|
289 |
+
|
290 |
+
while ( bp_activities() ) :
|
291 |
+
bp_the_activity();
|
292 |
+
|
293 |
+
// Activity basic details.
|
294 |
$activity_feed[ $i ]['id'] = $activities_template->activity->id;
|
295 |
$activity_feed[ $i ]['activity_type'] = $activities_template->activity->type;
|
296 |
$activity_feed[ $i ]['activity_time'] = bp_get_activity_date_recorded();
|
297 |
+
$activity_feed[ $i ]['activity_time_human'] = wp_strip_all_tags( bp_insert_activity_meta( '' ) );
|
298 |
$activity_feed[ $i ]['activity_content'] = $activities_template->activity->content;
|
299 |
|
300 |
+
// activity User.
|
301 |
if ( ! $activity_user_id ) {
|
302 |
+
// Activity User data.
|
303 |
$activity_feed[ $i ]['user'] = $this->rtmedia_api_user_data_from_id( bp_get_activity_user_id() );
|
304 |
}
|
305 |
|
306 |
+
// Media Details.
|
307 |
if ( class_exists( 'RTMediaModel' ) ) {
|
308 |
$model = new RTMediaModel();
|
309 |
$media = $model->get_by_activity_id( $activities_template->activity->id );
|
310 |
|
311 |
if ( isset( $media['result'] ) && count( $media['result'] ) > 0 ) {
|
312 |
+
// Create media array.
|
313 |
$media = $this->rtmedia_api_media_details( $media['result'] );
|
314 |
} else {
|
315 |
$media = false;
|
316 |
}
|
317 |
}
|
318 |
+
|
319 |
if ( $activity_id ) {
|
320 |
+
// Activity Comment Count.
|
|
|
321 |
$id = $media[0]['id'];
|
322 |
$activity_feed[ $i ]['comments'] = $this->rtmedia_api_get_media_comments( $id );
|
323 |
}
|
324 |
+
// Activity Image.
|
325 |
$activity_feed[ $i ]['media'] = $media;
|
326 |
+
$i++;
|
327 |
endwhile;
|
328 |
endif;
|
329 |
|
330 |
return $activity_feed;
|
331 |
}
|
332 |
|
333 |
+
/**
|
334 |
+
* Function to get media comments.
|
335 |
+
*
|
336 |
+
* @param int $media_id Media id to get comments.
|
337 |
+
*
|
338 |
+
* @return array
|
339 |
+
*/
|
340 |
+
public function rtmedia_api_get_media_comments( $media_id ) {
|
341 |
global $wpdb;
|
342 |
$rtmjsonapi = new RTMediaJsonApi();
|
343 |
$id = rtmedia_media_id( $media_id );
|
344 |
+
|
345 |
if ( empty( $id ) ) {
|
346 |
wp_send_json( $rtmjsonapi->rtmedia_api_response_object( 'FALSE', $rtmjsonapi->ec_invalid_media_id, $rtmjsonapi->msg_invalid_media_id ) );
|
347 |
}
|
348 |
+
|
349 |
$comments = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->comments} WHERE comment_post_ID = %d limit 100", $id ), ARRAY_A );
|
350 |
|
351 |
$media_comments = array();
|
352 |
if ( ! empty( $comments ) ) {
|
353 |
+
|
354 |
foreach ( $comments as $comment ) {
|
355 |
$media_comments['comments'][] = array(
|
356 |
'comment_ID' => $comment['comment_ID'],
|
357 |
'comment_content' => $comment['comment_content'],
|
358 |
'user_id' => $comment['user_id'],
|
359 |
);
|
360 |
+
|
361 |
if ( ! array_key_exists( $comment['user_id'], $media_comments['user'] ) ) {
|
362 |
|
363 |
$user_data = $this->rtmedia_api_user_data_from_id( $comment['user_id'] );
|
373 |
return $media_comments;
|
374 |
}
|
375 |
|
376 |
+
/**
|
377 |
+
* Get users who liked particular media.
|
378 |
+
*
|
379 |
+
* @param int $media_id Media id to get users who liked it.
|
380 |
+
*
|
381 |
+
* @return array
|
382 |
+
*/
|
383 |
+
public function rtmedia_api_media_liked_by_user( $media_id ) {
|
384 |
$rtmedia_interaction_model = new RTMediaInteractionModel();
|
385 |
+
$media_like_cols = array(
|
386 |
'media_id' => $media_id,
|
387 |
'action' => 'like',
|
388 |
'value' => 1,
|
389 |
);
|
|
|
390 |
|
391 |
+
$liked_by = $rtmedia_interaction_model->get( $media_like_cols, false, false, 'action_date' );
|
392 |
+
|
393 |
+
return $liked_by;
|
394 |
}
|
395 |
|
396 |
+
/**
|
397 |
+
* Function to get details of media in album.
|
398 |
+
*
|
399 |
+
* @param int $album_id Album id to get details.
|
400 |
+
*
|
401 |
+
* @return array|bool
|
402 |
+
*/
|
403 |
+
public function rtmedia_api_album_media( $album_id ) {
|
404 |
if ( empty( $album_id ) ) {
|
405 |
return false;
|
406 |
}
|
407 |
+
|
408 |
$rtmediamodel = new RTMediaModel();
|
409 |
$args = array(
|
410 |
'album_id' => $album_id,
|
411 |
);
|
412 |
$media_list = $rtmediamodel->get( $args );
|
413 |
$media_data = array();
|
414 |
+
|
415 |
if ( ! empty( $media_list ) && is_array( $media_list ) ) {
|
416 |
+
|
417 |
foreach ( $media_list as $media ) {
|
418 |
$media_data[] = array(
|
419 |
'id' => $media->id,
|
428 |
return $media_data;
|
429 |
}
|
430 |
|
431 |
+
/**
|
432 |
+
* Function to return user id from json API object.
|
433 |
+
*
|
434 |
+
* @return mixed
|
435 |
+
*/
|
436 |
+
public function rtmedia_api_set_user_id() {
|
437 |
global $rtmediajsonapi;
|
438 |
|
439 |
return $rtmediajsonapi->user_id;
|
app/main/controllers/group/RTMediaGroup.php
CHANGED
@@ -1,23 +1,36 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
|
4 |
-
* To change this template, choose Tools | Templates
|
5 |
-
* and open the template in the editor.
|
6 |
*
|
|
|
7 |
*/
|
8 |
|
|
|
|
|
|
|
9 |
class RTMediaGroup {
|
|
|
|
|
|
|
|
|
|
|
10 |
public $create_slug = 'media-setting';
|
11 |
|
12 |
-
|
|
|
|
|
|
|
13 |
global $rtmedia;
|
14 |
$options = $rtmedia->options;
|
|
|
15 |
if ( isset( $options['buddypress_enableOnGroup'] ) && 1 === intval( $options ['buddypress_enableOnGroup'] ) ) {
|
16 |
-
// return
|
17 |
$extension = true;
|
|
|
18 |
if ( isset( $options['general_enableAlbums'] ) && 0 === intval( $options['general_enableAlbums'] ) ) {
|
19 |
$extension = false;
|
20 |
}
|
|
|
21 |
$extension = apply_filters( 'rtmedia_group_media_extension', $extension );
|
22 |
if ( ! $extension ) {
|
23 |
return;
|
@@ -35,9 +48,9 @@ class RTMediaGroup {
|
|
35 |
/**
|
36 |
* Update group last activity.
|
37 |
*
|
38 |
-
* @param $group_id
|
39 |
*/
|
40 |
-
static function update_last_active( $group_id ) {
|
41 |
groups_update_last_activity( $group_id );
|
42 |
}
|
43 |
}
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* Handles rtMedia media group related tasks.
|
|
|
|
|
4 |
*
|
5 |
+
* @package rtMedia
|
6 |
*/
|
7 |
|
8 |
+
/**
|
9 |
+
* Class RTMediaGroup to handle rtMedia media group related tasks.
|
10 |
+
*/
|
11 |
class RTMediaGroup {
|
12 |
+
/**
|
13 |
+
* Media setting slug.
|
14 |
+
*
|
15 |
+
* @var string
|
16 |
+
*/
|
17 |
public $create_slug = 'media-setting';
|
18 |
|
19 |
+
/**
|
20 |
+
* RTMediaGroup constructor.
|
21 |
+
*/
|
22 |
+
public function __construct() {
|
23 |
global $rtmedia;
|
24 |
$options = $rtmedia->options;
|
25 |
+
|
26 |
if ( isset( $options['buddypress_enableOnGroup'] ) && 1 === intval( $options ['buddypress_enableOnGroup'] ) ) {
|
27 |
+
// return.
|
28 |
$extension = true;
|
29 |
+
|
30 |
if ( isset( $options['general_enableAlbums'] ) && 0 === intval( $options['general_enableAlbums'] ) ) {
|
31 |
$extension = false;
|
32 |
}
|
33 |
+
|
34 |
$extension = apply_filters( 'rtmedia_group_media_extension', $extension );
|
35 |
if ( ! $extension ) {
|
36 |
return;
|
48 |
/**
|
49 |
* Update group last activity.
|
50 |
*
|
51 |
+
* @param int $group_id Group id to get last activity.
|
52 |
*/
|
53 |
+
public static function update_last_active( $group_id ) {
|
54 |
groups_update_last_activity( $group_id );
|
55 |
}
|
56 |
}
|
app/main/controllers/group/RTMediaGroupExtension.php
CHANGED
@@ -1,31 +1,76 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
-
*
|
4 |
*
|
|
|
5 |
* @author faishal
|
6 |
*/
|
7 |
-
if ( class_exists( 'BP_Group_Extension' ) ) :// Recommended, to prevent problems during upgrade or when Groups are disabled
|
8 |
|
|
|
|
|
|
|
|
|
|
|
9 |
class RTMediaGroupExtension extends BP_Group_Extension {
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
$this->create_step_position = 21;
|
15 |
-
$this->enable_nav_item
|
16 |
}
|
17 |
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
if ( ! bp_is_group_creation_step( $this->slug ) ) {
|
21 |
-
return false;
|
22 |
-
|
|
|
|
|
23 |
do_action( 'rtmedia_group_media_control_create' );
|
24 |
|
25 |
global $rtmedia;
|
26 |
$options = $rtmedia->options; ?>
|
27 |
<div class='rtmedia-group-media-settings'>
|
28 |
-
<?php if ( isset( $options['general_enableAlbums'] ) && 1 === intval( $options['general_enableAlbums'] ) ) { // album is enabled ?>
|
29 |
|
30 |
<h4><?php esc_html_e( 'Album Creation Control', 'buddypress-media' ); ?></h4>
|
31 |
<p><?php esc_html_e( 'Who can create Albums in this group?', 'buddypress-media' ); ?></p>
|
@@ -52,24 +97,26 @@ if ( class_exists( 'BP_Group_Extension' ) ) :// Recommended, to prevent problems
|
|
52 |
wp_nonce_field( 'groups_create_save_' . $this->slug );
|
53 |
}
|
54 |
|
|
|
55 |
/**
|
|
|
56 |
*
|
57 |
-
* @
|
58 |
*/
|
59 |
-
function create_screen_save( $group_id = null ) {
|
60 |
global $bp;
|
61 |
|
62 |
check_admin_referer( 'groups_create_save_' . $this->slug );
|
63 |
|
64 |
/**
|
65 |
-
*
|
66 |
* By: Yahil
|
67 |
*/
|
68 |
-
$rt_album_creation_control
|
69 |
-
$rtmp_playlist_creation_control = filter_input( INPUT_POST, 'rtmp_playlist_creation_control', FILTER_SANITIZE_STRING );
|
70 |
|
71 |
/**
|
72 |
-
*
|
73 |
* By: Yahil
|
74 |
*/
|
75 |
if ( isset( $rt_album_creation_control ) && ! empty( $rt_album_creation_control ) ) {
|
@@ -80,16 +127,17 @@ if ( class_exists( 'BP_Group_Extension' ) ) :// Recommended, to prevent problems
|
|
80 |
groups_update_groupmeta( $bp->groups->new_group_id, 'rtmp_create_playlist_control_level', $rtmp_playlist_creation_control );
|
81 |
}
|
82 |
|
83 |
-
|
84 |
}
|
85 |
|
86 |
/**
|
|
|
87 |
*
|
88 |
-
* @param null
|
89 |
*
|
90 |
* @return bool
|
91 |
*/
|
92 |
-
function edit_screen( $group_id = null ) {
|
93 |
if ( ! bp_is_group_admin_screen( $this->slug ) ) {
|
94 |
return false; }
|
95 |
$current_level = groups_get_groupmeta( bp_get_current_group_id(), 'rt_media_group_control_level' );
|
@@ -97,54 +145,58 @@ if ( class_exists( 'BP_Group_Extension' ) ) :// Recommended, to prevent problems
|
|
97 |
$current_level = 'all';
|
98 |
}
|
99 |
|
100 |
-
// HOOK to add PER GROUP MEDIA enable/diable option in rtMedia PRO
|
101 |
-
do_action( 'rtmedia_group_media_control_edit' );
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
|
|
|
|
|
|
133 |
}
|
134 |
|
135 |
/**
|
|
|
136 |
*
|
137 |
-
* @param null/int $group_id
|
138 |
*
|
139 |
* @return bool
|
140 |
*/
|
141 |
-
function edit_screen_save( $group_id = null ) {
|
142 |
global $bp;
|
143 |
|
144 |
-
$is_save = filter_input( INPUT_POST, 'save', FILTER_SANITIZE_STRING, FILTER_FLAG_EMPTY_STRING_NULL );
|
145 |
|
146 |
/**
|
147 |
-
*
|
148 |
* if ( ! empty( $is_save ) ) {
|
149 |
* it was returning false even when $is_save variable was not empty
|
150 |
* remove this comment after sometime
|
@@ -158,14 +210,14 @@ if ( class_exists( 'BP_Group_Extension' ) ) :// Recommended, to prevent problems
|
|
158 |
* Add PLAYLIST CREATION CONTROL save functionality
|
159 |
* By: Yahil
|
160 |
*/
|
161 |
-
$rt_album_creation_control
|
162 |
-
$rtmp_playlist_creation_control
|
163 |
|
164 |
check_admin_referer( 'groups_edit_save_' . $this->slug );
|
165 |
|
166 |
-
if ( isset( $rt_album_creation_control ) && ! empty( $rt_album_creation_control )
|
167 |
$success = groups_update_groupmeta( bp_get_current_group_id(), 'rt_media_group_control_level', $rt_album_creation_control );
|
168 |
-
do_action( 'rtmedia_edit_save_group_media_settings'
|
169 |
$success = true;
|
170 |
} else {
|
171 |
$success = false;
|
@@ -173,11 +225,11 @@ if ( class_exists( 'BP_Group_Extension' ) ) :// Recommended, to prevent problems
|
|
173 |
|
174 |
if ( isset( $rtmp_playlist_creation_control ) && ! empty( $rtmp_playlist_creation_control ) ) {
|
175 |
$success = groups_update_groupmeta( bp_get_current_group_id(), 'rtmp_create_playlist_control_level', $rtmp_playlist_creation_control );
|
176 |
-
do_action( 'rtmedia_edit_save_group_media_settings'
|
177 |
$success = true;
|
178 |
}
|
179 |
|
180 |
-
|
181 |
if ( ! $success ) {
|
182 |
bp_core_add_message( esc_html__( 'There was an error saving, please try again', 'buddypress-media' ), 'error' );
|
183 |
} else {
|
@@ -191,16 +243,13 @@ if ( class_exists( 'BP_Group_Extension' ) ) :// Recommended, to prevent problems
|
|
191 |
* The display method for the extension
|
192 |
*
|
193 |
* @since BuddyPress Media 2.3
|
194 |
-
*/
|
195 |
-
|
196 |
-
/**
|
197 |
*
|
198 |
* @global type $bp_media
|
199 |
*/
|
200 |
-
function widget_display() {
|
201 |
?>
|
202 |
<div class="info-group" >
|
203 |
-
<h4><?php echo esc_html( $this->name ) ?></h4>
|
204 |
<p>
|
205 |
<?php esc_html_e( 'You could display a small snippet of information from your group extension here. It will show on the group home screen.', 'buddypress-media' ); ?>
|
206 |
</p>
|
@@ -209,4 +258,4 @@ if ( class_exists( 'BP_Group_Extension' ) ) :// Recommended, to prevent problems
|
|
209 |
}
|
210 |
}
|
211 |
|
212 |
-
endif; // class_exists
|
1 |
<?php
|
2 |
/**
|
3 |
+
* Handles Group albums settings.
|
4 |
*
|
5 |
+
* @package rtMedia
|
6 |
* @author faishal
|
7 |
*/
|
|
|
8 |
|
9 |
+
if ( class_exists( 'BP_Group_Extension' ) ) :// Recommended, to prevent problems during upgrade or when Groups are disabled.
|
10 |
+
|
11 |
+
/**
|
12 |
+
* Class to handle Media group albums.
|
13 |
+
*/
|
14 |
class RTMediaGroupExtension extends BP_Group_Extension {
|
15 |
|
16 |
+
/**
|
17 |
+
* Media settings tab name.
|
18 |
+
*
|
19 |
+
* @var void|string
|
20 |
+
*/
|
21 |
+
public $name;
|
22 |
+
|
23 |
+
/**
|
24 |
+
* Media setting slug.
|
25 |
+
*
|
26 |
+
* @var string
|
27 |
+
*/
|
28 |
+
public $slug;
|
29 |
+
|
30 |
+
/**
|
31 |
+
* Group creation step position.
|
32 |
+
*
|
33 |
+
* @var int
|
34 |
+
*/
|
35 |
+
public $create_step_position;
|
36 |
+
|
37 |
+
/**
|
38 |
+
* Enable navigation.
|
39 |
+
*
|
40 |
+
* @var bool
|
41 |
+
*/
|
42 |
+
public $enable_nav_item;
|
43 |
+
|
44 |
+
/**
|
45 |
+
* RTMediaGroupExtension constructor.
|
46 |
+
*/
|
47 |
+
public function __construct() {
|
48 |
+
$this->name = apply_filters( 'rtmedia_media_tab_name', RTMEDIA_MEDIA_LABEL );
|
49 |
+
$this->slug = RTMEDIA_MEDIA_SLUG . '-setting';
|
50 |
$this->create_step_position = 21;
|
51 |
+
$this->enable_nav_item = false;
|
52 |
}
|
53 |
|
54 |
+
/**
|
55 |
+
* Group album creation screen div.
|
56 |
+
*
|
57 |
+
* @param int $group_id Group id to create media group.
|
58 |
+
*
|
59 |
+
* @return bool
|
60 |
+
*/
|
61 |
+
public function create_screen( $group_id = null ) {
|
62 |
|
63 |
if ( ! bp_is_group_creation_step( $this->slug ) ) {
|
64 |
+
return false;
|
65 |
+
}
|
66 |
+
|
67 |
+
// HOOK to add PER GROUP MEDIA enable/diable option in rtMedia PRO.
|
68 |
do_action( 'rtmedia_group_media_control_create' );
|
69 |
|
70 |
global $rtmedia;
|
71 |
$options = $rtmedia->options; ?>
|
72 |
<div class='rtmedia-group-media-settings'>
|
73 |
+
<?php if ( isset( $options['general_enableAlbums'] ) && 1 === intval( $options['general_enableAlbums'] ) ) { // album is enabled. ?>
|
74 |
|
75 |
<h4><?php esc_html_e( 'Album Creation Control', 'buddypress-media' ); ?></h4>
|
76 |
<p><?php esc_html_e( 'Who can create Albums in this group?', 'buddypress-media' ); ?></p>
|
97 |
wp_nonce_field( 'groups_create_save_' . $this->slug );
|
98 |
}
|
99 |
|
100 |
+
|
101 |
/**
|
102 |
+
* Save group media details.
|
103 |
*
|
104 |
+
* @param int $group_id Group id to save details.
|
105 |
*/
|
106 |
+
public function create_screen_save( $group_id = null ) {
|
107 |
global $bp;
|
108 |
|
109 |
check_admin_referer( 'groups_create_save_' . $this->slug );
|
110 |
|
111 |
/**
|
112 |
+
* Add playlist Save functionality
|
113 |
* By: Yahil
|
114 |
*/
|
115 |
+
$rt_album_creation_control = sanitize_text_field( filter_input( INPUT_POST, 'rt_album_creation_control', FILTER_SANITIZE_STRING ) );
|
116 |
+
$rtmp_playlist_creation_control = sanitize_text_field( filter_input( INPUT_POST, 'rtmp_playlist_creation_control', FILTER_SANITIZE_STRING ) );
|
117 |
|
118 |
/**
|
119 |
+
* Save details 'ALBUM CREATION CONTROL' and 'PLAYLIST CREATION CONTROL'
|
120 |
* By: Yahil
|
121 |
*/
|
122 |
if ( isset( $rt_album_creation_control ) && ! empty( $rt_album_creation_control ) ) {
|
127 |
groups_update_groupmeta( $bp->groups->new_group_id, 'rtmp_create_playlist_control_level', $rtmp_playlist_creation_control );
|
128 |
}
|
129 |
|
130 |
+
do_action( 'rtmedia_create_save_group_media_settings', $_POST );
|
131 |
}
|
132 |
|
133 |
/**
|
134 |
+
* Edit media group screen.
|
135 |
*
|
136 |
+
* @param null|int $group_id Group id to edit.
|
137 |
*
|
138 |
* @return bool
|
139 |
*/
|
140 |
+
public function edit_screen( $group_id = null ) {
|
141 |
if ( ! bp_is_group_admin_screen( $this->slug ) ) {
|
142 |
return false; }
|
143 |
$current_level = groups_get_groupmeta( bp_get_current_group_id(), 'rt_media_group_control_level' );
|
145 |
$current_level = 'all';
|
146 |
}
|
147 |
|
148 |
+
// HOOK to add PER GROUP MEDIA enable/diable option in rtMedia PRO.
|
149 |
+
do_action( 'rtmedia_group_media_control_edit' );
|
150 |
+
?>
|
151 |
+
|
152 |
+
<div class='rtmedia-group-media-settings'>
|
153 |
+
|
154 |
+
<?php
|
155 |
+
global $rtmedia;
|
156 |
+
$options = $rtmedia->options;
|
157 |
+
if ( isset( $options['general_enableAlbums'] ) && 1 === intval( $options['general_enableAlbums'] ) ) { // album is enabled.
|
158 |
+
?>
|
159 |
+
|
160 |
+
<h4><?php esc_html_e( 'Album Creation Control', 'buddypress-media' ); ?></h4>
|
161 |
+
<p><?php esc_html_e( 'Who can create Albums in this group?', 'buddypress-media' ); ?></p>
|
162 |
+
<div class="radio">
|
163 |
+
<label>
|
164 |
+
<input name="rt_album_creation_control" type="radio" id="rt_media_group_level_moderators" value="all"<?php checked( $current_level, 'all', true ); ?>>
|
165 |
+
<strong><?php esc_html_e( 'All Group Members', 'buddypress-media' ); ?></strong>
|
166 |
+
</label>
|
167 |
+
<label>
|
168 |
+
<input name="rt_album_creation_control" type="radio" id="rt_media_group_level_moderators" value="moderators" <?php checked( $current_level, 'moderators', true ); ?>>
|
169 |
+
<strong><?php esc_html_e( 'Group Admins and Mods only', 'buddypress-media' ); ?></strong>
|
170 |
+
</label>
|
171 |
+
<label>
|
172 |
+
<input name="rt_album_creation_control" type="radio" id="rt_media_group_level_admin" value="admin" <?php checked( $current_level, 'admin', true ); ?>>
|
173 |
+
<strong><?php esc_html_e( 'Group Admin only', 'buddypress-media' ); ?></strong>
|
174 |
+
</label>
|
175 |
+
</div>
|
176 |
+
<hr>
|
177 |
+
<?php } ?>
|
178 |
+
|
179 |
+
<?php do_action( 'rtmedia_playlist_creation_settings_groups_edit' ); ?>
|
180 |
+
</div>
|
181 |
+
<input type="submit" name="save" value="<?php esc_attr_e( 'Save Changes', 'buddypress-media' ); ?>" />
|
182 |
+
<?php
|
183 |
+
wp_nonce_field( 'groups_edit_save_' . $this->slug );
|
184 |
}
|
185 |
|
186 |
/**
|
187 |
+
* Save edited group media.
|
188 |
*
|
189 |
+
* @param null/int $group_id Group id to save.
|
190 |
*
|
191 |
* @return bool
|
192 |
*/
|
193 |
+
public function edit_screen_save( $group_id = null ) {
|
194 |
global $bp;
|
195 |
|
196 |
+
$is_save = sanitize_text_field( filter_input( INPUT_POST, 'save', FILTER_SANITIZE_STRING, FILTER_FLAG_EMPTY_STRING_NULL ) );
|
197 |
|
198 |
/**
|
199 |
+
* Updated the following condition
|
200 |
* if ( ! empty( $is_save ) ) {
|
201 |
* it was returning false even when $is_save variable was not empty
|
202 |
* remove this comment after sometime
|
210 |
* Add PLAYLIST CREATION CONTROL save functionality
|
211 |
* By: Yahil
|
212 |
*/
|
213 |
+
$rt_album_creation_control = sanitize_text_field( filter_input( INPUT_POST, 'rt_album_creation_control', FILTER_SANITIZE_STRING ) );
|
214 |
+
$rtmp_playlist_creation_control = sanitize_text_field( filter_input( INPUT_POST, 'rtmp_playlist_creation_control', FILTER_SANITIZE_STRING ) );
|
215 |
|
216 |
check_admin_referer( 'groups_edit_save_' . $this->slug );
|
217 |
|
218 |
+
if ( isset( $rt_album_creation_control ) && ! empty( $rt_album_creation_control ) ) {
|
219 |
$success = groups_update_groupmeta( bp_get_current_group_id(), 'rt_media_group_control_level', $rt_album_creation_control );
|
220 |
+
do_action( 'rtmedia_edit_save_group_media_settings', $_POST );
|
221 |
$success = true;
|
222 |
} else {
|
223 |
$success = false;
|
225 |
|
226 |
if ( isset( $rtmp_playlist_creation_control ) && ! empty( $rtmp_playlist_creation_control ) ) {
|
227 |
$success = groups_update_groupmeta( bp_get_current_group_id(), 'rtmp_create_playlist_control_level', $rtmp_playlist_creation_control );
|
228 |
+
do_action( 'rtmedia_edit_save_group_media_settings', $_POST );
|
229 |
$success = true;
|
230 |
}
|
231 |
|
232 |
+
// To post an error/success message to the screen, use the following.
|
233 |
if ( ! $success ) {
|
234 |
bp_core_add_message( esc_html__( 'There was an error saving, please try again', 'buddypress-media' ), 'error' );
|
235 |
} else {
|
243 |
* The display method for the extension
|
244 |
*
|
245 |
* @since BuddyPress Media 2.3
|
|
|
|
|
|
|
246 |
*
|
247 |
* @global type $bp_media
|
248 |
*/
|
249 |
+
public function widget_display() {
|
250 |
?>
|
251 |
<div class="info-group" >
|
252 |
+
<h4><?php echo esc_html( $this->name ); ?></h4>
|
253 |
<p>
|
254 |
<?php esc_html_e( 'You could display a small snippet of information from your group extension here. It will show on the group home screen.', 'buddypress-media' ); ?>
|
255 |
</p>
|
258 |
}
|
259 |
}
|
260 |
|
261 |
+
endif; // end class_exists 'BP_Group_Extension'.
|
app/main/controllers/media/RTMediaAlbum.php
CHANGED
@@ -1,28 +1,26 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
/*
|
4 |
-
* To change this template, choose Tools | Templates
|
5 |
-
* and open the template in the editor.
|
6 |
-
*/
|
7 |
-
|
8 |
/**
|
9 |
-
*
|
10 |
*
|
11 |
* @author Udit Desai <udit.desai@rtcamp.com>
|
|
|
|
|
|
|
|
|
|
|
12 |
*/
|
13 |
class RTMediaAlbum {
|
14 |
|
15 |
/**
|
16 |
-
*
|
17 |
-
* @var RTMediaMedia
|
18 |
-
*
|
19 |
* Media object associated with the album. It works as an interface
|
20 |
* for the actions specific the media from this album
|
|
|
|
|
21 |
*/
|
22 |
-
|
23 |
|
24 |
/**
|
25 |
-
*
|
26 |
*/
|
27 |
public function __construct() {
|
28 |
add_action( 'init', array( &$this, 'register_post_types' ), 12 );
|
@@ -30,9 +28,13 @@ class RTMediaAlbum {
|
|
30 |
$this->media = new RTMediaMedia();
|
31 |
}
|
32 |
|
33 |
-
|
|
|
|
|
|
|
34 |
$args = array(
|
35 |
'label' => _x( 'hidden', 'Status General Name', 'buddypress-media' ),
|
|
|
36 |
'label_count' => _n_noop( 'Hidden (%s)', 'Hidden (%s)', 'buddypress-media' ),
|
37 |
'public' => false,
|
38 |
'show_in_admin_all_list' => false,
|
@@ -46,9 +48,9 @@ class RTMediaAlbum {
|
|
46 |
/**
|
47 |
* Register Custom Post Types required by rtMedia
|
48 |
*/
|
49 |
-
function register_post_types() {
|
50 |
|
51 |
-
|
52 |
$album_labels = array(
|
53 |
'name' => esc_html__( 'Albums', 'buddypress-media' ),
|
54 |
'singular_name' => esc_html__( 'Album', 'buddypress-media' ),
|
@@ -74,7 +76,7 @@ class RTMediaAlbum {
|
|
74 |
'feeds' => false,
|
75 |
);
|
76 |
|
77 |
-
|
78 |
$album_args = array(
|
79 |
'labels' => $album_labels,
|
80 |
'public' => false,
|
@@ -91,7 +93,7 @@ class RTMediaAlbum {
|
|
91 |
);
|
92 |
$album_args = apply_filters( 'rtmedia_albums_args', $album_args );
|
93 |
|
94 |
-
|
95 |
register_post_type( 'rtmedia_album', $album_args );
|
96 |
}
|
97 |
|
@@ -99,18 +101,17 @@ class RTMediaAlbum {
|
|
99 |
* Method verifies the nonce passed while performing any CRUD operations
|
100 |
* on the album.
|
101 |
*
|
102 |
-
* @param
|
103 |
*
|
104 |
* @return boolean
|
105 |
*/
|
106 |
-
function verify_nonce( $mode ) {
|
107 |
|
108 |
-
$nonce = $mode
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
$mode = sanitize_text_field( wp_unslash( $_REQUEST['mode'] ) );
|
114 |
}
|
115 |
|
116 |
if ( wp_verify_nonce( $nonce, 'rtmedia_' . $mode ) ) {
|
@@ -121,40 +122,39 @@ class RTMediaAlbum {
|
|
121 |
}
|
122 |
|
123 |
/**
|
124 |
-
*
|
125 |
*
|
126 |
* @global int $current_user
|
127 |
* @return int
|
128 |
*/
|
129 |
-
function get_current_author() {
|
130 |
|
131 |
return intval( apply_filters( 'rtmedia_current_user', get_current_user_id() ) );
|
132 |
}
|
133 |
|
134 |
/**
|
135 |
-
* Adds a new album
|
136 |
-
*
|
137 |
-
* @param string $title
|
138 |
-
* @param bool|int $author_id
|
139 |
-
* @param bool|type $new
|
140 |
-
* @param bool|int $post_id
|
141 |
*
|
142 |
-
* @param
|
143 |
-
* @param bool $
|
144 |
-
*
|
145 |
-
* @
|
146 |
-
* @
|
|
|
|
|
147 |
*
|
|
|
|
|
148 |
*/
|
149 |
-
function add( $title = '', $author_id = false, $new = true, $post_id = false, $context = false, $context_id = false, $album_description = '' ) {
|
150 |
|
151 |
global $rtmedia_interaction;
|
152 |
-
|
153 |
do_action( 'rtmedia_before_add_album' );
|
154 |
|
155 |
$author_id = $author_id ? $author_id : $this->get_current_author();
|
156 |
|
157 |
-
|
158 |
$post_vars = array(
|
159 |
'post_title' => ( empty( $title ) ) ? esc_html__( 'Untitled Album', 'buddypress-media' ) : $title,
|
160 |
'post_type' => 'rtmedia_album',
|
@@ -163,24 +163,24 @@ class RTMediaAlbum {
|
|
163 |
);
|
164 |
|
165 |
if ( ! empty( $album_description ) ) {
|
166 |
-
$post_vars['post_content'] = $album_description;
|
167 |
}
|
168 |
|
169 |
-
|
|
|
170 |
* This is the case when a user creates a album of his own. We need to
|
171 |
-
* create a
|
172 |
* all the media uploaded to that album
|
173 |
-
|
174 |
-
* */
|
175 |
if ( $new ) {
|
176 |
$album_id = wp_insert_post( $post_vars );
|
177 |
-
}
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
$album_id = $post_id;
|
185 |
}
|
186 |
|
@@ -191,10 +191,10 @@ class RTMediaAlbum {
|
|
191 |
if ( false === $context_id ) {
|
192 |
$context_id = ( isset( $rtmedia_interaction->context->id ) ) ? $rtmedia_interaction->context->id : null;
|
193 |
}
|
194 |
-
// add in the media since album is also a media
|
195 |
-
//defaults
|
196 |
|
197 |
-
|
|
|
|
|
198 |
'blog_id' => get_current_blog_id(),
|
199 |
'media_id' => $album_id,
|
200 |
'album_id' => null,
|
@@ -206,14 +206,19 @@ class RTMediaAlbum {
|
|
206 |
'activity_id' => null,
|
207 |
'privacy' => null,
|
208 |
);
|
209 |
-
|
|
|
210 |
$rtmedia_id = $this->media->insert_album( $attributes );
|
211 |
$rtmedia_nav = new RTMediaNav();
|
212 |
-
$media_count = $rtmedia_nav->refresh_counts(
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
|
|
|
|
|
|
|
|
217 |
global $rtmedia_points_media_id;
|
218 |
$rtmedia_points_media_id = $rtmedia_id;
|
219 |
do_action( 'rtmedia_after_add_album', $this );
|
@@ -224,16 +229,15 @@ class RTMediaAlbum {
|
|
224 |
/**
|
225 |
* Wrapper method to add a global album
|
226 |
*
|
227 |
-
* @param string $title
|
228 |
*
|
229 |
-
* @return bool
|
230 |
*/
|
231 |
-
function add_global( $title = '' ) {
|
232 |
|
233 |
-
// $super_user_ids = get_super_admins();
|
234 |
$author_id = $this->get_current_author();
|
235 |
/**
|
236 |
-
*
|
237 |
*/
|
238 |
if ( current_user_can( 'activate_plugins' ) ) {
|
239 |
|
@@ -252,7 +256,7 @@ class RTMediaAlbum {
|
|
252 |
*
|
253 |
* @return bool/mixed/void
|
254 |
*/
|
255 |
-
static function get_globals() {
|
256 |
return rtmedia_get_site_option( 'rtmedia-global-albums' );
|
257 |
}
|
258 |
|
@@ -260,9 +264,9 @@ class RTMediaAlbum {
|
|
260 |
* There is a default global album which works as a Wall Post Album for the
|
261 |
* user.
|
262 |
*
|
263 |
-
* @return
|
264 |
*/
|
265 |
-
static function get_default() {
|
266 |
$albums = self::get_globals();
|
267 |
if ( isset( $albums[0] ) ) {
|
268 |
return intval( $albums[0] );
|
@@ -274,11 +278,11 @@ class RTMediaAlbum {
|
|
274 |
/**
|
275 |
* Save global albums for newly added album
|
276 |
*
|
277 |
-
* @param bool
|
278 |
*
|
279 |
* @return bool
|
280 |
*/
|
281 |
-
function save_globals( $album_ids = false ) {
|
282 |
|
283 |
if ( ! $album_ids ) {
|
284 |
return false;
|
@@ -296,17 +300,18 @@ class RTMediaAlbum {
|
|
296 |
|
297 |
$albums = array_merge( $albums, $album_ids );
|
298 |
rtmedia_update_site_option( 'rtmedia-global-albums', $albums );
|
|
|
299 |
}
|
300 |
|
301 |
/**
|
302 |
* Wrapper method to update details for any global album
|
303 |
*
|
304 |
-
* @param int
|
305 |
-
* @param string $title
|
306 |
*
|
307 |
* @return bool
|
308 |
*/
|
309 |
-
function update_global( $id, $title = '' ) {
|
310 |
|
311 |
/**
|
312 |
* Only admin can update global albums
|
@@ -322,28 +327,31 @@ class RTMediaAlbum {
|
|
322 |
/**
|
323 |
* Update any album. Generic method for all the user.
|
324 |
*
|
325 |
-
* @param int
|
326 |
-
* @param string $title
|
327 |
*
|
328 |
* @return bool
|
329 |
*/
|
330 |
-
function update( $id, $title = '' ) {
|
331 |
|
332 |
-
|
333 |
do_action( 'rtmedia_before_update_album', $this );
|
|
|
334 |
if ( empty( $title ) && empty( $id ) ) {
|
335 |
return false;
|
336 |
} else {
|
337 |
|
338 |
-
$args
|
339 |
'ID' => $id,
|
340 |
'post_title' => $title,
|
341 |
);
|
|
|
342 |
$status = wp_insert_post( $args );
|
|
|
343 |
if ( is_wp_error( $status ) || 0 === $status ) {
|
344 |
return false;
|
345 |
} else {
|
346 |
-
|
347 |
do_action( 'rtmedia_after_update_album', $this );
|
348 |
|
349 |
return true;
|
@@ -354,11 +362,11 @@ class RTMediaAlbum {
|
|
354 |
/**
|
355 |
* Wrapper method to delete a global album
|
356 |
*
|
357 |
-
* @param int $id
|
358 |
*
|
359 |
* @return boolean
|
360 |
*/
|
361 |
-
function delete_global( $id ) {
|
362 |
|
363 |
/**
|
364 |
* Only admin can delete a global album
|
@@ -379,7 +387,7 @@ class RTMediaAlbum {
|
|
379 |
* If a global album is deleted then all the media of that album
|
380 |
* is merged to the default global album and then the album is deleted.
|
381 |
*/
|
382 |
-
//merge with the default album
|
383 |
$this->merge( $default_album, $id );
|
384 |
|
385 |
return $this->delete( $id );
|
@@ -391,13 +399,13 @@ class RTMediaAlbum {
|
|
391 |
/**
|
392 |
* Generic method to delete any album
|
393 |
*
|
394 |
-
* @param int $id
|
395 |
*
|
396 |
* @return bool
|
397 |
*/
|
398 |
-
function delete( $id ) {
|
399 |
|
400 |
-
|
401 |
do_action( 'rtmedia_before_delete_album', $this );
|
402 |
|
403 |
/**
|
@@ -410,18 +418,22 @@ class RTMediaAlbum {
|
|
410 |
/**
|
411 |
* Delete each media from the album first
|
412 |
*/
|
413 |
-
|
|
|
414 |
|
415 |
-
|
|
|
416 |
|
417 |
-
|
418 |
|
419 |
-
|
420 |
-
|
|
|
421 |
}
|
422 |
|
423 |
-
$page
|
424 |
-
|
|
|
425 |
|
426 |
/**
|
427 |
* If all the media are deleted from the album then delete the album at last.
|
@@ -430,7 +442,7 @@ class RTMediaAlbum {
|
|
430 |
$this->media->delete( $id );
|
431 |
}
|
432 |
|
433 |
-
|
434 |
do_action( 'rtmedia_after_delete_album', $this );
|
435 |
|
436 |
return $flag;
|
@@ -439,12 +451,12 @@ class RTMediaAlbum {
|
|
439 |
/**
|
440 |
* Helper function to set number of queries in pagination
|
441 |
*
|
442 |
-
* @param int
|
443 |
-
* @param string $table_name
|
444 |
*
|
445 |
* @return int
|
446 |
*/
|
447 |
-
function set_queries_per_page( $per_page, $table_name ) {
|
448 |
|
449 |
$per_page = 1;
|
450 |
|
@@ -454,12 +466,12 @@ class RTMediaAlbum {
|
|
454 |
/**
|
455 |
* Generic function to merge two albums
|
456 |
*
|
457 |
-
* @param int $primary_album_id
|
458 |
-
* @param int $secondary_album_id
|
459 |
*
|
460 |
* @return int/bool
|
461 |
*/
|
462 |
-
function merge( $primary_album_id, $secondary_album_id ) {
|
463 |
|
464 |
add_filter( 'rt_db_model_per_page', array( $this, 'set_queries_per_page' ), 10, 2 );
|
465 |
$page = 1;
|
@@ -467,13 +479,16 @@ class RTMediaAlbum {
|
|
467 |
/**
|
468 |
* Transfer all the media from secondary album to primary album
|
469 |
*/
|
470 |
-
|
|
|
471 |
|
472 |
-
|
473 |
-
|
|
|
|
|
474 |
|
475 |
-
$page
|
476 |
-
}
|
477 |
|
478 |
$author = $this->get_current_author();
|
479 |
$admins = get_super_admins();
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
+
* Handles album operations.
|
4 |
*
|
5 |
* @author Udit Desai <udit.desai@rtcamp.com>
|
6 |
+
* @package rtMedia
|
7 |
+
*/
|
8 |
+
|
9 |
+
/**
|
10 |
+
* Class to Handle album operations.
|
11 |
*/
|
12 |
class RTMediaAlbum {
|
13 |
|
14 |
/**
|
|
|
|
|
|
|
15 |
* Media object associated with the album. It works as an interface
|
16 |
* for the actions specific the media from this album
|
17 |
+
*
|
18 |
+
* @var RTMediaMedia
|
19 |
*/
|
20 |
+
public $media;
|
21 |
|
22 |
/**
|
23 |
+
* RTMediaAlbum constructor.
|
24 |
*/
|
25 |
public function __construct() {
|
26 |
add_action( 'init', array( &$this, 'register_post_types' ), 12 );
|
28 |
$this->media = new RTMediaMedia();
|
29 |
}
|
30 |
|
31 |
+
/**
|
32 |
+
* Register custom post status for album.
|
33 |
+
*/
|
34 |
+
public function rtmedia_album_custom_post_status() {
|
35 |
$args = array(
|
36 |
'label' => _x( 'hidden', 'Status General Name', 'buddypress-media' ),
|
37 |
+
// translators: %s: Album.
|
38 |
'label_count' => _n_noop( 'Hidden (%s)', 'Hidden (%s)', 'buddypress-media' ),
|
39 |
'public' => false,
|
40 |
'show_in_admin_all_list' => false,
|
48 |
/**
|
49 |
* Register Custom Post Types required by rtMedia
|
50 |
*/
|
51 |
+
public function register_post_types() {
|
52 |
|
53 |
+
// Set up Album labels.
|
54 |
$album_labels = array(
|
55 |
'name' => esc_html__( 'Albums', 'buddypress-media' ),
|
56 |
'singular_name' => esc_html__( 'Album', 'buddypress-media' ),
|
76 |
'feeds' => false,
|
77 |
);
|
78 |
|
79 |
+
// Set up Album post type arguments.
|
80 |
$album_args = array(
|
81 |
'labels' => $album_labels,
|
82 |
'public' => false,
|
93 |
);
|
94 |
$album_args = apply_filters( 'rtmedia_albums_args', $album_args );
|
95 |
|
96 |
+
// register Album post type.
|
97 |
register_post_type( 'rtmedia_album', $album_args );
|
98 |
}
|
99 |
|
101 |
* Method verifies the nonce passed while performing any CRUD operations
|
102 |
* on the album.
|
103 |
*
|
104 |
+
* @param string $mode Album operation mode.
|
105 |
*
|
106 |
* @return boolean
|
107 |
*/
|
108 |
+
public function verify_nonce( $mode ) {
|
109 |
|
110 |
+
$nonce = sanitize_text_field( filter_input( INPUT_POST, "rtmedia_{$mode}_album_nonce", FILTER_SANITIZE_STRING ) );
|
111 |
+
$mode = sanitize_text_field( filter_input( INPUT_POST, 'mode', FILTER_SANITIZE_STRING ) );
|
112 |
+
|
113 |
+
if ( empty( $mode ) ) {
|
114 |
+
$mode = '';
|
|
|
115 |
}
|
116 |
|
117 |
if ( wp_verify_nonce( $nonce, 'rtmedia_' . $mode ) ) {
|
122 |
}
|
123 |
|
124 |
/**
|
125 |
+
* Returns user_id of the current logged in user in WordPress
|
126 |
*
|
127 |
* @global int $current_user
|
128 |
* @return int
|
129 |
*/
|
130 |
+
public function get_current_author() {
|
131 |
|
132 |
return intval( apply_filters( 'rtmedia_current_user', get_current_user_id() ) );
|
133 |
}
|
134 |
|
135 |
/**
|
136 |
+
* Adds a new album.
|
|
|
|
|
|
|
|
|
|
|
137 |
*
|
138 |
+
* @param string $title Album title.
|
139 |
+
* @param bool|int $author_id Author id.
|
140 |
+
* @param bool $new Weather new or not.
|
141 |
+
* @param bool|int $post_id Post id.
|
142 |
+
* @param bool $context Album context.
|
143 |
+
* @param bool $context_id Context id.
|
144 |
+
* @param string $album_description Album description.
|
145 |
*
|
146 |
+
* @return int
|
147 |
+
* @global type $rtmedia_interaction
|
148 |
*/
|
149 |
+
public function add( $title = '', $author_id = false, $new = true, $post_id = false, $context = false, $context_id = false, $album_description = '' ) {
|
150 |
|
151 |
global $rtmedia_interaction;
|
152 |
+
// action to perform any task before adding the album.
|
153 |
do_action( 'rtmedia_before_add_album' );
|
154 |
|
155 |
$author_id = $author_id ? $author_id : $this->get_current_author();
|
156 |
|
157 |
+
// Album Details which will be passed to Database query to add the album.
|
158 |
$post_vars = array(
|
159 |
'post_title' => ( empty( $title ) ) ? esc_html__( 'Untitled Album', 'buddypress-media' ) : $title,
|
160 |
'post_type' => 'rtmedia_album',
|
163 |
);
|
164 |
|
165 |
if ( ! empty( $album_description ) ) {
|
166 |
+
$post_vars['post_content'] = $album_description;
|
167 |
}
|
168 |
|
169 |
+
/**
|
170 |
+
* Check whether to create a new album in wp_post table
|
171 |
* This is the case when a user creates a album of his own. We need to
|
172 |
+
* create a separate post in wp_post which will work as parent for
|
173 |
* all the media uploaded to that album
|
174 |
+
*/
|
|
|
175 |
if ( $new ) {
|
176 |
$album_id = wp_insert_post( $post_vars );
|
177 |
+
} else {
|
178 |
+
/**
|
179 |
+
* If user uploads any media directly to a post or a page or any custom
|
180 |
+
* post then the context in which the user is uploading a media becomes
|
181 |
+
* an album in itself. We do not need to create a separate album in this
|
182 |
+
* case.
|
183 |
+
*/
|
184 |
$album_id = $post_id;
|
185 |
}
|
186 |
|
191 |
if ( false === $context_id ) {
|
192 |
$context_id = ( isset( $rtmedia_interaction->context->id ) ) ? $rtmedia_interaction->context->id : null;
|
193 |
}
|
|
|
|
|
194 |
|
195 |
+
// add in the media since album is also a media.
|
196 |
+
// defaults.
|
197 |
+
$attributes = array(
|
198 |
'blog_id' => get_current_blog_id(),
|
199 |
'media_id' => $album_id,
|
200 |
'album_id' => null,
|
206 |
'activity_id' => null,
|
207 |
'privacy' => null,
|
208 |
);
|
209 |
+
|
210 |
+
$attributes = apply_filters( 'rtmedia_before_save_album_attributes', $attributes, $_POST ); // phpcs:ignore WordPress.Security.NonceVerification.NoNonceVerification
|
211 |
$rtmedia_id = $this->media->insert_album( $attributes );
|
212 |
$rtmedia_nav = new RTMediaNav();
|
213 |
+
$media_count = $rtmedia_nav->refresh_counts(
|
214 |
+
$context_id,
|
215 |
+
array(
|
216 |
+
'context' => $context,
|
217 |
+
'media_author' => $context_id,
|
218 |
+
)
|
219 |
+
);
|
220 |
+
|
221 |
+
// action to perform any task after adding the album.
|
222 |
global $rtmedia_points_media_id;
|
223 |
$rtmedia_points_media_id = $rtmedia_id;
|
224 |
do_action( 'rtmedia_after_add_album', $this );
|
229 |
/**
|
230 |
* Wrapper method to add a global album
|
231 |
*
|
232 |
+
* @param string $title Album title.
|
233 |
*
|
234 |
+
* @return bool|int
|
235 |
*/
|
236 |
+
public function add_global( $title = '' ) {
|
237 |
|
|
|
238 |
$author_id = $this->get_current_author();
|
239 |
/**
|
240 |
+
* Only admin privileged user can add a global album
|
241 |
*/
|
242 |
if ( current_user_can( 'activate_plugins' ) ) {
|
243 |
|
256 |
*
|
257 |
* @return bool/mixed/void
|
258 |
*/
|
259 |
+
public static function get_globals() {
|
260 |
return rtmedia_get_site_option( 'rtmedia-global-albums' );
|
261 |
}
|
262 |
|
264 |
* There is a default global album which works as a Wall Post Album for the
|
265 |
* user.
|
266 |
*
|
267 |
+
* @return int|bool
|
268 |
*/
|
269 |
+
public static function get_default() {
|
270 |
$albums = self::get_globals();
|
271 |
if ( isset( $albums[0] ) ) {
|
272 |
return intval( $albums[0] );
|
278 |
/**
|
279 |
* Save global albums for newly added album
|
280 |
*
|
281 |
+
* @param bool|int $album_ids Album ids to save as globals.
|
282 |
*
|
283 |
* @return bool
|
284 |
*/
|
285 |
+
public function save_globals( $album_ids = false ) {
|
286 |
|
287 |
if ( ! $album_ids ) {
|
288 |
return false;
|
300 |
|
301 |
$albums = array_merge( $albums, $album_ids );
|
302 |
rtmedia_update_site_option( 'rtmedia-global-albums', $albums );
|
303 |
+
|
304 |
}
|
305 |
|
306 |
/**
|
307 |
* Wrapper method to update details for any global album
|
308 |
*
|
309 |
+
* @param int $id Album id.
|
310 |
+
* @param string $title Album title.
|
311 |
*
|
312 |
* @return bool
|
313 |
*/
|
314 |
+
public function update_global( $id, $title = '' ) {
|
315 |
|
316 |
/**
|
317 |
* Only admin can update global albums
|
327 |
/**
|
328 |
* Update any album. Generic method for all the user.
|
329 |
*
|
330 |
+
* @param int $id Album id.
|
331 |
+
* @param string $title Album title.
|
332 |
*
|
333 |
* @return bool
|
334 |
*/
|
335 |
+
public function update( $id, $title = '' ) {
|
336 |
|
337 |
+
// Action to perform before updating the album.
|
338 |
do_action( 'rtmedia_before_update_album', $this );
|
339 |
+
|
340 |
if ( empty( $title ) && empty( $id ) ) {
|
341 |
return false;
|
342 |
} else {
|
343 |
|
344 |
+
$args = array(
|
345 |
'ID' => $id,
|
346 |
'post_title' => $title,
|
347 |
);
|
348 |
+
|
349 |
$status = wp_insert_post( $args );
|
350 |
+
|
351 |
if ( is_wp_error( $status ) || 0 === $status ) {
|
352 |
return false;
|
353 |
} else {
|
354 |
+
// Action to perform after updating the album.
|
355 |
do_action( 'rtmedia_after_update_album', $this );
|
356 |
|
357 |
return true;
|
362 |
/**
|
363 |
* Wrapper method to delete a global album
|
364 |
*
|
365 |
+
* @param int $id Album id.
|
366 |
*
|
367 |
* @return boolean
|
368 |
*/
|
369 |
+
public function delete_global( $id ) {
|
370 |
|
371 |
/**
|
372 |
* Only admin can delete a global album
|
387 |
* If a global album is deleted then all the media of that album
|
388 |
* is merged to the default global album and then the album is deleted.
|
389 |
*/
|
390 |
+
// merge with the default album.
|
391 |
$this->merge( $default_album, $id );
|
392 |
|
393 |
return $this->delete( $id );
|
399 |
/**
|
400 |
* Generic method to delete any album
|
401 |
*
|
402 |
+
* @param int $id Media album id.
|
403 |
*
|
404 |
* @return bool
|
405 |
*/
|
406 |
+
public function delete( $id ) {
|
407 |
|
408 |
+
// action to perform any task before deleting an album.
|
409 |
do_action( 'rtmedia_before_delete_album', $this );
|
410 |
|
411 |
/**
|
418 |
/**
|
419 |
* Delete each media from the album first
|
420 |
*/
|
421 |
+
do {
|
422 |
+
$media = $this->media->model->get_by_album_id( $id, $page );
|
423 |
|
424 |
+
if ( ! empty( $media['result'] ) ) {
|
425 |
+
$media_id = $media['result'][0]['media_id'];
|
426 |
|
427 |
+
$flag = wp_delete_attachment( $media_id );
|
428 |
|
429 |
+
if ( ! $flag ) {
|
430 |
+
break;
|
431 |
+
}
|
432 |
}
|
433 |
|
434 |
+
$page++;
|
435 |
+
|
436 |
+
} while ( ! empty( $media ) );
|
437 |
|
438 |
/**
|
439 |
* If all the media are deleted from the album then delete the album at last.
|
442 |
$this->media->delete( $id );
|
443 |
}
|
444 |
|
445 |
+
// action to perform any task after deleting an album.
|
446 |
do_action( 'rtmedia_after_delete_album', $this );
|
447 |
|
448 |
return $flag;
|
451 |
/**
|
452 |
* Helper function to set number of queries in pagination
|
453 |
*
|
454 |
+
* @param int $per_page Per page result.
|
455 |
+
* @param string $table_name Table name for query.
|
456 |
*
|
457 |
* @return int
|
458 |
*/
|
459 |
+
public function set_queries_per_page( $per_page, $table_name ) {
|
460 |
|
461 |
$per_page = 1;
|
462 |
|
466 |
/**
|
467 |
* Generic function to merge two albums
|
468 |
*
|
469 |
+
* @param int $primary_album_id Primary album id.
|
470 |
+
* @param int $secondary_album_id Secondary album id.
|
471 |
*
|
472 |
* @return int/bool
|
473 |
*/
|
474 |
+
public function merge( $primary_album_id, $secondary_album_id ) {
|
475 |
|
476 |
add_filter( 'rt_db_model_per_page', array( $this, 'set_queries_per_page' ), 10, 2 );
|
477 |
$page = 1;
|
479 |
/**
|
480 |
* Transfer all the media from secondary album to primary album
|
481 |
*/
|
482 |
+
do {
|
483 |
+
$media = $this->media->model->get_by_album_id( $secondary_album_id, $page );
|
484 |
|
485 |
+
if ( ! empty( $media['result'] ) ) {
|
486 |
+
$media_id = $media['result'][0]['media_id'];
|
487 |
+
$this->media->move( $media_id, $primary_album_id );
|
488 |
+
}
|
489 |
|
490 |
+
$page++;
|
491 |
+
} while ( ! empty( $media ) );
|
492 |
|
493 |
$author = $this->get_current_author();
|
494 |
$admins = get_super_admins();
|
app/main/controllers/media/RTMediaComment.php
CHANGED
@@ -1,30 +1,45 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
/*
|
4 |
-
* To change this template, choose Tools | Templates
|
5 |
-
* and open the template in the editor.
|
6 |
-
*/
|
7 |
-
|
8 |
/**
|
9 |
-
*
|
10 |
*
|
|
|
11 |
* @author udit
|
12 |
*/
|
|
|
|
|
|
|
|
|
13 |
class RTMediaComment {
|
14 |
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
16 |
|
|
|
|
|
|
|
17 |
public function __construct() {
|
18 |
$this->rtmedia_comment_model = new RTMediaCommentModel();
|
19 |
}
|
20 |
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
if ( $echo ) {
|
23 |
-
wp_nonce_field( 'rtmedia_comment_nonce','rtmedia_comment_nonce' );
|
24 |
} else {
|
25 |
$token = array(
|
26 |
'action' => 'rtmedia_comment_nonce',
|
27 |
-
'nonce'
|
28 |
);
|
29 |
|
30 |
return wp_json_encode( $token );
|
@@ -32,12 +47,12 @@ class RTMediaComment {
|
|
32 |
}
|
33 |
|
34 |
/**
|
35 |
-
*
|
36 |
*
|
37 |
* @global WP_User $current_user
|
38 |
* @return int
|
39 |
*/
|
40 |
-
function get_current_id() {
|
41 |
|
42 |
global $current_user;
|
43 |
|
@@ -46,12 +61,12 @@ class RTMediaComment {
|
|
46 |
}
|
47 |
|
48 |
/**
|
49 |
-
*
|
50 |
*
|
51 |
* @global WP_User $current_user
|
52 |
* @return string
|
53 |
*/
|
54 |
-
function get_current_author() {
|
55 |
|
56 |
global $current_user;
|
57 |
|
@@ -59,39 +74,51 @@ class RTMediaComment {
|
|
59 |
|
60 |
}
|
61 |
|
62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
global $allowedtags;
|
64 |
do_action( 'rtmedia_before_add_comment', $attr );
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
|
|
69 |
);
|
70 |
$attr['comment_content'] = rtmedia_wp_kses_of_buddypress( $attr['comment_content'], $allowedtags );
|
71 |
-
$params
|
72 |
-
$id
|
|
|
73 |
global $rtmedia_points_media_id;
|
74 |
$rtmedia_points_media_id = rtmedia_id( $params['comment_post_ID'] );
|
75 |
-
$params['comment_id']
|
76 |
|
77 |
-
|
78 |
-
if ( isset( $_REQUEST['rtMedia_attached_files'] ) ) {
|
79 |
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
if ( is_array( $rtMedia_attached_files ) && ! empty( $rtMedia_attached_files ) ) {
|
84 |
-
add_rtmedia_meta( $rtMedia_attached_files[0], 'rtmedia_comment_media_comment_id', $id );
|
85 |
-
}
|
86 |
}
|
87 |
|
88 |
-
|
89 |
do_action( 'rtmedia_after_add_comment', $params );
|
90 |
|
91 |
return $id;
|
92 |
}
|
93 |
|
94 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
|
96 |
do_action( 'rtmedia_before_remove_comment', $id );
|
97 |
|
@@ -100,14 +127,14 @@ class RTMediaComment {
|
|
100 |
$comment = get_comment( $id );
|
101 |
}
|
102 |
|
103 |
-
|
104 |
if ( isset( $comment->comment_post_ID ) && isset( $comment->user_id ) ) {
|
105 |
|
106 |
$model = new RTMediaModel();
|
107 |
|
108 |
-
//get the current media from the comment_post_ID
|
109 |
-
$media
|
110 |
-
|
|
|
111 |
if ( isset( $media[0]->media_author ) && ( is_rt_admin() || intval( $comment->user_id ) === get_current_user_id() || intval( $media[0]->media_author ) === get_current_user_id() ) ) {
|
112 |
$comment_deleted = $this->rtmedia_comment_model->delete( $id );
|
113 |
do_action( 'rtmedia_after_remove_comment', $id );
|
@@ -118,13 +145,12 @@ class RTMediaComment {
|
|
118 |
return false;
|
119 |
}
|
120 |
|
121 |
-
|
122 |
/**
|
123 |
* Helper function to check whether the shortcode should be rendered or not
|
124 |
*
|
125 |
* @return bool
|
126 |
*/
|
127 |
-
static function display_allowed() {
|
128 |
global $rtmedia_query;
|
129 |
$media_enabled = ( is_rtmedia_upload_music_enabled() || is_rtmedia_upload_photo_enabled()
|
130 |
|| is_rtmedia_upload_video_enabled() || is_rtmedia_upload_document_enabled()
|
@@ -140,15 +166,14 @@ class RTMediaComment {
|
|
140 |
return $flag;
|
141 |
}
|
142 |
|
143 |
-
|
144 |
/**
|
145 |
* Render the uploader shortcode and attach the uploader panel
|
146 |
*
|
147 |
-
* @param mixed $attr
|
148 |
*
|
149 |
* @return string|void
|
150 |
*/
|
151 |
-
static function pre_comment_render( $attr ) {
|
152 |
ob_start();
|
153 |
if ( rtmedia_is_uploader_view_allowed( true, 'comment_media' ) ) {
|
154 |
|
@@ -159,56 +184,68 @@ class RTMediaComment {
|
|
159 |
$attr = apply_filters( 'rtmedia_media_comment_attributes', $attr );
|
160 |
|
161 |
if ( self::display_allowed() ) {
|
|
|
162 |
if ( ! _device_can_upload() ) {
|
163 |
echo '<p>' . esc_html_e( 'The web browser on your device cannot be used to upload files.', 'buddypress-media' ) . '</p>';
|
164 |
return;
|
165 |
}
|
|
|
166 |
$template = 'uploader';
|
167 |
-
|
|
|
168 |
$template = 'comment-media';
|
169 |
}
|
|
|
170 |
$view = new RTMediaUploadView( $attr );
|
171 |
-
echo $view->render( $template );
|
172 |
|
173 |
}
|
174 |
} else {
|
175 |
-
echo "<div class='rtmedia-upload-not-allowed'>" . wp_kses( apply_filters( 'rtmedia_upload_not_allowed_message', esc_html__( 'You are not allowed to upload/attach media.','buddypress-media' ), 'uploader_shortcode' ), RTMediaUpload::$wp_kses_allowed_tags ) . '</div>';
|
176 |
}
|
|
|
177 |
$output = ob_get_contents();
|
178 |
ob_end_clean();
|
179 |
return $output;
|
180 |
}
|
181 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
182 |
|
183 |
-
|
184 |
-
* update the Comment Media album when Parent Media Album is change
|
185 |
-
* @param int $media_id ( media id )
|
186 |
-
*/
|
187 |
-
function update_comment_media_album( $post_id = false ) {
|
188 |
-
/* get album id */
|
189 |
-
$album_id = filter_input( INPUT_POST, 'album_id', FILTER_SANITIZE_NUMBER_INT );
|
190 |
-
/* RTMediaModel class exites and post_id is not NULL and album id is not NULL */
|
191 |
if ( class_exists( 'RTMediaModel' ) && ! empty( $post_id ) && isset( $album_id ) && ! empty( $album_id ) ) {
|
192 |
-
|
193 |
$comments = $this->rtmedia_comment_model->get( array( 'post_id' => $post_id ) );
|
194 |
-
|
|
|
195 |
if ( isset( $comments ) && is_array( $comments ) && ! empty( $comments ) ) {
|
196 |
-
|
197 |
-
|
|
|
|
|
198 |
foreach ( $comments as $comment ) {
|
199 |
-
|
|
|
200 |
if ( isset( $comment->comment_ID ) ) {
|
201 |
-
|
|
|
202 |
$comment_media_id = get_comment_meta( $comment->comment_ID, 'rtmedia_comment_media_id', true );
|
203 |
-
|
|
|
204 |
if ( isset( $comment_media_id ) && ! empty( $comment_media_id ) ) {
|
205 |
-
|
206 |
-
$where
|
207 |
|
208 |
-
|
209 |
$columns = array( 'album_id' => $album_id );
|
210 |
|
211 |
-
// update media privacy
|
212 |
$media_model->update( $columns, $where );
|
213 |
}
|
214 |
}
|
@@ -217,22 +254,23 @@ class RTMediaComment {
|
|
217 |
}
|
218 |
}
|
219 |
|
220 |
-
|
221 |
-
|
222 |
-
*
|
223 |
-
* @param int
|
224 |
-
* @param string $type
|
|
|
225 |
*
|
226 |
-
* @return
|
227 |
-
|
228 |
-
static function add_uplaod_media_button( $id, $type, $context ) {
|
229 |
$attr = array(
|
230 |
-
'comment'
|
231 |
-
'privacy'
|
232 |
-
'upload_parent_id'
|
233 |
-
'upload_parent_id_type'
|
234 |
'upload_parent_id_context' => $context,
|
235 |
-
|
236 |
-
return
|
237 |
}
|
238 |
}
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
+
* Handles operations on media comments.
|
4 |
*
|
5 |
+
* @package rtMedia
|
6 |
* @author udit
|
7 |
*/
|
8 |
+
|
9 |
+
/**
|
10 |
+
* Class to handle operations on media comments.
|
11 |
+
*/
|
12 |
class RTMediaComment {
|
13 |
|
14 |
+
/**
|
15 |
+
* Comment model object.
|
16 |
+
*
|
17 |
+
* @var RTMediaCommentModel
|
18 |
+
*/
|
19 |
+
public $rtmedia_comment_model;
|
20 |
|
21 |
+
/**
|
22 |
+
* RTMediaComment constructor.
|
23 |
+
*/
|
24 |
public function __construct() {
|
25 |
$this->rtmedia_comment_model = new RTMediaCommentModel();
|
26 |
}
|
27 |
|
28 |
+
/**
|
29 |
+
* Create nonce for comment form.
|
30 |
+
*
|
31 |
+
* @param bool $echo Echo or not.
|
32 |
+
*
|
33 |
+
* @return false|string
|
34 |
+
*/
|
35 |
+
public static function comment_nonce_generator( $echo = true ) {
|
36 |
+
|
37 |
if ( $echo ) {
|
38 |
+
wp_nonce_field( 'rtmedia_comment_nonce', 'rtmedia_comment_nonce' );
|
39 |
} else {
|
40 |
$token = array(
|
41 |
'action' => 'rtmedia_comment_nonce',
|
42 |
+
'nonce' => wp_create_nonce( 'rtmedia_comment_nonce' ),
|
43 |
);
|
44 |
|
45 |
return wp_json_encode( $token );
|
47 |
}
|
48 |
|
49 |
/**
|
50 |
+
* Returns user_id of the current logged in user in WordPress
|
51 |
*
|
52 |
* @global WP_User $current_user
|
53 |
* @return int
|
54 |
*/
|
55 |
+
public function get_current_id() {
|
56 |
|
57 |
global $current_user;
|
58 |
|
61 |
}
|
62 |
|
63 |
/**
|
64 |
+
* Returns user_id of the current logged in user in WordPress
|
65 |
*
|
66 |
* @global WP_User $current_user
|
67 |
* @return string
|
68 |
*/
|
69 |
+
public function get_current_author() {
|
70 |
|
71 |
global $current_user;
|
72 |
|
74 |
|
75 |
}
|
76 |
|
77 |
+
/**
|
78 |
+
* Add comment.
|
79 |
+
*
|
80 |
+
* @param array $attr Comment arguments array.
|
81 |
+
*
|
82 |
+
* @return false|int
|
83 |
+
*/
|
84 |
+
public function add( $attr ) {
|
85 |
+
|
86 |
global $allowedtags;
|
87 |
do_action( 'rtmedia_before_add_comment', $attr );
|
88 |
+
|
89 |
+
$defaults = array(
|
90 |
+
'user_id' => $this->get_current_id(),
|
91 |
+
'comment_author' => $this->get_current_author(),
|
92 |
+
'comment_date' => current_time( 'mysql' ),
|
93 |
);
|
94 |
$attr['comment_content'] = rtmedia_wp_kses_of_buddypress( $attr['comment_content'], $allowedtags );
|
95 |
+
$params = wp_parse_args( $attr, $defaults );
|
96 |
+
$id = $this->rtmedia_comment_model->insert( $params );
|
97 |
+
|
98 |
global $rtmedia_points_media_id;
|
99 |
$rtmedia_points_media_id = rtmedia_id( $params['comment_post_ID'] );
|
100 |
+
$params['comment_id'] = $id;
|
101 |
|
102 |
+
$rtmedia_attached_files = filter_input( INPUT_POST, 'rtMedia_attached_files', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY );
|
|
|
103 |
|
104 |
+
// add comment id in the rtmedia meta fields.
|
105 |
+
if ( ! empty( $rtmedia_attached_files ) && is_array( $rtmedia_attached_files ) ) {
|
106 |
+
add_rtmedia_meta( $rtmedia_attached_files[0], 'rtmedia_comment_media_comment_id', $id );
|
|
|
|
|
|
|
107 |
}
|
108 |
|
|
|
109 |
do_action( 'rtmedia_after_add_comment', $params );
|
110 |
|
111 |
return $id;
|
112 |
}
|
113 |
|
114 |
+
/**
|
115 |
+
* Remove id.
|
116 |
+
*
|
117 |
+
* @param int $id Comment id.
|
118 |
+
*
|
119 |
+
* @return bool
|
120 |
+
*/
|
121 |
+
public function remove( $id ) {
|
122 |
|
123 |
do_action( 'rtmedia_before_remove_comment', $id );
|
124 |
|
127 |
$comment = get_comment( $id );
|
128 |
}
|
129 |
|
|
|
130 |
if ( isset( $comment->comment_post_ID ) && isset( $comment->user_id ) ) {
|
131 |
|
132 |
$model = new RTMediaModel();
|
133 |
|
134 |
+
// get the current media from the comment_post_ID.
|
135 |
+
$media = $model->get( array( 'media_id' => $comment->comment_post_ID ) );
|
136 |
+
|
137 |
+
// if user is comment creator, or media uploader or admin, allow to delete.
|
138 |
if ( isset( $media[0]->media_author ) && ( is_rt_admin() || intval( $comment->user_id ) === get_current_user_id() || intval( $media[0]->media_author ) === get_current_user_id() ) ) {
|
139 |
$comment_deleted = $this->rtmedia_comment_model->delete( $id );
|
140 |
do_action( 'rtmedia_after_remove_comment', $id );
|
145 |
return false;
|
146 |
}
|
147 |
|
|
|
148 |
/**
|
149 |
* Helper function to check whether the shortcode should be rendered or not
|
150 |
*
|
151 |
* @return bool
|
152 |
*/
|
153 |
+
public static function display_allowed() {
|
154 |
global $rtmedia_query;
|
155 |
$media_enabled = ( is_rtmedia_upload_music_enabled() || is_rtmedia_upload_photo_enabled()
|
156 |
|| is_rtmedia_upload_video_enabled() || is_rtmedia_upload_document_enabled()
|
166 |
return $flag;
|
167 |
}
|
168 |
|
|
|
169 |
/**
|
170 |
* Render the uploader shortcode and attach the uploader panel
|
171 |
*
|
172 |
+
* @param mixed $attr Attributes array.
|
173 |
*
|
174 |
* @return string|void
|
175 |
*/
|
176 |
+
public static function pre_comment_render( $attr ) {
|
177 |
ob_start();
|
178 |
if ( rtmedia_is_uploader_view_allowed( true, 'comment_media' ) ) {
|
179 |
|
184 |
$attr = apply_filters( 'rtmedia_media_comment_attributes', $attr );
|
185 |
|
186 |
if ( self::display_allowed() ) {
|
187 |
+
|
188 |
if ( ! _device_can_upload() ) {
|
189 |
echo '<p>' . esc_html_e( 'The web browser on your device cannot be used to upload files.', 'buddypress-media' ) . '</p>';
|
190 |
return;
|
191 |
}
|
192 |
+
|
193 |
$template = 'uploader';
|
194 |
+
|
195 |
+
if ( isset( $attr['upload_parent_id_type'] ) && isset( $attr['upload_parent_id'] ) ) {
|
196 |
$template = 'comment-media';
|
197 |
}
|
198 |
+
|
199 |
$view = new RTMediaUploadView( $attr );
|
200 |
+
echo wp_kses( $view->render( $template ), RTMedia::expanded_allowed_tags() );
|
201 |
|
202 |
}
|
203 |
} else {
|
204 |
+
echo "<div class='rtmedia-upload-not-allowed'>" . wp_kses( apply_filters( 'rtmedia_upload_not_allowed_message', esc_html__( 'You are not allowed to upload/attach media.', 'buddypress-media' ), 'uploader_shortcode' ), RTMediaUpload::$wp_kses_allowed_tags ) . '</div>';
|
205 |
}
|
206 |
+
|
207 |
$output = ob_get_contents();
|
208 |
ob_end_clean();
|
209 |
return $output;
|
210 |
}
|
211 |
|
212 |
+
/**
|
213 |
+
* Update the Comment Media album when Parent Media Album is change
|
214 |
+
*
|
215 |
+
* @param int|false $post_id media id.
|
216 |
+
*/
|
217 |
+
public function update_comment_media_album( $post_id = false ) {
|
218 |
+
// get album id.
|
219 |
+
$album_id = filter_input( INPUT_POST, 'album_id', FILTER_SANITIZE_NUMBER_INT );
|
220 |
|
221 |
+
// RTMediaModel class exists and post_id is not NULL and album id is not NULL.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
222 |
if ( class_exists( 'RTMediaModel' ) && ! empty( $post_id ) && isset( $album_id ) && ! empty( $album_id ) ) {
|
223 |
+
// get the comments from the post id.
|
224 |
$comments = $this->rtmedia_comment_model->get( array( 'post_id' => $post_id ) );
|
225 |
+
|
226 |
+
// check if comment exists or not.
|
227 |
if ( isset( $comments ) && is_array( $comments ) && ! empty( $comments ) ) {
|
228 |
+
|
229 |
+
$media_model = new RTMediaModel();
|
230 |
+
|
231 |
+
// comment loop.
|
232 |
foreach ( $comments as $comment ) {
|
233 |
+
|
234 |
+
// check for comment id.
|
235 |
if ( isset( $comment->comment_ID ) ) {
|
236 |
+
|
237 |
+
// get the media id from the comment.
|
238 |
$comment_media_id = get_comment_meta( $comment->comment_ID, 'rtmedia_comment_media_id', true );
|
239 |
+
|
240 |
+
// check if comment has media or not.
|
241 |
if ( isset( $comment_media_id ) && ! empty( $comment_media_id ) ) {
|
242 |
+
// media id.
|
243 |
+
$where = array( 'id' => $comment_media_id );
|
244 |
|
245 |
+
// album id.
|
246 |
$columns = array( 'album_id' => $album_id );
|
247 |
|
248 |
+
// update media privacy.
|
249 |
$media_model->update( $columns, $where );
|
250 |
}
|
251 |
}
|
254 |
}
|
255 |
}
|
256 |
|
257 |
+
/**
|
258 |
+
* Add media upload in add comment section
|
259 |
+
*
|
260 |
+
* @param int $id media id or activity id.
|
261 |
+
* @param string $type media or activity.
|
262 |
+
* @param string $context Media context.
|
263 |
*
|
264 |
+
* @return string
|
265 |
+
*/
|
266 |
+
public static function add_uplaod_media_button( $id, $type, $context ) {
|
267 |
$attr = array(
|
268 |
+
'comment' => true,
|
269 |
+
'privacy' => 0,
|
270 |
+
'upload_parent_id' => $id,
|
271 |
+
'upload_parent_id_type' => $type,
|
272 |
'upload_parent_id_context' => $context,
|
273 |
+
);
|
274 |
+
return self::pre_comment_render( $attr );
|
275 |
}
|
276 |
}
|
app/main/controllers/media/RTMediaFeatured.php
CHANGED
@@ -1,25 +1,45 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
|
4 |
-
*
|
5 |
-
*
|
6 |
*/
|
7 |
|
8 |
/**
|
9 |
-
*
|
10 |
*
|
11 |
* @author saurabh
|
12 |
*/
|
13 |
class RTMediaFeatured extends RTMediaUserInteraction {
|
14 |
|
15 |
/**
|
|
|
16 |
*
|
|
|
17 |
*/
|
18 |
public $user_id;
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
public $featured;
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
public $settings;
|
21 |
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
$args = array(
|
24 |
'action' => 'featured',
|
25 |
'label' => esc_html__( 'Set as Featured', 'buddypress-media' ),
|
@@ -36,6 +56,7 @@ class RTMediaFeatured extends RTMediaUserInteraction {
|
|
36 |
$this->user_id = $user_id;
|
37 |
parent::__construct( $args );
|
38 |
$this->settings();
|
|
|
39 |
remove_filter( 'rtmedia_action_buttons_before_delete', array( $this, 'button_filter' ) );
|
40 |
if ( $flag ) {
|
41 |
add_filter( 'rtmedia_addons_action_buttons', array( $this, 'button_filter' ) );
|
@@ -44,17 +65,29 @@ class RTMediaFeatured extends RTMediaUserInteraction {
|
|
44 |
add_action( 'rtmedia_featured_button_filter', array( $this, 'featured_button_filter_nonce' ), 10, 1 );
|
45 |
}
|
46 |
|
47 |
-
|
|
|
|
|
|
|
|
|
|
|
48 |
$this->get();
|
|
|
49 |
if ( ( ! ( isset( $this->settings[ $this->media->media_type ] ) && $this->settings[ $this->media->media_type ] ) ) || ( isset( $this->media->context ) && ( 'profile' !== $this->media->context ) ) ) {
|
50 |
return false;
|
51 |
}
|
|
|
52 |
if ( isset( $this->action_query ) && isset( $this->action_query->id ) && intval( $this->action_query->id ) === intval( $this->featured ) ) {
|
53 |
$this->label = $this->undo_label;
|
54 |
}
|
55 |
}
|
56 |
|
57 |
-
|
|
|
|
|
|
|
|
|
|
|
58 |
if ( false === $media_id ) {
|
59 |
return;
|
60 |
}
|
@@ -62,11 +95,16 @@ class RTMediaFeatured extends RTMediaUserInteraction {
|
|
62 |
$this->user_id = get_current_user_id();
|
63 |
}
|
64 |
|
65 |
-
//todo user attribute
|
66 |
update_user_meta( $this->user_id, 'rtmedia_featured_media', $media_id );
|
67 |
}
|
68 |
|
69 |
-
|
|
|
|
|
|
|
|
|
|
|
70 |
if ( false === $this->user_id ) {
|
71 |
if ( function_exists( 'bp_displayed_user_id' ) ) {
|
72 |
$this->user_id = bp_displayed_user_id();
|
@@ -75,8 +113,9 @@ class RTMediaFeatured extends RTMediaUserInteraction {
|
|
75 |
$this->user_id = get_current_user_id();
|
76 |
}
|
77 |
}
|
78 |
-
//todo user attribute
|
79 |
$this->featured = get_user_meta( $this->user_id, 'rtmedia_featured_media', true );
|
|
|
80 |
if ( empty( $this->featured ) ) {
|
81 |
$this->featured = get_user_meta( $this->user_id, 'bp_media_featured_media', true );
|
82 |
}
|
@@ -84,8 +123,12 @@ class RTMediaFeatured extends RTMediaUserInteraction {
|
|
84 |
return $this->featured;
|
85 |
}
|
86 |
|
87 |
-
|
|
|
|
|
|
|
88 |
global $rtmedia;
|
|
|
89 |
$this->settings['photo'] = isset( $rtmedia->options['allowedTypes_photo_featured'] ) ? $rtmedia->options['allowedTypes_photo_featured'] : 0;
|
90 |
$this->settings['video'] = isset( $rtmedia->options['allowedTypes_video_featured'] ) ? $rtmedia->options['allowedTypes_video_featured'] : 0;
|
91 |
$this->settings['music'] = isset( $rtmedia->options['allowedTypes_music_featured'] ) ? $rtmedia->options['allowedTypes_music_featured'] : 0;
|
@@ -94,7 +137,14 @@ class RTMediaFeatured extends RTMediaUserInteraction {
|
|
94 |
$this->settings['crop'] = isset( $rtmedia->options['defaultSizes_featured_default_crop'] ) ? $rtmedia->options['defaultSizes_featured_default_crop'] : 1;
|
95 |
}
|
96 |
|
97 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
if ( isset( $this->settings[ $type ] ) && $this->settings[ $type ] > 0 ) {
|
99 |
return true;
|
100 |
}
|
@@ -102,22 +152,33 @@ class RTMediaFeatured extends RTMediaUserInteraction {
|
|
102 |
return false;
|
103 |
}
|
104 |
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
|
|
110 |
$metadata = wp_get_attachment_metadata( $media_id );
|
111 |
$resized = image_make_intermediate_size( get_attached_file( $media_id ), $this->settings['width'], $this->settings['height'], $this->settings['crop'] );
|
|
|
112 |
if ( $resized ) {
|
113 |
$metadata['sizes']['rt_media_featured_image'] = $resized;
|
114 |
wp_update_attachment_metadata( $media_id, $metadata );
|
115 |
}
|
116 |
}
|
117 |
|
118 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
global $wpdb;
|
|
|
120 |
$post_exists = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->posts} WHERE id = %d", $id ), 'ARRAY_A' );
|
|
|
121 |
if ( $post_exists ) {
|
122 |
return true;
|
123 |
} else {
|
@@ -125,55 +186,69 @@ class RTMediaFeatured extends RTMediaUserInteraction {
|
|
125 |
}
|
126 |
}
|
127 |
|
128 |
-
|
|
|
|
|
|
|
|
|
|
|
129 |
$this->get();
|
130 |
$actions = $this->model->get( array( 'id' => $this->featured ) );
|
131 |
if ( ! $actions ) {
|
132 |
return false;
|
133 |
}
|
134 |
|
135 |
-
$featured
|
136 |
-
$type
|
|
|
137 |
|
138 |
-
$content_xtra = '';
|
139 |
switch ( $type ) {
|
140 |
-
case 'video'
|
141 |
$this->generate_featured_size( $this->featured );
|
142 |
if ( $featured->media_id ) {
|
143 |
-
$image_array
|
144 |
-
$
|
145 |
}
|
146 |
-
$content = '<video class="bp-media-featured-media wp-video-shortcode"' . $
|
147 |
break;
|
148 |
-
case 'music'
|
149 |
-
$content = '<audio class="bp-media-featured-media wp-audio-shortcode"' . $
|
150 |
break;
|
151 |
-
case 'photo'
|
152 |
$this->generate_featured_size( $featured->media_id );
|
153 |
$image_array = image_downsize( $featured->media_id, 'rt_media_featured_image' );
|
154 |
$content = '<img src="' . esc_url( $image_array[0] ) . '" alt="' . esc_attr( $featured->media_title ) . '" />';
|
155 |
break;
|
156 |
-
default
|
157 |
return false;
|
158 |
}
|
159 |
|
160 |
return apply_filters( 'rtmedia_featured_media_content', $content );
|
161 |
}
|
162 |
|
163 |
-
|
|
|
|
|
|
|
|
|
|
|
164 |
if ( ! isset( $this->action_query->id ) ) {
|
165 |
return;
|
166 |
}
|
167 |
-
|
|
|
|
|
168 |
if ( ! wp_verify_nonce( $nonce, 'rtm_media_featured_nonce' . $this->media->id ) ) {
|
169 |
$return['nonce'] = true;
|
170 |
wp_send_json( $return );
|
171 |
}
|
|
|
172 |
$return = array();
|
173 |
$return['nonce'] = false;
|
174 |
$this->model = new RTMediaModel();
|
175 |
$actions = $this->model->get( array( 'id' => $this->action_query->id ) );
|
176 |
$this->get();
|
|
|
177 |
if ( 1 === intval( $this->settings[ $actions[0]->media_type ] ) ) {
|
178 |
if ( $this->action_query->id === $this->featured ) {
|
179 |
$this->set( 0 );
|
@@ -184,15 +259,18 @@ class RTMediaFeatured extends RTMediaUserInteraction {
|
|
184 |
$return['next'] = $this->undo_label;
|
185 |
$return['action'] = true;
|
186 |
}
|
|
|
187 |
$return['status'] = true;
|
188 |
global $rtmedia_points_media_id;
|
189 |
$rtmedia_points_media_id = $this->action_query->id;
|
190 |
do_action( 'rtmedia_after_set_featured', $this );
|
|
|
191 |
} else {
|
192 |
$return['status'] = false;
|
193 |
$return['error'] = esc_html__( 'Media type is not allowed', 'buddypress-media' );
|
194 |
}
|
195 |
-
|
|
|
196 |
|
197 |
if ( ! empty( $is_json ) && 'true' === $is_json ) {
|
198 |
wp_send_json( $return );
|
@@ -202,17 +280,36 @@ class RTMediaFeatured extends RTMediaUserInteraction {
|
|
202 |
}
|
203 |
}
|
204 |
|
205 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
206 |
$button .= wp_nonce_field( 'rtm_media_featured_nonce' . $this->media->id, 'rtm_media_featured_nonce', true, false );
|
207 |
|
208 |
return $button;
|
209 |
}
|
210 |
}
|
211 |
|
|
|
|
|
|
|
|
|
|
|
212 |
function rtmedia_featured( $user_id = false ) {
|
213 |
-
echo rtmedia_get_featured( $user_id );
|
214 |
}
|
215 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
216 |
function rtmedia_get_featured( $user_id = false ) {
|
217 |
$featured = new RTMediaFeatured( $user_id, false );
|
218 |
|
@@ -221,10 +318,22 @@ function rtmedia_get_featured( $user_id = false ) {
|
|
221 |
|
222 |
if ( ! function_exists( 'bp_media_featured' ) ) {
|
223 |
|
|
|
|
|
|
|
|
|
|
|
224 |
function bp_media_featured( $user_id = false ) {
|
225 |
-
echo rtmedia_get_featured( $user_id )
|
226 |
}
|
227 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
228 |
function bp_media_get_featured( $user_id = false ) {
|
229 |
return rtmedia_get_featured( $user_id );
|
230 |
}
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* Handles users featured media related operations.
|
4 |
+
*
|
5 |
+
* @package rtMedia
|
6 |
*/
|
7 |
|
8 |
/**
|
9 |
+
* Class to Handle users featured media related operations
|
10 |
*
|
11 |
* @author saurabh
|
12 |
*/
|
13 |
class RTMediaFeatured extends RTMediaUserInteraction {
|
14 |
|
15 |
/**
|
16 |
+
* User id.
|
17 |
*
|
18 |
+
* @var bool|int
|
19 |
*/
|
20 |
public $user_id;
|
21 |
+
|
22 |
+
/**
|
23 |
+
* Featured media
|
24 |
+
*
|
25 |
+
* @var string
|
26 |
+
*/
|
27 |
public $featured;
|
28 |
+
|
29 |
+
/**
|
30 |
+
* Array of settings.
|
31 |
+
*
|
32 |
+
* @var array
|
33 |
+
*/
|
34 |
public $settings;
|
35 |
|
36 |
+
/**
|
37 |
+
* RTMediaFeatured constructor.
|
38 |
+
*
|
39 |
+
* @param bool|int $user_id User id.
|
40 |
+
* @param bool $flag Show featured media button or not.
|
41 |
+
*/
|
42 |
+
public function __construct( $user_id = false, $flag = true ) {
|
43 |
$args = array(
|
44 |
'action' => 'featured',
|
45 |
'label' => esc_html__( 'Set as Featured', 'buddypress-media' ),
|
56 |
$this->user_id = $user_id;
|
57 |
parent::__construct( $args );
|
58 |
$this->settings();
|
59 |
+
|
60 |
remove_filter( 'rtmedia_action_buttons_before_delete', array( $this, 'button_filter' ) );
|
61 |
if ( $flag ) {
|
62 |
add_filter( 'rtmedia_addons_action_buttons', array( $this, 'button_filter' ) );
|
65 |
add_action( 'rtmedia_featured_button_filter', array( $this, 'featured_button_filter_nonce' ), 10, 1 );
|
66 |
}
|
67 |
|
68 |
+
/**
|
69 |
+
* Before rendering featured media.
|
70 |
+
*
|
71 |
+
* @return bool|void
|
72 |
+
*/
|
73 |
+
public function before_render() {
|
74 |
$this->get();
|
75 |
+
|
76 |
if ( ( ! ( isset( $this->settings[ $this->media->media_type ] ) && $this->settings[ $this->media->media_type ] ) ) || ( isset( $this->media->context ) && ( 'profile' !== $this->media->context ) ) ) {
|
77 |
return false;
|
78 |
}
|
79 |
+
|
80 |
if ( isset( $this->action_query ) && isset( $this->action_query->id ) && intval( $this->action_query->id ) === intval( $this->featured ) ) {
|
81 |
$this->label = $this->undo_label;
|
82 |
}
|
83 |
}
|
84 |
|
85 |
+
/**
|
86 |
+
* Set featured media to current user.
|
87 |
+
*
|
88 |
+
* @param bool|int $media_id Media id.
|
89 |
+
*/
|
90 |
+
public function set( $media_id = false ) {
|
91 |
if ( false === $media_id ) {
|
92 |
return;
|
93 |
}
|
95 |
$this->user_id = get_current_user_id();
|
96 |
}
|
97 |
|
98 |
+
// todo user attribute.
|
99 |
update_user_meta( $this->user_id, 'rtmedia_featured_media', $media_id );
|
100 |
}
|
101 |
|
102 |
+
/**
|
103 |
+
* Get featured media for user.
|
104 |
+
*
|
105 |
+
* @return mixed
|
106 |
+
*/
|
107 |
+
public function get() {
|
108 |
if ( false === $this->user_id ) {
|
109 |
if ( function_exists( 'bp_displayed_user_id' ) ) {
|
110 |
$this->user_id = bp_displayed_user_id();
|
113 |
$this->user_id = get_current_user_id();
|
114 |
}
|
115 |
}
|
116 |
+
// todo user attribute.
|
117 |
$this->featured = get_user_meta( $this->user_id, 'rtmedia_featured_media', true );
|
118 |
+
|
119 |
if ( empty( $this->featured ) ) {
|
120 |
$this->featured = get_user_meta( $this->user_id, 'bp_media_featured_media', true );
|
121 |
}
|
123 |
return $this->featured;
|
124 |
}
|
125 |
|
126 |
+
/**
|
127 |
+
* Set media settings.
|
128 |
+
*/
|
129 |
+
public function settings() {
|
130 |
global $rtmedia;
|
131 |
+
|
132 |
$this->settings['photo'] = isset( $rtmedia->options['allowedTypes_photo_featured'] ) ? $rtmedia->options['allowedTypes_photo_featured'] : 0;
|
133 |
$this->settings['video'] = isset( $rtmedia->options['allowedTypes_video_featured'] ) ? $rtmedia->options['allowedTypes_video_featured'] : 0;
|
134 |
$this->settings['music'] = isset( $rtmedia->options['allowedTypes_music_featured'] ) ? $rtmedia->options['allowedTypes_music_featured'] : 0;
|
137 |
$this->settings['crop'] = isset( $rtmedia->options['defaultSizes_featured_default_crop'] ) ? $rtmedia->options['defaultSizes_featured_default_crop'] : 1;
|
138 |
}
|
139 |
|
140 |
+
/**
|
141 |
+
* Check if media type is valid.
|
142 |
+
*
|
143 |
+
* @param string $type Media type.
|
144 |
+
*
|
145 |
+
* @return bool
|
146 |
+
*/
|
147 |
+
public function valid_type( $type ) {
|
148 |
if ( isset( $this->settings[ $type ] ) && $this->settings[ $type ] > 0 ) {
|
149 |
return true;
|
150 |
}
|
152 |
return false;
|
153 |
}
|
154 |
|
155 |
+
/**
|
156 |
+
* Generate featured size for given media.
|
157 |
+
*
|
158 |
+
* @param int $media_id Media id.
|
159 |
+
*/
|
160 |
+
public function generate_featured_size( $media_id ) {
|
161 |
$metadata = wp_get_attachment_metadata( $media_id );
|
162 |
$resized = image_make_intermediate_size( get_attached_file( $media_id ), $this->settings['width'], $this->settings['height'], $this->settings['crop'] );
|
163 |
+
|
164 |
if ( $resized ) {
|
165 |
$metadata['sizes']['rt_media_featured_image'] = $resized;
|
166 |
wp_update_attachment_metadata( $media_id, $metadata );
|
167 |
}
|
168 |
}
|
169 |
|
170 |
+
/**
|
171 |
+
* Check if provided media exists.
|
172 |
+
*
|
173 |
+
* @param int $id Media id.
|
174 |
+
*
|
175 |
+
* @return bool
|
176 |
+
*/
|
177 |
+
public function media_exists( $id ) {
|
178 |
global $wpdb;
|
179 |
+
|
180 |
$post_exists = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->posts} WHERE id = %d", $id ), 'ARRAY_A' );
|
181 |
+
|
182 |
if ( $post_exists ) {
|
183 |
return true;
|
184 |
} else {
|
186 |
}
|
187 |
}
|
188 |
|
189 |
+
/**
|
190 |
+
* Get featured video/audio/image content.
|
191 |
+
*
|
192 |
+
* @return bool|mixed|void
|
193 |
+
*/
|
194 |
+
public function content() {
|
195 |
$this->get();
|
196 |
$actions = $this->model->get( array( 'id' => $this->featured ) );
|
197 |
if ( ! $actions ) {
|
198 |
return false;
|
199 |
}
|
200 |
|
201 |
+
$featured = $actions[0];
|
202 |
+
$type = $featured->media_type;
|
203 |
+
$content_extra = '';
|
204 |
|
|
|
205 |
switch ( $type ) {
|
206 |
+
case 'video':
|
207 |
$this->generate_featured_size( $this->featured );
|
208 |
if ( $featured->media_id ) {
|
209 |
+
$image_array = image_downsize( $featured->media_id, 'rt_media_thumbnail' );
|
210 |
+
$content_extra = ' poster="' . esc_url( $image_array[0] ) . '" ';
|
211 |
}
|
212 |
+
$content = '<video class="bp-media-featured-media wp-video-shortcode"' . $content_extra . 'src="' . esc_url( wp_get_attachment_url( $featured->media_id ) ) . '" width="' . esc_attr( $this->settings['width'] ) . '" height="' . esc_attr( $this->settings['height'] ) . '" type="video/mp4" id="bp_media_video_' . esc_attr( $this->featured ) . '" controls="controls" preload="true"></video>';
|
213 |
break;
|
214 |
+
case 'music':
|
215 |
+
$content = '<audio class="bp-media-featured-media wp-audio-shortcode"' . $content_extra . 'src="' . esc_url( wp_get_attachment_url( $featured->media_id ) ) . '" width="' . esc_attr( $this->settings['width'] ) . '" type="audio/mp3" id="bp_media_audio_' . esc_attr( $this->featured ) . '" controls="controls" preload="none"></audio>';
|
216 |
break;
|
217 |
+
case 'photo':
|
218 |
$this->generate_featured_size( $featured->media_id );
|
219 |
$image_array = image_downsize( $featured->media_id, 'rt_media_featured_image' );
|
220 |
$content = '<img src="' . esc_url( $image_array[0] ) . '" alt="' . esc_attr( $featured->media_title ) . '" />';
|
221 |
break;
|
222 |
+
default:
|
223 |
return false;
|
224 |
}
|
225 |
|
226 |
return apply_filters( 'rtmedia_featured_media_content', $content );
|
227 |
}
|
228 |
|
229 |
+
/**
|
230 |
+
* Process featured media request.
|
231 |
+
*
|
232 |
+
* @return int|void
|
233 |
+
*/
|
234 |
+
public function process() {
|
235 |
if ( ! isset( $this->action_query->id ) ) {
|
236 |
return;
|
237 |
}
|
238 |
+
|
239 |
+
$nonce = sanitize_text_field( filter_input( INPUT_POST, 'featured_nonce', FILTER_SANITIZE_STRING ) );
|
240 |
+
|
241 |
if ( ! wp_verify_nonce( $nonce, 'rtm_media_featured_nonce' . $this->media->id ) ) {
|
242 |
$return['nonce'] = true;
|
243 |
wp_send_json( $return );
|
244 |
}
|
245 |
+
|
246 |
$return = array();
|
247 |
$return['nonce'] = false;
|
248 |
$this->model = new RTMediaModel();
|
249 |
$actions = $this->model->get( array( 'id' => $this->action_query->id ) );
|
250 |
$this->get();
|
251 |
+
|
252 |
if ( 1 === intval( $this->settings[ $actions[0]->media_type ] ) ) {
|
253 |
if ( $this->action_query->id === $this->featured ) {
|
254 |
$this->set( 0 );
|
259 |
$return['next'] = $this->undo_label;
|
260 |
$return['action'] = true;
|
261 |
}
|
262 |
+
|
263 |
$return['status'] = true;
|
264 |
global $rtmedia_points_media_id;
|
265 |
$rtmedia_points_media_id = $this->action_query->id;
|
266 |
do_action( 'rtmedia_after_set_featured', $this );
|
267 |
+
|
268 |
} else {
|
269 |
$return['status'] = false;
|
270 |
$return['error'] = esc_html__( 'Media type is not allowed', 'buddypress-media' );
|
271 |
}
|
272 |
+
|
273 |
+
$is_json = sanitize_text_field( filter_input( INPUT_POST, 'json', FILTER_SANITIZE_STRING ) );
|
274 |
|
275 |
if ( ! empty( $is_json ) && 'true' === $is_json ) {
|
276 |
wp_send_json( $return );
|
280 |
}
|
281 |
}
|
282 |
|
283 |
+
/**
|
284 |
+
* Add media featured nonce to button.
|
285 |
+
*
|
286 |
+
* @param string $button Button html.
|
287 |
+
*
|
288 |
+
* @return string
|
289 |
+
*/
|
290 |
+
public function featured_button_filter_nonce( $button ) {
|
291 |
$button .= wp_nonce_field( 'rtm_media_featured_nonce' . $this->media->id, 'rtm_media_featured_nonce', true, false );
|
292 |
|
293 |
return $button;
|
294 |
}
|
295 |
}
|
296 |
|
297 |
+
/**
|
298 |
+
* Get featured media for user.
|
299 |
+
*
|
300 |
+
* @param bool|int $user_id User ID.
|
301 |
+
*/
|
302 |
function rtmedia_featured( $user_id = false ) {
|
303 |
+
echo wp_kses( rtmedia_get_featured( $user_id ), RTMedia::expanded_allowed_tags() );
|
304 |
}
|
305 |
|
306 |
+
/**
|
307 |
+
* Get featured media for user.
|
308 |
+
*
|
309 |
+
* @param bool|int $user_id User ID.
|
310 |
+
*
|
311 |
+
* @return bool|mixed|void
|
312 |
+
*/
|
313 |
function rtmedia_get_featured( $user_id = false ) {
|
314 |
$featured = new RTMediaFeatured( $user_id, false );
|
315 |
|
318 |
|
319 |
if ( ! function_exists( 'bp_media_featured' ) ) {
|
320 |
|
321 |
+
/**
|
322 |
+
* Get featured media for user.
|
323 |
+
*
|
324 |
+
* @param bool|int $user_id User ID.
|
325 |
+
*/
|
326 |
function bp_media_featured( $user_id = false ) {
|
327 |
+
echo wp_kses( rtmedia_get_featured( $user_id ), RTMedia::expanded_allowed_tags() );
|
328 |
}
|
329 |
|
330 |
+
/**
|
331 |
+
* Get featured media for user.
|
332 |
+
*
|
333 |
+
* @param bool|int $user_id User ID.
|
334 |
+
*
|
335 |
+
* @return bool|mixed|void
|
336 |
+
*/
|
337 |
function bp_media_get_featured( $user_id = false ) {
|
338 |
return rtmedia_get_featured( $user_id );
|
339 |
}
|
app/main/controllers/media/RTMediaGalleryItemAction.php
CHANGED
@@ -1,34 +1,55 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
/**
|
4 |
-
*
|
5 |
*
|
6 |
-
*
|
|
|
|
|
|
|
|
|
|
|
7 |
*/
|
8 |
class RTMediaGalleryItemAction {
|
9 |
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
12 |
add_action( 'rtmedia_before_item', array( $this, 'action_buttons_before_media_thumbnail' ), 11 );
|
13 |
-
// In load more of media all the data render through backbone template and so we need to avail it in backbone variable
|
14 |
add_filter( 'rtmedia_media_array_backbone', array( $this, 'rtmedia_media_actions_backbone' ), 10, 1 );
|
15 |
-
// add a custom class to media gallery item if the user on his profile which will be used to show the action buttons on the media gallery item
|
16 |
add_filter( 'rtmedia_gallery_class_filter', array( $this, 'add_class_to_rtmedia_gallery' ), 11, 1 );
|
17 |
-
// remove rtMedia Pro actions
|
18 |
add_action( 'rtmedia_before_media_gallery', array( $this, 'remove_rtmedia_pro_hooks' ) );
|
19 |
}
|
20 |
|
21 |
-
|
|
|
|
|
|
|
22 |
remove_action( 'rtmedia_before_item', 'add_action_buttons_before_media_thumbnail', 11 );
|
23 |
}
|
24 |
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
global $rtmedia_query;
|
27 |
$user_id = get_current_user_id();
|
|
|
28 |
if ( is_rt_admin() || ( isset( $rtmedia_query->query['context'] ) && 'profile' === $rtmedia_query->query['context'] && isset( $rtmedia_query->query['context_id'] ) && $rtmedia_query->query['context_id'] === $user_id ) ) {
|
29 |
$classes .= ' rtm-pro-allow-action';
|
30 |
}
|
|
|
31 |
if ( isset( $rtmedia_query->query['context'] ) && 'group' === $rtmedia_query->query['context'] ) {
|
|
|
32 |
$group_id = $rtmedia_query->query['context_id'];
|
33 |
if ( groups_is_user_mod( $user_id, $group_id ) || groups_is_user_admin( $user_id, $group_id ) ) {
|
34 |
$classes .= ' rtm-pro-allow-action';
|
@@ -39,13 +60,16 @@ class RTMediaGalleryItemAction {
|
|
39 |
|
40 |
}
|
41 |
|
42 |
-
|
43 |
-
|
44 |
-
|
|
|
|
|
45 |
global $rtmedia_media, $rtmedia_backbone;
|
46 |
?>
|
47 |
<?php
|
48 |
if ( is_user_logged_in() ) {
|
|
|
49 |
if ( $rtmedia_backbone['backbone'] ) {
|
50 |
echo '<%= media_actions %>';
|
51 |
} else {
|
@@ -53,17 +77,15 @@ class RTMediaGalleryItemAction {
|
|
53 |
$user_id = get_current_user_id();
|
54 |
|
55 |
if ( is_rt_admin()
|
56 |
-
|
57 |
-
|
58 |
) {
|
59 |
?>
|
60 |
<div class='rtmedia-gallery-item-actions'>
|
61 |
-
<a href="<?php rtmedia_permalink(); ?>edit" class='no-popup' target='_blank'
|
62 |
-
title='<?php esc_attr_e( 'Edit this media', 'buddypress-media' ); ?>'>
|
63 |
<i class='dashicons dashicons-edit'></i><?php esc_html_e( 'Edit', 'buddypress-media' ); ?>
|
64 |
</a>
|
65 |
-
<a href="#" class="no-popup rtm-delete-media"
|
66 |
-
title='<?php esc_attr_e( 'Delete this media', 'buddypress-media' ); ?>'>
|
67 |
<i class='dashicons dashicons-trash'></i><?php esc_html_e( 'Delete', 'buddypress-media' ); ?>
|
68 |
</a>
|
69 |
</div>
|
@@ -73,7 +95,14 @@ class RTMediaGalleryItemAction {
|
|
73 |
}
|
74 |
}
|
75 |
|
76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
$context_id = $media_array->context_id;
|
78 |
$user_id = get_current_user_id();
|
79 |
|
1 |
<?php
|
|
|
2 |
/**
|
3 |
+
* Edits/deletes links on gallery items.
|
4 |
*
|
5 |
+
* @author Ritesh <ritesh.patel@rtcamp.com>
|
6 |
+
* @package rtMedia
|
7 |
+
*/
|
8 |
+
|
9 |
+
/**
|
10 |
+
* Edit/delete links on gallery items.
|
11 |
*/
|
12 |
class RTMediaGalleryItemAction {
|
13 |
|
14 |
+
/**
|
15 |
+
* RTMediaGalleryItemAction constructor.
|
16 |
+
*/
|
17 |
+
public function __construct() {
|
18 |
+
// add edit/delete buttons in media gallery besides thumbnails.
|
19 |
add_action( 'rtmedia_before_item', array( $this, 'action_buttons_before_media_thumbnail' ), 11 );
|
20 |
+
// In load more of media all the data render through backbone template and so we need to avail it in backbone variable.
|
21 |
add_filter( 'rtmedia_media_array_backbone', array( $this, 'rtmedia_media_actions_backbone' ), 10, 1 );
|
22 |
+
// add a custom class to media gallery item if the user on his profile which will be used to show the action buttons on the media gallery item.
|
23 |
add_filter( 'rtmedia_gallery_class_filter', array( $this, 'add_class_to_rtmedia_gallery' ), 11, 1 );
|
24 |
+
// remove rtMedia Pro actions.
|
25 |
add_action( 'rtmedia_before_media_gallery', array( $this, 'remove_rtmedia_pro_hooks' ) );
|
26 |
}
|
27 |
|
28 |
+
/**
|
29 |
+
* Hook to add button for medias.
|
30 |
+
*/
|
31 |
+
public function remove_rtmedia_pro_hooks() {
|
32 |
remove_action( 'rtmedia_before_item', 'add_action_buttons_before_media_thumbnail', 11 );
|
33 |
}
|
34 |
|
35 |
+
/**
|
36 |
+
* Add classes to media gallery.
|
37 |
+
*
|
38 |
+
* @param string $classes CSS classes for media gallery.
|
39 |
+
*
|
40 |
+
* @return string
|
41 |
+
*/
|
42 |
+
public function add_class_to_rtmedia_gallery( $classes ) {
|
43 |
+
|
44 |
global $rtmedia_query;
|
45 |
$user_id = get_current_user_id();
|
46 |
+
|
47 |
if ( is_rt_admin() || ( isset( $rtmedia_query->query['context'] ) && 'profile' === $rtmedia_query->query['context'] && isset( $rtmedia_query->query['context_id'] ) && $rtmedia_query->query['context_id'] === $user_id ) ) {
|
48 |
$classes .= ' rtm-pro-allow-action';
|
49 |
}
|
50 |
+
|
51 |
if ( isset( $rtmedia_query->query['context'] ) && 'group' === $rtmedia_query->query['context'] ) {
|
52 |
+
|
53 |
$group_id = $rtmedia_query->query['context_id'];
|
54 |
if ( groups_is_user_mod( $user_id, $group_id ) || groups_is_user_admin( $user_id, $group_id ) ) {
|
55 |
$classes .= ' rtm-pro-allow-action';
|
60 |
|
61 |
}
|
62 |
|
63 |
+
/**
|
64 |
+
* Add actions buttons before showing thumbnail.
|
65 |
+
*/
|
66 |
+
public function action_buttons_before_media_thumbnail() {
|
67 |
+
// add edit and delete links on single media.
|
68 |
global $rtmedia_media, $rtmedia_backbone;
|
69 |
?>
|
70 |
<?php
|
71 |
if ( is_user_logged_in() ) {
|
72 |
+
|
73 |
if ( $rtmedia_backbone['backbone'] ) {
|
74 |
echo '<%= media_actions %>';
|
75 |
} else {
|
77 |
$user_id = get_current_user_id();
|
78 |
|
79 |
if ( is_rt_admin()
|
80 |
+
|| ( function_exists( 'groups_is_user_mod' ) && groups_is_user_mod( $user_id, $context_id ) )
|
81 |
+
|| ( isset( $rtmedia_media ) && isset( $rtmedia_media->media_author ) && get_current_user_id() === intval( $rtmedia_media->media_author ) )
|
82 |
) {
|
83 |
?>
|
84 |
<div class='rtmedia-gallery-item-actions'>
|
85 |
+
<a href="<?php rtmedia_permalink(); ?>edit" class='no-popup' target='_blank' title='<?php esc_attr_e( 'Edit this media', 'buddypress-media' ); ?>'>
|
|
|
86 |
<i class='dashicons dashicons-edit'></i><?php esc_html_e( 'Edit', 'buddypress-media' ); ?>
|
87 |
</a>
|
88 |
+
<a href="#" class="no-popup rtm-delete-media" title='<?php esc_attr_e( 'Delete this media', 'buddypress-media' ); ?>'>
|
|
|
89 |
<i class='dashicons dashicons-trash'></i><?php esc_html_e( 'Delete', 'buddypress-media' ); ?>
|
90 |
</a>
|
91 |
</div>
|
95 |
}
|
96 |
}
|
97 |
|
98 |
+
/**
|
99 |
+
* Add Div to show media action buttons.
|
100 |
+
*
|
101 |
+
* @param object $media_array Media details.
|
102 |
+
*
|
103 |
+
* @return mixed
|
104 |
+
*/
|
105 |
+
public function rtmedia_media_actions_backbone( $media_array ) {
|
106 |
$context_id = $media_array->context_id;
|
107 |
$user_id = get_current_user_id();
|
108 |
|
app/main/controllers/media/RTMediaGroupFeatured.php
CHANGED
@@ -1,17 +1,45 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
/**
|
4 |
-
*
|
5 |
*
|
|
|
6 |
* @author ritz <ritesh.patel@rtcamp.com>
|
7 |
*/
|
|
|
|
|
|
|
|
|
8 |
class RTMediaGroupFeatured extends RTMediaUserInteraction {
|
9 |
|
|
|
|
|
|
|
|
|
|
|
10 |
public $group_id;
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
public $featured;
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
public $settings;
|
13 |
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
$args = array(
|
16 |
'action' => 'group-featured',
|
17 |
'label' => esc_html__( 'Set as Featured', 'buddypress-media' ),
|
@@ -29,13 +57,19 @@ class RTMediaGroupFeatured extends RTMediaUserInteraction {
|
|
29 |
parent::__construct( $args );
|
30 |
$this->settings();
|
31 |
remove_filter( 'rtmedia_action_buttons_before_delete', array( $this, 'button_filter' ) );
|
|
|
32 |
if ( $flag ) {
|
33 |
add_filter( 'rtmedia_addons_action_buttons', array( $this, 'button_filter' ) );
|
34 |
add_filter( 'rtmedia_author_media_options', array( $this, 'button_filter' ), 12, 1 );
|
35 |
}
|
36 |
}
|
37 |
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
if ( ! class_exists( 'BuddyPress' ) || ! bp_is_active( 'groups' ) ) {
|
41 |
return false;
|
@@ -43,19 +77,19 @@ class RTMediaGroupFeatured extends RTMediaUserInteraction {
|
|
43 |
|
44 |
$this->get();
|
45 |
|
46 |
-
// if group id is not set, don't render "Set featured"
|
47 |
if ( empty( $this->group_id ) ) {
|
48 |
return false;
|
49 |
}
|
50 |
|
51 |
$user_id = get_current_user_id();
|
52 |
|
53 |
-
// if current is not group moderator or group admin, don't render "Set featured"
|
54 |
if ( ! groups_is_user_mod( $user_id, $this->group_id ) && ! groups_is_user_admin( $user_id, $this->group_id ) && ! is_rt_admin() ) {
|
55 |
return false;
|
56 |
}
|
57 |
|
58 |
-
// if current media is not any group media, don't render "Set featured"
|
59 |
if ( ( ! ( isset( $this->settings[ $this->media->media_type ] ) && $this->settings[ $this->media->media_type ] ) ) || ( isset( $this->media->context ) && ( 'group' !== $this->media->context ) ) ) {
|
60 |
return false;
|
61 |
}
|
@@ -65,7 +99,12 @@ class RTMediaGroupFeatured extends RTMediaUserInteraction {
|
|
65 |
}
|
66 |
}
|
67 |
|
68 |
-
|
|
|
|
|
|
|
|
|
|
|
69 |
if ( false === $media_id ) {
|
70 |
return;
|
71 |
}
|
@@ -75,7 +114,12 @@ class RTMediaGroupFeatured extends RTMediaUserInteraction {
|
|
75 |
groups_update_groupmeta( $this->group_id, 'rtmedia_group_featured_media', $media_id );
|
76 |
}
|
77 |
|
78 |
-
|
|
|
|
|
|
|
|
|
|
|
79 |
if ( false === $this->group_id ) {
|
80 |
global $groups_template;
|
81 |
if ( ! empty( $groups_template->group ) ) {
|
@@ -83,7 +127,7 @@ class RTMediaGroupFeatured extends RTMediaUserInteraction {
|
|
83 |
if ( ! empty( $group_id ) ) {
|
84 |
$this->group_id = $group_id;
|
85 |
}
|
86 |
-
}
|
87 |
$this->group_id = $this->media->context_id;
|
88 |
} else {
|
89 |
return false;
|
@@ -94,7 +138,10 @@ class RTMediaGroupFeatured extends RTMediaUserInteraction {
|
|
94 |
return $this->featured;
|
95 |
}
|
96 |
|
97 |
-
|
|
|
|
|
|
|
98 |
global $rtmedia;
|
99 |
$this->settings['photo'] = isset( $rtmedia->options['allowedTypes_photo_featured'] ) ? $rtmedia->options['allowedTypes_photo_featured'] : 0;
|
100 |
$this->settings['video'] = isset( $rtmedia->options['allowedTypes_video_featured'] ) ? $rtmedia->options['allowedTypes_video_featured'] : 0;
|
@@ -104,7 +151,14 @@ class RTMediaGroupFeatured extends RTMediaUserInteraction {
|
|
104 |
$this->settings['crop'] = isset( $rtmedia->options['defaultSizes_featured_default_crop'] ) ? $rtmedia->options['defaultSizes_featured_default_crop'] : 1;
|
105 |
}
|
106 |
|
107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
if ( isset( $this->settings[ $type ] ) && $this->settings[ $type ] > 0 ) {
|
109 |
return true;
|
110 |
}
|
@@ -112,20 +166,36 @@ class RTMediaGroupFeatured extends RTMediaUserInteraction {
|
|
112 |
return false;
|
113 |
}
|
114 |
|
115 |
-
|
116 |
-
|
|
|
|
|
|
|
117 |
}
|
118 |
|
119 |
-
|
|
|
|
|
|
|
|
|
|
|
120 |
$metadata = wp_get_attachment_metadata( $media_id );
|
121 |
$resized = image_make_intermediate_size( get_attached_file( $media_id ), $this->settings['width'], $this->settings['height'], $this->settings['crop'] );
|
|
|
122 |
if ( $resized ) {
|
123 |
$metadata['sizes']['rt_media_featured_image'] = $resized;
|
124 |
wp_update_attachment_metadata( $media_id, $metadata );
|
125 |
}
|
126 |
}
|
127 |
|
128 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
129 |
global $wpdb;
|
130 |
$post_exists = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->posts} WHERE id = %d", $id ), 'ARRAY_A' );
|
131 |
if ( $post_exists ) {
|
@@ -135,66 +205,87 @@ class RTMediaGroupFeatured extends RTMediaUserInteraction {
|
|
135 |
}
|
136 |
}
|
137 |
|
138 |
-
|
|
|
|
|
|
|
|
|
|
|
139 |
$this->get();
|
140 |
$actions = $this->model->get( array( 'id' => $this->featured ) );
|
|
|
141 |
if ( ! $actions ) {
|
142 |
return false;
|
143 |
}
|
144 |
|
145 |
-
$featured
|
146 |
-
$type
|
|
|
147 |
|
148 |
-
$content_xtra = '';
|
149 |
switch ( $type ) {
|
150 |
-
case 'video'
|
151 |
$this->generate_featured_size( $this->featured );
|
152 |
if ( $featured->media_id ) {
|
153 |
-
$image_array
|
154 |
-
$
|
155 |
}
|
156 |
-
$content = '<video class="bp-media-featured-media wp-video-shortcode"' . esc_attr( $
|
157 |
break;
|
158 |
-
case 'music'
|
159 |
$content = '<audio class="bp-media-featured-media wp-audio-shortcode" src="' . esc_url( wp_get_attachment_url( $featured->media_id ) ) . '" width="' . esc_attr( $this->settings['width'] ) . '" type="audio/mp3" id="bp_media_audio_' . esc_attr( $this->featured ) . '" controls="controls" preload="none"></audio>';
|
160 |
break;
|
161 |
-
case 'photo'
|
162 |
$this->generate_featured_size( $featured->media_id );
|
163 |
$image_array = image_downsize( $featured->media_id, 'rt_media_featured_image' );
|
164 |
$content = '<img src="' . esc_url( $image_array[0] ) . '" alt="' . esc_attr( $featured->media_title ) . '" />';
|
165 |
break;
|
166 |
-
default
|
167 |
return false;
|
168 |
}
|
169 |
|
170 |
return apply_filters( 'rtmedia_featured_media_content', $content );
|
171 |
}
|
172 |
|
173 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
174 |
if ( ! isset( $this->action_query->id ) ) {
|
175 |
return;
|
176 |
}
|
|
|
177 |
$return = array();
|
178 |
$this->model = new RTMediaModel();
|
179 |
$actions = $this->model->get( array( 'id' => $this->action_query->id ) );
|
180 |
$this->get();
|
|
|
181 |
if ( 1 === intval( $this->settings[ $actions[0]->media_type ] ) ) {
|
|
|
182 |
if ( $this->action_query->id === $this->featured ) {
|
183 |
$this->set( 0 );
|
184 |
-
$return['next']
|
|
|
185 |
} else {
|
186 |
$this->set( $this->action_query->id );
|
187 |
-
$return['next']
|
|
|
188 |
}
|
|
|
189 |
$return['status'] = true;
|
190 |
global $rtmedia_points_media_id;
|
191 |
$rtmedia_points_media_id = $this->action_query->id;
|
192 |
do_action( 'rtmedia_after_set_featured', $this );
|
|
|
193 |
} else {
|
194 |
$return['status'] = false;
|
195 |
$return['error'] = esc_html__( 'Media type is not allowed', 'buddypress-media' );
|
196 |
}
|
197 |
-
|
|
|
|
|
198 |
if ( isset( $is_json ) && 'true' === $is_json ) {
|
199 |
wp_send_json( $return );
|
200 |
} else {
|
@@ -204,10 +295,22 @@ class RTMediaGroupFeatured extends RTMediaUserInteraction {
|
|
204 |
}
|
205 |
}
|
206 |
|
|
|
|
|
|
|
|
|
|
|
207 |
function rtmedia_group_featured( $group_id = false ) {
|
208 |
-
echo rtmedia_get_group_featured( $group_id )
|
209 |
}
|
210 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
211 |
function rtmedia_get_group_featured( $group_id = false ) {
|
212 |
$featured = new RTMediaGroupFeatured( $group_id, false );
|
213 |
|
1 |
<?php
|
|
|
2 |
/**
|
3 |
+
* Handles media group featured media.
|
4 |
*
|
5 |
+
* @package rtMedia
|
6 |
* @author ritz <ritesh.patel@rtcamp.com>
|
7 |
*/
|
8 |
+
|
9 |
+
/**
|
10 |
+
* Class to handle media group featured media.
|
11 |
+
*/
|
12 |
class RTMediaGroupFeatured extends RTMediaUserInteraction {
|
13 |
|
14 |
+
/**
|
15 |
+
* Media group id.
|
16 |
+
*
|
17 |
+
* @var bool|int
|
18 |
+
*/
|
19 |
public $group_id;
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Group featured media.
|
23 |
+
*
|
24 |
+
* @var int
|
25 |
+
*/
|
26 |
public $featured;
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Featured media settings.
|
30 |
+
*
|
31 |
+
* @var array
|
32 |
+
*/
|
33 |
public $settings;
|
34 |
|
35 |
+
/**
|
36 |
+
* RTMediaGroupFeatured constructor.
|
37 |
+
*
|
38 |
+
* @param bool|int $group_id Group id.
|
39 |
+
* @param bool $flag Add edit options or not.
|
40 |
+
*/
|
41 |
+
public function __construct( $group_id = false, $flag = true ) {
|
42 |
+
|
43 |
$args = array(
|
44 |
'action' => 'group-featured',
|
45 |
'label' => esc_html__( 'Set as Featured', 'buddypress-media' ),
|
57 |
parent::__construct( $args );
|
58 |
$this->settings();
|
59 |
remove_filter( 'rtmedia_action_buttons_before_delete', array( $this, 'button_filter' ) );
|
60 |
+
|
61 |
if ( $flag ) {
|
62 |
add_filter( 'rtmedia_addons_action_buttons', array( $this, 'button_filter' ) );
|
63 |
add_filter( 'rtmedia_author_media_options', array( $this, 'button_filter' ), 12, 1 );
|
64 |
}
|
65 |
}
|
66 |
|
67 |
+
/**
|
68 |
+
* Before rendering featured media.
|
69 |
+
*
|
70 |
+
* @return bool|void
|
71 |
+
*/
|
72 |
+
public function before_render() {
|
73 |
|
74 |
if ( ! class_exists( 'BuddyPress' ) || ! bp_is_active( 'groups' ) ) {
|
75 |
return false;
|
77 |
|
78 |
$this->get();
|
79 |
|
80 |
+
// if group id is not set, don't render "Set featured".
|
81 |
if ( empty( $this->group_id ) ) {
|
82 |
return false;
|
83 |
}
|
84 |
|
85 |
$user_id = get_current_user_id();
|
86 |
|
87 |
+
// if current is not group moderator or group admin, don't render "Set featured".
|
88 |
if ( ! groups_is_user_mod( $user_id, $this->group_id ) && ! groups_is_user_admin( $user_id, $this->group_id ) && ! is_rt_admin() ) {
|
89 |
return false;
|
90 |
}
|
91 |
|
92 |
+
// if current media is not any group media, don't render "Set featured".
|
93 |
if ( ( ! ( isset( $this->settings[ $this->media->media_type ] ) && $this->settings[ $this->media->media_type ] ) ) || ( isset( $this->media->context ) && ( 'group' !== $this->media->context ) ) ) {
|
94 |
return false;
|
95 |
}
|
99 |
}
|
100 |
}
|
101 |
|
102 |
+
/**
|
103 |
+
* Set group featured media.
|
104 |
+
*
|
105 |
+
* @param bool|int $media_id Media id.
|
106 |
+
*/
|
107 |
+
public function set( $media_id = false ) {
|
108 |
if ( false === $media_id ) {
|
109 |
return;
|
110 |
}
|
114 |
groups_update_groupmeta( $this->group_id, 'rtmedia_group_featured_media', $media_id );
|
115 |
}
|
116 |
|
117 |
+
/**
|
118 |
+
* Get group featured media.
|
119 |
+
*
|
120 |
+
* @return bool|int
|
121 |
+
*/
|
122 |
+
public function get() {
|
123 |
if ( false === $this->group_id ) {
|
124 |
global $groups_template;
|
125 |
if ( ! empty( $groups_template->group ) ) {
|
127 |
if ( ! empty( $group_id ) ) {
|
128 |
$this->group_id = $group_id;
|
129 |
}
|
130 |
+
} elseif ( isset( $this->media ) && isset( $this->media->context_id ) ) {
|
131 |
$this->group_id = $this->media->context_id;
|
132 |
} else {
|
133 |
return false;
|
138 |
return $this->featured;
|
139 |
}
|
140 |
|
141 |
+
/**
|
142 |
+
* Set featured media settings.
|
143 |
+
*/
|
144 |
+
public function settings() {
|
145 |
global $rtmedia;
|
146 |
$this->settings['photo'] = isset( $rtmedia->options['allowedTypes_photo_featured'] ) ? $rtmedia->options['allowedTypes_photo_featured'] : 0;
|
147 |
$this->settings['video'] = isset( $rtmedia->options['allowedTypes_video_featured'] ) ? $rtmedia->options['allowedTypes_video_featured'] : 0;
|
151 |
$this->settings['crop'] = isset( $rtmedia->options['defaultSizes_featured_default_crop'] ) ? $rtmedia->options['defaultSizes_featured_default_crop'] : 1;
|
152 |
}
|
153 |
|
154 |
+
/**
|
155 |
+
* Check if media is valid type.
|
156 |
+
*
|
157 |
+
* @param string $type Media type.
|
158 |
+
*
|
159 |
+
* @return bool
|
160 |
+
*/
|
161 |
+
public function valid_type( $type ) {
|
162 |
if ( isset( $this->settings[ $type ] ) && $this->settings[ $type ] > 0 ) {
|
163 |
return true;
|
164 |
}
|
166 |
return false;
|
167 |
}
|
168 |
|
169 |
+
/**
|
170 |
+
* Get last media.
|
171 |
+
*/
|
172 |
+
public function get_last_media() {
|
173 |
+
// todo:remove if not used.
|
174 |
}
|
175 |
|
176 |
+
/**
|
177 |
+
* Generate featured size for media.
|
178 |
+
*
|
179 |
+
* @param int $media_id media id.
|
180 |
+
*/
|
181 |
+
public function generate_featured_size( $media_id ) {
|
182 |
$metadata = wp_get_attachment_metadata( $media_id );
|
183 |
$resized = image_make_intermediate_size( get_attached_file( $media_id ), $this->settings['width'], $this->settings['height'], $this->settings['crop'] );
|
184 |
+
|
185 |
if ( $resized ) {
|
186 |
$metadata['sizes']['rt_media_featured_image'] = $resized;
|
187 |
wp_update_attachment_metadata( $media_id, $metadata );
|
188 |
}
|
189 |
}
|
190 |
|
191 |
+
/**
|
192 |
+
* Check if media exists.
|
193 |
+
*
|
194 |
+
* @param int $id media id.
|
195 |
+
*
|
196 |
+
* @return bool
|
197 |
+
*/
|
198 |
+
public function media_exists( $id ) {
|
199 |
global $wpdb;
|
200 |
$post_exists = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->posts} WHERE id = %d", $id ), 'ARRAY_A' );
|
201 |
if ( $post_exists ) {
|
205 |
}
|
206 |
}
|
207 |
|
208 |
+
/**
|
209 |
+
* Show featured media.
|
210 |
+
*
|
211 |
+
* @return bool|mixed|void
|
212 |
+
*/
|
213 |
+
public function content() {
|
214 |
$this->get();
|
215 |
$actions = $this->model->get( array( 'id' => $this->featured ) );
|
216 |
+
|
217 |
if ( ! $actions ) {
|
218 |
return false;
|
219 |
}
|
220 |
|
221 |
+
$featured = $actions[0];
|
222 |
+
$type = $featured->media_type;
|
223 |
+
$content_extra = '';
|
224 |
|
|
|
225 |
switch ( $type ) {
|
226 |
+
case 'video':
|
227 |
$this->generate_featured_size( $this->featured );
|
228 |
if ( $featured->media_id ) {
|
229 |
+
$image_array = image_downsize( $featured->media_id, 'rt_media_thumbnail' );
|
230 |
+
$content_extra = 'poster="' . esc_url( $image_array[0] ) . '" ';
|
231 |
}
|
232 |
+
$content = '<video class="bp-media-featured-media wp-video-shortcode"' . esc_attr( $content_extra ) . 'src="' . esc_url( wp_get_attachment_url( $featured->media_id ) ) . '" width="' . esc_attr( $this->settings['width'] ) . '" height="' . esc_attr( $this->settings['height'] ) . '" type="video/mp4" id="bp_media_video_' . esc_attr( $this->featured ) . '" controls="controls" preload="true"></video>';
|
233 |
break;
|
234 |
+
case 'music':
|
235 |
$content = '<audio class="bp-media-featured-media wp-audio-shortcode" src="' . esc_url( wp_get_attachment_url( $featured->media_id ) ) . '" width="' . esc_attr( $this->settings['width'] ) . '" type="audio/mp3" id="bp_media_audio_' . esc_attr( $this->featured ) . '" controls="controls" preload="none"></audio>';
|
236 |
break;
|
237 |
+
case 'photo':
|
238 |
$this->generate_featured_size( $featured->media_id );
|
239 |
$image_array = image_downsize( $featured->media_id, 'rt_media_featured_image' );
|
240 |
$content = '<img src="' . esc_url( $image_array[0] ) . '" alt="' . esc_attr( $featured->media_title ) . '" />';
|
241 |
break;
|
242 |
+
default:
|
243 |
return false;
|
244 |
}
|
245 |
|
246 |
return apply_filters( 'rtmedia_featured_media_content', $content );
|
247 |
}
|
248 |
|
249 |
+
/**
|
250 |
+
* Process media for featured media.
|
251 |
+
*
|
252 |
+
* @return int|void
|
253 |
+
*/
|
254 |
+
public function process() {
|
255 |
+
|
256 |
if ( ! isset( $this->action_query->id ) ) {
|
257 |
return;
|
258 |
}
|
259 |
+
|
260 |
$return = array();
|
261 |
$this->model = new RTMediaModel();
|
262 |
$actions = $this->model->get( array( 'id' => $this->action_query->id ) );
|
263 |
$this->get();
|
264 |
+
|
265 |
if ( 1 === intval( $this->settings[ $actions[0]->media_type ] ) ) {
|
266 |
+
|
267 |
if ( $this->action_query->id === $this->featured ) {
|
268 |
$this->set( 0 );
|
269 |
+
$return['next'] = $this->label;
|
270 |
+
$return['action'] = false;
|
271 |
} else {
|
272 |
$this->set( $this->action_query->id );
|
273 |
+
$return['next'] = $this->undo_label;
|
274 |
+
$return['action'] = true;
|
275 |
}
|
276 |
+
|
277 |
$return['status'] = true;
|
278 |
global $rtmedia_points_media_id;
|
279 |
$rtmedia_points_media_id = $this->action_query->id;
|
280 |
do_action( 'rtmedia_after_set_featured', $this );
|
281 |
+
|
282 |
} else {
|
283 |
$return['status'] = false;
|
284 |
$return['error'] = esc_html__( 'Media type is not allowed', 'buddypress-media' );
|
285 |
}
|
286 |
+
|
287 |
+
$is_json = sanitize_text_field( filter_input( INPUT_POST, 'json', FILTER_SANITIZE_STRING ) );
|
288 |
+
|
289 |
if ( isset( $is_json ) && 'true' === $is_json ) {
|
290 |
wp_send_json( $return );
|
291 |
} else {
|
295 |
}
|
296 |
}
|
297 |
|
298 |
+
/**
|
299 |
+
* Get featured group media.
|
300 |
+
*
|
301 |
+
* @param bool|int $group_id Group id.
|
302 |
+
*/
|
303 |
function rtmedia_group_featured( $group_id = false ) {
|
304 |
+
echo wp_kses( rtmedia_get_group_featured( $group_id ), RTMedia::expanded_allowed_tags() );
|
305 |
}
|
306 |
|
307 |
+
/**
|
308 |
+
* Get featured group media.
|
309 |
+
*
|
310 |
+
* @param bool|int $group_id Group id.
|
311 |
+
*
|
312 |
+
* @return bool|mixed|void
|
313 |
+
*/
|
314 |
function rtmedia_get_group_featured( $group_id = false ) {
|
315 |
$featured = new RTMediaGroupFeatured( $group_id, false );
|
316 |
|
app/main/controllers/media/RTMediaLike.php
CHANGED
@@ -1,37 +1,50 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
/*
|
4 |
-
* To change this template, choose Tools | Templates
|
5 |
-
* and open the template in the editor.
|
6 |
-
*/
|
7 |
-
|
8 |
/**
|
9 |
-
*
|
10 |
*
|
|
|
11 |
* @author saurabh
|
12 |
*/
|
|
|
|
|
|
|
|
|
13 |
class RTMediaLike extends RTMediaUserInteraction {
|
14 |
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
$args = array(
|
17 |
-
'action'
|
18 |
-
'person_label'
|
19 |
-
'person_plural_label'
|
20 |
-
'label'
|
21 |
-
'plural'
|
22 |
-
'undo_label'
|
23 |
-
'privacy'
|
24 |
-
'countable'
|
25 |
-
'single'
|
26 |
-
'repeatable'
|
27 |
-
'undoable'
|
28 |
);
|
|
|
29 |
parent::__construct( $args );
|
|
|
30 |
remove_filter( 'rtmedia_action_buttons_before_delete', array( $this, 'button_filter' ) );
|
31 |
add_action( 'rtmedia_action_buttons_after_media', array( $this, 'button_filter' ), 12 );
|
32 |
add_action( 'rtmedia_actions_before_comments', array( $this, 'like_button_filter' ), 10 );
|
33 |
add_action( 'like_button_no_comments', array( $this, 'like_button_no_comments_callback' ), 10 );
|
34 |
add_action( 'rtmedia_like_button_filter', array( $this, 'like_button_filter_nonce' ), 10, 1 );
|
|
|
35 |
if ( ! rtmedia_comments_enabled() ) {
|
36 |
add_action( 'rtmedia_actions_without_lightbox', array( $this, 'like_button_without_lightbox_filter' ) );
|
37 |
}
|
@@ -39,31 +52,37 @@ class RTMediaLike extends RTMediaUserInteraction {
|
|
39 |
add_filter( 'rtmedia_check_enable_disable_like', array( $this, 'rtmedia_check_enable_disable_like' ), 10, 1 );
|
40 |
}
|
41 |
|
42 |
-
|
43 |
/**
|
44 |
-
*
|
|
|
45 |
* @global type $rtmedia
|
46 |
-
*
|
|
|
|
|
47 |
* @return boolean True if Likes for media is enabled else returns false
|
48 |
*/
|
49 |
-
function rtmedia_check_enable_disable_like( $enable_like ) {
|
50 |
global $rtmedia;
|
51 |
$options = $rtmedia->options;
|
52 |
-
|
|
|
53 |
return true;
|
54 |
} else {
|
55 |
return false;
|
56 |
}
|
57 |
}
|
58 |
|
59 |
-
|
|
|
|
|
|
|
60 |
if ( empty( $this->media ) ) {
|
61 |
$this->init();
|
62 |
}
|
63 |
$button = $this->render();
|
64 |
|
65 |
if ( $button ) {
|
66 |
-
echo '<span>' . $button . '</span>';
|
67 |
}
|
68 |
}
|
69 |
|
@@ -71,42 +90,61 @@ class RTMediaLike extends RTMediaUserInteraction {
|
|
71 |
* This function displays the like button even if comment
|
72 |
* section is disabled.
|
73 |
*/
|
74 |
-
function like_button_no_comments_callback() {
|
|
|
75 |
if ( empty( $this->media ) ) {
|
76 |
$this->init();
|
77 |
}
|
|
|
78 |
$button = $this->render();
|
79 |
|
80 |
if ( $button ) {
|
81 |
-
echo '<span>' . $button . '</span>';
|
82 |
}
|
83 |
}
|
84 |
|
85 |
-
|
|
|
|
|
|
|
|
|
86 |
if ( empty( $this->media ) ) {
|
87 |
$this->init();
|
88 |
}
|
|
|
89 |
$button = $this->render();
|
|
|
90 |
if ( $button ) {
|
91 |
-
echo $button
|
92 |
}
|
93 |
}
|
94 |
|
95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
$actions = $this->model->get( array( 'id' => $this->action_query->id ) );
|
97 |
-
$like_nonce = filter_input( INPUT_POST, 'like_nonce', FILTER_SANITIZE_STRING );
|
|
|
98 |
if ( ! wp_verify_nonce( $like_nonce, 'rtm_media_like_nonce' . $this->media->id ) ) {
|
99 |
die();
|
100 |
}
|
|
|
101 |
$rtmediainteraction = new RTMediaInteractionModel();
|
102 |
$user_id = $this->interactor;
|
103 |
$media_id = $this->action_query->id;
|
104 |
$action = $this->action;
|
105 |
$check_action = $rtmediainteraction->check( $user_id, $media_id, $action );
|
|
|
106 |
if ( $check_action ) {
|
|
|
107 |
$results = $rtmediainteraction->get_row( $user_id, $media_id, $action );
|
108 |
$row = $results[0];
|
109 |
$curr_value = $row->value;
|
|
|
110 |
if ( 1 === intval( $curr_value ) ) {
|
111 |
$value = '0';
|
112 |
$this->increase = false;
|
@@ -114,6 +152,7 @@ class RTMediaLike extends RTMediaUserInteraction {
|
|
114 |
$value = '1';
|
115 |
$this->increase = true;
|
116 |
}
|
|
|
117 |
$update_data = array( 'value' => $value );
|
118 |
$where_columns = array(
|
119 |
'user_id' => $user_id,
|
@@ -121,7 +160,9 @@ class RTMediaLike extends RTMediaUserInteraction {
|
|
121 |
'action' => $action,
|
122 |
);
|
123 |
$update = $rtmediainteraction->update( $update_data, $where_columns );
|
|
|
124 |
} else {
|
|
|
125 |
$value = '1';
|
126 |
$columns = array(
|
127 |
'user_id' => $user_id,
|
@@ -131,6 +172,7 @@ class RTMediaLike extends RTMediaUserInteraction {
|
|
131 |
);
|
132 |
$insert_id = $rtmediainteraction->insert( $columns );
|
133 |
$this->increase = true;
|
|
|
134 |
}
|
135 |
|
136 |
$actionwa = $this->action . 's';
|
@@ -149,11 +191,11 @@ class RTMediaLike extends RTMediaUserInteraction {
|
|
149 |
}
|
150 |
|
151 |
$like_html = '<span class="rtmedia-like-counter"></span>';
|
152 |
-
if ( $actions > 0
|
153 |
$like_html = rtmedia_who_like_html( $actions, $this->increase );
|
154 |
}
|
155 |
|
156 |
-
|
157 |
if ( 1 === $actions ) {
|
158 |
$return['person_text'] = apply_filters( 'rtmedia_' . $this->action . '_person_label_text', $like_html );
|
159 |
} else {
|
@@ -166,10 +208,12 @@ class RTMediaLike extends RTMediaUserInteraction {
|
|
166 |
|
167 |
$return['count'] = $actions;
|
168 |
$this->model->update( array( 'likes' => $actions ), array( 'id' => $this->action_query->id ) );
|
|
|
169 |
global $rtmedia_points_media_id;
|
170 |
$rtmedia_points_media_id = $this->action_query->id;
|
171 |
do_action( 'rtmedia_after_like_media', $this );
|
172 |
-
|
|
|
173 |
|
174 |
if ( ! empty( $is_json ) && 'true' === $is_json ) {
|
175 |
wp_send_json( $return );
|
@@ -182,42 +226,74 @@ class RTMediaLike extends RTMediaUserInteraction {
|
|
182 |
return $actions;
|
183 |
}
|
184 |
|
185 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
186 |
|
187 |
if ( empty( $this->media ) ) {
|
188 |
$this->init();
|
189 |
}
|
|
|
190 |
$button = $this->render();
|
191 |
|
192 |
if ( $button ) {
|
193 |
-
echo $button
|
194 |
}
|
195 |
}
|
196 |
|
197 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
198 |
$rtmediainteraction = new RTMediaInteractionModel();
|
|
|
199 |
if ( ! $user_id ) {
|
200 |
$user_id = $this->interactor;
|
201 |
}
|
|
|
202 |
if ( ! $media_id ) {
|
203 |
$media_id = $this->action_query->id;
|
204 |
}
|
|
|
205 |
$action = $this->action;
|
206 |
|
207 |
return $rtmediainteraction->check( $user_id, $media_id, $action );
|
208 |
}
|
209 |
|
210 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
211 |
$rtmediainteraction = new RTMediaInteractionModel();
|
|
|
212 |
if ( ! $user_id ) {
|
213 |
$user_id = $this->interactor;
|
214 |
}
|
|
|
215 |
if ( ! $media_id ) {
|
216 |
$media_id = $this->action_query->id;
|
217 |
}
|
|
|
218 |
$action = $this->action;
|
219 |
$results = $rtmediainteraction->get_row( $user_id, $media_id, $action );
|
220 |
$row = $results[0];
|
|
|
221 |
if ( 1 === intval( $row->value ) ) {
|
222 |
$this->increase = false;
|
223 |
|
@@ -229,7 +305,14 @@ class RTMediaLike extends RTMediaUserInteraction {
|
|
229 |
}
|
230 |
}
|
231 |
|
232 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
233 |
$rtmediainteraction = new RTMediaInteractionModel();
|
234 |
$user_id = $this->interactor;
|
235 |
$media_id = $this->action_query->id;
|
@@ -243,24 +326,36 @@ class RTMediaLike extends RTMediaUserInteraction {
|
|
243 |
);
|
244 |
$insert_id = $rtmediainteraction->insert( $columns );
|
245 |
$like_media = trim( str_replace( ',' . $this->action_query->id . ',', ',', ',' . $like_media . ',' ), ',' );
|
246 |
-
//todo user attribute
|
247 |
update_user_meta( $this->interactor, 'rtmedia_liked_media', $like_media );
|
248 |
|
249 |
return $insert_id;
|
250 |
}
|
251 |
|
252 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
253 |
if ( ! $interactor ) {
|
254 |
$interactor = $this->interactor;
|
255 |
}
|
|
|
256 |
if ( ! $media_id ) {
|
257 |
$media_id = $this->action_query->id;
|
258 |
}
|
259 |
-
|
|
|
260 |
$like_media = get_user_meta( $interactor, 'rtmedia_liked_media', true );
|
261 |
if ( $this->is_like_migrated( $media_id, $interactor ) ) {
|
262 |
return $this->get_like_value( $media_id, $interactor );
|
263 |
} else {
|
|
|
264 |
if ( strpos( ',' . $like_media . ',', ',' . $media_id . ',' ) === false ) {
|
265 |
$this->increase = true;
|
266 |
|
@@ -274,14 +369,16 @@ class RTMediaLike extends RTMediaUserInteraction {
|
|
274 |
}
|
275 |
}
|
276 |
|
277 |
-
|
278 |
-
|
279 |
-
|
|
|
|
|
|
|
|
|
280 |
$enable_like = true;
|
281 |
$enable_like = apply_filters( 'rtmedia_check_enable_disable_like', $enable_like );
|
282 |
|
283 |
-
/* if is comment media then return false */
|
284 |
-
// if ( ! $enable_like || ! empty( $comment_media ) ) {
|
285 |
if ( ! $enable_like ) {
|
286 |
return false;
|
287 |
}
|
@@ -291,8 +388,21 @@ class RTMediaLike extends RTMediaUserInteraction {
|
|
291 |
}
|
292 |
}
|
293 |
|
294 |
-
|
295 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
296 |
return $button;
|
297 |
}
|
298 |
}
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
+
* Handles media like operations.
|
4 |
*
|
5 |
+
* @package rtMedia
|
6 |
* @author saurabh
|
7 |
*/
|
8 |
+
|
9 |
+
/**
|
10 |
+
* Class to handle media like operations.
|
11 |
+
*/
|
12 |
class RTMediaLike extends RTMediaUserInteraction {
|
13 |
|
14 |
+
/**
|
15 |
+
* Check whether like nonce is already added or not.
|
16 |
+
*
|
17 |
+
* @var boolean
|
18 |
+
*/
|
19 |
+
private $like_nonce_loaded = false;
|
20 |
+
|
21 |
+
/**
|
22 |
+
* RTMediaLike constructor.
|
23 |
+
*/
|
24 |
+
public function __construct() {
|
25 |
+
|
26 |
$args = array(
|
27 |
+
'action' => 'like',
|
28 |
+
'person_label' => esc_html__( 'person likes this', 'buddypress-media' ),
|
29 |
+
'person_plural_label' => esc_html__( 'people like this', 'buddypress-media' ),
|
30 |
+
'label' => esc_html__( 'Like', 'buddypress-media' ),
|
31 |
+
'plural' => esc_html__( 'Likes', 'buddypress-media' ),
|
32 |
+
'undo_label' => esc_html__( 'Unlike', 'buddypress-media' ),
|
33 |
+
'privacy' => 20,
|
34 |
+
'countable' => true,
|
35 |
+
'single' => false,
|
36 |
+
'repeatable' => false,
|
37 |
+
'undoable' => true,
|
38 |
);
|
39 |
+
|
40 |
parent::__construct( $args );
|
41 |
+
|
42 |
remove_filter( 'rtmedia_action_buttons_before_delete', array( $this, 'button_filter' ) );
|
43 |
add_action( 'rtmedia_action_buttons_after_media', array( $this, 'button_filter' ), 12 );
|
44 |
add_action( 'rtmedia_actions_before_comments', array( $this, 'like_button_filter' ), 10 );
|
45 |
add_action( 'like_button_no_comments', array( $this, 'like_button_no_comments_callback' ), 10 );
|
46 |
add_action( 'rtmedia_like_button_filter', array( $this, 'like_button_filter_nonce' ), 10, 1 );
|
47 |
+
|
48 |
if ( ! rtmedia_comments_enabled() ) {
|
49 |
add_action( 'rtmedia_actions_without_lightbox', array( $this, 'like_button_without_lightbox_filter' ) );
|
50 |
}
|
52 |
add_filter( 'rtmedia_check_enable_disable_like', array( $this, 'rtmedia_check_enable_disable_like' ), 10, 1 );
|
53 |
}
|
54 |
|
|
|
55 |
/**
|
56 |
+
* Check Likes for media is enabled or not
|
57 |
+
*
|
58 |
* @global type $rtmedia
|
59 |
+
*
|
60 |
+
* @param bool $enable_like Enable like or not.
|
61 |
+
*
|
62 |
* @return boolean True if Likes for media is enabled else returns false
|
63 |
*/
|
64 |
+
public function rtmedia_check_enable_disable_like( $enable_like ) {
|
65 |
global $rtmedia;
|
66 |
$options = $rtmedia->options;
|
67 |
+
|
68 |
+
if ( ( isset( $options['general_enableLikes'] ) && 1 === intval( $options['general_enableLikes'] ) ) || ! isset( $options['general_enableLikes'] ) ) {
|
69 |
return true;
|
70 |
} else {
|
71 |
return false;
|
72 |
}
|
73 |
}
|
74 |
|
75 |
+
/**
|
76 |
+
* Add like button.
|
77 |
+
*/
|
78 |
+
public function like_button_filter() {
|
79 |
if ( empty( $this->media ) ) {
|
80 |
$this->init();
|
81 |
}
|
82 |
$button = $this->render();
|
83 |
|
84 |
if ( $button ) {
|
85 |
+
echo '<span>' . wp_kses( $button, RTMedia::expanded_allowed_tags() ) . '</span>';
|
86 |
}
|
87 |
}
|
88 |
|
90 |
* This function displays the like button even if comment
|
91 |
* section is disabled.
|
92 |
*/
|
93 |
+
public function like_button_no_comments_callback() {
|
94 |
+
|
95 |
if ( empty( $this->media ) ) {
|
96 |
$this->init();
|
97 |
}
|
98 |
+
|
99 |
$button = $this->render();
|
100 |
|
101 |
if ( $button ) {
|
102 |
+
echo '<span>' . wp_kses( $button, RTMedia::expanded_allowed_tags() ) . '</span>';
|
103 |
}
|
104 |
}
|
105 |
|
106 |
+
/**
|
107 |
+
* Render like button.
|
108 |
+
*/
|
109 |
+
public function like_button_without_lightbox_filter() {
|
110 |
+
|
111 |
if ( empty( $this->media ) ) {
|
112 |
$this->init();
|
113 |
}
|
114 |
+
|
115 |
$button = $this->render();
|
116 |
+
|
117 |
if ( $button ) {
|
118 |
+
echo wp_kses( $button, RTMedia::expanded_allowed_tags() );
|
119 |
}
|
120 |
}
|
121 |
|
122 |
+
/**
|
123 |
+
* Process media like.
|
124 |
+
*
|
125 |
+
* @return int
|
126 |
+
*/
|
127 |
+
public function process() {
|
128 |
+
|
129 |
$actions = $this->model->get( array( 'id' => $this->action_query->id ) );
|
130 |
+
$like_nonce = sanitize_text_field( filter_input( INPUT_POST, 'like_nonce', FILTER_SANITIZE_STRING ) );
|
131 |
+
|
132 |
if ( ! wp_verify_nonce( $like_nonce, 'rtm_media_like_nonce' . $this->media->id ) ) {
|
133 |
die();
|
134 |
}
|
135 |
+
|
136 |
$rtmediainteraction = new RTMediaInteractionModel();
|
137 |
$user_id = $this->interactor;
|
138 |
$media_id = $this->action_query->id;
|
139 |
$action = $this->action;
|
140 |
$check_action = $rtmediainteraction->check( $user_id, $media_id, $action );
|
141 |
+
|
142 |
if ( $check_action ) {
|
143 |
+
|
144 |
$results = $rtmediainteraction->get_row( $user_id, $media_id, $action );
|
145 |
$row = $results[0];
|
146 |
$curr_value = $row->value;
|
147 |
+
|
148 |
if ( 1 === intval( $curr_value ) ) {
|
149 |
$value = '0';
|
150 |
$this->increase = false;
|
152 |
$value = '1';
|
153 |
$this->increase = true;
|
154 |
}
|
155 |
+
|
156 |
$update_data = array( 'value' => $value );
|
157 |
$where_columns = array(
|
158 |
'user_id' => $user_id,
|
160 |
'action' => $action,
|
161 |
);
|
162 |
$update = $rtmediainteraction->update( $update_data, $where_columns );
|
163 |
+
|
164 |
} else {
|
165 |
+
|
166 |
$value = '1';
|
167 |
$columns = array(
|
168 |
'user_id' => $user_id,
|
172 |
);
|
173 |
$insert_id = $rtmediainteraction->insert( $columns );
|
174 |
$this->increase = true;
|
175 |
+
|
176 |
}
|
177 |
|
178 |
$actionwa = $this->action . 's';
|
191 |
}
|
192 |
|
193 |
$like_html = '<span class="rtmedia-like-counter"></span>';
|
194 |
+
if ( $actions > 0 && function_exists( 'rtmedia_who_like_html' ) ) {
|
195 |
$like_html = rtmedia_who_like_html( $actions, $this->increase );
|
196 |
}
|
197 |
|
198 |
+
// label for "person/people like this" in media popup".
|
199 |
if ( 1 === $actions ) {
|
200 |
$return['person_text'] = apply_filters( 'rtmedia_' . $this->action . '_person_label_text', $like_html );
|
201 |
} else {
|
208 |
|
209 |
$return['count'] = $actions;
|
210 |
$this->model->update( array( 'likes' => $actions ), array( 'id' => $this->action_query->id ) );
|
211 |
+
|
212 |
global $rtmedia_points_media_id;
|
213 |
$rtmedia_points_media_id = $this->action_query->id;
|
214 |
do_action( 'rtmedia_after_like_media', $this );
|
215 |
+
|
216 |
+
$is_json = sanitize_text_field( filter_input( INPUT_POST, 'json', FILTER_SANITIZE_STRING ) );
|
217 |
|
218 |
if ( ! empty( $is_json ) && 'true' === $is_json ) {
|
219 |
wp_send_json( $return );
|
226 |
return $actions;
|
227 |
}
|
228 |
|
229 |
+
/**
|
230 |
+
* Show like button.
|
231 |
+
*
|
232 |
+
* @param array $buttons Buttons to show.
|
233 |
+
*
|
234 |
+
* @return array|void
|
235 |
+
*/
|
236 |
+
public function button_filter( $buttons ) {
|
237 |
|
238 |
if ( empty( $this->media ) ) {
|
239 |
$this->init();
|
240 |
}
|
241 |
+
|
242 |
$button = $this->render();
|
243 |
|
244 |
if ( $button ) {
|
245 |
+
echo wp_kses( $button, RTMedia::expanded_allowed_tags() );
|
246 |
}
|
247 |
}
|
248 |
|
249 |
+
/**
|
250 |
+
* Check if user has liked media.
|
251 |
+
*
|
252 |
+
* @param bool|int $media_id Media id.
|
253 |
+
* @param bool|int $user_id User id.
|
254 |
+
*
|
255 |
+
* @return bool
|
256 |
+
*/
|
257 |
+
public function is_like_migrated( $media_id = false, $user_id = false ) {
|
258 |
$rtmediainteraction = new RTMediaInteractionModel();
|
259 |
+
|
260 |
if ( ! $user_id ) {
|
261 |
$user_id = $this->interactor;
|
262 |
}
|
263 |
+
|
264 |
if ( ! $media_id ) {
|
265 |
$media_id = $this->action_query->id;
|
266 |
}
|
267 |
+
|
268 |
$action = $this->action;
|
269 |
|
270 |
return $rtmediainteraction->check( $user_id, $media_id, $action );
|
271 |
}
|
272 |
|
273 |
+
/**
|
274 |
+
* Get media likes value.
|
275 |
+
*
|
276 |
+
* @param bool|int $media_id Media id.
|
277 |
+
* @param bool|int $user_id User id.
|
278 |
+
*
|
279 |
+
* @return bool
|
280 |
+
*/
|
281 |
+
public function get_like_value( $media_id = false, $user_id = false ) {
|
282 |
+
|
283 |
$rtmediainteraction = new RTMediaInteractionModel();
|
284 |
+
|
285 |
if ( ! $user_id ) {
|
286 |
$user_id = $this->interactor;
|
287 |
}
|
288 |
+
|
289 |
if ( ! $media_id ) {
|
290 |
$media_id = $this->action_query->id;
|
291 |
}
|
292 |
+
|
293 |
$action = $this->action;
|
294 |
$results = $rtmediainteraction->get_row( $user_id, $media_id, $action );
|
295 |
$row = $results[0];
|
296 |
+
|
297 |
if ( 1 === intval( $row->value ) ) {
|
298 |
$this->increase = false;
|
299 |
|
305 |
}
|
306 |
}
|
307 |
|
308 |
+
/**
|
309 |
+
* Migrate liked media.
|
310 |
+
*
|
311 |
+
* @param int $like_media media id.
|
312 |
+
*
|
313 |
+
* @return int
|
314 |
+
*/
|
315 |
+
public function migrate_likes( $like_media ) {
|
316 |
$rtmediainteraction = new RTMediaInteractionModel();
|
317 |
$user_id = $this->interactor;
|
318 |
$media_id = $this->action_query->id;
|
326 |
);
|
327 |
$insert_id = $rtmediainteraction->insert( $columns );
|
328 |
$like_media = trim( str_replace( ',' . $this->action_query->id . ',', ',', ',' . $like_media . ',' ), ',' );
|
329 |
+
// todo user attribute.
|
330 |
update_user_meta( $this->interactor, 'rtmedia_liked_media', $like_media );
|
331 |
|
332 |
return $insert_id;
|
333 |
}
|
334 |
|
335 |
+
/**
|
336 |
+
* Check if media is liked by user.
|
337 |
+
*
|
338 |
+
* @param bool|int $media_id Media id.
|
339 |
+
* @param bool|int $interactor Interactor/user id.
|
340 |
+
*
|
341 |
+
* @return bool
|
342 |
+
*/
|
343 |
+
public function is_liked( $media_id = false, $interactor = false ) {
|
344 |
+
|
345 |
if ( ! $interactor ) {
|
346 |
$interactor = $this->interactor;
|
347 |
}
|
348 |
+
|
349 |
if ( ! $media_id ) {
|
350 |
$media_id = $this->action_query->id;
|
351 |
}
|
352 |
+
|
353 |
+
// todo user attribute.
|
354 |
$like_media = get_user_meta( $interactor, 'rtmedia_liked_media', true );
|
355 |
if ( $this->is_like_migrated( $media_id, $interactor ) ) {
|
356 |
return $this->get_like_value( $media_id, $interactor );
|
357 |
} else {
|
358 |
+
|
359 |
if ( strpos( ',' . $like_media . ',', ',' . $media_id . ',' ) === false ) {
|
360 |
$this->increase = true;
|
361 |
|
369 |
}
|
370 |
}
|
371 |
|
372 |
+
/**
|
373 |
+
* Code to execute before rendering like button.
|
374 |
+
*
|
375 |
+
* @return bool|void
|
376 |
+
*/
|
377 |
+
public function before_render() {
|
378 |
+
|
379 |
$enable_like = true;
|
380 |
$enable_like = apply_filters( 'rtmedia_check_enable_disable_like', $enable_like );
|
381 |
|
|
|
|
|
382 |
if ( ! $enable_like ) {
|
383 |
return false;
|
384 |
}
|
388 |
}
|
389 |
}
|
390 |
|
391 |
+
/**
|
392 |
+
* Add nonce in like button.
|
393 |
+
*
|
394 |
+
* @param string $button Button html.
|
395 |
+
*
|
396 |
+
* @return string
|
397 |
+
*/
|
398 |
+
public function like_button_filter_nonce( $button ) {
|
399 |
+
// We create only 1 nonce field for like button.
|
400 |
+
if ( empty( $this->like_nonce_loaded ) ) {
|
401 |
+
$button .= wp_nonce_field( 'rtm_media_like_nonce' . $this->media->id, 'rtm_media_like_nonce', true, false );
|
402 |
+
|
403 |
+
$this->like_nonce_loaded = true;
|
404 |
+
}
|
405 |
+
|
406 |
return $button;
|
407 |
}
|
408 |
}
|
app/main/controllers/media/RTMediaLoginPopup.php
CHANGED
@@ -1,50 +1,61 @@
|
|
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 |
-
*
|
11 |
*
|
|
|
12 |
* @author sanket
|
13 |
*/
|
|
|
|
|
|
|
|
|
14 |
class RTMediaLoginPopup {
|
15 |
|
16 |
-
|
|
|
|
|
|
|
17 |
add_action( 'rtmedia_album_gallery_actions', array( $this, 'rtmedia_add_upload_album_button_popup' ), 99 );
|
18 |
add_action( 'rtmedia_media_gallery_actions', array( $this, 'rtmedia_add_upload_album_button_popup' ), 99 );
|
19 |
add_action( 'rtmedia_before_media_gallery', array( $this, 'rtmedia_login_register_modal_popup' ) );
|
20 |
add_action( 'rtmedia_before_album_gallery', array( $this, 'rtmedia_login_register_modal_popup' ) );
|
21 |
-
// remove rtMedia Pro actions
|
22 |
add_action( 'rtmedia_before_media_gallery', array( $this, 'remove_rtmedia_media_pro_hooks' ) );
|
23 |
add_action( 'rtmedia_before_album_gallery', array( $this, 'remove_rtmedia_album_pro_hooks' ) );
|
24 |
}
|
25 |
|
26 |
-
|
|
|
|
|
|
|
27 |
remove_action( 'rtmedia_media_gallery_actions', 'rtmedia_add_upload_album_button', 99 );
|
28 |
remove_action( 'rtmedia_before_media_gallery', 'rtmedia_login_register_modal' );
|
29 |
}
|
30 |
|
31 |
-
|
|
|
|
|
|
|
32 |
remove_action( 'rtmedia_album_gallery_actions', 'rtmedia_add_upload_album_button', 99 );
|
33 |
remove_action( 'rtmedia_before_album_gallery', 'rtmedia_login_register_modal' );
|
34 |
}
|
35 |
|
36 |
-
|
|
|
|
|
|
|
37 |
if ( ! is_user_logged_in() ) {
|
38 |
-
echo '<span><a href="#rtmedia-login-register-modal" class="primary rtmedia-upload-media-link rtmedia-modal-link" id="rtmedia-login-register-modal" title="' . apply_filters( 'rtm_album_upload_title_label', __( 'Upload Media', 'buddypress-media' ) ) . '"><i class="dashicons dashicons-upload"></i>' . apply_filters( 'rtm_album_upload_label', __( 'Upload', 'buddypress-media' ) ) . '</a></span>';
|
39 |
}
|
40 |
}
|
41 |
|
42 |
-
|
|
|
|
|
|
|
|
|
43 |
if ( ! is_user_logged_in() ) {
|
44 |
-
$uri = '';
|
45 |
-
if ( isset( $_REQUEST['REQUEST_URI'] ) ) {
|
46 |
-
$uri = esc_url_raw( wp_unslash( $_REQUEST['REQUEST_URI'] ) );
|
47 |
-
}
|
48 |
?>
|
49 |
<div class="rtmedia-popup mfp-hide rtm-modal" id="rtmedia-login-register-modal">
|
50 |
<div id="rtm-modal-container">
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
+
* Handles rtMedia login popup.
|
4 |
*
|
5 |
+
* @package rtMedia
|
6 |
* @author sanket
|
7 |
*/
|
8 |
+
|
9 |
+
/**
|
10 |
+
* Class to handle login/register popups.
|
11 |
+
*/
|
12 |
class RTMediaLoginPopup {
|
13 |
|
14 |
+
/**
|
15 |
+
* RTMediaLoginPopup constructor.
|
16 |
+
*/
|
17 |
+
public function __construct() {
|
18 |
add_action( 'rtmedia_album_gallery_actions', array( $this, 'rtmedia_add_upload_album_button_popup' ), 99 );
|
19 |
add_action( 'rtmedia_media_gallery_actions', array( $this, 'rtmedia_add_upload_album_button_popup' ), 99 );
|
20 |
add_action( 'rtmedia_before_media_gallery', array( $this, 'rtmedia_login_register_modal_popup' ) );
|
21 |
add_action( 'rtmedia_before_album_gallery', array( $this, 'rtmedia_login_register_modal_popup' ) );
|
22 |
+
// remove rtMedia Pro actions.
|
23 |
add_action( 'rtmedia_before_media_gallery', array( $this, 'remove_rtmedia_media_pro_hooks' ) );
|
24 |
add_action( 'rtmedia_before_album_gallery', array( $this, 'remove_rtmedia_album_pro_hooks' ) );
|
25 |
}
|
26 |
|
27 |
+
/**
|
28 |
+
* Remove rtmedia pro hooks.
|
29 |
+
*/
|
30 |
+
public function remove_rtmedia_media_pro_hooks() {
|
31 |
remove_action( 'rtmedia_media_gallery_actions', 'rtmedia_add_upload_album_button', 99 );
|
32 |
remove_action( 'rtmedia_before_media_gallery', 'rtmedia_login_register_modal' );
|
33 |
}
|
34 |
|
35 |
+
/**
|
36 |
+
* Remove rtmedia pro album hooks.
|
37 |
+
*/
|
38 |
+
public function remove_rtmedia_album_pro_hooks() {
|
39 |
remove_action( 'rtmedia_album_gallery_actions', 'rtmedia_add_upload_album_button', 99 );
|
40 |
remove_action( 'rtmedia_before_album_gallery', 'rtmedia_login_register_modal' );
|
41 |
}
|
42 |
|
43 |
+
/**
|
44 |
+
* Upload album button popup.
|
45 |
+
*/
|
46 |
+
public function rtmedia_add_upload_album_button_popup() {
|
47 |
if ( ! is_user_logged_in() ) {
|
48 |
+
echo '<span><a href="#rtmedia-login-register-modal" class="primary rtmedia-upload-media-link rtmedia-modal-link" id="rtmedia-login-register-modal" title="' . esc_attr( apply_filters( 'rtm_album_upload_title_label', __( 'Upload Media', 'buddypress-media' ) ) ) . '"><i class="dashicons dashicons-upload"></i>' . esc_html( apply_filters( 'rtm_album_upload_label', __( 'Upload', 'buddypress-media' ) ) ) . '</a></span>';
|
49 |
}
|
50 |
}
|
51 |
|
52 |
+
/**
|
53 |
+
* Login/register popup display.
|
54 |
+
*/
|
55 |
+
public function rtmedia_login_register_modal_popup() {
|
56 |
+
|
57 |
if ( ! is_user_logged_in() ) {
|
58 |
+
$uri = rtm_get_server_var( 'REQUEST_URI', 'FILTER_SANITIZE_URL' );
|
|
|
|
|
|
|
59 |
?>
|
60 |
<div class="rtmedia-popup mfp-hide rtm-modal" id="rtmedia-login-register-modal">
|
61 |
<div id="rtm-modal-container">
|
app/main/controllers/media/RTMediaMedia.php
CHANGED
@@ -1,18 +1,22 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
/*
|
4 |
-
* To change this template, choose Tools | Templates
|
5 |
-
* and open the template in the editor.
|
6 |
-
*/
|
7 |
-
|
8 |
/**
|
9 |
-
*
|
10 |
*
|
|
|
11 |
* @author Udit Desai <udit.desai@rtcamp.com>
|
12 |
*/
|
|
|
|
|
|
|
|
|
13 |
class RTMediaMedia {
|
14 |
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
16 |
'id',
|
17 |
'blog_id',
|
18 |
'media_id',
|
@@ -41,24 +45,24 @@ class RTMediaMedia {
|
|
41 |
*
|
42 |
* @var object the database model
|
43 |
*/
|
44 |
-
|
45 |
|
46 |
/**
|
47 |
-
* Initialises the model object of the
|
48 |
*/
|
49 |
public function __construct() {
|
50 |
-
|
51 |
$this->model = new RTMediaModel();
|
52 |
}
|
53 |
|
54 |
/**
|
55 |
* Generate nonce
|
56 |
*
|
57 |
-
* @param
|
|
|
58 |
*
|
59 |
* @return string json encoded nonce
|
60 |
*/
|
61 |
-
static function media_nonce_generator( $id, $echo = true ) {
|
62 |
if ( $echo ) {
|
63 |
wp_nonce_field( 'rtmedia_' . $id, 'rtmedia_media_nonce' );
|
64 |
} else {
|
@@ -75,18 +79,17 @@ class RTMediaMedia {
|
|
75 |
* Method verifies the nonce passed while performing any CRUD operations
|
76 |
* on the media.
|
77 |
*
|
78 |
-
* @param string $mode The upload mode
|
79 |
*
|
80 |
* @return boolean whether the nonce is valid
|
81 |
*/
|
82 |
-
function verify_nonce( $mode ) {
|
83 |
|
84 |
-
$nonce = $mode
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
$mode = sanitize_text_field( wp_unslash( $_REQUEST['mode'] ) );
|
90 |
}
|
91 |
|
92 |
if ( wp_verify_nonce( $nonce, 'rtmedia_' . $mode ) ) {
|
@@ -108,10 +111,10 @@ class RTMediaMedia {
|
|
108 |
/**
|
109 |
* Adds taxonomy
|
110 |
*
|
111 |
-
* @param array $attachments ids of the attachments created after upload
|
112 |
-
* @param array $taxonomies array of terms indexed by a taxonomy
|
113 |
*/
|
114 |
-
function add_taxonomy( $attachments, $taxonomies ) {
|
115 |
|
116 |
foreach ( $attachments as $id ) {
|
117 |
|
@@ -126,13 +129,14 @@ class RTMediaMedia {
|
|
126 |
}
|
127 |
|
128 |
/**
|
|
|
129 |
*
|
130 |
-
* @param array $attachments attachment ids
|
131 |
-
* @param array $custom_fields array of key value pairs of meta
|
132 |
*
|
133 |
* @return boolean success of meta
|
134 |
*/
|
135 |
-
function add_meta( $attachments, $custom_fields ) {
|
136 |
|
137 |
foreach ( $attachments as $id ) {
|
138 |
$row = array( 'media_id' => $id );
|
@@ -160,42 +164,43 @@ class RTMediaMedia {
|
|
160 |
*
|
161 |
* @return boolean
|
162 |
*/
|
163 |
-
function is_multisite() {
|
164 |
return is_multisite();
|
165 |
}
|
166 |
|
167 |
/**
|
168 |
* Generic method to add a media
|
169 |
*
|
170 |
-
* @param
|
171 |
-
* @param
|
172 |
*
|
173 |
-
* @return
|
|
|
174 |
*/
|
175 |
-
function add( $uploaded, $file_object ) {
|
176 |
|
177 |
-
|
178 |
do_action( 'rtmedia_before_add_media', $file_object, $uploaded );
|
179 |
|
180 |
-
|
181 |
$attachments = $this->generate_post_array( $uploaded, $file_object );
|
182 |
|
183 |
-
|
184 |
$attachment_ids = $this->insert_attachment( $attachments, $file_object );
|
185 |
|
186 |
-
|
187 |
if ( ! $this->is_multisite() ) {
|
188 |
$this->add_taxonomy( $attachment_ids, $uploaded['taxonomy'] );
|
189 |
}
|
190 |
|
191 |
-
|
192 |
$this->add_meta( $attachment_ids, $uploaded['custom_fields'] );
|
193 |
|
194 |
-
|
195 |
-
$media_ids = $this->insertmedia( $attachment_ids, $uploaded, $file_object
|
196 |
|
197 |
$rtmedia_type = rtmedia_type( $media_ids );
|
198 |
-
|
199 |
global $rtmedia_points_media_id;
|
200 |
if ( $media_ids && is_array( $media_ids ) && isset( $media_ids[0] ) ) {
|
201 |
$rtmedia_points_media_id = $media_ids[0];
|
@@ -211,15 +216,15 @@ class RTMediaMedia {
|
|
211 |
/**
|
212 |
* Generic method to update a media. media details can be changed from this method
|
213 |
*
|
214 |
-
* @param $id
|
215 |
-
* @param $data
|
216 |
-
* @param int
|
217 |
*
|
218 |
* @return bool
|
219 |
*/
|
220 |
-
function update( $id, $data, $media_id ) {
|
221 |
|
222 |
-
|
223 |
do_action( 'rtmedia_before_update_media', $id );
|
224 |
|
225 |
$defaults = array();
|
@@ -228,13 +233,14 @@ class RTMediaMedia {
|
|
228 |
|
229 |
if ( array_key_exists( 'media_title', $data ) || array_key_exists( 'description', $data ) ) {
|
230 |
$post_data['ID'] = $media_id;
|
|
|
231 |
if ( isset( $data['media_title'] ) ) {
|
232 |
$data['media_title'] = wp_kses( $data['media_title'], wp_kses_allowed_html() );
|
233 |
$post_data['post_title'] = $data['media_title'];
|
234 |
$post_data['post_name'] = $data['media_title'];
|
235 |
}
|
236 |
if ( isset( $data['description'] ) ) {
|
237 |
-
// filter post_content for allowed html tags
|
238 |
$post_data['post_content'] = wp_kses( $data['description'], wp_kses_allowed_html() );
|
239 |
unset( $data['description'] );
|
240 |
}
|
@@ -243,18 +249,18 @@ class RTMediaMedia {
|
|
243 |
|
244 |
$status = $this->model->update( $data, $where );
|
245 |
|
246 |
-
// insert/update activity details in rtmedia activity table
|
247 |
$media_model = new RTMediaModel();
|
248 |
$media = $media_model->get( array( 'id' => $id ) );
|
249 |
|
250 |
if ( ! empty( $media ) ) {
|
251 |
-
$media_ids_of_activity
|
252 |
$rtmedia_activity_model = new RTMediaActivityModel();
|
253 |
$similar_media = $media_model->get( array( 'activity_id' => $media[0]->activity_id ) );
|
254 |
$max_privacy = 0;
|
255 |
|
256 |
foreach ( $similar_media as $s_media ) {
|
257 |
-
|
258 |
$media_ids_of_activity[] = $s_media->id;
|
259 |
|
260 |
if ( $s_media->privacy > $max_privacy ) {
|
@@ -263,24 +269,29 @@ class RTMediaMedia {
|
|
263 |
}
|
264 |
|
265 |
if ( ! $rtmedia_activity_model->check( $media[0]->activity_id ) ) {
|
266 |
-
$rtmedia_activity_model->insert(
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
|
|
|
|
271 |
} else {
|
272 |
-
$rtmedia_activity_model->update(
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
|
|
|
|
|
|
277 |
}
|
278 |
|
279 |
-
|
280 |
$rtmedia_activity_model->profile_activity_update( $media_ids_of_activity, $max_privacy, $media[0]->activity_id );
|
281 |
}
|
282 |
|
283 |
-
|
284 |
do_action( 'rtmedia_after_update_media', $id );
|
285 |
|
286 |
if ( false === $status ) {
|
@@ -291,13 +302,11 @@ class RTMediaMedia {
|
|
291 |
}
|
292 |
|
293 |
/**
|
294 |
-
* Generic method to delete a media from
|
295 |
-
*
|
296 |
-
* @param int $id
|
297 |
*
|
298 |
-
* @
|
299 |
*/
|
300 |
-
function delete_wordpress_attachment( $id ) {
|
301 |
$media = $this->model->get( array( 'media_id' => $id ), false, false );
|
302 |
|
303 |
if ( $media ) {
|
@@ -308,16 +317,16 @@ class RTMediaMedia {
|
|
308 |
/**
|
309 |
* Method to reassign media to another user while deleting user
|
310 |
*
|
311 |
-
* @param int $user_id
|
312 |
-
*
|
313 |
*/
|
314 |
public function reassign_wordpress_user( $user_id, $reassign ) {
|
315 |
if ( null !== $reassign || '' !== $reassign ) {
|
316 |
-
// Updating media author
|
317 |
$rtmedia_model = new RTMediaModel();
|
318 |
$rtmedia_model->update( array( 'media_author' => $reassign ), array( 'media_author' => $user_id ) );
|
319 |
|
320 |
-
// Updating user id from interaction
|
321 |
$rtmediainteraction = new RTMediaInteractionModel();
|
322 |
$rtmediainteraction->update( array( 'user_id' => $reassign ), array( 'user_id' => $user_id ) );
|
323 |
}
|
@@ -326,14 +335,13 @@ class RTMediaMedia {
|
|
326 |
/**
|
327 |
* Generic method to delete a media
|
328 |
*
|
329 |
-
* @param int
|
330 |
-
* @param bool $core
|
331 |
-
* @param bool $delete_activity
|
332 |
*
|
333 |
* @return bool
|
334 |
-
*
|
335 |
*/
|
336 |
-
function delete( $id, $core = false, $delete_activity = true ) {
|
337 |
do_action( 'rtmedia_before_delete_media', $id );
|
338 |
|
339 |
$media = $this->model->get( array( 'id' => $id ), false, false );
|
@@ -342,109 +350,124 @@ class RTMediaMedia {
|
|
342 |
|
343 |
if ( $media ) {
|
344 |
|
345 |
-
// delete the child media of the media where the media context type is ( post, comment, reply )
|
346 |
-
$
|
347 |
-
|
348 |
-
|
|
|
349 |
$has_comment_media = get_rtmedia_meta( $media[0]->id, 'has_comment_media' );
|
|
|
350 |
if ( is_array( $has_comment_media ) ) {
|
|
|
351 |
foreach ( $has_comment_media as $value ) {
|
352 |
-
// first delete the child media
|
353 |
$delete = $this->delete( $value );
|
354 |
}
|
355 |
}
|
356 |
}
|
357 |
|
358 |
-
|
359 |
-
|
|
|
|
|
360 |
$rtmedia_media_used = get_rtmedia_meta( $media[0]->id, 'rtmedia_media_used' );
|
361 |
-
if( isset( $rtmedia_media_used[
|
362 |
$template = new RTMediaTemplate();
|
363 |
-
$template->rtmedia_delete_comment_and_activity( $rtmedia_media_used[
|
364 |
}
|
365 |
}
|
366 |
|
367 |
-
|
368 |
if ( $delete_activity ) {
|
|
|
369 |
if ( $media[0]->activity_id && function_exists( 'bp_activity_delete_by_activity_id' ) ) {
|
|
|
370 |
$related_media = $this->model->get( array( 'activity_id' => $media[0]->activity_id ), false, false );
|
|
|
371 |
if ( count( $related_media ) > 1 ) {
|
372 |
$activity_media = array();
|
|
|
373 |
foreach ( $related_media as $temp_media ) {
|
374 |
if ( $temp_media->id === $id ) {
|
375 |
continue;
|
376 |
}
|
377 |
$activity_media[] = $temp_media->id;
|
378 |
}
|
|
|
379 |
$obj_activity = new RTMediaActivity( $activity_media );
|
380 |
global $wpdb, $bp;
|
381 |
-
$wpdb->update(
|
382 |
-
|
383 |
-
|
384 |
-
|
|
|
|
|
|
|
|
|
385 |
} else {
|
386 |
if ( isset( $media[0] ) && isset( $media[0]->activity_id ) ) {
|
387 |
bp_activity_delete_by_activity_id( $media[0]->activity_id );
|
388 |
}
|
389 |
}
|
390 |
|
391 |
-
// Deleting like and comment activity for media
|
392 |
if ( function_exists( 'bp_activity_delete' ) ) {
|
393 |
-
|
394 |
-
if( isset( $media[0]->context ) && ( 'group'
|
395 |
|
396 |
-
|
397 |
bp_activity_delete(
|
398 |
array(
|
399 |
-
'component '
|
400 |
-
'type '
|
401 |
-
'item_id'
|
402 |
-
'secondary_item_id' => $media[0]->id
|
403 |
)
|
404 |
);
|
405 |
|
406 |
-
|
407 |
$comments = rtmedia_get_comments_details_for_media_id( $media[0]->media_id );
|
408 |
|
409 |
$delete_ca = false;
|
410 |
-
if( is_array( $comments ) && ! empty( $comments ) ){
|
411 |
-
foreach ($comments as $comment) {
|
412 |
$comment_id = $comment->comment_ID;
|
413 |
-
$user_id
|
414 |
-
$meta_key
|
415 |
|
416 |
// Delete activity when user remove his comment.
|
417 |
-
//todo user_attribute
|
418 |
$activity_id = get_user_meta( $user_id, $meta_key, true );
|
419 |
|
420 |
-
|
421 |
$delete_ca = bp_activity_delete(
|
422 |
array(
|
423 |
-
'component ' => 'groups'
|
424 |
-
'type '
|
425 |
-
'id'
|
426 |
)
|
427 |
);
|
428 |
|
429 |
-
if( $delete_ca ){
|
430 |
delete_user_meta( $user_id, $meta_key );
|
431 |
}
|
432 |
}
|
433 |
}
|
434 |
-
|
435 |
-
|
436 |
-
/* any other context type */
|
437 |
bp_activity_delete( array( 'item_id' => $media[0]->id ) );
|
438 |
}
|
439 |
}
|
440 |
}
|
441 |
}
|
|
|
442 |
if ( ! $core && ! is_admin() ) {
|
443 |
wp_delete_attachment( $media[0]->media_id, true );
|
444 |
}
|
|
|
445 |
$status = $this->model->delete( array( 'id' => $id ) );
|
446 |
|
447 |
-
//delete media meta (view) from wp_rt_rtm_media_meta
|
448 |
$delete_rtmedia_views = delete_rtmedia_meta( $id, 'view' );
|
449 |
|
450 |
if ( 0 !== $status && ( 'album' === $media[0]->media_type || 'playlist' === $media[0]->media_type ) ) {
|
@@ -452,15 +475,21 @@ class RTMediaMedia {
|
|
452 |
}
|
453 |
$rtmedia_nav = new RTMediaNav();
|
454 |
if ( 'group' === $media[0]->context ) {
|
455 |
-
$rtmedia_nav->refresh_counts(
|
456 |
-
|
457 |
-
|
458 |
-
|
|
|
|
|
|
|
459 |
} else {
|
460 |
-
$rtmedia_nav->refresh_counts(
|
461 |
-
|
462 |
-
|
463 |
-
|
|
|
|
|
|
|
464 |
}
|
465 |
}
|
466 |
|
@@ -480,22 +509,22 @@ class RTMediaMedia {
|
|
480 |
*
|
481 |
* @global type $wpdb
|
482 |
*
|
483 |
-
* @param
|
484 |
-
* @param
|
485 |
*
|
486 |
* @return boolean
|
487 |
*/
|
488 |
-
function move( $media_id, $album_id ) {
|
489 |
|
490 |
global $wpdb;
|
491 |
-
|
492 |
$status = $wpdb->update( $wpdb->posts, array( 'post_parent' => $album_id ), array( 'ID' => $media_id ) );
|
493 |
|
494 |
if ( is_wp_error( $status ) || 0 === $status ) {
|
495 |
return false;
|
496 |
} else {
|
497 |
$id = rtmedia_id( $media_id );
|
498 |
-
|
499 |
$album_data = $this->model->get( array( 'media_id' => $media_id ) );
|
500 |
$data = array(
|
501 |
'album_id' => $album_id,
|
@@ -511,7 +540,7 @@ class RTMediaMedia {
|
|
511 |
/**
|
512 |
* Imports attachment as media
|
513 |
*/
|
514 |
-
function import_attachment() {
|
515 |
|
516 |
}
|
517 |
|
@@ -520,7 +549,7 @@ class RTMediaMedia {
|
|
520 |
*
|
521 |
* @return boolean
|
522 |
*/
|
523 |
-
function activity_enabled() {
|
524 |
|
525 |
if ( ! function_exists( 'bp_is_active' ) || ! bp_is_active( 'activity' ) ) {
|
526 |
return false;
|
@@ -532,16 +561,20 @@ class RTMediaMedia {
|
|
532 |
}
|
533 |
|
534 |
/**
|
|
|
535 |
*
|
536 |
-
* @param
|
537 |
-
* @param
|
538 |
*
|
539 |
-
* @return
|
540 |
*/
|
541 |
-
function generate_post_array( $uploaded, $file_object ) {
|
|
|
542 |
if ( $uploaded['album_id'] ) {
|
|
|
543 |
$model = new RTMediaModel();
|
544 |
$parent_details = $model->get( array( 'id' => $uploaded['album_id'] ) );
|
|
|
545 |
if ( is_array( $parent_details ) && count( $parent_details ) > 0 ) {
|
546 |
$album_id = $parent_details[0]->media_id;
|
547 |
} else {
|
@@ -558,8 +591,9 @@ class RTMediaMedia {
|
|
558 |
$attachments = array();
|
559 |
|
560 |
foreach ( $file_object as $index => $file ) {
|
561 |
-
|
562 |
-
|
|
|
563 |
$uploaded['description'] = wp_kses( $uploaded['description'], wp_kses_allowed_html() );
|
564 |
$attachments[ $index ] = array(
|
565 |
'post_mime_type' => $file['type'],
|
@@ -579,36 +613,43 @@ class RTMediaMedia {
|
|
579 |
}
|
580 |
|
581 |
/**
|
|
|
582 |
*
|
583 |
-
* @param
|
584 |
-
* @param
|
585 |
*
|
586 |
* @return array $updated_attachment_ids
|
587 |
-
* @throws Exception
|
588 |
*/
|
589 |
-
function insert_attachment( $attachments, $file_object ) {
|
|
|
590 |
$updated_attachment_ids = array();
|
591 |
foreach ( $attachments as $key => $attachment ) {
|
|
|
592 |
$attachment_id = wp_insert_attachment( $attachment, $file_object[ $key ]['file'], $attachment['post_parent'] );
|
|
|
593 |
if ( ! is_wp_error( $attachment_id ) ) {
|
|
|
594 |
add_filter( 'intermediate_image_sizes', array( $this, 'image_sizes' ), 99 );
|
595 |
/**
|
596 |
-
* FIX
|
597 |
-
*/
|
598 |
-
require_once( ABSPATH . 'wp-admin/includes/media.php' );
|
599 |
-
/**
|
600 |
-
*
|
601 |
*/
|
|
|
602 |
wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $file_object[ $key ]['file'] ) );
|
|
|
603 |
} else {
|
|
|
604 |
$file = $file_object[ $key ]['file'];
|
605 |
-
|
|
|
606 |
wp_delete_file( $file );
|
607 |
} else {
|
608 |
-
unlink( $file );
|
609 |
}
|
|
|
610 |
throw new Exception( esc_html__( 'Error creating attachment for the media file, please try again', 'buddypress-media' ) );
|
611 |
}
|
|
|
612 |
$updated_attachment_ids[] = $attachment_id;
|
613 |
}
|
614 |
|
@@ -616,12 +657,13 @@ class RTMediaMedia {
|
|
616 |
}
|
617 |
|
618 |
/**
|
|
|
619 |
*
|
620 |
-
* @param
|
621 |
*
|
622 |
-
* @return
|
623 |
*/
|
624 |
-
function image_sizes( $sizes ) {
|
625 |
return array(
|
626 |
'rt_media_thumbnail',
|
627 |
'rt_media_activity_image',
|
@@ -631,43 +673,48 @@ class RTMediaMedia {
|
|
631 |
}
|
632 |
|
633 |
/**
|
|
|
634 |
*
|
635 |
-
* @param
|
636 |
*
|
637 |
* @return int
|
638 |
*/
|
639 |
-
function insert_album( $attributes ) {
|
640 |
|
641 |
return $this->model->insert( $attributes );
|
642 |
}
|
643 |
|
644 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
645 |
switch ( $mime_type ) {
|
646 |
case 'image':
|
647 |
return 'photo';
|
648 |
-
break;
|
649 |
case 'audio':
|
650 |
return 'music';
|
651 |
-
break;
|
652 |
case 'video':
|
653 |
return 'video';
|
654 |
-
break;
|
655 |
default:
|
656 |
return apply_filters( 'rtmedia_set_media_type_filter', $mime_type, $file_object );
|
657 |
-
break;
|
658 |
}
|
659 |
}
|
660 |
|
661 |
/**
|
|
|
662 |
*
|
663 |
-
* @param array $attachment_ids
|
664 |
-
* @param array $uploaded
|
665 |
-
*
|
666 |
-
* @param $file_object
|
667 |
*
|
668 |
* @return array
|
669 |
*/
|
670 |
-
function insertmedia( $attachment_ids, $uploaded, $file_object /* added for file extension */ ) {
|
671 |
|
672 |
$defaults = array(
|
673 |
'activity_id' => $this->activity_enabled(),
|
@@ -688,7 +735,7 @@ class RTMediaMedia {
|
|
688 |
'album_id' => $uploaded['album_id'],
|
689 |
'media_author' => $attachment['post_author'],
|
690 |
'media_title' => $attachment['post_title'],
|
691 |
-
'media_type' => $this->set_media_type( $mime_type[0], $file_object
|
692 |
'context' => $uploaded['context'],
|
693 |
'context_id' => $uploaded['context_id'],
|
694 |
'privacy' => $uploaded['privacy'],
|
@@ -703,7 +750,16 @@ class RTMediaMedia {
|
|
703 |
return $media_id;
|
704 |
}
|
705 |
|
706 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
707 |
if ( ! $this->activity_enabled() ) {
|
708 |
return false;
|
709 |
}
|
@@ -712,7 +768,7 @@ class RTMediaMedia {
|
|
712 |
$activity_content = $activity->create_activity_html();
|
713 |
$user = get_userdata( $media->media_author );
|
714 |
$username = '<a href="' . esc_url( get_rtmedia_user_link( $media->media_author ) ) . '">' . esc_html( $user->display_name ) . '</a>';
|
715 |
-
$count = is_array( $id ) ? count( $id ) : 1
|
716 |
$media_const = 'RTMEDIA_' . strtoupper( $media->media_type );
|
717 |
if ( $count > 1 ) {
|
718 |
$media_const .= '_PLURAL';
|
@@ -722,6 +778,7 @@ class RTMediaMedia {
|
|
722 |
|
723 |
$media_str = constant( $media_const );
|
724 |
|
|
|
725 |
$action = sprintf( ( 1 === $count ) ? esc_html__( '%1$s added a %2$s', 'buddypress-media' ) : esc_html__( '%1$s added %4$d %3$s', 'buddypress-media' ), $username, $media->media_type, $media_str, $count );
|
726 |
$action = apply_filters( 'rtmedia_buddypress_action_text_fitler', $action, $username, $count, $user->display_name, $media->media_type );
|
727 |
$activity_args = array(
|
@@ -752,21 +809,26 @@ class RTMediaMedia {
|
|
752 |
|
753 |
$this->model->update( array( 'activity_id' => $activity_id ), array( 'id' => $media->id ) );
|
754 |
|
755 |
-
// insert/update activity details in rtmedia activity table
|
756 |
$rtmedia_activity_model = new RTMediaActivityModel();
|
757 |
|
758 |
if ( ! $rtmedia_activity_model->check( $activity_id ) ) {
|
759 |
-
$rtmedia_activity_model->insert(
|
760 |
-
|
761 |
-
|
762 |
-
|
763 |
-
|
|
|
|
|
764 |
} else {
|
765 |
-
$rtmedia_activity_model->update(
|
766 |
-
|
767 |
-
|
768 |
-
|
769 |
-
|
|
|
|
|
|
|
770 |
}
|
771 |
|
772 |
return $activity_id;
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
+
* Handles media functionality.
|
4 |
*
|
5 |
+
* @package rtMedia
|
6 |
* @author Udit Desai <udit.desai@rtcamp.com>
|
7 |
*/
|
8 |
+
|
9 |
+
/**
|
10 |
+
* Class to Handle media functionality.
|
11 |
+
*/
|
12 |
class RTMediaMedia {
|
13 |
|
14 |
+
/**
|
15 |
+
* Default media data.
|
16 |
+
*
|
17 |
+
* @var array
|
18 |
+
*/
|
19 |
+
public static $default_object = array(
|
20 |
'id',
|
21 |
'blog_id',
|
22 |
'media_id',
|
45 |
*
|
46 |
* @var object the database model
|
47 |
*/
|
48 |
+
public $model;
|
49 |
|
50 |
/**
|
51 |
+
* Initialises the model object of the media object
|
52 |
*/
|
53 |
public function __construct() {
|
|
|
54 |
$this->model = new RTMediaModel();
|
55 |
}
|
56 |
|
57 |
/**
|
58 |
* Generate nonce
|
59 |
*
|
60 |
+
* @param int $id Media id.
|
61 |
+
* @param boolean $echo whether nonce should be echoed.
|
62 |
*
|
63 |
* @return string json encoded nonce
|
64 |
*/
|
65 |
+
public static function media_nonce_generator( $id, $echo = true ) {
|
66 |
if ( $echo ) {
|
67 |
wp_nonce_field( 'rtmedia_' . $id, 'rtmedia_media_nonce' );
|
68 |
} else {
|
79 |
* Method verifies the nonce passed while performing any CRUD operations
|
80 |
* on the media.
|
81 |
*
|
82 |
+
* @param string $mode The upload mode.
|
83 |
*
|
84 |
* @return boolean whether the nonce is valid
|
85 |
*/
|
86 |
+
public function verify_nonce( $mode ) {
|
87 |
|
88 |
+
$nonce = sanitize_text_field( filter_input( INPUT_POST, "rtmedia_{$mode}_media_nonce", FILTER_SANITIZE_STRING ) );
|
89 |
+
$mode = sanitize_text_field( filter_input( INPUT_POST, 'mode', FILTER_SANITIZE_STRING ) );
|
90 |
+
|
91 |
+
if ( empty( $mode ) ) {
|
92 |
+
$mode = '';
|
|
|
93 |
}
|
94 |
|
95 |
if ( wp_verify_nonce( $nonce, 'rtmedia_' . $mode ) ) {
|
111 |
/**
|
112 |
* Adds taxonomy
|
113 |
*
|
114 |
+
* @param array $attachments ids of the attachments created after upload.
|
115 |
+
* @param array $taxonomies array of terms indexed by a taxonomy.
|
116 |
*/
|
117 |
+
public function add_taxonomy( $attachments, $taxonomies ) {
|
118 |
|
119 |
foreach ( $attachments as $id ) {
|
120 |
|
129 |
}
|
130 |
|
131 |
/**
|
132 |
+
* Add media meta.
|
133 |
*
|
134 |
+
* @param array $attachments attachment ids.
|
135 |
+
* @param array $custom_fields array of key value pairs of meta.
|
136 |
*
|
137 |
* @return boolean success of meta
|
138 |
*/
|
139 |
+
public function add_meta( $attachments, $custom_fields ) {
|
140 |
|
141 |
foreach ( $attachments as $id ) {
|
142 |
$row = array( 'media_id' => $id );
|
164 |
*
|
165 |
* @return boolean
|
166 |
*/
|
167 |
+
public function is_multisite() {
|
168 |
return is_multisite();
|
169 |
}
|
170 |
|
171 |
/**
|
172 |
* Generic method to add a media
|
173 |
*
|
174 |
+
* @param array $uploaded Uploaded media details.
|
175 |
+
* @param array $file_object File details.
|
176 |
*
|
177 |
+
* @return array
|
178 |
+
* @throws Exception Exception while adding media.
|
179 |
*/
|
180 |
+
public function add( $uploaded, $file_object ) {
|
181 |
|
182 |
+
// action to perform any task before adding a media.
|
183 |
do_action( 'rtmedia_before_add_media', $file_object, $uploaded );
|
184 |
|
185 |
+
// Generate media details required to feed in database.
|
186 |
$attachments = $this->generate_post_array( $uploaded, $file_object );
|
187 |
|
188 |
+
// Insert the media as an attachment in WordPress context.
|
189 |
$attachment_ids = $this->insert_attachment( $attachments, $file_object );
|
190 |
|
191 |
+
// check for multisite and if valid then add taxonomies.
|
192 |
if ( ! $this->is_multisite() ) {
|
193 |
$this->add_taxonomy( $attachment_ids, $uploaded['taxonomy'] );
|
194 |
}
|
195 |
|
196 |
+
// fetch custom fields and add them to meta table.
|
197 |
$this->add_meta( $attachment_ids, $uploaded['custom_fields'] );
|
198 |
|
199 |
+
// add media in rtMedia context.
|
200 |
+
$media_ids = $this->insertmedia( $attachment_ids, $uploaded, $file_object ); // $file_object passing file object to check the extension.
|
201 |
|
202 |
$rtmedia_type = rtmedia_type( $media_ids );
|
203 |
+
// action to perform any task after adding a media.
|
204 |
global $rtmedia_points_media_id;
|
205 |
if ( $media_ids && is_array( $media_ids ) && isset( $media_ids[0] ) ) {
|
206 |
$rtmedia_points_media_id = $media_ids[0];
|
216 |
/**
|
217 |
* Generic method to update a media. media details can be changed from this method
|
218 |
*
|
219 |
+
* @param int $id Post id.
|
220 |
+
* @param array $data Data to update.
|
221 |
+
* @param int $media_id Media id.
|
222 |
*
|
223 |
* @return bool
|
224 |
*/
|
225 |
+
public function update( $id, $data, $media_id ) {
|
226 |
|
227 |
+
// action to perform any task before updating a media.
|
228 |
do_action( 'rtmedia_before_update_media', $id );
|
229 |
|
230 |
$defaults = array();
|
233 |
|
234 |
if ( array_key_exists( 'media_title', $data ) || array_key_exists( 'description', $data ) ) {
|
235 |
$post_data['ID'] = $media_id;
|
236 |
+
|
237 |
if ( isset( $data['media_title'] ) ) {
|
238 |
$data['media_title'] = wp_kses( $data['media_title'], wp_kses_allowed_html() );
|
239 |
$post_data['post_title'] = $data['media_title'];
|
240 |
$post_data['post_name'] = $data['media_title'];
|
241 |
}
|
242 |
if ( isset( $data['description'] ) ) {
|
243 |
+
// filter post_content for allowed html tags.
|
244 |
$post_data['post_content'] = wp_kses( $data['description'], wp_kses_allowed_html() );
|
245 |
unset( $data['description'] );
|
246 |
}
|
249 |
|
250 |
$status = $this->model->update( $data, $where );
|
251 |
|
252 |
+
// insert/update activity details in rtmedia activity table.
|
253 |
$media_model = new RTMediaModel();
|
254 |
$media = $media_model->get( array( 'id' => $id ) );
|
255 |
|
256 |
if ( ! empty( $media ) ) {
|
257 |
+
$media_ids_of_activity = array();
|
258 |
$rtmedia_activity_model = new RTMediaActivityModel();
|
259 |
$similar_media = $media_model->get( array( 'activity_id' => $media[0]->activity_id ) );
|
260 |
$max_privacy = 0;
|
261 |
|
262 |
foreach ( $similar_media as $s_media ) {
|
263 |
+
// get all the media ids in the activity.
|
264 |
$media_ids_of_activity[] = $s_media->id;
|
265 |
|
266 |
if ( $s_media->privacy > $max_privacy ) {
|
269 |
}
|
270 |
|
271 |
if ( ! $rtmedia_activity_model->check( $media[0]->activity_id ) ) {
|
272 |
+
$rtmedia_activity_model->insert(
|
273 |
+
array(
|
274 |
+
'activity_id' => $media[0]->activity_id,
|
275 |
+
'user_id' => $media[0]->media_author,
|
276 |
+
'privacy' => $max_privacy,
|
277 |
+
)
|
278 |
+
);
|
279 |
} else {
|
280 |
+
$rtmedia_activity_model->update(
|
281 |
+
array(
|
282 |
+
'activity_id' => $media[0]->activity_id,
|
283 |
+
'user_id' => $media[0]->media_author,
|
284 |
+
'privacy' => $max_privacy,
|
285 |
+
),
|
286 |
+
array( 'activity_id' => $media[0]->activity_id )
|
287 |
+
);
|
288 |
}
|
289 |
|
290 |
+
// is the activate has any media then move the like and comment of that media to for the privacy.
|
291 |
$rtmedia_activity_model->profile_activity_update( $media_ids_of_activity, $max_privacy, $media[0]->activity_id );
|
292 |
}
|
293 |
|
294 |
+
// action to perform any task after updating a media.
|
295 |
do_action( 'rtmedia_after_update_media', $id );
|
296 |
|
297 |
if ( false === $status ) {
|
302 |
}
|
303 |
|
304 |
/**
|
305 |
+
* Generic method to delete a media from WordPress media library ( other than by rtMedia )
|
|
|
|
|
306 |
*
|
307 |
+
* @param int $id Media id.
|
308 |
*/
|
309 |
+
public function delete_wordpress_attachment( $id ) {
|
310 |
$media = $this->model->get( array( 'media_id' => $id ), false, false );
|
311 |
|
312 |
if ( $media ) {
|
317 |
/**
|
318 |
* Method to reassign media to another user while deleting user
|
319 |
*
|
320 |
+
* @param int $user_id User id.
|
321 |
+
* @param int $reassign User id to assign.
|
322 |
*/
|
323 |
public function reassign_wordpress_user( $user_id, $reassign ) {
|
324 |
if ( null !== $reassign || '' !== $reassign ) {
|
325 |
+
// Updating media author.
|
326 |
$rtmedia_model = new RTMediaModel();
|
327 |
$rtmedia_model->update( array( 'media_author' => $reassign ), array( 'media_author' => $user_id ) );
|
328 |
|
329 |
+
// Updating user id from interaction.
|
330 |
$rtmediainteraction = new RTMediaInteractionModel();
|
331 |
$rtmediainteraction->update( array( 'user_id' => $reassign ), array( 'user_id' => $user_id ) );
|
332 |
}
|
335 |
/**
|
336 |
* Generic method to delete a media
|
337 |
*
|
338 |
+
* @param int $id Media id.
|
339 |
+
* @param bool $core Core media or not.
|
340 |
+
* @param bool $delete_activity Add activity or not.
|
341 |
*
|
342 |
* @return bool
|
|
|
343 |
*/
|
344 |
+
public function delete( $id, $core = false, $delete_activity = true ) {
|
345 |
do_action( 'rtmedia_before_delete_media', $id );
|
346 |
|
347 |
$media = $this->model->get( array( 'id' => $id ), false, false );
|
350 |
|
351 |
if ( $media ) {
|
352 |
|
353 |
+
// delete the child media of the media where the media context type is ( post, comment, reply ).
|
354 |
+
$context_type = array( 'post', 'comment', 'reply' );
|
355 |
+
|
356 |
+
if ( isset( $media[0]->context ) && in_array( $media[0]->context, $context_type, true ) ) {
|
357 |
+
// get the child media of the current media.
|
358 |
$has_comment_media = get_rtmedia_meta( $media[0]->id, 'has_comment_media' );
|
359 |
+
|
360 |
if ( is_array( $has_comment_media ) ) {
|
361 |
+
|
362 |
foreach ( $has_comment_media as $value ) {
|
363 |
+
// first delete the child media.
|
364 |
$delete = $this->delete( $value );
|
365 |
}
|
366 |
}
|
367 |
}
|
368 |
|
369 |
+
$post_comment = sanitize_text_field( filter_input( INPUT_POST, 'comment_id', FILTER_SANITIZE_STRING ) );
|
370 |
+
|
371 |
+
// delete comment if media is in the comment.
|
372 |
+
if ( class_exists( 'RTMediaTemplate' ) && isset( $media[0]->id ) && empty( $post_comment ) ) {
|
373 |
$rtmedia_media_used = get_rtmedia_meta( $media[0]->id, 'rtmedia_media_used' );
|
374 |
+
if ( isset( $rtmedia_media_used['comment'] ) && ! empty( $rtmedia_media_used['comment'] ) ) {
|
375 |
$template = new RTMediaTemplate();
|
376 |
+
$template->rtmedia_delete_comment_and_activity( $rtmedia_media_used['comment'] );
|
377 |
}
|
378 |
}
|
379 |
|
380 |
+
// delete meta.
|
381 |
if ( $delete_activity ) {
|
382 |
+
|
383 |
if ( $media[0]->activity_id && function_exists( 'bp_activity_delete_by_activity_id' ) ) {
|
384 |
+
|
385 |
$related_media = $this->model->get( array( 'activity_id' => $media[0]->activity_id ), false, false );
|
386 |
+
|
387 |
if ( count( $related_media ) > 1 ) {
|
388 |
$activity_media = array();
|
389 |
+
|
390 |
foreach ( $related_media as $temp_media ) {
|
391 |
if ( $temp_media->id === $id ) {
|
392 |
continue;
|
393 |
}
|
394 |
$activity_media[] = $temp_media->id;
|
395 |
}
|
396 |
+
|
397 |
$obj_activity = new RTMediaActivity( $activity_media );
|
398 |
global $wpdb, $bp;
|
399 |
+
$wpdb->update(
|
400 |
+
$bp->activity->table_name,
|
401 |
+
array(
|
402 |
+
'type' => 'rtmedia_update',
|
403 |
+
'content' => $obj_activity->create_activity_html(),
|
404 |
+
),
|
405 |
+
array( 'id' => $media[0]->activity_id )
|
406 |
+
);
|
407 |
} else {
|
408 |
if ( isset( $media[0] ) && isset( $media[0]->activity_id ) ) {
|
409 |
bp_activity_delete_by_activity_id( $media[0]->activity_id );
|
410 |
}
|
411 |
}
|
412 |
|
413 |
+
// Deleting like and comment activity for media.
|
414 |
if ( function_exists( 'bp_activity_delete' ) ) {
|
415 |
+
// if the media type is group or profile( activity ).
|
416 |
+
if ( isset( $media[0]->context ) && ( 'group' === $media[0]->context || 'group-reply' === $media[0]->context ) ) {
|
417 |
|
418 |
+
// only delete the activity that is being like in the group.
|
419 |
bp_activity_delete(
|
420 |
array(
|
421 |
+
'component ' => 'groups',
|
422 |
+
'type ' => 'rtmedia_like_activity',
|
423 |
+
'item_id' => $media[0]->context_id,
|
424 |
+
'secondary_item_id' => $media[0]->id,
|
425 |
)
|
426 |
);
|
427 |
|
428 |
+
// rtMedia get the media comment details.
|
429 |
$comments = rtmedia_get_comments_details_for_media_id( $media[0]->media_id );
|
430 |
|
431 |
$delete_ca = false;
|
432 |
+
if ( is_array( $comments ) && ! empty( $comments ) ) {
|
433 |
+
foreach ( $comments as $comment ) {
|
434 |
$comment_id = $comment->comment_ID;
|
435 |
+
$user_id = $comment->user_id;
|
436 |
+
$meta_key = 'rtm-bp-media-comment-activity-' . $media[0]->id . '-' . $comment_id;
|
437 |
|
438 |
// Delete activity when user remove his comment.
|
439 |
+
// todo user_attribute.
|
440 |
$activity_id = get_user_meta( $user_id, $meta_key, true );
|
441 |
|
442 |
+
// only delete the activity that is being like in the group.
|
443 |
$delete_ca = bp_activity_delete(
|
444 |
array(
|
445 |
+
'component ' => 'groups',
|
446 |
+
'type ' => 'rtmedia_comment_activity',
|
447 |
+
'id' => $activity_id,
|
448 |
)
|
449 |
);
|
450 |
|
451 |
+
if ( $delete_ca ) {
|
452 |
delete_user_meta( $user_id, $meta_key );
|
453 |
}
|
454 |
}
|
455 |
}
|
456 |
+
} else {
|
457 |
+
// any other context type.
|
|
|
458 |
bp_activity_delete( array( 'item_id' => $media[0]->id ) );
|
459 |
}
|
460 |
}
|
461 |
}
|
462 |
}
|
463 |
+
|
464 |
if ( ! $core && ! is_admin() ) {
|
465 |
wp_delete_attachment( $media[0]->media_id, true );
|
466 |
}
|
467 |
+
|
468 |
$status = $this->model->delete( array( 'id' => $id ) );
|
469 |
|
470 |
+
// delete media meta (view) from wp_rt_rtm_media_meta.
|
471 |
$delete_rtmedia_views = delete_rtmedia_meta( $id, 'view' );
|
472 |
|
473 |
if ( 0 !== $status && ( 'album' === $media[0]->media_type || 'playlist' === $media[0]->media_type ) ) {
|
475 |
}
|
476 |
$rtmedia_nav = new RTMediaNav();
|
477 |
if ( 'group' === $media[0]->context ) {
|
478 |
+
$rtmedia_nav->refresh_counts(
|
479 |
+
$media[0]->context_id,
|
480 |
+
array(
|
481 |
+
'context' => $media[0]->context,
|
482 |
+
'context_id' => $media[0]->context_id,
|
483 |
+
)
|
484 |
+
);
|
485 |
} else {
|
486 |
+
$rtmedia_nav->refresh_counts(
|
487 |
+
$media[0]->media_author,
|
488 |
+
array(
|
489 |
+
'context' => 'profile',
|
490 |
+
'media_author' => $media[0]->media_author,
|
491 |
+
)
|
492 |
+
);
|
493 |
}
|
494 |
}
|
495 |
|
509 |
*
|
510 |
* @global type $wpdb
|
511 |
*
|
512 |
+
* @param int $media_id Media id.
|
513 |
+
* @param int $album_id Album id.
|
514 |
*
|
515 |
* @return boolean
|
516 |
*/
|
517 |
+
public function move( $media_id, $album_id ) {
|
518 |
|
519 |
global $wpdb;
|
520 |
+
// update the post_parent value in wp_post table.
|
521 |
$status = $wpdb->update( $wpdb->posts, array( 'post_parent' => $album_id ), array( 'ID' => $media_id ) );
|
522 |
|
523 |
if ( is_wp_error( $status ) || 0 === $status ) {
|
524 |
return false;
|
525 |
} else {
|
526 |
$id = rtmedia_id( $media_id );
|
527 |
+
// update album_id, context, context_id and privacy in rtMedia context.
|
528 |
$album_data = $this->model->get( array( 'media_id' => $media_id ) );
|
529 |
$data = array(
|
530 |
'album_id' => $album_id,
|
540 |
/**
|
541 |
* Imports attachment as media
|
542 |
*/
|
543 |
+
public function import_attachment() {
|
544 |
|
545 |
}
|
546 |
|
549 |
*
|
550 |
* @return boolean
|
551 |
*/
|
552 |
+
public function activity_enabled() {
|
553 |
|
554 |
if ( ! function_exists( 'bp_is_active' ) || ! bp_is_active( 'activity' ) ) {
|
555 |
return false;
|
561 |
}
|
562 |
|
563 |
/**
|
564 |
+
* Generates post array from uploaded media.
|
565 |
*
|
566 |
+
* @param array $uploaded uploaded album details.
|
567 |
+
* @param array $file_object array of files uploaded.
|
568 |
*
|
569 |
+
* @return array
|
570 |
*/
|
571 |
+
public function generate_post_array( $uploaded, $file_object ) {
|
572 |
+
|
573 |
if ( $uploaded['album_id'] ) {
|
574 |
+
|
575 |
$model = new RTMediaModel();
|
576 |
$parent_details = $model->get( array( 'id' => $uploaded['album_id'] ) );
|
577 |
+
|
578 |
if ( is_array( $parent_details ) && count( $parent_details ) > 0 ) {
|
579 |
$album_id = $parent_details[0]->media_id;
|
580 |
} else {
|
591 |
$attachments = array();
|
592 |
|
593 |
foreach ( $file_object as $index => $file ) {
|
594 |
+
|
595 |
+
$uploaded['title'] = wp_kses( $uploaded['title'], wp_kses_allowed_html() );
|
596 |
+
// filter description for allowed html tags.
|
597 |
$uploaded['description'] = wp_kses( $uploaded['description'], wp_kses_allowed_html() );
|
598 |
$attachments[ $index ] = array(
|
599 |
'post_mime_type' => $file['type'],
|
613 |
}
|
614 |
|
615 |
/**
|
616 |
+
* Insert attachments.
|
617 |
*
|
618 |
+
* @param array $attachments Array of attachments.
|
619 |
+
* @param array $file_object File details.
|
620 |
*
|
621 |
* @return array $updated_attachment_ids
|
622 |
+
* @throws Exception Error creating/inserting attachment.
|
623 |
*/
|
624 |
+
public function insert_attachment( $attachments, $file_object ) {
|
625 |
+
|
626 |
$updated_attachment_ids = array();
|
627 |
foreach ( $attachments as $key => $attachment ) {
|
628 |
+
|
629 |
$attachment_id = wp_insert_attachment( $attachment, $file_object[ $key ]['file'], $attachment['post_parent'] );
|
630 |
+
|
631 |
if ( ! is_wp_error( $attachment_id ) ) {
|
632 |
+
|
633 |
add_filter( 'intermediate_image_sizes', array( $this, 'image_sizes' ), 99 );
|
634 |
/**
|
635 |
+
* FIX WordPress 3.6 METADATA
|
|
|
|
|
|
|
|
|
636 |
*/
|
637 |
+
require_once ABSPATH . 'wp-admin/includes/media.php';
|
638 |
wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $file_object[ $key ]['file'] ) );
|
639 |
+
|
640 |
} else {
|
641 |
+
|
642 |
$file = $file_object[ $key ]['file'];
|
643 |
+
|
644 |
+
if ( function_exists( 'wp_delete_file' ) ) { // wp_delete_file is introduced in WordPress 4.2.
|
645 |
wp_delete_file( $file );
|
646 |
} else {
|
647 |
+
unlink( $file );
|
648 |
}
|
649 |
+
|
650 |
throw new Exception( esc_html__( 'Error creating attachment for the media file, please try again', 'buddypress-media' ) );
|
651 |
}
|
652 |
+
|
653 |
$updated_attachment_ids[] = $attachment_id;
|
654 |
}
|
655 |
|
657 |
}
|
658 |
|
659 |
/**
|
660 |
+
* Get image registered sizes.
|
661 |
*
|
662 |
+
* @param array $sizes Image sizes.
|
663 |
*
|
664 |
+
* @return array
|
665 |
*/
|
666 |
+
public function image_sizes( $sizes ) {
|
667 |
return array(
|
668 |
'rt_media_thumbnail',
|
669 |
'rt_media_activity_image',
|
673 |
}
|
674 |
|
675 |
/**
|
676 |
+
* Insert album.
|
677 |
*
|
678 |
+
* @param array $attributes Attributes.
|
679 |
*
|
680 |
* @return int
|
681 |
*/
|
682 |
+
public function insert_album( $attributes ) {
|
683 |
|
684 |
return $this->model->insert( $attributes );
|
685 |
}
|
686 |
|
687 |
+
/**
|
688 |
+
* Get media type based on mime type.
|
689 |
+
*
|
690 |
+
* @param string $mime_type Media mime type.
|
691 |
+
* @param array $file_object File details.
|
692 |
+
*
|
693 |
+
* @return mixed|string|void
|
694 |
+
*/
|
695 |
+
public function set_media_type( $mime_type, $file_object ) {
|
696 |
switch ( $mime_type ) {
|
697 |
case 'image':
|
698 |
return 'photo';
|
|
|
699 |
case 'audio':
|
700 |
return 'music';
|
|
|
701 |
case 'video':
|
702 |
return 'video';
|
|
|
703 |
default:
|
704 |
return apply_filters( 'rtmedia_set_media_type_filter', $mime_type, $file_object );
|
|
|
705 |
}
|
706 |
}
|
707 |
|
708 |
/**
|
709 |
+
* Insert media with given details.
|
710 |
*
|
711 |
+
* @param array $attachment_ids Attachments.
|
712 |
+
* @param array $uploaded Uploaded media.
|
713 |
+
* @param array $file_object File details.
|
|
|
714 |
*
|
715 |
* @return array
|
716 |
*/
|
717 |
+
public function insertmedia( $attachment_ids, $uploaded, $file_object /* added for file extension */ ) {
|
718 |
|
719 |
$defaults = array(
|
720 |
'activity_id' => $this->activity_enabled(),
|
735 |
'album_id' => $uploaded['album_id'],
|
736 |
'media_author' => $attachment['post_author'],
|
737 |
'media_title' => $attachment['post_title'],
|
738 |
+
'media_type' => $this->set_media_type( $mime_type[0], $file_object ), // $file_object added for file extension.
|
739 |
'context' => $uploaded['context'],
|
740 |
'context_id' => $uploaded['context_id'],
|
741 |
'privacy' => $uploaded['privacy'],
|
750 |
return $media_id;
|
751 |
}
|
752 |
|
753 |
+
/**
|
754 |
+
* Insert activity for media.
|
755 |
+
*
|
756 |
+
* @param int $id activity id.
|
757 |
+
* @param object $media Media details object.
|
758 |
+
* @param bool|string $activity_text Activity text.
|
759 |
+
*
|
760 |
+
* @return bool
|
761 |
+
*/
|
762 |
+
public function insert_activity( $id, $media, $activity_text = false ) {
|
763 |
if ( ! $this->activity_enabled() ) {
|
764 |
return false;
|
765 |
}
|
768 |
$activity_content = $activity->create_activity_html();
|
769 |
$user = get_userdata( $media->media_author );
|
770 |
$username = '<a href="' . esc_url( get_rtmedia_user_link( $media->media_author ) ) . '">' . esc_html( $user->display_name ) . '</a>';
|
771 |
+
$count = is_array( $id ) ? count( $id ) : 1;
|
772 |
$media_const = 'RTMEDIA_' . strtoupper( $media->media_type );
|
773 |
if ( $count > 1 ) {
|
774 |
$media_const .= '_PLURAL';
|
778 |
|
779 |
$media_str = constant( $media_const );
|
780 |
|
781 |
+
// translators: 1: username, 2: media type, 3: media name, 4: total media.
|
782 |
$action = sprintf( ( 1 === $count ) ? esc_html__( '%1$s added a %2$s', 'buddypress-media' ) : esc_html__( '%1$s added %4$d %3$s', 'buddypress-media' ), $username, $media->media_type, $media_str, $count );
|
783 |
$action = apply_filters( 'rtmedia_buddypress_action_text_fitler', $action, $username, $count, $user->display_name, $media->media_type );
|
784 |
$activity_args = array(
|
809 |
|
810 |
$this->model->update( array( 'activity_id' => $activity_id ), array( 'id' => $media->id ) );
|
811 |
|
812 |
+
// insert/update activity details in rtmedia activity table.
|
813 |
$rtmedia_activity_model = new RTMediaActivityModel();
|
814 |
|
815 |
if ( ! $rtmedia_activity_model->check( $activity_id ) ) {
|
816 |
+
$rtmedia_activity_model->insert(
|
817 |
+
array(
|
818 |
+
'activity_id' => $activity_id,
|
819 |
+
'user_id' => $media->media_author,
|
820 |
+
'privacy' => $media->privacy,
|
821 |
+
)
|
822 |
+
);
|
823 |
} else {
|
824 |
+
$rtmedia_activity_model->update(
|
825 |
+
array(
|
826 |
+
'activity_id' => $activity_id,
|
827 |
+
'user_id' => $media->media_author,
|
828 |
+
'privacy' => $media->privacy,
|
829 |
+
),
|
830 |
+
array( 'activity_id' => $activity_id )
|
831 |
+
);
|
832 |
}
|
833 |
|
834 |
return $activity_id;
|
app/main/controllers/media/RTMediaMeta.php
CHANGED
@@ -1,24 +1,38 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
/*
|
4 |
-
* To change this template, choose Tools | Templates
|
5 |
-
* and open the template in the editor.
|
6 |
-
*/
|
7 |
-
|
8 |
/**
|
9 |
-
*
|
10 |
*
|
|
|
11 |
* @author saurabh
|
12 |
*/
|
|
|
|
|
|
|
|
|
13 |
class RTMediaMeta {
|
14 |
|
15 |
/**
|
|
|
16 |
*
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
*/
|
18 |
public function __construct() {
|
19 |
$this->model = new RTDBModel( 'rtm_media_meta', false, 10, true );
|
20 |
}
|
21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
public function get_meta( $id = false, $key = false ) {
|
23 |
if ( false === $id ) {
|
24 |
return false;
|
@@ -30,22 +44,45 @@ class RTMediaMeta {
|
|
30 |
}
|
31 |
}
|
32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
private function get_all_meta( $id = false ) {
|
34 |
-
if ( false === $id) {
|
35 |
return false;
|
36 |
}
|
37 |
|
38 |
return maybe_unserialize( $this->model->get( array( 'media_id' => $id ) ) );
|
39 |
}
|
40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
private function get_single_meta( $id = false, $key = false ) {
|
42 |
if ( false === $id ) {
|
43 |
return false;
|
44 |
}
|
|
|
45 |
if ( false === $key ) {
|
46 |
return false;
|
47 |
}
|
48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
if ( isset( $value[0] ) ) {
|
50 |
return maybe_unserialize( $value[0]->meta_value );
|
51 |
} else {
|
@@ -53,10 +90,30 @@ class RTMediaMeta {
|
|
53 |
}
|
54 |
}
|
55 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
public function add_meta( $id = false, $key = false, $value = false, $duplicate = false ) {
|
57 |
return $this->update_meta( $id, $key, $value, $duplicate );
|
58 |
}
|
59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
public function update_meta( $id = false, $key = false, $value = false, $duplicate = false ) {
|
61 |
if ( false === $id ) {
|
62 |
return false;
|
@@ -70,28 +127,55 @@ class RTMediaMeta {
|
|
70 |
$value = maybe_serialize( $value );
|
71 |
|
72 |
if ( true === $duplicate ) {
|
73 |
-
$media_meta = $this->model->insert(
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
} else {
|
75 |
-
if ( $this->get_single_meta( $id, $key ) ) {
|
76 |
$meta = array( 'meta_value' => $value );
|
77 |
-
$where = array(
|
|
|
|
|
|
|
78 |
$media_meta = $this->model->update( $meta, $where );
|
79 |
} else {
|
80 |
-
$media_meta = $this->model->insert(
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
}
|
82 |
}
|
83 |
|
84 |
return $media_meta;
|
85 |
}
|
86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
public function delete_meta( $id = false, $key = false ) {
|
88 |
if ( false === $id ) {
|
89 |
return false;
|
90 |
}
|
|
|
91 |
if ( false === $key ) {
|
92 |
$where = array( 'media_id' => $id );
|
93 |
} else {
|
94 |
-
$where = array(
|
|
|
|
|
|
|
95 |
}
|
96 |
|
97 |
return $this->model->delete( $where );
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
+
* Handles media meta operations.
|
4 |
*
|
5 |
+
* @package rtMedia
|
6 |
* @author saurabh
|
7 |
*/
|
8 |
+
|
9 |
+
/**
|
10 |
+
* Class to handle media meta operations.
|
11 |
+
*/
|
12 |
class RTMediaMeta {
|
13 |
|
14 |
/**
|
15 |
+
* RTDBModel object.
|
16 |
*
|
17 |
+
* @var RTDBModel
|
18 |
+
*/
|
19 |
+
public $model;
|
20 |
+
|
21 |
+
/**
|
22 |
+
* RTMediaMeta constructor.
|
23 |
*/
|
24 |
public function __construct() {
|
25 |
$this->model = new RTDBModel( 'rtm_media_meta', false, 10, true );
|
26 |
}
|
27 |
|
28 |
+
/**
|
29 |
+
* Get meta from media.
|
30 |
+
*
|
31 |
+
* @param bool|int $id Media id.
|
32 |
+
* @param bool|string $key Meta key.
|
33 |
+
*
|
34 |
+
* @return bool|mixed
|
35 |
+
*/
|
36 |
public function get_meta( $id = false, $key = false ) {
|
37 |
if ( false === $id ) {
|
38 |
return false;
|
44 |
}
|
45 |
}
|
46 |
|
47 |
+
/**
|
48 |
+
* Get all meta of media.
|
49 |
+
*
|
50 |
+
* @param bool $id Media id.
|
51 |
+
*
|
52 |
+
* @return bool|mixed
|
53 |
+
*/
|
54 |
private function get_all_meta( $id = false ) {
|
55 |
+
if ( false === $id ) {
|
56 |
return false;
|
57 |
}
|
58 |
|
59 |
return maybe_unserialize( $this->model->get( array( 'media_id' => $id ) ) );
|
60 |
}
|
61 |
|
62 |
+
/**
|
63 |
+
* Get single meta value.
|
64 |
+
*
|
65 |
+
* @param bool|int $id Media id.
|
66 |
+
* @param bool|string $key Meta key.
|
67 |
+
*
|
68 |
+
* @return bool|mixed
|
69 |
+
*/
|
70 |
private function get_single_meta( $id = false, $key = false ) {
|
71 |
if ( false === $id ) {
|
72 |
return false;
|
73 |
}
|
74 |
+
|
75 |
if ( false === $key ) {
|
76 |
return false;
|
77 |
}
|
78 |
+
|
79 |
+
$value = $this->model->get(
|
80 |
+
array(
|
81 |
+
'media_id' => $id,
|
82 |
+
'meta_key' => $key,
|
83 |
+
)
|
84 |
+
);
|
85 |
+
|
86 |
if ( isset( $value[0] ) ) {
|
87 |
return maybe_unserialize( $value[0]->meta_value );
|
88 |
} else {
|
90 |
}
|
91 |
}
|
92 |
|
93 |
+
/**
|
94 |
+
* Add meta.
|
95 |
+
*
|
96 |
+
* @param bool|int $id Media id.
|
97 |
+
* @param bool|string $key Meta key.
|
98 |
+
* @param bool|string $value Meta value.
|
99 |
+
* @param bool $duplicate Duplicate meta or not.
|
100 |
+
*
|
101 |
+
* @return bool|false|int
|
102 |
+
*/
|
103 |
public function add_meta( $id = false, $key = false, $value = false, $duplicate = false ) {
|
104 |
return $this->update_meta( $id, $key, $value, $duplicate );
|
105 |
}
|
106 |
|
107 |
+
/**
|
108 |
+
* Update meta.
|
109 |
+
*
|
110 |
+
* @param bool|int $id Media id.
|
111 |
+
* @param bool|string $key Meta key.
|
112 |
+
* @param bool|string $value Meta value.
|
113 |
+
* @param bool $duplicate Duplicate meta or not.
|
114 |
+
*
|
115 |
+
* @return bool|false|int
|
116 |
+
*/
|
117 |
public function update_meta( $id = false, $key = false, $value = false, $duplicate = false ) {
|
118 |
if ( false === $id ) {
|
119 |
return false;
|
127 |
$value = maybe_serialize( $value );
|
128 |
|
129 |
if ( true === $duplicate ) {
|
130 |
+
$media_meta = $this->model->insert(
|
131 |
+
array(
|
132 |
+
'media_id' => $id,
|
133 |
+
'meta_key' => $key,
|
134 |
+
'meta_value' => $value,
|
135 |
+
)
|
136 |
+
);
|
137 |
} else {
|
138 |
+
if ( false !== $this->get_single_meta( $id, $key ) ) {
|
139 |
$meta = array( 'meta_value' => $value );
|
140 |
+
$where = array(
|
141 |
+
'media_id' => $id,
|
142 |
+
'meta_key' => $key,
|
143 |
+
);
|
144 |
$media_meta = $this->model->update( $meta, $where );
|
145 |
} else {
|
146 |
+
$media_meta = $this->model->insert(
|
147 |
+
array(
|
148 |
+
'media_id' => $id,
|
149 |
+
'meta_key' => $key,
|
150 |
+
'meta_value' => $value,
|
151 |
+
)
|
152 |
+
);
|
153 |
}
|
154 |
}
|
155 |
|
156 |
return $media_meta;
|
157 |
}
|
158 |
|
159 |
+
/**
|
160 |
+
* Delete meta for media id.
|
161 |
+
*
|
162 |
+
* @param bool|int $id Media id.
|
163 |
+
* @param bool|string $key Meta key.
|
164 |
+
*
|
165 |
+
* @return array|bool
|
166 |
+
*/
|
167 |
public function delete_meta( $id = false, $key = false ) {
|
168 |
if ( false === $id ) {
|
169 |
return false;
|
170 |
}
|
171 |
+
|
172 |
if ( false === $key ) {
|
173 |
$where = array( 'media_id' => $id );
|
174 |
} else {
|
175 |
+
$where = array(
|
176 |
+
'media_id' => $id,
|
177 |
+
'meta_key' => $key,
|
178 |
+
);
|
179 |
}
|
180 |
|
181 |
return $this->model->delete( $where );
|
app/main/controllers/media/RTMediaTags.php
CHANGED
@@ -1,39 +1,55 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
/**
|
4 |
-
*
|
5 |
-
*
|
6 |
*
|
|
|
|
|
|
|
|
|
|
|
7 |
*/
|
8 |
class RTMediaTags {
|
|
|
9 |
/**
|
|
|
10 |
*
|
11 |
-
* @var object
|
12 |
*/
|
13 |
private static $_id3;
|
14 |
|
15 |
/**
|
|
|
16 |
*
|
17 |
-
* @var
|
18 |
*/
|
19 |
private $file;
|
20 |
|
21 |
/**
|
|
|
22 |
*
|
23 |
-
* @var object
|
24 |
*/
|
25 |
private $id3;
|
26 |
|
27 |
-
|
28 |
/**
|
|
|
29 |
*
|
30 |
-
*
|
31 |
-
* @var array key and value of analyzed file
|
32 |
*/
|
33 |
private $data = null;
|
34 |
|
35 |
-
|
|
|
|
|
|
|
|
|
36 |
private $duration_info = array( 'duration' );
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
private $tags = array(
|
38 |
'title',
|
39 |
'artist',
|
@@ -46,29 +62,48 @@ class RTMediaTags {
|
|
46 |
'attached_picture',
|
47 |
'image',
|
48 |
);
|
49 |
-
private $readonly_tags = array( 'track_total', 'attached_picture', 'image' );
|
50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
public function __construct( $file ) {
|
53 |
|
54 |
$this->file = $file;
|
55 |
$this->id3 = self::id3();
|
56 |
}
|
57 |
|
|
|
|
|
|
|
|
|
|
|
58 |
public function update_filepath( $file ) {
|
59 |
|
60 |
$this->file = $file;
|
61 |
}
|
62 |
|
63 |
/**
|
64 |
-
*
|
65 |
* Writes data inside the files after manipulation, mainly mp3 files.
|
|
|
|
|
|
|
66 |
*/
|
67 |
public function save() {
|
68 |
|
69 |
-
include_once
|
70 |
|
71 |
-
$tagwriter = new getid3_writetags;
|
72 |
$tagwriter->filename = $this->file;
|
73 |
$tagwriter->tag_encoding = 'UTF-8';
|
74 |
$tagwriter->tagformats = array( 'id3v2.3', 'id3v1' );
|
@@ -88,19 +123,18 @@ class RTMediaTags {
|
|
88 |
}
|
89 |
}
|
90 |
|
91 |
-
|
92 |
/**
|
93 |
-
*
|
94 |
* Initialize the getid3 class
|
95 |
*
|
96 |
-
* @return object
|
|
|
97 |
*/
|
98 |
public static function id3() {
|
99 |
|
100 |
-
include_once
|
101 |
|
102 |
if ( ! self::$_id3 ) {
|
103 |
-
self::$_id3 = new getID3;
|
104 |
}
|
105 |
|
106 |
return self::$_id3;
|
@@ -108,12 +142,11 @@ class RTMediaTags {
|
|
108 |
|
109 |
|
110 |
/**
|
111 |
-
*
|
112 |
* Sets cover art for mp3 files
|
113 |
*
|
114 |
-
* @param $data
|
115 |
-
* @param string $mime
|
116 |
-
* @param string $description
|
117 |
*/
|
118 |
public function set_art( $data, $mime = 'jpeg', $description = 'Description' ) {
|
119 |
|
@@ -124,11 +157,19 @@ class RTMediaTags {
|
|
124 |
$this->data['attached_picture'] = array();
|
125 |
|
126 |
$this->data['attached_picture'][0]['data'] = $data;
|
127 |
-
$this->data['attached_picture'][0]['picturetypeid'] = 0x03; // 'Cover (front)'
|
128 |
$this->data['attached_picture'][0]['description'] = $description;
|
129 |
$this->data['attached_picture'][0]['mime'] = 'image/' . $mime;
|
130 |
}
|
131 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
public function __get( $key ) {
|
133 |
|
134 |
if ( ! in_array( $key, $this->tags, true ) && ! in_array( $key, $this->duration_info, true ) && ! isset( $this->duration_info[ $key ] ) ) {
|
@@ -156,6 +197,14 @@ class RTMediaTags {
|
|
156 |
}
|
157 |
}
|
158 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
159 |
public function __set( $key, $value ) {
|
160 |
|
161 |
if ( ! in_array( $key, $this->tags, true ) ) {
|
@@ -174,13 +223,12 @@ class RTMediaTags {
|
|
174 |
|
175 |
|
176 |
/**
|
177 |
-
*
|
178 |
* Analyze file
|
179 |
*/
|
180 |
private function analyze() {
|
181 |
|
182 |
-
$array_ext
|
183 |
-
$path_parts
|
184 |
$path_parts['extension'] = $path_parts['extension'] ? $path_parts['extension'] : false;
|
185 |
|
186 |
$data = $this->id3->analyze( $this->file );
|
@@ -207,7 +255,7 @@ class RTMediaTags {
|
|
207 |
|
208 |
if ( strstr( $track, '/' ) ) {
|
209 |
list( $track, $track_total ) = explode( '/', $track );
|
210 |
-
$this->data['track_total']
|
211 |
}
|
212 |
|
213 |
$this->data['track'] = array( $track );
|
1 |
<?php
|
|
|
2 |
/**
|
3 |
+
* Handles Media tags.
|
|
|
4 |
*
|
5 |
+
* @package rtMedia
|
6 |
+
*/
|
7 |
+
|
8 |
+
/**
|
9 |
+
* Handles Media tags.
|
10 |
*/
|
11 |
class RTMediaTags {
|
12 |
+
|
13 |
/**
|
14 |
+
* A new instance of the getid3 class
|
15 |
*
|
16 |
+
* @var object
|
17 |
*/
|
18 |
private static $_id3;
|
19 |
|
20 |
/**
|
21 |
+
* File to analyze
|
22 |
*
|
23 |
+
* @var string
|
24 |
*/
|
25 |
private $file;
|
26 |
|
27 |
/**
|
28 |
+
* Holds a copy of the variable $_id3
|
29 |
*
|
30 |
+
* @var object
|
31 |
*/
|
32 |
private $id3;
|
33 |
|
|
|
34 |
/**
|
35 |
+
* Key and value of analyzed file
|
36 |
*
|
37 |
+
* @var array
|
|
|
38 |
*/
|
39 |
private $data = null;
|
40 |
|
41 |
+
/**
|
42 |
+
* Media duration.
|
43 |
+
*
|
44 |
+
* @var array
|
45 |
+
*/
|
46 |
private $duration_info = array( 'duration' );
|
47 |
+
|
48 |
+
/**
|
49 |
+
* Media tags.
|
50 |
+
*
|
51 |
+
* @var array
|
52 |
+
*/
|
53 |
private $tags = array(
|
54 |
'title',
|
55 |
'artist',
|
62 |
'attached_picture',
|
63 |
'image',
|
64 |
);
|
|
|
65 |
|
66 |
+
/**
|
67 |
+
* Readonly tags.
|
68 |
+
*
|
69 |
+
* @var array
|
70 |
+
*/
|
71 |
+
private $readonly_tags = array( 'track_total', 'attached_picture', 'image' );
|
72 |
|
73 |
+
/**
|
74 |
+
* RTMediaTags constructor.
|
75 |
+
*
|
76 |
+
* @param string $file File path.
|
77 |
+
*
|
78 |
+
* @throws getid3_exception Exception while initializing id3.
|
79 |
+
*/
|
80 |
public function __construct( $file ) {
|
81 |
|
82 |
$this->file = $file;
|
83 |
$this->id3 = self::id3();
|
84 |
}
|
85 |
|
86 |
+
/**
|
87 |
+
* Change file path.
|
88 |
+
*
|
89 |
+
* @param string $file File path.
|
90 |
+
*/
|
91 |
public function update_filepath( $file ) {
|
92 |
|
93 |
$this->file = $file;
|
94 |
}
|
95 |
|
96 |
/**
|
|
|
97 |
* Writes data inside the files after manipulation, mainly mp3 files.
|
98 |
+
*
|
99 |
+
* @return bool|WP_Error
|
100 |
+
* @throws Exception Exception while adding data.
|
101 |
*/
|
102 |
public function save() {
|
103 |
|
104 |
+
include_once trailingslashit( RTMEDIA_PATH ) . 'lib/getid3/write.php';
|
105 |
|
106 |
+
$tagwriter = new getid3_writetags();
|
107 |
$tagwriter->filename = $this->file;
|
108 |
$tagwriter->tag_encoding = 'UTF-8';
|
109 |
$tagwriter->tagformats = array( 'id3v2.3', 'id3v1' );
|
123 |
}
|
124 |
}
|
125 |
|
|
|
126 |
/**
|
|
|
127 |
* Initialize the getid3 class
|
128 |
*
|
129 |
+
* @return getID3|object
|
130 |
+
* @throws getid3_exception Exception while initializing getID3.
|
131 |
*/
|
132 |
public static function id3() {
|
133 |
|
134 |
+
include_once trailingslashit( RTMEDIA_PATH ) . 'lib/getid3/getid3.php';
|
135 |
|
136 |
if ( ! self::$_id3 ) {
|
137 |
+
self::$_id3 = new getID3();
|
138 |
}
|
139 |
|
140 |
return self::$_id3;
|
142 |
|
143 |
|
144 |
/**
|
|
|
145 |
* Sets cover art for mp3 files
|
146 |
*
|
147 |
+
* @param array $data Image data.
|
148 |
+
* @param string $mime Image mime type.
|
149 |
+
* @param string $description Description of image.
|
150 |
*/
|
151 |
public function set_art( $data, $mime = 'jpeg', $description = 'Description' ) {
|
152 |
|
157 |
$this->data['attached_picture'] = array();
|
158 |
|
159 |
$this->data['attached_picture'][0]['data'] = $data;
|
160 |
+
$this->data['attached_picture'][0]['picturetypeid'] = 0x03; // 'Cover (front)'.
|
161 |
$this->data['attached_picture'][0]['description'] = $description;
|
162 |
$this->data['attached_picture'][0]['mime'] = 'image/' . $mime;
|
163 |
}
|
164 |
|
165 |
+
/**
|
166 |
+
* Get tag value.
|
167 |
+
*
|
168 |
+
* @param string $key Tag key.
|
169 |
+
*
|
170 |
+
* @return array|mixed|null
|
171 |
+
* @throws Exception Unknown tag for class.
|
172 |
+
*/
|
173 |
public function __get( $key ) {
|
174 |
|
175 |
if ( ! in_array( $key, $this->tags, true ) && ! in_array( $key, $this->duration_info, true ) && ! isset( $this->duration_info[ $key ] ) ) {
|
197 |
}
|
198 |
}
|
199 |
|
200 |
+
/**
|
201 |
+
* Set tag to album.
|
202 |
+
*
|
203 |
+
* @param string $key Tag string.
|
204 |
+
* @param string $value Tag value.
|
205 |
+
*
|
206 |
+
* @throws Exception Exception for read only tags.
|
207 |
+
*/
|
208 |
public function __set( $key, $value ) {
|
209 |
|
210 |
if ( ! in_array( $key, $this->tags, true ) ) {
|
223 |
|
224 |
|
225 |
/**
|
|
|
226 |
* Analyze file
|
227 |
*/
|
228 |
private function analyze() {
|
229 |
|
230 |
+
$array_ext = array( 'ogg', 'm4a', 'mp4', 'webm' );
|
231 |
+
$path_parts = pathinfo( $this->file );
|
232 |
$path_parts['extension'] = $path_parts['extension'] ? $path_parts['extension'] : false;
|
233 |
|
234 |
$data = $this->id3->analyze( $this->file );
|
255 |
|
256 |
if ( strstr( $track, '/' ) ) {
|
257 |
list( $track, $track_total ) = explode( '/', $track );
|
258 |
+
$this->data['track_total'] = array( $track_total );
|
259 |
}
|
260 |
|
261 |
$this->data['track'] = array( $track );
|
app/main/controllers/media/RTMediaUserInteraction.php
CHANGED
@@ -1,65 +1,121 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
/*
|
4 |
-
* To change this template, choose Tools | Templates
|
5 |
-
* and open the template in the editor.
|
6 |
-
*/
|
7 |
-
|
8 |
/**
|
9 |
-
*
|
10 |
*
|
|
|
11 |
* @author saurabh
|
12 |
*/
|
|
|
|
|
|
|
|
|
13 |
class RTMediaUserInteraction {
|
14 |
|
15 |
/**
|
|
|
16 |
*
|
17 |
-
* @var string
|
18 |
*/
|
19 |
public $action;
|
20 |
|
21 |
/**
|
|
|
22 |
*
|
23 |
-
* @var string
|
24 |
*/
|
25 |
public $actions;
|
26 |
|
27 |
/**
|
|
|
28 |
*
|
29 |
-
* @var boolean
|
30 |
*/
|
31 |
public $increase;
|
32 |
|
33 |
|
34 |
/**
|
|
|
35 |
*
|
36 |
-
* @var object
|
37 |
*/
|
38 |
public $action_query;
|
39 |
|
40 |
/**
|
|
|
41 |
*
|
42 |
-
* @var object
|
43 |
*/
|
44 |
public $model;
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
public $interactor;
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
public $owner;
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
public $media;
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
public $privacy;
|
49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
/**
|
51 |
* Initialise the user interaction
|
52 |
*
|
53 |
-
* @param array $args
|
54 |
*
|
55 |
* @global object $rtmedia_query Default query
|
56 |
*
|
57 |
-
* @internal param string $action The user action
|
58 |
-
* @internal param bool $private Whether other users are allowed the action
|
59 |
-
* @internal param string $label The label for the button
|
60 |
-
* @internal param bool $increase Increase or decrease the action count
|
61 |
*/
|
62 |
-
function __construct( $args = array() ) {
|
63 |
$defaults = array(
|
64 |
'action' => '',
|
65 |
'label' => '',
|
@@ -80,17 +136,21 @@ class RTMediaUserInteraction {
|
|
80 |
|
81 |
$this->init();
|
82 |
|
83 |
-
// filter the default actions with this new one
|
84 |
add_filter( 'rtmedia_query_actions', array( $this, 'register' ) );
|
85 |
-
// hook into the template for this action
|
86 |
add_action( 'rtmedia_pre_action_' . $this->action, array( $this, 'preprocess' ) );
|
87 |
add_filter( 'rtmedia_action_buttons_before_delete', array( $this, 'button_filter' ) );
|
88 |
}
|
89 |
|
90 |
|
91 |
-
|
|
|
|
|
|
|
92 |
$this->model = new RTMediaModel();
|
93 |
global $rtmedia_query;
|
|
|
94 |
if ( ! isset( $rtmedia_query->action_query ) ) {
|
95 |
return;
|
96 |
}
|
@@ -108,21 +168,26 @@ class RTMediaUserInteraction {
|
|
108 |
/**
|
109 |
* Checks if there's a label, if not creates from the action name
|
110 |
*/
|
111 |
-
function set_label() {
|
112 |
if ( empty( $this->label ) ) {
|
113 |
$this->label = ucfirst( $this->action );
|
114 |
}
|
115 |
}
|
116 |
|
117 |
-
|
|
|
|
|
|
|
118 |
if ( empty( $this->plural ) ) {
|
119 |
$this->plural = $this->label . 's';
|
120 |
}
|
121 |
}
|
122 |
|
123 |
-
|
|
|
|
|
|
|
124 |
|
125 |
-
$media_id = false;
|
126 |
$this->media = false;
|
127 |
|
128 |
global $rtmedia_query;
|
@@ -139,7 +204,10 @@ class RTMediaUserInteraction {
|
|
139 |
|
140 |
}
|
141 |
|
142 |
-
|
|
|
|
|
|
|
143 |
$this->interactor = false;
|
144 |
if ( is_user_logged_in() ) {
|
145 |
$this->interactor = get_current_user_id();
|
@@ -147,7 +215,12 @@ class RTMediaUserInteraction {
|
|
147 |
$this->interactor_privacy = $this->interactor_privacy();
|
148 |
}
|
149 |
|
150 |
-
|
|
|
|
|
|
|
|
|
|
|
151 |
|
152 |
if ( ! isset( $this->interactor ) ) {
|
153 |
return 0;
|
@@ -169,7 +242,12 @@ class RTMediaUserInteraction {
|
|
169 |
return 20;
|
170 |
}
|
171 |
|
172 |
-
|
|
|
|
|
|
|
|
|
|
|
173 |
if ( $this->interactor_privacy >= $this->privacy ) {
|
174 |
return true;
|
175 |
}
|
@@ -177,8 +255,14 @@ class RTMediaUserInteraction {
|
|
177 |
return false;
|
178 |
}
|
179 |
|
180 |
-
|
|
|
|
|
|
|
|
|
|
|
181 |
$clickable = false;
|
|
|
182 |
if ( $this->repeatable ) {
|
183 |
$clickable = true;
|
184 |
if ( $this->undoable ) {
|
@@ -193,20 +277,32 @@ class RTMediaUserInteraction {
|
|
193 |
return $clickable;
|
194 |
}
|
195 |
|
196 |
-
|
|
|
|
|
|
|
197 |
|
198 |
}
|
199 |
|
200 |
-
|
|
|
|
|
|
|
|
|
|
|
201 |
$before_render = $this->before_render();
|
|
|
202 |
if ( false === $before_render ) {
|
203 |
return false;
|
204 |
}
|
205 |
-
|
|
|
|
|
206 |
if ( $this->is_visible() ) {
|
207 |
-
$link = trailingslashit( get_rtmedia_permalink( $this->media->id ) ) .
|
208 |
-
|
209 |
-
$
|
|
|
210 |
if ( ! $this->is_clickable() ) {
|
211 |
$disabled = ' disabled';
|
212 |
}
|
@@ -214,12 +310,21 @@ class RTMediaUserInteraction {
|
|
214 |
if ( isset( $this->icon_class ) && '' !== $this->icon_class ) {
|
215 |
$icon = "<i class='" . esc_attr( $this->icon_class ) . "'></i>";
|
216 |
}
|
|
|
217 |
$button_start = '<form action="' . esc_url( $link ) . '">';
|
218 |
$button_label = apply_filters( 'rtmedia_' . $this->action . '_label_text', $this->label );
|
219 |
$button = '<button type="submit" id="rtmedia-' . esc_attr( $this->action ) . '-button-' . esc_attr( $this->media->id ) . '" class="rtmedia-' . esc_attr( $this->action )
|
220 |
. ' rtmedia-action-buttons button' . esc_attr( $disabled ) . '" title="' . esc_attr( $button_label ) . '">' . $icon . '<span>' . esc_html( $button_label ) . '</span></button>';
|
221 |
|
222 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
223 |
$button = apply_filters( 'rtmedia_' . $this->action . '_button_filter', $button );
|
224 |
|
225 |
$button_end = '</form>';
|
@@ -231,7 +336,15 @@ class RTMediaUserInteraction {
|
|
231 |
return $button;
|
232 |
}
|
233 |
|
234 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
235 |
if ( empty( $this->media ) ) {
|
236 |
$this->init();
|
237 |
}
|
@@ -241,12 +354,13 @@ class RTMediaUserInteraction {
|
|
241 |
}
|
242 |
|
243 |
/**
|
|
|
244 |
*
|
245 |
-
* @param array $actions The default array of actions
|
246 |
*
|
247 |
* @return array $actions Filtered actions array
|
248 |
*/
|
249 |
-
function register( $actions ) {
|
250 |
if ( empty( $this->media ) ) {
|
251 |
$this->init();
|
252 |
}
|
@@ -260,9 +374,8 @@ class RTMediaUserInteraction {
|
|
260 |
* Checks if an id is set
|
261 |
* Creates pre and post process hooks for the action
|
262 |
* Calls the process
|
263 |
-
*
|
264 |
*/
|
265 |
-
function preprocess() {
|
266 |
global $rtmedia_query;
|
267 |
$this->action_query = $rtmedia_query->action_query;
|
268 |
|
@@ -286,7 +399,7 @@ class RTMediaUserInteraction {
|
|
286 |
|
287 |
do_action( 'rtmedia_post_process_' . $this->action, $result );
|
288 |
|
289 |
-
print_r( $result );
|
290 |
|
291 |
die();
|
292 |
}
|
@@ -296,7 +409,7 @@ class RTMediaUserInteraction {
|
|
296 |
*
|
297 |
* @return integer New count
|
298 |
*/
|
299 |
-
function process() {
|
300 |
return false;
|
301 |
}
|
302 |
}
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
+
* Handles user interactions with media
|
4 |
*
|
5 |
+
* @package rtMedia
|
6 |
* @author saurabh
|
7 |
*/
|
8 |
+
|
9 |
+
/**
|
10 |
+
* Class to handle user interactions
|
11 |
+
*/
|
12 |
class RTMediaUserInteraction {
|
13 |
|
14 |
/**
|
15 |
+
* The singular action word (like, unlike, view, download, etc)
|
16 |
*
|
17 |
+
* @var string
|
18 |
*/
|
19 |
public $action;
|
20 |
|
21 |
/**
|
22 |
+
* The plural of the action (likes, unlikes, etc)
|
23 |
*
|
24 |
+
* @var string
|
25 |
*/
|
26 |
public $actions;
|
27 |
|
28 |
/**
|
29 |
+
* Whether the action increases the count or decreases the count
|
30 |
*
|
31 |
+
* @var boolean
|
32 |
*/
|
33 |
public $increase;
|
34 |
|
35 |
|
36 |
/**
|
37 |
+
* The action query populated by the default query
|
38 |
*
|
39 |
+
* @var object
|
40 |
*/
|
41 |
public $action_query;
|
42 |
|
43 |
/**
|
44 |
+
* The db model
|
45 |
*
|
46 |
+
* @var object
|
47 |
*/
|
48 |
public $model;
|
49 |
+
|
50 |
+
/**
|
51 |
+
* User id.
|
52 |
+
*
|
53 |
+
* @var int
|
54 |
+
*/
|
55 |
public $interactor;
|
56 |
+
|
57 |
+
/**
|
58 |
+
* Media owner
|
59 |
+
*
|
60 |
+
* @var int $owner
|
61 |
+
*/
|
62 |
public $owner;
|
63 |
+
|
64 |
+
/**
|
65 |
+
* Media details
|
66 |
+
*
|
67 |
+
* @var array|object
|
68 |
+
*/
|
69 |
public $media;
|
70 |
+
|
71 |
+
/**
|
72 |
+
* Privacy setting.
|
73 |
+
*
|
74 |
+
* @var int
|
75 |
+
*/
|
76 |
public $privacy;
|
77 |
|
78 |
+
/**
|
79 |
+
* Action button label.
|
80 |
+
*
|
81 |
+
* @var string
|
82 |
+
*/
|
83 |
+
public $label;
|
84 |
+
|
85 |
+
/**
|
86 |
+
* Remove action button label.
|
87 |
+
*
|
88 |
+
* @var string
|
89 |
+
*/
|
90 |
+
public $undo_label;
|
91 |
+
|
92 |
+
/**
|
93 |
+
* Privacy setting of user.
|
94 |
+
*
|
95 |
+
* @var int
|
96 |
+
*/
|
97 |
+
public $interactor_privacy;
|
98 |
+
|
99 |
+
/**
|
100 |
+
* Plural label.
|
101 |
+
*
|
102 |
+
* @var string
|
103 |
+
*/
|
104 |
+
public $plural;
|
105 |
+
|
106 |
/**
|
107 |
* Initialise the user interaction
|
108 |
*
|
109 |
+
* @param array $args Arguments array.
|
110 |
*
|
111 |
* @global object $rtmedia_query Default query
|
112 |
*
|
113 |
+
* @internal param string $action The user action.
|
114 |
+
* @internal param bool $private Whether other users are allowed the action.
|
115 |
+
* @internal param string $label The label for the button.
|
116 |
+
* @internal param bool $increase Increase or decrease the action count.
|
117 |
*/
|
118 |
+
public function __construct( $args = array() ) {
|
119 |
$defaults = array(
|
120 |
'action' => '',
|
121 |
'label' => '',
|
136 |
|
137 |
$this->init();
|
138 |
|
139 |
+
// filter the default actions with this new one.
|
140 |
add_filter( 'rtmedia_query_actions', array( $this, 'register' ) );
|
141 |
+
// hook into the template for this action.
|
142 |
add_action( 'rtmedia_pre_action_' . $this->action, array( $this, 'preprocess' ) );
|
143 |
add_filter( 'rtmedia_action_buttons_before_delete', array( $this, 'button_filter' ) );
|
144 |
}
|
145 |
|
146 |
|
147 |
+
/**
|
148 |
+
* Initialize class.
|
149 |
+
*/
|
150 |
+
public function init() {
|
151 |
$this->model = new RTMediaModel();
|
152 |
global $rtmedia_query;
|
153 |
+
|
154 |
if ( ! isset( $rtmedia_query->action_query ) ) {
|
155 |
return;
|
156 |
}
|
168 |
/**
|
169 |
* Checks if there's a label, if not creates from the action name
|
170 |
*/
|
171 |
+
public function set_label() {
|
172 |
if ( empty( $this->label ) ) {
|
173 |
$this->label = ucfirst( $this->action );
|
174 |
}
|
175 |
}
|
176 |
|
177 |
+
/**
|
178 |
+
* Set plural label.
|
179 |
+
*/
|
180 |
+
public function set_plural() {
|
181 |
if ( empty( $this->plural ) ) {
|
182 |
$this->plural = $this->label . 's';
|
183 |
}
|
184 |
}
|
185 |
|
186 |
+
/**
|
187 |
+
* Set media and owner.
|
188 |
+
*/
|
189 |
+
public function set_media() {
|
190 |
|
|
|
191 |
$this->media = false;
|
192 |
|
193 |
global $rtmedia_query;
|
204 |
|
205 |
}
|
206 |
|
207 |
+
/**
|
208 |
+
* Set user interactor.
|
209 |
+
*/
|
210 |
+
public function set_interactor() {
|
211 |
$this->interactor = false;
|
212 |
if ( is_user_logged_in() ) {
|
213 |
$this->interactor = get_current_user_id();
|
215 |
$this->interactor_privacy = $this->interactor_privacy();
|
216 |
}
|
217 |
|
218 |
+
/**
|
219 |
+
* Set interactor privacy.
|
220 |
+
*
|
221 |
+
* @return int
|
222 |
+
*/
|
223 |
+
public function interactor_privacy() {
|
224 |
|
225 |
if ( ! isset( $this->interactor ) ) {
|
226 |
return 0;
|
242 |
return 20;
|
243 |
}
|
244 |
|
245 |
+
/**
|
246 |
+
* Check if element is visible.
|
247 |
+
*
|
248 |
+
* @return bool
|
249 |
+
*/
|
250 |
+
public function is_visible() {
|
251 |
if ( $this->interactor_privacy >= $this->privacy ) {
|
252 |
return true;
|
253 |
}
|
255 |
return false;
|
256 |
}
|
257 |
|
258 |
+
/**
|
259 |
+
* Check if current button clickable or not.
|
260 |
+
*
|
261 |
+
* @return bool
|
262 |
+
*/
|
263 |
+
public function is_clickable() {
|
264 |
$clickable = false;
|
265 |
+
|
266 |
if ( $this->repeatable ) {
|
267 |
$clickable = true;
|
268 |
if ( $this->undoable ) {
|
277 |
return $clickable;
|
278 |
}
|
279 |
|
280 |
+
/**
|
281 |
+
* Before rendering button.
|
282 |
+
*/
|
283 |
+
public function before_render() {
|
284 |
|
285 |
}
|
286 |
|
287 |
+
/**
|
288 |
+
* Render buttons.
|
289 |
+
*
|
290 |
+
* @return bool|mixed|string|void
|
291 |
+
*/
|
292 |
+
public function render() {
|
293 |
$before_render = $this->before_render();
|
294 |
+
|
295 |
if ( false === $before_render ) {
|
296 |
return false;
|
297 |
}
|
298 |
+
|
299 |
+
$button = '';
|
300 |
+
|
301 |
if ( $this->is_visible() ) {
|
302 |
+
$link = trailingslashit( get_rtmedia_permalink( $this->media->id ) ) . $this->action . '/';
|
303 |
+
$disabled = '';
|
304 |
+
$icon = '';
|
305 |
+
|
306 |
if ( ! $this->is_clickable() ) {
|
307 |
$disabled = ' disabled';
|
308 |
}
|
310 |
if ( isset( $this->icon_class ) && '' !== $this->icon_class ) {
|
311 |
$icon = "<i class='" . esc_attr( $this->icon_class ) . "'></i>";
|
312 |
}
|
313 |
+
|
314 |
$button_start = '<form action="' . esc_url( $link ) . '">';
|
315 |
$button_label = apply_filters( 'rtmedia_' . $this->action . '_label_text', $this->label );
|
316 |
$button = '<button type="submit" id="rtmedia-' . esc_attr( $this->action ) . '-button-' . esc_attr( $this->media->id ) . '" class="rtmedia-' . esc_attr( $this->action )
|
317 |
. ' rtmedia-action-buttons button' . esc_attr( $disabled ) . '" title="' . esc_attr( $button_label ) . '">' . $icon . '<span>' . esc_html( $button_label ) . '</span></button>';
|
318 |
|
319 |
+
/**
|
320 |
+
* Like button is displayed more then 1 time on same page, so giving this button ID will result
|
321 |
+
* in HTML warnings.
|
322 |
+
*/
|
323 |
+
if ( 'like' === $this->action ) {
|
324 |
+
$button = '<button type="submit" class="rtmedia-' . esc_attr( $this->action ) . ' rtmedia-action-buttons button' . esc_attr( $disabled ) . '" title="' . esc_attr( $button_label ) . '">' . $icon . '<span>' . esc_html( $button_label ) . '</span></button>';
|
325 |
+
}
|
326 |
+
|
327 |
+
// Filter the button as required.
|
328 |
$button = apply_filters( 'rtmedia_' . $this->action . '_button_filter', $button );
|
329 |
|
330 |
$button_end = '</form>';
|
336 |
return $button;
|
337 |
}
|
338 |
|
339 |
+
/**
|
340 |
+
* Add buttons.
|
341 |
+
*
|
342 |
+
* @param array $buttons buttons to show.
|
343 |
+
*
|
344 |
+
* @return array
|
345 |
+
*/
|
346 |
+
public function button_filter( $buttons ) {
|
347 |
+
|
348 |
if ( empty( $this->media ) ) {
|
349 |
$this->init();
|
350 |
}
|
354 |
}
|
355 |
|
356 |
/**
|
357 |
+
* Register action.
|
358 |
*
|
359 |
+
* @param array $actions The default array of actions.
|
360 |
*
|
361 |
* @return array $actions Filtered actions array
|
362 |
*/
|
363 |
+
public function register( $actions ) {
|
364 |
if ( empty( $this->media ) ) {
|
365 |
$this->init();
|
366 |
}
|
374 |
* Checks if an id is set
|
375 |
* Creates pre and post process hooks for the action
|
376 |
* Calls the process
|
|
|
377 |
*/
|
378 |
+
public function preprocess() {
|
379 |
global $rtmedia_query;
|
380 |
$this->action_query = $rtmedia_query->action_query;
|
381 |
|
399 |
|
400 |
do_action( 'rtmedia_post_process_' . $this->action, $result );
|
401 |
|
402 |
+
print_r( $result ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r
|
403 |
|
404 |
die();
|
405 |
}
|
409 |
*
|
410 |
* @return integer New count
|
411 |
*/
|
412 |
+
public function process() {
|
413 |
return false;
|
414 |
}
|
415 |
}
|
app/main/controllers/media/RTMediaViewCount.php
CHANGED
@@ -1,17 +1,20 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
/*
|
4 |
-
* To change this template, choose Tools | Templates
|
5 |
-
* and open the template in the editor.
|
6 |
-
*/
|
7 |
-
|
8 |
/**
|
9 |
-
*
|
10 |
*
|
|
|
11 |
* @author ritz
|
12 |
*/
|
|
|
|
|
|
|
|
|
13 |
class RTMediaViewCount extends RTMediaUserInteraction {
|
14 |
-
|
|
|
|
|
|
|
|
|
15 |
$args = array(
|
16 |
'action' => 'view',
|
17 |
'label' => 'view',
|
@@ -22,7 +25,12 @@ class RTMediaViewCount extends RTMediaUserInteraction {
|
|
22 |
add_filter( 'rtmedia_action_buttons_after_delete', array( $this, 'button_filter' ), 99 );
|
23 |
}
|
24 |
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
26 |
/**
|
27 |
* We were using session to store view count for a media by a particular user.
|
28 |
* Session will no more use in rtmedia.
|
@@ -35,15 +43,23 @@ class RTMediaViewCount extends RTMediaUserInteraction {
|
|
35 |
do_action( 'rtmedia_view_media_counts', $this );
|
36 |
}
|
37 |
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
39 |
$user_id = $this->interactor;
|
|
|
40 |
if ( ! $user_id ) {
|
41 |
$user_id = - 1;
|
42 |
}
|
|
|
43 |
$media_id = $this->action_query->id;
|
44 |
$action = $this->action_query->action;
|
45 |
$rtmediainteraction = new RTMediaInteractionModel();
|
46 |
$check_action = $rtmediainteraction->check( $user_id, $media_id, $action );
|
|
|
47 |
if ( $check_action ) {
|
48 |
$results = $rtmediainteraction->get_row( $user_id, $media_id, $action );
|
49 |
$row = $results[0];
|
@@ -65,7 +81,7 @@ class RTMediaViewCount extends RTMediaUserInteraction {
|
|
65 |
$insert_id = $rtmediainteraction->insert( $columns );
|
66 |
}
|
67 |
|
68 |
-
//todo update `views` column in media index table, might be need to write migration as well for old media
|
69 |
global $rtmedia_points_media_id;
|
70 |
$rtmedia_points_media_id = $this->action_query->id;
|
71 |
do_action( 'rtmedia_after_view_media', $this );
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
+
* Handles view count of media.
|
4 |
*
|
5 |
+
* @package rtMedia
|
6 |
* @author ritz
|
7 |
*/
|
8 |
+
|
9 |
+
/**
|
10 |
+
* Class to handle media view count.
|
11 |
+
*/
|
12 |
class RTMediaViewCount extends RTMediaUserInteraction {
|
13 |
+
|
14 |
+
/**
|
15 |
+
* RTMediaViewCount constructor.
|
16 |
+
*/
|
17 |
+
public function __construct() {
|
18 |
$args = array(
|
19 |
'action' => 'view',
|
20 |
'label' => 'view',
|
25 |
add_filter( 'rtmedia_action_buttons_after_delete', array( $this, 'button_filter' ), 99 );
|
26 |
}
|
27 |
|
28 |
+
/**
|
29 |
+
* Renders media view form.
|
30 |
+
*
|
31 |
+
* @return bool|mixed|string|void
|
32 |
+
*/
|
33 |
+
public function render() {
|
34 |
/**
|
35 |
* We were using session to store view count for a media by a particular user.
|
36 |
* Session will no more use in rtmedia.
|
43 |
do_action( 'rtmedia_view_media_counts', $this );
|
44 |
}
|
45 |
|
46 |
+
/**
|
47 |
+
* Process updating view count.
|
48 |
+
*
|
49 |
+
* @return int|void
|
50 |
+
*/
|
51 |
+
public function process() {
|
52 |
$user_id = $this->interactor;
|
53 |
+
|
54 |
if ( ! $user_id ) {
|
55 |
$user_id = - 1;
|
56 |
}
|
57 |
+
|
58 |
$media_id = $this->action_query->id;
|
59 |
$action = $this->action_query->action;
|
60 |
$rtmediainteraction = new RTMediaInteractionModel();
|
61 |
$check_action = $rtmediainteraction->check( $user_id, $media_id, $action );
|
62 |
+
|
63 |
if ( $check_action ) {
|
64 |
$results = $rtmediainteraction->get_row( $user_id, $media_id, $action );
|
65 |
$row = $results[0];
|
81 |
$insert_id = $rtmediainteraction->insert( $columns );
|
82 |
}
|
83 |
|
84 |
+
// todo update `views` column in media index table, might be need to write migration as well for old media.
|
85 |
global $rtmedia_points_media_id;
|
86 |
$rtmedia_points_media_id = $this->action_query->id;
|
87 |
do_action( 'rtmedia_after_view_media', $this );
|
app/main/controllers/privacy/RTMediaFriends.php
CHANGED
@@ -1,21 +1,20 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
/*
|
4 |
-
* To change this template, choose Tools | Templates
|
5 |
-
* and open the template in the editor.
|
6 |
-
*/
|
7 |
-
|
8 |
/**
|
9 |
-
*
|
10 |
*
|
|
|
11 |
* @author saurabh
|
12 |
*/
|
|
|
|
|
|
|
|
|
13 |
class RTMediaFriends {
|
14 |
|
15 |
/**
|
16 |
-
*
|
17 |
*/
|
18 |
-
function __construct() {
|
19 |
if ( ! class_exists( 'BuddyPress' ) ) {
|
20 |
return;
|
21 |
}
|
@@ -24,7 +23,14 @@ class RTMediaFriends {
|
|
24 |
}
|
25 |
}
|
26 |
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
if ( ! class_exists( 'BuddyPress' ) ) {
|
30 |
return array();
|
@@ -45,7 +51,12 @@ class RTMediaFriends {
|
|
45 |
return $friends;
|
46 |
}
|
47 |
|
48 |
-
|
|
|
|
|
|
|
|
|
|
|
49 |
if ( ! class_exists( 'BuddyPress' ) ) {
|
50 |
return;
|
51 |
}
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
+
* Handles rtMedia friends related tasks.
|
4 |
*
|
5 |
+
* @package rtMedia
|
6 |
* @author saurabh
|
7 |
*/
|
8 |
+
|
9 |
+
/**
|
10 |
+
* To Handle rtMedia friends related tasks.
|
11 |
+
*/
|
12 |
class RTMediaFriends {
|
13 |
|
14 |
/**
|
15 |
+
* RTMediaFriends constructor.
|
16 |
*/
|
17 |
+
public function __construct() {
|
18 |
if ( ! class_exists( 'BuddyPress' ) ) {
|
19 |
return;
|
20 |
}
|
23 |
}
|
24 |
}
|
25 |
|
26 |
+
/**
|
27 |
+
* Function to get cached friends.
|
28 |
+
*
|
29 |
+
* @param int $user User ID to get friends.
|
30 |
+
*
|
31 |
+
* @return array|bool|mixed|void
|
32 |
+
*/
|
33 |
+
public function get_friends_cache( $user ) {
|
34 |
|
35 |
if ( ! class_exists( 'BuddyPress' ) ) {
|
36 |
return array();
|
51 |
return $friends;
|
52 |
}
|
53 |
|
54 |
+
/**
|
55 |
+
* Refresh friends cache for user.
|
56 |
+
*
|
57 |
+
* @param int $user User id to refresh cache.
|
58 |
+
*/
|
59 |
+
public static function refresh_friends_cache( $user ) {
|
60 |
if ( ! class_exists( 'BuddyPress' ) ) {
|
61 |
return;
|
62 |
}
|
app/main/controllers/privacy/RTMediaPrivacy.php
CHANGED
@@ -1,31 +1,44 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
*
|
4 |
-
*
|
|
|
5 |
*/
|
6 |
|
7 |
/**
|
8 |
-
*
|
9 |
*
|
10 |
* @author saurabh
|
11 |
*/
|
12 |
class RTMediaPrivacy {
|
13 |
|
14 |
/**
|
|
|
15 |
*
|
16 |
-
* @var object
|
17 |
*/
|
18 |
public $default_privacy;
|
19 |
|
|
|
|
|
|
|
|
|
|
|
20 |
public $rtm_activity_table_alias = 'ra';
|
21 |
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
if ( is_rtmedia_privacy_enable() && $flag ) {
|
24 |
add_action( 'bp_init', array( $this, 'add_nav' ) );
|
25 |
add_action( 'bp_template_content', array( $this, 'content' ) );
|
26 |
add_filter( 'bp_activity_get_user_join_filter', array( $this, 'activity_privacy' ), 10, 6 );
|
27 |
|
28 |
-
// Filter bp_activity_get_user_join_filter to get activity privacy field in loop
|
29 |
add_filter( 'bp_activity_get_user_join_filter', array( $this, 'activity_privacy_sql_field' ), 10, 6 );
|
30 |
|
31 |
add_filter( 'bp_use_legacy_activity_query', array( $this, 'enable_buddypress_privacy' ), 10, 3 );
|
@@ -37,10 +50,10 @@ class RTMediaPrivacy {
|
|
37 |
// To show load more button all the time.
|
38 |
add_filter( 'bp_activity_has_more_items', array( $this, 'rtm_bp_activity_has_more_items' ) );
|
39 |
|
40 |
-
// Add nonce field to change activity privacy option
|
41 |
add_action( 'template_notices', array( $this, 'add_activity_privacy_nonce' ) );
|
42 |
|
43 |
-
// save update privacy value
|
44 |
add_action( 'wp_ajax_rtm_change_activity_privacy', array( $this, 'rtm_change_activity_privacy' ) );
|
45 |
|
46 |
}
|
@@ -64,13 +77,16 @@ class RTMediaPrivacy {
|
|
64 |
*
|
65 |
* Show privacy dropdown inside activity loop along with activity meta buttons.
|
66 |
*/
|
67 |
-
function update_activity_privacy_option() {
|
68 |
global $activities_template;
|
69 |
$rtmedia_activity_types = array( 'rtmedia_comment_activity', 'rtmedia_like_activity', 'activity_comment' );
|
|
|
70 |
if ( function_exists( 'bp_activity_user_can_delete' ) && bp_activity_user_can_delete()
|
71 |
&& ( ! bp_is_groups_component() ) && is_rtmedia_privacy_user_overide()
|
72 |
&& apply_filters( 'rtm_load_bp_activity_privacy_update_ui', true )
|
73 |
-
&& isset( $activities_template->activity )
|
|
|
|
|
74 |
) {
|
75 |
|
76 |
$selected = 0;
|
@@ -78,8 +94,8 @@ class RTMediaPrivacy {
|
|
78 |
$selected = intval( $activities_template->activity->privacy );
|
79 |
}
|
80 |
|
81 |
-
//todo strict standard error
|
82 |
-
if ( isset( $activities_template->activity->privacy ) &&
|
83 |
self::select_privacy_ui( true, 'rtm-ac-privacy-' . $activities_template->activity->id, array( 'rtm-activity-privacy-opt' ), $selected );
|
84 |
}
|
85 |
}
|
@@ -88,52 +104,58 @@ class RTMediaPrivacy {
|
|
88 |
/**
|
89 |
* Add nonce field for activity privacy change action verification
|
90 |
*/
|
91 |
-
function add_activity_privacy_nonce() {
|
92 |
wp_nonce_field( 'rtmedia_activity_privacy_nonce', 'rtmedia_activity_privacy_nonce' );
|
93 |
}
|
94 |
|
95 |
-
|
96 |
-
|
|
|
|
|
|
|
|
|
97 |
$privacy = filter_input( INPUT_POST, 'privacy', FILTER_SANITIZE_NUMBER_INT );
|
98 |
$activity_id = filter_input( INPUT_POST, 'activity_id', FILTER_SANITIZE_NUMBER_INT );
|
99 |
|
100 |
if ( wp_verify_nonce( $nonce, 'rtmedia_activity_privacy_nonce' ) ) {
|
101 |
$media_ids_of_activity = array();
|
102 |
-
$rtm_activity_model
|
103 |
-
$is_ac_privacy_exist
|
104 |
|
105 |
$privacy = intval( $privacy );
|
106 |
$activity_id = intval( $activity_id );
|
107 |
|
108 |
if ( ! $is_ac_privacy_exist ) {
|
109 |
-
// Very first privacy entry for this activity
|
110 |
-
$status = $rtm_activity_model->insert(
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
|
|
|
|
115 |
} else {
|
116 |
-
// Just update the existing value
|
117 |
$status = $rtm_activity_model->update( array( 'privacy' => $privacy ), array( 'activity_id' => $activity_id ) );
|
118 |
}
|
119 |
|
120 |
-
// update privacy of corresponding media
|
121 |
$media_model = new RTMediaModel();
|
122 |
$activity_media = $media_model->get( array( 'activity_id' => $activity_id ) );
|
123 |
if ( ! empty( $activity_media ) && is_array( $activity_media ) ) {
|
124 |
foreach ( $activity_media as $single_media ) {
|
125 |
-
|
126 |
$media_ids_of_activity[] = $single_media->id;
|
127 |
|
128 |
$where = array( 'id' => $single_media->id );
|
129 |
$columns = array( 'privacy' => $privacy );
|
130 |
|
131 |
-
// update media privacy
|
132 |
$media_model->update( $columns, $where );
|
133 |
}
|
134 |
}
|
135 |
|
136 |
-
|
137 |
$rtm_activity_model->profile_activity_update( $media_ids_of_activity, $privacy, $activity_id );
|
138 |
|
139 |
if ( false === $status ) {
|
@@ -147,9 +169,19 @@ class RTMediaPrivacy {
|
|
147 |
}
|
148 |
}
|
149 |
|
150 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
151 |
global $rtmedia;
|
152 |
$option = $rtmedia->options;
|
|
|
153 |
if ( isset( $option['privacy_enabled'] ) && 0 !== intval( $option['privacy_enabled'] ) ) {
|
154 |
if ( 'BP_Activity_Activity::get' === $method ) {
|
155 |
$flag = true;
|
@@ -159,7 +191,17 @@ class RTMediaPrivacy {
|
|
159 |
return $flag;
|
160 |
}
|
161 |
|
162 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
163 |
global $rtmedia;
|
164 |
|
165 |
if ( ! is_rtmedia_privacy_enable() ) {
|
@@ -177,7 +219,7 @@ class RTMediaPrivacy {
|
|
177 |
} elseif ( isset( $rtmedia_media->privacy ) ) {
|
178 |
$default = $rtmedia_media->privacy;
|
179 |
} else {
|
180 |
-
//todo user attribute
|
181 |
$default = get_user_meta( get_current_user_id(), 'rtmedia-default-privacy', true );
|
182 |
if ( ( false === $default ) || '' === $default ) {
|
183 |
$default = get_rtmedia_default_privacy();
|
@@ -195,15 +237,19 @@ class RTMediaPrivacy {
|
|
195 |
$attributes_class = array_merge( $attributes_class, $element_class );
|
196 |
}
|
197 |
}
|
|
|
198 |
$attributes = array(
|
199 |
'name' => 'privacy',
|
200 |
'class' => $attributes_class,
|
201 |
);
|
|
|
202 |
if ( $element_id && '' !== $element_id ) {
|
203 |
$attributes['id'] = $element_id;
|
204 |
}
|
|
|
205 |
global $rtmedia;
|
206 |
$privacy_levels = $rtmedia->privacy_settings['levels'];
|
|
|
207 |
if ( class_exists( 'BuddyPress' ) ) {
|
208 |
if ( ! bp_is_active( 'friends' ) ) {
|
209 |
unset( $privacy_levels[40] );
|
@@ -211,6 +257,7 @@ class RTMediaPrivacy {
|
|
211 |
} else {
|
212 |
unset( $privacy_levels[40] );
|
213 |
}
|
|
|
214 |
foreach ( $privacy_levels as $key => $value ) {
|
215 |
$privacy = explode( ' - ', $value );
|
216 |
$attributes['rtForm_options'][] = array(
|
@@ -220,32 +267,44 @@ class RTMediaPrivacy {
|
|
220 |
}
|
221 |
|
222 |
if ( $echo ) {
|
223 |
-
echo $form->get_select( $attributes )
|
224 |
} else {
|
225 |
return $form->get_select( $attributes );
|
226 |
}
|
227 |
}
|
228 |
|
229 |
-
|
230 |
-
|
|
|
|
|
|
|
|
|
231 |
return 0;
|
232 |
}
|
233 |
|
234 |
-
|
235 |
-
|
|
|
|
|
|
|
|
|
236 |
global $rtmedia;
|
237 |
|
238 |
return rtmedia_get_site_option( 'privacy_settings' );
|
239 |
}
|
240 |
|
241 |
-
|
242 |
-
|
243 |
-
|
|
|
|
|
244 |
}
|
245 |
|
246 |
-
|
247 |
-
|
248 |
-
|
|
|
|
|
249 |
|
250 |
if ( false === $default_privacy ) {
|
251 |
$default_privacy = $this->site_default();
|
@@ -256,55 +315,75 @@ class RTMediaPrivacy {
|
|
256 |
}
|
257 |
}
|
258 |
|
259 |
-
|
260 |
-
|
|
|
|
|
|
|
|
|
261 |
global $bp_media;
|
262 |
$options = $bp_media->options;
|
|
|
263 |
if ( ! array_key_exists( 'privacy_enabled', $options ) ) {
|
264 |
return false;
|
265 |
-
}
|
266 |
-
|
267 |
-
return false;
|
268 |
-
}
|
269 |
}
|
270 |
|
271 |
return true;
|
272 |
}
|
273 |
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
|
|
|
|
|
|
|
|
|
|
278 |
if ( false === $user_id ) {
|
279 |
global $bp;
|
280 |
$user_id = $bp->loggedin_user->id;
|
281 |
}
|
282 |
|
283 |
-
//todo user attribute
|
284 |
return update_user_meta( $user_id, 'bp_media_privacy', $level );
|
285 |
}
|
286 |
|
287 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
288 |
if ( false === $user_id ) {
|
289 |
global $bp;
|
290 |
$user_id = $bp->loggedin_user->id;
|
291 |
}
|
292 |
-
//todo user attribute
|
293 |
$user_privacy = get_user_meta( $user_id, 'bp_media_privacy', true );
|
294 |
|
295 |
return $user_privacy;
|
296 |
}
|
297 |
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
|
|
|
|
|
|
302 |
if ( false === BPMediaPrivacy::is_enabled() ) {
|
303 |
return;
|
304 |
}
|
|
|
305 |
if ( false === $object_id ) {
|
306 |
return;
|
307 |
}
|
|
|
308 |
$privacy = BPMediaPrivacy::get_privacy( $object_id );
|
309 |
$parent = get_post_field( 'post_parent', $object_id, 'raw' );
|
310 |
$parent_privacy = BPMediaPrivacy::get_privacy( $parent );
|
@@ -320,7 +399,10 @@ class RTMediaPrivacy {
|
|
320 |
return $privacy;
|
321 |
}
|
322 |
|
323 |
-
|
|
|
|
|
|
|
324 |
|
325 |
if ( bp_displayed_user_domain() ) {
|
326 |
$user_domain = bp_displayed_user_domain();
|
@@ -333,9 +415,11 @@ class RTMediaPrivacy {
|
|
333 |
if ( ! is_rtmedia_profile_media_enable() ) {
|
334 |
return;
|
335 |
}
|
|
|
336 |
if ( ! is_rtmedia_privacy_enable() ) {
|
337 |
return;
|
338 |
}
|
|
|
339 |
if ( ! is_rtmedia_privacy_user_overide() ) {
|
340 |
return;
|
341 |
}
|
@@ -343,66 +427,79 @@ class RTMediaPrivacy {
|
|
343 |
$settings_link = trailingslashit( $user_domain . 'settings' );
|
344 |
|
345 |
$defaults = array(
|
346 |
-
'name' => $this->title(), // Display name for the nav item
|
347 |
-
'slug' => 'privacy', // URL slug for the nav item
|
348 |
-
'parent_slug' => 'settings', // URL slug of the parent nav item
|
349 |
-
'parent_url' => $settings_link, // URL of the parent item
|
350 |
-
'item_css_id' => 'rtmedia-privacy-settings', // The CSS ID to apply to the HTML of the nav item
|
351 |
'user_has_access' => true, // Can the logged in user see this nav item?
|
352 |
'site_admin_only' => false, // Can only site admins see this nav item?
|
353 |
-
'position' => 80, // Index of where this nav item should be positioned
|
354 |
-
'screen_function' => array( $this, 'settings_ui' ), // The name of the function to run when clicked
|
355 |
-
'link' => ''
|
356 |
);
|
357 |
bp_core_new_subnav_item( $defaults );
|
358 |
}
|
359 |
|
360 |
-
|
|
|
|
|
|
|
361 |
if ( bp_action_variables() ) {
|
362 |
bp_do_404();
|
363 |
|
364 |
return;
|
365 |
}
|
366 |
|
367 |
-
// Load the template
|
368 |
bp_core_load_template( apply_filters( 'bp_settings_screen_delete_account', 'members/single/plugins' ) );
|
369 |
}
|
370 |
|
371 |
/**
|
372 |
-
*
|
373 |
*/
|
374 |
-
function rt_privacy_settings_action() {
|
375 |
if ( 'privacy' !== buddypress()->current_action ) {
|
376 |
return;
|
377 |
}
|
378 |
|
379 |
-
$default_privacy = filter_input( INPUT_POST, 'rtmedia-default-privacy', FILTER_SANITIZE_STRING );
|
380 |
-
$nonce = filter_input( INPUT_POST, 'rtmedia_member_settings_privacy', FILTER_SANITIZE_STRING );
|
|
|
|
|
381 |
|
382 |
-
if ( null !== $default_privacy ) {
|
383 |
$status = false;
|
384 |
if ( wp_verify_nonce( $nonce, 'rtmedia_member_settings_privacy' ) ) {
|
385 |
-
//todo user attribute
|
386 |
$status = update_user_meta( get_current_user_id(), 'rtmedia-default-privacy', $default_privacy );
|
387 |
}
|
|
|
|
|
|
|
|
|
388 |
if ( false === $status ) {
|
389 |
$feedback = esc_html__( 'No changes were made to your account.', 'buddypress-media' );
|
390 |
$feedback_type = 'error';
|
391 |
-
}
|
392 |
$feedback = esc_html__( 'Your default privacy settings saved successfully.', 'buddypress-media' );
|
393 |
$feedback_type = 'success';
|
394 |
}
|
|
|
395 |
bp_core_add_message( $feedback, $feedback_type );
|
396 |
do_action( 'bp_core_general_settings_after_save' );
|
397 |
bp_core_redirect( bp_displayed_user_domain() . bp_get_settings_slug() . '/privacy/' );
|
398 |
}
|
399 |
}
|
400 |
|
401 |
-
|
|
|
|
|
|
|
402 |
if ( 'privacy' !== buddypress()->current_action ) {
|
403 |
return;
|
404 |
}
|
405 |
-
|
|
|
406 |
$default_privacy = get_user_meta( get_current_user_id(), 'rtmedia-default-privacy', true );
|
407 |
if ( false === $default_privacy || '' === $default_privacy ) {
|
408 |
$default_privacy = get_rtmedia_default_privacy();
|
@@ -416,26 +513,44 @@ class RTMediaPrivacy {
|
|
416 |
<div class="rtm-title"><h3><?php esc_html_e( 'Default Privacy', 'buddypress-media' ); ?></h3></div>
|
417 |
<div class="rtm-privacy-levels">
|
418 |
<?php foreach ( $rtmedia->privacy_settings['levels'] as $level => $data ) { ?>
|
419 |
-
<label
|
420 |
-
|
421 |
-
|
|
|
|
|
422 |
<?php } ?>
|
423 |
</div>
|
424 |
</div>
|
425 |
</div>
|
426 |
<div class="submit">
|
427 |
-
<input type="submit" name="submit" value="<?php esc_attr_e( 'Save Changes', 'buddypress-media' ); ?>"
|
428 |
-
id="submit" class="auto">
|
429 |
</div>
|
430 |
</form>
|
431 |
<?php
|
432 |
}
|
433 |
|
434 |
-
|
|
|
|
|
|
|
|
|
|
|
435 |
return esc_html__( 'Privacy', 'buddypress-media' );
|
436 |
}
|
437 |
|
438 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
439 |
if ( is_rt_admin() ) {
|
440 |
return $sql;
|
441 |
}
|
@@ -451,10 +566,12 @@ class RTMediaPrivacy {
|
|
451 |
$user = 0;
|
452 |
}
|
453 |
|
454 |
-
// admin has upgraded rtmedia activity so we can use rt_rtm_activity table for rtmedia related activity filters
|
455 |
if ( $this->can_use_rtm_ac_privacy() ) {
|
|
|
456 |
$rtmedia_activity_model = new RTMediaActivityModel();
|
457 |
-
$where
|
|
|
458 |
if ( $user ) {
|
459 |
$where .= "OR (({$this->rtm_activity_table_alias}.privacy=20)";
|
460 |
$where .= " OR (a.user_id={$user} AND {$this->rtm_activity_table_alias}.privacy >= 40)";
|
@@ -465,7 +582,7 @@ class RTMediaPrivacy {
|
|
465 |
if ( isset( $friends ) && ! empty( $friends ) ) {
|
466 |
$in_str_arr = array_fill( 0, count( $friends ), '%d' );
|
467 |
$in_str = join( ',', $in_str_arr );
|
468 |
-
$where
|
469 |
}
|
470 |
}
|
471 |
}
|
@@ -478,14 +595,16 @@ class RTMediaPrivacy {
|
|
478 |
|
479 |
$select_sql .= " ,{$this->rtm_activity_table_alias}.privacy ";
|
480 |
|
481 |
-
$from_sql = $wpdb->prepare( " FROM {$bp->activity->table_name} a LEFT JOIN {$wpdb->users} u ON a.user_id = u.ID LEFT JOIN {$rtmedia_activity_model->table_name} {$this->rtm_activity_table_alias} ON ( a.id = {$this->rtm_activity_table_alias}.activity_id and ra.blog_id = %d ) ", get_current_blog_id() ); //
|
482 |
|
483 |
// removed NOT EXISTS check for `rtmedia_privacy` activty meta value.
|
484 |
-
// check git history for more details ;)
|
485 |
$where_sql = $where_sql . " AND ({$where})";
|
486 |
$newsql = "{$select_sql} {$from_sql} {$where_sql} ORDER BY a.date_recorded {$sort} {$pag_sql}";
|
487 |
} else {
|
|
|
488 |
$where .= ' (m.max_privacy is NULL OR m.max_privacy <= 0) ';
|
|
|
489 |
if ( $user ) {
|
490 |
$where .= 'OR ((m.max_privacy=20)';
|
491 |
$where .= " OR (a.user_id={$user} AND m.max_privacy >= 40)";
|
@@ -500,16 +619,19 @@ class RTMediaPrivacy {
|
|
500 |
}
|
501 |
$where .= ')';
|
502 |
}
|
|
|
503 |
if ( function_exists( 'bp_core_get_table_prefix' ) ) {
|
504 |
$bp_prefix = bp_core_get_table_prefix();
|
505 |
} else {
|
506 |
$bp_prefix = '';
|
507 |
}
|
|
|
508 |
if ( strpos( $select_sql, 'SELECT DISTINCT' ) === false ) {
|
509 |
$select_sql = str_replace( 'SELECT', 'SELECT DISTINCT', $select_sql );
|
510 |
}
|
|
|
511 |
$media_table = "SELECT *, max( privacy ) as max_privacy from {$rtmedia_model->table_name} group by activity_id";
|
512 |
-
$from_sql = $wpdb->prepare( " FROM {$bp->activity->table_name} a LEFT JOIN {$wpdb->users} u ON a.user_id = u.ID LEFT JOIN ( $media_table ) m ON ( a.id = m.activity_id AND m.blog_id = %d ) ", get_current_blog_id() ); //
|
513 |
$where_sql = $where_sql . " AND (NOT EXISTS (SELECT m.activity_id FROM {$bp_prefix}bp_activity_meta m WHERE m.meta_key='rtmedia_privacy' AND m.activity_id=a.id) OR ( {$where} ) )";
|
514 |
$newsql = "{$select_sql} {$from_sql} {$where_sql} ORDER BY a.date_recorded {$sort} {$pag_sql}";
|
515 |
}
|
@@ -523,24 +645,24 @@ class RTMediaPrivacy {
|
|
523 |
* Use only if current user has admin capability because for non admin users privacy field will be added in
|
524 |
* privacy filter query itself.
|
525 |
*
|
526 |
-
* @param $sql
|
527 |
-
* @param $select_sql
|
528 |
-
* @param $from_sql
|
529 |
-
* @param $where_sql
|
530 |
-
* @param $sort
|
531 |
-
* @param string $pag_sql
|
532 |
*
|
533 |
* @return string
|
534 |
*/
|
535 |
-
function activity_privacy_sql_field( $sql, $select_sql, $from_sql, $where_sql, $sort, $pag_sql = '' ) {
|
536 |
global $wpdb, $bp;
|
537 |
|
538 |
if ( $this->can_use_rtm_ac_privacy() && is_rt_admin() ) {
|
539 |
$rtmedia_activity_model = new RTMediaActivityModel();
|
540 |
if ( strpos( $sql, $rtmedia_activity_model->table_name ) === false ) {
|
541 |
$select_sql .= " ,{$this->rtm_activity_table_alias}.privacy ";
|
542 |
-
$from_sql
|
543 |
-
$sql
|
544 |
}
|
545 |
}
|
546 |
|
@@ -552,7 +674,7 @@ class RTMediaPrivacy {
|
|
552 |
*
|
553 |
* @return bool|mixed|void
|
554 |
*/
|
555 |
-
function can_use_rtm_ac_privacy() {
|
556 |
return rtmedia_get_site_option( 'rtmedia_activity_done_upgrade' );
|
557 |
}
|
558 |
}
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* Handles media activity privacy operations.
|
4 |
+
*
|
5 |
+
* @package rtMedia
|
6 |
*/
|
7 |
|
8 |
/**
|
9 |
+
* Class to handle media activity privacy operations.
|
10 |
*
|
11 |
* @author saurabh
|
12 |
*/
|
13 |
class RTMediaPrivacy {
|
14 |
|
15 |
/**
|
16 |
+
* Default application wide privacy levels
|
17 |
*
|
18 |
+
* @var object
|
19 |
*/
|
20 |
public $default_privacy;
|
21 |
|
22 |
+
/**
|
23 |
+
* Activity table name.
|
24 |
+
*
|
25 |
+
* @var string
|
26 |
+
*/
|
27 |
public $rtm_activity_table_alias = 'ra';
|
28 |
|
29 |
+
/**
|
30 |
+
* RTMediaPrivacy constructor.
|
31 |
+
*
|
32 |
+
* @param bool $flag Flag to enable privacy for rtMedia.
|
33 |
+
*/
|
34 |
+
public function __construct( $flag = true ) {
|
35 |
+
|
36 |
if ( is_rtmedia_privacy_enable() && $flag ) {
|
37 |
add_action( 'bp_init', array( $this, 'add_nav' ) );
|
38 |
add_action( 'bp_template_content', array( $this, 'content' ) );
|
39 |
add_filter( 'bp_activity_get_user_join_filter', array( $this, 'activity_privacy' ), 10, 6 );
|
40 |
|
41 |
+
// Filter bp_activity_get_user_join_filter to get activity privacy field in loop.
|
42 |
add_filter( 'bp_activity_get_user_join_filter', array( $this, 'activity_privacy_sql_field' ), 10, 6 );
|
43 |
|
44 |
add_filter( 'bp_use_legacy_activity_query', array( $this, 'enable_buddypress_privacy' ), 10, 3 );
|
50 |
// To show load more button all the time.
|
51 |
add_filter( 'bp_activity_has_more_items', array( $this, 'rtm_bp_activity_has_more_items' ) );
|
52 |
|
53 |
+
// Add nonce field to change activity privacy option.
|
54 |
add_action( 'template_notices', array( $this, 'add_activity_privacy_nonce' ) );
|
55 |
|
56 |
+
// save update privacy value.
|
57 |
add_action( 'wp_ajax_rtm_change_activity_privacy', array( $this, 'rtm_change_activity_privacy' ) );
|
58 |
|
59 |
}
|
77 |
*
|
78 |
* Show privacy dropdown inside activity loop along with activity meta buttons.
|
79 |
*/
|
80 |
+
public function update_activity_privacy_option() {
|
81 |
global $activities_template;
|
82 |
$rtmedia_activity_types = array( 'rtmedia_comment_activity', 'rtmedia_like_activity', 'activity_comment' );
|
83 |
+
|
84 |
if ( function_exists( 'bp_activity_user_can_delete' ) && bp_activity_user_can_delete()
|
85 |
&& ( ! bp_is_groups_component() ) && is_rtmedia_privacy_user_overide()
|
86 |
&& apply_filters( 'rtm_load_bp_activity_privacy_update_ui', true )
|
87 |
+
&& isset( $activities_template->activity )
|
88 |
+
&& isset( $activities_template->activity->type )
|
89 |
+
&& ! in_array( $activities_template->activity->type, $rtmedia_activity_types, true )
|
90 |
) {
|
91 |
|
92 |
$selected = 0;
|
94 |
$selected = intval( $activities_template->activity->privacy );
|
95 |
}
|
96 |
|
97 |
+
// todo strict standard error.
|
98 |
+
if ( isset( $activities_template->activity->privacy ) && 80 !== intval( $activities_template->activity->privacy ) ) {
|
99 |
self::select_privacy_ui( true, 'rtm-ac-privacy-' . $activities_template->activity->id, array( 'rtm-activity-privacy-opt' ), $selected );
|
100 |
}
|
101 |
}
|
104 |
/**
|
105 |
* Add nonce field for activity privacy change action verification
|
106 |
*/
|
107 |
+
public function add_activity_privacy_nonce() {
|
108 |
wp_nonce_field( 'rtmedia_activity_privacy_nonce', 'rtmedia_activity_privacy_nonce' );
|
109 |
}
|
110 |
|
111 |
+
/**
|
112 |
+
* Ajax callback to change activity privacy.
|
113 |
+
*/
|
114 |
+
public function rtm_change_activity_privacy() {
|
115 |
+
|
116 |
+
$nonce = sanitize_text_field( filter_input( INPUT_POST, 'nonce', FILTER_SANITIZE_STRING ) );
|
117 |
$privacy = filter_input( INPUT_POST, 'privacy', FILTER_SANITIZE_NUMBER_INT );
|
118 |
$activity_id = filter_input( INPUT_POST, 'activity_id', FILTER_SANITIZE_NUMBER_INT );
|
119 |
|
120 |
if ( wp_verify_nonce( $nonce, 'rtmedia_activity_privacy_nonce' ) ) {
|
121 |
$media_ids_of_activity = array();
|
122 |
+
$rtm_activity_model = new RTMediaActivityModel();
|
123 |
+
$is_ac_privacy_exist = $rtm_activity_model->check( $activity_id );
|
124 |
|
125 |
$privacy = intval( $privacy );
|
126 |
$activity_id = intval( $activity_id );
|
127 |
|
128 |
if ( ! $is_ac_privacy_exist ) {
|
129 |
+
// Very first privacy entry for this activity.
|
130 |
+
$status = $rtm_activity_model->insert(
|
131 |
+
array(
|
132 |
+
'privacy' => $privacy,
|
133 |
+
'activity_id' => $activity_id,
|
134 |
+
'user_id' => get_current_user_id(),
|
135 |
+
)
|
136 |
+
);
|
137 |
} else {
|
138 |
+
// Just update the existing value.
|
139 |
$status = $rtm_activity_model->update( array( 'privacy' => $privacy ), array( 'activity_id' => $activity_id ) );
|
140 |
}
|
141 |
|
142 |
+
// update privacy of corresponding media.
|
143 |
$media_model = new RTMediaModel();
|
144 |
$activity_media = $media_model->get( array( 'activity_id' => $activity_id ) );
|
145 |
if ( ! empty( $activity_media ) && is_array( $activity_media ) ) {
|
146 |
foreach ( $activity_media as $single_media ) {
|
147 |
+
// get all the media ids in the activity.
|
148 |
$media_ids_of_activity[] = $single_media->id;
|
149 |
|
150 |
$where = array( 'id' => $single_media->id );
|
151 |
$columns = array( 'privacy' => $privacy );
|
152 |
|
153 |
+
// update media privacy.
|
154 |
$media_model->update( $columns, $where );
|
155 |
}
|
156 |
}
|
157 |
|
158 |
+
// is the activate has any media then move the like and comment of that media to for the privacy.
|
159 |
$rtm_activity_model->profile_activity_update( $media_ids_of_activity, $privacy, $activity_id );
|
160 |
|
161 |
if ( false === $status ) {
|
169 |
}
|
170 |
}
|
171 |
|
172 |
+
/**
|
173 |
+
* Function to enable buddypress privacy.
|
174 |
+
*
|
175 |
+
* @param bool $flag Privacy enabled or not.
|
176 |
+
* @param string $method Method name to check.
|
177 |
+
* @param array $func_args Arguments array.
|
178 |
+
*
|
179 |
+
* @return bool
|
180 |
+
*/
|
181 |
+
public function enable_buddypress_privacy( $flag, $method, $func_args ) {
|
182 |
global $rtmedia;
|
183 |
$option = $rtmedia->options;
|
184 |
+
|
185 |
if ( isset( $option['privacy_enabled'] ) && 0 !== intval( $option['privacy_enabled'] ) ) {
|
186 |
if ( 'BP_Activity_Activity::get' === $method ) {
|
187 |
$flag = true;
|
191 |
return $flag;
|
192 |
}
|
193 |
|
194 |
+
/**
|
195 |
+
* Generates select UI for privacy setting.
|
196 |
+
*
|
197 |
+
* @param bool $echo To echo or not.
|
198 |
+
* @param bool|string $element_id HTML Element id.
|
199 |
+
* @param array $element_class HTML Element classes.
|
200 |
+
* @param bool|string $selected Selected option.
|
201 |
+
*
|
202 |
+
* @return bool|string
|
203 |
+
*/
|
204 |
+
public function select_privacy_ui( $echo = true, $element_id = false, $element_class = array(), $selected = false ) {
|
205 |
global $rtmedia;
|
206 |
|
207 |
if ( ! is_rtmedia_privacy_enable() ) {
|
219 |
} elseif ( isset( $rtmedia_media->privacy ) ) {
|
220 |
$default = $rtmedia_media->privacy;
|
221 |
} else {
|
222 |
+
// todo user attribute.
|
223 |
$default = get_user_meta( get_current_user_id(), 'rtmedia-default-privacy', true );
|
224 |
if ( ( false === $default ) || '' === $default ) {
|
225 |
$default = get_rtmedia_default_privacy();
|
237 |
$attributes_class = array_merge( $attributes_class, $element_class );
|
238 |
}
|
239 |
}
|
240 |
+
|
241 |
$attributes = array(
|
242 |
'name' => 'privacy',
|
243 |
'class' => $attributes_class,
|
244 |
);
|
245 |
+
|
246 |
if ( $element_id && '' !== $element_id ) {
|
247 |
$attributes['id'] = $element_id;
|
248 |
}
|
249 |
+
|
250 |
global $rtmedia;
|
251 |
$privacy_levels = $rtmedia->privacy_settings['levels'];
|
252 |
+
|
253 |
if ( class_exists( 'BuddyPress' ) ) {
|
254 |
if ( ! bp_is_active( 'friends' ) ) {
|
255 |
unset( $privacy_levels[40] );
|
257 |
} else {
|
258 |
unset( $privacy_levels[40] );
|
259 |
}
|
260 |
+
|
261 |
foreach ( $privacy_levels as $key => $value ) {
|
262 |
$privacy = explode( ' - ', $value );
|
263 |
$attributes['rtForm_options'][] = array(
|
267 |
}
|
268 |
|
269 |
if ( $echo ) {
|
270 |
+
echo wp_kses( $form->get_select( $attributes ), RTMedia::expanded_allowed_tags() );
|
271 |
} else {
|
272 |
return $form->get_select( $attributes );
|
273 |
}
|
274 |
}
|
275 |
|
276 |
+
/**
|
277 |
+
* Get system default privacy.
|
278 |
+
*
|
279 |
+
* @return int
|
280 |
+
*/
|
281 |
+
public function system_default() {
|
282 |
return 0;
|
283 |
}
|
284 |
|
285 |
+
/**
|
286 |
+
* Get default privacy.
|
287 |
+
*
|
288 |
+
* @return bool|mixed|void
|
289 |
+
*/
|
290 |
+
public function site_default() {
|
291 |
global $rtmedia;
|
292 |
|
293 |
return rtmedia_get_site_option( 'privacy_settings' );
|
294 |
}
|
295 |
|
296 |
+
/**
|
297 |
+
* Get user default privacy.
|
298 |
+
*/
|
299 |
+
public function user_default() {
|
300 |
+
return 0;
|
301 |
}
|
302 |
|
303 |
+
/**
|
304 |
+
* Get default privacy.
|
305 |
+
*/
|
306 |
+
public function get_default() {
|
307 |
+
$default_privacy = $this->user_default(); // todo:check if function use is correct.
|
308 |
|
309 |
if ( false === $default_privacy ) {
|
310 |
$default_privacy = $this->site_default();
|
315 |
}
|
316 |
}
|
317 |
|
318 |
+
/**
|
319 |
+
* Check if privacy is enabled or not.
|
320 |
+
*
|
321 |
+
* @return bool
|
322 |
+
*/
|
323 |
+
public static function is_enabled() {
|
324 |
global $bp_media;
|
325 |
$options = $bp_media->options;
|
326 |
+
|
327 |
if ( ! array_key_exists( 'privacy_enabled', $options ) ) {
|
328 |
return false;
|
329 |
+
} elseif ( true !== $options['privacy_enabled'] ) {
|
330 |
+
return false;
|
|
|
|
|
331 |
}
|
332 |
|
333 |
return true;
|
334 |
}
|
335 |
|
336 |
+
/**
|
337 |
+
* Set user default privacy.
|
338 |
+
*
|
339 |
+
* @param int $level Privacy level.
|
340 |
+
* @param bool $user_id User Id.
|
341 |
+
*
|
342 |
+
* @return bool|int
|
343 |
+
*/
|
344 |
+
public static function save_user_default( $level = 0, $user_id = false ) {
|
345 |
if ( false === $user_id ) {
|
346 |
global $bp;
|
347 |
$user_id = $bp->loggedin_user->id;
|
348 |
}
|
349 |
|
350 |
+
// todo user attribute.
|
351 |
return update_user_meta( $user_id, 'bp_media_privacy', $level );
|
352 |
}
|
353 |
|
354 |
+
/**
|
355 |
+
* Get media privacy from user id.
|
356 |
+
*
|
357 |
+
* @param bool $user_id User ID.
|
358 |
+
*
|
359 |
+
* @return mixed
|
360 |
+
*/
|
361 |
+
public static function get_user_default( $user_id = false ) {
|
362 |
if ( false === $user_id ) {
|
363 |
global $bp;
|
364 |
$user_id = $bp->loggedin_user->id;
|
365 |
}
|
366 |
+
// todo user attribute.
|
367 |
$user_privacy = get_user_meta( $user_id, 'bp_media_privacy', true );
|
368 |
|
369 |
return $user_privacy;
|
370 |
}
|
371 |
|
372 |
+
/**
|
373 |
+
* Check privacy of given object id.
|
374 |
+
*
|
375 |
+
* @param bool $object_id Object id to check.
|
376 |
+
*/
|
377 |
+
public static function required_access( $object_id = false ) {
|
378 |
+
|
379 |
if ( false === BPMediaPrivacy::is_enabled() ) {
|
380 |
return;
|
381 |
}
|
382 |
+
|
383 |
if ( false === $object_id ) {
|
384 |
return;
|
385 |
}
|
386 |
+
|
387 |
$privacy = BPMediaPrivacy::get_privacy( $object_id );
|
388 |
$parent = get_post_field( 'post_parent', $object_id, 'raw' );
|
389 |
$parent_privacy = BPMediaPrivacy::get_privacy( $parent );
|
399 |
return $privacy;
|
400 |
}
|
401 |
|
402 |
+
/**
|
403 |
+
* Add navigation menu for privacy settings.
|
404 |
+
*/
|
405 |
+
public function add_nav() {
|
406 |
|
407 |
if ( bp_displayed_user_domain() ) {
|
408 |
$user_domain = bp_displayed_user_domain();
|
415 |
if ( ! is_rtmedia_profile_media_enable() ) {
|
416 |
return;
|
417 |
}
|
418 |
+
|
419 |
if ( ! is_rtmedia_privacy_enable() ) {
|
420 |
return;
|
421 |
}
|
422 |
+
|
423 |
if ( ! is_rtmedia_privacy_user_overide() ) {
|
424 |
return;
|
425 |
}
|
427 |
$settings_link = trailingslashit( $user_domain . 'settings' );
|
428 |
|
429 |
$defaults = array(
|
430 |
+
'name' => $this->title(), // Display name for the nav item.
|
431 |
+
'slug' => 'privacy', // URL slug for the nav item.
|
432 |
+
'parent_slug' => 'settings', // URL slug of the parent nav item.
|
433 |
+
'parent_url' => $settings_link, // URL of the parent item.
|
434 |
+
'item_css_id' => 'rtmedia-privacy-settings', // The CSS ID to apply to the HTML of the nav item.
|
435 |
'user_has_access' => true, // Can the logged in user see this nav item?
|
436 |
'site_admin_only' => false, // Can only site admins see this nav item?
|
437 |
+
'position' => 80, // Index of where this nav item should be positioned.
|
438 |
+
'screen_function' => array( $this, 'settings_ui' ), // The name of the function to run when clicked.
|
439 |
+
'link' => '', // The link for the subnav item; optional, not usually required.
|
440 |
);
|
441 |
bp_core_new_subnav_item( $defaults );
|
442 |
}
|
443 |
|
444 |
+
/**
|
445 |
+
* Load setting UI.
|
446 |
+
*/
|
447 |
+
public function settings_ui() {
|
448 |
if ( bp_action_variables() ) {
|
449 |
bp_do_404();
|
450 |
|
451 |
return;
|
452 |
}
|
453 |
|
454 |
+
// Load the template.
|
455 |
bp_core_load_template( apply_filters( 'bp_settings_screen_delete_account', 'members/single/plugins' ) );
|
456 |
}
|
457 |
|
458 |
/**
|
459 |
+
* Changing and saving of privacy setting save action
|
460 |
*/
|
461 |
+
public function rt_privacy_settings_action() {
|
462 |
if ( 'privacy' !== buddypress()->current_action ) {
|
463 |
return;
|
464 |
}
|
465 |
|
466 |
+
$default_privacy = sanitize_text_field( filter_input( INPUT_POST, 'rtmedia-default-privacy', FILTER_SANITIZE_STRING ) );
|
467 |
+
$nonce = sanitize_text_field( filter_input( INPUT_POST, 'rtmedia_member_settings_privacy', FILTER_SANITIZE_STRING ) );
|
468 |
+
|
469 |
+
if ( ! empty( $default_privacy ) || 0 === intval( $default_privacy ) ) {
|
470 |
|
|
|
471 |
$status = false;
|
472 |
if ( wp_verify_nonce( $nonce, 'rtmedia_member_settings_privacy' ) ) {
|
473 |
+
// todo user attribute.
|
474 |
$status = update_user_meta( get_current_user_id(), 'rtmedia-default-privacy', $default_privacy );
|
475 |
}
|
476 |
+
|
477 |
+
$feedback_type = '';
|
478 |
+
$feedback = '';
|
479 |
+
|
480 |
if ( false === $status ) {
|
481 |
$feedback = esc_html__( 'No changes were made to your account.', 'buddypress-media' );
|
482 |
$feedback_type = 'error';
|
483 |
+
} elseif ( true === $status ) {
|
484 |
$feedback = esc_html__( 'Your default privacy settings saved successfully.', 'buddypress-media' );
|
485 |
$feedback_type = 'success';
|
486 |
}
|
487 |
+
|
488 |
bp_core_add_message( $feedback, $feedback_type );
|
489 |
do_action( 'bp_core_general_settings_after_save' );
|
490 |
bp_core_redirect( bp_displayed_user_domain() . bp_get_settings_slug() . '/privacy/' );
|
491 |
}
|
492 |
}
|
493 |
|
494 |
+
/**
|
495 |
+
* Display privacy settings form.
|
496 |
+
*/
|
497 |
+
public function content() {
|
498 |
if ( 'privacy' !== buddypress()->current_action ) {
|
499 |
return;
|
500 |
}
|
501 |
+
|
502 |
+
// todo user attribute.
|
503 |
$default_privacy = get_user_meta( get_current_user_id(), 'rtmedia-default-privacy', true );
|
504 |
if ( false === $default_privacy || '' === $default_privacy ) {
|
505 |
$default_privacy = get_rtmedia_default_privacy();
|
513 |
<div class="rtm-title"><h3><?php esc_html_e( 'Default Privacy', 'buddypress-media' ); ?></h3></div>
|
514 |
<div class="rtm-privacy-levels">
|
515 |
<?php foreach ( $rtmedia->privacy_settings['levels'] as $level => $data ) { ?>
|
516 |
+
<label>
|
517 |
+
<input type='radio' value='<?php echo esc_attr( $level ); ?>' name='rtmedia-default-privacy' <?php checked( intval( $default_privacy ), $level, true ); ?> />
|
518 |
+
<?php echo esc_html( $data ); ?>
|
519 |
+
</label>
|
520 |
+
<br/>
|
521 |
<?php } ?>
|
522 |
</div>
|
523 |
</div>
|
524 |
</div>
|
525 |
<div class="submit">
|
526 |
+
<input type="submit" name="submit" value="<?php esc_attr_e( 'Save Changes', 'buddypress-media' ); ?>" id="submit" class="auto">
|
|
|
527 |
</div>
|
528 |
</form>
|
529 |
<?php
|
530 |
}
|
531 |
|
532 |
+
/**
|
533 |
+
* Get privacy title.
|
534 |
+
*
|
535 |
+
* @return string
|
536 |
+
*/
|
537 |
+
public function title() {
|
538 |
return esc_html__( 'Privacy', 'buddypress-media' );
|
539 |
}
|
540 |
|
541 |
+
/**
|
542 |
+
* Set activity privacy.
|
543 |
+
*
|
544 |
+
* @param string $sql SQL query string.
|
545 |
+
* @param string $select_sql Select query string.
|
546 |
+
* @param string $from_sql From SQL string.
|
547 |
+
* @param string $where_sql Where condition string.
|
548 |
+
* @param string $sort Sorting string.
|
549 |
+
* @param string $pag_sql Pagination string.
|
550 |
+
*
|
551 |
+
* @return string
|
552 |
+
*/
|
553 |
+
public function activity_privacy( $sql, $select_sql, $from_sql, $where_sql, $sort, $pag_sql = '' ) {
|
554 |
if ( is_rt_admin() ) {
|
555 |
return $sql;
|
556 |
}
|
566 |
$user = 0;
|
567 |
}
|
568 |
|
569 |
+
// admin has upgraded rtmedia activity so we can use rt_rtm_activity table for rtmedia related activity filters.
|
570 |
if ( $this->can_use_rtm_ac_privacy() ) {
|
571 |
+
|
572 |
$rtmedia_activity_model = new RTMediaActivityModel();
|
573 |
+
$where .= " ({$this->rtm_activity_table_alias}.privacy is NULL OR {$this->rtm_activity_table_alias}.privacy <= 0) "; // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
574 |
+
|
575 |
if ( $user ) {
|
576 |
$where .= "OR (({$this->rtm_activity_table_alias}.privacy=20)";
|
577 |
$where .= " OR (a.user_id={$user} AND {$this->rtm_activity_table_alias}.privacy >= 40)";
|
582 |
if ( isset( $friends ) && ! empty( $friends ) ) {
|
583 |
$in_str_arr = array_fill( 0, count( $friends ), '%d' );
|
584 |
$in_str = join( ',', $in_str_arr );
|
585 |
+
$where .= $wpdb->prepare( " OR ({$this->rtm_activity_table_alias}.privacy=40 AND a.user_id IN ({$in_str}) )", $friends ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare
|
586 |
}
|
587 |
}
|
588 |
}
|
595 |
|
596 |
$select_sql .= " ,{$this->rtm_activity_table_alias}.privacy ";
|
597 |
|
598 |
+
$from_sql = $wpdb->prepare( " FROM {$bp->activity->table_name} a LEFT JOIN {$wpdb->users} u ON a.user_id = u.ID LEFT JOIN {$rtmedia_activity_model->table_name} {$this->rtm_activity_table_alias} ON ( a.id = {$this->rtm_activity_table_alias}.activity_id and ra.blog_id = %d ) ", get_current_blog_id() ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
599 |
|
600 |
// removed NOT EXISTS check for `rtmedia_privacy` activty meta value.
|
601 |
+
// check git history for more details ;).
|
602 |
$where_sql = $where_sql . " AND ({$where})";
|
603 |
$newsql = "{$select_sql} {$from_sql} {$where_sql} ORDER BY a.date_recorded {$sort} {$pag_sql}";
|
604 |
} else {
|
605 |
+
|
606 |
$where .= ' (m.max_privacy is NULL OR m.max_privacy <= 0) ';
|
607 |
+
|
608 |
if ( $user ) {
|
609 |
$where .= 'OR ((m.max_privacy=20)';
|
610 |
$where .= " OR (a.user_id={$user} AND m.max_privacy >= 40)";
|
619 |
}
|
620 |
$where .= ')';
|
621 |
}
|
622 |
+
|
623 |
if ( function_exists( 'bp_core_get_table_prefix' ) ) {
|
624 |
$bp_prefix = bp_core_get_table_prefix();
|
625 |
} else {
|
626 |
$bp_prefix = '';
|
627 |
}
|
628 |
+
|
629 |
if ( strpos( $select_sql, 'SELECT DISTINCT' ) === false ) {
|
630 |
$select_sql = str_replace( 'SELECT', 'SELECT DISTINCT', $select_sql );
|
631 |
}
|
632 |
+
|
633 |
$media_table = "SELECT *, max( privacy ) as max_privacy from {$rtmedia_model->table_name} group by activity_id";
|
634 |
+
$from_sql = $wpdb->prepare( " FROM {$bp->activity->table_name} a LEFT JOIN {$wpdb->users} u ON a.user_id = u.ID LEFT JOIN ( $media_table ) m ON ( a.id = m.activity_id AND m.blog_id = %d ) ", get_current_blog_id() ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
635 |
$where_sql = $where_sql . " AND (NOT EXISTS (SELECT m.activity_id FROM {$bp_prefix}bp_activity_meta m WHERE m.meta_key='rtmedia_privacy' AND m.activity_id=a.id) OR ( {$where} ) )";
|
636 |
$newsql = "{$select_sql} {$from_sql} {$where_sql} ORDER BY a.date_recorded {$sort} {$pag_sql}";
|
637 |
}
|
645 |
* Use only if current user has admin capability because for non admin users privacy field will be added in
|
646 |
* privacy filter query itself.
|
647 |
*
|
648 |
+
* @param string $sql SQL query string.
|
649 |
+
* @param string $select_sql Select query string.
|
650 |
+
* @param string $from_sql From SQL string.
|
651 |
+
* @param string $where_sql Where condition string.
|
652 |
+
* @param string $sort Sorting string.
|
653 |
+
* @param string $pag_sql Pagination string.
|
654 |
*
|
655 |
* @return string
|
656 |
*/
|
657 |
+
public function activity_privacy_sql_field( $sql, $select_sql, $from_sql, $where_sql, $sort, $pag_sql = '' ) {
|
658 |
global $wpdb, $bp;
|
659 |
|
660 |
if ( $this->can_use_rtm_ac_privacy() && is_rt_admin() ) {
|
661 |
$rtmedia_activity_model = new RTMediaActivityModel();
|
662 |
if ( strpos( $sql, $rtmedia_activity_model->table_name ) === false ) {
|
663 |
$select_sql .= " ,{$this->rtm_activity_table_alias}.privacy ";
|
664 |
+
$from_sql = $wpdb->prepare( " FROM {$bp->activity->table_name} a LEFT JOIN {$wpdb->users} u ON a.user_id = u.ID LEFT JOIN {$rtmedia_activity_model->table_name} {$this->rtm_activity_table_alias} ON ( a.id = {$this->rtm_activity_table_alias}.activity_id and ra.blog_id = %d ) ", get_current_blog_id() ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
|
665 |
+
$sql = "{$select_sql} {$from_sql} {$where_sql} ORDER BY a.date_recorded {$sort} {$pag_sql}";
|
666 |
}
|
667 |
}
|
668 |
|
674 |
*
|
675 |
* @return bool|mixed|void
|
676 |
*/
|
677 |
+
public function can_use_rtm_ac_privacy() {
|
678 |
return rtmedia_get_site_option( 'rtmedia_activity_done_upgrade' );
|
679 |
}
|
680 |
}
|
app/main/controllers/shortcodes/RTMediaGalleryShortcode.php
CHANGED
@@ -1,23 +1,25 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
/*
|
4 |
-
* To change this template, choose Tools | Templates
|
5 |
-
* and open the template in the editor.
|
6 |
-
*/
|
7 |
-
|
8 |
/**
|
9 |
-
*
|
10 |
-
*
|
11 |
-
* rtMedia Gallery Shortcode to embedd a gallery of media anywhere
|
12 |
*
|
|
|
13 |
* @author Udit Desai <udit.desai@rtcamp.com>
|
14 |
*/
|
15 |
-
class RTMediaGalleryShortcode {
|
16 |
|
17 |
-
|
|
|
|
|
|
|
18 |
|
19 |
/**
|
|
|
20 |
*
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
*/
|
22 |
public function __construct() {
|
23 |
add_shortcode( 'rtmedia_gallery', array( 'RTMediaGalleryShortcode', 'render' ) );
|
@@ -25,12 +27,12 @@ class RTMediaGalleryShortcode {
|
|
25 |
add_action( 'wp_ajax_nopriv_rtmedia_get_template', array( &$this, 'ajax_rtmedia_get_template' ) );
|
26 |
}
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
if ( ! empty( $template ) ) {
|
35 |
$template_url = RTMediaTemplate::locate_template( $template, 'media/', false );
|
36 |
require_once $template_url;
|
@@ -38,7 +40,10 @@ class RTMediaGalleryShortcode {
|
|
38 |
die();
|
39 |
}
|
40 |
|
41 |
-
|
|
|
|
|
|
|
42 |
$options = get_option( 'rtmedia-options' );
|
43 |
/**
|
44 |
* Check whether user is allowed to upload media without login
|
@@ -51,28 +56,41 @@ class RTMediaGalleryShortcode {
|
|
51 |
if ( ! wp_script_is( 'plupload-all' ) ) {
|
52 |
wp_enqueue_script( 'plupload-all' );
|
53 |
}
|
54 |
-
|
55 |
}
|
56 |
|
57 |
-
wp_enqueue_script(
|
58 |
-
'
|
59 |
-
'backbone',
|
60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
|
62 |
if ( is_rtmedia_album_gallery() ) {
|
63 |
|
64 |
-
$album_template_args = apply_filters(
|
65 |
-
'
|
66 |
-
|
67 |
-
|
|
|
|
|
|
|
68 |
|
69 |
$template_url = esc_url( add_query_arg( $album_template_args, admin_url( 'admin-ajax.php' ) ), null, '' );
|
70 |
} else {
|
71 |
|
72 |
-
$media_template_args = apply_filters(
|
73 |
-
'
|
74 |
-
|
75 |
-
|
|
|
|
|
|
|
76 |
|
77 |
$template_url = esc_url( add_query_arg( $media_template_args, admin_url( 'admin-ajax.php' ) ), null, '' );
|
78 |
}
|
@@ -81,18 +99,21 @@ class RTMediaGalleryShortcode {
|
|
81 |
$url = rtmedia_get_upload_url( $request_uri );
|
82 |
|
83 |
$upload_max_size = ( wp_max_upload_size() ) / ( 1024 * 1024 ) . 'M';
|
84 |
-
$params
|
85 |
'url' => $url,
|
86 |
'runtimes' => 'html5,flash,html4',
|
87 |
'browse_button' => apply_filters( 'rtmedia_upload_button_id', 'rtMedia-upload-button' ),
|
88 |
'container' => 'rtmedia-upload-container',
|
89 |
'drop_element' => 'drag-drop-area',
|
90 |
-
'filters' => apply_filters(
|
|
|
91 |
array(
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
|
|
|
|
96 |
'max_file_size' => $upload_max_size,
|
97 |
'multipart' => true,
|
98 |
'urlstream_upload' => true,
|
@@ -100,14 +121,17 @@ class RTMediaGalleryShortcode {
|
|
100 |
'silverlight_xap_url' => includes_url( 'js/plupload/plupload.silverlight.xap' ),
|
101 |
'file_data_name' => 'rtmedia_file', // key passed to $_FILE.
|
102 |
'multi_selection' => true,
|
103 |
-
'multipart_params' => apply_filters(
|
104 |
-
'
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
|
|
|
|
|
|
111 |
'max_file_size_msg' => apply_filters( 'rtmedia_plupload_file_size_msg', $upload_max_size ),
|
112 |
);
|
113 |
|
@@ -119,9 +143,9 @@ class RTMediaGalleryShortcode {
|
|
119 |
/**
|
120 |
* Helper function to check whether the shortcode should be rendered or not
|
121 |
*
|
122 |
-
* @return
|
123 |
*/
|
124 |
-
static function display_allowed() {
|
125 |
$flag = true;
|
126 |
|
127 |
$flag = apply_filters( 'before_rtmedia_gallery_display', $flag );
|
@@ -132,16 +156,18 @@ class RTMediaGalleryShortcode {
|
|
132 |
/**
|
133 |
* Render a shortcode according to the attributes passed with it
|
134 |
*
|
135 |
-
* @param
|
136 |
*
|
137 |
* @return bool|string
|
138 |
*/
|
139 |
-
static function render( $attr ) {
|
|
|
140 |
if ( self::display_allowed() ) {
|
|
|
141 |
self::$add_script = true;
|
142 |
|
143 |
ob_start();
|
144 |
-
$authorized_member = true; //by default, viewer is authorized
|
145 |
|
146 |
if ( ( ! isset( $attr ) ) || empty( $attr ) ) {
|
147 |
$attr = true;
|
@@ -168,21 +194,21 @@ class RTMediaGalleryShortcode {
|
|
168 |
$attr['attr']['context_id'] = $post->ID;
|
169 |
}
|
170 |
|
171 |
-
//check if context is group, then the gallery should only be visible to users according to the group privacy
|
172 |
if ( isset( $attr['attr']['context'] ) && 'group' === $attr['attr']['context'] ) {
|
173 |
|
174 |
-
if ( function_exists( 'groups_get_group' ) ) { //if buddypress group is enabled
|
175 |
$group = groups_get_group( array( 'group_id' => $attr['attr']['context_id'] ) );
|
176 |
if ( isset( $group->status ) && 'public' !== $group->status ) {
|
177 |
if ( is_user_logged_in() ) {
|
178 |
$is_member = groups_is_user_member( get_current_user_id(), $attr['attr']['context_id'] );
|
179 |
if ( ! $is_member ) {
|
180 |
$authorized_member = false;
|
181 |
-
//if user
|
182 |
}
|
183 |
} else {
|
184 |
$authorized_member = false;
|
185 |
-
//if user is
|
186 |
}
|
187 |
}
|
188 |
}
|
@@ -191,32 +217,38 @@ class RTMediaGalleryShortcode {
|
|
191 |
if ( ! isset( $attr['attr']['context'] ) && isset( $post->post_type ) ) {
|
192 |
$attr['attr']['context'] = $post->post_type;
|
193 |
}
|
194 |
-
}// End if
|
195 |
|
196 |
$rtmedia_shortcode_attr = $attr['attr'];
|
197 |
|
198 |
-
// Set template according to media type
|
199 |
if ( is_rtmedia_album_gallery() || ( isset( $attr['attr']['media_type'] ) && 'album' === $attr['attr']['media_type'] ) ) {
|
200 |
|
201 |
-
$album_template_args = apply_filters(
|
202 |
-
'
|
203 |
-
|
204 |
-
|
|
|
|
|
|
|
205 |
|
206 |
$template_url = esc_url( add_query_arg( $album_template_args, admin_url( 'admin-ajax.php' ) ), null, '' );
|
207 |
} else {
|
208 |
|
209 |
-
$media_template_args = apply_filters(
|
210 |
-
'
|
211 |
-
|
212 |
-
|
|
|
|
|
|
|
213 |
|
214 |
$template_url = esc_url( add_query_arg( $media_template_args, admin_url( 'admin-ajax.php' ) ), null, '' );
|
215 |
}
|
216 |
wp_localize_script( 'rtmedia-backbone', 'template_url', $template_url );
|
217 |
|
218 |
/**
|
219 |
-
* Remove search_filter
|
220 |
* Reason: Showing error on Database Errors [ SQL Query ]
|
221 |
* Solution: Unset search_filter parameter store value on another variable.
|
222 |
*/
|
@@ -227,27 +259,36 @@ class RTMediaGalleryShortcode {
|
|
227 |
}
|
228 |
}
|
229 |
|
230 |
-
if ( $authorized_member ) { // if current user has access to view the gallery (when context is 'group')
|
231 |
global $rtmedia_query;
|
|
|
232 |
if ( ! $rtmedia_query ) {
|
233 |
$rtmedia_query = new RTMediaQuery( $attr['attr'] );
|
234 |
}
|
235 |
-
|
236 |
-
|
237 |
-
$
|
|
|
238 |
$rtmedia_query->is_gallery_shortcode = true;// to check if gallery shortcode is executed to display the gallery.
|
239 |
|
240 |
$template = new RTMediaTemplate();
|
241 |
$gallery_template = false;
|
|
|
242 |
if ( isset( $attr['attr']['global'] ) && true === (bool) $attr['attr']['global'] ) {
|
243 |
-
add_filter(
|
244 |
-
'
|
245 |
-
|
246 |
-
|
|
|
|
|
|
|
|
|
|
|
247 |
}
|
248 |
|
249 |
$attr['attr']['hide_comment_media'] = false;
|
250 |
-
$remove_comment_media
|
|
|
251 |
if ( isset( $remove_comment_media ) && ! empty( $remove_comment_media ) ) {
|
252 |
add_filter( 'rtmedia-model-where-query', array( 'RTMediaGalleryShortcode', 'rtmedia_query_where_filter_remove_comment_media' ), 11, 3 );
|
253 |
$attr['attr']['hide_comment_media'] = true;
|
@@ -267,29 +308,49 @@ class RTMediaGalleryShortcode {
|
|
267 |
}
|
268 |
|
269 |
if ( isset( $attr['attr']['global'] ) && true === (bool) $attr['attr']['global'] ) {
|
270 |
-
remove_filter(
|
271 |
-
'
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
|
|
|
|
|
|
|
|
276 |
esc_html_e( 'You do not have sufficient privileges to view this gallery', 'buddypress-media' );
|
277 |
return false;
|
278 |
-
}// End if
|
279 |
return ob_get_clean();
|
280 |
-
}// End if
|
281 |
}
|
282 |
|
283 |
-
|
284 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
285 |
if ( function_exists( 'rtmedia_query_where_filter_remove_comment_media' ) ) {
|
286 |
$where = rtmedia_query_where_filter_remove_comment_media( $where, $table_name, $join );
|
287 |
}
|
288 |
return $where;
|
289 |
}
|
290 |
|
291 |
-
|
292 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
293 |
$where .= ' AND (' . $table_name . '.privacy = "0" OR ' . $table_name . '.privacy is NULL ) ';
|
294 |
|
295 |
return $where;
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
/**
|
3 |
+
* Handles rtMedia Gallery Shortcode to embed a gallery of media anywhere
|
|
|
|
|
4 |
*
|
5 |
+
* @package rtMedia
|
6 |
* @author Udit Desai <udit.desai@rtcamp.com>
|
7 |
*/
|
|
|
8 |
|
9 |
+
/**
|
10 |
+
* Class to handle rtMedia Gallery Shortcode to embed a gallery of media anywhere
|
11 |
+
*/
|
12 |
+
class RTMediaGalleryShortcode {
|
13 |
|
14 |
/**
|
15 |
+
* Add shortcode script or not.
|
16 |
*
|
17 |
+
* @var bool
|
18 |
+
*/
|
19 |
+
public static $add_script;
|
20 |
+
|
21 |
+
/**
|
22 |
+
* RTMediaGalleryShortcode constructor.
|
23 |
*/
|
24 |
public function __construct() {
|
25 |
add_shortcode( 'rtmedia_gallery', array( 'RTMediaGalleryShortcode', 'render' ) );
|
27 |
add_action( 'wp_ajax_nopriv_rtmedia_get_template', array( &$this, 'ajax_rtmedia_get_template' ) );
|
28 |
}
|
29 |
|
30 |
+
/**
|
31 |
+
* Get template for json response.
|
32 |
+
*/
|
33 |
+
public function ajax_rtmedia_get_template() {
|
34 |
+
$template = sanitize_text_field( filter_input( INPUT_GET, 'template', FILTER_SANITIZE_STRING ) );
|
35 |
+
|
36 |
if ( ! empty( $template ) ) {
|
37 |
$template_url = RTMediaTemplate::locate_template( $template, 'media/', false );
|
38 |
require_once $template_url;
|
40 |
die();
|
41 |
}
|
42 |
|
43 |
+
/**
|
44 |
+
* Register shortcode scripts.
|
45 |
+
*/
|
46 |
+
public static function register_scripts() {
|
47 |
$options = get_option( 'rtmedia-options' );
|
48 |
/**
|
49 |
* Check whether user is allowed to upload media without login
|
56 |
if ( ! wp_script_is( 'plupload-all' ) ) {
|
57 |
wp_enqueue_script( 'plupload-all' );
|
58 |
}
|
|
|
59 |
}
|
60 |
|
61 |
+
wp_enqueue_script(
|
62 |
+
'rtmedia-backbone',
|
63 |
+
RTMEDIA_URL . 'app/assets/js/rtMedia.backbone.js',
|
64 |
+
array(
|
65 |
+
'plupload-all',
|
66 |
+
'backbone',
|
67 |
+
// Whole rtmedia-backbone file is dependent on rtmedia-main file (eg. rtMediaHook).
|
68 |
+
'rtmedia-main'
|
69 |
+
),
|
70 |
+
RTMEDIA_VERSION,
|
71 |
+
true
|
72 |
+
);
|
73 |
|
74 |
if ( is_rtmedia_album_gallery() ) {
|
75 |
|
76 |
+
$album_template_args = apply_filters(
|
77 |
+
'album_template_args',
|
78 |
+
array(
|
79 |
+
'action' => 'rtmedia_get_template',
|
80 |
+
'template' => 'album-gallery-item',
|
81 |
+
)
|
82 |
+
);
|
83 |
|
84 |
$template_url = esc_url( add_query_arg( $album_template_args, admin_url( 'admin-ajax.php' ) ), null, '' );
|
85 |
} else {
|
86 |
|
87 |
+
$media_template_args = apply_filters(
|
88 |
+
'media_template_args',
|
89 |
+
array(
|
90 |
+
'action' => 'rtmedia_get_template',
|
91 |
+
'template' => apply_filters( 'rtmedia_backbone_template_filter', 'media-gallery-item' ),
|
92 |
+
)
|
93 |
+
);
|
94 |
|
95 |
$template_url = esc_url( add_query_arg( $media_template_args, admin_url( 'admin-ajax.php' ) ), null, '' );
|
96 |
}
|
99 |
$url = rtmedia_get_upload_url( $request_uri );
|
100 |
|
101 |
$upload_max_size = ( wp_max_upload_size() ) / ( 1024 * 1024 ) . 'M';
|
102 |
+
$params = array(
|
103 |
'url' => $url,
|
104 |
'runtimes' => 'html5,flash,html4',
|
105 |
'browse_button' => apply_filters( 'rtmedia_upload_button_id', 'rtMedia-upload-button' ),
|
106 |
'container' => 'rtmedia-upload-container',
|
107 |
'drop_element' => 'drag-drop-area',
|
108 |
+
'filters' => apply_filters(
|
109 |
+
'rtmedia_plupload_files_filter',
|
110 |
array(
|
111 |
+
array(
|
112 |
+
'title' => esc_html__( 'Media Files', 'buddypress-media' ),
|
113 |
+
'extensions' => get_rtmedia_allowed_upload_type(),
|
114 |
+
),
|
115 |
+
)
|
116 |
+
),
|
117 |
'max_file_size' => $upload_max_size,
|
118 |
'multipart' => true,
|
119 |
'urlstream_upload' => true,
|
121 |
'silverlight_xap_url' => includes_url( 'js/plupload/plupload.silverlight.xap' ),
|
122 |
'file_data_name' => 'rtmedia_file', // key passed to $_FILE.
|
123 |
'multi_selection' => true,
|
124 |
+
'multipart_params' => apply_filters( // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
|
125 |
+
'rtmedia-multi-params',
|
126 |
+
array(
|
127 |
+
'redirect' => 'no',
|
128 |
+
'redirection' => 'false',
|
129 |
+
'action' => 'wp_handle_upload',
|
130 |
+
'_wp_http_referer' => $request_uri,
|
131 |
+
'mode' => 'file_upload',
|
132 |
+
'rtmedia_upload_nonce' => RTMediaUploadView::upload_nonce_generator( false, true ),
|
133 |
+
)
|
134 |
+
),
|
135 |
'max_file_size_msg' => apply_filters( 'rtmedia_plupload_file_size_msg', $upload_max_size ),
|
136 |
);
|
137 |
|
143 |
/**
|
144 |
* Helper function to check whether the shortcode should be rendered or not
|
145 |
*
|
146 |
+
* @return bool
|
147 |
*/
|
148 |
+
public static function display_allowed() {
|
149 |
$flag = true;
|
150 |
|
151 |
$flag = apply_filters( 'before_rtmedia_gallery_display', $flag );
|
156 |
/**
|
157 |
* Render a shortcode according to the attributes passed with it
|
158 |
*
|
159 |
+
* @param bool|array $attr Shortcode attributes.
|
160 |
*
|
161 |
* @return bool|string
|
162 |
*/
|
163 |
+
public static function render( $attr ) {
|
164 |
+
|
165 |
if ( self::display_allowed() ) {
|
166 |
+
|
167 |
self::$add_script = true;
|
168 |
|
169 |
ob_start();
|
170 |
+
$authorized_member = true; // by default, viewer is authorized.
|
171 |
|
172 |
if ( ( ! isset( $attr ) ) || empty( $attr ) ) {
|
173 |
$attr = true;
|
194 |
$attr['attr']['context_id'] = $post->ID;
|
195 |
}
|
196 |
|
197 |
+
// check if context is group, then the gallery should only be visible to users according to the group privacy.
|
198 |
if ( isset( $attr['attr']['context'] ) && 'group' === $attr['attr']['context'] ) {
|
199 |
|
200 |
+
if ( function_exists( 'groups_get_group' ) ) { // if buddypress group is enabled.
|
201 |
$group = groups_get_group( array( 'group_id' => $attr['attr']['context_id'] ) );
|
202 |
if ( isset( $group->status ) && 'public' !== $group->status ) {
|
203 |
if ( is_user_logged_in() ) {
|
204 |
$is_member = groups_is_user_member( get_current_user_id(), $attr['attr']['context_id'] );
|
205 |
if ( ! $is_member ) {
|
206 |
$authorized_member = false;
|
207 |
+
// if user does not have access to the specified group.
|
208 |
}
|
209 |
} else {
|
210 |
$authorized_member = false;
|
211 |
+
// if user is group not logged in and visits group media gallery.
|
212 |
}
|
213 |
}
|
214 |
}
|
217 |
if ( ! isset( $attr['attr']['context'] ) && isset( $post->post_type ) ) {
|
218 |
$attr['attr']['context'] = $post->post_type;
|
219 |
}
|
220 |
+
}// End if.
|
221 |
|
222 |
$rtmedia_shortcode_attr = $attr['attr'];
|
223 |
|
224 |
+
// Set template according to media type.
|
225 |
if ( is_rtmedia_album_gallery() || ( isset( $attr['attr']['media_type'] ) && 'album' === $attr['attr']['media_type'] ) ) {
|
226 |
|
227 |
+
$album_template_args = apply_filters(
|
228 |
+
'album_template_args',
|
229 |
+
array(
|
230 |
+
'action' => 'rtmedia_get_template',
|
231 |
+
'template' => 'album-gallery-item',
|
232 |
+
)
|
233 |
+
);
|
234 |
|
235 |
$template_url = esc_url( add_query_arg( $album_template_args, admin_url( 'admin-ajax.php' ) ), null, '' );
|
236 |
} else {
|
237 |
|
238 |
+
$media_template_args = apply_filters(
|
239 |
+
'media_template_args',
|
240 |
+
array(
|
241 |
+
'action' => 'rtmedia_get_template',
|
242 |
+
'template' => apply_filters( 'rtmedia_backbone_template_filter', 'media-gallery-item' ),
|
243 |
+
)
|
244 |
+
);
|
245 |
|
246 |
$template_url = esc_url( add_query_arg( $media_template_args, admin_url( 'admin-ajax.php' ) ), null, '' );
|
247 |
}
|
248 |
wp_localize_script( 'rtmedia-backbone', 'template_url', $template_url );
|
249 |
|
250 |
/**
|
251 |
+
* Remove search_filter parameter from attr,
|
252 |
* Reason: Showing error on Database Errors [ SQL Query ]
|
253 |
* Solution: Unset search_filter parameter store value on another variable.
|
254 |
*/
|
259 |
}
|
260 |
}
|
261 |
|
262 |
+
if ( $authorized_member ) { // if current user has access to view the gallery (when context is 'group').
|
263 |
global $rtmedia_query;
|
264 |
+
|
265 |
if ( ! $rtmedia_query ) {
|
266 |
$rtmedia_query = new RTMediaQuery( $attr['attr'] );
|
267 |
}
|
268 |
+
|
269 |
+
do_action( 'rtmedia_shortcode_action', $attr['attr'] );// do extra stuff with attributes.
|
270 |
+
$page_number = ( get_query_var( 'pg' ) ) ? get_query_var( 'pg' ) : 1; // get page number.
|
271 |
+
$rtmedia_query->action_query->page = intval( $page_number );
|
272 |
$rtmedia_query->is_gallery_shortcode = true;// to check if gallery shortcode is executed to display the gallery.
|
273 |
|
274 |
$template = new RTMediaTemplate();
|
275 |
$gallery_template = false;
|
276 |
+
|
277 |
if ( isset( $attr['attr']['global'] ) && true === (bool) $attr['attr']['global'] ) {
|
278 |
+
add_filter(
|
279 |
+
'rtmedia-model-where-query',
|
280 |
+
array(
|
281 |
+
'RTMediaGalleryShortcode',
|
282 |
+
'rtmedia_query_where_filter',
|
283 |
+
),
|
284 |
+
10,
|
285 |
+
3
|
286 |
+
);
|
287 |
}
|
288 |
|
289 |
$attr['attr']['hide_comment_media'] = false;
|
290 |
+
$remove_comment_media = apply_filters( 'rtmedia_query_where_filter_remove_comment_media', true, 'galleryshortcode' );
|
291 |
+
|
292 |
if ( isset( $remove_comment_media ) && ! empty( $remove_comment_media ) ) {
|
293 |
add_filter( 'rtmedia-model-where-query', array( 'RTMediaGalleryShortcode', 'rtmedia_query_where_filter_remove_comment_media' ), 11, 3 );
|
294 |
$attr['attr']['hide_comment_media'] = true;
|
308 |
}
|
309 |
|
310 |
if ( isset( $attr['attr']['global'] ) && true === (bool) $attr['attr']['global'] ) {
|
311 |
+
remove_filter(
|
312 |
+
'rtmedia-model-where-query',
|
313 |
+
array(
|
314 |
+
'RTMediaGalleryShortcode',
|
315 |
+
'rtmedia_query_where_filter',
|
316 |
+
),
|
317 |
+
10
|
318 |
+
);
|
319 |
+
} // End if.
|
320 |
+
} else { // if user cannot view the media gallery (when context is 'group'), show message.
|
321 |
esc_html_e( 'You do not have sufficient privileges to view this gallery', 'buddypress-media' );
|
322 |
return false;
|
323 |
+
} // End if.
|
324 |
return ob_get_clean();
|
325 |
+
} // End if.
|
326 |
}
|
327 |
|
328 |
+
/**
|
329 |
+
* For gallery shortcode remove all comment media reply
|
330 |
+
*
|
331 |
+
* @param string $where Where clause of query.
|
332 |
+
* @param string $table_name Table name for query.
|
333 |
+
* @param string $join Join query part.
|
334 |
+
*
|
335 |
+
* @return string
|
336 |
+
*/
|
337 |
+
public static function rtmedia_query_where_filter_remove_comment_media( $where, $table_name, $join ) {
|
338 |
if ( function_exists( 'rtmedia_query_where_filter_remove_comment_media' ) ) {
|
339 |
$where = rtmedia_query_where_filter_remove_comment_media( $where, $table_name, $join );
|
340 |
}
|
341 |
return $where;
|
342 |
}
|
343 |
|
344 |
+
/**
|
345 |
+
* For gallery shortcode having attribute global as true, include all media except ones having context as "group".
|
346 |
+
*
|
347 |
+
* @param string $where Where clause of query.
|
348 |
+
* @param string $table_name Table name for query.
|
349 |
+
* @param string $join Join query part.
|
350 |
+
*
|
351 |
+
* @return string
|
352 |
+
*/
|
353 |
+
public static function rtmedia_query_where_filter( $where, $table_name, $join ) {
|
354 |
$where .= ' AND (' . $table_name . '.privacy = "0" OR ' . $table_name . '.privacy is NULL ) ';
|
355 |
|
356 |
return $where;
|
app/main/controllers/shortcodes/RTMediaUploadShortcode.php
CHANGED
@@ -1,20 +1,39 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
/**
|
4 |
-
*
|
5 |
-
*
|
6 |
-
* rtMedia uploader shortcode
|
7 |
*
|
8 |
* @author joshua
|
|
|
|
|
|
|
|
|
|
|
9 |
*/
|
10 |
class RTMediaUploadShortcode {
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
15 |
|
16 |
/**
|
|
|
17 |
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
*/
|
19 |
public function __construct() {
|
20 |
|
@@ -22,7 +41,7 @@ class RTMediaUploadShortcode {
|
|
22 |
$method_name = strtolower( str_replace( 'RTMedia', '', __CLASS__ ) );
|
23 |
|
24 |
if ( is_callable( "RTMediaDeprecated::{$method_name}", true, $callable_name ) ) {
|
25 |
-
$this->deprecated = RTMediaDeprecated::$method_name
|
26 |
}
|
27 |
}
|
28 |
|
@@ -31,7 +50,7 @@ class RTMediaUploadShortcode {
|
|
31 |
*
|
32 |
* @return bool
|
33 |
*/
|
34 |
-
static function display_allowed() {
|
35 |
global $rtmedia_query;
|
36 |
$media_enabled = ( is_rtmedia_upload_music_enabled() || is_rtmedia_upload_photo_enabled()
|
37 |
|| is_rtmedia_upload_video_enabled() || is_rtmedia_upload_document_enabled()
|
@@ -51,20 +70,24 @@ class RTMediaUploadShortcode {
|
|
51 |
/**
|
52 |
* Render the uploader shortcode and attach the uploader panel
|
53 |
*
|
54 |
-
* @param mixed $attr
|
55 |
*
|
56 |
* @return string|void
|
57 |
*/
|
58 |
-
static function pre_render( $attr ) {
|
59 |
if ( rtmedia_is_uploader_view_allowed( true, 'uploader_shortcode' ) ) {
|
|
|
60 |
global $post;
|
61 |
global $rtmedia_query;
|
|
|
62 |
if ( ! $rtmedia_query ) {
|
63 |
-
$rtmedia_query = new RTMediaQuery();
|
|
|
|
|
64 |
if ( ! isset( $attr['is_up_shortcode'] ) || false !== $attr['is_up_shortcode'] ) {
|
65 |
-
$rtmedia_query->is_upload_shortcode = true;// set is_upload_shortcode in rtmedia query as true
|
66 |
} else {
|
67 |
-
$rtmedia_query->is_upload_shortcode = false;// set is_upload_shortcode in rtmedia query as true
|
68 |
}
|
69 |
|
70 |
if ( isset( $attr['media_type'] ) ) {
|
@@ -99,7 +122,7 @@ class RTMediaUploadShortcode {
|
|
99 |
return ob_get_clean();
|
100 |
}
|
101 |
} else {
|
102 |
-
echo "<div class='rtmedia-upload-not-allowed'>" . wp_kses( apply_filters( 'rtmedia_upload_not_allowed_message', esc_html__( 'You are not allowed to upload/attach media.','buddypress-media' ), 'uploader_shortcode' ), RTMediaUpload::$wp_kses_allowed_tags ) . '</div>';
|
103 |
}
|
104 |
}
|
105 |
}
|
1 |
<?php
|
|
|
2 |
/**
|
3 |
+
* Handles rtMedia uploader shortcode
|
|
|
|
|
4 |
*
|
5 |
* @author joshua
|
6 |
+
* @package rtMedia
|
7 |
+
*/
|
8 |
+
|
9 |
+
/**
|
10 |
+
* Handles rtMedia uploader shortcode
|
11 |
*/
|
12 |
class RTMediaUploadShortcode {
|
13 |
|
14 |
+
/**
|
15 |
+
* Flag to add shortcode script.
|
16 |
+
*
|
17 |
+
* @var bool
|
18 |
+
*/
|
19 |
+
public static $add_sc_script = false;
|
20 |
|
21 |
/**
|
22 |
+
* Add deprecated method.
|
23 |
*
|
24 |
+
* @var bool
|
25 |
+
*/
|
26 |
+
public $deprecated = false;
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Displayed uploader.
|
30 |
+
*
|
31 |
+
* @var bool
|
32 |
+
*/
|
33 |
+
public static $uploader_displayed = false;
|
34 |
+
|
35 |
+
/**
|
36 |
+
* RTMediaUploadShortcode constructor.
|
37 |
*/
|
38 |
public function __construct() {
|
39 |
|
41 |
$method_name = strtolower( str_replace( 'RTMedia', '', __CLASS__ ) );
|
42 |
|
43 |
if ( is_callable( "RTMediaDeprecated::{$method_name}", true, $callable_name ) ) {
|
44 |
+
$this->deprecated = RTMediaDeprecated::$method_name();
|
45 |
}
|
46 |
}
|
47 |
|
50 |
*
|
51 |
* @return bool
|
52 |
*/
|
53 |
+
public static function display_allowed() {
|
54 |
global $rtmedia_query;
|
55 |
$media_enabled = ( is_rtmedia_upload_music_enabled() || is_rtmedia_upload_photo_enabled()
|
56 |
|| is_rtmedia_upload_video_enabled() || is_rtmedia_upload_document_enabled()
|
70 |
/**
|
71 |
* Render the uploader shortcode and attach the uploader panel
|
72 |
*
|
73 |
+
* @param mixed $attr Attributes of shortcodes.
|
74 |
*
|
75 |
* @return string|void
|
76 |
*/
|
77 |
+
public static function pre_render( $attr ) {
|
78 |
if ( rtmedia_is_uploader_view_allowed( true, 'uploader_shortcode' ) ) {
|
79 |
+
|
80 |
global $post;
|
81 |
global $rtmedia_query;
|
82 |
+
|
83 |
if ( ! $rtmedia_query ) {
|
84 |
+
$rtmedia_query = new RTMediaQuery();
|
85 |
+
}
|
86 |
+
|
87 |
if ( ! isset( $attr['is_up_shortcode'] ) || false !== $attr['is_up_shortcode'] ) {
|
88 |
+
$rtmedia_query->is_upload_shortcode = true;// set is_upload_shortcode in rtmedia query as true.
|
89 |
} else {
|
90 |
+
$rtmedia_query->is_upload_shortcode = false;// set is_upload_shortcode in rtmedia query as true.
|
91 |
}
|
92 |
|
93 |
if ( isset( $attr['media_type'] ) ) {
|
122 |
return ob_get_clean();
|
123 |
}
|
124 |
} else {
|
125 |
+
echo "<div class='rtmedia-upload-not-allowed'>" . wp_kses( apply_filters( 'rtmedia_upload_not_allowed_message', esc_html__( 'You are not allowed to upload/attach media.', 'buddypress-media' ), 'uploader_shortcode' ), RTMediaUpload::$wp_kses_allowed_tags ) . '</div>';
|
126 |
}
|
127 |
}
|
128 |
}
|
app/main/controllers/template/RTMediaAJAX.php
CHANGED
@@ -1,37 +1,49 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
|
4 |
-
*
|
5 |
-
*
|
6 |
*/
|
7 |
|
8 |
/**
|
9 |
-
*
|
10 |
*
|
11 |
* @author udit
|
12 |
*/
|
13 |
class RTMediaAJAX {
|
14 |
|
|
|
|
|
|
|
15 |
public function __construct() {
|
16 |
add_action( 'wp_ajax_rtmedia_backbone_template', array( $this, 'backbone_template' ) );
|
17 |
add_action( 'wp_ajax_rtmedia_create_album', array( $this, 'create_album' ) );
|
18 |
}
|
19 |
|
20 |
-
|
|
|
|
|
|
|
21 |
include RTMEDIA_PATH . 'templates/media/media-gallery-item.php';
|
22 |
}
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
|
|
|
|
|
|
28 |
|
29 |
$return['error'] = false;
|
30 |
if ( wp_verify_nonce( $nonce, 'rtmedia_create_album_nonce' ) && isset( $_name ) && $_name && is_rtmedia_album_enable() ) {
|
31 |
-
|
|
|
32 |
$_context_id = filter_input( INPUT_POST, 'context_id', FILTER_SANITIZE_NUMBER_INT );
|
|
|
33 |
if ( ! empty( $_context ) && 'group' === $_context ) {
|
34 |
$group_id = ! empty( $_context_id ) ? $_context_id : '';
|
|
|
35 |
if ( false === can_user_create_album_in_group( $group_id ) ) {
|
36 |
$return['error'] = esc_html__( 'You can not create album in this group.', 'buddypress-media' );
|
37 |
}
|
@@ -53,7 +65,7 @@ class RTMediaAJAX {
|
|
53 |
|
54 |
$album = new RTMediaAlbum();
|
55 |
|
56 |
-
// setup context values
|
57 |
$context = $_context;
|
58 |
if ( 'profile' === $context ) {
|
59 |
$context_id = get_current_user_id();
|
@@ -61,31 +73,40 @@ class RTMediaAJAX {
|
|
61 |
$context_id = ( ! empty( $_context_id ) ? $_context_id : 0 );
|
62 |
}
|
63 |
|
64 |
-
// setup new album data
|
65 |
-
$album_data = apply_filters(
|
66 |
-
'
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
|
|
|
|
|
|
74 |
|
75 |
$rtmedia_id = $album->add( $album_data['title'], $album_data['author'], $album_data['new'], $album_data['post_id'], $album_data['context'], $album_data['context_id'], $album_data['album_description'] );
|
76 |
|
77 |
$rtmedia_nav = new RTMediaNav();
|
78 |
|
79 |
if ( 'group' === $_context ) {
|
80 |
-
$rtmedia_nav->refresh_counts(
|
81 |
-
|
82 |
-
|
83 |
-
|
|
|
|
|
|
|
84 |
} else {
|
85 |
-
$rtmedia_nav->refresh_counts(
|
86 |
-
|
87 |
-
|
88 |
-
|
|
|
|
|
|
|
89 |
}
|
90 |
|
91 |
if ( $rtmedia_id ) {
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* Handle media ajax.
|
4 |
+
*
|
5 |
+
* @package rtMedia
|
6 |
*/
|
7 |
|
8 |
/**
|
9 |
+
* Class to handle media ajax.
|
10 |
*
|
11 |
* @author udit
|
12 |
*/
|
13 |
class RTMediaAJAX {
|
14 |
|
15 |
+
/**
|
16 |
+
* RTMediaAJAX constructor.
|
17 |
+
*/
|
18 |
public function __construct() {
|
19 |
add_action( 'wp_ajax_rtmedia_backbone_template', array( $this, 'backbone_template' ) );
|
20 |
add_action( 'wp_ajax_rtmedia_create_album', array( $this, 'create_album' ) );
|
21 |
}
|
22 |
|
23 |
+
/**
|
24 |
+
* Display media gallery items template.
|
25 |
+
*/
|
26 |
+
public function backbone_template() {
|
27 |
include RTMEDIA_PATH . 'templates/media/media-gallery-item.php';
|
28 |
}
|
29 |
|
30 |
+
/**
|
31 |
+
* Create album.
|
32 |
+
*/
|
33 |
+
public function create_album() {
|
34 |
+
$nonce = sanitize_text_field( filter_input( INPUT_POST, 'create_album_nonce', FILTER_SANITIZE_STRING ) );
|
35 |
+
$_name = sanitize_text_field( filter_input( INPUT_POST, 'name', FILTER_SANITIZE_STRING ) );
|
36 |
+
$_description = sanitize_text_field( filter_input( INPUT_POST, 'description', FILTER_SANITIZE_STRING ) );
|
37 |
|
38 |
$return['error'] = false;
|
39 |
if ( wp_verify_nonce( $nonce, 'rtmedia_create_album_nonce' ) && isset( $_name ) && $_name && is_rtmedia_album_enable() ) {
|
40 |
+
|
41 |
+
$_context = sanitize_text_field( filter_input( INPUT_POST, 'context', FILTER_SANITIZE_STRING ) );
|
42 |
$_context_id = filter_input( INPUT_POST, 'context_id', FILTER_SANITIZE_NUMBER_INT );
|
43 |
+
|
44 |
if ( ! empty( $_context ) && 'group' === $_context ) {
|
45 |
$group_id = ! empty( $_context_id ) ? $_context_id : '';
|
46 |
+
|
47 |
if ( false === can_user_create_album_in_group( $group_id ) ) {
|
48 |
$return['error'] = esc_html__( 'You can not create album in this group.', 'buddypress-media' );
|
49 |
}
|
65 |
|
66 |
$album = new RTMediaAlbum();
|
67 |
|
68 |
+
// setup context values.
|
69 |
$context = $_context;
|
70 |
if ( 'profile' === $context ) {
|
71 |
$context_id = get_current_user_id();
|
73 |
$context_id = ( ! empty( $_context_id ) ? $_context_id : 0 );
|
74 |
}
|
75 |
|
76 |
+
// setup new album data.
|
77 |
+
$album_data = apply_filters(
|
78 |
+
'rtmedia_create_album_data',
|
79 |
+
array(
|
80 |
+
'title' => $_name,
|
81 |
+
'author' => get_current_user_id(),
|
82 |
+
'new' => true,
|
83 |
+
'post_id' => false,
|
84 |
+
'context' => $context,
|
85 |
+
'context_id' => $context_id,
|
86 |
+
'album_description' => $_description,
|
87 |
+
)
|
88 |
+
);
|
89 |
|
90 |
$rtmedia_id = $album->add( $album_data['title'], $album_data['author'], $album_data['new'], $album_data['post_id'], $album_data['context'], $album_data['context_id'], $album_data['album_description'] );
|
91 |
|
92 |
$rtmedia_nav = new RTMediaNav();
|
93 |
|
94 |
if ( 'group' === $_context ) {
|
95 |
+
$rtmedia_nav->refresh_counts(
|
96 |
+
$_context_id,
|
97 |
+
array(
|
98 |
+
'context' => $_context,
|
99 |
+
'context_id' => $_context_id,
|
100 |
+
)
|
101 |
+
);
|
102 |
} else {
|
103 |
+
$rtmedia_nav->refresh_counts(
|
104 |
+
get_current_user_id(),
|
105 |
+
array(
|
106 |
+
'context' => 'profile',
|
107 |
+
'media_author' => get_current_user_id(),
|
108 |
+
)
|
109 |
+
);
|
110 |
}
|
111 |
|
112 |
if ( $rtmedia_id ) {
|
app/main/controllers/template/RTMediaNav.php
CHANGED
@@ -1,8 +1,21 @@
|
|
1 |
<?php
|
2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
class RTMediaNav {
|
4 |
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
6 |
if ( false === $action ) {
|
7 |
return;
|
8 |
}
|
@@ -19,22 +32,36 @@ class RTMediaNav {
|
|
19 |
|
20 |
if ( class_exists( 'BuddyPress' ) ) {
|
21 |
add_action( 'bp_init', array( $this, 'custom_media_nav_tab' ), 10, 1 );
|
|
|
|
|
22 |
}
|
23 |
|
24 |
add_filter( 'bp_settings_admin_nav', array( $this, 'setup_settings_privacy_nav' ), 3 );
|
25 |
}
|
26 |
|
27 |
-
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
}
|
30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
public function setup_settings_privacy_nav( $wp_admin_nav ) {
|
32 |
-
// Setup the logged in user variables
|
33 |
-
|
34 |
if ( is_rtmedia_privacy_user_overide() ) {
|
35 |
$settings_link = trailingslashit( bp_loggedin_user_domain() . bp_get_settings_slug() );
|
36 |
|
37 |
-
// Add the "Profile" subnav item
|
38 |
$wp_admin_nav[] = array(
|
39 |
'parent' => 'my-account-' . buddypress()->settings->id,
|
40 |
'id' => 'my-account-' . buddypress()->settings->id . '-privacy',
|
@@ -51,44 +78,51 @@ class RTMediaNav {
|
|
51 |
*
|
52 |
* @global object $bp global BuddyPress object
|
53 |
*/
|
54 |
-
function custom_media_nav_tab() {
|
55 |
$bp = buddypress();
|
|
|
56 |
if ( ! function_exists( 'bp_core_new_nav_item' ) ) {
|
57 |
return;
|
58 |
}
|
|
|
59 |
if ( bp_is_blog_page() || ( ! bp_is_group() && ! ( isset( $bp->displayed_user ) && isset( $bp->displayed_user->id ) ) ) || apply_filters( 'rtmedia_render_bp_nav', false ) ) {
|
60 |
return;
|
61 |
}
|
|
|
62 |
global $rtmedia;
|
|
|
63 |
if ( function_exists( 'bp_is_group' ) && ! bp_is_group() ) {
|
|
|
64 |
if ( isset( $bp->displayed_user ) && isset( $bp->displayed_user->id ) ) {
|
65 |
$profile_counts = $this->actual_counts( $bp->displayed_user->id );
|
66 |
}
|
|
|
67 |
$tab_position = apply_filters( 'rtmedia_media_tab_position', 99 );
|
68 |
if ( 0 !== intval( $rtmedia->options['buddypress_enableOnProfile'] ) ) {
|
69 |
-
bp_core_new_nav_item(
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
|
|
|
|
76 |
}
|
77 |
}
|
|
|
78 |
if ( bp_is_group() && 0 !== intval( $rtmedia->options['buddypress_enableOnGroup'] ) ) {
|
79 |
$media_enabled = true;
|
80 |
-
//filter for rtMedia PRO for PER GROUP MEDIA enable/disable functionality
|
81 |
$media_enabled = apply_filters( 'rtmedia_media_enabled_for_current_group', $media_enabled );
|
82 |
|
83 |
-
// check if current user can view this group
|
84 |
$current_group = groups_get_current_group();
|
85 |
/**
|
86 |
-
*
|
87 |
* reason : In Buddypress 2.7 `is_visible` return false so we can't display `media` tab on group
|
88 |
-
* issue id
|
89 |
*/
|
90 |
-
|
91 |
-
// $is_visible_to_current_user = $current_group->is_visible;
|
92 |
$is_visible_to_current_user = bp_group_is_visible( $current_group );
|
93 |
|
94 |
if ( $media_enabled && $is_visible_to_current_user ) {
|
@@ -98,25 +132,27 @@ class RTMediaNav {
|
|
98 |
|
99 |
if ( isset( $bp->version ) && $bp->version > '2.5.3' ) {
|
100 |
|
101 |
-
|
102 |
* As from BuddyPress 2.6, you can't access $bp->bp_options_nav directly.
|
103 |
* Use `bp_core_new_subnav_item` to add subnav item.
|
104 |
*
|
105 |
* Check https://buddypress.trac.wordpress.org/ticket/6534 and https://buddypress.trac.wordpress.org/changeset/10745
|
106 |
* for more details
|
107 |
*/
|
108 |
-
bp_core_new_subnav_item(
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
|
|
|
|
120 |
|
121 |
} else {
|
122 |
$bp->bp_options_nav[ bp_get_current_group_slug() ]['media'] = array(
|
@@ -134,7 +170,10 @@ class RTMediaNav {
|
|
134 |
}
|
135 |
}
|
136 |
|
137 |
-
|
|
|
|
|
|
|
138 |
global $wp_admin_bar;
|
139 |
global $rtmedia;
|
140 |
if ( ( ! isset( $rtmedia->options['buddypress_enableOnProfile'] ) ) || ( isset( $rtmedia->options['buddypress_enableOnProfile'] ) && 0 === intval( $rtmedia->options['buddypress_enableOnProfile'] ) ) ) {
|
@@ -144,27 +183,32 @@ class RTMediaNav {
|
|
144 |
return;
|
145 |
}
|
146 |
|
147 |
-
// Bail if this is an ajax request
|
148 |
if ( defined( 'DOING_AJAX' ) ) {
|
149 |
return;
|
150 |
}
|
151 |
-
|
|
|
152 |
if ( is_user_logged_in() ) {
|
153 |
-
// Add secondary parent item for all BuddyPress components
|
154 |
-
$wp_admin_bar->add_menu(
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
|
|
|
|
160 |
|
161 |
if ( is_rtmedia_album_enable() ) {
|
162 |
-
$wp_admin_bar->add_menu(
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
|
|
|
|
168 |
}
|
169 |
|
170 |
global $rtmedia;
|
@@ -175,18 +219,23 @@ class RTMediaNav {
|
|
175 |
continue;
|
176 |
}
|
177 |
$name = strtoupper( $type['name'] );
|
178 |
-
$wp_admin_bar->add_menu(
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
|
|
|
|
184 |
}
|
185 |
}
|
186 |
do_action( 'rtmedia_add_admin_bar_media_sub_menu', 'my-account-' . RTMEDIA_MEDIA_SLUG );
|
187 |
}
|
188 |
}
|
189 |
|
|
|
|
|
|
|
190 |
public function sub_nav() {
|
191 |
global $rtmedia, $rtmedia_query;
|
192 |
|
@@ -194,6 +243,7 @@ class RTMediaNav {
|
|
194 |
if ( isset( $active_components['groups'] ) ) {
|
195 |
$user_groups = $active_components['groups'];
|
196 |
}
|
|
|
197 |
$user_group_status = ( isset( $user_groups ) && ( '1' === $user_groups ) ) ? true : false;
|
198 |
if ( function_exists( 'bp_is_group' ) && bp_is_group() && $user_group_status ) {
|
199 |
if ( isset( $rtmedia->options['buddypress_enableOnGroup'] ) && 0 === intval( $rtmedia->options['buddypress_enableOnGroup'] ) ) {
|
@@ -214,6 +264,7 @@ class RTMediaNav {
|
|
214 |
$model = new RTMediaModel();
|
215 |
$other_count = $model->get_other_album_count( bp_get_group_id(), 'group' );
|
216 |
} else {
|
|
|
217 |
if ( function_exists( 'bp_displayed_user_id' ) && bp_displayed_user_id() ) {
|
218 |
$link = get_rtmedia_user_link( bp_displayed_user_id() );
|
219 |
} elseif ( get_query_var( 'author' ) ) {
|
@@ -222,6 +273,7 @@ class RTMediaNav {
|
|
222 |
$model = new RTMediaModel();
|
223 |
$other_count = $model->get_other_album_count( bp_displayed_user_id(), 'profile' );
|
224 |
}
|
|
|
225 |
$all = '';
|
226 |
if ( ! isset( $rtmedia_query->action_query->media_type ) && ! isset( $rtmedia_query->query['media_type'] ) ) {
|
227 |
$all = 'current selected';
|
@@ -237,7 +289,6 @@ class RTMediaNav {
|
|
237 |
$albums = 'current selected';
|
238 |
} elseif ( isset( $rtmedia_query->action_query->media_type ) && ( 'album' === $rtmedia_query->action_query->media_type ) ) {
|
239 |
$albums = 'current selected';
|
240 |
-
|
241 |
}
|
242 |
|
243 |
if ( is_rtmedia_album_enable() ) {
|
@@ -304,10 +355,19 @@ class RTMediaNav {
|
|
304 |
do_action( 'add_extra_sub_nav' );
|
305 |
}
|
306 |
|
307 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
308 |
$model = new RTMediaModel();
|
309 |
$counts = $model->get_counts( $user_id, $where );
|
310 |
$media_count = array();
|
|
|
311 |
foreach ( $counts as $count ) {
|
312 |
if ( ! isset( $count->privacy ) ) {
|
313 |
$count->privacy = 0;
|
@@ -324,9 +384,9 @@ class RTMediaNav {
|
|
324 |
|
325 |
if ( isset( $where['context'] ) ) {
|
326 |
if ( 'profile' === $where['context'] ) {
|
327 |
-
//todo user attr
|
328 |
update_user_meta( $user_id, 'rtmedia_counts_' . get_current_blog_id(), $media_count );
|
329 |
-
}
|
330 |
groups_update_groupmeta( $user_id, 'rtmedia_counts_' . get_current_blog_id(), $media_count );
|
331 |
}
|
332 |
}
|
@@ -334,38 +394,62 @@ class RTMediaNav {
|
|
334 |
return $media_count;
|
335 |
}
|
336 |
|
337 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
338 |
if ( false === $profile_id && 'profile' === $context ) {
|
339 |
$profile_id = $this->profile_id();
|
340 |
-
}
|
341 |
$profile_id = $this->group_id();
|
342 |
}
|
|
|
343 |
if ( ! $profile_id ) {
|
344 |
return false;
|
345 |
}
|
|
|
346 |
if ( 'profile' === $context ) {
|
347 |
-
//todo user attr
|
348 |
$counts = get_user_meta( $profile_id, 'rtmedia_counts_' . get_current_blog_id(), true );
|
|
|
349 |
if ( empty( $counts ) ) {
|
350 |
-
$counts = $this->refresh_counts(
|
351 |
-
|
352 |
-
|
353 |
-
|
|
|
|
|
|
|
354 |
}
|
355 |
-
}
|
|
|
356 |
$counts = groups_get_groupmeta( $profile_id, 'rtmedia_counts_' . get_current_blog_id() );
|
|
|
357 |
if ( empty( $counts ) ) {
|
358 |
-
$counts = $this->refresh_counts(
|
359 |
-
|
360 |
-
|
361 |
-
|
|
|
|
|
|
|
362 |
}
|
363 |
}
|
364 |
|
365 |
return $counts;
|
366 |
}
|
367 |
|
368 |
-
|
|
|
|
|
|
|
|
|
|
|
369 |
global $rtmedia_query;
|
370 |
if ( isset( $rtmedia_query->query['context'] ) && ( 'profile' === $rtmedia_query->query['context'] ) ) {
|
371 |
return $rtmedia_query->query['context_id'];
|
@@ -374,14 +458,27 @@ class RTMediaNav {
|
|
374 |
return false;
|
375 |
}
|
376 |
|
377 |
-
|
|
|
|
|
|
|
|
|
|
|
378 |
global $rtmedia_query;
|
379 |
if ( isset( $rtmedia_query->query['context'] ) && ( 'group' === $rtmedia_query->query['context'] ) ) {
|
380 |
return $rtmedia_query->query['context_id'];
|
381 |
}
|
382 |
}
|
383 |
|
384 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
385 |
if ( false === $profile_id ) {
|
386 |
if ( ! $this->profile_id() ) {
|
387 |
return;
|
@@ -394,16 +491,29 @@ class RTMediaNav {
|
|
394 |
return $this->process_count( $media_count, $privacy );
|
395 |
}
|
396 |
|
397 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
398 |
$total = array( 'all' => 0 );
|
399 |
$media_count = ! empty( $media_count ) ? $media_count : array();
|
400 |
$exclude_type_count = apply_filters( 'rtmedia_media_count_exclude_type', array( 'album' ) );
|
|
|
401 |
foreach ( $media_count as $private => $ind_count ) {
|
|
|
402 |
if ( $private <= $privacy ) {
|
|
|
403 |
foreach ( $ind_count as $type => $ind_ind_count ) {
|
|
|
404 |
if ( ! in_array( $type, $exclude_type_count, true ) ) {
|
405 |
$total['all'] += (int) $ind_ind_count;
|
406 |
}
|
|
|
407 |
if ( ! isset( $total[ $type ] ) ) {
|
408 |
$total[ $type ] = 0;
|
409 |
}
|
@@ -419,7 +529,12 @@ class RTMediaNav {
|
|
419 |
return $media_count;
|
420 |
}
|
421 |
|
422 |
-
|
|
|
|
|
|
|
|
|
|
|
423 |
if ( is_user_logged_in() ) {
|
424 |
$user = get_current_user_id();
|
425 |
} else {
|
@@ -429,7 +544,14 @@ class RTMediaNav {
|
|
429 |
return $user;
|
430 |
}
|
431 |
|
432 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
433 |
if ( is_rt_admin() ) {
|
434 |
return 60;
|
435 |
}
|
@@ -439,19 +561,113 @@ class RTMediaNav {
|
|
439 |
if ( $user ) {
|
440 |
$privacy = 20;
|
441 |
}
|
|
|
442 |
if ( false === $profile ) {
|
443 |
$profile = $this->profile_id();
|
444 |
}
|
|
|
445 |
if ( class_exists( 'BuddyPress' ) && bp_is_active( 'friends' ) ) {
|
446 |
|
447 |
if ( friends_check_friendship_status( $user, $profile ) ) {
|
448 |
$privacy = 40;
|
449 |
}
|
450 |
}
|
|
|
451 |
if ( $user === $profile ) {
|
452 |
$privacy = 60;
|
453 |
}
|
454 |
|
455 |
return $privacy;
|
456 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
457 |
}
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* Handles rtMedia navigation menus.
|
4 |
+
*
|
5 |
+
* @package rtMedia
|
6 |
+
*/
|
7 |
+
|
8 |
+
/**
|
9 |
+
* Class to handle rtMedia navigation menus.
|
10 |
+
*/
|
11 |
class RTMediaNav {
|
12 |
|
13 |
+
/**
|
14 |
+
* RTMediaNav constructor.
|
15 |
+
*
|
16 |
+
* @param bool $action Add filters/actions or not.
|
17 |
+
*/
|
18 |
+
public function __construct( $action = true ) {
|
19 |
if ( false === $action ) {
|
20 |
return;
|
21 |
}
|
32 |
|
33 |
if ( class_exists( 'BuddyPress' ) ) {
|
34 |
add_action( 'bp_init', array( $this, 'custom_media_nav_tab' ), 10, 1 );
|
35 |
+
add_filter( 'bp_nouveau_nav_has_count', array( $this, 'rtmedia_bp_nouveau_nav_has_count' ), 10, 3 );
|
36 |
+
add_filter( 'bp_nouveau_get_nav_count', array( $this, 'rtmedia_bp_nouveau_get_nav_count' ), 10, 3 );
|
37 |
}
|
38 |
|
39 |
add_filter( 'bp_settings_admin_nav', array( $this, 'setup_settings_privacy_nav' ), 3 );
|
40 |
}
|
41 |
|
42 |
+
/**
|
43 |
+
* Media screen.
|
44 |
+
*
|
45 |
+
* @return null
|
46 |
+
*/
|
47 |
+
public function media_screen() {
|
48 |
+
// todo:remove if not used.
|
49 |
+
return null;
|
50 |
}
|
51 |
|
52 |
+
/**
|
53 |
+
* Add my account admin menu.
|
54 |
+
*
|
55 |
+
* @param array $wp_admin_nav Admin navigation menu arrays.
|
56 |
+
*
|
57 |
+
* @return array
|
58 |
+
*/
|
59 |
public function setup_settings_privacy_nav( $wp_admin_nav ) {
|
60 |
+
// Setup the logged in user variables.
|
|
|
61 |
if ( is_rtmedia_privacy_user_overide() ) {
|
62 |
$settings_link = trailingslashit( bp_loggedin_user_domain() . bp_get_settings_slug() );
|
63 |
|
64 |
+
// Add the "Profile" subnav item.
|
65 |
$wp_admin_nav[] = array(
|
66 |
'parent' => 'my-account-' . buddypress()->settings->id,
|
67 |
'id' => 'my-account-' . buddypress()->settings->id . '-privacy',
|
78 |
*
|
79 |
* @global object $bp global BuddyPress object
|
80 |
*/
|
81 |
+
public function custom_media_nav_tab() {
|
82 |
$bp = buddypress();
|
83 |
+
|
84 |
if ( ! function_exists( 'bp_core_new_nav_item' ) ) {
|
85 |
return;
|
86 |
}
|
87 |
+
|
88 |
if ( bp_is_blog_page() || ( ! bp_is_group() && ! ( isset( $bp->displayed_user ) && isset( $bp->displayed_user->id ) ) ) || apply_filters( 'rtmedia_render_bp_nav', false ) ) {
|
89 |
return;
|
90 |
}
|
91 |
+
|
92 |
global $rtmedia;
|
93 |
+
|
94 |
if ( function_exists( 'bp_is_group' ) && ! bp_is_group() ) {
|
95 |
+
|
96 |
if ( isset( $bp->displayed_user ) && isset( $bp->displayed_user->id ) ) {
|
97 |
$profile_counts = $this->actual_counts( $bp->displayed_user->id );
|
98 |
}
|
99 |
+
|
100 |
$tab_position = apply_filters( 'rtmedia_media_tab_position', 99 );
|
101 |
if ( 0 !== intval( $rtmedia->options['buddypress_enableOnProfile'] ) ) {
|
102 |
+
bp_core_new_nav_item(
|
103 |
+
array(
|
104 |
+
'name' => apply_filters( 'rtmedia_media_tab_name', RTMEDIA_MEDIA_LABEL ) . ' <span>' . rtmedia_number_to_human_readable( $profile_counts['total']['all'] ) . '</span>',
|
105 |
+
'slug' => apply_filters( 'rtmedia_media_tab_slug', RTMEDIA_MEDIA_SLUG ),
|
106 |
+
'screen_function' => array( $this, 'media_screen' ),
|
107 |
+
'default_subnav_slug' => 'all',
|
108 |
+
'position' => $tab_position,
|
109 |
+
)
|
110 |
+
);
|
111 |
}
|
112 |
}
|
113 |
+
|
114 |
if ( bp_is_group() && 0 !== intval( $rtmedia->options['buddypress_enableOnGroup'] ) ) {
|
115 |
$media_enabled = true;
|
116 |
+
// filter for rtMedia PRO for PER GROUP MEDIA enable/disable functionality.
|
117 |
$media_enabled = apply_filters( 'rtmedia_media_enabled_for_current_group', $media_enabled );
|
118 |
|
119 |
+
// check if current user can view this group.
|
120 |
$current_group = groups_get_current_group();
|
121 |
/**
|
122 |
+
* Remove `$current_group->is_visible` and add `bp_group_is_visible( $current_group )`
|
123 |
* reason : In Buddypress 2.7 `is_visible` return false so we can't display `media` tab on group
|
124 |
+
* issue id : http://git.rtcamp.com/rtmedia/rtMedia/issues/119
|
125 |
*/
|
|
|
|
|
126 |
$is_visible_to_current_user = bp_group_is_visible( $current_group );
|
127 |
|
128 |
if ( $media_enabled && $is_visible_to_current_user ) {
|
132 |
|
133 |
if ( isset( $bp->version ) && $bp->version > '2.5.3' ) {
|
134 |
|
135 |
+
/**
|
136 |
* As from BuddyPress 2.6, you can't access $bp->bp_options_nav directly.
|
137 |
* Use `bp_core_new_subnav_item` to add subnav item.
|
138 |
*
|
139 |
* Check https://buddypress.trac.wordpress.org/ticket/6534 and https://buddypress.trac.wordpress.org/changeset/10745
|
140 |
* for more details
|
141 |
*/
|
142 |
+
bp_core_new_subnav_item(
|
143 |
+
array(
|
144 |
+
'name' => apply_filters( 'rtmedia_media_tab_name', RTMEDIA_MEDIA_LABEL ) . ' <span>' . rtmedia_number_to_human_readable( $group_counts['total']['all'] ) . '</span>',
|
145 |
+
'link' => trailingslashit( bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/' . bp_get_current_group_slug() . '/' ) . $slug,
|
146 |
+
'slug' => $slug,
|
147 |
+
'parent_slug' => bp_get_current_group_slug(),
|
148 |
+
'parent_url' => trailingslashit( bp_get_root_domain() . '/' . bp_get_groups_root_slug() . '/' . bp_get_current_group_slug() . '/' ),
|
149 |
+
'user_has_access' => true,
|
150 |
+
'css_id' => 'rtmedia-media-nav',
|
151 |
+
'position' => $media_tab_position,
|
152 |
+
'screen_function' => array( $this, 'media_screen' ),
|
153 |
+
'default_subnav_slug' => 'all',
|
154 |
+
)
|
155 |
+
);
|
156 |
|
157 |
} else {
|
158 |
$bp->bp_options_nav[ bp_get_current_group_slug() ]['media'] = array(
|
170 |
}
|
171 |
}
|
172 |
|
173 |
+
/**
|
174 |
+
* Add my account admin menu.
|
175 |
+
*/
|
176 |
+
public function admin_nav() {
|
177 |
global $wp_admin_bar;
|
178 |
global $rtmedia;
|
179 |
if ( ( ! isset( $rtmedia->options['buddypress_enableOnProfile'] ) ) || ( isset( $rtmedia->options['buddypress_enableOnProfile'] ) && 0 === intval( $rtmedia->options['buddypress_enableOnProfile'] ) ) ) {
|
183 |
return;
|
184 |
}
|
185 |
|
186 |
+
// Bail if this is an ajax request.
|
187 |
if ( defined( 'DOING_AJAX' ) ) {
|
188 |
return;
|
189 |
}
|
190 |
+
|
191 |
+
// Only add menu for logged in user.
|
192 |
if ( is_user_logged_in() ) {
|
193 |
+
// Add secondary parent item for all BuddyPress components.
|
194 |
+
$wp_admin_bar->add_menu(
|
195 |
+
array(
|
196 |
+
'parent' => 'my-account',
|
197 |
+
'id' => 'my-account-' . RTMEDIA_MEDIA_SLUG,
|
198 |
+
'title' => apply_filters( 'rtmedia_media_tab_name', RTMEDIA_MEDIA_LABEL ),
|
199 |
+
'href' => trailingslashit( get_rtmedia_user_link( get_current_user_id() ) ) . RTMEDIA_MEDIA_SLUG . '/',
|
200 |
+
)
|
201 |
+
);
|
202 |
|
203 |
if ( is_rtmedia_album_enable() ) {
|
204 |
+
$wp_admin_bar->add_menu(
|
205 |
+
array(
|
206 |
+
'parent' => 'my-account-' . RTMEDIA_MEDIA_SLUG,
|
207 |
+
'id' => 'my-account-media-' . RTMEDIA_ALBUM_SLUG,
|
208 |
+
'title' => RTMEDIA_ALBUM_PLURAL_LABEL,
|
209 |
+
'href' => trailingslashit( get_rtmedia_user_link( get_current_user_id() ) ) . RTMEDIA_MEDIA_SLUG . '/album/',
|
210 |
+
)
|
211 |
+
);
|
212 |
}
|
213 |
|
214 |
global $rtmedia;
|
219 |
continue;
|
220 |
}
|
221 |
$name = strtoupper( $type['name'] );
|
222 |
+
$wp_admin_bar->add_menu(
|
223 |
+
array(
|
224 |
+
'parent' => 'my-account-' . constant( 'RTMEDIA_MEDIA_SLUG' ),
|
225 |
+
'id' => 'my-account-media-' . constant( 'RTMEDIA_' . $name . '_SLUG' ),
|
226 |
+
'title' => $type['plural_label'],
|
227 |
+
'href' => trailingslashit( get_rtmedia_user_link( get_current_user_id() ) ) . RTMEDIA_MEDIA_SLUG . '/' . constant( 'RTMEDIA_' . $name . '_SLUG' ) . '/',
|
228 |
+
)
|
229 |
+
);
|
230 |
}
|
231 |
}
|
232 |
do_action( 'rtmedia_add_admin_bar_media_sub_menu', 'my-account-' . RTMEDIA_MEDIA_SLUG );
|
233 |
}
|
234 |
}
|
235 |
|
236 |
+
/**
|
237 |
+
* Add submenus for My account.
|
238 |
+
*/
|
239 |
public function sub_nav() {
|
240 |
global $rtmedia, $rtmedia_query;
|
241 |
|
243 |
if ( isset( $active_components['groups'] ) ) {
|
244 |
$user_groups = $active_components['groups'];
|
245 |
}
|
246 |
+
|
247 |
$user_group_status = ( isset( $user_groups ) && ( '1' === $user_groups ) ) ? true : false;
|
248 |
if ( function_exists( 'bp_is_group' ) && bp_is_group() && $user_group_status ) {
|
249 |
if ( isset( $rtmedia->options['buddypress_enableOnGroup'] ) && 0 === intval( $rtmedia->options['buddypress_enableOnGroup'] ) ) {
|
264 |
$model = new RTMediaModel();
|
265 |
$other_count = $model->get_other_album_count( bp_get_group_id(), 'group' );
|
266 |
} else {
|
267 |
+
|
268 |
if ( function_exists( 'bp_displayed_user_id' ) && bp_displayed_user_id() ) {
|
269 |
$link = get_rtmedia_user_link( bp_displayed_user_id() );
|
270 |
} elseif ( get_query_var( 'author' ) ) {
|
273 |
$model = new RTMediaModel();
|
274 |
$other_count = $model->get_other_album_count( bp_displayed_user_id(), 'profile' );
|
275 |
}
|
276 |
+
|
277 |
$all = '';
|
278 |
if ( ! isset( $rtmedia_query->action_query->media_type ) && ! isset( $rtmedia_query->query['media_type'] ) ) {
|
279 |
$all = 'current selected';
|
289 |
$albums = 'current selected';
|
290 |
} elseif ( isset( $rtmedia_query->action_query->media_type ) && ( 'album' === $rtmedia_query->action_query->media_type ) ) {
|
291 |
$albums = 'current selected';
|
|
|
292 |
}
|
293 |
|
294 |
if ( is_rtmedia_album_enable() ) {
|
355 |
do_action( 'add_extra_sub_nav' );
|
356 |
}
|
357 |
|
358 |
+
/**
|
359 |
+
* Get User media count.
|
360 |
+
*
|
361 |
+
* @param int $user_id User id.
|
362 |
+
* @param array $where Media details.
|
363 |
+
*
|
364 |
+
* @return array
|
365 |
+
*/
|
366 |
+
public function refresh_counts( $user_id, $where ) {
|
367 |
$model = new RTMediaModel();
|
368 |
$counts = $model->get_counts( $user_id, $where );
|
369 |
$media_count = array();
|
370 |
+
|
371 |
foreach ( $counts as $count ) {
|
372 |
if ( ! isset( $count->privacy ) ) {
|
373 |
$count->privacy = 0;
|
384 |
|
385 |
if ( isset( $where['context'] ) ) {
|
386 |
if ( 'profile' === $where['context'] ) {
|
387 |
+
// todo user attr.
|
388 |
update_user_meta( $user_id, 'rtmedia_counts_' . get_current_blog_id(), $media_count );
|
389 |
+
} elseif ( 'group' === $where['context'] && function_exists( 'groups_update_groupmeta' ) ) {
|
390 |
groups_update_groupmeta( $user_id, 'rtmedia_counts_' . get_current_blog_id(), $media_count );
|
391 |
}
|
392 |
}
|
394 |
return $media_count;
|
395 |
}
|
396 |
|
397 |
+
/**
|
398 |
+
* Get media counts.
|
399 |
+
*
|
400 |
+
* @param bool|int $profile_id User id.
|
401 |
+
* @param string $context Count context.
|
402 |
+
*
|
403 |
+
* @return array|bool|mixed
|
404 |
+
*/
|
405 |
+
public function get_counts( $profile_id = false, $context = 'profile' ) {
|
406 |
if ( false === $profile_id && 'profile' === $context ) {
|
407 |
$profile_id = $this->profile_id();
|
408 |
+
} elseif ( false === $profile_id && 'profile' === $context ) {
|
409 |
$profile_id = $this->group_id();
|
410 |
}
|
411 |
+
|
412 |
if ( ! $profile_id ) {
|
413 |
return false;
|
414 |
}
|
415 |
+
|
416 |
if ( 'profile' === $context ) {
|
417 |
+
// todo user attr.
|
418 |
$counts = get_user_meta( $profile_id, 'rtmedia_counts_' . get_current_blog_id(), true );
|
419 |
+
|
420 |
if ( empty( $counts ) ) {
|
421 |
+
$counts = $this->refresh_counts(
|
422 |
+
$profile_id,
|
423 |
+
array(
|
424 |
+
'context' => $context,
|
425 |
+
'media_author' => $profile_id,
|
426 |
+
)
|
427 |
+
);
|
428 |
}
|
429 |
+
} elseif ( function_exists( 'groups_get_groupmeta' ) && 'group' === $context ) {
|
430 |
+
|
431 |
$counts = groups_get_groupmeta( $profile_id, 'rtmedia_counts_' . get_current_blog_id() );
|
432 |
+
|
433 |
if ( empty( $counts ) ) {
|
434 |
+
$counts = $this->refresh_counts(
|
435 |
+
$profile_id,
|
436 |
+
array(
|
437 |
+
'context' => $context,
|
438 |
+
'context_id' => $profile_id,
|
439 |
+
)
|
440 |
+
);
|
441 |
}
|
442 |
}
|
443 |
|
444 |
return $counts;
|
445 |
}
|
446 |
|
447 |
+
/**
|
448 |
+
* Get profile id.
|
449 |
+
*
|
450 |
+
* @return bool
|
451 |
+
*/
|
452 |
+
public function profile_id() {
|
453 |
global $rtmedia_query;
|
454 |
if ( isset( $rtmedia_query->query['context'] ) && ( 'profile' === $rtmedia_query->query['context'] ) ) {
|
455 |
return $rtmedia_query->query['context_id'];
|
458 |
return false;
|
459 |
}
|
460 |
|
461 |
+
/**
|
462 |
+
* Get group id.
|
463 |
+
*
|
464 |
+
* @return mixed
|
465 |
+
*/
|
466 |
+
public function group_id() {
|
467 |
global $rtmedia_query;
|
468 |
if ( isset( $rtmedia_query->query['context'] ) && ( 'group' === $rtmedia_query->query['context'] ) ) {
|
469 |
return $rtmedia_query->query['context_id'];
|
470 |
}
|
471 |
}
|
472 |
|
473 |
+
/**
|
474 |
+
* Get media count.
|
475 |
+
*
|
476 |
+
* @param bool|int $profile_id Profile/user id.
|
477 |
+
* @param string $context Count context.
|
478 |
+
*
|
479 |
+
* @return array|void
|
480 |
+
*/
|
481 |
+
public function actual_counts( $profile_id = false, $context = 'profile' ) {
|
482 |
if ( false === $profile_id ) {
|
483 |
if ( ! $this->profile_id() ) {
|
484 |
return;
|
491 |
return $this->process_count( $media_count, $privacy );
|
492 |
}
|
493 |
|
494 |
+
/**
|
495 |
+
* Process media count.
|
496 |
+
*
|
497 |
+
* @param array $media_count media count array.
|
498 |
+
* @param int $privacy media privacy.
|
499 |
+
*
|
500 |
+
* @return array
|
501 |
+
*/
|
502 |
+
public function process_count( $media_count, $privacy ) {
|
503 |
$total = array( 'all' => 0 );
|
504 |
$media_count = ! empty( $media_count ) ? $media_count : array();
|
505 |
$exclude_type_count = apply_filters( 'rtmedia_media_count_exclude_type', array( 'album' ) );
|
506 |
+
|
507 |
foreach ( $media_count as $private => $ind_count ) {
|
508 |
+
|
509 |
if ( $private <= $privacy ) {
|
510 |
+
|
511 |
foreach ( $ind_count as $type => $ind_ind_count ) {
|
512 |
+
|
513 |
if ( ! in_array( $type, $exclude_type_count, true ) ) {
|
514 |
$total['all'] += (int) $ind_ind_count;
|
515 |
}
|
516 |
+
|
517 |
if ( ! isset( $total[ $type ] ) ) {
|
518 |
$total[ $type ] = 0;
|
519 |
}
|
529 |
return $media_count;
|
530 |
}
|
531 |
|
532 |
+
/**
|
533 |
+
* Get user id.
|
534 |
+
*
|
535 |
+
* @return int
|
536 |
+
*/
|
537 |
+
public function visitor_id() {
|
538 |
if ( is_user_logged_in() ) {
|
539 |
$user = get_current_user_id();
|
540 |
} else {
|
544 |
return $user;
|
545 |
}
|
546 |
|
547 |
+
/**
|
548 |
+
* Get profile privacy.
|
549 |
+
*
|
550 |
+
* @param int $profile Profile id.
|
551 |
+
*
|
552 |
+
* @return int
|
553 |
+
*/
|
554 |
+
public function set_privacy( $profile ) {
|
555 |
if ( is_rt_admin() ) {
|
556 |
return 60;
|
557 |
}
|
561 |
if ( $user ) {
|
562 |
$privacy = 20;
|
563 |
}
|
564 |
+
|
565 |
if ( false === $profile ) {
|
566 |
$profile = $this->profile_id();
|
567 |
}
|
568 |
+
|
569 |
if ( class_exists( 'BuddyPress' ) && bp_is_active( 'friends' ) ) {
|
570 |
|
571 |
if ( friends_check_friendship_status( $user, $profile ) ) {
|
572 |
$privacy = 40;
|
573 |
}
|
574 |
}
|
575 |
+
|
576 |
if ( $user === $profile ) {
|
577 |
$privacy = 60;
|
578 |
}
|
579 |
|
580 |
return $privacy;
|
581 |
}
|
582 |
+
|
583 |
+
/**
|
584 |
+
* Check if media component has counts.
|
585 |
+
*
|
586 |
+
* @param bool $has_count True if the nav has a count attribute. False otherwise.
|
587 |
+
* @param object $object Nav object.
|
588 |
+
* @param string $value Current component (personal, groups, etc).
|
589 |
+
*
|
590 |
+
* @return bool
|
591 |
+
*/
|
592 |
+
public function rtmedia_bp_nouveau_nav_has_count( $has_count, $object, $value ) {
|
593 |
+
|
594 |
+
// Check if its media.
|
595 |
+
if ( RTMEDIA_MEDIA_SLUG !== $object->slug ) {
|
596 |
+
return $has_count;
|
597 |
+
}
|
598 |
+
|
599 |
+
global $bp;
|
600 |
+
|
601 |
+
$media = [];
|
602 |
+
|
603 |
+
// If current component is `groups` then fetch its media.
|
604 |
+
if ( 'groups' === $value ) {
|
605 |
+
$media = $this->actual_counts( $bp->groups->current_group->id, 'group' );
|
606 |
+
}
|
607 |
+
|
608 |
+
// If current component is `personal` then fetch its media.
|
609 |
+
if ( 'personal' === $value ) {
|
610 |
+
$media = $this->actual_counts( $bp->displayed_user->id );
|
611 |
+
}
|
612 |
+
|
613 |
+
if ( empty( $media ) || empty( $media['total'] ) || empty( $media['total']['all'] ) ) {
|
614 |
+
return $has_count;
|
615 |
+
}
|
616 |
+
|
617 |
+
// Convert to number.
|
618 |
+
$media_count = rtmedia_number_to_human_readable( absint( $media['total']['all'] ) );
|
619 |
+
|
620 |
+
if ( empty( $media_count ) ) {
|
621 |
+
return $has_count;
|
622 |
+
}
|
623 |
+
|
624 |
+
// Return true because `media` has count.
|
625 |
+
return true;
|
626 |
+
}
|
627 |
+
|
628 |
+
/**
|
629 |
+
* Add count to media component.
|
630 |
+
*
|
631 |
+
* @param int $count Component feed count.
|
632 |
+
* @param object $object Nav object.
|
633 |
+
* @param string $value Current component (personal, groups, etc).
|
634 |
+
*
|
635 |
+
* @return int
|
636 |
+
*/
|
637 |
+
public function rtmedia_bp_nouveau_get_nav_count( $count, $object, $value ) {
|
638 |
+
|
639 |
+
// Check if its media.
|
640 |
+
if ( RTMEDIA_MEDIA_SLUG !== $object->slug ) {
|
641 |
+
return $count;
|
642 |
+
}
|
643 |
+
|
644 |
+
global $bp;
|
645 |
+
|
646 |
+
$media = [];
|
647 |
+
|
648 |
+
// If current component is `groups` then fetch its media.
|
649 |
+
if ( 'groups' === $value ) {
|
650 |
+
$media = $this->actual_counts( $bp->groups->current_group->id, 'group' );
|
651 |
+
}
|
652 |
+
|
653 |
+
// If current component is `personal` then fetch its media.
|
654 |
+
if ( 'personal' === $value ) {
|
655 |
+
$media = $this->actual_counts( $bp->displayed_user->id );
|
656 |
+
}
|
657 |
+
|
658 |
+
if ( empty( $media ) || empty( $media['total'] ) || empty( $media['total']['all'] ) ) {
|
659 |
+
return $count;
|
660 |
+
}
|
661 |
+
|
662 |
+
// Convert to number.
|
663 |
+
$media_count = rtmedia_number_to_human_readable( absint( $media['total']['all'] ) );
|
664 |
+
|
665 |
+
if ( empty( $media_count ) ) {
|
666 |
+
return $count;
|
667 |
+
}
|
668 |
+
|
669 |
+
// Return media count.
|
670 |
+
return $media_count;
|
671 |
+
}
|
672 |
+
|
673 |
}
|
app/main/controllers/template/RTMediaTemplate.php
CHANGED
@@ -1,18 +1,28 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
/**
|
4 |
-
* Description of RTMediaTemplate
|
5 |
-
*
|
6 |
* Template to display rtMedia Gallery.
|
7 |
* A stand alone template that renders the gallery/uploader on the page.
|
8 |
*
|
|
|
9 |
* @author saurabh
|
10 |
*/
|
|
|
|
|
|
|
|
|
11 |
class RTMediaTemplate {
|
12 |
|
|
|
|
|
|
|
|
|
|
|
13 |
public $media_args;
|
14 |
|
15 |
-
|
|
|
|
|
|
|
16 |
global $rtmedia_query;
|
17 |
|
18 |
if ( $rtmedia_query ) {
|
@@ -30,7 +40,7 @@ class RTMediaTemplate {
|
|
30 |
/**
|
31 |
* Enqueues required scripts on the page
|
32 |
*/
|
33 |
-
function enqueue_scripts() {
|
34 |
wp_enqueue_script( 'rtmedia-backbone' );
|
35 |
|
36 |
$is_album = is_rtmedia_album() ? true : false;
|
@@ -40,37 +50,45 @@ class RTMediaTemplate {
|
|
40 |
wp_localize_script( 'rtmedia-backbone', 'is_edit_allowed', array( $is_edit_allowed ) );
|
41 |
}
|
42 |
|
43 |
-
|
|
|
|
|
|
|
44 |
global $rtmedia_query;
|
45 |
|
46 |
wp_enqueue_script( 'wp-ajax-response' );
|
47 |
|
48 |
if ( $rtmedia_query->is_single_edit() ) {
|
49 |
-
wp_enqueue_script(
|
50 |
-
'
|
51 |
-
'
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
}
|
57 |
}
|
58 |
|
59 |
/**
|
60 |
-
*
|
61 |
-
* Pass on the shortcode attributes to the template so that the shortcode can
|
62 |
*
|
63 |
* Also handles the json request coming from the AJAX calls for the media
|
64 |
*
|
65 |
-
* @param bool|
|
66 |
-
* @param bool|
|
67 |
*
|
68 |
-
* @return
|
69 |
* @global type $rtmedia_query
|
70 |
* @global type $rtmedia_interaction
|
71 |
-
*
|
72 |
*/
|
73 |
-
function set_template( $template = false, $shortcode_attr = false ) {
|
74 |
global $rtmedia_query, $rtmedia_interaction, $rtmedia_media;
|
75 |
|
76 |
do_action( 'rtmedia_pre_template' );
|
@@ -84,10 +102,14 @@ class RTMediaTemplate {
|
|
84 |
$this->check_return_json();
|
85 |
$this->check_return_upload();
|
86 |
|
87 |
-
if ( $rtmedia_interaction && isset( $rtmedia_interaction->context ) && in_array(
|
|
|
|
|
88 |
'profile',
|
89 |
'group',
|
90 |
-
|
|
|
|
|
91 |
) {
|
92 |
$this->check_return_edit();
|
93 |
$this->check_return_delete();
|
@@ -107,10 +129,10 @@ class RTMediaTemplate {
|
|
107 |
|
108 |
$this->add_hidden_fields_in_gallery();
|
109 |
|
110 |
-
$gallery_template = apply_filters( 'rtmedia-before-template', $template, $shortcode_attr );
|
111 |
|
112 |
-
// check if file exists
|
113 |
-
if ( file_exists(
|
114 |
include $this->locate_template( $gallery_template );
|
115 |
}
|
116 |
|
@@ -141,7 +163,6 @@ class RTMediaTemplate {
|
|
141 |
$rtaccount = 0;
|
142 |
}
|
143 |
|
144 |
-
//add_action("rtmedia_before_media_gallery",array(&$this,"")) ;
|
145 |
$include_uploader = false;
|
146 |
|
147 |
if ( isset( $shortcode_attr['attr'] ) && isset( $shortcode_attr['attr']['uploader'] ) ) {
|
@@ -151,24 +172,24 @@ class RTMediaTemplate {
|
|
151 |
}
|
152 |
|
153 |
if ( 'before' === $include_uploader ) {
|
154 |
-
echo RTMediaUploadShortcode::pre_render( $shortcode_attr['attr'] )
|
155 |
}
|
156 |
|
157 |
echo "<div class='rtmedia_gallery_wrapper'>";
|
158 |
|
159 |
$this->add_hidden_fields_in_gallery();
|
160 |
|
161 |
-
$gallery_template = apply_filters( 'rtmedia-before-template', $template, $shortcode_attr );
|
162 |
|
163 |
-
// check if file exists
|
164 |
-
if ( file_exists(
|
165 |
include $this->locate_template( $gallery_template );
|
166 |
}
|
167 |
|
168 |
echo '</div>';
|
169 |
|
170 |
if ( 'after' === $include_uploader || 'true' === $include_uploader ) {
|
171 |
-
echo RTMediaUploadShortcode::pre_render( $shortcode_attr['attr'] )
|
172 |
}
|
173 |
} else {
|
174 |
echo esc_html__( 'Invalid attribute passed for rtmedia_gallery shortcode.', 'buddypress-media' );
|
@@ -180,11 +201,14 @@ class RTMediaTemplate {
|
|
180 |
}
|
181 |
}
|
182 |
|
183 |
-
|
|
|
|
|
|
|
184 |
global $rtmedia_query;
|
185 |
|
186 |
-
$is_on_home
|
187 |
-
$return_str
|
188 |
$return_str .= "<input name='is_on_home' value='$is_on_home' type='hidden' />";
|
189 |
|
190 |
if ( $rtmedia_query->original_query && is_array( $rtmedia_query->original_query ) ) {
|
@@ -193,10 +217,13 @@ class RTMediaTemplate {
|
|
193 |
}
|
194 |
}
|
195 |
|
196 |
-
echo $return_str
|
197 |
}
|
198 |
|
199 |
-
|
|
|
|
|
|
|
200 |
global $rtmedia_query;
|
201 |
|
202 |
if ( 'json' === $rtmedia_query->format ) {
|
@@ -206,7 +233,10 @@ class RTMediaTemplate {
|
|
206 |
}
|
207 |
}
|
208 |
|
209 |
-
|
|
|
|
|
|
|
210 |
global $rtmedia_query;
|
211 |
|
212 |
if ( 'upload' !== $rtmedia_query->action_query->action ) {
|
@@ -218,7 +248,10 @@ class RTMediaTemplate {
|
|
218 |
$upload->template_redirect();
|
219 |
}
|
220 |
|
221 |
-
|
|
|
|
|
|
|
222 |
global $rtmedia_query, $rtmedia;
|
223 |
|
224 |
$options = $rtmedia->options;
|
@@ -227,15 +260,18 @@ class RTMediaTemplate {
|
|
227 |
if ( $rtmedia_query->media ) {
|
228 |
|
229 |
// Remove all filters used for search functionality to avoid modifying query for current media results.
|
230 |
-
remove_filter( 'rtmedia-model-where-query', 'rtmedia_search_fillter_where_query', 10
|
231 |
-
remove_filter( 'rtmedia-model-join-query', 'rtmedia_search_fillter_join_query', 11
|
232 |
-
remove_filter( 'rtmedia-model-query-columns', 'rtmedia_model_query_columns', 10
|
233 |
|
234 |
foreach ( $rtmedia_query->media as $key => $media ) {
|
|
|
235 |
$media_class = 'hide';
|
236 |
-
if( isset( $media->media_type ) && function_exists( 'rtmedia_hide_title_media_gallery
|
1 |
<?php
|
|
|
2 |
/**
|
|
|
|
|
3 |
* Template to display rtMedia Gallery.
|
4 |
* A stand alone template that renders the gallery/uploader on the page.
|
5 |
*
|
6 |
+
* @package rtMedia
|
7 |
* @author saurabh
|
8 |
*/
|
9 |
+
|
10 |
+
/**
|
11 |
+
* Class to display rtMedia Gallery
|
12 |
+
*/
|
13 |
class RTMediaTemplate {
|
14 |
|
15 |
+
/**
|
16 |
+
* Media arguments.
|
17 |
+
*
|
18 |
+
* @var array
|
19 |
+
*/
|
20 |
public $media_args;
|
21 |
|
22 |
+
/**
|
23 |
+
* RTMediaTemplate constructor.
|
24 |
+
*/
|
25 |
+
public function __construct() {
|
26 |
global $rtmedia_query;
|
27 |
|
28 |
if ( $rtmedia_query ) {
|
40 |
/**
|
41 |
* Enqueues required scripts on the page
|
42 |
*/
|
43 |
+
public function enqueue_scripts() {
|
44 |
wp_enqueue_script( 'rtmedia-backbone' );
|
45 |
|
46 |
$is_album = is_rtmedia_album() ? true : false;
|
50 |
wp_localize_script( 'rtmedia-backbone', 'is_edit_allowed', array( $is_edit_allowed ) );
|
51 |
}
|
52 |
|
53 |
+
/**
|
54 |
+
* Enqueue image editor scripts.
|
55 |
+
*/
|
56 |
+
public function enqueue_image_editor_scripts() {
|
57 |
global $rtmedia_query;
|
58 |
|
59 |
wp_enqueue_script( 'wp-ajax-response' );
|
60 |
|
61 |
if ( $rtmedia_query->is_single_edit() ) {
|
62 |
+
wp_enqueue_script(
|
63 |
+
'rtmedia-image-edit',
|
64 |
+
admin_url( 'js/image-edit.js' ),
|
65 |
+
array(
|
66 |
+
'jquery',
|
67 |
+
'json2',
|
68 |
+
'imgareaselect',
|
69 |
+
),
|
70 |
+
RTMEDIA_VERSION,
|
71 |
+
1
|
72 |
+
);
|
73 |
+
wp_enqueue_style( 'rtmedia-image-area-select', includes_url( '/js/imgareaselect/imgareaselect.css' ), array(), RTMEDIA_VERSION );
|
74 |
+
wp_enqueue_style( 'rtmedia-image-edit', admin_url( 'css/media.css' ), array(), RTMEDIA_VERSION );
|
75 |
}
|
76 |
}
|
77 |
|
78 |
/**
|
79 |
+
* Redirects to the template according to the page request
|
80 |
+
* Pass on the shortcode attributes to the template so that the shortcode can be rendered accordingly.
|
81 |
*
|
82 |
* Also handles the json request coming from the AJAX calls for the media
|
83 |
*
|
84 |
+
* @param bool|string $template Template name.
|
85 |
+
* @param bool|array $shortcode_attr Shortcode attributes to render.
|
86 |
*
|
87 |
+
* @return bool|string
|
88 |
* @global type $rtmedia_query
|
89 |
* @global type $rtmedia_interaction
|
|
|
90 |
*/
|
91 |
+
public function set_template( $template = false, $shortcode_attr = false ) {
|
92 |
global $rtmedia_query, $rtmedia_interaction, $rtmedia_media;
|
93 |
|
94 |
do_action( 'rtmedia_pre_template' );
|
102 |
$this->check_return_json();
|
103 |
$this->check_return_upload();
|
104 |
|
105 |
+
if ( $rtmedia_interaction && isset( $rtmedia_interaction->context ) && in_array(
|
106 |
+
$rtmedia_interaction->context->type,
|
107 |
+
array(
|
108 |
'profile',
|
109 |
'group',
|
110 |
+
),
|
111 |
+
true
|
112 |
+
)
|
113 |
) {
|
114 |
$this->check_return_edit();
|
115 |
$this->check_return_delete();
|
129 |
|
130 |
$this->add_hidden_fields_in_gallery();
|
131 |
|
132 |
+
$gallery_template = apply_filters( 'rtmedia-before-template', $template, $shortcode_attr ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
|
133 |
|
134 |
+
// check if file exists.
|
135 |
+
if ( file_exists( $this->locate_template( $gallery_template ) ) ) {
|
136 |
include $this->locate_template( $gallery_template );
|
137 |
}
|
138 |
|
163 |
$rtaccount = 0;
|
164 |
}
|
165 |
|
|
|
166 |
$include_uploader = false;
|
167 |
|
168 |
if ( isset( $shortcode_attr['attr'] ) && isset( $shortcode_attr['attr']['uploader'] ) ) {
|
172 |
}
|
173 |
|
174 |
if ( 'before' === $include_uploader ) {
|
175 |
+
echo wp_kses( RTMediaUploadShortcode::pre_render( $shortcode_attr['attr'] ), RTMedia::expanded_allowed_tags() );
|
176 |
}
|
177 |
|
178 |
echo "<div class='rtmedia_gallery_wrapper'>";
|
179 |
|
180 |
$this->add_hidden_fields_in_gallery();
|
181 |
|
182 |
+
$gallery_template = apply_filters( 'rtmedia-before-template', $template, $shortcode_attr ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
|
183 |
|
184 |
+
// check if file exists.
|
185 |
+
if ( file_exists( $this->locate_template( $gallery_template ) ) ) {
|
186 |
include $this->locate_template( $gallery_template );
|
187 |
}
|
188 |
|
189 |
echo '</div>';
|
190 |
|
191 |
if ( 'after' === $include_uploader || 'true' === $include_uploader ) {
|
192 |
+
echo wp_kses( RTMediaUploadShortcode::pre_render( $shortcode_attr['attr'] ), RTMedia::expanded_allowed_tags() );
|
193 |
}
|
194 |
} else {
|
195 |
echo esc_html__( 'Invalid attribute passed for rtmedia_gallery shortcode.', 'buddypress-media' );
|
201 |
}
|
202 |
}
|
203 |
|
204 |
+
/**
|
205 |
+
* Add hidden fields in gallery for shortcode and home etc.
|
206 |
+
*/
|
207 |
+
public function add_hidden_fields_in_gallery() {
|
208 |
global $rtmedia_query;
|
209 |
|
210 |
+
$is_on_home = ( is_front_page() ) ? true : false;
|
211 |
+
$return_str = "<input name='rtmedia_shortcode' value='true' type='hidden' />";
|
212 |
$return_str .= "<input name='is_on_home' value='$is_on_home' type='hidden' />";
|
213 |
|
214 |
if ( $rtmedia_query->original_query && is_array( $rtmedia_query->original_query ) ) {
|
217 |
}
|
218 |
}
|
219 |
|
220 |
+
echo wp_kses( $return_str, RTMedia::expanded_allowed_tags() );
|
221 |
}
|
222 |
|
223 |
+
/**
|
224 |
+
* Check if format is json.
|
225 |
+
*/
|
226 |
+
public function check_return_json() {
|
227 |
global $rtmedia_query;
|
228 |
|
229 |
if ( 'json' === $rtmedia_query->format ) {
|
233 |
}
|
234 |
}
|
235 |
|
236 |
+
/**
|
237 |
+
* Check if current query action is upload or not.
|
238 |
+
*/
|
239 |
+
public function check_return_upload() {
|
240 |
global $rtmedia_query;
|
241 |
|
242 |
if ( 'upload' !== $rtmedia_query->action_query->action ) {
|
248 |
$upload->template_redirect();
|
249 |
}
|
250 |
|
251 |
+
/**
|
252 |
+
* Output template data as json.
|
253 |
+
*/
|
254 |
+
public function json_output() {
|
255 |
global $rtmedia_query, $rtmedia;
|
256 |
|
257 |
$options = $rtmedia->options;
|
260 |
if ( $rtmedia_query->media ) {
|
261 |
|
262 |
// Remove all filters used for search functionality to avoid modifying query for current media results.
|
263 |
+
remove_filter( 'rtmedia-model-where-query', 'rtmedia_search_fillter_where_query', 10 );
|
264 |
+
remove_filter( 'rtmedia-model-join-query', 'rtmedia_search_fillter_join_query', 11 );
|
265 |
+
remove_filter( 'rtmedia-model-query-columns', 'rtmedia_model_query_columns', 10 );
|
266 |
|
267 |
foreach ( $rtmedia_query->media as $key => $media ) {
|
268 |
+
|
269 |
$media_class = 'hide';
|
|