Author: joshua
Inheritance: extends RTDBModel
Exemplo n.º 1
0
 function rtm_change_activity_privacy()
 {
     $data = $_POST;
     if (wp_verify_nonce($data['nonce'], 'rtmedia_activity_privacy_nonce')) {
         $rtm_activity_model = new RTMediaActivityModel();
         $is_ac_privacy_exist = $rtm_activity_model->check($data['activity_id']);
         $privacy = intval($data['privacy']);
         $activity_id = intval($data['activity_id']);
         if (!$is_ac_privacy_exist) {
             // Very first privacy entry for this activity
             $status = $rtm_activity_model->insert(array('privacy' => $privacy, 'activity_id' => $activity_id, 'user_id' => get_current_user_id()));
         } else {
             // Just update the existing value
             $status = $rtm_activity_model->update(array('privacy' => $privacy), array('activity_id' => $activity_id));
         }
         // update privacy of corresponding media
         $media_model = new RTMediaModel();
         $activity_media = $media_model->get(array('activity_id' => $activity_id));
         if (!empty($activity_media) && is_array($activity_media)) {
             foreach ($activity_media as $single_media) {
                 $where = array('id' => $single_media->id);
                 $columns = array('privacy' => $privacy);
                 // update media privacy
                 $media_model->update($columns, $where);
             }
         }
         if ($status === false) {
             $status = 'false';
         } else {
             $status = 'true';
         }
         echo $status;
         wp_die();
     }
 }
Exemplo n.º 2
0
 function create_activity_html()
 {
     $html = '';
     $html .= '<div class="rtmedia-activity-container">';
     if (!empty($this->activity_text)) {
         $html .= '<div class="rtmedia-activity-text">';
         $html .= $this->activity_text;
         $html .= '</div>';
     }
     global $rtmedia;
     if (isset($rtmedia->options['buddypress_limitOnActivity'])) {
         $limitActivityFeed = $rtmedia->options['buddypress_limitOnActivity'];
     } else {
         $limitActivityFeed = 0;
     }
     $mediaObj = new RTMediaModel();
     $media_details = $mediaObj->get(array('id' => $this->media));
     if (intval($limitActivityFeed) > 0) {
         $media_details = array_slice($media_details, 0, $limitActivityFeed, true);
     }
     $rtmedia_activity_ul_class = apply_filters('rtmedia_activity_ul_class', 'large-block-grid-3');
     $li_content = '';
     $count = 0;
     foreach ($media_details as $media) {
         $li_content .= '<li class="rtmedia-list-item media-type-' . $media->media_type . '">';
         if ('photo' == $media->media_type) {
             $li_content .= '<a href ="' . get_rtmedia_permalink($media->id) . '">';
         }
         $li_content .= '<div class="rtmedia-item-thumbnail">';
         $li_content .= $this->media($media);
         $li_content .= '</div>';
         $li_content .= '<div class="rtmedia-item-title">';
         $li_content .= '<h4 title="' . $media->media_title . '">';
         if ('photo' != $media->media_type) {
             $li_content .= '<a href="' . get_rtmedia_permalink($media->id) . '">';
         }
         $li_content .= $media->media_title;
         if ('photo' != $media->media_type) {
             $li_content .= '</a>';
         }
         $li_content .= '</h4>';
         $li_content .= '</div>';
         if ('photo' == $media->media_type) {
             $li_content .= '</a>';
         }
         $li_content .= '<div class="rtmedia-item-actions">';
         $li_content .= $this->actions();
         $li_content .= '</div>';
         $li_content .= '</li>';
         $count++;
     }
     $html .= '<ul class="rtmedia-list ' . $rtmedia_activity_ul_class . ' rtmedia-activity-media-length-' . $count . '">';
     $html .= $li_content;
     $html .= '</ul>';
     $html .= '</div>';
     return bp_activity_filter_kses($html);
 }
 function comment_sync($comment_id, $param)
 {
     $user_id = '';
     $comment_author = '';
     extract($param);
     if (!empty($user_id)) {
         $user_data = get_userdata($user_id);
         $comment_author = $user_data->data->user_login;
     }
     $mediamodel = new RTMediaModel();
     $media = $mediamodel->get(array('activity_id' => $param['activity_id']));
     // if there is only single media in activity
     if (sizeof($media) == 1 && isset($media[0]->media_id)) {
         $media_id = $media[0]->media_id;
         $comment = new RTMediaComment();
         $id = $comment->add(array('comment_content' => $param['content'], 'comment_post_ID' => $media_id, 'user_id' => $user_id, 'comment_author' => $comment_author));
         update_comment_meta($id, 'activity_id', $comment_id);
     }
 }
Exemplo n.º 4
0
 function remove($id)
 {
     do_action('rtmedia_before_remove_comment', $id);
     $comment = '';
     if (!empty($id)) {
         $comment = get_comment($id);
     }
     if (isset($comment->comment_post_ID) && isset($comment->user_id)) {
         $model = new RTMediaModel();
         //get the current media from the comment_post_ID
         $media = $model->get(array('media_id' => $comment->comment_post_ID));
         // if user is comment creator, or media uploader or admin, allow to delete
         if (isset($media[0]->media_author) && (is_rt_admin() || intval($comment->user_id) === get_current_user_id() || intval($media[0]->media_author) === get_current_user_id())) {
             $comment_deleted = $this->rtmedia_comment_model->delete($id);
             do_action('rtmedia_after_remove_comment', $id);
             return $comment_deleted;
         }
     }
     return false;
 }
