refresh_counts() public method

public refresh_counts ( $user_id, $where )
コード例 #1
0
ファイル: RTMediaAJAX.php プロジェクト: rtCamp/rtMedia
 function create_album()
 {
     $nonce = filter_input(INPUT_POST, 'create_album_nonce', FILTER_SANITIZE_STRING);
     $_name = filter_input(INPUT_POST, 'name', FILTER_SANITIZE_STRING);
     $return['error'] = false;
     if (wp_verify_nonce($nonce, 'rtmedia_create_album_nonce') && isset($_name) && $_name && is_rtmedia_album_enable()) {
         $_context = filter_input(INPUT_POST, 'context', FILTER_SANITIZE_STRING);
         $_context_id = filter_input(INPUT_POST, 'context_id', FILTER_SANITIZE_NUMBER_INT);
         if (!empty($_context) && 'group' === $_context) {
             $group_id = !empty($_context_id) ? $_context_id : '';
             if (false === can_user_create_album_in_group($group_id)) {
                 $return['error'] = esc_html__('You can not create album in this group.', 'buddypress-media');
             }
         }
         $create_album = apply_filters('rtm_is_album_create_enable', true);
         if (!$create_album) {
             $return['error'] = esc_html__('You can not create album.', 'buddypress-media');
         }
         $create_album = apply_filters('rtm_display_create_album_button', true, $_context_id);
         if (!$create_album) {
             $return['error'] = esc_html__('You can not create more albums, you exceed your album limit.', 'buddypress-media');
         }
         if (false !== $return['error']) {
             wp_send_json($return);
         }
         $album = new RTMediaAlbum();
         // setup context values
         $context = $_context;
         if ('profile' === $context) {
             $context_id = get_current_user_id();
         } else {
             $context_id = !empty($_context_id) ? $_context_id : 0;
         }
         // setup new album data
         $album_data = apply_filters('rtmedia_create_album_data', array('title' => $_name, 'author' => get_current_user_id(), 'new' => true, 'post_id' => false, 'context' => $context, 'context_id' => $context_id));
         $rtmedia_id = $album->add($album_data['title'], $album_data['author'], $album_data['new'], $album_data['post_id'], $album_data['context'], $album_data['context_id']);
         $rtmedia_nav = new RTMediaNav();
         if ('group' === $_context) {
             $rtmedia_nav->refresh_counts($_context_id, array('context' => $_context, 'context_id' => $_context_id));
         } else {
             $rtmedia_nav->refresh_counts(get_current_user_id(), array('context' => 'profile', 'media_author' => get_current_user_id()));
         }
         if ($rtmedia_id) {
             $return['album'] = apply_filters('rtmedia_create_album_response', $rtmedia_id);
             wp_send_json($return);
         } else {
             echo false;
         }
     } else {
         $return['error'] = esc_html__('Data mismatch, Please insert data properly.', 'buddypress-media');
         wp_send_json($return);
     }
     wp_die();
 }
