set_template() public method

Also handles the json request coming from the AJAX calls for the media
public set_template ( boolean | type $template = false, boolean | type $shortcode_attr = false ) : type
$template boolean | type
$shortcode_attr boolean | type
return type
Ejemplo n.º 1
0
 /**
  * Hook into the template_include filter to load custom template files
  *
  * @param string $template Template file path of the default template
  * @return string File path of the template file to be loaded
  */
 function template_include($template)
 {
     // if it is not our route, return the default template early
     if (!$this->is_template()) {
         return $template;
     }
     // otherwise, apply a filter to the template,
     // pass the template  and slug to the function hooking here
     // so it can load a custom template
     $template_load = new RTMediaTemplate();
     global $new_rt_template;
     $new_rt_template = $template_load->set_template($template);
     $new_rt_template = apply_filters("rtmedia_" . $this->slug . "_include", $new_rt_template);
     global $rt_ajax_request;
     $rt_ajax_request = false;
     // check if it is an ajax request
     if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
         $rt_ajax_request = true;
     }
     if ($rt_ajax_request) {
         return $new_rt_template;
     }
     if (function_exists('bp_set_theme_compat_active')) {
         bp_set_theme_compat_active(apply_filters('rtmedia_main_template_set_theme_compat', true));
     }
     add_filter('the_content', array(&$this, 'rt_replace_the_content'));
     $this->rt_theme_compat_reset_post();
     return apply_filters('rtmedia_main_template_include', $template, $new_rt_template);
 }
 /**
  * Render a shortcode according to the attributes passed with it
  *
  * @param boolean $attr
  */
 static function render($attr)
 {
     if (self::display_allowed()) {
         self::$add_script = true;
         ob_start();
         $authorized_member = true;
         //by default, viewer is authorized
         if (!isset($attr) || empty($attr)) {
             $attr = true;
         }
         $attr = array('name' => 'gallery', 'attr' => $attr);
         global $post;
         if (isset($attr) && isset($attr["attr"])) {
             if (!is_array($attr["attr"])) {
                 $attr["attr"] = array();
             }
             if (!isset($attr["attr"]["context_id"]) && isset($attr["attr"]["context"]) && $attr["attr"]["context"] == 'profile') {
                 $attr["attr"]["context_id"] = get_current_user_id();
             } elseif (!isset($attr["attr"]["context_id"]) && isset($post->ID)) {
                 $attr["attr"]["context_id"] = $post->ID;
             }
             //check if context is group, then the gallery should only be visible to users according to the group privacy
             if (isset($attr['attr']['context']) && $attr['attr']['context'] == 'group') {
                 if (function_exists('groups_get_group')) {
                     //if buddypress group is enabled
                     $group = groups_get_group(array('group_id' => $attr["attr"]["context_id"]));
                     if (isset($group->status) && $group->status != 'public') {
                         if (is_user_logged_in()) {
                             $is_member = groups_is_user_member(get_current_user_id(), $attr["attr"]["context_id"]);
                             if (!$is_member) {
                                 $authorized_member = false;
                                 //if user doesnot have access to the specified group
                             }
                         } else {
                             $authorized_member = false;
                             //if user is  groupnot logged in and visits group media gallery
                         }
                     }
                 }
             }
             if (!isset($attr["attr"]["context"]) && isset($post->post_type)) {
                 $attr["attr"]["context"] = $post->post_type;
             }
         }
         if ($authorized_member) {
             // if current user has access to view the gallery (when context is 'group')
             global $rtmedia_query;
             if (!$rtmedia_query) {
                 $rtmedia_query = new RTMediaQuery($attr["attr"]);
             }
             $rtmedia_query->is_gallery_shortcode = true;
             // to check if gallery shortcode is executed to display the gallery.
             $template = new RTMediaTemplate();
             $gallery_template = false;
             if (isset($attr["attr"]["global"]) && $attr["attr"]["global"] == true) {
                 add_filter('rtmedia-model-where-query', array('RTMediaGalleryShortcode', 'rtmedia_query_where_filter'), 10, 3);
             }
             $template->set_template($gallery_template, $attr);
             if (isset($attr["attr"]["global"]) && $attr["attr"]["global"] == true) {
                 remove_filter('rtmedia-model-where-query', array('RTMediaGalleryShortcode', 'rtmedia_query_where_filter'), 10, 3);
             }
         } else {
             //if user cannot view the media gallery (when context is 'group'), show message
             echo __('You do not have sufficient privileges to view this gallery', 'rtmedia');
             return false;
         }
         return ob_get_clean();
     }
 }