Exemplo n.º 5
0
 /**
  * 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);
     }
 }
Exemplo n.º 6
0
 function rtm_change_activity_privacy()
 {
     $nonce = filter_input(INPUT_POST, 'nonce', FILTER_SANITIZE_STRING);
     $privacy = filter_input(INPUT_POST, 'privacy', FILTER_SANITIZE_NUMBER_INT);
     $activity_id = filter_input(INPUT_POST, 'activity_id', FILTER_SANITIZE_NUMBER_INT);
     if (wp_verify_nonce($nonce, 'rtmedia_activity_privacy_nonce')) {
         $rtm_activity_model = new RTMediaActivityModel();
         $is_ac_privacy_exist = $rtm_activity_model->check($activity_id);
         $privacy = intval($privacy);
         $activity_id = intval($activity_id);
         if (!$is_ac_privacy_exist) {
             // Very first privacy entry for this activity
             $status = $rtm_activity_model->insert(array('privacy' => $privacy, 'activity_id' => $activity_id, 'user_id' => get_current_user_id()));
         } else {
             // Just update the existing value
             $status = $rtm_activity_model->update(array('privacy' => $privacy), array('activity_id' => $activity_id));
         }
         // update privacy of corresponding media
         $media_model = new RTMediaModel();
         $activity_media = $media_model->get(array('activity_id' => $activity_id));
         if (!empty($activity_media) && is_array($activity_media)) {
             foreach ($activity_media as $single_media) {
                 $where = array('id' => $single_media->id);
                 $columns = array('privacy' => $privacy);
                 // update media privacy
                 $media_model->update($columns, $where);
             }
         }
         if (false === $status) {
             $status = 'false';
         } else {
             $status = 'true';
         }
         echo esc_html($status);
         wp_die();
     }
 }
Exemplo n.º 7
0
 function refresh_counts($user_id, $where)
 {
     $model = new RTMediaModel();
     $counts = $model->get_counts($user_id, $where);
     $media_count = array();
     foreach ($counts as $count) {
         if (!isset($count->privacy)) {
             $count->privacy = 0;
         }
         if (isset($media_count[strval($count->privacy)])) {
             foreach ($media_count[strval($count->privacy)] as $key => $val) {
                 $media_count[strval($count->privacy)]->{$key} = intval($count->{$key}) + intval($val);
             }
         } else {
             $media_count[strval($count->privacy)] = $count;
         }
         unset($media_count[strval($count->privacy)]->privacy);
     }
     if (isset($where["context"])) {
         if ($where["context"] == "profile") {
             update_user_meta($user_id, 'rtmedia_counts_' . get_current_blog_id(), $media_count);
         } else {
             if ($where["context"] == "group" && function_exists("groups_update_groupmeta")) {
                 groups_update_groupmeta($user_id, 'rtmedia_counts_' . get_current_blog_id(), $media_count);
             }
         }
     }
     return $media_count;
 }
 function bp_prefetch_activity_object_data($activities)
 {
     // If activities array is empty then return
     if (empty($activities)) {
         return;
     }
     // To store activity_id
     $activity_ids = array();
     $activity_index_array = array();
     foreach ($activities as $i => $activity) {
         // Checking if activity_type is of rtmedia and component must be profile
         if ($activity->type == 'rtmedia_update' && $activity->component == 'profile') {
             // Storing activity_id
             $activity_ids[] = $activity->id;
             // Storing index of activity from activities array
             $activity_index_array[] = $i;
         }
     }
     // Checking if media is linked with any of activity
     if (!empty($activity_ids)) {
         $rtmedia_model = new RTMediaModel();
         // Where condition array to get media using activity_id from rtm_media table
         $rtmedia_media_where_array = array();
         $rtmedia_media_where_array['activity_id'] = array('compare' => 'IN', 'value' => $activity_ids);
         $rtmedia_media_query = $rtmedia_model->get($rtmedia_media_where_array);
         // Array to store media_type in simplified manner with activity_id as key
         $rtmedia_media_type_array = array();
         for ($i = 0; $i < sizeof($rtmedia_media_query); $i++) {
             // Storing media_type of uploaded media to check whether all media are of same type or different and key is activity_id
             // Making activity_id array because there might be more then 1 media linked with activity
             if (!isset($rtmedia_media_type_array[$rtmedia_media_query[$i]->activity_id]) || !is_array($rtmedia_media_type_array[$rtmedia_media_query[$i]->activity_id])) {
                 $rtmedia_media_type_array[$rtmedia_media_query[$i]->activity_id] = array();
             }
             array_push($rtmedia_media_type_array[$rtmedia_media_query[$i]->activity_id], $rtmedia_media_query[$i]->media_type);
         }
         // Updating action
         for ($a = 0; $a < sizeof($activity_ids); $a++) {
             // Getting index of activity which is being updated
             $index = $activity_index_array[$a];
             //error_log( var_export( $activities[ $index ], true ) );
             // This pattern is for getting name. User might have change display name as first name or something instead on nicename.
             $pattern = "/<a ?.*>(.*)<\\/a>/";
             preg_match($pattern, $activities[$index]->action, $matches);
             // Generating user_link with name
             $user_link = '<a href="' . $activities[$index]->primary_link . '">' . $matches[1] . '</a>';
             // Counting media linked with activity
             $count = sizeof($rtmedia_media_type_array[$activities[$index]->id]);
             // Getting constant with single label or plural label
             $media_const = 'RTMEDIA_' . strtoupper($rtmedia_media_type_array[$activities[$index]->id][0]);
             if ($count > 1) {
                 $media_const .= '_PLURAL';
             }
             $media_const .= '_LABEL';
             if (defined($media_const)) {
                 $media_str = constant($media_const);
             } else {
                 $media_str = RTMEDIA_MEDIA_SLUG;
             }
             $action = '';
             $user = get_userdata($activities[$index]->user_id);
             // Updating activity based on count
             if ($count == 1) {
                 $action = sprintf(__('%s added a %s', 'buddypress-media'), $user_link, $media_str);
             } else {
                 // Checking all the media linked with activity are of same type
                 if (isset($rtmedia_media_type_array[$activities[$index]->id]) && !empty($rtmedia_media_type_array[$activities[$index]->id]) && count(array_unique($rtmedia_media_type_array[$activities[$index]->id])) == 1) {
                     $action = sprintf(__('%s added %d %s', 'buddypress-media'), $user_link, $count, $media_str);
                 } else {
                     $action = sprintf(__('%s added %d %s', 'buddypress-media'), $user_link, $count, RTMEDIA_MEDIA_SLUG);
                 }
             }
             $action = apply_filters('rtmedia_bp_activity_action_text', $action, $user_link, $count, $user, $rtmedia_media_type_array[$activities[$index]->id][0], $activities[$index]->id);
             $activities[$index]->action = $action;
         }
     }
     return $activities;
 }
function get_rtmedia_privacy_symbol($rtmedia_id = false)
{
    $mediamodel = new RTMediaModel();
    $actions = $mediamodel->get(array('id' => rtmedia_id($rtmedia_id)));
    $privacy = "";
    if (isset($actions[0]->privacy) && $actions[0]->privacy != "") {
        $title = $icon = "";
        switch ($actions[0]->privacy) {
            case 0:
                //public
                $title = __("Public", 'rtmedia');
                $icon = 'rtmicon-globe';
                break;
            case 20:
                //users
                $title = __("All members", 'rtmedia');
                $icon = 'rtmicon-users';
                break;
            case 40:
                // friends
                $title = __("Your friends", 'rtmedia');
                $icon = 'rtmicon-users-1';
                break;
            case 60:
                // private
                $title = __("Only you", 'rtmedia');
                $icon = 'rtmicon-lock';
                break;
            case 80:
                // private
                $title = __("Blocked Temperorily", 'rtmedia');
                $icon = 'rtmicon-ban';
                break;
        }
        if ($title != "" && $icon != "") {
            $privacy = "<i class='" . $icon . "' title='" . $title . "'></i>";
        }
    }
    return $privacy;
}
Exemplo n.º 10
0
 function save_video_thumbnail($post, $attachment)
 {
     if (isset($post['rtmedia-thumbnail'])) {
         $rtmedia_model = new RTMediaModel();
         $model = new RTMediaModel();
         $media = $model->get(array('media_id' => $post['ID']));
         $media_id = $media[0]->id;
         $rtmedia_model->update(array('cover_art' => $post['rtmedia-thumbnail']), array('media_id' => $post['ID']));
         update_activity_after_thumb_set($media_id);
     }
     return $post;
 }
Exemplo n.º 11
0
<?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
Exemplo n.º 12
0
 function filter_image_sizes_details($sizes)
 {
     if (isset($_REQUEST['post_id'])) {
         $sizes = $this->unset_bp_media_image_sizes_details($sizes);
     } elseif (isset($_REQUEST['id'])) {
         //For Regenerate Thumbnails Plugin
         $model = new RTMediaModel();
         $result = $model->get(array('media_id' => intval(wp_unslash($_REQUEST['id']))));
         if (!empty($result)) {
             $bp_media_sizes = $this->image_sizes();
             $sizes = array('rt_media_thumbnail' => $bp_media_sizes['thumbnail'], 'rt_media_activity_image' => $bp_media_sizes['activity'], 'rt_media_single_image' => $bp_media_sizes['single'], 'rt_media_featured_image' => $bp_media_sizes['featured']);
         } else {
             $sizes = $this->unset_bp_media_image_sizes_details($sizes);
         }
     }
     return $sizes;
 }
Exemplo n.º 13
0
function get_rtmedia_privacy_symbol($rtmedia_id = false)
{
    $mediamodel = new RTMediaModel();
    $actions = $mediamodel->get(array('id' => rtmedia_id($rtmedia_id)));
    $privacy = "";
    if (isset($actions[0]->privacy) && $actions[0]->privacy != "") {
        $title = $icon = "";
        switch ($actions[0]->privacy) {
            case 0:
                //public
                $title = __("Public", 'rtmedia');
                $icon = 'dashicons dashicons-admin-site rtmicon';
                break;
            case 20:
                //users
                $title = __("All members", 'rtmedia');
                $icon = 'dashicons dashicons-groups rtmicon';
                break;
            case 40:
                // friends
                $title = __("Your friends", 'rtmedia');
                $icon = 'dashicons dashicons-networking rtmicon';
                break;
            case 60:
                // private
                $title = __("Only you", 'rtmedia');
                $icon = 'dashicons dashicons-lock rtmicon';
                break;
            case 80:
                // private
                $title = __("Blocked temporarily", 'rtmedia');
                $icon = 'dashicons dashicons-dismiss rtmicon';
                break;
        }
        if ($title != "" && $icon != "") {
            $privacy = "<i class='" . $icon . "' title='" . $title . "'></i>";
        }
    }
    return $privacy;
}
 /**
  * Remove activity when comment on media is deleted
  *
  * @param $comment_id
  */
 function remove_activity_after_media_comment_delete($comment_id)
 {
     if (!empty($comment_id)) {
         // get comment details from comment id
         $comment = get_comment($comment_id);
         $user_id = $comment->user_id;
         if (isset($comment->comment_post_ID) && isset($comment->user_id)) {
             $model = new RTMediaModel();
             $media_obj = $model->get(array('media_id' => $comment->comment_post_ID));
             $media_obj = $media_obj[0];
             if (!empty($media_obj)) {
                 $meta_key = 'rtm-bp-media-comment-activity-' . $media_obj->id . '-' . $comment_id;
                 // Delete activity when user remove his comment.
                 $activity_id = get_user_meta($user_id, $meta_key, true);
                 if (!empty($activity_id)) {
                     if (bp_activity_delete(array('id' => $activity_id))) {
                         delete_user_meta($user_id, $meta_key);
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 15
0
 function check_return_comments()
 {
     global $rtmedia_query;
     if ('comment' !== $rtmedia_query->action_query->action) {
         return;
     }
     if (isset($rtmedia_query->action_query->id) && count($_POST)) {
         // @codingStandardsIgnoreLine
         /**
          * /media/comments [POST]
          * Post a comment to the album by post id
          */
         $nonce = isset($_REQUEST['rtmedia_comment_nonce']) ? wp_unslash($_REQUEST['rtmedia_comment_nonce']) : '';
         $comment_content = isset($_REQUEST['comment_content']) ? sanitize_text_field(wp_unslash($_REQUEST['comment_content'])) : '';
         if (wp_verify_nonce($nonce, 'rtmedia_comment_nonce')) {
             if (empty($comment_content)) {
                 return false;
             }
             $comment = new RTMediaComment();
             $attr = $_POST;
             $media_model = new RTMediaModel();
             $result = $media_model->get(array('id' => $rtmedia_query->action_query->id));
             if (!isset($attr['comment_post_ID'])) {
                 $attr['comment_post_ID'] = $result[0]->media_id;
             }
             $id = $comment->add($attr);
             if (!is_null($result[0]->activity_id)) {
                 global $rtmedia_buddypress_activity;
                 remove_action('bp_activity_comment_posted', array($rtmedia_buddypress_activity, 'comment_sync'), 10, 2);
                 if (function_exists('bp_activity_new_comment')) {
                     $comment_activity_id = bp_activity_new_comment(array('content' => $comment_content, 'activity_id' => $result[0]->activity_id));
                     do_action('rtm_bp_activity_comment_posted', $comment_activity_id, $result[0]);
                 }
             }
             if (!empty($comment_activity_id)) {
                 $rtmedia_activity_comment = rtmedia_activity_comment($comment_activity_id);
                 if ($rtmedia_activity_comment['content']) {
                     update_comment_meta($id, 'activity_comment_content', $rtmedia_activity_comment['content']);
                 }
                 update_comment_meta($id, 'activity_id', $comment_activity_id);
             }
             $_rt_ajax = filter_input(INPUT_POST, 'rtajax', FILTER_SANITIZE_STRING);
             if (!empty($_rt_ajax)) {
                 global $wpdb;
                 $comments = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->comments} WHERE comment_ID = %d limit 100", $id), ARRAY_A);
                 echo rmedia_single_comment($comments);
                 // @codingStandardsIgnoreLine
                 exit;
             }
         } else {
             esc_html_e('Ooops !!! Invalid access. No nonce was found !!', 'buddypress-media');
         }
     }
 }
Exemplo n.º 16
0
 function rtmedia_api_process_rtmedia_get_media_details_request()
 {
     $this->rtmediajsonapifunction->rtmedia_api_verfiy_token();
     $this->rtmediajsonapifunction->rtmedia_api_media_activity_id_missing();
     //Errors
     $ec_single_media = 150002;
     $msg_single_media = esc_html__('single media', 'buddypress-media');
     $media_id = filter_input(INPUT_POST, 'media_id', FILTER_SANITIZE_NUMBER_INT);
     $id = rtmedia_media_id($media_id);
     if (empty($id)) {
         wp_send_json($this->rtmedia_api_response_object('TRUE', $this->ec_invalid_media_id, $this->msg_invalid_media_id));
     }
     if (class_exists('RTMediaModel')) {
         $rtmediamodel = new RTMediaModel();
         $args = array('media_id' => $id, 'id' => $media_id);
         $media = $rtmediamodel->get($args);
     }
     $activity_id = !empty($media) ? $media[0]->activity_id : '';
     if (empty($activity_id)) {
         wp_send_json($this->rtmedia_api_response_object('FALSE', $this->ec_invalid_media_id, $this->msg_invalid_media_id));
     }
     $media_single = $this->rtmediajsonapifunction->rtmedia_api_get_feed(false, $activity_id);
     if ($media_single) {
         wp_send_json($this->rtmedia_api_response_object('TRUE', $ec_single_media, $msg_single_media, $media_single));
     }
 }
Exemplo n.º 17
0
/**
 * @param $album_id
 *
 * @return array
 */
function rtm_get_album_media_count($album_id)
{
    global $rtmedia_query;
    $args = array();
    if (isset($album_id) && $album_id) {
        $args['album_id'] = $album_id;
    }
    if (isset($rtmedia_query->query['context']) && $rtmedia_query->query['context']) {
        $args['context'] = $rtmedia_query->query['context'];
    }
    if (isset($rtmedia_query->query['context_id']) && $rtmedia_query->query['context_id']) {
        $args['context_id'] = $rtmedia_query->query['context_id'];
    }
    $rtmedia_model = new RTMediaModel();
    if ($args) {
        $count = $rtmedia_model->get($args, false, false, 'media_id desc', true);
    }
    return $count;
}
Exemplo n.º 18
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;
}
    /**
     *
     * 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;
    }
Exemplo n.º 20
0
    /**
     *
     * 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;
    }
Exemplo n.º 21
0
 function rtmedia_wpseo_og_image($data)
 {
     global $wp_query;
     if (class_exists("BuddyPress")) {
         global $bp;
         if (bp_is_single_activity()) {
             $mediaObj = new RTMediaModel();
             $media_details = $mediaObj->get(array('activity_id' => $bp->current_action));
             foreach ($media_details as $media) {
                 if ($media->media_type == 'photo') {
                     $img = wp_get_attachment_image_src($media->media_id, "full");
                     if ($img && isset($img[0]) && $img[0] != "") {
                         echo "<meta property='og:image' content='" . esc_url($img[0]) . "' />\n";
                     }
                 }
             }
         }
     }
     if (array_key_exists('media', $wp_query->query_vars)) {
         global $rtmedia_query;
         if (isset($rtmedia_query->media) && $rtmedia_query->media && count($rtmedia_query->media) > 0) {
             foreach ($rtmedia_query->media as $media) {
                 $img = wp_get_attachment_image_src($media->media_id, "full");
                 if ($img && isset($img[0]) && $img[0] != "") {
                     echo "<meta property='og:image' content='" . esc_url($img[0]) . "' />\n";
                 }
             }
         }
     }
     return $data;
 }
 function rtmedia_api_album_media($album_id)
 {
     if (empty($album_id)) {
         return false;
     }
     $rtmediamodel = new RTMediaModel();
     $args = array('album_id' => $album_id);
     $media_list = $rtmediamodel->get($args);
     $media_data = array();
     if (!empty($media_list) && is_array($media_list)) {
         foreach ($media_list as $media) {
             $media_data[] = array('id' => $media->id, 'media_title' => $media->media_title, 'media_url' => get_rtmedia_permalink($media->media_id), 'media_author' => $media->media_author, 'cover' => rtmedia_image('rt_media_thumbnail', $media->media_id, FALSE));
         }
     }
     return $media_data;
 }
Exemplo n.º 23
0
 function importmedia($id, $prefix)
 {
     $delete = false;
     $attached_file = get_attached_file($id);
     $attached_file_option = get_post_meta($id, '_wp_attached_file', true);
     $basename = wp_basename($attached_file);
     $file_folder_path = trailingslashit(str_replace($basename, '', $attached_file));
     $siteurl = get_option('siteurl');
     $upload_path = trim(get_option('upload_path'));
     if (empty($upload_path) || 'wp-content/uploads' == $upload_path) {
         $dir = WP_CONTENT_DIR . '/uploads';
     } elseif (0 !== strpos($upload_path, ABSPATH)) {
         // $dir is absolute, $upload_path is (maybe) relative to ABSPATH
         $dir = path_join(ABSPATH, $upload_path);
     } else {
         $dir = $upload_path;
     }
     if (!($url = get_option('upload_url_path'))) {
         if (empty($upload_path) || 'wp-content/uploads' == $upload_path || $upload_path == $dir) {
             $url = WP_CONTENT_URL . '/uploads';
         } else {
             $url = trailingslashit($siteurl) . $upload_path;
         }
     }
     // Obey the value of UPLOADS. This happens as long as ms-files rewriting is disabled.
     // We also sometimes obey UPLOADS when rewriting is enabled -- see the next block.
     if (defined('UPLOADS') && !(is_multisite() && rtmedia_get_site_option('ms_files_rewriting'))) {
         $dir = ABSPATH . UPLOADS;
         $url = trailingslashit($siteurl) . UPLOADS;
     }
     // If multisite (and if not the main site in a post-MU network)
     if (is_multisite() && !(is_main_site() && defined('MULTISITE'))) {
         if (!rtmedia_get_site_option('ms_files_rewriting')) {
             // If ms-files rewriting is disabled (networks created post-3.5), it is fairly straightforward:
             // Append sites/%d if we're not on the main site (for post-MU networks). (The extra directory
             // prevents a four-digit ID from conflicting with a year-based directory for the main site.
             // But if a MU-era network has disabled ms-files rewriting manually, they don't need the extra
             // directory, as they never had wp-content/uploads for the main site.)
             if (defined('MULTISITE')) {
                 $ms_dir = '/sites/' . get_current_blog_id();
             } else {
                 $ms_dir = '/' . get_current_blog_id();
             }
             $dir .= $ms_dir;
             $url .= $ms_dir;
         } elseif (defined('UPLOADS') && !ms_is_switched()) {
             // Handle the old-form ms-files.php rewriting if the network still has that enabled.
             // When ms-files rewriting is enabled, then we only listen to UPLOADS when:
             //   1) we are not on the main site in a post-MU network,
             //      as wp-content/uploads is used there, and
             //   2) we are not switched, as ms_upload_constants() hardcodes
             //      these constants to reflect the original blog ID.
             //
             // Rather than UPLOADS, we actually use BLOGUPLOADDIR if it is set, as it is absolute.
             // (And it will be set, see ms_upload_constants().) Otherwise, UPLOADS can be used, as
             // as it is relative to ABSPATH. For the final piece: when UPLOADS is used with ms-files
             // rewriting in multisite, the resulting URL is /files. (#WP22702 for background.)
             if (defined('BLOGUPLOADDIR')) {
                 $dir = untrailingslashit(BLOGUPLOADDIR);
             } else {
                 $dir = ABSPATH . UPLOADS;
             }
             $url = trailingslashit($siteurl) . 'files';
         }
     }
     $basedir = trailingslashit($dir);
     $baseurl = trailingslashit($url);
     $new_file_folder_path = trailingslashit(str_replace($basedir, $basedir . "rtMedia/{$prefix}/", $file_folder_path));
     $year_month = untrailingslashit(str_replace($basedir, '', $file_folder_path));
     $metadata = wp_get_attachment_metadata($id);
     $backup_metadata = get_post_meta($id, '_wp_attachment_backup_sizes', true);
     $instagram_thumbs = get_post_meta($id, '_instagram_thumbs', true);
     $instagram_full_images = get_post_meta($id, '_instagram_full_images', true);
     $instagram_metadata = get_post_meta($id, '_instagram_metadata', true);
     $encoding_job_id = get_post_meta($id, 'bp-media-encoding-job-id', true);
     $ffmpeg_thumbnail_ids = get_post_meta($id, 'bp_media_thumbnail_ids', true);
     $ffmpeg_thumbnail = get_post_meta($id, 'bp_media_thumbnail', true);
     $ffmpeg_remote_id = get_post_meta($id, 'bp_media_ffmpeg_remote_id', true);
     $kaltura_remote_id = get_post_meta($id, 'bp_media_kaltura_remote_id', true);
     if (wp_mkdir_p($basedir . "rtMedia/{$prefix}/" . $year_month)) {
         if (copy($attached_file, str_replace($basedir, $basedir . "rtMedia/{$prefix}/", $attached_file))) {
             $delete = true;
             if (isset($metadata['sizes'])) {
                 foreach ($metadata['sizes'] as $size) {
                     if (!copy($file_folder_path . $size['file'], $new_file_folder_path . $size['file'])) {
                         $delete = false;
                     } else {
                         $delete_sizes[] = $file_folder_path . $size['file'];
                         $this->search_and_replace(trailingslashit($baseurl . $year_month) . $size['file'], trailingslashit($baseurl . "rtMedia/{$prefix}/" . $year_month) . $size['file']);
                     }
                 }
             }
             if ($backup_metadata) {
                 foreach ($backup_metadata as $backup_images) {
                     if (!copy($file_folder_path . $backup_images['file'], $new_file_folder_path . $backup_images['file'])) {
                         $delete = false;
                     } else {
                         $delete_sizes[] = $file_folder_path . $backup_images['file'];
                         $this->search_and_replace(trailingslashit($baseurl . $year_month) . $backup_images['file'], trailingslashit($baseurl . "rtMedia/{$prefix}/" . $year_month) . $backup_images['file']);
                     }
                 }
             }
             if ($instagram_thumbs) {
                 foreach ($instagram_thumbs as $key => $insta_thumb) {
                     try {
                         if (!copy(str_replace($baseurl, $basedir, $insta_thumb), str_replace($baseurl, $basedir . "rtMedia/{$prefix}/", $insta_thumb))) {
                             $delete = false;
                         } else {
                             $delete_sizes[] = str_replace($baseurl, $basedir, $insta_thumb);
                             $instagram_thumbs_new[$key] = str_replace($baseurl, $baseurl . "rtMedia/{$prefix}/", $insta_thumb);
                             $this->search_and_replace(trailingslashit($baseurl . $year_month) . $insta_thumb, trailingslashit($baseurl . "rtMedia/{$prefix}/" . $year_month) . $insta_thumb);
                         }
                     } catch (Exceptio $e) {
                         $delete = false;
                     }
                 }
             }
             if ($instagram_full_images) {
                 foreach ($instagram_full_images as $key => $insta_full_image) {
                     if (!copy($insta_full_image, str_replace($basedir, $basedir . "rtMedia/{$prefix}/", $insta_full_image))) {
                         $delete = false;
                     } else {
                         $delete_sizes[] = $insta_full_image;
                         $instagram_full_images_new[$key] = str_replace($basedir, $basedir . "rtMedia/{$prefix}", $insta_full_image);
                         $this->search_and_replace(trailingslashit($baseurl . $year_month) . $insta_full_image, trailingslashit($baseurl . "rtMedia/{$prefix}/" . $year_month) . $insta_full_image);
                     }
                 }
             }
             if ($instagram_metadata) {
                 $instagram_metadata_new = $instagram_metadata;
                 foreach ($instagram_metadata as $wp_size => $insta_metadata) {
                     if (isset($insta_metadata['file'])) {
                         if (!copy($basedir . $insta_metadata['file'], $basedir . "rtMedia/{$prefix}/" . $insta_metadata['file'])) {
                             $delete = false;
                         } else {
                             $delete_sizes[] = $basedir . $insta_metadata['file'];
                             $instagram_metadata_new[$wp_size]['file'] = "rtMedia/{$prefix}/" . $insta_metadata['file'];
                             if (isset($insta_metadata['sizes'])) {
                                 foreach ($insta_metadata['sizes'] as $key => $insta_size) {
                                     if (!copy($file_folder_path . $insta_size['file'], $new_file_folder_path . $insta_size['file'])) {
                                         $delete = false;
                                     } else {
                                         $delete_sizes[] = $file_folder_path . $insta_size['file'];
                                         $this->search_and_replace(trailingslashit($baseurl . $year_month) . $insta_size['file'], trailingslashit($baseurl . "rtMedia/{$prefix}/" . $year_month) . $insta_size['file']);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             if ($delete) {
                 if (file_exists($attached_file)) {
                     unlink($attached_file);
                 }
                 if (isset($delete_sizes)) {
                     foreach ($delete_sizes as $delete_size) {
                         if (file_exists($delete_size)) {
                             unlink($delete_size);
                         }
                     }
                 }
                 update_post_meta($id, '_wp_attached_file', "rtMedia/{$prefix}/" . $attached_file_option);
                 if (isset($metadata['file'])) {
                     $metadata['file'] = "rtMedia/{$prefix}/" . $metadata['file'];
                     wp_update_attachment_metadata($id, $metadata);
                 }
                 if ($instagram_thumbs) {
                     update_rtmedia_meta($id, '_instagram_thumbs', $instagram_thumbs_new);
                 }
                 if ($instagram_full_images) {
                     update_rtmedia_meta($id, '_instagram_full_images', $instagram_full_images_new);
                 }
                 if ($instagram_metadata) {
                     update_rtmedia_meta($id, '_instagram_metadata', $instagram_metadata_new);
                 }
                 if ($encoding_job_id) {
                     update_rtmedia_meta($id, 'rtmedia-encoding-job-id', $encoding_job_id);
                 }
                 if ($ffmpeg_thumbnail_ids) {
                     update_rtmedia_meta($id, 'rtmedia-thumbnail-ids', $ffmpeg_thumbnail_ids);
                 }
                 if ($ffmpeg_thumbnail) {
                     $model = new RTMediaModel();
                     $model->update(array('cover_art' => $ffmpeg_thumbnail), array('id' => $id));
                 }
                 if ($ffmpeg_remote_id) {
                     update_rtmedia_meta($id, 'rtmedia-ffmpeg-remote-id', $ffmpeg_remote_id);
                 }
                 if ($kaltura_remote_id) {
                     update_rtmedia_meta($id, 'rtmedia-kaltura-remote-id', $kaltura_remote_id);
                 }
                 $attachment = array();
                 $attachment['ID'] = $id;
                 $old_guid = get_post_field('guid', $id);
                 $attachment['guid'] = str_replace($baseurl, $baseurl . "rtMedia/{$prefix}/", $old_guid);
                 /**
                  * For Activity
                  */
                 global $last_baseurl, $last_newurl;
                 $last_baseurl = $baseurl;
                 $last_newurl = $baseurl . "rtMedia/{$prefix}/";
                 $this->search_and_replace($old_guid, $attachment['guid']);
                 wp_update_post($attachment);
             }
         }
     }
 }
