示例#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');
     }
 }
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/
if (!defined('TOTAL_SLIDER_REQUIRED_CAPABILITY')) {
    header('HTTP/1.1 403 Forbidden');
    die('<h1>Forbidden</h1>');
}
if (!function_exists('__')) {
    header('HTTP/1.1 403 Forbidden');
    die('<h1>Forbidden</h1>');
}
if (array_key_exists('total-slider-uploader', $_GET) && 'bgimage' == $_GET['total-slider-uploader']) {
    if (!array_key_exists('total-slider-slide-group-template', $_GET) || empty($_GET['total-slider-slide-group-template']) || !array_key_exists('total-slider-slide-group-template-location', $_GET) || empty($_GET['total-slider-slide-group-template-location'])) {
        $crop = array('crop_width' => TOTAL_SLIDER_DEFAULT_CROP_WIDTH, 'crop_height' => TOTAL_SLIDER_DEFAULT_CROP_HEIGHT);
    } else {
        try {
            $t = new Total_Slider_Template($_GET['total-slider-slide-group-template'], $_GET['total-slider-slide-group-template-location']);
            $crop = $t->determine_options();
        } catch (Exception $e) {
            $crop = array('crop_width' => TOTAL_SLIDER_DEFAULT_CROP_WIDTH, 'crop_height' => TOTAL_SLIDER_DEFAULT_CROP_HEIGHT);
        }
    }
    ?>
<!-- a little shimming to prettify the uploader/media library options for Total Slider purposes -->
<style type="text/css">
#media-items .post_title,#media-items .image_alt,#media-items .post_excerpt,#media-items .post_content, #media-items .url, #media-items .align { display:none !important; }
</style>
<script type="text/javascript">
//<![CDATA[
jQuery(document).ready(function() {
	jQuery('.imgedit-response').append('<p style="text-align:center;font-size:12px;color:#909090;"><?php 
    printf(__('Choose ‘Edit Image’ and crop to %d×%d for best results.', 'total-slider'), $crop['crop_width'], $crop['crop_height']);
 /**
  * Discover templates that are available in the specified location.
  *
  * Returns an array of the template slugs and names, which can be used for further inspection by
  * instantiating a Total_Slider_Template class with the returned slug and supplied template location.
  *
  * @param string $location One of 'builtin','theme','downloaded','legacy'.
  * @param boolean $should_parse_name Set to false to avoid the overhead of parsing template names.
  * @return array
  */
 public function discover_templates($location, $should_parse_name = true)
 {
     if (!is_array(Total_Slider::$allowed_template_locations)) {
         throw new UnexpectedValueException(__('The allowed template locations are not available. This file must not be loaded without class.total-slide-group.php', 'total-slider'), 103);
         return false;
     }
     // check the location given is valid
     if (!in_array($location, Total_Slider::$allowed_template_locations)) {
         throw new UnexpectedValueException(__('The supplied template location is not one of the allowed template locations', 'total-slider'), 101);
         return false;
     }
     // what path(s) should we walk?
     $paths = array();
     $css_name = 'style.css';
     switch ($location) {
         case 'builtin':
             $paths[] = plugin_dir_path(dirname(__FILE__)) . '/' . TOTAL_SLIDER_TEMPLATES_BUILTIN_DIR . '/';
             break;
         case 'theme':
             $paths[] = get_stylesheet_directory() . '/' . TOTAL_SLIDER_TEMPLATES_DIR . '/';
             if (get_stylesheet_directory() != get_template_directory()) {
                 $paths[] = get_template_directory() . '/' . TOTAL_SLIDER_TEMPLATES_DIR . '/';
             }
             break;
         case 'downloaded':
             if (!defined('WP_CONTENT_DIR')) {
                 throw new UnexpectedValueException(__('Unable to determine the WP_CONTENT_DIR, so cannot find relevant templates.', 'total-slider'), 102);
                 return false;
             }
             // in the absence of content_dir() existing, we must use the WP_CONTENT_DIR constant. Sorry!
             $paths[] = WP_CONTENT_DIR . '/' . TOTAL_SLIDER_TEMPLATES_DIR . '/';
             break;
         case 'legacy':
             $path = get_stylesheet_directory() . '/' . TOTAL_SLIDER_TEMPLATES_DIR . '/';
             if (!@file_exists($path) || !@is_dir($path)) {
                 return false;
             }
             $files = @scandir($path);
             if (!$files) {
                 return false;
             }
             foreach ($files as $f) {
                 $templates = array();
                 $i = 0;
                 if ('total-slider-template.php' == $f) {
                     $templates[$i]['slug'] = Total_Slider_Template::sanitize_slug(basename($f));
                     $templates[$i]['name'] = __('v1.0 Custom Template', 'total-slider');
                     return $templates;
                 }
             }
             return false;
             break;
         default:
             return false;
             break;
     }
     $templates = array();
     $i = 0;
     // walk the walk
     foreach ($paths as $key => $path) {
         if (!@file_exists($path) || !@is_dir($path)) {
             continue;
         }
         $files = @scandir($path);
         if (!$files) {
             continue;
         }
         foreach ($files as $f) {
             if ('.' == $f || '..' == $f) {
                 continue;
             }
             if (@is_dir($path . '/' . $f)) {
                 if (@file_exists($path . '/' . $f . '/' . $css_name)) {
                     if ($should_parse_name) {
                         $tpl_content = @file_get_contents($path . '/' . $f . '/' . $css_name);
                         // extract the template name
                         $matches = array();
                         preg_match('/^\\s*Template\\sName:\\s*(.*)/im', $tpl_content, $matches);
                         unset($tpl_content);
                         $templates[$i]['slug'] = Total_Slider_Template::sanitize_slug(basename($f));
                         if ($matches && count($matches) > 1) {
                             $templates[$i]['name'] = $matches[1];
                         }
                         ++$i;
                     } else {
                         $templates[$i]['slug'] = Total_Slider_Template::sanitize_slug(basename($f));
                         ++$i;
                     }
                 }
             }
         }
     }
     return $templates;
 }
 /**
  * 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);
 }
示例#5
0
 $existing_terms = get_terms('total_slider_slide_group', array('hide_empty' => false));
 if (!$collision && is_array($existing_terms) && count($existing_terms) > 0) {
     foreach ($existing_terms as $term) {
         if ($term->name == $_POST['group-name']) {
             $collision = true;
             break;
         }
     }
 }
 // if collision, throw an error:
 if ($collision) {
     $create_error = __('Unable to create this slide group, as there is already a group with this name.', 'total-slider');
 } else {
     $new_group = new Total_Slide_Group($new_slug, $_POST['group-name']);
     // set the new template
     $desired_tpl_slug = Total_Slider_Template::sanitize_slug($_POST['template-slug']);
     $tpl_location = false;
     $tpl_slug = false;
     // determine which template location this template is from
     $t = new Total_Slider_Template_Iterator();
     foreach (Total_Slider::$allowed_template_locations as $l) {
         if ($tpl_location || $tpl_slug) {
             break;
         }
         $choices = $t->discover_templates($l, false);
         // find the right template and set our provision template slug and location to it
         if (is_array($choices) && count($choices) > 0) {
             foreach ($choices as $c) {
                 if ($desired_tpl_slug == $c['slug']) {
                     $tpl_location = $l;
                     $tpl_slug = $desired_tpl_slug;
    /**
     * Render an HTML mini-preview of the slide images, for use in the widget selector. TODO UNFINISHED
     *
     * This allows an at-a-glance verification that the selected slide group is the desired slide group.
     *
     * @return void
     */
    public function mini_preview()
    {
        /*
        	* Extract background images from slides.
        	* (Get thumbnail versions?)
        	* Get suggested crop width and height, scale down proportionally to calculate thumbnail size of template
        	* Render thumbnail images against those dimensions
        	* JS to spin through them with some kind of animation?
        	
        	How do we disclaim that this isn't truly WYSIWYG? Is that a problem?
        */
        if (empty($this->template) || empty($this->templateLocation)) {
            if (!$this->load()) {
                return false;
            }
        }
        // load template information
        try {
            $t = new Total_Slider_Template($this->template, $this->templateLocation);
        } catch (Exception $e) {
            if (defined('WP_DEBUG') && WP_DEBUG) {
                printf(__('Unable to render the slide mini-preview: %s (error code %d)', 'total-slider'), $e->getMessage(), $e->getCode());
            }
            return false;
        }
        $template_options = $t->determine_options();
        ?>
<p><strong><?php 
        _e('Template:', 'total-slider');
        ?>
</strong> <?php 
        echo esc_html($t->name());
        ?>
</p><?php 
        $current_slides = get_option('total_slider_slides_' . $this->slug);
        if (false === $current_slides || !is_array($current_slides) || count($current_slides) < 0) {
            ?>
<p><?php 
            _e('There are no slides to show.', 'total-slider');
            ?>
</p><?php 
            return true;
        }
        ?>
<div class="total-slider-mini-preview">
		<ul><?php 
        foreach ($current_slides as $idx => $slide) {
            if (is_numeric($slide['background']) && intval($slide['background']) == $slide['background']) {
                // background references an attachment ID
                $image = wp_get_attachment_image_src(intval($slide['background']), 'thumbnail');
                $image = $image[0];
            } else {
                $image = $slide['background'];
            }
            ?>
<li><img src="<?php 
            echo esc_url($image);
            ?>
" alt="<?php 
            echo esc_attr($slide['title']);
            ?>
" title="<?php 
            echo esc_attr($slide['title']);
            ?>
" width="100" height="32" /></li><?php 
        }
        ?>
		</ul>
		</div><?php 
    }
 /**
  * Return the template name used for the slide group.
  *
  * @param Total_Slide_Group $item A slide group object.
  * @return string
  */
 public function column_template($item)
 {
     if (property_exists($item, 'template') && !empty($item->template) && property_exists($item, 'templateLocation') && !empty($item->templateLocation)) {
         // load template's friendly name
         try {
             $t = new Total_Slider_Template($item->template, $item->templateLocation);
         } catch (Exception $e) {
             return esc_html($item->template);
         }
         if ($t->name()) {
             return esc_html($t->name());
         } else {
             return esc_html($item->template);
         }
     } else {
         return 'Default';
     }
 }