rtMedia uploader shortcode
Author: joshua
 /**
  * Render the uploader shortcode and attach the uploader panel
  *
  * @param type $attr
  */
 static function pre_render($attr)
 {
     $allow_upload = apply_filters('rtmedia_allow_uploader_view', true, 'uploader_shortcode');
     if ($allow_upload) {
         global $post;
         global $rtmedia_query;
         if (!$rtmedia_query) {
             $rtmedia_query = new RTMediaQuery();
         }
         if (!isset($attr['is_up_shortcode']) || $attr['is_up_shortcode'] !== false) {
             $rtmedia_query->is_upload_shortcode = true;
             // set is_upload_shortcode in rtmedia query as true
         } else {
             $rtmedia_query->is_upload_shortcode = false;
             // set is_upload_shortcode in rtmedia query as true
         }
         if (isset($attr['media_type'])) {
             global $rtmedia;
             $allowed_media_type = $rtmedia->allowed_types;
             if (isset($allowed_media_type[$attr['media_type']])) {
                 wp_localize_script('rtmedia-backbone', "rtmedia_upload_type_filter", $allowed_media_type[$attr['media_type']]['extn']);
             }
         }
         if (isset($attr) && !empty($attr)) {
             if (!is_array($attr)) {
                 $attr = array();
             }
             if (!isset($attr["context_id"]) && isset($post->ID)) {
                 $attr["context_id"] = $post->ID;
             }
             if (!isset($attr["context"]) && isset($post->post_type)) {
                 $attr["context"] = $post->post_type;
             }
         }
         $attr = apply_filters('rtmedia_media_uploader_attributes', $attr);
         if (self::display_allowed() || isset($attr['allow_anonymous']) && $attr['allow_anonymous'] === true) {
             if (!_device_can_upload()) {
                 echo '<p>' . __('The web browser on your device cannot be used to upload files.', 'rtmedia') . '</p>';
                 return;
             }
             ob_start();
             self::$add_sc_script = true;
             RTMediaUploadTemplate::render($attr);
             self::$uploader_displayed = true;
             return ob_get_clean();
         }
     } else {
         echo "<div class='rtmedia-upload-not-allowed'>" . apply_filters('rtmedia_upload_not_allowed_message', __('You are not allowed to upload/attach media.', 'rtmedia'), 'uploader_shortcode') . "</div>";
     }
 }
 /**
  * redirects to the template according to the page request
  * Pass on the shortcode attributes to the template so that the shortcode can berendered accordingly.
  *
  * Also handles the json request coming from the AJAX calls for the media
  *
  * @global type $rtmedia_query
  * @global type $rtmedia_interaction
  *
  * @param type  $template
  * @param type  $shortcode_attr
  *
  * @return type
  */
 function set_template($template = false, $shortcode_attr = false)
 {
     global $rtmedia_query, $rtmedia_interaction, $rtmedia_media;
     do_action('rtmedia_pre_template');
     if (isset($rtmedia_query->action_query->action)) {
         do_action('rtmedia_pre_action_' . $rtmedia_query->action_query->action);
     } else {
         do_action('rtmedia_pre_action_default');
     }
     $this->check_return_json();
     $this->check_return_upload();
     if ($rtmedia_interaction && isset($rtmedia_interaction->context) && in_array($rtmedia_interaction->context->type, array("profile", "group"))) {
         $this->check_return_edit();
         $this->check_return_delete();
         $this->check_return_merge();
         $this->check_return_comments();
         $this->check_delete_comments();
         if (isset($rtmedia_query->is_gallery_shortcode) && $rtmedia_query->is_gallery_shortcode == true && isset($shortcode_attr['name']) && $shortcode_attr['name'] == 'gallery') {
             $valid = $this->sanitize_gallery_attributes($shortcode_attr['attr']);
             if ($valid) {
                 if (is_array($shortcode_attr['attr'])) {
                     $this->update_global_query($shortcode_attr['attr']);
                 }
                 echo "<div class='rtmedia_gallery_wrapper'>";
                 $this->add_hidden_fields_in_gallery();
                 $gallery_template = apply_filters("rtmedia-before-template", $template, $shortcode_attr);
                 include $this->locate_template($gallery_template);
                 echo "</div>";
             } else {
                 echo __('Invalid attribute passed for rtmedia_gallery shortcode.', 'buddypress-media');
                 return false;
             }
         } else {
             return $this->get_default_template();
         }
     } else {
         if (!$shortcode_attr) {
             return $this->get_default_template();
         } else {
             if ($shortcode_attr['name'] == 'gallery') {
                 $valid = $this->sanitize_gallery_attributes($shortcode_attr['attr']);
                 if ($valid) {
                     if (is_array($shortcode_attr['attr'])) {
                         $this->update_global_query($shortcode_attr['attr']);
                     }
                     global $rtaccount;
                     if (!isset($rtaccount)) {
                         $rtaccount = 0;
                     }
                     //add_action("rtmedia_before_media_gallery",array(&$this,"")) ;
                     $include_uploader = false;
                     if (isset($shortcode_attr['attr']) && isset($shortcode_attr['attr']['uploader'])) {
                         $include_uploader = $shortcode_attr['attr']['uploader'];
                         unset($shortcode_attr['attr']['uploader']);
                     }
                     if ($include_uploader == "before") {
                         echo RTMediaUploadShortcode::pre_render($shortcode_attr['attr']);
                     }
                     echo "<div class='rtmedia_gallery_wrapper'>";
                     $this->add_hidden_fields_in_gallery();
                     $gallery_template = apply_filters("rtmedia-before-template", $template, $shortcode_attr);
                     include $this->locate_template($gallery_template);
                     echo "</div>";
                     if ($include_uploader == "after" || $include_uploader == "true") {
                         echo RTMediaUploadShortcode::pre_render($shortcode_attr['attr']);
                     }
                 } else {
                     echo __('Invalid attribute passed for rtmedia_gallery shortcode.', 'buddypress-media');
                     return false;
                 }
             }
         }
     }
 }