Exemplo n.º 24
0
 /**
  *
  * @param type $uploaded
  * @param type $file_object
  *
  * @return type
  */
 function generate_post_array($uploaded, $file_object)
 {
     if ($uploaded['album_id']) {
         $model = new RTMediaModel();
         $parent_details = $model->get(array('id' => $uploaded['album_id']));
         if (is_array($parent_details) && count($parent_details) > 0) {
             $album_id = $parent_details[0]->media_id;
         } else {
             $album_id = 0;
         }
     } else {
         $album_id = 0;
     }
     if (!in_array($uploaded['context'], array('profile', 'group'), true)) {
         $album_id = $uploaded['context_id'];
     }
     $attachments = array();
     foreach ($file_object as $index => $file) {
         $uploaded['title'] = wp_kses($uploaded['title'], wp_kses_allowed_html());
         // filter description for allowed html tags
         $uploaded['description'] = wp_kses($uploaded['description'], wp_kses_allowed_html());
         $attachments[$index] = array('post_mime_type' => $file['type'], 'guid' => esc_url_raw($file['url']), 'post_title' => sanitize_text_field($uploaded['title'] ? $uploaded['title'] : preg_replace('/\\.[^.\\s]{3,4}$/', '', $file['name'])), 'post_content' => $uploaded['description'] ? $uploaded['description'] : '', 'post_parent' => intval($album_id), 'post_author' => intval($uploaded['media_author']));
         if (!empty($uploaded['date'])) {
             $attachments[$index]['post_date'] = $uploaded['date'];
         }
     }
     return $attachments;
 }
