/**
  * 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);
 }
    along with this program; if not, write to the Free Software
    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>');
}
?>
<!--sortable slides-->
<?php 
$group = new Total_Slide_Group($TS_Total_Slider->slug);
$group->load();
$current_slides = $group->get_slides();
?>
<div id="slidesort-container">
<ul id="slidesort" style="width:<?php 
echo intval(count($current_slides) * 180);
?>
px;">
<?php 
if (is_array($current_slides) && count($current_slides) > 0) {
    foreach ($current_slides as $slide) {
        $my_id = $TS_Total_Slider->id_filter($slide['id']);
        if (is_numeric($slide['background'])) {
            $background_url = wp_get_attachment_url((int) $slide['background']);
        } else {
            $background_url = $slide['background'];
// if the URL otherwise has 'group' in the GET parameters, it's time to pass control
// to print_slides_page() for editing purposes
if (array_key_exists('group', $_GET)) {
    $TS_Total_Slider->print_slides_page();
    return;
}
// if we are to create a new slide group, do that and redirect to edit
if (array_key_exists('action', $_GET) && 'new_slide_group' == $_GET['action'] && array_key_exists('_wpnonce', $_REQUEST)) {
    if (wp_verify_nonce($_REQUEST['_wpnonce'], 'new-slide-group')) {
        if (!empty($_POST['group-name']) && !empty($_POST['template-slug'])) {
            // add the new slide group
            $new_slug = $TS_Total_Slider->sanitize_slide_group_slug(sanitize_title_with_dashes($_POST['group-name']));
            // slide group already with this name?
            $existing = new Total_Slide_Group($new_slug);
            $collision = false;
            if ($existing->load()) {
                $collision = true;
            }
            // v2.0: we can no longer have slide groups that have identical names, even if slugs don't clash
            $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');
    /**
     * Print the HTML for the slide template metabox.
     *
     * @return void
     *
     */
    public function print_slide_template_metabox()
    {
        global $TS_Total_Slider;
        if (!$this->slug) {
            if (!array_key_exists('group', $_GET)) {
                return false;
            }
            $this->slug = $this->sanitize_slide_group_slug($_GET['group']);
        }
        $slide_group = new Total_Slide_Group($this->slug);
        if (!$slide_group->load()) {
            return false;
        }
        ?>
<div id="template-switch-controls">
			<p>
			<?php 
        $t = new Total_Slider_Template_Iterator();
        ?>
				<select name="template-slug" id="template-slug-selector">
					
					<?php 
        $builtin = $t->discover_templates('builtin');
        ?>
					<?php 
        if (is_array($builtin) && count($builtin) > 0) {
            ?>
					<optgroup label="<?php 
            _e('Built-in', 'total-slider');
            ?>
">
						<?php 
            foreach ($builtin as $tpl) {
                ?>

							<option
								value="<?php 
                echo esc_attr($tpl['slug']);
                ?>
"
								<?php 
                if ('builtin' == $slide_group->templateLocation && $slide_group->template == $tpl['slug']) {
                    ?>
								selected="selected"
								<?php 
                }
                ?>
								
							><?php 
                echo esc_html($tpl['name']);
                ?>
</option>
						<?php 
            }
            ?>
					</optgroup>
					<?php 
        }
        ?>
					
					<?php 
        $theme = $t->discover_templates('theme');
        ?>
					<?php 
        if (is_array($theme) && count($theme) > 0) {
            ?>
					<optgroup label="<?php 
            _e('Theme', 'total-slider');
            ?>
">
						<?php 
            foreach ($theme as $tpl) {
                ?>
							<option
								value="<?php 
                echo esc_attr($tpl['slug']);
                ?>
"
								<?php 
                if ('theme' == $slide_group->templateLocation && $slide_group->template == $tpl['slug']) {
                    ?>
								selected="selected"
								<?php 
                }
                ?>
								
							><?php 
                echo esc_html($tpl['name']);
                ?>
</option>
						<?php 
            }
            ?>
					</optgroup>
					<?php 
        }
        ?>
					
					<?php 
        $legacy = $t->discover_templates('legacy', false);
        ?>
					<?php 
        if (is_array($legacy) && count($legacy) > 0) {
            ?>
					<optgroup label="<?php 
            _e('v1.0 Templates', 'total-slider');
            ?>
">
						<?php 
            foreach ($legacy as $tpl) {
                ?>
							<option
							value="<?php 
                echo esc_attr($tpl['slug']);
                ?>
"
							<?php 
                if ('legacy' == $slide_group->templateLocation) {
                    ?>
								selected="selected"
								<?php 
                }
                ?>
							><?php 
                echo esc_html($tpl['name']);
                ?>
</option>
						<?php 
            }
            ?>
					</optgroup>								
					<?php 
        }
        ?>
										
			
					<?php 
        //$downloaded = $t->discover_templates('downloaded');
        ?>
					<?php 
        $downloaded = false;
        ?>
					<?php 
        if (is_array($downloaded) && count($downloaded) > 0) {
            ?>
					<!--<optgroup label="<?php 
            _e('Downloaded', 'total-slider');
            ?>
">
						<?php 
            foreach ($downloaded as $tpl) {
                ?>
							<option
								value="<?php 
                echo esc_attr($tpl['slug']);
                ?>
"
								<?php 
                if ('downloaded' == $slide_group->templateLocation && $slideGroup->template == $tpl['slug']) {
                    ?>
								selected="selected"
								<?php 
                }
                ?>
								
							><?php 
                echo esc_html($tpl['name']);
                ?>
</option>
						<?php 
            }
            ?>
																
					</optgroup>	-->
					<?php 
        }
        ?>
													
				</select>
			<input id="template-switch-button" type="submit" class="button-secondary action" style="margin-top:8px; max-width:180px;" value="<?php 
        _e('Change Template', 'total-slider');
        ?>
" />
			</p>
		</div><?php 
    }
 /**
  * Get the Slide Groups, so we can display them in the table.
  *
  * @return array
  *
  */
 public function get_groups()
 {
     $args = array('hide_empty' => false);
     $groups = get_terms('total_slider_slide_group', $args);
     // load template information
     if (is_array($groups) && count($groups) > 0) {
         foreach ($groups as $group) {
             $group_object = new Total_Slide_Group($group->slug);
             $group_object->load();
             $group->template = $group_object->template;
             $group->templateLocation = $group_object->templateLocation;
         }
     }
     return $groups;
 }
