<?php /**
 * Redux Framework is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * any later version.
 *
 * Redux Framework is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Redux Framework. If not, see <http://www.gnu.org/licenses/>.
 *
 * @package     ReduxFramework
 * @subpackage  Field_Border
 * @author      Daniel J Griffiths (Ghost1227)
 * @author      Dovy Paukstys (dovy)
 * @version     3.0.0
 */

// Exit if accessed directly
if( !defined( 'ABSPATH' ) ) exit;

// Don't duplicate me!
if( !class_exists( 'ReduxFramework_border' ) ) {

    /**
     * Main ReduxFramework_border class
     *
     * @since       1.0.0
     */
    class ReduxFramework_border extends ReduxFramework{ 
    
        /**
         * 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       array $value
         * @param       array $parent
         * @return      void
         */
        public function __construct( $field = array(), $value = '', $parent ) {
        
            parent::__construct( $parent-&gt;sections, $parent-&gt;args, $parent-&gt;extra_tabs );
        
            $this-&gt;field = $field;
            $this-&gt;value = $value;      
        }

    
        /**
         * Field Render Function.
         *
         * Takes the vars and outputs the HTML for the field in the settings
         *
         * @since ReduxFramework 1.0.0
         * @access      public
         * @return      void
         */
        public function render() {

            // No errors please
            $defaults = array(
                'border-color' =&gt; '',
                'border-style' =&gt; '',
                'border-width'  =&gt; '',
                'units'         =&gt; 'px'
                );
            $this-&gt;field = wp_parse_args( $this-&gt;field, $defaults );
            $this-&gt;value = wp_parse_args( $this-&gt;value, $defaults );

            if ( empty( $this-&gt;value['units'] ) || ( !in_array($this-&gt;value['units'], array( '%, in, cm, mm, em, ex, pt, pc, px' ) ) ) ) {
                if ( empty( $this-&gt;field['units'] ) || ( !in_array($this-&gt;field['units'], array( '%, in, cm, mm, em, ex, pt, pc, px' ) ) ) ) {
                    $this-&gt;field['units'] = "px";
                }
                $this-&gt;value['units'] = $this-&gt;field['units'];
            }            

            if( empty( $this-&gt;field['min'] ) )
                $this-&gt;field['min'] = 0;
        
            if( empty( $this-&gt;field['max'] ) )
                $this-&gt;field['max'] = 10;
       
            

            $options = array(
                ''          =&gt; 'None',
                'solid'     =&gt; 'Solid',
                'dashed'    =&gt; 'Dashed',
                'dotted'    =&gt; 'Dotted'
            );

            echo '<div class="redux-border">';
        
	            echo '<select original-title="' . __( 'Border size', 'redux-framework' ) . '" id="' . $this-&gt;field['id'] . '[border-width]" name="' . $this-&gt;args['opt_name'] . '[' . $this-&gt;field['id'] . '][border-width]" class="tips redux-border-size mini' . $this-&gt;field['class'] . '" rows="6" data-id="'.$this-&gt;field['id'].'">';

	            for( $k = $this-&gt;field['min']; $k field['max']; $k++ ) {
	                echo '<option value="' . $k.$this-&gt;field['units'] . '" . selected>value['border-width'], $k.$this-&gt;field['units'], false) . '&gt;' . $k . '</option>';
	            }

	            echo '</select>';

	            echo '<select original-title="' . __( 'Border style', 'redux-framework' ) . '" id="' . $this-&gt;field['id'] . '[border-style]" name="' . $this-&gt;args['opt_name'] . '[' . $this-&gt;field['id'] . '][border-style]" class="tips redux-border-style' . $this-&gt;field['class'] . '" rows="6" data-id="'.$this-&gt;field['id'].'">';

	            foreach( $options as $k =&gt; $v ) {
	                echo '<option value="' . $k . '" . selected>value['border-style'], $k, false ) . '&gt;' . $v . '</option>';
	            }

	            echo '</select>';   

	            echo '<input name="' . $this-&gt;args['opt_name'] . '[' . $this-&gt;field['id'] . '][border-color]" id="' . $this-&gt;field['id'] . '-border" class="redux-border-color redux-color redux-color-init ' . $this-&gt;field['class'] . '" type="text" value="' . $this-&gt;value['border-color'] . '" data-default-color="' . $this-&gt;field['border-color'] . '" data-id="'.$this-&gt;field['id'].'">';
	            
	        
            
            echo '</div>';
        }
    
        /**
         * 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-color-js', 
                ReduxFramework::$_url . 'inc/fields/color/field_color.min.js', 
                array( 'jquery', 'wp-color-picker' ),
                time(),
                true
            );

            wp_enqueue_style(
                'redux-field-color-css', 
                ReduxFramework::$_url . 'inc/fields/color/field_color.css', 
                time(),
                true
            );      
        
            wp_enqueue_style(
                'redux-field-border-css', 
                ReduxFramework::$_url . 'inc/fields/border/field_border.css', 
                time(),
                true
            );

        }

        public function output() {
            if ( !isset($this-&gt;field['output']) || empty( $this-&gt;field['output'] ) ) {
                return;
            }

            $keys = implode(",", $this-&gt;field['output']);

            $style = '<style type="text/css" class="redux-'.$this-&gt;field['type'].'">';
                $style .= $keys."{";
                foreach($this->value as $key=>$value) {
                    if (empty($value)) {
                        $value = 0;
                    }
                    $style .= $key.':'.$value.';';
                }
                $style .= '}';
            $style .= '</style>';
            echo $style;
            
        }

    }
}