Exemplo n.º 25
0
 function check_return_comments()
 {
     global $rtmedia_query;
     if ($rtmedia_query->action_query->action != 'comment') {
         return;
     }
     if (isset($rtmedia_query->action_query->id) && count($_POST)) {
         /**
          * /media/comments [POST]
          * Post a comment to the album by post id
          */
         $nonce = $_REQUEST['rtmedia_comment_nonce'];
         if (wp_verify_nonce($nonce, 'rtmedia_comment_nonce')) {
             if (empty($_POST['comment_content'])) {
                 return false;
             }
             $comment = new RTMediaComment();
             $attr = $_POST;
             $mediaModel = new RTMediaModel();
             $result = $mediaModel->get(array('id' => $rtmedia_query->action_query->id));
             if (!isset($attr['comment_post_ID'])) {
                 $attr['comment_post_ID'] = $result[0]->media_id;
             }
             $id = $comment->add($attr);
             if ($result[0]->activity_id != null) {
                 global $rtmedia_buddypress_activity;
                 remove_action("bp_activity_comment_posted", array($rtmedia_buddypress_activity, "comment_sync"), 10, 2);
                 if (function_exists('bp_activity_new_comment')) {
                     $comment_activity_id = bp_activity_new_comment(array('content' => $_POST['comment_content'], 'activity_id' => $result[0]->activity_id));
                 }
             }
             if (!empty($comment_activity_id)) {
                 update_comment_meta($id, 'activity_id', $comment_activity_id);
             }
             if (isset($_POST["rtajax"])) {
                 global $wpdb;
                 $comments = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->comments} WHERE comment_ID = %d", $id), ARRAY_A);
                 echo rmedia_single_comment($comments);
                 exit;
             }
         } else {
             _e('Ooops !!! Invalid access. No nonce was found !!', 'buddypress-media');
         }
     }
 }
