Ejemplo n.º 1
0
 function save_single_edit()
 {
     add_filter('intermediate_image_sizes_advanced', array($this, 'filter_image_sizes_details'));
     global $rtmedia_query;
     $nonce = $_POST['rtmedia_media_nonce'];
     if (wp_verify_nonce($nonce, 'rtmedia_' . $rtmedia_query->action_query->id)) {
         /*
          * Need this file in order to use `wp_generate_attachment_metadata` function
          */
         require_once ABSPATH . 'wp-admin/includes/image.php';
         do_action('rtmedia_before_update_media', $rtmedia_query->action_query->id);
         $data_array = array('media_title', 'description', 'privacy');
         //for medias except album and playlist, if album_is is found, then update album_id for the media also
         if (isset($_POST['album_id']) && $_POST['album_id'] != '') {
             $data_array[] = 'album_id';
         }
         $data = rtmedia_sanitize_object($_POST, $data_array);
         $media = new RTMediaMedia();
         $image_path = get_attached_file($rtmedia_query->media[0]->media_id);
         if ($image_path && $rtmedia_query->media[0]->media_type == "photo") {
             $image_meta_data = wp_generate_attachment_metadata($rtmedia_query->media[0]->media_id, $image_path);
             wp_update_attachment_metadata($rtmedia_query->media[0]->media_id, $image_meta_data);
         }
         $state = $media->update($rtmedia_query->action_query->id, $data, $rtmedia_query->media[0]->media_id);
         if (isset($_POST['rtmedia-filepath-old'])) {
             $is_valid_url = preg_match("/\\b(?:(?:https?|ftp):\\/\\/|www\\.)[-a-z0-9+&@#\\/%?=~_|!:,.;]*[-a-z0-9+&@#\\/%=~_|]/i", $_POST['rtmedia-filepath-old']);
             if ($is_valid_url && function_exists('bp_is_active') && bp_is_active('activity')) {
                 $thumbnailinfo = wp_get_attachment_image_src($rtmedia_query->media[0]->media_id, 'rt_media_activity_image');
                 $activity_id = rtmedia_activity_id($rtmedia_query->media[0]->id);
                 if ($rtmedia_query->media[0]->media_id && !empty($activity_id)) {
                     global $wpdb, $bp;
                     if (!empty($bp->activity)) {
                         $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();
                         // Replacing the filename with new effected filename
                         $activity_content = str_replace($_POST['rtmedia-filepath-old'], $thumbnailinfo[0], $activity_content_new);
                         $wpdb->update($bp->activity->table_name, array('content' => $activity_content), array('id' => $activity_id));
                     }
                 }
             }
         }
         $rtmedia_query->query(false);
         global $rtmedia_points_media_id;
         $rtmedia_points_media_id = $rtmedia_query->action_query->id;
         do_action('rtmedia_after_edit_media', $rtmedia_query->action_query->id, $state);
         //refresh
         $rtMediaNav = new RTMediaNav();
         if ($rtmedia_query->media[0]->context == "group") {
             $rtMediaNav->refresh_counts($rtmedia_query->media[0]->context_id, array("context" => $rtmedia_query->media[0]->context, 'context_id' => $rtmedia_query->media[0]->context_id));
         } else {
             $rtMediaNav->refresh_counts($rtmedia_query->media[0]->media_author, array("context" => "profile", 'media_author' => $rtmedia_query->media[0]->media_author));
         }
         $state = apply_filters('rtmedia_single_edit_state', $state);
         if ($state !== false) {
             add_action("rtmedia_before_template_load", array(&$this, "media_update_success_messege"));
         } else {
             add_action("rtmedia_before_template_load", array(&$this, "media_update_success_error"));
         }
     } else {
         _e('Ooops !!! Invalid access. No nonce was found !!', 'buddypress-media');
     }
     remove_filter('intermediate_image_sizes_advanced', array($this, 'filter_image_sizes_details'));
 }
