/**
  * Get data for a specified theme.
  * @since  1.0.4
  * @param  array $args  Arguments for the current slideshow.
  * @return string       The slug of the theme, or 'default'.
  */
 public function get_theme_data($key)
 {
     $theme = array('name' => 'default', 'stylesheet' => '');
     if (in_array($key, array_keys(WooSlider_Utils::get_slider_themes()))) {
         $themes = WooSlider_Utils::get_slider_themes();
         $theme = $themes[esc_attr($key)];
     }
     return $theme;
 }
Пример #2
0
    /**
     * Fields specific to the "Add Media" popup.
     * @since  1.0.0
     * @return void
     */
    public function popup_fields()
    {
        $types = WooSlider_Utils::get_slider_types();
        $slider_types = array();
        foreach ((array) $types as $k => $v) {
            $slider_types[$k] = $v['name'];
        }
        ?>
	<table class="form-table">
		<tbody>
			<tr valign="top">
				<th scope="row"><?php 
        _e('Slideshow Type', 'wooslider');
        ?>
</th>
				<td><select id="slider_type" name="wooslider-settings[slider_type]">
					<?php 
        foreach ((array) $slider_types as $k => $v) {
            echo '<option value="' . esc_attr($k) . '">' . $v . '</option>' . "\n";
        }
        ?>
					</select>
					<p><span class="description"><?php 
        _e('The type of slideshow to insert', 'wooslider');
        ?>
</span></p>
				</td>
			</tr>
			<?php 
        // Theming engine integration.
        $themes = WooSlider_Utils::get_slider_themes();
        if (is_array($themes) && 1 < count($themes)) {
            ?>
			<tr valign="top">
				<th scope="row"><?php 
            _e('Slideshow Theme', 'wooslider');
            ?>
</th>
				<td><select id="theme" name="wooslider-settings[theme]">
					<?php 
            foreach ((array) $themes as $k => $v) {
                echo '<option value="' . esc_attr($k) . '">' . $v['name'] . '</option>' . "\n";
            }
            ?>
					</select>
					<p><span class="description"><?php 
            _e('The desired slideshow theme', 'wooslider');
            ?>
</span></p>
				</td>
			</tr>
			<?php 
        }
        ?>
			<tr valign="top">
				<th scope="row"><?php 
        _e('Slideshow ID', 'wooslider');
        ?>
</th>
				<td><input type="text" name="wooslider-settings[id]" id="id" value="" />
					<p><span class="description"><?php 
        _e('Give this slideshow a specific ID (optional)', 'wooslider');
        ?>
</span></p>
				</td>
			</tr>
		</tbody>
	</table>
<?php 
        // Allow themes/plugins to act here.
        do_action('wooslider_popup_conditional_fields', $types);
    }
    /**
     * form function.
     * 
     * @since  1.0.0
     * @access public
     * @param array $instance
     * @uses  global $wooslider object
     * @return void
     */
    public function form($instance)
    {
        global $wooslider;
        /* Set up some default widget settings. */
        /* Make sure all keys are added here, even with empty string values. */
        $defaults = $this->defaults;
        // Allow child themes/plugins to filter here.
        $defaults = apply_filters($this->woo_widget_idbase . '_widget_defaults', $defaults, $this);
        $defaults['show_advanced_settings'] = 0;
        $defaults['theme'] = 'default';
        $advanced_fields = array();
        $wooslider->settings->init_fields();
        $advanced_fields = $wooslider->settings->fields;
        if (is_array($advanced_fields) && count($advanced_fields) > 0) {
            foreach ($advanced_fields as $k => $v) {
                if (!isset($defaults[$k])) {
                    $defaults[$k] = $v['default'];
                }
            }
        }
        $has_fields = false;
        if (isset($this->slider_type) && $this->slider_type != '') {
            $fields = $wooslider->admin->generate_default_conditional_fields(array($this->slider_type => $this->slider_type));
            $has_fields = true;
            if (0 < count($fields)) {
                foreach ($fields[$this->slider_type] as $k => $v) {
                    if (isset($v['args']['data']['default'])) {
                        $defaults[$k] = $v['args']['data']['default'];
                    }
                }
            }
        }
        // Get the supported themes.
        $themes = WooSlider_Utils::get_slider_themes();
        $instance = wp_parse_args($instance, $defaults);
        ?>
		<!-- Widget Title: Text Input -->
		<p>
			<label for="<?php 
        echo $this->get_field_id('title');
        ?>
"><?php 
        _e('Title (optional):', 'wooslider');
        ?>
</label>
			<input type="text" name="<?php 
        echo $this->get_field_name('title');
        ?>
"  value="<?php 
        echo $instance['title'];
        ?>
" class="widefat" id="<?php 
        echo $this->get_field_id('title');
        ?>
" />
		</p>
		<?php 
        if (is_array($themes) && 1 < count($themes)) {
            ?>
		<!-- Widget Theme: Select Input -->
		<p>
			<label for="<?php 
            echo $this->get_field_id('theme');
            ?>
"><?php 
            _e('Slider Theme:', 'wooslider');
            ?>
</label>
			<select name="<?php 
            echo $this->get_field_name('theme');
            ?>
" class="widefat" id="<?php 
            echo $this->get_field_id('theme');
            ?>
">
				<?php 
            foreach ($themes as $k => $v) {
                ?>
					<option value="<?php 
                echo esc_attr($k);
                ?>
"<?php 
                selected($instance['theme'], $k);
                ?>
><?php 
                echo $v['name'];
                ?>
</option> 
				<?php 
            }
            ?>
      
			</select>
		</p>
		<?php 
        } else {
            echo '<input type="hidden" name="' . esc_attr($this->get_field_name('theme')) . '" id="' . esc_attr($this->get_field_id('theme')) . '" value="' . esc_attr($instance['theme']) . '" />' . "\n";
        }
        ?>
		<?php 
        if (isset($this->slider_type) && $this->slider_type != '') {
            foreach ($fields[$this->slider_type] as $k => $v) {
                ?>
		<p>
			<?php 
                $field_label = '<label for="' . esc_attr($k) . '">' . $v['name'] . '</label>' . "\n";
                if ($v['type'] != 'checkbox') {
                    echo $field_label;
                }
                // Display the label first if the field isn't a checkbox.
                $this->generate_field_by_type($v['type'], $v['args'], $instance);
                if ($v['type'] == 'checkbox') {
                    echo $field_label;
                }
                // Display the label last if the field is a checkbox.
                ?>
		</p>
		<?php 
            }
            ?>
		<hr />
		<!-- Widget Advanced Fields: Text Input -->
		<p>
			<input type="checkbox" name="<?php 
            echo $this->get_field_name('show_advanced_settings');
            ?>
"  value="1" id="<?php 
            echo $this->get_field_id('show_advanced_settings');
            ?>
" <?php 
            checked('1', $instance['show_advanced_settings']);
            ?>
 />
			<label for="<?php 
            echo $this->get_field_id('show_advanced_settings');
            ?>
"><?php 
            _e('Customise Advanced Settings', 'wooslider');
            ?>
</label>
		</p>
		<p><small><?php 
            _e('Save the widget settings with this checkbox checked to customise slider settings.', 'wooslider');
            ?>
</small></p>
		<?php 
            if (isset($instance['show_advanced_settings']) && $instance['show_advanced_settings'] == 1) {
                if (is_array($advanced_fields) && count($advanced_fields) > 0) {
                    foreach ($advanced_fields as $k => $v) {
                        echo '<p>' . "\n";
                        $label = $v['name'];
                        if ($label == '') {
                            $label = $v['description'];
                        }
                        $field_label = '<label for="' . esc_attr($k) . '">' . $label . '</label>' . "\n";
                        if ($v['type'] != 'checkbox') {
                            echo $field_label;
                        }
                        // Display the label first if the field isn't a checkbox.
                        $this->generate_field_by_type($v['type'], array('key' => $k, 'data' => $v), $instance);
                        if ($v['type'] == 'checkbox') {
                            echo $field_label;
                        }
                        // Display the label last if the field is a checkbox.
                        echo '</p>' . "\n";
                    }
                }
            } else {
                if (is_array($advanced_fields) && count($advanced_fields) > 0) {
                    foreach ($advanced_fields as $k => $v) {
                        echo '<input type="hidden" name="' . esc_attr($this->get_field_name($k)) . '" id="' . esc_attr($this->get_field_id($k)) . '" value="' . esc_attr($instance[$k]) . '" />' . "\n";
                    }
                }
            }
        }
        // Allow child themes/plugins to act here.
        do_action($this->woo_widget_idbase . '_widget_settings', $instance, $this);
    }