Exemplo n.º 26
0
 /**
  *
  * @param type $uploaded
  * @param type $file_object
  *
  * @return type
  */
 function generate_post_array($uploaded, $file_object)
 {
     if ($uploaded['album_id']) {
         $model = new RTMediaModel();
         $parent_details = $model->get(array('id' => $uploaded['album_id']));
         if (is_array($parent_details) && sizeof($parent_details) > 0) {
             $album_id = $parent_details[0]->media_id;
         } else {
             $album_id = 0;
         }
     } else {
         $album_id = 0;
     }
     if (!in_array($uploaded["context"], array("profile", "group"))) {
         $album_id = $uploaded["context_id"];
     }
     $attachments = array();
     foreach ($file_object as $index => $file) {
         $uploaded['title'] = wp_kses($uploaded['title'], wp_kses_allowed_html());
         $uploaded['description'] = sanitize_text_field($uploaded['description']);
         $attachments[$index] = array('post_mime_type' => $file['type'], 'guid' => $file['url'], 'post_title' => $uploaded['title'] ? $uploaded['title'] : preg_replace("/\\.[^.\\s]{3,4}\$/", "", $file['name']), 'post_content' => $uploaded['description'] ? $uploaded['description'] : '', 'post_parent' => $album_id, 'post_author' => $uploaded['media_author']);
         if (!empty($uploaded['date'])) {
             $attachments[$index]['post_date'] = $uploaded['date'];
         }
     }
     return $attachments;
 }