Ejemplo n.º 2
0
 function save_single_edit()
 {
     add_filter('intermediate_image_sizes_advanced', array($this, 'filter_image_sizes_details'));
     global $rtmedia_query;
     $nonce = $_POST['rtmedia_media_nonce'];
     if (wp_verify_nonce($nonce, 'rtmedia_' . $rtmedia_query->action_query->id)) {
         do_action('rtmedia_before_update_media', $rtmedia_query->action_query->id);
         $data_array = array('media_title', 'description', 'privacy');
         //for medias except album and playlist, if album_is is found, then update album_id for the media also
         if (isset($_POST['album_id']) && $_POST['album_id'] != '') {
             $data_array[] = 'album_id';
         }
         $data = rtmedia_sanitize_object($_POST, $data_array);
         $media = new RTMediaMedia();
         $image_path = get_attached_file($rtmedia_query->media[0]->media_id);
         if ($image_path && $rtmedia_query->media[0]->media_type == "photo") {
             $image_meta_data = wp_generate_attachment_metadata($rtmedia_query->media[0]->media_id, $image_path);
             wp_update_attachment_metadata($rtmedia_query->media[0]->media_id, $image_meta_data);
         }
         if (isset($_POST['rtmedia-filepath-old'])) {
             $is_valid_url = preg_match("/\\b(?:(?:https?|ftp):\\/\\/|www\\.)[-a-z0-9+&@#\\/%?=~_|!:,.;]*[-a-z0-9+&@#\\/%=~_|]/i", $_POST['rtmedia-filepath-old']);
             if ($is_valid_url) {
                 $thumbnailinfo = wp_get_attachment_image_src($rtmedia_query->media[0]->media_id, 'rt_media_activity_image');
                 $activity_id = rtmedia_activity_id($rtmedia_query->media[0]->id);
                 if ($rtmedia_query->media[0]->media_id && !empty($activity_id)) {
                     global $wpdb;
                     $content = $wpdb->get_var("SELECT content FROM {$wpdb->prefix}bp_activity WHERE id = {$activity_id}");
                     // Replacing the filename with new effected filename
                     $activity_content = str_replace($_POST['rtmedia-filepath-old'], $thumbnailinfo[0], $content);
                     $wpdb->update($wpdb->prefix . 'bp_activity', array('content' => $activity_content), array('id' => $activity_id));
                 }
             }
         }
         $state = $media->update($rtmedia_query->action_query->id, $data, $rtmedia_query->media[0]->media_id);
         $rtmedia_query->query(false);
         global $rtmedia_points_media_id;
         $rtmedia_points_media_id = $rtmedia_query->action_query->id;
         do_action('rtmedia_after_edit_media', $rtmedia_query->action_query->id, $state);
         //refresh
         $rtMediaNav = new RTMediaNav();
         if ($rtmedia_query->media[0]->context == "group") {
             $rtMediaNav->refresh_counts($rtmedia_query->media[0]->context_id, array("context" => $rtmedia_query->media[0]->context, 'context_id' => $rtmedia_query->media[0]->context_id));
         } else {
             $rtMediaNav->refresh_counts($rtmedia_query->media[0]->media_author, array("context" => "profile", 'media_author' => $rtmedia_query->media[0]->media_author));
         }
         $state = apply_filters('rtmedia_single_edit_state', $state);
         if ($state !== false) {
             add_action("rtmedia_before_template_load", array(&$this, "media_update_success_messege"));
         } else {
             add_action("rtmedia_before_template_load", array(&$this, "media_update_success_error"));
         }
     } else {
         _e('Ooops !!! Invalid access. No nonce was found !!', 'rtmedia');
     }
     remove_filter('intermediate_image_sizes_advanced', array($this, 'filter_image_sizes_details'));
 }
Ejemplo n.º 3
0
function update_activity_after_thumb_set($id)
{
    $model = new RTMediaModel();
    $mediaObj = new RTMediaMedia();
    $media = $model->get(array('id' => $id));
    $privacy = $media[0]->privacy;
    $activity_id = rtmedia_activity_id($id);
    if (!empty($activity_id)) {
        $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;
        }
        $objActivity = new RTMediaActivity($update_activity_media, $privacy, false);
        global $wpdb, $bp;
        $activity_old_content = bp_activity_get_meta($activity_id, "bp_old_activity_content");
        $activity_text = bp_activity_get_meta($activity_id, "bp_activity_text");
        if ($activity_old_content == "") {
            // get old activity content and save in activity meta
            $activity_get = bp_activity_get_specific(array('activity_ids' => $activity_id));
            $activity = $activity_get['activities'][0];
            $activity_body = $activity->content;
            bp_activity_update_meta($activity_id, "bp_old_activity_content", $activity_body);
            //extract activity text from old content
            $activity_text = strip_tags($activity_body, '<span>');
            $activity_text = explode("</span>", $activity_text);
            $activity_text = strip_tags($activity_text[0]);
            bp_activity_update_meta($activity_id, "bp_activity_text", $activity_text);
        }
        $activity_text = bp_activity_get_meta($activity_id, "bp_activity_text");
        $objActivity->activity_text = $activity_text;
        $wpdb->update($bp->activity->table_name, array("type" => "rtmedia_update", "content" => $objActivity->create_activity_html()), array("id" => $activity_id));
    }
}
Ejemplo n.º 4
0
/**
 * [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;
}