コード例 #1
0
 /**
  * Render the widget output. Invoke the Slide Group Template file to perform the bulk of the work.
  *
  * @param array $args
  * @param array $instance
  */
 public function widget($args, $instance)
 {
     $this->instance = $instance;
     // clear out all the data
     $this->slide_title = null;
     $this->slide_description = null;
     $this->slide_background_url = null;
     $this->slide_link = null;
     $this->slide_x = null;
     $this->slide_y = null;
     $this->slide_identifier = null;
     $this->slides = null;
     $this->slider_iteration = 0;
     // determine the correct template to use
     $this->slide_group = new Total_Slide_Group(Total_Slider::sanitize_slide_group_slug($this->instance['groupSlug']));
     if (!$this->slide_group->load()) {
         _e('<strong>Total Slider:</strong> Could not find the selected slide group to show. Does it still exist?', 'total-slider');
         return;
     }
     try {
         $tpl = new Total_Slider_Template($this->slide_group->template, $this->slide_group->templateLocation);
     } catch (Exception $e) {
         _e('<strong>Total Slider:</strong> Unable to load the template for this slide group.', 'total-slider');
         if (is_user_logged_in() && current_user_can('publish_posts')) {
             echo ' <em>' . esc_html($e->getMessage()) . '</em>';
         }
         return;
     }
     $general_options = get_option('total_slider_general_options');
     // only enqueue template if relevant option is set (fixes #29)
     if (is_array($general_options) && array_key_exists('should_enqueue_template', $general_options) && $general_options['should_enqueue_template'] == '1') {
         // enqueue CSS and JS
         wp_register_style('total-slider-' . esc_attr($this->slide_group->template), $tpl->css_uri(), array(), date("YmdHis", @filemtime($tpl->css_path())), 'all');
         wp_enqueue_style('total-slider-' . esc_attr($this->slide_group->template));
         // load .min.js if available, if SCRIPT_DEBUG is not true in wp-config.php
         $is_min = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? false : true;
         if ($is_min) {
             $js_uri = $tpl->js_min_uri();
             $js_path = $tpl->js_min_path();
         } else {
             $js_uri = $tpl->js_uri();
             $js_path = $tpl->js_path();
         }
         wp_register_script('total-slider-' . esc_attr($this->slide_group->template), $js_uri, array('jquery'), date('YmdHis', @filemtime($js_path)), true);
         wp_enqueue_script('total-slider-' . esc_attr($this->slide_group->template));
     }
     $s =& $this;
     // $s is used by the theme to call our functions to actually display the data
     // include the template
     include $tpl->php_path();
     unset($s);
 }