コード例 #2
0
ファイル: RTMediaAJAX.php プロジェクト: neerukoul/rtMedia
 function create_album()
 {
     $nonce = $_POST['create_album_nonce'];
     $return['error'] = false;
     if (wp_verify_nonce($nonce, 'rtmedia_create_album_nonce') && isset($_POST['name']) && $_POST['name'] && is_rtmedia_album_enable()) {
         if (isset($_POST['context']) && $_POST['context'] == "group") {
             $group_id = !empty($_POST['context_id']) ? $_POST['context_id'] : '';
             if (can_user_create_album_in_group($group_id) == false) {
                 $return['error'] = __('You can not create album in this group.', 'buddypress-media');
             }
         }
         $create_album = apply_filters("rtm_is_album_create_enable", true);
         if (!$create_album) {
             $return['error'] = __('You can not create album.', 'buddypress-media');
         }
         $create_album = apply_filters("rtm_display_create_album_button", true, $_POST['context_id']);
         if (!$create_album) {
             $return['error'] = __('You can not create more albums, you exceed your album limit.', 'buddypress-media');
         }
         if ($return['error'] !== false) {
             echo json_encode($return);
             wp_die();
         }
         $album = new RTMediaAlbum();
         // setup context values
         $context = $_POST['context'];
         if ($context == 'profile') {
             $context_id = get_current_user_id();
         } else {
             $context_id = isset($_POST['context_id']) ? $_POST['context_id'] : 0;
         }
         // setup new album data
         $album_data = apply_filters('rtmedia_create_album_data', array('title' => $_POST['name'], 'author' => get_current_user_id(), 'new' => true, 'post_id' => false, 'context' => $context, 'context_id' => $context_id));
         $rtmedia_id = $album->add($album_data['title'], $album_data['author'], $album_data['new'], $album_data['post_id'], $album_data['context'], $album_data['context_id']);
         $rtMediaNav = new RTMediaNav();
         if ($_POST['context'] == "group") {
             $rtMediaNav->refresh_counts($_POST['context_id'], array("context" => $_POST['context'], 'context_id' => $_POST['context_id']));
         } else {
             $rtMediaNav->refresh_counts(get_current_user_id(), array("context" => "profile", 'media_author' => get_current_user_id()));
         }
         if ($rtmedia_id) {
             $return['album'] = apply_filters('rtmedia_create_album_response', $rtmedia_id);
             echo json_encode($return);
         } else {
             echo esc_attr(false);
         }
     } else {
         $return['error'] = __('Data mismatch, Please insert data properly.', 'buddypress-media');
         echo json_encode($return);
     }
     wp_die();
 }
コード例 #3
0
 function create_album()
 {
     $nonce = $_POST['create_album_nonce'];
     if (wp_verify_nonce($nonce, 'rtmedia_create_album_nonce') && isset($_POST['name']) && $_POST['name'] && is_rtmedia_album_enable()) {
         if (isset($_POST['context']) && $_POST['context'] == "group") {
             $group_id = !empty($_POST['context_id']) ? $_POST['context_id'] : '';
             if (can_user_create_album_in_group($group_id) == false) {
                 echo false;
                 wp_die();
             }
         }
         $create_album = apply_filters("rtm_is_album_create_enable", true);
         if (!$create_album) {
             echo false;
             wp_die();
         }
         $create_album = apply_filters("rtm_display_create_album_button", true, $_POST['context_id']);
         if (!$create_album) {
             echo false;
             wp_die();
         }
         $album = new RTMediaAlbum();
         $rtmedia_id = $album->add($_POST['name'], get_current_user_id(), true, false, $_POST['context'], $_POST['context_id']);
         $rtMediaNav = new RTMediaNav();
         if ($_POST['context'] == "group") {
             $rtMediaNav->refresh_counts($_POST['context_id'], array("context" => $_POST['context'], 'context_id' => $_POST['context_id']));
         } else {
             $rtMediaNav->refresh_counts(get_current_user_id(), array("context" => "profile", 'media_author' => get_current_user_id()));
         }
         if ($rtmedia_id) {
             echo $rtmedia_id;
         } else {
             echo false;
         }
     } else {
         echo false;
     }
     wp_die();
 }