Exemplo n.º 27
0
 public function reencoding($attachment, $autoformat = true)
 {
     $rtmedia_model = new RTMediaModel();
     $media_array = $rtmedia_model->get(array("media_id" => $attachment));
     $media_id = $media_array[0]->id;
     $attached_file = get_post_meta($attachment, '_wp_attached_file');
     $upload_path = trim(get_option('upload_path'));
     if (empty($upload_path) || 'wp-content/uploads' == $upload_path) {
         $dir = WP_CONTENT_DIR . '/uploads';
     } elseif (0 !== strpos($upload_path, ABSPATH)) {
         // $dir is absolute, $upload_path is (maybe) relative to ABSPATH
         $dir = path_join(ABSPATH, $upload_path);
     } else {
         $dir = $upload_path;
     }
     $file = trailingslashit($dir) . $attached_file[0];
     $url = wp_get_attachment_url($attachment);
     $file_name_array = explode("/", $url);
     $file_name = $file_name_array[sizeof($file_name_array) - 1];
     $file_object = array();
     $media_type = get_post_field('post_mime_type', $attachment);
     $media_type_array = explode("/", $media_type);
     if ($media_type_array[0] == "video") {
         $file_object[] = array("file" => $file, "url" => $url, "name" => $file_name, "type" => $media_type);
         $this->encoding(array($media_id), $file_object, array(), $autoformat);
     }
 }
