/** * Format string and media url for notification * * @param array $params array ('action', 'post_id', 'initiator_id', 'total_items', 'format' ) * * @return string/array format notification as $params['format'] request */ function format_like_notifications($params) { $action = $params['action']; $post_id = intval($params['post_id']); if ($this->component_action . $post_id === $action) { $initiator_id = $params['initiator_id']; $total_items = $params['total_items']; $format = $params['format']; $rtmedia_id = rtmedia_id($post_id); $liked_list = $this->fetch_media_like_stats($rtmedia_id); $liked_by = bp_core_get_username($liked_list[0]->user_id); $like_count = get_rtmedia_like($post_id); $link = esc_url(get_rtmedia_permalink($rtmedia_id)); $media_type = rtmedia_type($rtmedia_id); $text = null; if (0 === intval($like_count)) { $this->delete_notification_by_item_id($initiator_id, $post_id); } elseif (1 === intval($like_count)) { $text = $liked_by . ' ' . __('liked your', 'buddypress-media') . ' ' . $media_type; } elseif (2 === intval($like_count)) { $text = $liked_by . ' ' . __('and one more friend liked your', 'buddypress-media') . ' ' . $media_type; } else { $count = $like_count - 1; $text = $liked_by . ' ' . __('and', 'buddypress-media') . ' ' . $count . ' ' . __('other friends liked your', 'buddypress-media') . ' ' . $media_type; } $return = apply_filters('rtmedia_before_like_notification', array('link' => $link, 'text' => $text), (int) $total_items); if ('string' === $format) { return '<a href="' . esc_url($return['link']) . '">' . esc_html($return['text']) . '</a>'; } else { return $return; } } }
/** * format the new notification in String or array * @param array $params * @return array/string As per $format */ function format_comment_notifications($params) { $action = $params['action']; $post_id = $params['post_id']; if ($this->component_action . $post_id == $action) { $initiator_id = $params['initiator_id']; $total_items = $params['total_items']; $format = $params['format']; $comment_author = bp_core_get_username($initiator_id); $media_url = get_rtmedia_permalink(rtmedia_id($post_id)); $media_type = rtmedia_type(rtmedia_id($post_id)); if ($total_items == 1) { $text = $comment_author . ' ' . __('commented on your', 'buddypress-media') . ' ' . $media_type; } else { $text = $total_items . ' ' . __('new comments on your', 'buddypress-media') . ' ' . $media_type; } $link = $media_url; if ($format == 'string') { $return = apply_filters('rtmedia_before_comment_notification', '<a href="' . $link . '">' . $text . '</a>', (int) $total_items); } else { $return = apply_filters('rtmedia_before_comment_notification', array('link' => $link, 'text' => $text), (int) $total_items); } return $return; } }
/** * Format string and media url for notification * * @param array $params array ('action', 'post_id', 'initiator_id', 'total_items', 'format' ) * @return string/array format notification as $params['format'] request */ function format_like_notifications($params) { $action = $params['action']; $post_id = $params['post_id']; if ($this->component_action . $post_id == $action) { $initiator_id = $params['initiator_id']; $total_items = $params['total_items']; $format = $params['format']; $liked_list = $this->fetch_media_like_stats(rtmedia_id($post_id)); $liked_by = bp_core_get_username($liked_list[0]->user_id); $like_count = get_rtmedia_like($post_id); $link = get_rtmedia_permalink(rtmedia_id($post_id)); $media_type = rtmedia_type(rtmedia_id($post_id)); if ($like_count == 0) { $this->delete_notification_by_item_id($initiator_id, $post_id); } elseif ($like_count == 1) { $text = $liked_by . ' ' . __('liked your', 'rtmedia') . ' ' . $media_type; } elseif ($like_count == 2) { $text = $liked_by . ' ' . __('and one more friend liked your', 'rtmedia') . ' ' . $media_type; } else { $count = $like_count - 1; $text = $liked_by . ' ' . __('and', 'rtmedia') . ' ' . $count . ' ' . __('other friends liked your', 'rtmedia') . ' ' . $media_type; } if ($format == 'string') { $return = apply_filters('rtmedia_before_like_notification', '<a href="' . $link . '">' . $text . '</a>', (int) $total_items); } else { $return = apply_filters('rtmedia_before_like_notification', array('link' => $link, 'text' => $text), (int) $total_items); } return $return; } }
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 render() { /** * We were using session to store view count for a media by a particular user. * Session will no more use in rtmedia. * * All Media View reports will be genrated using rtmedia_interaction table only */ $link = trailingslashit(get_rtmedia_permalink($this->media->id)) . $this->action . '/'; echo '<form action="' . esc_url($link) . '" id="rtmedia-media-view-form"></form>'; do_action('rtmedia_view_media_counts', $this); }
function render() { if (isset($_SESSION['rtmedia_media_view']) && $_SESSION['rtmedia_media_view'] != "" && sizeof($_SESSION['rtmedia_media_view'] > 0)) { $key = array_search($this->media->id, $_SESSION['rtmedia_media_view']); if (!$key) { $_SESSION['rtmedia_media_view'][] = $this->media->id; $this->rtmedia_update_view_meta($this->media->id, $this->action); } } else { $_SESSION['rtmedia_media_view'] = array(); $_SESSION['rtmedia_media_view'][] = "do not consider 0 index in php"; $_SESSION['rtmedia_media_view'][] = $this->media->id; $this->rtmedia_update_view_meta($this->media->id, $this->action); } $link = trailingslashit(get_rtmedia_permalink($this->media->id)) . $this->action . '/'; //echo '<div style="clear:both"></div><form action="'. $link .'" id="rtmedia-media-view-form"></form>'; echo '<form action="' . $link . '" id="rtmedia-media-view-form"></form>'; do_action("rtmedia_view_media_counts", $this); }
function rtmedia_api_process_rtmedia_gallery_request() { $this->rtmediajsonapifunction->rtmedia_api_verfiy_token(); //Errors $ec_media = 160002; $msg_media = __('media list', 'rtmedia'); $ec_no_media = 160003; $msg_no_media = __('no media found for requested media type', 'rtmedia'); $ec_invalid_media_type = 160004; $msg_invalid_media_type = __('media_type not allowed', 'rtmedia'); global $rtmedia; $rtmediamodel = new RTMediaModel(); //Media type to fetch $media_type = $allowed_types = array_keys($rtmedia->allowed_types); $media_type[] = 'album'; $allowed_types[] = 'album'; if (!empty($_REQUEST['media_type'])) { if (!is_array($_REQUEST['media_type'])) { $media_type = explode(',', $_REQUEST['media_type']); } else { $media_type = $_REQUEST['media_type']; } //Check array for currently allowed media types $media_type = array_intersect($media_type, $allowed_types); } //Args for fetching media $args = array('media_type' => $media_type); //global if (isset($_REQUEST['global'])) { if ($_REQUEST['global'] == 'false') { $args['context'] = array('compare' => 'IS NOT', 'value' => 'NULL'); } } //context if (isset($_REQUEST['context'])) { $args['context'] = $_REQUEST['context']; } //context Id if (isset($_POST['context_id'])) { $args['context_id'] = $_REQUEST['context_id']; } //Media Author $media_author = ''; if (!is_super_admin()) { $media_author = $this->user_id; $args['media_author'] = $media_author; } if (!empty($_REQUEST['media_author'])) { if (is_super_admin($this->user_id)) { $media_author = (int) $_REQUEST['media_author']; $args['media_author'] = $media_author; } } $offset = !empty($_REQUEST['page']) ? (int) $_REQUEST['page'] : 0; $per_page = isset($_REQUEST['per_page']) ? (int) $_REQUEST['per_page'] : 10; $order_by = !empty($_REQUEST['order_by']) ? $_REQUEST['order_by'] : 'media_id desc'; $media_list = $rtmediamodel->get($args, $offset, $per_page, $order_by); $media_result = array(); foreach ($media_list as $media) { $data = array('id' => $media->id, 'media_title' => $media->media_title, 'album_id' => $media->album_id, 'media_type' => $media->media_type, 'media_author' => $media->media_author, 'url' => get_rtmedia_permalink($media->id), 'cover' => rtmedia_image('rt_media_thumbnail', $media->media_id, FALSE)); //for album list all medias if ($media->media_type == 'album') { $data['media'] = $this->rtmediajsonapifunction->rtmedia_api_album_media($media->id); } $media_result[] = $data; } if (!empty($media_result)) { echo $this->rtmedia_api_response_object("TRUE", $ec_media, $msg_media, $media_result); } else { echo $this->rtmedia_api_response_object("FALSE", $ec_no_media, $msg_no_media); } }
function template_redirect($create_activity = true) { ob_start(); if (!count($_POST)) { // @codingStandardsIgnoreLine include get_404_template(); } else { $nonce = $mode = ''; $_activity_id = -1; if (isset($_REQUEST['rtmedia_upload_nonce'])) { $nonce = sanitize_text_field(wp_unslash($_REQUEST['rtmedia_upload_nonce'])); } if (isset($_REQUEST['mode'])) { $mode = sanitize_text_field(wp_unslash($_REQUEST['mode'])); } if (isset($_REQUEST['activity_id'])) { $_activity_id = sanitize_text_field($_REQUEST['activity_id']); } $_redirect_url = filter_input(INPUT_POST, 'redirect', FILTER_SANITIZE_NUMBER_INT); $rtupload = false; $activity_id = -1; $redirect_url = ''; if (wp_verify_nonce($nonce, 'rtmedia_upload_nonce')) { $model = new RTMediaUploadModel(); do_action('rtmedia_upload_set_post_object'); $this->upload = $model->set_post_object(); if (-1 !== $_activity_id) { $this->upload['activity_id'] = $_activity_id; $activity_id = $_activity_id; } //if media upload is being made for a group, identify the group privacy and set media privacy accordingly if (isset($this->upload['context']) && isset($this->upload['context_id']) && 'group' === $this->upload['context'] && function_exists('groups_get_group')) { $group = groups_get_group(array('group_id' => $this->upload['context_id'])); if (isset($group->status) && 'public' !== $group->status) { // if group is not public, then set media privacy as 20, so only the group members can see the images $this->upload['privacy'] = '20'; } else { // if group is public, then set media privacy as 0 $this->upload['privacy'] = '0'; } } $this->upload = apply_filters('rtmedia_media_param_before_upload', $this->upload); $rtupload = new RTMediaUpload($this->upload); $media_obj = new RTMediaMedia(); $media = $media_obj->model->get(array('id' => $rtupload->media_ids[0])); $rtmedia_nav = new RTMediaNav(); $perma_link = ''; if (isset($media) && count($media) > 0) { $perma_link = get_rtmedia_permalink($media[0]->id); if ('photo' === $media[0]->media_type) { $thumb_image = rtmedia_image('rt_media_thumbnail', $rtupload->media_ids[0], false); } elseif ('music' === $media[0]->media_type) { $thumb_image = $media[0]->cover_art; } else { $thumb_image = ''; } if ('group' === $media[0]->context) { $rtmedia_nav->refresh_counts($media[0]->context_id, array('context' => $media[0]->context, 'context_id' => $media[0]->context_id)); } else { $rtmedia_nav->refresh_counts($media[0]->media_author, array('context' => 'profile', 'media_author' => $media[0]->media_author)); } if (false !== $create_activity && class_exists('BuddyPress') && bp_is_active('activity')) { $allow_single_activity = apply_filters('rtmedia_media_single_activity', false); // Following will not apply to activity uploads. For first time activity won't be generated. // Create activity first and pass activity id in response. // todo fixme rtmedia_media_single_activity filter. It will create 2 activity with same media if uploaded from activity page. $_rtmedia_update = filter_input(INPUT_POST, 'rtmedia_update', FILTER_SANITIZE_STRING); if (-1 === intval($activity_id) && !(isset($_rtmedia_update) && 'true' === $_rtmedia_update) || $allow_single_activity) { $activity_id = $media_obj->insert_activity($media[0]->media_id, $media[0]); } else { $media_obj->model->update(array('activity_id' => $activity_id), array('id' => $rtupload->media_ids[0])); // $same_medias = $media_obj->model->get(array('activity_id' => $activity_id)); $update_activity_media = array(); foreach ($same_medias as $a_media) { $update_activity_media[] = $a_media->id; } $privacy = filter_input(INPUT_POST, 'privacy', FILTER_SANITIZE_NUMBER_INT); if (empty($privacy)) { $privacy = 0; } $obj_activity = new RTMediaActivity($update_activity_media, $privacy, false); global $wpdb, $bp; $user = get_userdata($same_medias[0]->media_author); $username = '******' . esc_url(get_rtmedia_user_link($same_medias[0]->media_author)) . '">' . esc_html($user->user_nicename) . '</a>'; $action = sprintf(esc_html__('%s added %d %s', 'buddypress-media'), $username, count($same_medias), RTMEDIA_MEDIA_SLUG); $action = apply_filters('rtmedia_buddypress_action_text_fitler_multiple_media', $action, $username, count($same_medias), $user->user_nicename); $wpdb->update($bp->activity->table_name, array('type' => 'rtmedia_update', 'content' => $obj_activity->create_activity_html(), 'action' => $action), array('id' => $activity_id)); } // update group last active if ('group' === $media[0]->context) { RTMediaGroup::update_last_active($media[0]->context_id); } } } if (isset($this->upload['rtmedia_simple_file_upload']) && true == $this->upload['rtmedia_simple_file_upload']) { if (isset($media) && count($media) > 0) { if (isset($_redirect_url)) { if (intval($_redirect_url) > 1) { //bulkurl if ('group' === $media[0]->context) { $redirect_url = trailingslashit(get_rtmedia_group_link($media[0]->context_id)) . RTMEDIA_MEDIA_SLUG; } else { $redirect_url = trailingslashit(get_rtmedia_user_link($media[0]->media_author)) . RTMEDIA_MEDIA_SLUG; } } else { $redirect_url = get_rtmedia_permalink($media[0]->id); } $redirect_url = apply_filters('rtmedia_simple_file_upload_redirect_url_filter', $redirect_url); wp_safe_redirect(esc_url_raw($redirect_url)); die; } return $media; } return false; } } $redirect_url = ''; if (isset($_redirect_url) && is_numeric($_redirect_url)) { if (intval($_redirect_url) > 1) { //bulkurl if ('group' === $media[0]->context) { $redirect_url = trailingslashit(get_rtmedia_group_link($media[0]->context_id)) . RTMEDIA_MEDIA_SLUG; } else { $redirect_url = trailingslashit(get_rtmedia_user_link($media[0]->media_author)) . RTMEDIA_MEDIA_SLUG; } } else { $redirect_url = get_rtmedia_permalink($media[0]->id); } } // Ha ha ha ob_end_clean(); //check for simpe $rtmedia_update = filter_input(INPUT_POST, 'rtmedia_update', FILTER_SANITIZE_STRING); $_user_agent = rtm_get_server_var('HTTP_USER_AGENT', 'FILTER_SANITIZE_STRING'); /** * if(redirect) * */ if (!empty($rtmedia_update) && 'true' === $rtmedia_update) { if (preg_match('/(?i)msie [1-9]/', $_user_agent)) { // if IE(<=9) set content type = text/plain header('Content-type: text/plain'); } else { header('Content-type: application/json'); } echo wp_json_encode($rtupload->media_ids); } else { // Media Upload Case - on album/post/profile/group if (isset($media[0])) { $data = array('media_id' => $media[0]->id, 'activity_id' => $activity_id, 'redirect_url' => $redirect_url, 'permalink' => $perma_link, 'cover_art' => $thumb_image); } else { $data = array(); } if (preg_match('/(?i)msie [1-9]/', $_user_agent)) { // if IE(<=9) set content type = text/plain header('Content-type: text/plain'); } else { header('Content-type: application/json'); } echo wp_json_encode(apply_filters('rtmedia_upload_endpoint_response', $data)); } die; } }
function render() { $before_render = $this->before_render(); if ($before_render === false) { return false; } $button = $button_start = $button_end = ''; if ($this->is_visible()) { $link = trailingslashit(get_rtmedia_permalink($this->media->id)) . $this->action . '/'; $disabled = $icon = ''; if (!$this->is_clickable()) { $disabled = ' disabled'; } if (isset($this->icon_class) && $this->icon_class != "") { $icon = "<i class='" . $this->icon_class . "'></i>"; } $button_start = '<form action="' . $link . '">'; $button = '<button type="submit" id="rtmedia-action-button-' . $this->media->id . '" class="rtmedia-' . $this->action . ' rtmedia-action-buttons button' . $disabled . '">' . $icon . '<span>' . $this->label . '</span></button>'; //filter the button as required $button = apply_filters('rtmedia_' . $this->action . '_button_filter', $button); $button_end = '</form>'; $button = $button_start . $button . $button_end; } return $button; }
function save_album_edit() { global $rtmedia_query; $nonce = $_REQUEST['rtmedia_media_nonce']; if (wp_verify_nonce($nonce, 'rtmedia_' . $rtmedia_query->media_query['album_id'])) { $media = new RTMediaMedia(); $model = new RTMediaModel(); if (isset($_POST['submit'])) { $data_array = array('media_title', 'description', 'privacy'); $data = rtmedia_sanitize_object($_POST, $data_array); $album = $model->get_media(array('id' => $rtmedia_query->media_query['album_id']), false, false); $state = $media->update($album[0]->id, $data, $album[0]->media_id); global $rtmedia_points_media_id; $rtmedia_points_media_id = $album[0]->id; do_action('rtmedia_after_update_album', $album[0]->id, $state); } elseif (isset($_POST['move-selected'])) { $album_move = $_POST['album']; $selected_ids = null; if (isset($_POST['selected'])) { $selected_ids = $_POST['selected']; unset($_POST['selected']); } if (!empty($selected_ids) && is_array($selected_ids)) { $album_move_details = $model->get_media(array('id' => $album_move), false, false); foreach ($selected_ids as $media_id) { $media_details = $model->get_media(array('id' => $media_id), false, false); $post_array['ID'] = $media_details[0]->media_id; $post_array['post_parent'] = $album_move_details[0]->media_id; wp_update_post($post_array); $media->update($media_details[0]->id, array('album_id' => $album_move_details[0]->id), $media_details[0]->media_id); } } } //refresh $rtMediaNav = new RTMediaNav(); if ($rtmedia_query->media_query['context'] == "group") { $rtMediaNav->refresh_counts($rtmedia_query->media_query['context_id'], array("context" => $rtmedia_query->media_query['context'], 'context_id' => $rtmedia_query->media_query['context_id'])); } else { $rtMediaNav->refresh_counts($rtmedia_query->media_query['media_author'], array("context" => "profile", 'media_author' => $rtmedia_query->media_query['media_author'])); } wp_safe_redirect(esc_url_raw(get_rtmedia_permalink($rtmedia_query->media_query['album_id']) . 'edit/')); die; } else { _e('Ooops !!! Invalid access. No nonce was found !!', 'buddypress-media'); } }
/** * Create BuddyPress activity when user comment on media * * @param $params array */ function activity_after_media_comment($params) { if (isset($params['comment_post_ID'])) { // get media details $media_model = new RTMediaModel(); $media_obj = $media_model->get(array('media_id' => $params['comment_post_ID'])); $media_obj = $media_obj[0]; // only proceed if corresponding media is exist. if (!empty($media_obj) && ($media_obj->context == 'profile' || $media_obj->context == 'group')) { $media_id = $media_obj->id; $user_id = $params['user_id']; $user = get_userdata($user_id); $username = '******' . get_rtmedia_user_link($user_id) . '">' . $user->display_name . '</a>'; $primary_link = get_rtmedia_permalink($media_id); $media_const = 'RTMEDIA_' . strtoupper($media_obj->media_type) . '_LABEL'; $media_str = '<a href="' . $primary_link . '">' . constant($media_const) . '</a>'; $media_author = $media_obj->media_author; if ($media_obj->context == 'group') { $group_data = groups_get_group(array('group_id' => $media_obj->context_id)); $group_name = '<a href="' . bp_get_group_permalink($group_data) . '">' . $group_data->name . '</a>'; $action = sprintf(__('%1$s commented on a %2$s in the group %3$s', 'buddypress-media'), $username, $media_str, $group_name); } else { if ($user_id == $media_author) { $action = sprintf(__('%1$s commented on their %2$s', 'buddypress-media'), $username, $media_str); } else { $media_author_data = get_userdata($media_author); $media_author_name = '<a href="' . get_rtmedia_user_link($media_author) . '">' . $media_author_data->display_name . '</a>'; $action = sprintf(__('%1$s commented on %2$s\'s %3$s', 'buddypress-media'), $username, $media_author_name, $media_str); } } $comment_content = $params['comment_content']; $wp_comment_id = $params['comment_id']; // prepare activity arguments $activity_args = array('user_id' => $user_id, 'action' => $action, 'content' => $comment_content, 'type' => 'rtmedia_comment_activity', 'primary_link' => $primary_link, 'item_id' => $media_id, 'secondary_item_id' => $wp_comment_id); // set activity component if ($media_obj->context == 'group' || $media_obj->context == 'profile') { $activity_args['component'] = $media_obj->context; if ($media_obj->context == 'group') { $activity_args['component'] = "groups"; $activity_args['item_id'] = $media_obj->context_id; } } // create BuddyPress activity $activity_id = bp_activity_add($activity_args); // Store activity id into user meta for reference update_user_meta($user_id, 'rtm-bp-media-comment-activity-' . $media_id . '-' . $wp_comment_id, $activity_id); } } }
function rtmedia_api_process_rtmedia_gallery_request() { $this->rtmediajsonapifunction->rtmedia_api_verfiy_token(); //Errors $ec_media = 160002; $msg_media = esc_html__('media list', 'buddypress-media'); $ec_no_media = 160003; $msg_no_media = esc_html__('no media found for requested media type', 'buddypress-media'); $ec_invalid_media_type = 160004; $msg_invalid_media_type = esc_html__('media_type not allowed', 'buddypress-media'); global $rtmedia; $rtmediamodel = new RTMediaModel(); //Media type to fetch $media_type = $allowed_types = array_keys($rtmedia->allowed_types); $media_type[] = 'album'; $allowed_types[] = 'album'; $media_type_temp = filter_input(INPUT_POST, 'media_type', FILTER_SANITIZE_STRING); $media_type_array = filter_input(INPUT_POST, 'media_type', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY); if (!empty($media_type_temp) || !empty($media_type_array)) { if (!is_array($media_type_array)) { $media_type = explode(',', $media_type_array); } else { $media_type = $media_type_temp; } //Check array for currently allowed media types $media_type = array_intersect($media_type, $allowed_types); } //Args for fetching media $args = array('media_type' => $media_type); //global $global = filter_input(INPUT_POST, 'global', FILTER_SANITIZE_STRING); if (isset($global)) { if ('false' === $global) { $args['context'] = array('compare' => 'IS NOT', 'value' => 'NULL'); } } //context $context = filter_input(INPUT_POST, 'context', FILTER_SANITIZE_STRING); if (isset($context)) { $args['context'] = $context; } //context Id $context_id = filter_input(INPUT_POST, 'context_id', FILTER_SANITIZE_NUMBER_INT); if (isset($context_id)) { $args['context_id'] = $context_id; } //album id $album_id = filter_input(INPUT_POST, 'album_id', FILTER_SANITIZE_NUMBER_INT); if (!empty($album_id)) { $args['album_id'] = $album_id; } //Media Author if (!is_super_admin()) { $media_author = $this->user_id; $args['media_author'] = $media_author; } $media_author = filter_input(INPUT_POST, 'media_author', FILTER_SANITIZE_NUMBER_INT); if (!empty($media_author)) { if (is_super_admin($this->user_id)) { $args['media_author'] = (int) $media_author; } } $page = filter_input(INPUT_POST, 'page', FILTER_SANITIZE_NUMBER_INT, FILTER_NULL_ON_FAILURE); $per_page = filter_input(INPUT_POST, 'per_page', FILTER_SANITIZE_NUMBER_INT, FILTER_NULL_ON_FAILURE); $order_by = filter_input(INPUT_POST, 'order_by', FILTER_SANITIZE_STRING, FILTER_NULL_ON_FAILURE); $offset = !empty($page) ? (int) $page : 0; $per_page = isset($per_page) && !is_null($per_page) ? (int) $per_page : 10; $order_by = !empty($order_by) ? $order_by : 'media_id desc'; $media_list = $rtmediamodel->get($args, $offset, $per_page, $order_by); $media_result = array(); foreach ($media_list as $media) { $data = array('id' => $media->id, 'media_title' => $media->media_title, 'album_id' => $media->album_id, 'media_type' => $media->media_type, 'media_author' => $media->media_author, 'url' => esc_url(get_rtmedia_permalink($media->id)), 'cover' => rtmedia_image('rt_media_thumbnail', $media->media_id, false)); //for album list all medias if ('album' === $media->media_type) { $data['media'] = $this->rtmediajsonapifunction->rtmedia_api_album_media($media->id); } $media_result[] = $data; } if (!empty($media_result)) { wp_send_json($this->rtmedia_api_response_object('TRUE', $ec_media, $msg_media, $media_result)); } else { wp_send_json($this->rtmedia_api_response_object('FALSE', $ec_no_media, $msg_no_media)); } }
/** * Function to edit attachment for media * * @param string $permalink attachment permalink * @param array $post_id return attachment post id * * @return string attachment post permalink */ function rtmedia_attachment_link_callback($permalink, $post_id) { $rtmedia_media_id = rtmedia_id($post_id); if (is_admin() && !empty($rtmedia_media_id)) { $permalink = esc_url(get_rtmedia_permalink(rtmedia_id($post_id))) . '#rtmedia_comment_ul'; } return $permalink; }
/** * * 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 save_album_edit() { global $rtmedia_query; $nonce = isset($_REQUEST['rtmedia_media_nonce']) ? wp_unslash($_REQUEST['rtmedia_media_nonce']) : ''; if (wp_verify_nonce($nonce, 'rtmedia_' . $rtmedia_query->media_query['album_id'])) { $media = new RTMediaMedia(); $model = new RTMediaModel(); $submit = filter_input(INPUT_POST, 'submit', FILTER_SANITIZE_STRING); $_move_selected = filter_input(INPUT_POST, 'move-selected', FILTER_SANITIZE_STRING); $_album = filter_input(INPUT_POST, 'album', FILTER_SANITIZE_STRING); $filters = array('selected' => array('filter' => FILTER_VALIDATE_INT, 'flags' => FILTER_REQUIRE_ARRAY)); $_selected_arr = filter_input_array(INPUT_POST, $filters); $_selected = $_selected_arr['selected']; if (isset($submit)) { $data_array = array('media_title', 'description', 'privacy'); $data = rtmedia_sanitize_object($_POST, $data_array); $album = $model->get_media(array('id' => $rtmedia_query->media_query['album_id']), false, false); $state = $media->update($album[0]->id, $data, $album[0]->media_id); global $rtmedia_points_media_id; $rtmedia_points_media_id = $album[0]->id; do_action('rtmedia_after_update_album', $album[0]->id, $state); } elseif (!empty($_move_selected)) { $album_move = $_album; $selected_ids = null; if (isset($_selected)) { $selected_ids = $_selected; unset($_selected); } if (!empty($selected_ids) && is_array($selected_ids)) { $album_move_details = $model->get_media(array('id' => $album_move), false, false); foreach ($selected_ids as $media_id) { $media_details = $model->get_media(array('id' => $media_id), false, false); $post_array['ID'] = $media_details[0]->media_id; $post_array['post_parent'] = $album_move_details[0]->media_id; wp_update_post($post_array); $media->update($media_details[0]->id, array('album_id' => $album_move_details[0]->id), $media_details[0]->media_id); } } } //refresh $rtmedia_nav = new RTMediaNav(); if ('group' === $rtmedia_query->media_query['context']) { $rtmedia_nav->refresh_counts($rtmedia_query->media_query['context_id'], array('context' => $rtmedia_query->media_query['context'], 'context_id' => $rtmedia_query->media_query['context_id'])); } else { $rtmedia_nav->refresh_counts($rtmedia_query->media_query['media_author'], array('context' => 'profile', 'media_author' => $rtmedia_query->media_query['media_author'])); } wp_safe_redirect(esc_url_raw(get_rtmedia_permalink($rtmedia_query->media_query['album_id']) . 'edit/')); die; } else { esc_html_e('Ooops !!! Invalid access. No nonce was found !!', 'buddypress-media'); } }
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; }
function rtmedia_delete_form($echo = true) { if (rtmedia_delete_allowed()) { $html = '<form method="post" action="' . get_rtmedia_permalink(rtmedia_id()) . 'delete/">'; $html .= '<input type="hidden" name="id" id="id" value="' . rtmedia_id() . '">'; $html .= '<input type="hidden" name="request_action" id="request_action" value="delete">'; if ($echo) { echo $html; RTMediaMedia::media_nonce_generator(rtmedia_id(), true); do_action("rtmedia_media_single_delete_form"); echo '<button type="submit" title="' . __('Delete Media', 'rtmedia') . '" class="rtmedia-delete-media rtmedia-action-buttons button">' . __('Delete', 'rtmedia') . '</button></form>'; } else { $output = $html; $rtm_nonce = RTMediaMedia::media_nonce_generator(rtmedia_id(), false); $rtm_nonce = json_decode($rtm_nonce); $rtm_nonce_field = wp_nonce_field('rtmedia_' . rtmedia_id(), $rtm_nonce->action, true, false); do_action("rtmedia_media_single_delete_form"); $output .= $rtm_nonce_field . '<button type="submit" title="' . __('Delete Media', 'rtmedia') . '" class="rtmedia-delete-media rtmedia-action-buttons button">' . __('Delete', 'rtmedia') . '</button></form>'; return $output; } } return false; }
/** * */ function template_redirect($create_activity = true) { ob_start(); if (!count($_POST)) { include get_404_template(); } else { $nonce = $_REQUEST['rtmedia_upload_nonce']; if (isset($_REQUEST['mode'])) { $mode = $_REQUEST['mode']; } $rtupload = false; $activity_id = -1; $redirect_url = ""; if (wp_verify_nonce($nonce, 'rtmedia_upload_nonce')) { $model = new RTMediaUploadModel(); do_action('rtmedia_upload_set_post_object'); $this->upload = $model->set_post_object(); if (isset($_POST['activity_id']) && $_POST['activity_id'] != -1) { $this->upload['activity_id'] = $_POST['activity_id']; $activity_id = $_POST['activity_id']; } // ////if media upload is being made for a group, identify the group privacy and set media privacy accordingly if (isset($this->upload['context']) && isset($this->upload['context_id']) && $this->upload['context'] == 'group' && function_exists('groups_get_group')) { $group = groups_get_group(array('group_id' => $this->upload['context_id'])); if (isset($group->status) && $group->status != 'public') { // if group is not public, then set media privacy as 20, so only the group members can see the images $this->upload['privacy'] = '20'; } else { // if group is public, then set media privacy as 0 $this->upload['privacy'] = '0'; } } $this->upload = apply_filters('rtmedia_media_param_before_upload', $this->upload); $rtupload = new RTMediaUpload($this->upload); $mediaObj = new RTMediaMedia(); $media = $mediaObj->model->get(array('id' => $rtupload->media_ids[0])); $rtMediaNav = new RTMediaNav(); $perma_link = ""; if (isset($media) && sizeof($media) > 0) { $perma_link = get_rtmedia_permalink($media[0]->id); if ($media[0]->media_type == "photo") { $thumb_image = rtmedia_image("rt_media_thumbnail", $rtupload->media_ids[0], false); } elseif ($media[0]->media_type == "music") { $thumb_image = $media[0]->cover_art; } else { $thumb_image = ""; } if ($media[0]->context == "group") { $rtMediaNav->refresh_counts($media[0]->context_id, array("context" => $media[0]->context, 'context_id' => $media[0]->context_id)); } else { $rtMediaNav->refresh_counts($media[0]->media_author, array("context" => "profile", 'media_author' => $media[0]->media_author)); } if ($create_activity !== false && class_exists('BuddyPress')) { $allow_single_activity = apply_filters('rtmedia_media_single_activity', false); // Following will not apply to activity uploads. For first time activity won't be generated. // Create activity first and pass activity id in response. // todo fixme rtmedia_media_single_activity filter. It will create 2 activity with same media if uploaded from activity page. if ($activity_id == -1 && !(isset($_POST["rtmedia_update"]) && $_POST["rtmedia_update"] == "true") || $allow_single_activity) { $activity_id = $mediaObj->insert_activity($media[0]->media_id, $media[0]); } else { $mediaObj->model->update(array('activity_id' => $activity_id), array('id' => $rtupload->media_ids[0])); // $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; } $privacy = 0; if (isset($_POST["privacy"])) { $privacy = $_POST["privacy"]; } $objActivity = new RTMediaActivity($update_activity_media, $privacy, false); global $wpdb, $bp; $user = get_userdata($same_medias[0]->media_author); $username = '******' . get_rtmedia_user_link($same_medias[0]->media_author) . '">' . $user->user_nicename . '</a>'; $action = sprintf(__('%s added %d %s', 'buddypress-media'), $username, sizeof($same_medias), RTMEDIA_MEDIA_SLUG); $action = apply_filters('rtmedia_buddypress_action_text_fitler_multiple_media', $action, $username, sizeof($same_medias), $user->user_nicename); $wpdb->update($bp->activity->table_name, array("type" => "rtmedia_update", "content" => $objActivity->create_activity_html(), 'action' => $action), array("id" => $activity_id)); } // update group last active if ($media[0]->context == "group") { RTMediaGroup::update_last_active($media[0]->context_id); } } } if (isset($this->upload['rtmedia_simple_file_upload']) && $this->upload['rtmedia_simple_file_upload'] == true) { if (isset($media) && sizeof($media) > 0) { if (isset($_POST["redirect"])) { if (intval($_POST["redirect"]) > 1) { //bulkurl if ($media[0]->context == "group") { $redirect_url = trailingslashit(get_rtmedia_group_link($media[0]->context_id)) . RTMEDIA_MEDIA_SLUG; } else { $redirect_url = trailingslashit(get_rtmedia_user_link($media[0]->media_author)) . RTMEDIA_MEDIA_SLUG; } } else { $redirect_url = get_rtmedia_permalink($media[0]->id); } $redirect_url = apply_filters("rtmedia_simple_file_upload_redirect_url_filter", $redirect_url); wp_safe_redirect(esc_url_raw($redirect_url)); die; } return $media; } return false; } } $redirect_url = ""; if (isset($_POST["redirect"]) && is_numeric($_POST["redirect"])) { if (intval($_POST["redirect"]) > 1) { //bulkurl if ($media[0]->context == "group") { $redirect_url = trailingslashit(get_rtmedia_group_link($media[0]->context_id)) . RTMEDIA_MEDIA_SLUG; } else { $redirect_url = trailingslashit(get_rtmedia_user_link($media[0]->media_author)) . RTMEDIA_MEDIA_SLUG; } } else { $redirect_url = get_rtmedia_permalink($media[0]->id); } } // Ha ha ha ob_end_clean(); //check for simpe /** * if(redirect) * */ if (isset($_POST["rtmedia_update"]) && $_POST["rtmedia_update"] == "true") { if (preg_match('/(?i)msie [1-9]/', $_SERVER['HTTP_USER_AGENT'])) { // if IE(<=9) set content type = text/plain header('Content-type: text/plain'); } else { header('Content-type: application/json'); } echo json_encode($rtupload->media_ids); } else { // Media Upload Case - on album/post/profile/group if (isset($media[0])) { $data = array('media_id' => $media[0]->id, 'activity_id' => $activity_id, 'redirect_url' => $redirect_url, 'permalink' => $perma_link, 'cover_art' => $thumb_image); } else { $data = array(); } if (preg_match('/(?i)msie [1-9]/', $_SERVER['HTTP_USER_AGENT'])) { // if IE(<=9) set content type = text/plain header('Content-type: text/plain'); } else { header('Content-type: application/json'); } echo json_encode(apply_filters('rtmedia_upload_endpoint_response', $data)); } die; } }
function modify_medialibrary_permalink($action, $post, $detached) { $rtm_id = rtmedia_id($post->ID); if ($rtm_id) { $link = get_rtmedia_permalink($rtm_id); $title = _draft_or_post_title($post->post_parent); $action['view'] = '<a href="' . $link . '" title="' . esc_attr(sprintf(esc_html__('View “%s”', 'buddypress-media'), $title)) . '" rel="permalink">' . esc_html__('View', 'buddypress-media') . '</a>'; } return $action; }
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 }