예제 #1
0
파일: RTMedia.php 프로젝트: rtCamp/rtMedia
function get_rtmedia_permalink($id)
{
    $media_model = new RTMediaModel();
    $media = $media_model->get(array('id' => intval($id)));
    global $rtmedia_query;
    // Adding filter to get permalink for current blog
    add_filter('bp_get_root_domain', 'rtmedia_get_current_blog_url');
    if (!isset($media[0]->context)) {
        if (function_exists('bp_get_groups_root_slug') && isset($rtmedia_query->query) && isset($rtmedia_query->query['context']) && 'group' === $rtmedia_query->query['context']) {
            $parent_link = get_rtmedia_group_link($rtmedia_query->query['context_id']);
        } else {
            // check for global album
            $parent_link = parentlink_global_album($id);
            if ('' === $parent_link) {
                $parent_link = get_rtmedia_user_link($media[0]->media_author);
            }
        }
    } else {
        if (function_exists('bp_get_groups_root_slug') && 'group' === $media[0]->context) {
            $parent_link = get_rtmedia_group_link($media[0]->context_id);
        } else {
            // check for global album
            $parent_link = parentlink_global_album($id);
            if ('' === $parent_link) {
                $parent_link = get_rtmedia_user_link($media[0]->media_author);
            }
        }
    }
    $parent_link = trailingslashit($parent_link);
    // Removing filter so that doesn't affect other calls to this function
    remove_filter('bp_get_root_domain', 'rtmedia_get_current_blog_url');
    return trailingslashit($parent_link . RTMEDIA_MEDIA_SLUG . '/' . $id);
}
예제 #2
0
 function migrate_single_media($result, $album = false)
 {
     $blog_id = get_current_blog_id();
     $old = $result;
     if (function_exists('bp_core_get_table_prefix')) {
         $bp_prefix = bp_core_get_table_prefix();
     } else {
         $bp_prefix = '';
     }
     global $wpdb;
     if (false !== $album && !is_object($result)) {
         $id = $wpdb->get_var($wpdb->prepare("select ID from {$this->bmp_table} where media_id = %d", $result));
         if (null == $id) {
             $sql = "select\n                        a.post_id as 'post_id',\n                        a.meta_value as 'privacy',\n                        b.meta_value as 'context_id',\n                        c.meta_value as 'activity_id',\n                        p.post_type,\n                        p.post_mime_type,\n                        p.post_author as 'media_author',\n                        p.post_title as 'media_title',\n                        p.post_parent as 'parent'\n                    from\n                        {$wpdb->postmeta} a\n                            left join\n                        {$wpdb->postmeta} b ON ((a.post_id = b.post_id)\n                            and (b.meta_key = 'bp-media-key'))\n                            left join\n                        {$wpdb->postmeta} c ON (a.post_id = c.post_id)\n                            and (c.meta_key = 'bp_media_child_activity')\n                            left join\n                        {$wpdb->posts} p ON (a.post_id = p.ID)\n                    where\n                        a.post_id = %d and (NOT p.ID IS NULL)\n                            and a.meta_key = 'bp_media_privacy'";
             $result = $wpdb->get_row($wpdb->prepare($sql, $result));
         } else {
             return $id;
         }
     }
     if (!isset($result) || !isset($result->post_id)) {
         return $old;
     }
     $media_id = $result->post_id;
     if (intval($result->context_id) > 0) {
         $media_context = 'profile';
         $prefix = 'users/' . abs(intval($result->context_id));
     } else {
         $media_context = 'group';
         $prefix = bp_get_groups_root_slug() . abs(intval($result->context_id));
     }
     $old_type = '';
     if ('attachment' != $result->post_type) {
         $media_type = 'album';
     } else {
         $mime_type = strtolower($result->post_mime_type);
         $old_type = '';
         if (0 === strpos($mime_type, 'image')) {
             $media_type = 'photo';
             $old_type = 'photos';
         } else {
             if (0 === strpos($mime_type, 'audio')) {
                 $media_type = 'music';
                 $old_type = 'music';
             } else {
                 if (0 === strpos($mime_type, 'video')) {
                     $media_type = 'video';
                     $old_type = 'videos';
                 } else {
                     $media_type = 'other';
                 }
             }
         }
     }
     $activity_data = $wpdb->get_row($wpdb->prepare("select * from {$bp_prefix}bp_activity where id= %d", $result->activity_id));
     if ('album' != $media_type) {
         $this->importmedia($media_id, $prefix);
     }
     if ($this->table_exists($bp_prefix . 'bp_activity') && class_exists('BP_Activity_Activity')) {
         $bp_activity = new BP_Activity_Activity();
         $activity_sql = $wpdb->prepare("SELECT\n                            *\n                        FROM\n                            {$bp_prefix}bp_activity\n                        where\n                                        id in (select distinct\n                                    a.meta_value\n                                from\n                                    {$wpdb->postmeta} a\n                                        left join\n                                    {$wpdb->posts} p ON (a.post_id = p.ID)\n                                where\n                                    (NOT p.ID IS NULL) and p.ID = %d\n                and a.meta_key = 'bp_media_child_activity')", $media_id);
         $all_activity = $wpdb->get_results($activity_sql);
         remove_all_actions('wp_insert_comment');
         foreach ($all_activity as $activity) {
             $comments = $bp_activity->get_activity_comments($activity->id, $activity->mptt_left, $activity->mptt_right);
             $exclude = get_post_meta($media_id, 'rtmedia_imported_activity', true);
             if (!is_array($exclude)) {
                 $exclude = array();
             }
             if ($comments) {
                 $this->insert_comment($media_id, $comments, $exclude);
             }
         }
     }
     if (0 !== intval($result->parent)) {
         $album_id = $this->migrate_single_media($result->parent, true);
     } else {
         $album_id = 0;
     }
     if (function_exists('bp_activity_get_meta')) {
         $likes = bp_activity_get_meta($result->activity_id, 'favorite_count');
     } else {
         $likes = 0;
     }
     $wpdb->insert($this->bmp_table, array('blog_id' => $blog_id, 'media_id' => $media_id, 'media_type' => $media_type, 'context' => $media_context, 'context_id' => abs(intval($result->context_id)), 'activity_id' => $result->activity_id, 'privacy' => intval($result->privacy) * 10, 'media_author' => $result->media_author, 'media_title' => $result->media_title, 'album_id' => $album_id, 'likes' => $likes), array('%d', '%d', '%s', '%s', '%d', '%d', '%d', '%d', '%s', '%d', '%d'));
     $last_id = $wpdb->insert_id;
     // Photo tag meta migration
     //$photo_tag_meta = get_post_meta($media_id, "bp-media-user-tags", true);
     //        if($photo_tag_meta && !empty($photo_tag_meta)){
     //            $wpdb->insert(
     //                $wpdb->prefix . "rt_rtm_media_meta", array(
     //                    'media_id' => $media_id,
     //                    'meta_key' => "user-tags",
     //                    "meta_value" =>  maybe_serialize($photo_tag_meta)), array('%d', '%s', '%s'));
     //        }
     if ('album' != $media_type && function_exists('bp_core_get_user_domain') && $activity_data) {
         if (function_exists('bp_core_get_table_prefix')) {
             $bp_prefix = bp_core_get_table_prefix();
         } else {
             $bp_prefix = '';
         }
         $activity_data->old_primary_link = $activity_data->primary_link;
         $parent_link = get_rtmedia_user_link($activity_data->user_id);
         $activity_data->primary_link = $parent_link . RTMEDIA_MEDIA_SLUG . '/' . $last_id;
         $this->search_and_replace($activity_data->old_primary_link, $activity_data->primary_link);
         $activity_data->action = str_replace($activity_data->old_primary_link, $activity_data->primary_link, $activity_data->action);
         $activity_data->content = str_replace($activity_data->old_primary_link, $activity_data->primary_link, $activity_data->content);
         global $last_baseurl, $last_newurl;
         $replace_img = $last_newurl;
         //$last_baseurl . "rtMedia/$prefix/";
         if (false === strpos($activity_data->content, $replace_img)) {
             $activity_data->content = str_replace($last_baseurl, $replace_img, $activity_data->content);
         }
         global $wpdb;
         $wpdb->update($bp_prefix . 'bp_activity', array('primary_link' => $activity_data->primary_link, 'action' => $activity_data->action, 'content' => $activity_data->content), array('id' => $activity_data->id));
     } else {
         if ('group' == $media_context) {
             $activity_data->old_primary_link = $activity_data->primary_link;
             $parent_link = get_rtmedia_group_link(abs(intval($result->context_id)));
             $parent_link = trailingslashit($parent_link);
             $activity_data->primary_link = trailingslashit($parent_link . RTMEDIA_MEDIA_SLUG . '/' . $last_id);
             $this->search_and_replace($activity_data->old_primary_link, $activity_data->primary_link);
         } else {
             $activity_data->old_primary_link = $activity_data->primary_link;
             $parent_link = get_rtmedia_user_link($activity_data->user_id);
             $parent_link = trailingslashit($parent_link);
             $activity_data->primary_link = trailingslashit($parent_link . RTMEDIA_MEDIA_SLUG . '/' . $last_id);
             $this->search_and_replace($activity_data->old_primary_link, $activity_data->primary_link);
         }
     }
     if ('' != $old_type) {
         if ('group' == $media_context) {
             $parent_link = get_rtmedia_group_link(abs(intval($result->context_id)));
             $parent_link = trailingslashit($parent_link);
             $this->search_and_replace(trailingslashit($parent_link . $old_type . '/' . $media_id), trailingslashit($parent_link . RTMEDIA_MEDIA_SLUG . '/' . $last_id));
         } else {
             $parent_link = get_rtmedia_user_link($activity_data->user_id);
             $parent_link = trailingslashit($parent_link);
             $this->search_and_replace(trailingslashit($parent_link . $old_type . '/' . $media_id), trailingslashit($parent_link . RTMEDIA_MEDIA_SLUG . '/' . $last_id));
         }
     }
     return $last_id;
 }