Exemplo n.º 28
0
/**
 * Get the media privacy symbol
 *
 * @param       bool|int    $rtmedia_id
 *
 * @return      string
 */
function get_rtmedia_privacy_symbol($rtmedia_id = false)
{
    $mediamodel = new RTMediaModel();
    $actions = $mediamodel->get(array('id' => rtmedia_id($rtmedia_id)));
    $privacy = '';
    if (intval($actions[0]->privacy) >= 0) {
        $title = $icon = '';
        switch ($actions[0]->privacy) {
            case 0:
                // public
                $title = esc_html__('Public', 'buddypress-media');
                $icon = 'dashicons dashicons-admin-site rtmicon';
                break;
            case 20:
                // users
                $title = esc_html__('All members', 'buddypress-media');
                $icon = 'dashicons dashicons-groups rtmicon';
                break;
            case 40:
                // friends
                $title = esc_html__('Your friends', 'buddypress-media');
                $icon = 'dashicons dashicons-networking rtmicon';
                break;
            case 60:
                // private
                $title = esc_html__('Only you', 'buddypress-media');
                $icon = 'dashicons dashicons-lock rtmicon';
                break;
            case 80:
                // private
                $title = esc_html__('Blocked temporarily', 'buddypress-media');
                $icon = 'dashicons dashicons-dismiss rtmicon';
                break;
        }
        if (!empty($title) && !empty($icon)) {
            $privacy = "<i class='" . esc_attr($icon) . "' title='" . esc_attr($title) . "'></i>";
        }
    }
    return $privacy;
}
 function migrate_single_media($result)
 {
     global $wpdb;
     $rtmedia_model = new RTMediaModel();
     $attached_file = get_attached_file($result->media_id);
     $return = true;
     if (file_exists($attached_file)) {
         $file_size = filesize($attached_file);
     } else {
         $file_size = '0';
         error_log('rtMedia size importer: file not exist. Media ID: ' . $result->id . ', File: ' . $attached_file);
         $return = false;
         return false;
     }
     $post = get_post($result->media_id);
     $post_date = $post->post_date;
     $rtmedia_model->update(array('upload_date' => $post_date, 'file_size' => $file_size), array('id' => $result->id));
     return $return;
 }