Exemple #6
0
<h1><?php 
    _e('This page is not accessible to your user.', 'total-slider');
    ?>
</h1><?php 
    return;
}
$TS_Total_Slider->slug = $TS_Total_Slider->sanitize_slide_group_slug($_GET['group']);
if (empty($TS_Total_Slider->slug)) {
    echo '<div class="wrap"><h1>';
    _e('No Slide Group selected.', 'total-slider');
    echo '</h1></div>';
    return;
}
// get the name data for this slide group based on its slug
$slide_group = new Total_Slide_Group($TS_Total_Slider->slug);
if (!$slide_group->load()) {
    echo '<div class="wrap"><h1>';
    _e('Could not load the selected Slide Group. Does it exist?', 'total-slider');
    echo '</h1></div>';
    return;
}
// determine and load template
if (!$TS_Total_Slider->template || !is_a($TS_Total_Slider->template, 'Total_Slider_Template')) {
    $TS_Total_Slider->determine_template();
}
if ('post' == strtolower($_SERVER['REQUEST_METHOD']) && array_key_exists('action', $_GET) && 'changeTemplate' == $_GET['action']) {
    // change the template and redirect
    if (!wp_verify_nonce($_POST['total-slider-change-template-nonce'], 'total-slider-change-template')) {
        die(__('Unable to confirm the form’s security.', 'total-slider'));
    }
    // update the new template
}
// get the group that we are supposed to be acting on
if (array_key_exists('group', $_GET)) {
    $slug = $_GET['group'];
} else {
    $slug = '';
}
if (empty($slug)) {
    header('HTTP/1.0 400 Bad Request');
    header('Content-Type: application/json');
    echo json_encode(array('error' => __('You did not supply the slide group to which this action should be applied.', 'total-slider')));
    die;
}
try {
    $g = new Total_Slide_Group($slug);
    if (!$g->load()) {
        header('HTTP/1.0 400 Bad Request');
        header('Content-Type: application/json');
        echo json_encode(array('error' => __('Could not load the selected Slide Group. Does it exist?', 'total-slider')));
        die;
    }
} catch (Exception $e) {
    header('HTTP/1.0 400 Bad Request');
    header('Content-Type: application/json');
    echo json_encode(array('error' => $e->getMessage()));
    die;
}
switch ($_GET['action']) {
    case 'createNewSlide':
        if (!current_user_can(TOTAL_SLIDER_REQUIRED_CAPABILITY)) {
            header('HTTP/1.0 403 Forbidden');