コード例 #4
0
 /**
  * Adds a new album
  *
  * @global type $rtmedia_interaction
  *
  * @param type  $title
  * @param type  $author_id
  * @param type  $new
  * @param type  $post_id
  *
  * @return type
  */
 function add($title = '', $author_id = false, $new = true, $post_id = false, $context = false, $context_id = false)
 {
     global $rtmedia_interaction;
     /* action to perform any task before adding the album */
     do_action('rtmedia_before_add_album');
     $author_id = $author_id ? $author_id : $this->get_current_author();
     /* Album Details which will be passed to Database query to add the album */
     $post_vars = array('post_title' => empty($title) ? __('Untitled Album', 'buddypress-media') : $title, 'post_type' => 'rtmedia_album', 'post_author' => $author_id, 'post_status' => 'hidden');
     /* Check whether to create a new album in wp_post table
      * This is the case when a user creates a album of his own. We need to
      * create a separte post in wp_post which will work as parent for
      * all the media uploaded to that album
      *
      *  */
     if ($new) {
         $album_id = wp_insert_post($post_vars);
     } else {
         $album_id = $post_id;
     }
     $current_album = get_post($album_id, ARRAY_A);
     if ($context === false) {
         $context = isset($rtmedia_interaction->context->type) ? $rtmedia_interaction->context->type : null;
     }
     if ($context_id === false) {
         $context_id = isset($rtmedia_interaction->context->id) ? $rtmedia_interaction->context->id : null;
     }
     // add in the media since album is also a media
     //defaults
     $attributes = array('blog_id' => get_current_blog_id(), 'media_id' => $album_id, 'album_id' => null, 'media_title' => $current_album['post_title'], 'media_author' => $current_album['post_author'], 'media_type' => 'album', 'context' => $context, 'context_id' => $context_id, 'activity_id' => null, 'privacy' => null);
     $attributes = apply_filters("rtmedia_before_save_album_attributes", $attributes, $_POST);
     $rtmedia_id = $this->media->insert_album($attributes);
     $rtMediaNav = new RTMediaNav();
     $media_count = $rtMediaNav->refresh_counts($context_id, array("context" => $context, 'media_author' => $context_id));
     /* action to perform any task after adding the album */
     global $rtmedia_points_media_id;
     $rtmedia_points_media_id = $rtmedia_id;
     do_action('rtmedia_after_add_album', $this);
     return $rtmedia_id;
 }
コード例 #5
0
 function save_album_edit()
 {
     global $rtmedia_query;
     $nonce = $_REQUEST['rtmedia_media_nonce'];
     if (wp_verify_nonce($nonce, 'rtmedia_' . $rtmedia_query->media_query['album_id'])) {
         $media = new RTMediaMedia();
         $model = new RTMediaModel();
         if (isset($_POST['submit'])) {
             $data_array = array('media_title', 'description', 'privacy');
             $data = rtmedia_sanitize_object($_POST, $data_array);
             $album = $model->get_media(array('id' => $rtmedia_query->media_query['album_id']), false, false);
             $state = $media->update($album[0]->id, $data, $album[0]->media_id);
             global $rtmedia_points_media_id;
             $rtmedia_points_media_id = $album[0]->id;
             do_action('rtmedia_after_update_album', $album[0]->id, $state);
         } elseif (isset($_POST['move-selected'])) {
             $album_move = $_POST['album'];
             $selected_ids = null;
             if (isset($_POST['selected'])) {
                 $selected_ids = $_POST['selected'];
                 unset($_POST['selected']);
             }
             if (!empty($selected_ids) && is_array($selected_ids)) {
                 $album_move_details = $model->get_media(array('id' => $album_move), false, false);
                 foreach ($selected_ids as $media_id) {
                     $media_details = $model->get_media(array('id' => $media_id), false, false);
                     $post_array['ID'] = $media_details[0]->media_id;
                     $post_array['post_parent'] = $album_move_details[0]->media_id;
                     wp_update_post($post_array);
                     $media->update($media_details[0]->id, array('album_id' => $album_move_details[0]->id), $media_details[0]->media_id);
                 }
             }
         }
         //refresh
         $rtMediaNav = new RTMediaNav();
         if ($rtmedia_query->media_query['context'] == "group") {
             $rtMediaNav->refresh_counts($rtmedia_query->media_query['context_id'], array("context" => $rtmedia_query->media_query['context'], 'context_id' => $rtmedia_query->media_query['context_id']));
         } else {
             $rtMediaNav->refresh_counts($rtmedia_query->media_query['media_author'], array("context" => "profile", 'media_author' => $rtmedia_query->media_query['media_author']));
         }
         wp_safe_redirect(esc_url_raw(get_rtmedia_permalink($rtmedia_query->media_query['album_id']) . 'edit/'));
         die;
     } else {
         _e('Ooops !!! Invalid access. No nonce was found !!', 'buddypress-media');
     }
 }
