. * * @package ReduxFramework * @subpackage Field_slides * @author Luciano "WebCaos" Ubertini * @author Daniel J Griffiths (Ghost1227) * @author Dovy Paukstys * @version 3.0.0 */ // Exit if accessed directly if (!defined('ABSPATH')) exit; // Don't duplicate me! if (!class_exists('ReduxFramework_slideshow')) { /** * Main ReduxFramework_slideshow class * * @since 1.0.0 */ class ReduxFramework_slideshow extends widget_handler{ var $titles = array(); var $field_id = ""; /** * Field Constructor. * * Required - must call the parent constructor, then assign field and value to vars, and obviously call the render field function * * @since 1.0.0 * @access public * @param array $field * @param string $value * @param $parent * @return \ReduxFramework_slideshow */ function __construct( $field = array(), $value ='', $parent ) { parent::__construct($field,$value,$parent); $this->field_id = $this->field['id']; $default_titles = array( 'name'=>"Slider", "add_slider" => "Add Slider", "add_slide" => "Add Slide", "remove_slider" => "Delete Slider", "remove_slide" => "Delete Slide", "new_slide" => "New item", ); if(!isset($this->field['titles']) || !is_array($this->field['titles'])) $this->field['titles'] = array(); $this->titles = wp_parse_args($this->field['titles'],$default_titles); $this->enqueue(); } public function blank_slider(){ echo '"; $this->widget_field(self::$product_selector); $this->widget_field(self::$category_selector); $this->widget_field(self::$url); } /** * Field Render Function. * * Takes the vars and outputs the HTML for the field in the settings * * @since 1.0.0 * @access public * @param bool $hidden * @return void */ public function render($hidden = false) { if($hidden == false) { $this->blank_slider(); if(!isset($this->value['count']) || empty($this->value['count'])) $this->value['count']=1; if(!isset($this->value['sliders']) || empty($this->value['sliders'])) $this->value['sliders']="1"; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; } $x = 0; if(!isset($this->value['items']) || empty($this->value['items'])){ if($this->field_id == "slider_widgets") { $this->value['items'] = array('1' => array('title' => 'Dummy Silder', 'slides' => array( array('title' => 'SLIDE 1', 'image' => 'http://dummyimage.com/300x100/ecf0f1/000000&text=SLIDE 1', 'thumb' => 'http://dummyimage.com/300x100/ecf0f1/000000&text=SLIDE 1' ), array('title' => 'SLIDE 2', 'image' => 'http://dummyimage.com/300x100/ecf0f1/000000&text=SLIDE 2', 'thumb' => 'http://dummyimage.com/300x100/ecf0f1/000000&text=SLIDE 2' ), array('title' => 'SLIDE 3', 'image' => 'http://dummyimage.com/300x100/ecf0f1/000000&text=SLIDE 3', 'thumb' => 'http://dummyimage.com/300x100/ecf0f1/000000&text=SLIDE 3' ) ))); }elseif($this->field_id == "grid_widgets") { $this->value['items'] = array('1' => array('title' => 'Dummy Grid', 'slides' => array( array('title' => 'Grid Item 1', 'image' => 'http://dummyimage.com/200x200/6a97a6/e0e0e0.png&text=GRID+ITEM+1', 'thumb' => 'http://dummyimage.com/200x200/6a97a6/e0e0e0.png&text=GRID+ITEM+1' ), array('title' => 'Grid Item 2', 'image' => 'http://dummyimage.com/200x200/6a97a6/e0e0e0.png&text=GRID+ITEM+2', 'thumb' => 'http://dummyimage.com/200x200/6a97a6/e0e0e0.png&text=GRID+ITEM+2' ), array('title' => 'Grid Item 3', 'image' => 'http://dummyimage.com/200x200/6a97a6/e0e0e0.png&text=GRID+ITEM+3', 'thumb' => 'http://dummyimage.com/200x200/6a97a6/e0e0e0.png&text=GRID+ITEM+3' ), array('title' => 'Grid Item 4', 'image' => 'http://dummyimage.com/200x200/6a97a6/e0e0e0.png&text=GRID+ITEM+4', 'thumb' => 'http://dummyimage.com/200x200/6a97a6/e0e0e0.png&text=GRID+ITEM+4' ), ))); }else{ $this->value['items'] = array('1' => array()); } }else if(isset($this->value['items']['_blank'])) unset($this->value['items']['_blank']); $filed_name = $this->field['name']; $id = $this->field['id']; if(isset($this->value['items'] )){ ksort($this->value['items']); } foreach($this->value['items'] as $key=>$value){ if(!$hidden) { if(empty($value['title'])) $value['title'] = $this->titles['name'].' '.$key; echo '
'.esc_attr($value['title']).''.$id.'_'.$key.'
'; $this->field['name']=$filed_name.'[items]['.$key.']'; $this->field['id']=$id.'_'.$key; }else{ $value['title'] = 'Slider _blank'; } echo '
'; echo ''; echo '
'; echo '
'; if(!$hidden) $this->field['name']=$filed_name.'[items]['.$key.'][slides]'; else $this->field['name']=$filed_name.'[slides]'; if (isset($value['slides']) && is_array($value['slides']) && !$hidden) { $slides = $value['slides']; foreach ($slides as $slide) { if ( empty( $slide ) ) { continue; } $defaults = array( 'title' => '', 'click_action' => '', 'sort' => '', 'click_action_value' => '', 'image' => '', 'thumb' => '', 'attachment_id' => '', 'height' => '', 'width' => '', 'select' => array(), ); $slide = wp_parse_args( $slide, $defaults ); if ( empty( $slide['thumb'] ) && !empty( $slide['attachment_id'] ) ) { $img = wp_get_attachment_image_src($slide['attachment_id'], 'full'); $slide['image'] = $img[0]; $slide['width'] = $img[1]; $slide['height'] = $img[2]; } echo '