Exemplo n.º 30
0
 function rtmedia_api_process_rtmedia_get_media_details_request()
 {
     $this->rtmediajsonapifunction->rtmedia_api_verfiy_token();
     $this->rtmediajsonapifunction->rtmedia_api_media_activity_id_missing();
     //Errors
     $ec_single_media = 150002;
     $msg_single_media = __('single media', 'rtmedia');
     extract($_REQUEST);
     $id = rtmedia_media_id($media_id);
     if (empty($id)) {
         echo $this->rtmedia_api_response_object('TRUE', $this->ec_invalid_media_id, $this->msg_invalid_media_id);
         exit;
     }
     if (class_exists('RTMediaModel')) {
         $rtmediamodel = new RTMediaModel();
         $args = array('media_id' => $id, 'id' => $media_id);
         $media = $rtmediamodel->get($args);
     }
     $activity_id = !empty($media) ? $media[0]->activity_id : '';
     if (empty($activity_id)) {
         echo $this->rtmedia_api_response_object('FALSE', $this->ec_invalid_media_id, $this->msg_invalid_media_id);
         exit;
     }
     $media_single = $this->rtmediajsonapifunction->rtmedia_api_get_feed(FALSE, $activity_id);
     if ($media_single) {
         echo $this->rtmedia_api_response_object('TRUE', $ec_single_media, $msg_single_media, $media_single);
         exit;
     }
 }