示例#1
0
 /**
  * When WP is enqueueing styles, inject our Slider CSS and JavaScript.
  *
  * We use the Template Manager to canonicalize the URIs and paths for the JS and CSS. If the $context is
  * 'backend', we load the CSS only, but not the JavaScript.
  *
  * @param string $context Either 'frontend' (default) or 'backend'.
  * @return void
  */
 public function enqueue_slider_frontend($context = 'frontend')
 {
     // load .min.js if available, if SCRIPT_DEBUG is not true in wp-config.php
     $is_min = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? false : true;
     $general_options = get_option('total_slider_general_options');
     // do not run if enqueue is disabled
     if (is_array($general_options) && array_key_exists('should_enqueue_template', $general_options) && '0' == $general_options['should_enqueue_template'] && $context != 'backend') {
         return false;
     }
     if (!$this->template || !is_a($this->template, 'Total_Slider_Template')) {
         // determine the current template
         if (!$this->determine_template()) {
             return false;
         }
     }
     // load the CSS
     wp_register_style('total-slider-frontend', $this->template->css_uri(), array(), date('YmdHis', @filemtime($this->template->css_path())), 'all');
     wp_enqueue_style('total-slider-frontend');
     if ('backend' != $context) {
         if ($is_min) {
             $js_uri = $this->template->js_min_uri();
             $js_path = $this->template->js_min_path();
         } else {
             $js_uri = $this->template->js_uri();
             $js_path = $this->template->js_path();
         }
         // enqueue the JS
         wp_register_script('total-slider-frontend', $js_uri, array('jquery'), date('YmdHis', @filemtime($jsPath)), true);
         wp_enqueue_script('total-slider-frontend');
     }
 }
 /**
  * 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);
 }