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(); }
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(); }
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(); }
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; } } } }
function rtmedia_global_albums() { return RTMediaAlbum::get_globals(); //get_site_option('rtmedia-global-albums'); }
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); } }
function get_other_album_count($profile_id, $context = "profile") { $global = RTMediaAlbum::get_globals(); $sql = "select distinct album_id from {$this->table_name} where 2=2 AND context = '{$context}' "; if (is_multisite()) { $sql .= " AND {$this->table_name}.blog_id = '" . get_current_blog_id() . "' "; } if (is_array($global) && count($global) > 0) { $sql .= " and album_id in ("; $sep = ""; foreach ($global as $id) { $sql .= $sep . $id; $sep = ","; } $sql .= ")"; } if ($context == "profile") { $sql .= " AND media_author={$profile_id} "; } else { if ($context == "group") { $sql .= " AND context_id={$profile_id} "; } } global $wpdb; $result = $wpdb->get_results($sql); if (isset($result)) { return count($result); } else { return 0; } }
/** * Get global albums * * @return array */ function rtmedia_global_albums() { return RTMediaAlbum::get_globals(); }
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; } }
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)); } }
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; } }
/** * * @param integer $profile_id * @param string $context * * @return int */ function get_other_album_count($profile_id, $context = 'profile') { global $wpdb; $global = RTMediaAlbum::get_globals(); $sql = $wpdb->prepare("select distinct album_id from {$this->table_name} where 2=2 AND context = %s ", $context); if (is_multisite()) { $sql .= $wpdb->prepare(" AND {$this->table_name}.blog_id = %d ", get_current_blog_id()); } if (is_array($global) && count($global) > 0) { $sql .= ' and album_id in ('; $sep = ''; foreach ($global as $id) { $sql .= $sep . esc_sql($id); $sep = ','; } $sql .= ')'; } if ('profile' === $context) { $sql .= $wpdb->prepare(' AND media_author=%d ', $profile_id); } else { if ('group' === $context) { $sql .= $wpdb->prepare(' AND context_id=%d ', $profile_id); } } $sql .= 'limit 100'; $result = $wpdb->get_results($sql); if (isset($result)) { return count($result); } else { return 0; } }