/** * Delete Media * @since 1.4 * @version 1.0 */ public function delete_media($media_id) { // Get media details from id $model = new RTMediaModel(); $media = $model->get_media(array('id' => $media_id), 0, 1); if (!isset($media->media_type)) { return; } // If this media type awards zero, bail if ($this->prefs['delete_media'][$media->media_type] == $this->core->zero()) { return; } // Check for exclusion if ($this->core->exclude_user($media->media_author) === true) { return; } // Only deduct if user gained points for this if ($this->core->has_entry($media->media_type . '_upload', $media->media_author, $media_id)) { // Execute $this->core->add_creds($media->media_type . '_deletion', $media->media_author, $this->prefs['delete_media'][$media->media_type], $this->prefs['delete_media'][$media->media_type . '_log'], $media_id, array('ref_type' => 'media', 'attachment_id' => $media->media_id), $this->mycred_type); } }
<?php global $rtmedia_query, $rtmedia_media; $model = new RTMediaModel(); $media = $model->get_media(array('id' => $rtmedia_query->media_query['album_id']), false, false); if (!isset($media[0])) { return; } $rtmedia_media = $media[0]; ?> <div class="rtmedia-container rtmedia-single-container rtmedia-media-edit"> <?php if (rtmedia_is_global_album($rtmedia_query->media_query['album_id'])) { ?> <h2><?php esc_html_e('Edit Album : ', 'buddypress-media'); echo esc_html($rtmedia_media->media_title); ?> </h2> <div class="rtmedia-edit-media-tabs rtmedia-editor-main"> <ul class="rtm-tabs clearfix"> <li class="active"><a href="#details-tab"><i class='dashicons dashicons-edit rtmicon'></i><?php esc_html_e('Details', 'buddypress-media'); ?> </a></li> <?php if (!is_rtmedia_group_album()) { ?> <li class=""><a href="#manage-media-tab"><i
/** * Function to handle the callback request by the FFMPEG encoding server * * @since 1.0 */ public function handle_callback() { require_once ABSPATH . 'wp-admin/includes/image.php'; if (isset($_REQUEST['job_id']) && isset($_REQUEST['download_url'])) { $has_thumbs = isset($_POST['thumbs']) ? true : false; $flag = false; global $wpdb; $model = new RTDBModel('rtm_media_meta', false, 10, true); $meta_details = $model->get(array('meta_value' => $_REQUEST['job_id'], 'meta_key' => 'rtmedia-encoding-job-id')); if (!isset($meta_details[0])) { $id = intval($_REQUEST["rt_id"]); } else { $id = $meta_details[0]->media_id; } if (isset($id) && is_numeric($id)) { $model = new RTMediaModel(); $media = $model->get_media(array('id' => $id), 0, 1); $this->media_author = $media[0]->media_author; $attachment_id = $media[0]->media_id; //error_log(var_export($_POST,true)); update_post_meta($attachment_id, 'rtmedia_encode_response', $_POST); if ($has_thumbs) { $cover_art = $this->add_media_thumbnails($attachment_id); } if (isset($_POST['format']) && $_POST['format'] == 'thumbnails') { die; } $this->uploaded["context"] = $media[0]->context; $this->uploaded["context_id"] = $media[0]->context_id; $this->uploaded["media_author"] = $media[0]->media_author; $attachemnt_post = get_post($attachment_id); $download_url = urldecode(urldecode($_REQUEST['download_url'])); //error_log($download_url); $new_wp_attached_file_pathinfo = pathinfo($download_url); $post_mime_type = $new_wp_attached_file_pathinfo['extension'] == 'mp4' ? 'video/mp4' : 'audio/mp3'; try { $file_bits = file_get_contents($download_url); } catch (Exception $e) { $flag = $e->getMessage(); } if ($file_bits) { unlink(get_attached_file($attachment_id)); add_filter('upload_dir', array($this, 'upload_dir')); $upload_info = wp_upload_bits($new_wp_attached_file_pathinfo['basename'], null, $file_bits); //error_log(var_dump($upload_info)); $wpdb->update($wpdb->posts, array('guid' => $upload_info['url'], 'post_mime_type' => $post_mime_type), array('ID' => $attachment_id)); $old_wp_attached_file = get_post_meta($attachment_id, '_wp_attached_file', true); $old_wp_attached_file_pathinfo = pathinfo($old_wp_attached_file); update_post_meta($attachment_id, '_wp_attached_file', str_replace($old_wp_attached_file_pathinfo['basename'], $new_wp_attached_file_pathinfo['basename'], $old_wp_attached_file)); // $media_entry = new BPMediaHostWordpress($attachment_id); // $activity_content = str_replace($old_wp_attached_file_pathinfo['basename'], $new_wp_attached_file_pathinfo['basename'], $media_entry->get_media_activity_content()); // $wpdb->update($wpdb->prefix . 'bp_activity', array('content' => $activity_content), array('id' => $media[0]->activity_id)); // Check if uplaod is through activity upload //update_post_meta($attachment_id, 'rtmedia_encode_response', $_POST); $activity_id = $media[0]->activity_id; if ($activity_id) { $content = $wpdb->get_var("SELECT content FROM {$wpdb->base_prefix}bp_activity WHERE id = {$activity_id}"); $activity_content = str_replace($attachemnt_post->guid, $upload_info['url'], $content); $wpdb->update($wpdb->base_prefix . 'bp_activity', array('content' => $activity_content), array('id' => $activity_id)); } } else { $flag = __('Could not read file.', 'buddypress-media'); error_log($flag); } } else { $flag = __('Something went wrong. The required attachment id does not exists. It must have been deleted.', 'buddypress-media'); error_log($flag); } $this->update_usage($this->api_key); if (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] == '4.30.110.155') { $mail = true; } else { $mail = false; } if ($flag && $mail) { $download_link = esc_url(add_query_arg(array('job_id' => $_GET['job_id'], 'download_url' => $_GET['download_url']), home_url())); $subject = __('rtMedia Encoding: Download Failed', 'buddypress-media'); $message = sprintf(__('<p><a href="%s">Media</a> was successfully encoded but there was an error while downloading:</p> <p><code>%s</code></p> <p>You can <a href="%s">retry the download</a>.</p>', 'buddypress-media'), get_edit_post_link($attachment_id), $flag, $download_link); $users = get_users(array('role' => 'administrator')); if ($users) { foreach ($users as $user) { $admin_email_ids[] = $user->user_email; } add_filter('wp_mail_content_type', create_function('', 'return "text/html";')); wp_mail($admin_email_ids, $subject, $message); } echo $flag; } elseif ($flag) { echo $flag; } else { _e("Done", 'buddypress-media'); } die; } }
/** * Define rt_media_regeneration. * * @access public * * @param void * * @return void */ public function rt_media_regeneration() { if (isset($_POST['media_id'])) { $model = new RTMediaModel(); $media = $model->get_media(array('media_id' => $_POST['media_id']), 0, 1); $media_type = $media[0]->media_type; $response = array(); if ('video' == $media_type) { $objRTMediaEncoding = new RTMediaEncoding(true); $autoformat = 'thumbnails'; $objRTMediaEncoding->reencoding(intval($_POST['media_id']), $autoformat); $response['status'] = true; } else { $response['status'] = false; $response['message'] = esc_html__('not a video ...', 'buddypress-media'); } echo json_encode($response); die; } }
function check_return_merge() { global $rtmedia_query; if ($rtmedia_query->action_query->action != 'merge') { return; } $nonce = $_REQUEST['rtmedia_merge_album_nonce']; if (wp_verify_nonce($nonce, 'rtmedia_merge_album_' . $rtmedia_query->media_query['album_id'])) { $media = new RTMediaMedia(); $model = new RTMediaModel(); $album_contents = $model->get(array('album_id' => $rtmedia_query->media_query['album_id']), false, false); $album_move_details = $model->get_media(array('id' => $_POST['album']), false, false); foreach ($album_contents as $album_media) { $post_array['ID'] = $album_media->media_id; $post_array['post_parent'] = $album_move_details[0]->media_id; wp_update_post($post_array); $media->update($album_media->id, array('album_id' => $album_move_details[0]->id), $album_media->media_id); } $media->delete($rtmedia_query->media_query['album_id']); } if (isset($rtmedia_query->media_query['context']) && $rtmedia_query->media_query['context'] == "group") { global $bp; $group_link = bp_get_group_permalink($bp->groups->current_group); wp_safe_redirect(esc_url_raw(trailingslashit($group_link) . RTMEDIA_MEDIA_SLUG . '/album/')); } else { wp_safe_redirect(esc_url_raw(trailingslashit(get_rtmedia_user_link(get_current_user_id())) . RTMEDIA_MEDIA_SLUG . '/album/')); } exit; }
function rtmedia_group_album_list($selected_album_id = false) { //by default, first album in list will be selected global $rtmedia_query; $model = new RTMediaModel(); $global_option = rtmedia_global_album_list($selected_album_id); $global_albums = rtmedia_global_albums(); $album_objects = $model->get_media(array('context' => $rtmedia_query->media_query['context'], 'context_id' => $rtmedia_query->media_query['context_id'], 'media_type' => 'album'), false, false); $option_group = ""; if ($album_objects) { foreach ($album_objects as $album) { $selected = ''; if ($selected_album_id != false && $selected_album_id != '' && $selected_album_id == $album->id) { $selected = 'selected="selected"'; } if (!in_array($album->id, $global_albums) && (isset($rtmedia_query->media_query['album_id']) && $album->id != $rtmedia_query->media_query['album_id'] || !isset($rtmedia_query->media_query['album_id']))) { $option_group .= '<option value="' . $album->id . '" ' . $selected . '>' . $album->media_title . '</option>'; } } } $option = $global_option; if ($option_group != "") { $option .= "<optgroup label='" . __("Group Albums", "rtmedia") . "' value = 'group'>{$option_group}</optgroup>"; } if ($option) { return $option; } else { return false; } }
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); } }
/** * Get group's album list * * @global RTMediaQuery $rtmedia_query * * @param bool|int $selected_album_id * * @return bool|null|string */ function rtmedia_group_album_list($selected_album_id = false) { //by default, first album in list will be selected global $rtmedia_query; $model = new RTMediaModel(); $global_option = rtmedia_global_album_list($selected_album_id); $global_albums = rtmedia_global_albums(); $album_objects = $model->get_media(array('context' => $rtmedia_query->media_query['context'], 'context_id' => $rtmedia_query->media_query['context_id'], 'media_type' => 'album'), false, false); $option_group = ''; if ($album_objects) { foreach ($album_objects as $album) { if (!in_array($album->id, $global_albums) && (isset($rtmedia_query->media_query['album_id']) && $album->id != $rtmedia_query->media_query['album_id'] || !isset($rtmedia_query->media_query['album_id']))) { $option_group .= '<option value="' . esc_attr($album->id) . '" ' . selected($selected_album_id, $album->id) . '>' . esc_html($album->media_title) . '</option>'; } } } $option = $global_option; if (!empty($option_group)) { $option .= "<optgroup label='" . esc_attr__('Group Albums', 'buddypress-media') . "' value = 'group'>{$option_group}</optgroup>"; } if ($option) { return $option; } else { return false; } }
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); } }
/** * [rtmedia_edit_media_on_database] * Update Media details on database while admin edit reported media * @param [Array] $data Image Details * @param [Number] $post_ID Media ID * @return [array] $data */ function rtmedia_edit_media_on_database($data, $post_ID) { $post = get_post($post_ID); if ($_REQUEST) { if (isset($_REQUEST['postid']) && 'image-editor' == $_REQUEST['action'] && 'edit-attachment' == $_REQUEST['context']) { $media = new RTMediaModel(); $media_available = $media->get_media(array('media_id' => $_REQUEST['postid']), 0, 1); $media_id = $media_available[0]->id; if (!empty($media_available)) { $rtmedia_filepath_old = rtmedia_image('rt_media_activity_image', $media_id, false); if (isset($rtmedia_filepath_old)) { $is_valid_url = preg_match("/\\b(?:(?:https?|ftp):\\/\\/|www\\.)[-a-z0-9+&@#\\/%?=~_|!:,.;]*[-a-z0-9+&@#\\/%=~_|]/i", $rtmedia_filepath_old); if ($is_valid_url && function_exists('bp_is_active') && bp_is_active('activity')) { $thumbnailinfo = wp_get_attachment_image_src($post_ID, 'rt_media_activity_image'); $activity_id = rtmedia_activity_id($media_id); if ($post_ID && !empty($activity_id)) { global $wpdb, $bp; if (!empty($bp->activity)) { $media->model = new RTMediaModel(); $related_media_data = $media->model->get(array('activity_id' => $activity_id)); $related_media = array(); foreach ($related_media_data as $activity_media) { $related_media[] = $activity_media->id; } $activity_text = bp_activity_get_meta($activity_id, 'bp_activity_text'); $activity = new RTMediaActivity($related_media, 0, $activity_text); $activity_content_new = $activity->create_activity_html(); $activity_content = str_replace($rtmedia_filepath_old, wp_get_attachment_url($post_ID), $activity_content_new); $wpdb->update($bp->activity->table_name, array('content' => $activity_content), array('id' => $activity_id)); } } } } } } } return $data; }
/** * * Outputs the HTML code of this widget. * * @param array An array of standard parameters for widgets in this theme * @param array An array of settings for this widget instance * @return void * **/ function widget($args, $instance) { global $bp; global $rtmedia_query, $rtmedia_interaction, $rtmedia_media; global $rtmedia_backbone; $cache = get_transient(md5($this->id)); $data_source_type = ''; // the part with the title and widget wrappers cannot be cached! // in order to avoid problems with the calculating columns // extract($args, EXTR_SKIP); $title = apply_filters('widget_title', empty($instance['title']) ? __('Latest Photos', GKTPLNAME) : $instance['title'], $instance, $this->id_base); echo $before_widget; echo $before_title; echo $title; echo $after_title; if ($cache) { echo $cache; echo $after_widget; return; } ob_start(); // $user_id = empty($instance['user_id']) ? '' : $instance['user_id']; $offset = empty($instance['offset']) ? 0 : $instance['offset']; $columns = empty($instance['columns']) ? 5 : $instance['columns']; $rows = empty($instance['rows']) ? 2 : $instance['rows']; $cache = empty($instance['cache']) ? 60 : $instance['cache']; if (!is_numeric($offset)) { $offset = 0; } else { $offset = intval($offset); } if (!is_numeric($rows)) { $rows = 0; } else { $rows = intval($rows); } if (!is_numeric($columns)) { $columns = 0; } else { $columns = intval($columns); } $model = new RTMediaModel(); if ($data_source_type == 'user') { $media = $model->get_media(array('media_type' => 'photo', 'media_author' => $user_id), $offset, $columns * $rows); } else { $media = $model->get_media(array('media_type' => 'photo'), $offset, $columns * $rows); } if ($media == null) { echo __('There has been no recent activity.', GKTPLNAME); } else { ?> <div class="gk-bp-latest-photos" data-cols="<?php echo $columns; ?> "> <div> <?php foreach ($media as $img) { ?> <a href ="<?php echo get_rtmedia_permalink(rtmedia_id($img->media_id)); ?> "> <img src="<?php rtmedia_image("rt_media_thumbnail", rtmedia_id($img->media_id)); ?> " alt="<?php _e('View full image', GKTPLNAME); ?> " /> </a> <?php } ?> </div> </div> <?php } // save the cache results $cache_output = ob_get_flush(); if (is_numeric($cache) && $cache > 0) { set_transient(md5($this->id), $cache_output, 60 * $cache); } else { delete_transient(md5($this->id)); } // echo $after_widget; }
/** * * Outputs the HTML code of this widget. * * @param array An array of standard parameters for widgets in this theme * @param array An array of settings for this widget instance * @return void * **/ function widget($args, $instance) { global $bp; global $rtmedia_query, $rtmedia_interaction, $rtmedia_media; global $rtmedia_backbone; $cache = get_transient(md5($this->id)); // the part with the title and widget wrappers cannot be cached! // in order to avoid problems with the calculating columns // extract($args, EXTR_SKIP); $title = apply_filters('widget_title', empty($instance['title']) ? __('BuddyPress Activity', GKTPLNAME) : $instance['title'], $instance, $this->id_base); echo $before_widget; echo $before_title; echo $title; echo $after_title; if ($cache) { echo $cache; echo $after_widget; return; } ob_start(); // $data_source_type = empty($instance['data_source_type']) ? 'latest' : $instance['data_source_type']; $user_id = empty($instance['user_id']) ? '' : $instance['user_id']; $total_amount = empty($instance['total_amount']) ? 8 : $instance['total_amount']; $show_username = empty($instance['show_username']) ? 'enable' : $instance['show_username']; $show_readmore = empty($instance['show_readmore']) ? 'enable' : $instance['show_readmore']; $amount_page = empty($instance['amount_page']) ? 4 : $instance['amount_page']; $autoanimation = empty($instance['autoanimation']) ? 'disable' : $instance['autoanimation']; $photo_width = empty($instance['photo_width']) ? 310 : $instance['photo_width']; $offset = empty($instance['offset']) ? 0 : $instance['offset']; if (!is_numeric($offset)) { $offset = 0; } else { $offset = intval($offset); } if (!is_numeric($total_amount)) { $total_amount = 0; } else { $total_amount = intval($total_amount); } $width = 3000; $new_width = $total_amount * $photo_width; if ($new_width > 3000) { $width = $new_width; } $model = new RTMediaModel(); if ($data_source_type == 'user') { $media = $model->get_media(array('media_type' => 'photo', 'media_author' => $user_id), $offset, $total_amount); } else { $media = $model->get_media(array('media_type' => 'photo'), $offset, $total_amount); } ?> <div data-cols="<?php echo $amount_page; ?> " style="width: <?php echo $width; ?> px" <?php if ($autoanimation == 'enabled') { echo 'class="animate"'; } ?> > <?php if ($media == null) { ?> <h4> <?php echo __('GK BuddyPress Gallery: There has been no recent activity.', GKTPLNAME); ?> </h4> <?php } else { ?> <?php foreach ($media as $img) { ?> <figure style="width: <?php echo $photo_width; ?> px"> <img src="<?php rtmedia_image("rt_media_activity_image", rtmedia_id($img->media_id)); ?> " alt="<?php _e('View full image', GKTPLNAME); ?> " /> <figcaption> <?php if ($show_username == 'enabled') { ?> <small><?php echo rtmedia_get_author_name($img->media_author); ?> </small> <?php } ?> <p><?php echo $this->activity_text($this->gk_activity_content($img->activity_id), 15, false); ?> </p> <?php if ($show_readmore == 'enabled') { ?> <a href ="<?php echo get_rtmedia_permalink(rtmedia_id($img->media_id)); ?> "><?php _e('Read more...', GKTPLNAME); ?> </a> <?php } ?> </figcaption> </figure> <?php } ?> <?php } ?> </div> <?php // save the cache results $cache_output = ob_get_flush(); set_transient(md5($this->id), $cache_output, 3 * 60 * 60); // echo $after_widget; }
function rtmedia_single_media_pagination() { $disable = apply_filters('rtmedia_single_media_pagination', false); if (true === $disable) { return; } if (rtmedia_id()) { $model = new RTMediaModel(); $media = $model->get_media(array('id' => rtmedia_id()), 0, 1); if ('profile' == $media[0]->context) { $media = $model->get_media(array('media_author' => $media[0]->media_author, 'context' => $media[0]->context)); } else { if ('group' == $media[0]->context) { $media = $model->get_media(array('media_author' => $media[0]->media_author, 'context' => $media[0]->context, 'context_id' => $media[0]->context_id)); } } for ($i = 0; $i < count($media); $i++) { if (rtmedia_id() == $media[$i]->id) { if (0 != $i) { $previous = $media[$i - 1]->id; } if (count($media) != $i + 1) { $next = $media[$i + 1]->id; } break; } } } $html = ''; $pagination_label = array('previous_title' => __('Previous', 'buddypress-media'), 'previous_label' => __('Previous', 'buddypress-media'), 'next_title' => __('Next', 'buddypress-media'), 'next_label' => __('Next', 'buddypress-media')); $pagination_label = apply_filters('rtmedia_media_pagination_label', $pagination_label); if (isset($previous) && $previous) { $html .= '<div class="previous-pagination"><a href="' . esc_url(get_rtmedia_permalink($previous)) . '" title="' . esc_html($pagination_label['previous_title']) . '">' . esc_html($pagination_label['previous_label']) . '</a></div>'; } if (isset($next) && $next) { $html .= '<div class="next-pagination"><a href="' . esc_url(get_rtmedia_permalink($next)) . '" title="' . esc_html($pagination_label['next_title']) . '">' . esc_html($pagination_label['next_label']) . '</a></div>'; } echo $html; // @codingStandardsIgnoreLine }