function bp_activity_deleted_activities($activity_ids_deleted) { $rt_model = new RTMediaModel(); $all_media = $rt_model->get(array('activity_id' => $activity_ids_deleted)); if ($all_media) { $media = new RTMediaMedia(); remove_action('bp_activity_deleted_activities', array(&$this, 'bp_activity_deleted_activities')); foreach ($all_media as $single_media) { $media->delete($single_media->id, false, false); } } }
/** * Delete uploaded media */ function rtmedia_delete_uploaded_media() { $action = filter_input(INPUT_POST, 'action', FILTER_SANITIZE_STRING); $nonce = filter_input(INPUT_POST, 'nonce', FILTER_SANITIZE_STRING); $media_id = filter_input(INPUT_POST, 'media_id', FILTER_SANITIZE_NUMBER_INT); if (!empty($action) && 'delete_uploaded_media' === $action && !empty($media_id)) { if (wp_verify_nonce($nonce, 'rtmedia_' . get_current_user_id())) { $media = new RTMediaMedia(); $delete = $media->delete($media_id); echo '1'; wp_die(); } } echo '0'; wp_die(); }
/** * Generic function to merge two albums * * @param int $primary_album_id * @param int $secondary_album_id * * @return int/bool */ function merge($primary_album_id, $secondary_album_id) { add_filter('rt_db_model_per_page', array($this, 'set_queries_per_page'), 10, 2); $page = 1; /** * Transfer all the media from secondary album to primary album */ while ($media = $this->media->model->get_by_album_id($secondary_album_id, $page)) { $media_id = $media['result'][0]['media_id']; $this->media->move($media_id, $primary_album_id); $page++; } $author = $this->get_current_author(); $admins = get_super_admins(); $global_albums = self::get_globals(); if (in_array(intval($secondary_album_id), array_map('intval', $global_albums), true)) { if (in_array($author, array_map('intval', $admins), true)) { $this->delete_global($secondary_album_id); } else { return false; } } else { $this->delete($secondary_album_id); } return $primary_album_id; }
<!--media management tab--> <?php if (!is_rtmedia_group_album()) { ?> <div class="content" id="manage-media-tab"> <?php if (have_rtmedia()) { ?> <form class="rtmedia-album-edit rtmedia-bulk-actions" method="post" name="rtmedia_album_edit"> <?php wp_nonce_field('rtmedia_bulk_delete_nonce', 'rtmedia_bulk_delete_nonce'); ?> <?php RTMediaMedia::media_nonce_generator($rtmedia_query->media_query['album_id']); ?> <p> <span><input type="checkbox" name="rtm-select-all" class="select-all" title="<?php esc_attr_e('Select All Visible', 'buddypress-media'); ?> "/></span> <button class="button rtmedia-move" type='button' title='<?php esc_attr_e('Move Selected media to another album.', 'buddypress-media'); ?> '><?php esc_html_e('Move', 'buddypress-media'); ?> </button>
function check_return_merge() { global $rtmedia_query; if ($rtmedia_query->action_query->action != 'merge') { return; } $nonce = $_REQUEST['rtmedia_merge_album_nonce']; if (wp_verify_nonce($nonce, 'rtmedia_merge_album_' . $rtmedia_query->media_query['album_id'])) { $media = new RTMediaMedia(); $model = new RTMediaModel(); $album_contents = $model->get(array('album_id' => $rtmedia_query->media_query['album_id']), false, false); $album_move_details = $model->get_media(array('id' => $_POST['album']), false, false); foreach ($album_contents as $album_media) { $post_array['ID'] = $album_media->media_id; $post_array['post_parent'] = $album_move_details[0]->media_id; wp_update_post($post_array); $media->update($album_media->id, array('album_id' => $album_move_details[0]->id), $album_media->media_id); } $media->delete($rtmedia_query->media_query['album_id']); } if (isset($rtmedia_query->media_query['context']) && $rtmedia_query->media_query['context'] == "group") { global $bp; $group_link = bp_get_group_permalink($bp->groups->current_group); wp_safe_redirect(esc_url_raw(trailingslashit($group_link) . RTMEDIA_MEDIA_SLUG . '/album/')); } else { wp_safe_redirect(esc_url_raw(trailingslashit(get_rtmedia_user_link(get_current_user_id())) . RTMEDIA_MEDIA_SLUG . '/album/')); } exit; }
function rtmedia_delete_uploaded_media() { if (isset($_POST) && isset($_POST['action']) && $_POST['action'] == 'delete_uploaded_media' && isset($_POST['media_id']) && $_POST['media_id'] != "") { if (wp_verify_nonce($_POST['nonce'], 'rtmedia_' . get_current_user_id())) { $media = new RTMediaMedia(); $media_id = $_POST['media_id']; $delete = $media->delete($media_id); echo "1"; die; } } echo "0"; die; }
/** * Hooks the plugin into BuddyPress via 'bp_include' action. * Initialises the plugin's functionalities, options, * loads media for Profiles and Groups. * Creates Admin panels * Loads accessory functions * * @global BPMediaAdmin $bp_media_admin */ function init() { // set metatable in $wpdb $this->set_rtmedia_meta_wpdbfix(); // rtMedia db upgrade add_action('rt_db_upgrade', array($this, 'fix_parent_id')); add_action('rt_db_upgrade', array($this, 'fix_privacy')); add_action('rt_db_upgrade', array($this, 'fix_group_media_privacy')); add_action('rt_db_upgrade', array($this, 'fix_db_collation')); $this->update_db(); remove_action('rt_db_upgrade', array($this, 'fix_parent_id')); remove_action('rt_db_upgrade', array($this, 'fix_privacy')); remove_action('rt_db_upgrade', array($this, 'fix_group_media_privacy')); remove_action('rt_db_upgrade', array($this, 'fix_db_collation')); $this->set_allowed_types(); // Define allowed types $this->constants(); // Define constants $this->redirect_on_change_slug(); $this->set_default_sizes(); // set default sizes $this->set_privacy(); // set privacy /** * Load options/settings */ $this->set_site_options(); /** * BuddyPress - Media Navigation Tab Inject * */ /** * Load accessory functions */ $class_construct = array('deprecated' => true, 'interaction' => true, 'upload_shortcode' => false, 'gallery_shortcode' => false, 'upload_endpoint' => false, 'privacy' => false, 'nav' => true, 'like' => false, 'featured' => false, 'GroupFeatured' => false, 'ViewCount' => false, 'GalleryItemAction' => false, 'LoginPopup' => false, 'CommentNotification' => false, 'LikeNotification' => false); global $rtmedia_nav; /** Legacy code for Add-ons * */ $bp_class_construct = apply_filters('bpmedia_class_construct', array()); foreach ($bp_class_construct as $classname => $global_scope) { $class = 'BPMedia' . ucfirst($classname); if (class_exists($class)) { if (true === $global_scope) { global ${'bp_media_' . $classname}; ${'bp_media_' . $classname} = new $class(); } else { new $class(); } } } /** ------------------- * */ $class_construct = apply_filters('rtmedia_class_construct', $class_construct); $class_construct['Group'] = false; // will be constructed after rtmedia pro class. foreach ($class_construct as $key => $global_scope) { $classname = ''; $ck = explode('_', $key); foreach ($ck as $cn) { $classname .= ucfirst($cn); } $class = 'RTMedia' . $classname; if (class_exists($class)) { if (true === $global_scope) { global ${'rtmedia_' . $key}; ${'rtmedia_' . $key} = new $class(); } else { new $class(); } } } $this->set_allowed_types(); // Define allowed types global $rtmedia_buddypress_activity; $rtmedia_buddypress_activity = new RTMediaBuddyPressActivity(); $media = new RTMediaMedia(); $media->delete_hook(); global $rtmedia_ajax; $rtmedia_ajax = new RTMediaAJAX(); //API Classes global $rtmediajsonapi; $rtmediajsonapi = new RTMediaJsonApi(); do_action('bp_media_init'); // legacy For plugin using this actions do_action('rtmedia_init'); }
<?php rtmedia_title_input(); ?> </div> <!--This function shows the privacy dropdown--> <?php echo rtmedia_edit_media_privacy_ui(); ?> <div class="rtmedia-editor-description rtm-field-wrap"> <label><?php _e('Description: ', 'rtmedia'); ?> </label> <?php echo rtmedia_description_input($editor = false); RTMediaMedia::media_nonce_generator(rtmedia_id()); ?> </div> <!-- Use this hook to add new fields to the edit form--> <?php do_action('rtmedia_add_edit_fields', rtmedia_type()); ?> </div> <!-- use this hook to add content of a new tab--> <?php do_action('rtmedia_add_edit_tab_content', rtmedia_type()); ?> </div> <div class="rtmedia-editor-buttons"> <input type="submit" class="button rtm-button rtm-button-save" value="<?php _e('Save', 'rtmedia');
function rtmedia_api_process_rtmedia_upload_media_request() { $this->rtmediajsonapifunction->rtmedia_api_verfiy_token(); //Error Codes for new look $ec_no_file = 140001; $msg_no_file = __('no file', 'rtmedia'); $ec_invalid_file_string = 140005; $msg_invalid_file_string = __('invalid file string', 'rtmedia'); $ec_image_type_missing = 140006; $msg_image_type_missing = __('image type missing', 'rtmedia'); $ec_no_file_title = 140002; $msg_no_file_title = __('no title', 'rtmedia'); $ec_invalid_image = 140003; $msg_invalid_image = __('upload failed, check size and file type', 'rtmedia'); $ec_look_updated = 140004; $msg_look_updated = __('media updated', 'rtmedia'); $description = ''; extract($_POST); $updated = FALSE; $uploaded_look = FALSE; if (empty($_POST['rtmedia_file']) && empty($_FILES['rtmedia_file'])) { echo $this->rtmedia_api_response_object('FALSE', $ec_no_file, $msg_no_file); exit; } if (!empty($_POST['rtmedia_file'])) { if (empty($_POST['image_type'])) { echo $this->rtmedia_api_response_object('FALSE', $ec_image_type_missing, $msg_image_type_missing); exit; } if (empty($title)) { echo $this->rtmedia_api_response_object('FALSE', $ec_no_file_title, $msg_no_file_title); exit; } } if (!empty($_FILES['rtmedia_file'])) { $_POST['rtmedia_upload_nonce'] = $_REQUEST['rtmedia_upload_nonce'] = wp_create_nonce('rtmedia_upload_nonce'); $_POST['rtmedia_simple_file_upload'] = $_REQUEST['rtmedia_simple_file_upload'] = 1; $_POST['context'] = $_REQUEST['context'] = !empty($_REQUEST['context']) ? $_REQUEST['context'] : 'profile'; $_POST['context_id'] = $_REQUEST['context_id'] = !empty($_REQUEST['context_id']) ? $_REQUEST['context_id'] : $this->user_id; $_POST['mode'] = $_REQUEST['mode'] = 'file_upload'; $_POST['media_author'] = $_REQUEST['media_author'] = $this->user_id; $upload = new RTMediaUploadEndpoint(); $uploaded_look = $upload->template_redirect(); } else { //Process rtmedia_file $img = $rtmedia_file; $img = str_replace('data:image/png;base64,', '', $img); // $img = str_replace(' ', '+', $img); $rtmedia_file = base64_decode($img); if (!$rtmedia_file) { echo $this->rtmedia_api_response_object('FALSE', $ec_invalid_file_string, $msg_invalid_file_string); exit; } define('UPLOAD_DIR_LOOK', sys_get_temp_dir() . '/'); $tmp_name = UPLOAD_DIR_LOOK . $title; $file = $tmp_name . '.' . $image_type; $success = file_put_contents($file, $rtmedia_file); add_filter('upload_dir', array($this, 'api_new_media_upload_dir')); // echo $file; $new_look = wp_upload_bits($title . '.' . $image_type, '', $rtmedia_file); $new_look['type'] = 'image/' . $image_type; remove_filter('upload_dir', array($this, 'api_new_media_upload_dir')); foreach ($new_look as $key => $value) { $new_look[0][$key] = $value; unset($new_look[$key]); } //Jugaad if (!empty($tags)) { $tags = explode(',', $tags); } $uploaded['rtmedia_upload_nonce'] = wp_create_nonce('rtmedia_upload_nonce'); $uploaded['rtmedia_simple_file_upload'] = 1; $uploaded['context'] = 'profile'; $uploaded['context_id'] = $this->user_id; $uploaded['mode'] = 'file_upload'; $uploaded['media_author'] = $this->user_id; $uploaded['album_id'] = $this->user_id; $uploaded['privacy'] = 0; $uploaded['title'] = $title; $uploaded['description'] = $description; $uploaded['taxonomy'] = array(); $uploaded['custom_fields'] = array(); $rtmedia = new RTMediaMedia(); $rtupload = $rtmedia->add($uploaded, $new_look); $id = rtmedia_media_id($rtupload[0]); if (!empty($_POST['tags'])) { wp_set_post_terms($id, $_POST["tags"], 'media-category', true); } $media = $rtmedia->model->get(array('id' => $rtupload[0])); $rtMediaNav = new RTMediaNav(); $perma_link = ""; if (isset($media) && sizeof($media) > 0) { $perma_link = get_rtmedia_permalink($media[0]->id); if ($media[0]->media_type == "photo") { $thumb_image = rtmedia_image("rt_media_thumbnail", $rtupload[0], false); } elseif ($media[0]->media_type == "music") { $thumb_image = $media[0]->cover_art; } else { $thumb_image = ""; } if ($media[0]->context == "group") { $rtMediaNav->refresh_counts($media[0]->context_id, array("context" => $media[0]->context, 'context_id' => $media[0]->context_id)); } else { $rtMediaNav->refresh_counts($media[0]->media_author, array("context" => "profile", 'media_author' => $media[0]->media_author)); } $activity_id = $rtmedia->insert_activity($media[0]->media_id, $media[0]); $rtmedia->model->update(array('activity_id' => $activity_id), array('id' => $rtupload[0])); // $same_medias = $rtmedia->model->get(array('activity_id' => $activity_id)); $update_activity_media = array(); foreach ($same_medias as $a_media) { $update_activity_media[] = $a_media->id; } $privacy = 0; $objActivity = new RTMediaActivity($update_activity_media, $privacy, false); global $wpdb, $bp; $updated = $wpdb->update($bp->activity->table_name, array("type" => "rtmedia_update", "content" => $objActivity->create_activity_html()), array("id" => $activity_id)); } } if ($updated || $uploaded_look) { echo $this->rtmedia_api_response_object('TRUE', $ec_look_updated, $msg_look_updated); exit; } else { echo $this->rtmedia_api_response_object('TRUE', $ec_invalid_image, $msg_invalid_image); exit; } }
/** * Rendering media delete form * * @param bool $echo * * @return bool|string */ function rtmedia_delete_form($echo = true) { if (rtmedia_delete_allowed()) { $html = '<form method="post" action="' . esc_url(get_rtmedia_permalink(rtmedia_id())) . 'delete/">'; $html .= '<input type="hidden" name="id" id="id" value="' . esc_attr(rtmedia_id()) . '">'; $html .= '<input type="hidden" name="request_action" id="request_action" value="delete">'; if ($echo) { echo $html; // @codingStandardsIgnoreLine RTMediaMedia::media_nonce_generator(rtmedia_id(), true); do_action('rtmedia_media_single_delete_form'); echo '<button type="submit" title="' . esc_attr__('Delete Media', 'buddypress-media') . '" class="rtmedia-delete-media rtmedia-action-buttons button">' . esc_html__('Delete', 'buddypress-media') . '</button></form>'; } else { $output = $html; $rtm_nonce = RTMediaMedia::media_nonce_generator(rtmedia_id(), false); $rtm_nonce = json_decode($rtm_nonce); $rtm_nonce_field = wp_nonce_field('rtmedia_' . rtmedia_id(), $rtm_nonce->action, true, false); do_action('rtmedia_media_single_delete_form'); $output .= $rtm_nonce_field . '<button type="submit" title="' . esc_attr__('Delete Media', 'buddypress-media') . '" class="rtmedia-delete-media rtmedia-action-buttons button">' . esc_html__('Delete', 'buddypress-media') . '</button></form>'; return $output; } } return false; }
function template_redirect($create_activity = true) { ob_start(); if (!count($_POST)) { // @codingStandardsIgnoreLine include get_404_template(); } else { $nonce = $mode = ''; $_activity_id = -1; if (isset($_REQUEST['rtmedia_upload_nonce'])) { $nonce = sanitize_text_field(wp_unslash($_REQUEST['rtmedia_upload_nonce'])); } if (isset($_REQUEST['mode'])) { $mode = sanitize_text_field(wp_unslash($_REQUEST['mode'])); } if (isset($_REQUEST['activity_id'])) { $_activity_id = sanitize_text_field($_REQUEST['activity_id']); } $_redirect_url = filter_input(INPUT_POST, 'redirect', FILTER_SANITIZE_NUMBER_INT); $rtupload = false; $activity_id = -1; $redirect_url = ''; if (wp_verify_nonce($nonce, 'rtmedia_upload_nonce')) { $model = new RTMediaUploadModel(); do_action('rtmedia_upload_set_post_object'); $this->upload = $model->set_post_object(); if (-1 !== $_activity_id) { $this->upload['activity_id'] = $_activity_id; $activity_id = $_activity_id; } //if media upload is being made for a group, identify the group privacy and set media privacy accordingly if (isset($this->upload['context']) && isset($this->upload['context_id']) && 'group' === $this->upload['context'] && function_exists('groups_get_group')) { $group = groups_get_group(array('group_id' => $this->upload['context_id'])); if (isset($group->status) && 'public' !== $group->status) { // if group is not public, then set media privacy as 20, so only the group members can see the images $this->upload['privacy'] = '20'; } else { // if group is public, then set media privacy as 0 $this->upload['privacy'] = '0'; } } $this->upload = apply_filters('rtmedia_media_param_before_upload', $this->upload); $rtupload = new RTMediaUpload($this->upload); $media_obj = new RTMediaMedia(); $media = $media_obj->model->get(array('id' => $rtupload->media_ids[0])); $rtmedia_nav = new RTMediaNav(); $perma_link = ''; if (isset($media) && count($media) > 0) { $perma_link = get_rtmedia_permalink($media[0]->id); if ('photo' === $media[0]->media_type) { $thumb_image = rtmedia_image('rt_media_thumbnail', $rtupload->media_ids[0], false); } elseif ('music' === $media[0]->media_type) { $thumb_image = $media[0]->cover_art; } else { $thumb_image = ''; } if ('group' === $media[0]->context) { $rtmedia_nav->refresh_counts($media[0]->context_id, array('context' => $media[0]->context, 'context_id' => $media[0]->context_id)); } else { $rtmedia_nav->refresh_counts($media[0]->media_author, array('context' => 'profile', 'media_author' => $media[0]->media_author)); } if (false !== $create_activity && class_exists('BuddyPress') && bp_is_active('activity')) { $allow_single_activity = apply_filters('rtmedia_media_single_activity', false); // Following will not apply to activity uploads. For first time activity won't be generated. // Create activity first and pass activity id in response. // todo fixme rtmedia_media_single_activity filter. It will create 2 activity with same media if uploaded from activity page. $_rtmedia_update = filter_input(INPUT_POST, 'rtmedia_update', FILTER_SANITIZE_STRING); if (-1 === intval($activity_id) && !(isset($_rtmedia_update) && 'true' === $_rtmedia_update) || $allow_single_activity) { $activity_id = $media_obj->insert_activity($media[0]->media_id, $media[0]); } else { $media_obj->model->update(array('activity_id' => $activity_id), array('id' => $rtupload->media_ids[0])); // $same_medias = $media_obj->model->get(array('activity_id' => $activity_id)); $update_activity_media = array(); foreach ($same_medias as $a_media) { $update_activity_media[] = $a_media->id; } $privacy = filter_input(INPUT_POST, 'privacy', FILTER_SANITIZE_NUMBER_INT); if (empty($privacy)) { $privacy = 0; } $obj_activity = new RTMediaActivity($update_activity_media, $privacy, false); global $wpdb, $bp; $user = get_userdata($same_medias[0]->media_author); $username = '******' . esc_url(get_rtmedia_user_link($same_medias[0]->media_author)) . '">' . esc_html($user->user_nicename) . '</a>'; $action = sprintf(esc_html__('%s added %d %s', 'buddypress-media'), $username, count($same_medias), RTMEDIA_MEDIA_SLUG); $action = apply_filters('rtmedia_buddypress_action_text_fitler_multiple_media', $action, $username, count($same_medias), $user->user_nicename); $wpdb->update($bp->activity->table_name, array('type' => 'rtmedia_update', 'content' => $obj_activity->create_activity_html(), 'action' => $action), array('id' => $activity_id)); } // update group last active if ('group' === $media[0]->context) { RTMediaGroup::update_last_active($media[0]->context_id); } } } if (isset($this->upload['rtmedia_simple_file_upload']) && true == $this->upload['rtmedia_simple_file_upload']) { if (isset($media) && count($media) > 0) { if (isset($_redirect_url)) { if (intval($_redirect_url) > 1) { //bulkurl if ('group' === $media[0]->context) { $redirect_url = trailingslashit(get_rtmedia_group_link($media[0]->context_id)) . RTMEDIA_MEDIA_SLUG; } else { $redirect_url = trailingslashit(get_rtmedia_user_link($media[0]->media_author)) . RTMEDIA_MEDIA_SLUG; } } else { $redirect_url = get_rtmedia_permalink($media[0]->id); } $redirect_url = apply_filters('rtmedia_simple_file_upload_redirect_url_filter', $redirect_url); wp_safe_redirect(esc_url_raw($redirect_url)); die; } return $media; } return false; } } $redirect_url = ''; if (isset($_redirect_url) && is_numeric($_redirect_url)) { if (intval($_redirect_url) > 1) { //bulkurl if ('group' === $media[0]->context) { $redirect_url = trailingslashit(get_rtmedia_group_link($media[0]->context_id)) . RTMEDIA_MEDIA_SLUG; } else { $redirect_url = trailingslashit(get_rtmedia_user_link($media[0]->media_author)) . RTMEDIA_MEDIA_SLUG; } } else { $redirect_url = get_rtmedia_permalink($media[0]->id); } } // Ha ha ha ob_end_clean(); //check for simpe $rtmedia_update = filter_input(INPUT_POST, 'rtmedia_update', FILTER_SANITIZE_STRING); $_user_agent = rtm_get_server_var('HTTP_USER_AGENT', 'FILTER_SANITIZE_STRING'); /** * if(redirect) * */ if (!empty($rtmedia_update) && 'true' === $rtmedia_update) { if (preg_match('/(?i)msie [1-9]/', $_user_agent)) { // if IE(<=9) set content type = text/plain header('Content-type: text/plain'); } else { header('Content-type: application/json'); } echo wp_json_encode($rtupload->media_ids); } else { // Media Upload Case - on album/post/profile/group if (isset($media[0])) { $data = array('media_id' => $media[0]->id, 'activity_id' => $activity_id, 'redirect_url' => $redirect_url, 'permalink' => $perma_link, 'cover_art' => $thumb_image); } else { $data = array(); } if (preg_match('/(?i)msie [1-9]/', $_user_agent)) { // if IE(<=9) set content type = text/plain header('Content-type: text/plain'); } else { header('Content-type: application/json'); } echo wp_json_encode(apply_filters('rtmedia_upload_endpoint_response', $data)); } die; } }
/** * */ function template_redirect($create_activity = true) { ob_start(); if (!count($_POST)) { include get_404_template(); } else { $nonce = $_REQUEST['rtmedia_upload_nonce']; if (isset($_REQUEST['mode'])) { $mode = $_REQUEST['mode']; } $rtupload = false; $activity_id = -1; $redirect_url = ""; if (wp_verify_nonce($nonce, 'rtmedia_upload_nonce')) { $model = new RTMediaUploadModel(); do_action('rtmedia_upload_set_post_object'); $this->upload = $model->set_post_object(); if (isset($_POST['activity_id']) && $_POST['activity_id'] != -1) { $this->upload['activity_id'] = $_POST['activity_id']; $activity_id = $_POST['activity_id']; } // ////if media upload is being made for a group, identify the group privacy and set media privacy accordingly if (isset($this->upload['context']) && isset($this->upload['context_id']) && $this->upload['context'] == 'group' && function_exists('groups_get_group')) { $group = groups_get_group(array('group_id' => $this->upload['context_id'])); if (isset($group->status) && $group->status != 'public') { // if group is not public, then set media privacy as 20, so only the group members can see the images $this->upload['privacy'] = '20'; } else { // if group is public, then set media privacy as 0 $this->upload['privacy'] = '0'; } } $this->upload = apply_filters('rtmedia_media_param_before_upload', $this->upload); $rtupload = new RTMediaUpload($this->upload); $mediaObj = new RTMediaMedia(); $media = $mediaObj->model->get(array('id' => $rtupload->media_ids[0])); $rtMediaNav = new RTMediaNav(); $perma_link = ""; if (isset($media) && sizeof($media) > 0) { $perma_link = get_rtmedia_permalink($media[0]->id); if ($media[0]->media_type == "photo") { $thumb_image = rtmedia_image("rt_media_thumbnail", $rtupload->media_ids[0], false); } elseif ($media[0]->media_type == "music") { $thumb_image = $media[0]->cover_art; } else { $thumb_image = ""; } if ($media[0]->context == "group") { $rtMediaNav->refresh_counts($media[0]->context_id, array("context" => $media[0]->context, 'context_id' => $media[0]->context_id)); } else { $rtMediaNav->refresh_counts($media[0]->media_author, array("context" => "profile", 'media_author' => $media[0]->media_author)); } if ($create_activity !== false && class_exists('BuddyPress')) { $allow_single_activity = apply_filters('rtmedia_media_single_activity', false); // Following will not apply to activity uploads. For first time activity won't be generated. // Create activity first and pass activity id in response. // todo fixme rtmedia_media_single_activity filter. It will create 2 activity with same media if uploaded from activity page. if ($activity_id == -1 && !(isset($_POST["rtmedia_update"]) && $_POST["rtmedia_update"] == "true") || $allow_single_activity) { $activity_id = $mediaObj->insert_activity($media[0]->media_id, $media[0]); } else { $mediaObj->model->update(array('activity_id' => $activity_id), array('id' => $rtupload->media_ids[0])); // $same_medias = $mediaObj->model->get(array('activity_id' => $activity_id)); $update_activity_media = array(); foreach ($same_medias as $a_media) { $update_activity_media[] = $a_media->id; } $privacy = 0; if (isset($_POST["privacy"])) { $privacy = $_POST["privacy"]; } $objActivity = new RTMediaActivity($update_activity_media, $privacy, false); global $wpdb, $bp; $user = get_userdata($same_medias[0]->media_author); $username = '******' . get_rtmedia_user_link($same_medias[0]->media_author) . '">' . $user->user_nicename . '</a>'; $action = sprintf(__('%s added %d %s', 'buddypress-media'), $username, sizeof($same_medias), RTMEDIA_MEDIA_SLUG); $action = apply_filters('rtmedia_buddypress_action_text_fitler_multiple_media', $action, $username, sizeof($same_medias), $user->user_nicename); $wpdb->update($bp->activity->table_name, array("type" => "rtmedia_update", "content" => $objActivity->create_activity_html(), 'action' => $action), array("id" => $activity_id)); } // update group last active if ($media[0]->context == "group") { RTMediaGroup::update_last_active($media[0]->context_id); } } } if (isset($this->upload['rtmedia_simple_file_upload']) && $this->upload['rtmedia_simple_file_upload'] == true) { if (isset($media) && sizeof($media) > 0) { if (isset($_POST["redirect"])) { if (intval($_POST["redirect"]) > 1) { //bulkurl if ($media[0]->context == "group") { $redirect_url = trailingslashit(get_rtmedia_group_link($media[0]->context_id)) . RTMEDIA_MEDIA_SLUG; } else { $redirect_url = trailingslashit(get_rtmedia_user_link($media[0]->media_author)) . RTMEDIA_MEDIA_SLUG; } } else { $redirect_url = get_rtmedia_permalink($media[0]->id); } $redirect_url = apply_filters("rtmedia_simple_file_upload_redirect_url_filter", $redirect_url); wp_safe_redirect(esc_url_raw($redirect_url)); die; } return $media; } return false; } } $redirect_url = ""; if (isset($_POST["redirect"]) && is_numeric($_POST["redirect"])) { if (intval($_POST["redirect"]) > 1) { //bulkurl if ($media[0]->context == "group") { $redirect_url = trailingslashit(get_rtmedia_group_link($media[0]->context_id)) . RTMEDIA_MEDIA_SLUG; } else { $redirect_url = trailingslashit(get_rtmedia_user_link($media[0]->media_author)) . RTMEDIA_MEDIA_SLUG; } } else { $redirect_url = get_rtmedia_permalink($media[0]->id); } } // Ha ha ha ob_end_clean(); //check for simpe /** * if(redirect) * */ if (isset($_POST["rtmedia_update"]) && $_POST["rtmedia_update"] == "true") { if (preg_match('/(?i)msie [1-9]/', $_SERVER['HTTP_USER_AGENT'])) { // if IE(<=9) set content type = text/plain header('Content-type: text/plain'); } else { header('Content-type: application/json'); } echo json_encode($rtupload->media_ids); } else { // Media Upload Case - on album/post/profile/group if (isset($media[0])) { $data = array('media_id' => $media[0]->id, 'activity_id' => $activity_id, 'redirect_url' => $redirect_url, 'permalink' => $perma_link, 'cover_art' => $thumb_image); } else { $data = array(); } if (preg_match('/(?i)msie [1-9]/', $_SERVER['HTTP_USER_AGENT'])) { // if IE(<=9) set content type = text/plain header('Content-type: text/plain'); } else { header('Content-type: application/json'); } echo json_encode(apply_filters('rtmedia_upload_endpoint_response', $data)); } die; } }
function rtmedia_api_process_rtmedia_upload_media_request() { $this->rtmediajsonapifunction->rtmedia_api_verfiy_token(); //Error Codes for new look $ec_no_file = 140001; $msg_no_file = esc_html__('no file', 'buddypress-media'); $ec_invalid_file_string = 140005; $msg_invalid_file_string = esc_html__('invalid file string', 'buddypress-media'); $ec_image_type_missing = 140006; $msg_image_type_missing = esc_html__('image type missing', 'buddypress-media'); $ec_no_file_title = 140002; $msg_no_file_title = esc_html__('no title', 'buddypress-media'); $ec_invalid_image = 140003; $msg_invalid_image = esc_html__('upload failed, check size and file type', 'buddypress-media'); $ec_look_updated = 140004; $msg_look_updated = esc_html__('media updated', 'buddypress-media'); $description = ''; $rtmedia_file = filter_input(INPUT_POST, 'rtmedia_file', FILTER_SANITIZE_STRING); $image_type = filter_input(INPUT_POST, 'image_type', FILTER_SANITIZE_STRING); $title = filter_input(INPUT_POST, 'title', FILTER_SANITIZE_STRING); $updated = false; $uploaded_look = false; if (empty($rtmedia_file) && empty($_FILES['rtmedia_file'])) { wp_send_json($this->rtmedia_api_response_object('FALSE', $ec_no_file, $msg_no_file)); } if (!empty($rtmedia_file)) { if (empty($image_type)) { wp_send_json($this->rtmedia_api_response_object('FALSE', $ec_image_type_missing, $msg_image_type_missing)); } if (empty($title)) { wp_send_json($this->rtmedia_api_response_object('FALSE', $ec_no_file_title, $msg_no_file_title)); } } if (!empty($_FILES['rtmedia_file'])) { $_POST['rtmedia_upload_nonce'] = $_REQUEST['rtmedia_upload_nonce'] = wp_create_nonce('rtmedia_upload_nonce'); $_POST['rtmedia_simple_file_upload'] = $_REQUEST['rtmedia_simple_file_upload'] = 1; $_POST['context'] = $_REQUEST['context'] = !empty($_REQUEST['context']) ? wp_unslash($_REQUEST['context']) : 'profile'; $_POST['context_id'] = $_REQUEST['context_id'] = !empty($_REQUEST['context_id']) ? absint($_REQUEST['context_id']) : $this->user_id; $_POST['mode'] = $_REQUEST['mode'] = 'file_upload'; $_POST['media_author'] = $_REQUEST['media_author'] = $this->user_id; $upload = new RTMediaUploadEndpoint(); //todo refactor below function so it takes param also and use if passed else use POST request $uploaded_look = $upload->template_redirect(); } else { //Process rtmedia_file $img = $rtmedia_file; $str_replace = 'data:image/' . $image_type . ';base64,'; $img = str_replace($str_replace, '', $img); $rtmedia_file = base64_decode($img); if (!$rtmedia_file) { wp_send_json($this->rtmedia_api_response_object('FALSE', $ec_invalid_file_string, $msg_invalid_file_string)); } define('UPLOAD_DIR_LOOK', sys_get_temp_dir() . '/'); $tmp_name = UPLOAD_DIR_LOOK . $title; $file = $tmp_name . '.' . $image_type; $success = file_put_contents($file, $rtmedia_file); add_filter('upload_dir', array($this, 'api_new_media_upload_dir')); $new_look = wp_upload_bits($title . '.' . $image_type, '', $rtmedia_file); $new_look['type'] = 'image/' . $image_type; remove_filter('upload_dir', array($this, 'api_new_media_upload_dir')); foreach ($new_look as $key => $value) { $new_look[0][$key] = $value; unset($new_look[$key]); } //Jugaad if (!empty($tags)) { $tags = explode(',', $tags); } $album_id = filter_input(INPUT_POST, 'album_id', FILTER_SANITIZE_NUMBER_INT); $context_id = filter_input(INPUT_POST, 'context_id', FILTER_SANITIZE_NUMBER_INT); $context = filter_input(INPUT_POST, 'context', FILTER_SANITIZE_STRING); $privacy = filter_input(INPUT_POST, 'privacy', FILTER_SANITIZE_STRING); $tags = filter_input(INPUT_POST, 'tags', FILTER_SANITIZE_STRING); $uploaded['rtmedia_upload_nonce'] = wp_create_nonce('rtmedia_upload_nonce'); $uploaded['rtmedia_simple_file_upload'] = 1; $uploaded['context'] = !empty($context) ? $context : 'profile'; $uploaded['context_id'] = !empty($context_id) ? $context_id : $this->user_id; $uploaded['mode'] = 'file_upload'; $uploaded['media_author'] = $this->user_id; $uploaded['album_id'] = !empty($album_id) ? $album_id : RTMediaAlbum::get_default(); $uploaded['privacy'] = !empty($privacy) ? $privacy : get_rtmedia_default_privacy(); $uploaded['title'] = $title; $uploaded['description'] = $description; $uploaded['taxonomy'] = array(); $uploaded['custom_fields'] = array(); $rtmedia = new RTMediaMedia(); $rtupload = $rtmedia->add($uploaded, $new_look); $id = rtmedia_media_id($rtupload[0]); if (!empty($tags)) { wp_set_post_terms($id, $tags, 'media-category', true); } $media = $rtmedia->model->get(array('id' => $rtupload[0])); $rtmedia_nav = new RTMediaNav(); if (isset($media) && count($media) > 0) { $perma_link = get_rtmedia_permalink($media[0]->id); if ('photo' === $media[0]->media_type) { $thumb_image = rtmedia_image('rt_media_thumbnail', $rtupload[0], false); } elseif ('music' === $media[0]->media_type) { $thumb_image = $media[0]->cover_art; } else { $thumb_image = ''; } if ('group' === $media[0]->context) { $rtmedia_nav->refresh_counts($media[0]->context_id, array('context' => sanitize_text_field($media[0]->context), 'context_id' => intval($media[0]->context_id))); } else { $rtmedia_nav->refresh_counts($media[0]->media_author, array('context' => 'profile', 'media_author' => sanitize_text_field($media[0]->media_author))); } $activity_id = $rtmedia->insert_activity($media[0]->media_id, $media[0]); $rtmedia->model->update(array('activity_id' => $activity_id), array('id' => intval($rtupload[0]))); // $same_medias = $rtmedia->model->get(array('activity_id' => $activity_id)); $update_activity_media = array(); foreach ($same_medias as $a_media) { $update_activity_media[] = $a_media->id; } $privacy = 0; $obj_activity = new RTMediaActivity($update_activity_media, $privacy, false); global $wpdb, $bp; $updated = $wpdb->update($bp->activity->table_name, array('type' => 'rtmedia_update', 'content' => $obj_activity->create_activity_html()), array('id' => $activity_id)); // if there is only single media the $updated value will be false even if the value we are passing to check is correct. // So we need to hardcode the $updated to true if there is only single media for same activity if (1 === count($same_medias) && $activity_id) { $updated = true; } } } if ($updated || $uploaded_look) { wp_send_json($this->rtmedia_api_response_object('TRUE', $ec_look_updated, $msg_look_updated)); } else { wp_send_json($this->rtmedia_api_response_object('TRUE', $ec_invalid_image, $msg_invalid_image)); } }
/** * Hooks the plugin into BuddyPress via 'bp_include' action. * Initialises the plugin's functionalities, options, * loads media for Profiles and Groups. * Creates Admin panels * Loads accessory functions * * @global BPMediaAdmin $bp_media_admin */ function init() { $this->set_allowed_types(); // Define allowed types $this->constants(); // Define constants $this->redirect_on_change_slug(); $this->set_default_sizes(); // set default sizes $this->set_privacy(); // set privacy /** * Load options/settings */ $this->set_site_options(); /** * Add a settings link to the Plugin list screen */ // add_filter('plugin_action_links', array($this, 'settings_link'), 10, 2); /** * BuddyPress - Media Navigation Tab Inject * */ /** * Load accessory functions */ // new BPMediaActivity(); $class_construct = array('deprecated' => true, 'interaction' => true, 'upload_shortcode' => false, 'gallery_shortcode' => false, 'upload_endpoint' => false, 'privacy' => false, 'nav' => true, 'like' => false, 'featured' => false, 'ViewCount' => false); global $rtmedia_nav; /** Legacy code for Add-ons * */ $bp_class_construct = apply_filters('bpmedia_class_construct', array()); foreach ($bp_class_construct as $classname => $global_scope) { $class = 'BPMedia' . ucfirst($classname); if (class_exists($class)) { if ($global_scope == true) { global ${'bp_media_' . $classname}; ${'bp_media_' . $classname} = new $class(); } else { new $class(); } } } /** ------------------- * */ $class_construct = apply_filters('rtmedia_class_construct', $class_construct); $class_construct['Group'] = false; // will be constructed after rtmedia pro class. foreach ($class_construct as $key => $global_scope) { $classname = ''; $ck = explode('_', $key); foreach ($ck as $cn) { $classname .= ucfirst($cn); } $class = 'RTMedia' . $classname; if (class_exists($class)) { if ($global_scope == true) { global ${'rtmedia_' . $key}; ${'rtmedia_' . $key} = new $class(); } else { new $class(); } } } $this->set_allowed_types(); // Define allowed types global $rtmedia_buddypress_activity; $rtmedia_buddypress_activity = new RTMediaBuddyPressActivity(); $media = new RTMediaMedia(); $media->delete_hook(); global $rtmedia_ajax; $rtmedia_ajax = new RTMediaAJAX(); //API Classes global $rtmediajsonapi; $rtmediajsonapi = new RTMediaJsonApi(); do_action('bp_media_init'); // legacy For plugin using this actions do_action('rtmedia_init'); }