' . $slide['title'] . '

'; $hide = ''; if ( empty( $slide['image'] ) ) { $hide = ' hide'; } echo '
'; echo ''; echo ''; echo ''; echo '
'; echo '
'; echo '' . __('Upload', 'redux-framework') . ''; $hide = ''; if ( empty( $slide['image'] ) || $slide['image'] == '' ) { $hide = ' hide'; } echo '' . __('Remove', 'redux-framework') . ''; echo '
' . "\n"; echo '
    '; $placeholder = (isset($this->field['placeholder']['title'])) ? esc_attr($this->field['placeholder']['title']) : __( 'Title', 'redux-framework' ); echo '
  • '; $placeholder = (isset($this->field['placeholder']['click_action'])) ? esc_attr($this->field['placeholder']['click_action']) : __( 'click_action', 'redux-framework' ); echo '
  • '; echo ''; echo '
  • '; echo '
  • '; echo ''; echo ''; echo ''; echo '
  • '; echo '
  • ' . __($this->titles['remove_slide'], 'redux-framework') . '
  • '; echo '
'; $x++; } } if ($x == 0) { echo '

'. __($this->titles['new_slide'], 'redux-framework').'

'; $hide = ' hide'; echo '
'; echo ''; echo ''; echo ''; echo '
'; //Upload controls DIV echo '
'; //If the user has WP3.5+ show upload/remove button echo '' . __('Upload image', 'redux-framework') . ''; echo '' . __('Remove', 'redux-framework') . ''; echo '
' . "\n"; echo '
    '; $placeholder = (isset($this->field['placeholder']['title'])) ? esc_attr($this->field['placeholder']['title']) : __( 'Title', 'redux-framework' ); echo '
  • '; $placeholder = (isset($this->field['placeholder']['click_action'])) ? esc_attr($this->field['placeholder']['click_action']) : __( 'click_action', 'redux-framework' ); echo '
  • '; echo ''; echo '
  • '; echo '
  • '; echo ''; echo ''; echo '
  • '; echo ''; echo '
  • '. __($this->titles['remove_slide'], 'redux-framework').'
  • '; echo '
'; } $id_for_action = ($hidden)?trim($this->field_id,'__blank'):$this->field_id; echo '
' . __($this->titles['add_slide'], 'redux-framework') . '
' . __($this->titles['remove_slider'], 'redux-framework') . ' '.__($this->titles['add_slider'], 'redux-framework').'
'; if(!$hidden) { echo '
'; } } if(!$hidden) { echo "
"; } } /** * Enqueue Function. * * If this field requires any scripts, or css define this function and register/enqueue the scripts/css * * @since 1.0.0 * @access public * @return void */ public function enqueue() { wp_enqueue_script( 'redux-field-media-js', ReduxFramework::$_url . 'assets/js/media/media.min.js', array( 'jquery', 'redux-js' ), time(), true ); wp_enqueue_style( 'redux-field-media-css', ReduxFramework::$_url . 'inc/fields/media/field_media.css', time(), true ); wp_enqueue_script( 'redux-field-slideshow-js', plugins_url('field_slides.js',__FILE__), array('jquery', 'jquery-ui-core', 'jquery-ui-accordion', 'wp-color-picker'), time(), true ); wp_enqueue_style( 'redux-field-slideshow-css', plugins_url('field_slides.css',__FILE__), time(), true ); parent::enqueue(); } } }