コード例 #6
0
ファイル: RTMediaTemplate.php プロジェクト: rtCamp/rtMedia
 function save_album_edit()
 {
     global $rtmedia_query;
     $nonce = isset($_REQUEST['rtmedia_media_nonce']) ? wp_unslash($_REQUEST['rtmedia_media_nonce']) : '';
     if (wp_verify_nonce($nonce, 'rtmedia_' . $rtmedia_query->media_query['album_id'])) {
         $media = new RTMediaMedia();
         $model = new RTMediaModel();
         $submit = filter_input(INPUT_POST, 'submit', FILTER_SANITIZE_STRING);
         $_move_selected = filter_input(INPUT_POST, 'move-selected', FILTER_SANITIZE_STRING);
         $_album = filter_input(INPUT_POST, 'album', FILTER_SANITIZE_STRING);
         $filters = array('selected' => array('filter' => FILTER_VALIDATE_INT, 'flags' => FILTER_REQUIRE_ARRAY));
         $_selected_arr = filter_input_array(INPUT_POST, $filters);
         $_selected = $_selected_arr['selected'];
         if (isset($submit)) {
             $data_array = array('media_title', 'description', 'privacy');
             $data = rtmedia_sanitize_object($_POST, $data_array);
             $album = $model->get_media(array('id' => $rtmedia_query->media_query['album_id']), false, false);
             $state = $media->update($album[0]->id, $data, $album[0]->media_id);
             global $rtmedia_points_media_id;
             $rtmedia_points_media_id = $album[0]->id;
             do_action('rtmedia_after_update_album', $album[0]->id, $state);
         } elseif (!empty($_move_selected)) {
             $album_move = $_album;
             $selected_ids = null;
             if (isset($_selected)) {
                 $selected_ids = $_selected;
                 unset($_selected);
             }
             if (!empty($selected_ids) && is_array($selected_ids)) {
                 $album_move_details = $model->get_media(array('id' => $album_move), false, false);
                 foreach ($selected_ids as $media_id) {
                     $media_details = $model->get_media(array('id' => $media_id), false, false);
                     $post_array['ID'] = $media_details[0]->media_id;
                     $post_array['post_parent'] = $album_move_details[0]->media_id;
                     wp_update_post($post_array);
                     $media->update($media_details[0]->id, array('album_id' => $album_move_details[0]->id), $media_details[0]->media_id);
                 }
             }
         }
         //refresh
         $rtmedia_nav = new RTMediaNav();
         if ('group' === $rtmedia_query->media_query['context']) {
             $rtmedia_nav->refresh_counts($rtmedia_query->media_query['context_id'], array('context' => $rtmedia_query->media_query['context'], 'context_id' => $rtmedia_query->media_query['context_id']));
         } else {
             $rtmedia_nav->refresh_counts($rtmedia_query->media_query['media_author'], array('context' => 'profile', 'media_author' => $rtmedia_query->media_query['media_author']));
         }
         wp_safe_redirect(esc_url_raw(get_rtmedia_permalink($rtmedia_query->media_query['album_id']) . 'edit/'));
         die;
     } else {
         esc_html_e('Ooops !!! Invalid access. No nonce was found !!', 'buddypress-media');
     }
 }
コード例 #7
0
 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;
     }
 }
コード例 #8
0
 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;
     }
 }
コード例 #9
0
 /**
  *
  */
 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;
     }
 }