/**
 *
 * @param type $attr
 */
function rtmedia_uploader($attr = '')
{
    if (rtmedia_is_uploader_view_allowed(true, 'media_gallery')) {
        if (function_exists('bp_is_blog_page') && !bp_is_blog_page()) {
            if (function_exists('bp_is_user') && bp_is_user() && function_exists('bp_displayed_user_id') && bp_displayed_user_id() == get_current_user_id()) {
                echo RTMediaUploadShortcode::pre_render($attr);
            } else {
                if (function_exists('bp_is_group') && bp_is_group()) {
                    if (can_user_upload_in_group()) {
                        echo RTMediaUploadShortcode::pre_render($attr);
                    }
                }
            }
        }
    } else {
        echo "<div class='rtmedia-upload-not-allowed'>" . apply_filters('rtmedia_upload_not_allowed_message', __('You are not allowed to upload/attach media.', 'rtmedia'), 'media_gallery') . "</div>";
    }
}
示例#4
0
/**
 * Rendering RTMedia Uploader
 *
 * @param       array|string    $attr
 */
function rtmedia_uploader($attr = '')
{
    if (rtmedia_is_uploader_view_allowed(true, 'media_gallery')) {
        if (function_exists('bp_is_blog_page') && !bp_is_blog_page()) {
            if (function_exists('bp_is_user') && bp_is_user() && function_exists('bp_displayed_user_id') && bp_displayed_user_id() === get_current_user_id()) {
                echo RTMediaUploadShortcode::pre_render($attr);
                // @codingStandardsIgnoreLine
            } else {
                if (function_exists('bp_is_group') && bp_is_group()) {
                    if (can_user_upload_in_group()) {
                        echo RTMediaUploadShortcode::pre_render($attr);
                        // @codingStandardsIgnoreLine
                    }
                }
            }
        }
    } else {
        echo "<div class='rtmedia-upload-not-allowed'>" . wp_kses(apply_filters('rtmedia_upload_not_allowed_message', esc_html__('You are not allowed to upload/attach media.', 'buddypress-media'), 'media_gallery'), RTMediaUpload::$wp_kses_allowed_tags) . '</div>';
    }
}