예제 #3
0
 public function sub_nav()
 {
     global $rtmedia, $rtmedia_query;
     if (function_exists('bp_is_group') && bp_is_group()) {
         if (isset($rtmedia->options['buddypress_enableOnGroup']) && $rtmedia->options['buddypress_enableOnGroup'] == '0') {
             return;
         }
         global $bp;
         $counts = $this->actual_counts($bp->groups->current_group->id, "group");
     } else {
         if (class_exists('BuddyPress') && isset($rtmedia->options['buddypress_enableOnProfile']) && $rtmedia->options['buddypress_enableOnProfile'] == '0') {
             return;
         }
         $counts = $this->actual_counts();
     }
     $default = false;
     if (function_exists('bp_is_group') && bp_is_group()) {
         $link = get_rtmedia_group_link(bp_get_group_id());
         $model = new RTMediaModel();
         $other_count = $model->get_other_album_count(bp_get_group_id(), "group");
     } else {
         if (function_exists('bp_displayed_user_id') && bp_displayed_user_id()) {
             $link = get_rtmedia_user_link(bp_displayed_user_id());
         } elseif (get_query_var('author')) {
             $link = get_rtmedia_user_link(get_query_var('author'));
         }
         $model = new RTMediaModel();
         $other_count = $model->get_other_album_count(bp_displayed_user_id(), "profile");
     }
     $all = '';
     if (!isset($rtmedia_query->action_query->media_type)) {
         $all = 'class="current selected"';
     }
     echo apply_filters('rtmedia_sub_nav_all', '<li id="rtmedia-nav-item-all-li" ' . $all . '><a id="rtmedia-nav-item-all" href="' . trailingslashit($link) . RTMEDIA_MEDIA_SLUG . '/">' . __("All", "rtmedia") . '<span>' . (isset($counts['total']['all']) ? $counts['total']['all'] : 0) . '</span>' . '</a></li>');
     if (!isset($rtmedia_query->action_query->action) || empty($rtmedia_query->action_query->action)) {
         $default = true;
     }
     //print_r($rtmedia_query->action_query);
     $global_album = '';
     $albums = '';
     if (isset($rtmedia_query->action_query->media_type) && $rtmedia_query->action_query->media_type == 'album') {
         $albums = 'class="current selected"';
     }
     //$other_count = 0;
     if (is_rtmedia_album_enable()) {
         if (!isset($counts['total']["album"])) {
             $counts['total']["album"] = 0;
         }
         $counts['total']["album"] = $counts['total']["album"] + $other_count;
         $album_label = __(defined('RTMEDIA_ALBUM_PLURAL_LABEL') ? constant('RTMEDIA_ALBUM_PLURAL_LABEL') : 'Albums', 'rtmedia');
         echo apply_filters('rtmedia_sub_nav_albums', '<li id="rtmedia-nav-item-albums-li" ' . $albums . '><a id="rtmedia-nav-item-albums" href="' . trailingslashit($link) . RTMEDIA_MEDIA_SLUG . '/album/">' . $album_label . '<span>' . (isset($counts['total']["album"]) ? $counts['total']["album"] : 0) . '</span>' . '</a></li>');
     }
     foreach ($rtmedia->allowed_types as $type) {
         //print_r($type);
         if (!isset($rtmedia->options['allowedTypes_' . $type['name'] . '_enabled'])) {
             continue;
         }
         if (!$rtmedia->options['allowedTypes_' . $type['name'] . '_enabled']) {
             continue;
         }
         $selected = '';
         if (isset($rtmedia_query->action_query->media_type) && $type['name'] == $rtmedia_query->action_query->media_type) {
             $selected = ' class="current selected"';
         } else {
             $selected = '';
         }
         $context = isset($rtmedia_query->query['context']) ? $rtmedia_query->query['context'] : 'default';
         $context_id = isset($rtmedia_query->query['context_id']) ? $rtmedia_query->query['context_id'] : 0;
         $name = strtoupper($type['name']);
         $is_group = false;
         $profile = self::profile_id();
         if (!$profile) {
             $profile = self::group_id();
             $is_group = true;
         }
         if (!$is_group) {
             $profile_link = trailingslashit(get_rtmedia_user_link($profile));
         } else {
             $profile_link = trailingslashit(get_rtmedia_group_link($profile));
         }
         $type_label = __(defined('RTMEDIA_' . $name . '_PLURAL_LABEL') ? constant('RTMEDIA_' . $name . '_PLURAL_LABEL') : $type['plural_label'], 'rtmedia');
         echo apply_filters('rtmedia_sub_nav_' . $type['name'], '<li id="rtmedia-nav-item-' . $type['name'] . '-' . $context . '-' . $context_id . '-li" ' . $selected . '><a id="rtmedia-nav-item-' . $type['name'] . '" href="' . $profile_link . RTMEDIA_MEDIA_SLUG . '/' . constant('RTMEDIA_' . $name . '_SLUG') . '/' . '">' . $type_label . '<span>' . (isset($counts['total'][$type['name']]) ? $counts['total'][$type['name']] : 0) . '</span>' . '</a></li>', $type['name']);
     }
     do_action("add_extra_sub_nav");
 }
