get_default() static public méthode

There is a default global album which works as a Wall Post Album for the user.
static public get_default ( ) : type
Résultat type
 function before_render()
 {
     $globa_id = RTMediaAlbum::get_default();
     if (isset($this->media->album_id) && $this->media->album_id > 0) {
         $album = $this->model->get(array('media_id' => $globa_id));
         if ($album && isset($album[0])) {
             if ($album[0]->id == $this->media->album_id) {
                 $this->privacy = 1000;
                 return;
             }
         }
         $album = $this->model->get(array('id' => $this->media->album_id));
         if ($album && isset($album[0])) {
             if ($album[0]->media_author != $this->interactor) {
                 $this->privacy = 1000;
                 return;
             }
         }
     }
 }
Exemple #2
0
 function check_global_album()
 {
     //todo: Nonce required
     $album = new RTMediaAlbum();
     $global_album = $album->get_default();
     // @codingStandardsIgnoreStart
     //** Hack for plupload default name
     if (isset($_POST['action']) && isset($_POST['mode']) && 'file_upload' === sanitize_text_field($_POST['mode'])) {
         unset($_POST['name']);
     }
     // @codingStandardsIgnoreEnd
     //**
     global $rtmedia_error;
     if (isset($rtmedia_error) && true === $rtmedia_error) {
         return false;
     }
     if (!$global_album) {
         $global_album = $album->add_global(esc_html__('Wall Posts', 'buddypress-media'));
     }
     // fix multisite global album doesn't exist issue.
     if (is_multisite() && !rtmedia_get_site_option('rtmedia_fix_multisite_global_albums', false)) {
         $model = new RTMediaModel();
         $global_albums = rtmedia_global_albums();
         $album_objects = $model->get_media(array('id' => $global_albums), false, false);
         if (empty($album_objects)) {
             $global_album = $album->add_global(esc_html__('Wall Posts', 'buddypress-media'));
         }
         rtmedia_update_site_option('rtmedia_fix_multisite_global_albums', true);
     }
 }
Exemple #3
0
 function check_global_album()
 {
     $album = new RTMediaAlbum();
     $global_album = $album->get_default();
     //** Hack for plupload default name
     if (isset($_POST["action"]) && isset($_POST["mode"]) && $_POST["mode"] == "file_upload") {
         unset($_POST["name"]);
     }
     //**
     global $rtmedia_error;
     if (isset($rtmedia_error) && $rtmedia_error === true) {
         return false;
     }
     if (!$global_album) {
         $global_album = $album->add_global(__("Wall Posts", 'buddypress-media'));
     }
     // fix multisite global album doesn't exist issue.
     if (is_multisite() && !rtmedia_get_site_option('rtmedia_fix_multisite_global_albums', false)) {
         $model = new RTMediaModel();
         $global_albums = rtmedia_global_albums();
         $album_objects = $model->get_media(array('id' => $global_albums), false, false);
         if (empty($album_objects)) {
             $global_album = $album->add_global(__("Wall Posts", 'buddypress-media'));
         }
         rtmedia_update_site_option('rtmedia_fix_multisite_global_albums', true);
     }
 }
 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;
         $image_type = $_POST['image_type'];
         $str_replace = 'data:image/' . $image_type . ';base64,';
         $img = str_replace($str_replace, '', $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'] = !empty($_POST['context']) ? $_POST['context'] : 'profile';
         $uploaded['context_id'] = !empty($_POST['context_id']) ? $_POST['context_id'] : $this->user_id;
         $uploaded['mode'] = 'file_upload';
         $uploaded['media_author'] = $this->user_id;
         $uploaded['album_id'] = !empty($_POST['album_id']) ? $_POST['album_id'] : RTMediaAlbum::get_default();
         $uploaded['privacy'] = !empty($_POST['privacy']) ? $_POST['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($_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 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 (sizeof($same_medias) == 1 && $activity_id) {
                 $updated = true;
             }
         }
     }
     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;
     }
 }
Exemple #5
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 = 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));
     }
 }
Exemple #6
0
 function check_global_album()
 {
     $album = new RTMediaAlbum();
     $global_album = $album->get_default();
     //** Hack for plupload default name
     if (isset($_POST["action"]) && isset($_POST["mode"]) && $_POST["mode"] == "file_upload") {
         unset($_POST["name"]);
     }
     //**
     global $rtmedia_error;
     if (isset($rtmedia_error) && $rtmedia_error === true) {
         return false;
     }
     if (!$global_album) {
         $global_album = $album->add_global(__("Wall Posts", "rtmedia", true));
     }
 }
 /**
  *
  */
 function set_bp_component_album_id()
 {
     switch (bp_current_component()) {
         case 'groups':
             $this->upload['album_id'] = RTMediaAlbum::get_default();
             break;
         default:
             $this->upload['album_id'] = RTMediaAlbum::get_default();
             break;
     }
 }