コード例 #10
0
ファイル: RTMediaMedia.php プロジェクト: poweronio/mbsite
 /**
  * Generic method to delete a media
  *
  * @param type $media_id
  *
  * @return boolean
  */
 function delete($id, $core = false, $delete_activity = true)
 {
     do_action('rtmedia_before_delete_media', $id);
     $media = $this->model->get(array('id' => $id), false, false);
     $status = 0;
     if ($media) {
         /* delete meta */
         //delete_rtmedia_meta($id);
         if ($delete_activity) {
             if ($media[0]->activity_id && function_exists('bp_activity_delete_by_activity_id')) {
                 $related_media = $this->model->get(array('activity_id' => $media[0]->activity_id), false, false);
                 if (count($related_media) > 1) {
                     $activity_media = array();
                     foreach ($related_media as $temp_media) {
                         if ($temp_media->id == $id) {
                             continue;
                         }
                         $activity_media[] = $temp_media->id;
                     }
                     $objActivity = new RTMediaActivity($activity_media);
                     global $wpdb, $bp;
                     $wpdb->update($bp->activity->table_name, array("type" => "rtmedia_update", "content" => $objActivity->create_activity_html()), array("id" => $media[0]->activity_id));
                 } else {
                     if (isset($media[0]) && isset($media[0]->activity_id)) {
                         bp_activity_delete_by_activity_id($media[0]->activity_id);
                     }
                 }
             }
         }
         if (!$core) {
             wp_delete_attachment($media[0]->media_id, true);
         }
         $status = $this->model->delete(array('id' => $id));
         //delete media meta (view) from wp_rt_rtm_media_meta
         $delete_rtmedia_views = delete_rtmedia_meta($id, 'view');
         if ($status != 0 && ($media[0]->media_type == "album" || $media[0]->media_type == "playlist")) {
             $status = wp_delete_post($media[0]->media_id);
         }
         $rtMediaNav = new RTMediaNav();
         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 (!$status) {
         return false;
     } else {
         global $rtmedia_points_media_id;
         $rtmedia_points_media_id = $id;
         do_action('rtmedia_after_delete_media', $id);
         return true;
     }
 }
コード例 #11
0
ファイル: RTMediaMedia.php プロジェクト: rtCamp/rtMedia
 /**
  * Generic method to delete a media
  *
  * @param int $id
  * @param bool $core
  * @param bool $delete_activity
  *
  * @return bool
  *
  */
 function delete($id, $core = false, $delete_activity = true)
 {
     do_action('rtmedia_before_delete_media', $id);
     $media = $this->model->get(array('id' => $id), false, false);
     $status = 0;
     if ($media) {
         /* delete meta */
         if ($delete_activity) {
             if ($media[0]->activity_id && function_exists('bp_activity_delete_by_activity_id')) {
                 $related_media = $this->model->get(array('activity_id' => $media[0]->activity_id), false, false);
                 if (count($related_media) > 1) {
                     $activity_media = array();
                     foreach ($related_media as $temp_media) {
                         if ($temp_media->id === $id) {
                             continue;
                         }
                         $activity_media[] = $temp_media->id;
                     }
                     $obj_activity = new RTMediaActivity($activity_media);
                     global $wpdb, $bp;
                     $wpdb->update($bp->activity->table_name, array('type' => 'rtmedia_update', 'content' => $obj_activity->create_activity_html()), array('id' => $media[0]->activity_id));
                 } else {
                     if (isset($media[0]) && isset($media[0]->activity_id)) {
                         bp_activity_delete_by_activity_id($media[0]->activity_id);
                     }
                 }
                 // Deleting like and comment activity for media
                 if (function_exists('bp_activity_delete')) {
                     bp_activity_delete(array('item_id' => $media[0]->id));
                 }
             }
         }
         if (!$core) {
             wp_delete_attachment($media[0]->media_id, true);
         }
         $status = $this->model->delete(array('id' => $id));
         //delete media meta (view) from wp_rt_rtm_media_meta
         $delete_rtmedia_views = delete_rtmedia_meta($id, 'view');
         if (0 !== $status && ('album' === $media[0]->media_type || 'playlist' === $media[0]->media_type)) {
             $status = wp_delete_post($media[0]->media_id);
         }
         $rtmedia_nav = new RTMediaNav();
         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 (!$status) {
         return false;
     } else {
         global $rtmedia_points_media_id;
         $rtmedia_points_media_id = $id;
         do_action('rtmedia_after_delete_media', $id);
         return true;
     }
 }
コード例 #12
0
ファイル: RTMediaJsonApi.php プロジェクト: rtCamp/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 = 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));
     }
 }