예제 #4
0
 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 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;
     }
 }
예제 #6
0
 public function sub_nav()
 {
     global $rtmedia, $rtmedia_query;
     if (function_exists('bp_is_group') && bp_is_group()) {
         if (isset($rtmedia->options['buddypress_enableOnGroup']) && 0 === intval($rtmedia->options['buddypress_enableOnGroup'])) {
             return;
         }
         global $bp;
         $counts = $this->actual_counts($bp->groups->current_group->id, 'group');
     } else {
         if (class_exists('BuddyPress') && isset($rtmedia->options['buddypress_enableOnProfile']) && 0 === intval($rtmedia->options['buddypress_enableOnProfile'])) {
             return;
         }
         $counts = $this->actual_counts();
     }
     $default = false;
     if (function_exists('bp_is_group') && bp_is_group()) {
         $link = get_rtmedia_group_link(bp_get_group_id());
         $model = new RTMediaModel();
         $other_count = $model->get_other_album_count(bp_get_group_id(), 'group');
     } else {
         if (function_exists('bp_displayed_user_id') && bp_displayed_user_id()) {
             $link = get_rtmedia_user_link(bp_displayed_user_id());
         } elseif (get_query_var('author')) {
             $link = get_rtmedia_user_link(get_query_var('author'));
         }
         $model = new RTMediaModel();
         $other_count = $model->get_other_album_count(bp_displayed_user_id(), 'profile');
     }
     $all = '';
     if (!isset($rtmedia_query->action_query->media_type) && !isset($rtmedia_query->query['media_type'])) {
         $all = 'current selected';
     }
     echo apply_filters('rtmedia_sub_nav_all', '<li id="rtmedia-nav-item-all-li" class="' . esc_attr($all) . '"><a id="rtmedia-nav-item-all" href="' . esc_url(trailingslashit($link)) . RTMEDIA_MEDIA_SLUG . '/">' . esc_html__('All', 'buddypress-media') . '<span>' . esc_html(isset($counts['total']['all']) ? $counts['total']['all'] : 0) . '</span>' . '</a></li>');
     // @codingStandardsIgnoreLine
     if (!isset($rtmedia_query->action_query->action) || empty($rtmedia_query->action_query->action)) {
         $default = true;
     }
     $albums = '';
     //condition to keep "Album" tab active
     if (array_key_exists('media_type', $rtmedia_query->query) && isset($rtmedia_query->query['media_type']) && 'album' === $rtmedia_query->query['media_type']) {
         $albums = 'current selected';
     } elseif (array_key_exists('media_type', $rtmedia_query->action_query) && isset($rtmedia_query->action_query->media_type) && 'album' === $rtmedia_query->action_query->media_type) {
         $albums = 'current selected';
     }
     if (is_rtmedia_album_enable()) {
         if (!isset($counts['total']['album'])) {
             $counts['total']['album'] = 0;
         }
         $counts['total']['album'] = $counts['total']['album'] + $other_count;
         $album_label = esc_html__(defined('RTMEDIA_ALBUM_PLURAL_LABEL') ? constant('RTMEDIA_ALBUM_PLURAL_LABEL') : 'Albums', 'buddypress-media');
         echo apply_filters('rtmedia_sub_nav_albums', '<li id="rtmedia-nav-item-albums-li" class="' . esc_attr($albums) . '"><a id="rtmedia-nav-item-albums" href="' . esc_url(trailingslashit($link)) . RTMEDIA_MEDIA_SLUG . '/album/">' . esc_html($album_label) . '<span>' . esc_html(isset($counts['total']['album']) ? $counts['total']['album'] : 0) . '</span>' . '</a></li>');
         // @codingStandardsIgnoreLine
     }
     foreach ($rtmedia->allowed_types as $type) {
         if (!isset($rtmedia->options['allowedTypes_' . $type['name'] . '_enabled'])) {
             continue;
         }
         if (!$rtmedia->options['allowedTypes_' . $type['name'] . '_enabled']) {
             continue;
         }
         $selected = '';
         if (isset($rtmedia_query->action_query->media_type) && $type['name'] === $rtmedia_query->action_query->media_type) {
             $selected = ' class="current selected"';
         } else {
             $selected = '';
         }
         $context = isset($rtmedia_query->query['context']) ? $rtmedia_query->query['context'] : 'default';
         $context_id = isset($rtmedia_query->query['context_id']) ? $rtmedia_query->query['context_id'] : 0;
         $name = strtoupper($type['name']);
         $is_group = false;
         $profile = self::profile_id();
         if (!$profile) {
             $profile = self::group_id();
             $is_group = true;
         }
         if (!$is_group) {
             $profile_link = trailingslashit(get_rtmedia_user_link($profile));
         } else {
             $profile_link = trailingslashit(get_rtmedia_group_link($profile));
         }
         $type_label = esc_html__(defined('RTMEDIA_' . $name . '_PLURAL_LABEL') ? constant('RTMEDIA_' . $name . '_PLURAL_LABEL') : $type['plural_label'], 'buddypress-media');
         echo apply_filters('rtmedia_sub_nav_' . $type['name'], '<li id="rtmedia-nav-item-' . esc_attr($type['name']) . '-' . esc_attr($context) . '-' . esc_attr($context_id) . '-li" ' . $selected . '><a id="rtmedia-nav-item-' . esc_attr($type['name']) . '" href="' . esc_url($profile_link . RTMEDIA_MEDIA_SLUG . '/' . constant('RTMEDIA_' . $name . '_SLUG') . '/') . '">' . $type_label . '<span>' . esc_html(isset($counts['total'][$type['name']]) ? $counts['total'][$type['name']] : 0) . '</span>' . '</a></li>', $type['name']);
     }
     do_action('add_extra_sub_nav');
 }
예제 #7
0
function get_rtmedia_permalink($id)
{
    $mediaModel = new RTMediaModel();
    $media = $mediaModel->get(array('id' => intval($id)));
    global $rtmedia_query;
    if (!isset($media[0]->context)) {
        if (function_exists("bp_get_groups_root_slug") && isset($rtmedia_query->query) && isset($rtmedia_query->query["context"]) && $rtmedia_query->query["context"] == "group") {
            $parent_link = get_rtmedia_group_link($rtmedia_query->query["context_id"]);
        } else {
            // check for global album
            $parent_link = parentlink_global_album($id);
            if ($parent_link == "") {
                $parent_link = get_rtmedia_user_link($media[0]->media_author);
            }
        }
    } else {
        if (function_exists("bp_get_groups_root_slug") && $media[0]->context == 'group') {
            $parent_link = get_rtmedia_group_link($media[0]->context_id);
        } else {
            // check for global album
            $parent_link = parentlink_global_album($id);
            if ($parent_link == "") {
                $parent_link = get_rtmedia_user_link($media[0]->media_author);
            }
        }
    }
    $parent_link = trailingslashit($parent_link);
    return trailingslashit($parent_link . RTMEDIA_MEDIA_SLUG . '/' . $id);
}