Plugin Directory

Changeset 1461229


Ignore:
Timestamp:
07/27/2016 08:03:15 AM (9 years ago)
Author:
tranthethang
Message:

1.1.5

  • Add new metabox-field: gallery_sortable
Location:
kopatheme/trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • kopatheme/trunk/assets/css/widget.css

    r1428092 r1461229  
    10531053  color: #999;
    10541054}
     1055
     1056.kf-ui-gallery ul {
     1057  margin: 0px;
     1058  padding: 0px;
     1059}
     1060.kf-ui-gallery ul li {
     1061  display: inline-block;
     1062  *display: inline-block;
     1063  zoom: 1;
     1064  margin: 0px 6px 6px 0px;
     1065  position: relative;
     1066  padding: 2px;
     1067  border: 1px solid #e5e5e5;
     1068  background-color: #fafafa;
     1069  width: 90px;
     1070  height: 90px;
     1071}
     1072.kf-ui-gallery ul li:hover .kf-ui-gallery__remove {
     1073  display: block;
     1074  background-color: #F9A825;
     1075}
     1076.kf-ui-gallery ul li img {
     1077  display: block;
     1078  width: 100%;
     1079  height: 100%;
     1080}
     1081.kf-ui-gallery .kf-ui-gallery__remove {
     1082  display: none;
     1083  position: absolute;
     1084  top: 50%;
     1085  right: 50%;
     1086  margin-top: -12px;
     1087  margin-right: -12px;
     1088  width: 24px;
     1089  height: 24px;
     1090  line-height: 24px;
     1091  border: 1px solid #F9A825;
     1092  background-color: #FBC02D;
     1093  color: #fff;
     1094  font-size: 13px;
     1095  -webkit-border-radius: 5px;
     1096  -moz-border-radius: 5px;
     1097  border-radius: 5px;
     1098  cursor: pointer;
     1099}
  • kopatheme/trunk/assets/css/widget.scss

    r1428092 r1461229  
    10371037    color: #999;
    10381038}
     1039
     1040.kf-ui-gallery{
     1041    ul{
     1042        margin: 0px;
     1043        padding: 0px;
     1044        li{
     1045            display: inline-block;
     1046            *display: inline-block;
     1047            zoom: 1;
     1048            margin: 0px 6px 6px 0px;           
     1049            position: relative;
     1050            padding: 2px;
     1051            border: 1px solid #e5e5e5;
     1052            background-color: #fafafa;
     1053            width: 90px;
     1054            height: 90px;
     1055
     1056            &:hover{
     1057                .kf-ui-gallery__remove{
     1058                    display: block;
     1059                    background-color: #F9A825;
     1060                }
     1061            }
     1062
     1063            img{
     1064                display: block;
     1065                width: 100%;
     1066                height: 100%;
     1067            }
     1068        }
     1069    }
     1070
     1071    .kf-ui-gallery__remove{
     1072        display: none;
     1073        position: absolute;
     1074        top: 50%;
     1075        right: 50%;
     1076        margin-top: -12px;
     1077        margin-right: -12px;       
     1078        width: 24px;
     1079        height: 24px;
     1080        line-height: 24px;
     1081        border: 1px solid #F9A825;
     1082        background-color: #FBC02D; 
     1083        color: #fff;
     1084        font-size: 13px;
     1085        -webkit-border-radius: 5px;       
     1086        -moz-border-radius: 5px;       
     1087        border-radius: 5px;     
     1088        cursor: pointer;   
     1089    }
     1090
     1091}
  • kopatheme/trunk/assets/js/custom-advanced-fields.js

    r1353276 r1461229  
    33
    44/* gallery */
    5 var FK_Gallery, kf_gallery_iframe, kf_gallery_button;
     5var KF_UI_Gallery, kf_gallery_iframe, kf_gallery_button;
    66kf_gallery_iframe = '';
    77kf_gallery_button = '';
     
    1515    KF_Datetime_Js.init_field_datetime();
    1616
    17     FK_Gallery.init();
     17    KF_UI_Gallery.init();
    1818
    1919    KF_Icon_Picker.init();
     
    2323    KF_Datetime_Js.init_field_datetime();
    2424
    25     FK_Gallery.init();
     25    KF_UI_Gallery.init();
    2626
    2727    KF_Icon_Picker.init();
     
    6161};
    6262
    63 FK_Gallery = {
     63KF_UI_Gallery = {
    6464    init: function() {
    6565        jQuery('.kopa-framework-gallery-box').on('click', '.kopa-framework-gallery-config', function(event) {
  • kopatheme/trunk/assets/js/custom-advanced-fields.min.js

    r1353276 r1461229  
    1 /* datetime */
    2 var KF_Datetime_Js;
    3 
    4 /* gallery */
    5 var FK_Gallery, kf_gallery_iframe, kf_gallery_button;
    6 kf_gallery_iframe = '';
    7 kf_gallery_button = '';
    8 
    9 /* icon picker */
    10 var KF_Icon_Picker;
     1var KF_Icon_Picker, KF_Datetime_Js, KF_UI_Gallery, kf_gallery_iframe, kf_gallery_button;
     2
     3var kf_gallery_sortable_uploader;
     4var kf_gallery_iframe;
     5var kf_gallery_button;
    116var kf_lighbox_icons_id = '#kf_advanced_field_lighbox_icons';
    127
    13 
    14 jQuery(document).ready(function() {
    15     KF_Datetime_Js.init_field_datetime();
    16 
    17     FK_Gallery.init();
    18 
    19     KF_Icon_Picker.init();
     8jQuery( document ).ready( function() {
     9    KF_UI.init();
    2010});
    2111
    22 jQuery(document).ajaxSuccess(function() {
    23     KF_Datetime_Js.init_field_datetime();
    24 
    25     FK_Gallery.init();
    26 
    27     KF_Icon_Picker.init();
     12jQuery( document ).ajaxSuccess( function() {
     13    KF_UI.init();
    2814});
    2915
    30 KF_Datetime_Js = {
     16var KF_UI = {
     17    init: function (){
     18        KF_Datetime_Js.init_field_datetime();
     19        KF_UI_Gallery.init();
     20        KF_UI_Gallery_Sortable.init();
     21        KF_Icon_Picker.init();
     22    }
     23}
     24
     25var KF_Datetime_Js = {
    3126    init_field_datetime: function() {
    3227        if (jQuery('.kopa-framework-datetime').length > 0) {
     
    6156};
    6257
    63 FK_Gallery = {
     58var KF_UI_Gallery = {
    6459    init: function() {
    6560        jQuery('.kopa-framework-gallery-box').on('click', '.kopa-framework-gallery-config', function(event) {
     
    112107};
    113108
    114 KF_Icon_Picker = {
     109var KF_Icon_Picker = {
    115110    init: function() {
    116         /*if (jQuery('.upside-icon-picker-select').length > 0) {
    117          jQuery('.upside-icon-picker-select').change(function(event){
    118          var btn = jQuery(this);
    119          var icon = btn.val();
    120          console.log(icon);
    121          btn.parent().find('.upside-icon-picker-preview i').attr('class', icon);
    122          });
    123          }*/
    124 
    125111        if (jQuery('.kf-icon-picker').length > 0) {
    126112            jQuery('.kf-icon-picker').click(function(event) {
     
    201187    }
    202188};
     189
     190var KF_UI_Gallery_Sortable = {
     191    init: function() {
     192        $galleries = jQuery( 'div.kf-ui-gallery' );
     193        if( $galleries.length ) {
     194           
     195            $galleries.map( function( $gallery ) {
     196                KF_UI_Gallery_Sortable._init_sortable( jQuery(this).find('ul').first() );
     197            } );
     198   
     199            $galleries.on( 'click', '.kf-ui-gallery__upload', function( $event ) {
     200                KF_UI_Gallery_Sortable._edit( $event, jQuery(this) );
     201            } );
     202
     203            $galleries.on( 'click', '.kf-ui-gallery__remove', function( $event ) {
     204                KF_UI_Gallery_Sortable._remove( $event, jQuery(this) );
     205            } );
     206        }
     207    },
     208    _edit: function( $event, $button ) {
     209        $event.preventDefault();       
     210
     211        $wrap         = $button.parents('.kf-ui-gallery');
     212        $sortable     = $wrap.find( 'ul' ).first();
     213        $inputs       = $wrap.find( 'input[type="hidden"]' );
     214        $previews     = $wrap.find( 'img' );
     215        $gallery_name = $wrap.attr( 'data-name' );
     216
     217        if (kf_gallery_sortable_uploader) {
     218            kf_gallery_sortable_uploader.open();
     219            return;
     220        }
     221
     222        kf_gallery_sortable_uploader = wp.media.frames.kf_gallery_sortable_uploader = wp.media({
     223            title: 'Uploader',
     224            $button: {
     225                text: 'Select'
     226            },
     227            library: { type: 'image' },
     228            multiple: true
     229        });
     230
     231        kf_gallery_sortable_uploader.on( 'open', function() {
     232
     233            if( $inputs.length ) {
     234
     235                selection = kf_gallery_sortable_uploader.state().get('selection');             
     236                jQuery.each( $inputs, function(){
     237                    var attachment = wp.media.attachment( parseInt( jQuery(this).val() ) );
     238                    attachment.fetch();
     239                    selection.add( attachment );
     240                } );
     241                             
     242            }
     243        });
     244
     245        kf_gallery_sortable_uploader.on( 'select', function() {
     246           
     247            var $results  = [];         
     248            var selection = kf_gallery_sortable_uploader.state().get('selection');
     249
     250            selection.map( function( $attachment ) {
     251                $attachment = $attachment.toJSON();
     252                $results.push( [ $attachment.id, $attachment.sizes.thumbnail.url] );
     253            });
     254            console.log($results);
     255            if ( $results.length ) {
     256                $sortable.html( '' );
     257
     258                $results.map( function( $image ) {
     259                    $html = KF_UI_Gallery_Sortable._build_single( $gallery_name, $image[0], $image[1] );
     260                    $sortable.append( jQuery( $html ) );
     261                } );
     262            }
     263
     264        });
     265
     266        kf_gallery_sortable_uploader.open();
     267    },
     268    _remove: function( $event, $button ) {
     269        $event.preventDefault();       
     270        $button.closest('.kf-ui-gallery__image').remove();     
     271    },
     272    _build_single: function( $gallery_name, $image_id, $image_src ){
     273
     274        $html = '<li class="kf-ui-gallery__image">';
     275        $html += '<input type="hidden" value="' + $image_id + '" name="' + $gallery_name + '[]">';
     276        $html += '<img alt="" src="' + $image_src + '">';
     277        $html += '<span class="kf-ui-gallery__remove dashicons dashicons-trash">';
     278        $html += '</span>';
     279        $html += '</li>';
     280
     281        return $html;
     282    },
     283    _init_sortable: function( $sortable ) {
     284        $sortable.sortable({
     285            containment: 'parent'
     286        });
     287        $sortable.disableSelection();
     288    }
     289}
  • kopatheme/trunk/includes/admin/class-kopa-admin-assets.php

    r1353276 r1461229  
    5252        wp_register_style( 'kopa_widget', KF()->framework_url() . '/assets/css/widget.css', array(), KOPA_FRAMEWORK_VERSION );
    5353
    54         // Advanced field
    55         $advanced_field = apply_filters('kopa_admin_metabox_advanced_field', false);
    56         if ( $advanced_field ) {
    57             wp_register_style( 'kopa_datetimepicker', KF()->framework_url() . '/assets/css/jquery.datetimepicker.css', array(), KOPA_FRAMEWORK_VERSION );
    58             wp_register_style( 'kopa_font_flaticon', KF()->framework_url() . '/assets/css/flaticon.css', array(), KOPA_FRAMEWORK_VERSION );
    59 
    60             wp_register_style('kopa_jquery_ui', KF()->framework_url() . "/assets/css/jquery-ui/jquery-ui.css", array(), NULL);
    61             wp_register_style('kopa_jquery_ui_structure', KF()->framework_url() . "/assets/css/jquery-ui/jquery-ui.structure.css", array(), NULL);
    62             wp_register_style('kopa_jquery_ui_theme', KF()->framework_url() . "/assets/css/jquery-ui/jquery-ui.theme.css", array(), NULL);
    63         }
    64 
     54    // Advanced field
     55    $advanced_field = apply_filters('kopa_admin_metabox_advanced_field', false);
     56    if ( $advanced_field ) {
     57      wp_register_style( 'kopa_datetimepicker', KF()->framework_url() . '/assets/css/jquery.datetimepicker.css', array(), KOPA_FRAMEWORK_VERSION );
     58      wp_register_style( 'kopa_font_flaticon', KF()->framework_url() . '/assets/css/flaticon.css', array(), KOPA_FRAMEWORK_VERSION );
     59    }
    6560
    6661        if(in_array($hook, array('widgets.php', 'post.php', 'post-new.php'))){
    6762            wp_enqueue_style( 'kopa_widget' );
    68             if ( $advanced_field ) {
    69                 wp_enqueue_style( 'kopa_datetimepicker' );
    70                 wp_enqueue_style( 'kopa_font_awesome' );
    71                 wp_enqueue_style( 'kopa_font_flaticon' );
    72                 wp_enqueue_style( 'kopa_jquery_ui' );
    73                 wp_enqueue_style( 'kopa_jquery_ui_structure' );
    74                 wp_enqueue_style( 'kopa_jquery_ui_theme' );
    75                 wp_enqueue_script('jquery-ui-core');
    76                 wp_enqueue_script('jquery-ui-dialog');
    77                 wp_enqueue_script('jquery-ui-position');
    78                 wp_enqueue_script('jquery-ui-droppable');
    79                 wp_enqueue_script('jquery-ui-draggable');
    80             }
     63      if ( $advanced_field ) {
     64          wp_enqueue_style( 'kopa_datetimepicker' );
     65          wp_enqueue_style( 'kopa_font_awesome' );
     66          wp_enqueue_style( 'kopa_font_flaticon' );
     67          wp_enqueue_style( 'kopa_jquery_ui' );
     68          wp_enqueue_style( 'kopa_jquery_ui_structure' );
     69          wp_enqueue_style( 'kopa_jquery_ui_theme' );
     70
     71          wp_enqueue_script( 'jquery-ui-core' );
     72          wp_enqueue_script( 'jquery-ui-dialog' );
     73          wp_enqueue_script( 'jquery-ui-position' );
     74          wp_enqueue_script( 'jquery-ui-droppable' );
     75          wp_enqueue_script( 'jquery-ui-draggable' );
     76      }
    8177        }
    8278
     
    10298        global $wp_query, $post;
    10399
    104         $screen       = get_current_screen();
    105         $suffix       = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
    106         // $suffix       = false ? '' : '.min';
     100        $screen = get_current_screen();
     101        $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
    107102
    108103        // Register scripts
     
    118113        wp_register_script( 'kopa_media_uploader', KF()->framework_url() . '/assets/js/media-uploader'.$suffix.'.js', array( 'jquery' ), KOPA_FRAMEWORK_VERSION );
    119114
    120         // script for advanced fields
    121         $advanced_field = apply_filters('kopa_admin_metabox_advanced_field', false);
    122         if ( $advanced_field ) {
    123             wp_register_script( 'kopa_datetimepicker', KF()->framework_url() . '/assets/js/jquery.datetimepicker'.$suffix.'.js', array( 'jquery' ), KOPA_FRAMEWORK_VERSION );
    124             wp_register_script( 'kopa_custom_advanced_fields', KF()->framework_url() . '/assets/js/custom-advanced-fields'.$suffix.'.js', array( 'jquery' ), KOPA_FRAMEWORK_VERSION );
    125             wp_register_script( 'kopa_custom_advanced_fields_gallery', KF()->framework_url() . '/assets/js/gallery'.$suffix.'.js', array( 'jquery' ), KOPA_FRAMEWORK_VERSION );
    126             wp_register_script( 'kopa_custom_advanced_fields_icon_picker', KF()->framework_url() . '/assets/js/icon_picker'.$suffix.'.js', array( 'jquery' ), KOPA_FRAMEWORK_VERSION );
    127         }
     115    // script for advanced fields
     116    $advanced_field = apply_filters('kopa_admin_metabox_advanced_field', false);
     117    if ( $advanced_field ) {
     118        wp_register_script( 'kopa_datetimepicker', KF()->framework_url() . '/assets/js/jquery.datetimepicker'.$suffix.'.js', array( 'jquery' ), KOPA_FRAMEWORK_VERSION );
     119        wp_register_script( 'kopa_custom_advanced_fields', KF()->framework_url() . '/assets/js/custom-advanced-fields'.$suffix.'.js', array( 'jquery' ), KOPA_FRAMEWORK_VERSION );
     120        wp_register_script( 'kopa_custom_advanced_fields_gallery', KF()->framework_url() . '/assets/js/gallery'.$suffix.'.js', array( 'jquery' ), KOPA_FRAMEWORK_VERSION );
     121        wp_register_script( 'kopa_custom_advanced_fields_icon_picker', KF()->framework_url() . '/assets/js/icon_picker'.$suffix.'.js', array( 'jquery' ), KOPA_FRAMEWORK_VERSION );
     122    }
    128123
    129124        // KopaFramework admin pages
  • kopatheme/trunk/includes/admin/class-kopa-admin-meta-box.php

    r1456755 r1461229  
    1515if ( ! class_exists( 'Kopa_Admin_Meta_Box' ) ) {
    1616
    17 /**
    18  * Kopa_Admin_Meta_Box Class
    19  */
    20 class Kopa_Admin_Meta_Box {
    21 
    2217    /**
    23      * @access private
    24      * @var array meta boxes settings
     18     * Kopa_Admin_Meta_Box Class
    2519     */
    26     private $settings = array();
    27 
    28     /**
    29      * Constructor
    30      *
    31      * @since 1.0.5
    32      * @access public
    33      */
    34     public function __construct( $settings ) {
    35         $this->settings = $settings;
    36 
    37         add_action( 'admin_enqueue_scripts', array( $this, 'meta_box_scripts' ) );
    38         add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) );
    39         add_action( 'save_post', array( $this, 'save_meta_boxes' ), 1, 2 );
    40     }
    41 
    42     /**
    43      * Metabox scripts
    44      *
    45      * @since 1.0.5
    46      * @access public
    47      */
    48     public function meta_box_scripts() {
    49         $screen = get_current_screen();
    50         $metabox = $this->settings;
    51 
    52         if ( in_array( $screen->id, (array) $metabox['pages'] ) ) {
    53             wp_enqueue_script( 'kopa_media_uploader' );
     20    class Kopa_Admin_Meta_Box {
     21
     22        /**
     23         * @access private
     24         * @var array meta boxes settings
     25         */
     26        private $settings = array();
     27
     28        /**
     29         * Constructor
     30         *
     31         * @since 1.0.5
     32         * @access public
     33         */
     34        public function __construct( $settings ) {
     35            $this->settings = $settings;
     36
     37            add_action( 'admin_enqueue_scripts', array( $this, 'meta_box_scripts' ) );
     38            add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) );
     39            add_action( 'save_post', array( $this, 'save_meta_boxes' ), 1, 2 );
    5440        }
    55     }
    56 
    57     /**
    58      * Add metaboxes
    59      *
    60      * @since 1.0.5
    61      * @access public
    62      */
    63     public function add_meta_boxes() {
    64         $metabox = $this->settings;
    65 
    66         foreach ( (array) $metabox['pages'] as $page ) {
    67             add_meta_box( $metabox['id'], $metabox['title'], array( $this, 'output' ), $page, $metabox['context'], $metabox['priority'], $metabox['fields'] );
    68         }
    69     }
    70 
    71     /**
    72      * Check if we're saving, the trigger an action based on the post type
    73      *
    74      * @param  int $post_id
    75      * @param  object $post
    76      *
    77      * @since 1.0.5
    78      * @access public
    79      */
    80     public function save_meta_boxes( $post_id, $post ) {
    81         $metabox = $this->settings;
    82 
    83         /* don't save if $_POST is empty */
    84         if ( empty( $_POST ) )
    85             return $post_id;
    86 
    87         /* don't save during autosave */
    88         if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
    89             return $post_id;
    90 
    91         /* verify nonce */
    92         if ( ! isset( $_POST[ $metabox['id'] . '_nonce'] ) || ! wp_verify_nonce( $_POST[ $metabox['id'] . '_nonce'], $metabox['id'] ) )
    93             return $post_id;
    94 
    95         /* check permissions */
    96         if ( isset( $_POST['post_type'] ) && 'page' == $_POST['post_type'] ) {
    97             if ( ! current_user_can( 'edit_page', $post_id ) )
    98                 return $post_id;
    99         } else {
    100             if ( ! current_user_can( 'edit_post', $post_id ) )
    101                 return $post_id;
    102         }
    103 
    104         // Options to update will be stored here
    105         $update_options = array();
    106 
    107         foreach ( $metabox['fields'] as $value ) {
    108             if ( ! isset( $value['id'] ) ) {
    109                 continue;
    110             }
    111 
    112             $type = isset( $value['type'] ) ? sanitize_title( $value['type'] ) : '';
    113 
    114             // Get the option name
    115             $option_value = null;
    116 
    117             if ( isset( $_POST[ $value['id'] ] ) ) {
    118                 $option_value = $_POST[ $value['id'] ];
    119             }
    120 
    121             // For a value to be submitted to database it must pass through a sanitization filter
    122             if ( has_filter( 'kopa_sanitize_option_' . $type ) ) {
    123                 $option_value = apply_filters( 'kopa_sanitize_option_' . $type, $option_value, $value );
    124             }
    125 
    126             if ( ! is_null( $option_value ) ) {
    127                 $update_options[ $value['id'] ] = $option_value;
     41
     42        /**
     43         * Metabox scripts
     44         *
     45         * @since 1.0.5
     46         * @access public
     47         */
     48        public function meta_box_scripts() {
     49            $screen = get_current_screen();
     50            $metabox = $this->settings;
     51
     52            if ( in_array( $screen->id, (array) $metabox['pages'] ) ) {
     53                wp_enqueue_script( 'kopa_media_uploader' );
    12854            }
    12955        }
    13056
    131         // Now save the options
    132         foreach( $update_options as $name => $value ) {
    133             update_post_meta( $post_id, $name, $value );
    134         }
    135 
    136         do_action( sprintf( 'kf_%s_saved', $metabox['id'] ), $post_id, $post );
    137 
    138         return true;
    139     }
    140 
    141     /**
    142      * Output meta box fields
    143      *
    144      * @since 1.0.5
    145      * @access public
    146      */
    147     public function output( $post, $args ) {
    148         $metabox = $this->settings;
    149 
    150         $option_wrap_start = '';
    151         $option_wrap_end = '';
    152         $output = '';
    153 
    154         $output .= '<div class="kopa-metabox-wrapper">';
    155 
    156         /* Use nonce for verification */
    157         $output .= '<input type="hidden" name="' . $metabox['id'] . '_nonce" value="' . wp_create_nonce( $metabox['id'] ) . '">';
    158        
    159         /* meta box description */
    160         if ( isset( $metabox['desc'] ) && ! empty( $metabox['desc'] ) ) {
    161             $allowed_tags = array(
    162                 'abbr'      => array( 'title' => true ),
    163                 'acronym'   => array( 'title' => true ),
    164                 'code'      => true,
    165                 'em'        => true,
    166                 'strong'    => true,
    167                 'a'         => array(
    168                     'href'  => true,
    169                     'title' => true,
    170                 ),
    171             );
    172             $metabox['desc'] = wp_kses( $metabox['desc'], $allowed_tags );
    173             $output .= '<p>' . $metabox['desc'] . '</p>';
    174         }
    175 
    176         $_loop_index = 0;
    177 
    178         foreach ( $metabox['fields'] as $value ) {
    179            
    180             if ( ! isset( $value['type'] ) ) continue;
    181 
    182             $value = Kopa_Admin_Settings::sanitize_option_arguments( $value );
    183 
    184             $option_wrap_start = '<p>';
    185             if ( $value['title'] ) {
    186                 $option_wrap_start .= '<strong>'.esc_html( $value['title'] ).'</strong>';
    187                 $option_wrap_start .= '<br>';
     57        /**
     58         * Add metaboxes
     59         *
     60         * @since 1.0.5
     61         * @access public
     62         */
     63        public function add_meta_boxes() {
     64            $metabox = $this->settings;
     65
     66            foreach ( (array) $metabox['pages'] as $page ) {
     67                add_meta_box( $metabox['id'], $metabox['title'], array( $this, 'output' ), $page, $metabox['context'], $metabox['priority'], $metabox['fields'] );
     68            }
     69        }
     70
     71        /**
     72         * Check if we're saving, the trigger an action based on the post type
     73         *
     74         * @param  int $post_id
     75         * @param  object $post
     76         *
     77         * @since 1.0.5
     78         * @access public
     79         */
     80        public function save_meta_boxes( $post_id, $post ) {
     81            $metabox = $this->settings;
     82
     83            /* don't save if $_POST is empty */
     84            if ( empty( $_POST ) )
     85                return $post_id;
     86
     87            /* don't save during autosave */
     88            if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
     89                return $post_id;
     90
     91            /* verify nonce */
     92            if ( ! isset( $_POST[ $metabox['id'] . '_nonce'] ) || ! wp_verify_nonce( $_POST[ $metabox['id'] . '_nonce'], $metabox['id'] ) )
     93                return $post_id;
     94
     95            /* check permissions */
     96            if ( isset( $_POST['post_type'] ) && 'page' == $_POST['post_type'] ) {
     97                if ( ! current_user_can( 'edit_page', $post_id ) )
     98                    return $post_id;
     99            } else {
     100                if ( ! current_user_can( 'edit_post', $post_id ) )
     101                    return $post_id;
    188102            }
    189             if ( $value['desc'] ) {
    190                 $option_wrap_start .= '<span>'.$value['desc'].'</span>';
    191                 $option_wrap_start .= '<br>';
     103
     104            // Options to update will be stored here
     105            $update_options = array();
     106
     107            foreach ( $metabox['fields'] as $value ) {
     108                if ( ! isset( $value['id'] ) ) {
     109                    continue;
     110                }
     111
     112                $type = isset( $value['type'] ) ? sanitize_title( $value['type'] ) : '';
     113
     114                // Get the option name
     115                $option_value = null;
     116
     117                if ( isset( $_POST[ $value['id'] ] ) ) {
     118                    $option_value = $_POST[ $value['id'] ];
     119                }
     120
     121                // For a value to be submitted to database it must pass through a sanitization filter
     122                if ( has_filter( 'kopa_sanitize_option_' . $type ) ) {
     123                    $option_value = apply_filters( 'kopa_sanitize_option_' . $type, $option_value, $value );
     124                }
     125
     126                if ( ! is_null( $option_value ) ) {
     127                        $update_options[ $value['id'] ] = $option_value;
     128                    }
    192129            }
    193130
    194             $option_wrap_end = '</p>';
    195 
    196             $option_wrap_start = apply_filters('kopa_admin_meta_box_wrap_start', $option_wrap_start, $value, $_loop_index);
    197             $option_wrap_end   = apply_filters('kopa_admin_meta_box_wrap_end', $option_wrap_end, $value, $_loop_index);         
    198 
    199             // get option value
    200             $option_value = get_post_meta( $post->ID, $value['id'] );
    201 
    202             $advanced_field = apply_filters('kopa_admin_metabox_advanced_field', false);
    203 
    204             if ( empty( $option_value ) ) {
    205                 $option_value = $value['default'];
    206             } elseif ( isset( $option_value[0] ) ) {
    207                 $option_value = $option_value[0];
    208             } else {
    209                 $option_value = '';
    210             }
    211 
    212             switch( $value['type'] ) {
    213                 case 'text':
    214                 case 'email':
    215                 case 'number':
    216                 case 'password':
    217                 case 'url':
    218                     if ( $value['type'] != 'password' ) {
    219                         $value['type'] = 'text';
    220                     }
    221                     $class = 'large-text';
    222                     if( isset( $value['class'] ) && !empty(  $value['class'] )){
    223                         $class = esc_attr(  $value['class'] );
    224                     }                   
    225 
    226                     $output .= $option_wrap_start;
    227                     $output .= '<input
    228                         class="' . esc_attr( $class ) . '"
    229                         type="'.esc_attr( $value['type'] ).'"
    230                         name="'.esc_attr( $value['id'] ).'"
    231                         id="'.esc_attr( $value['id'] ).'"
    232                         value="'.esc_attr( $option_value ).'">';
    233                     $output .= $option_wrap_end;
    234                 break;
    235 
    236                 case 'textarea':
    237                     $value = wp_parse_args( $value, array(
    238                         'rows' => '',
    239                     ) );
    240 
    241                     $output .= $option_wrap_start;
    242                     $output .= '<textarea
    243                         class="large-text"
    244                         rows="'.esc_attr( $value['rows'] ).'"
    245                         name="'.esc_attr( $value['id'] ).'"
    246                         id="'.esc_attr( $value['id'] ).'">'.
    247                         esc_textarea( $option_value ).
    248                         '</textarea>';
    249                     $output .= $option_wrap_end;
    250                 break;
    251 
    252                 case 'select':
    253                 case 'multiselect':
    254                     $value = wp_parse_args( $value, array(
    255                         'size' => '',
    256                     ) );
    257 
    258                     $output .= $option_wrap_start;
    259 
    260                     $output .= '<select
    261                         class="large-text widefat"
    262                         size="'.esc_attr( $value['size'] ).'"
    263                         name="'.esc_attr( $value['id'] ).( 'multiselect' === $value['type'] ? '[]' : '' ).'"
    264                         id="'.esc_attr( $value['id'] ).'"'.
    265                         ( 'multiselect' === $value['type'] ? ' multiple="multiple"' : '' ).
    266                         '>';
    267 
    268                     foreach ( $value['options'] as $key => $val ) {
    269                         $output .= '<option value="'.esc_attr( $key ).'" ';
    270                         if ( is_array( $option_value ) ) {
    271                             $output .= selected( in_array( $key, $option_value ), true, false );
    272                         } else {
    273                             $output .= selected( $key, $option_value, false );
     131            // Now save the options
     132            foreach( $update_options as $name => $value ) {
     133                update_post_meta( $post_id, $name, $value );
     134            }
     135
     136            do_action( sprintf( 'kf_%s_saved', $metabox['id'] ), $post_id, $post );
     137
     138            return true;
     139        }
     140
     141        /**
     142         * Output meta box fields
     143         *
     144         * @since 1.0.5
     145         * @access public
     146         */
     147        public function output( $post, $args ) {
     148            $metabox = $this->settings;
     149
     150            $option_wrap_start = '';
     151            $option_wrap_end = '';
     152            $output = '';
     153
     154            $output .= '<div class="kopa-metabox-wrapper">';
     155
     156            /* Use nonce for verification */
     157            $output .= '<input type="hidden" name="' . $metabox['id'] . '_nonce" value="' . wp_create_nonce( $metabox['id'] ) . '">';
     158           
     159            /* meta box description */
     160            if ( isset( $metabox['desc'] ) && ! empty( $metabox['desc'] ) ) {
     161                $allowed_tags = array(
     162                    'abbr'      => array( 'title' => true ),
     163                    'acronym'   => array( 'title' => true ),
     164                    'code'      => true,
     165                    'em'        => true,
     166                    'strong'    => true,
     167                    'a'         => array(
     168                        'href'  => true,
     169                        'title' => true,
     170                    ),
     171                );
     172                $metabox['desc'] = wp_kses( $metabox['desc'], $allowed_tags );
     173                $output .= '<p>' . $metabox['desc'] . '</p>';
     174            }
     175
     176            $_loop_index = 0;
     177
     178            foreach ( $metabox['fields'] as $value ) {
     179               
     180                if ( ! isset( $value['type'] ) ) continue;
     181
     182                $value = Kopa_Admin_Settings::sanitize_option_arguments( $value );
     183
     184                $option_wrap_start = '<p>';
     185                if ( $value['title'] ) {
     186                    $option_wrap_start .= '<strong>'.esc_html( $value['title'] ).'</strong>';
     187                    $option_wrap_start .= '<br>';
     188                }
     189                if ( $value['desc'] ) {
     190                    $option_wrap_start .= '<span>'.$value['desc'].'</span>';
     191                    $option_wrap_start .= '<br>';
     192                }
     193
     194                $option_wrap_end = '</p>';
     195
     196                $option_wrap_start = apply_filters('kopa_admin_meta_box_wrap_start', $option_wrap_start, $value, $_loop_index);
     197                $option_wrap_end   = apply_filters('kopa_admin_meta_box_wrap_end', $option_wrap_end, $value, $_loop_index);         
     198
     199                // get option value
     200                $option_value = get_post_meta( $post->ID, $value['id'] );
     201
     202                $advanced_field = apply_filters('kopa_admin_metabox_advanced_field', false);
     203
     204                if ( empty( $option_value ) ) {
     205                    $option_value = $value['default'];
     206                } elseif ( isset( $option_value[0] ) ) {
     207                    $option_value = $option_value[0];
     208                } else {
     209                    $option_value = '';
     210                }
     211
     212                switch( $value['type'] ) {
     213                    case 'text':
     214                    case 'email':
     215                    case 'number':
     216                    case 'password':
     217                    case 'url':
     218                        if ( $value['type'] != 'password' ) {
     219                            $value['type'] = 'text';
     220                        }
     221                        $class = 'large-text';
     222                        if( isset( $value['class'] ) && !empty(  $value['class'] )){
     223                            $class = esc_attr(  $value['class'] );
     224                        }                   
     225
     226                        $output .= $option_wrap_start;
     227                        $output .= '<input
     228                            class="' . esc_attr( $class ) . '"
     229                            type="'.esc_attr( $value['type'] ).'"
     230                            name="'.esc_attr( $value['id'] ).'"
     231                            id="'.esc_attr( $value['id'] ).'"
     232                            value="'.esc_attr( $option_value ).'">';
     233                        $output .= $option_wrap_end;
     234                        break;
     235
     236                    case 'textarea':
     237                        $value = wp_parse_args( $value, array(
     238                            'rows' => '',
     239                        ) );
     240
     241                        $output .= $option_wrap_start;
     242                        $output .= '<textarea
     243                            class="large-text"
     244                            rows="'.esc_attr( $value['rows'] ).'"
     245                            name="'.esc_attr( $value['id'] ).'"
     246                            id="'.esc_attr( $value['id'] ).'">'.
     247                            esc_textarea( $option_value ).
     248                            '</textarea>';
     249                        $output .= $option_wrap_end;
     250                        break;
     251
     252                    case 'select':
     253                    case 'multiselect':
     254                        $value = wp_parse_args( $value, array(
     255                            'size' => '',
     256                        ) );
     257
     258                        $output .= $option_wrap_start;
     259
     260                        $output .= '<select
     261                            class="large-text widefat"
     262                            size="'.esc_attr( $value['size'] ).'"
     263                            name="'.esc_attr( $value['id'] ).( 'multiselect' === $value['type'] ? '[]' : '' ).'"
     264                            id="'.esc_attr( $value['id'] ).'"'.
     265                            ( 'multiselect' === $value['type'] ? ' multiple="multiple"' : '' ).
     266                            '>';
     267
     268                        foreach ( $value['options'] as $key => $val ) {
     269                            $output .= '<option value="'.esc_attr( $key ).'" ';
     270                            if ( is_array( $option_value ) ) {
     271                                $output .= selected( in_array( $key, $option_value ), true, false );
     272                            } else {
     273                                $output .= selected( $key, $option_value, false );
     274                            }
     275                            $output .= '>'.esc_html( $val ).'</option>';
    274276                        }
    275                         $output .= '>'.esc_html( $val ).'</option>';
    276                     }
    277 
    278                     $output .= '</select>';
    279 
    280                     $output .= $option_wrap_end;
    281                 break;
    282 
    283                 case 'checkbox':
    284                     $value = wp_parse_args( $value, array(
    285                         'label' => '',
    286                     ) );
    287 
    288                     if ( ! isset( $value['checkboxgroup'] ) ||
    289                          ( isset( $value['checkboxgroup'] ) && 'start' == $value['checkboxgroup'] ) ) {
    290                         $output .= $option_wrap_start;
    291                     }
    292 
    293                     $output .= '<label>';
    294                     $output .= '<input
    295                         type="'.esc_attr( $value['type'] ).'"
    296                         name="'.esc_attr( $value['id'] ) .'"
    297                         id="'.esc_attr( $value['id'] ).'" value="1"'.
    298                         ( checked( $option_value, 1, false ) ).
    299                         '>';
    300                     $output .= ' '.esc_html( $value['label'] ).'</label>';
    301                     $output .= '<br>';
    302 
    303                     if ( ! isset( $value['checkboxgroup'] ) ||
    304                          ( isset( $value['checkboxgroup'] ) && 'end' == $value['checkboxgroup'] ) ) {
     277
     278                        $output .= '</select>';
     279
    305280                        $output .= $option_wrap_end;
    306                     }
    307                 break;
    308 
    309                 case 'multicheck':
    310                     $output .= $option_wrap_start;
    311 
    312                     foreach ( $value['options'] as $key => $val ) {
    313                         $name = $value['id'].'['.$key.']';
    314                         $checked = isset( $option_value[ $key ] ) ? checked( $option_value[ $key ], 1, false ) : '';
    315 
    316                         $output .= '<label>';
    317                         $output .= '<input
    318                             type="checkbox"
    319                             name="'.esc_attr( $name ).'"
    320                             id="'.esc_attr( $value['id'] ).'"
    321                             value="1" '.$checked.
    322                             '>';
    323                         $output .= ' '.esc_html( $val ).'</label>';
    324                         $output .= '<br>';
    325                     }
    326 
    327                     $output .= $option_wrap_end;
    328                 break;
    329 
    330                 case 'radio':
    331                     $output .= $option_wrap_start;
    332                    
    333                     foreach ( $value['options'] as $key => $val ) {
     281                        break;
     282
     283                    case 'checkbox':
     284                        $value = wp_parse_args( $value, array(
     285                            'label' => '',
     286                        ) );
     287
     288                        if ( ! isset( $value['checkboxgroup'] ) ||
     289                             ( isset( $value['checkboxgroup'] ) && 'start' == $value['checkboxgroup'] ) ) {
     290                            $output .= $option_wrap_start;
     291                        }
     292
    334293                        $output .= '<label>';
    335294                        $output .= '<input
    336295                            type="'.esc_attr( $value['type'] ).'"
     296                            name="'.esc_attr( $value['id'] ) .'"
     297                            id="'.esc_attr( $value['id'] ).'" value="1"'.
     298                            ( checked( $option_value, 1, false ) ).
     299                            '>';
     300                        $output .= ' '.esc_html( $value['label'] ).'</label>';
     301                        $output .= '<br>';
     302
     303                        if ( ! isset( $value['checkboxgroup'] ) ||
     304                             ( isset( $value['checkboxgroup'] ) && 'end' == $value['checkboxgroup'] ) ) {
     305                            $output .= $option_wrap_end;
     306                        }
     307                        break;
     308
     309                    case 'multicheck':
     310                        $output .= $option_wrap_start;
     311
     312                        foreach ( $value['options'] as $key => $val ) {
     313                            $name = $value['id'].'['.$key.']';
     314                            $checked = isset( $option_value[ $key ] ) ? checked( $option_value[ $key ], 1, false ) : '';
     315
     316                            $output .= '<label>';
     317                            $output .= '<input
     318                                type="checkbox"
     319                                name="'.esc_attr( $name ).'"
     320                                id="'.esc_attr( $value['id'] ).'"
     321                                value="1" '.$checked.
     322                                '>';
     323                            $output .= ' '.esc_html( $val ).'</label>';
     324                            $output .= '<br>';
     325                        }
     326
     327                        $output .= $option_wrap_end;
     328                        break;
     329
     330                    case 'radio':
     331                        $output .= $option_wrap_start;
     332                       
     333                        foreach ( $value['options'] as $key => $val ) {
     334                            $output .= '<label>';
     335                            $output .= '<input
     336                                type="'.esc_attr( $value['type'] ).'"
     337                                name="'.esc_attr( $value['id'] ).'"
     338                                id="'.esc_attr( $value['id'].'_'.$key ).'"
     339                                value="'.esc_attr( $key ).'" '.
     340                                checked( $key, $option_value, false ).'>';
     341                            $output .= ' '.esc_html( $val ).'</label>';
     342                            $output .= '<br>';
     343                        }
     344
     345                        $output .= $option_wrap_end;
     346                        break;
     347
     348                    case 'upload':
     349                        // make sure mimes key is set
     350                        $value = wp_parse_args( $value, array(
     351                            'mimes' => '',
     352                        ) );
     353
     354                        $output .= '<div class="kopa_section">';
     355                        $output .= $option_wrap_start;
     356
     357                        $output .= '<input type="text"
     358                            class="large-text kopa_upload"
    337359                            name="'.esc_attr( $value['id'] ).'"
    338                             id="'.esc_attr( $value['id'].'_'.$key ).'"
    339                             value="'.esc_attr( $key ).'" '.
    340                             checked( $key, $option_value, false ).'>';
    341                         $output .= ' '.esc_html( $val ).'</label>';
     360                            id="'.esc_attr( $value['id'] ).'"
     361                            value="'.esc_attr( $option_value ).'"
     362                            data-type="'.esc_attr( $value['mimes'] ).'">';
     363
    342364                        $output .= '<br>';
    343                     }
    344 
    345                     $output .= $option_wrap_end;
    346                 break;
    347 
    348                 case 'upload':
    349                     // make sure mimes key is set
    350                     $value = wp_parse_args( $value, array(
    351                         'mimes' => '',
    352                     ) );
    353 
    354                     $output .= '<div class="kopa_section">';
    355                     $output .= $option_wrap_start;
    356 
    357                     $output .= '<input type="text"
    358                         class="large-text kopa_upload"
    359                         name="'.esc_attr( $value['id'] ).'"
    360                         id="'.esc_attr( $value['id'] ).'"
    361                         value="'.esc_attr( $option_value ).'"
    362                         data-type="'.esc_attr( $value['mimes'] ).'">';
    363 
    364                     $output .= '<br>';
    365 
    366                     if ( function_exists( 'wp_enqueue_media' ) ) {
    367                         if ( $option_value == '' ) {
    368                             $output .= '<a style="margin-top: 3px" class="kopa_upload_button button">'.esc_html__( 'Upload', 'kopa-framework' ).'</a>';
     365
     366                        if ( function_exists( 'wp_enqueue_media' ) ) {
     367                            if ( $option_value == '' ) {
     368                                $output .= '<a style="margin-top: 3px" class="kopa_upload_button button">'.esc_html__( 'Upload', 'kopa-framework' ).'</a>';
     369                            } else {
     370                                $output .= '<a style="margin-top: 3px" class="kopa_remove_file button">'.esc_html__( 'Remove', 'kopa-framework' ).'</a>';
     371                            }
    369372                        } else {
    370                             $output .= '<a style="margin-top: 3px" class="kopa_remove_file button">'.esc_html__( 'Remove', 'kopa-framework' ).'</a>';
     373                            $output .= '<small class="kopa_upload_notice">'.esc_html__( 'Upgrade your version of WordPress for full media support.', 'kopa-framework' ).'</small>';
    371374                        }
    372                     } else {
    373                         $output .= '<small class="kopa_upload_notice">'.esc_html__( 'Upgrade your version of WordPress for full media support.', 'kopa-framework' ).'</small>';
    374                     }
    375                     $output .= $option_wrap_end;
    376 
    377                     $output .= '<p class="kopa_screenshot">';
    378 
    379                     if ( $option_value ) {
    380                         $remove = '<a class="button kopa_remove_image">'.esc_html__( 'Remove', 'kopa-framework' ).'</a>';
    381                         $image = preg_match( '/(^.*\.jpg|jpeg|png|gif|ico*)/i', $option_value );
    382                         if ( $image ) {
    383                             $output .= '<img style="max-width: 300px" src="' . esc_attr( $option_value ) . '" alt=""><br>' . $remove;
     375                        $output .= $option_wrap_end;
     376
     377                        $output .= '<p class="kopa_screenshot">';
     378
     379                        if ( $option_value ) {
     380                            $remove = '<a class="button kopa_remove_image">'.esc_html__( 'Remove', 'kopa-framework' ).'</a>';
     381                            $image = preg_match( '/(^.*\.jpg|jpeg|png|gif|ico*)/i', $option_value );
     382                            if ( $image ) {
     383                                $output .= '<img style="max-width: 300px" src="' . esc_attr( $option_value ) . '" alt=""><br>' . $remove;
     384                            }
    384385                        }
    385                     }
    386 
    387                     $output .= '</p>';
    388                     $output .= '</div>';
    389                 break;
    390 
    391                 case 'datetime':
    392                     if ( $advanced_field ) {
    393                         $date_value_time = '';
    394                         if ( isset($value['format']) && ! empty($option_value) && is_numeric($option_value) ) {
    395                             $date_value_time = date($value['format'],$option_value);
    396                         } else {
    397                             $date_value_time = $option_value;
    398                         }
    399                         if ( ! isset($value['timepicker']) || empty($value['timepicker']) ) {
    400                             $value['timepicker'] = "0";
    401                         }
    402                         if ( ! isset($value['datepicker']) || empty($value['datepicker']) ) {
    403                             $value['datepicker'] = "0";
    404                         }
    405 
    406                         $output .= $option_wrap_start;
    407                         $output .= '<input
    408                         class="medium-text kopa-framework-datetime"
    409                         type="'.esc_attr( $value['type'] ).'"
    410                         name="'.esc_attr( $value['id'] ).'"
    411                         id="'.esc_attr( $value['id'] ).'"
    412                         value="'. esc_attr( $date_value_time ).'"
    413                         data-timepicker="' . esc_attr($value['timepicker']) . '"
    414                         data-datepicker="' . esc_attr($value['datepicker']) . '"
    415                         data-format="' . wp_kses_post($value['format']) . '"
    416                         autocomplete="off">';
    417                         $output .= $option_wrap_end;
    418                     }
    419 
    420                     break;
    421 
    422                 case 'gallery':
    423                     if ( $advanced_field ) {
    424                         $output .= $option_wrap_start;
    425                         $output .= '<div class="kopa-framework-gallery-box">';
    426                         $output .= '<input
    427                         class="medium-text kopa-framework-gallery"
    428                         type="text"
    429                         name="'.esc_attr( $value['id'] ).'"
    430                         id="'.esc_attr( $value['id'] ).'"
    431                         value="'.esc_attr( $option_value ).'"
    432                         autocomplete="off">';
    433 
    434                         $output .= '
    435                             <a href="#" class="kopa-framework-gallery-config button button-secondary">
    436                                 ' . esc_html__('Config', 'kopa-framework') . '
    437                             </a>
    438                         ';
    439                         $output .= '</div>';
    440                         $output .= $option_wrap_end;
    441                     }
    442                     break;
    443                 case 'icon':
    444                     if ( $advanced_field ) {
    445                         $output .= $option_wrap_start;
    446                         $output .= '<div class="kf-row">';
    447                         $output .= '<div class="kf-col-xs-12">';
    448                         $output .= '<a class="kf-icon-picker" href="#">' . esc_html__('Select icon', 'kopa-framework') . '</a>';
    449                         $output .= '
    450                                 <input type="hidden"
    451                                     name="'.esc_attr( $value['id'] ).'"
    452                                     id="'.esc_attr( $value['id'] ).'"
    453                                     value="'.esc_attr( $option_value ).'"
    454                                     autocomplete="off"
    455                                     class="large-text kf-icon-picker-value"/>
    456                             ';
    457 
    458                         $output .= '<span class="kf-icon-picker-preview"><i class="'.esc_attr( $option_value ).'"></i></span>';
    459 
    460                         $output .= '</div>';
    461                         $output .= '</div>';
    462                         $output .= $option_wrap_end;
    463                     }
    464                     break;
    465 
    466                 case 'color':
    467                     if ( $advanced_field ) {
    468                         $default_color = '';
    469                         $field_class = '';
    470 
    471                         if ( 'color' === $value['type'] ) {
    472                             $field_class = ' kopa_color';
    473 
    474                             if ( $value['default'] ) {
    475                                 $default_color = ' data-default-color="' .esc_attr( $value['default'] ) . '" ';
    476                             } // end check empty option value
    477                         } // end check color type
    478 
    479                         $output .= $option_wrap_start;
    480                         $output .= '<input
    481                         class="'.esc_attr( $field_class ).'"
    482                         style="'.esc_attr( $value['css'] ).'"
    483                         type="'.esc_attr( $value['type'] ).'"
    484                         name="'.esc_attr( $value['id'] ).'"
    485                         id="'.esc_attr( $value['id'] ).'"
    486                         value="'.esc_attr( $option_value ).'"'.
    487                             $default_color.'>';
    488                         $output .= $option_wrap_end;
    489                     }
    490                     break;
    491                 default:
    492                     $output .= apply_filters( 'kopa_admin_meta_box_field_' . $value['type'], '', $option_wrap_start, $option_wrap_end, $value, $option_value);
    493                 break;
    494             }
    495 
    496             $_loop_index++;
    497         } // end foreach
    498 
    499         $output .= '</div>'; // .kopa-metabox-wrapper
    500 
    501         // finally, output fields
    502         echo $output;
    503     }
    504 
    505 } // end class Kopa_Admin_Meta_Box
     386
     387                        $output .= '</p>';
     388                        $output .= '</div>';
     389                        break;
     390
     391            case 'datetime':
     392                if ( $advanced_field ) {
     393                    $date_value_time = '';
     394                    if ( isset($value['format']) && ! empty($option_value) && is_numeric($option_value) ) {
     395                        $date_value_time = date($value['format'],$option_value);
     396                    } else {
     397                        $date_value_time = $option_value;
     398                    }
     399                    if ( ! isset($value['timepicker']) || empty($value['timepicker']) ) {
     400                        $value['timepicker'] = "0";
     401                    }
     402                    if ( ! isset($value['datepicker']) || empty($value['datepicker']) ) {
     403                        $value['datepicker'] = "0";
     404                    }
     405
     406                    $output .= $option_wrap_start;
     407                    $output .= '<input
     408                                        class="medium-text kopa-framework-datetime"
     409                                        type="'.esc_attr( $value['type'] ).'"
     410                                        name="'.esc_attr( $value['id'] ).'"
     411                                        id="'.esc_attr( $value['id'] ).'"
     412                                        value="'. esc_attr( $date_value_time ).'"
     413                                        data-timepicker="' . esc_attr($value['timepicker']) . '"
     414                                        data-datepicker="' . esc_attr($value['datepicker']) . '"
     415                                        data-format="' . wp_kses_post($value['format']) . '"
     416                                        autocomplete="off">';
     417                    $output .= $option_wrap_end;
     418                }
     419
     420                break;
     421
     422            case 'gallery':
     423                if ( $advanced_field ) {
     424                    $output .= $option_wrap_start;
     425                    $output .= '<div class="kopa-framework-gallery-box">';
     426                    $output .= '<input
     427                                        class="medium-text kopa-framework-gallery"
     428                                        type="text"
     429                                        name="'.esc_attr( $value['id'] ).'"
     430                                        id="'.esc_attr( $value['id'] ).'"
     431                                        value="'.esc_attr( $option_value ).'"
     432                                        autocomplete="off">';
     433
     434                    $output .= '<a href="#" class="kopa-framework-gallery-config button button-secondary">' . esc_html__('Config', 'kopa-framework') . '</a>';
     435                    $output .= '</div>';
     436                    $output .= $option_wrap_end;                               
     437                }
     438                break;
     439           
     440            case 'gallery_sortable':
     441                           
     442              $html = '<div class="kf-ui-gallery" data-name="' . esc_attr( $value['id'] ) . '">';
     443                $html .= '<ul>';
     444                                       
     445                                    $thumbnail_size = isset( $value['thumbnail_size'] ) ? $value['thumbnail_size'] : 'thumbnail';
     446
     447                                    if( is_array( $option_value ) && $option_value ) {
     448                                   
     449                                        foreach( $option_value as $image_id ) {
     450
     451                                            $thumb = '';
     452                                            if( $image_id ) {
     453                                                $image = wp_get_attachment_image_src( $image_id, $thumbnail_size );
     454                                                if( isset( $image[0] ) ) {
     455                                                    $thumb = $image[0];
     456                                                }
     457                                            }
     458                                           
     459
     460                                            $html .= '<li class="kf-ui-gallery__image">';
     461                                            $html .= '<input type="hidden" name="' . esc_attr( $value['id'] ) . '[]" value="' . esc_attr( $image_id ) . '">';
     462                                            $html .= '<img src="' . esc_url( $thumb ) . '" alt="">';
     463                                            $html .= '<span class="kf-ui-gallery__remove dashicons dashicons-trash"></span>';
     464                                            $html .= '</li>';
     465                                                                                               
     466                                        }
     467                                    }
     468                                   
     469                            $html .= '</ul>';
     470
     471                            $html .= '<p class="kf-ui-gallery__placehold">';
     472                            $html .= '<span class="kf-ui-gallery__upload button button-secondary">' . esc_html__( 'Add new image', 'kopa-framework' ) . '</span>';
     473                            $html .= '</p>';
     474
     475                        $html .= '</div>';
     476
     477                        $output .= $option_wrap_start . $html . $option_wrap_end;
     478           
     479                break;
     480
     481            case 'icon':
     482                if ( $advanced_field ) {
     483                    $output .= $option_wrap_start;
     484                    $output .= '<div class="kf-row">';
     485                    $output .= '<div class="kf-col-xs-12">';
     486                    $output .= '<a class="kf-icon-picker" href="#">' . esc_html__('Select icon', 'kopa-framework') . '</a>';
     487                    $output .= '
     488                            <input type="hidden"
     489                                name="'.esc_attr( $value['id'] ).'"
     490                                id="'.esc_attr( $value['id'] ).'"
     491                                value="'.esc_attr( $option_value ).'"
     492                                autocomplete="off"
     493                                class="large-text kf-icon-picker-value"/>
     494                        ';
     495
     496                    $output .= '<span class="kf-icon-picker-preview"><i class="'.esc_attr( $option_value ).'"></i></span>';
     497
     498                    $output .= '</div>';
     499                    $output .= '</div>';
     500                    $output .= $option_wrap_end;
     501                }
     502                break;
     503
     504            case 'color':
     505                if ( $advanced_field ) {
     506                    $default_color = '';
     507                    $field_class = '';
     508
     509                    if ( 'color' === $value['type'] ) {
     510                        $field_class = ' kopa_color';
     511
     512                        if ( $value['default'] ) {
     513                            $default_color = ' data-default-color="' .esc_attr( $value['default'] ) . '" ';
     514                        } // end check empty option value
     515                    } // end check color type
     516
     517                    $output .= $option_wrap_start;
     518                    $output .= '<input
     519                                        class="'.esc_attr( $field_class ).'"
     520                                        style="'.esc_attr( $value['css'] ).'"
     521                                        type="'.esc_attr( $value['type'] ).'"
     522                                        name="'.esc_attr( $value['id'] ).'"
     523                                        id="'.esc_attr( $value['id'] ).'"
     524                                        value="'.esc_attr( $option_value ).'"'.
     525                        $default_color.'>';
     526                    $output .= $option_wrap_end;
     527                }
     528                break;                         
     529
     530                    default:
     531                        $output .= apply_filters( 'kopa_admin_meta_box_field_' . $value['type'], '', $option_wrap_start, $option_wrap_end, $value, $option_value);
     532                        break;
     533          }
     534
     535                $_loop_index++;
     536
     537            } // end foreach
     538
     539            $output .= '</div>'; // .kopa-metabox-wrapper
     540
     541            // finally, output fields
     542            echo $output;
     543        }
     544
     545    } // end class Kopa_Admin_Meta_Box
    506546
    507547}
  • kopatheme/trunk/includes/admin/class-kopa-admin-settings.php

    r1428092 r1461229  
    10661066
    10671067                    $output .= $option_wrap_end;
    1068                 break;
     1068                    break;
    10691069
    10701070                // Default: run an action
    1071                 default:
    1072                     $output .= apply_filters( 'kopa_admin_field_' . $value['type'], '', $option_wrap_start, $option_wrap_end, $value );
    1073                 break;
     1071        default:
     1072            $output .= apply_filters( 'kopa_admin_field_' . $value['type'], '', $option_wrap_start, $option_wrap_end, $value );
     1073          break;
    10741074
    10751075            } // end switch option type
  • kopatheme/trunk/includes/admin/class-kopa-admin-term-meta.php

    r1353276 r1461229  
    4343        $this->settings = $settings;
    4444        $this->add_meta_boxes();
    45         add_action( 'admin_enqueue_scripts', array( $this, 'meta_box_scripts' ) );
    46         //add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) );
     45        add_action( 'admin_enqueue_scripts', array( $this, 'meta_box_scripts' ) );     
    4746    }
    4847
  • kopatheme/trunk/kopa-framework.php

    r1456755 r1461229  
    33 * Plugin Name: Kopa Framework
    44 * Description: A WordPress framework by Kopatheme.
    5  * Version: 1.1.4
     5 * Version: 1.1.5
    66 * Author: Kopa Theme
    77 * Author URI: http://kopatheme.com
    88 * License: GPLv2 or later
    99 * Requires at least: 3.8
    10  * Tested up to: 4.5.1
     10 * Tested up to: 4.5.3
    1111 *
    1212 * Text Domain: kopa-framework
  • kopatheme/trunk/languages/kopa-framework-en_US.pot

    r1353276 r1461229  
     1#, fuzzy
    12msgid ""
    23msgstr ""
    34"Project-Id-Version: Kopa Framework\n"
    45"Report-Msgid-Bugs-To: \n"
    5 "POT-Creation-Date: 2015-05-17 23:17+0700\n"
     6"POT-Creation-Date: 2016-07-26 16:30+0700\n"
    67"PO-Revision-Date: 2015-05-17 23:17+0700\n"
    78"Last-Translator: thanh4890 <[email protected]>\n"
     
    1213"Content-Transfer-Encoding: 8bit\n"
    1314"Plural-Forms: nplurals=2; plural=n != 1;\n"
    14 "X-Generator: Poedit 1.7.6\n"
     15"X-Generator: Poedit 1.8.7\n"
    1516"X-Poedit-SourceCharset: UTF-8\n"
    1617"X-Poedit-KeywordsList: __;_e;__ngettext:1,2;_n:1,2;__ngettext_noop:1,2;"
    1718"_n_noop:1,2;_c,_nc:4c,1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;_nx_noop:4c,1,2\n"
    18 "X-Poedit-Basepath: ../\n"
     19"X-Poedit-Basepath: ..\n"
    1920"X-Textdomain-Support: yes\n"
    2021"X-Poedit-SearchPath-0: .\n"
    2122
    22 #: includes/admin/class-kopa-admin-assets.php:105
    23 #: includes/admin/class-kopa-admin-settings.php:711
     23#: includes/admin/class-kopa-admin-assets.php:135
     24#: includes/admin/class-kopa-admin-settings.php:737
    2425msgid "Enter font name"
    2526msgstr ""
    2627
    27 #: includes/admin/class-kopa-admin-assets.php:107
     28#: includes/admin/class-kopa-admin-assets.php:137
    2829msgid "Custom font"
    2930msgstr ""
    3031
    31 #: includes/admin/class-kopa-admin-assets.php:111
    32 #: includes/admin/class-kopa-admin-settings.php:716
     32#: includes/admin/class-kopa-admin-assets.php:141
     33#: includes/admin/class-kopa-admin-settings.php:742
    3334msgid "Upload .woff font file"
    3435msgstr ""
    3536
    36 #: includes/admin/class-kopa-admin-assets.php:116
    37 #: includes/admin/class-kopa-admin-settings.php:721
     37#: includes/admin/class-kopa-admin-assets.php:146
     38#: includes/admin/class-kopa-admin-settings.php:747
    3839msgid "Upload .ttf font file"
    3940msgstr ""
    4041
    41 #: includes/admin/class-kopa-admin-assets.php:121
    42 #: includes/admin/class-kopa-admin-settings.php:726
     42#: includes/admin/class-kopa-admin-assets.php:151
     43#: includes/admin/class-kopa-admin-settings.php:752
    4344msgid "Upload .eot font file"
    4445msgstr ""
    4546
    46 #: includes/admin/class-kopa-admin-assets.php:126
    47 #: includes/admin/class-kopa-admin-settings.php:731
     47#: includes/admin/class-kopa-admin-assets.php:156
     48#: includes/admin/class-kopa-admin-settings.php:757
    4849msgid "Upload .svg font file"
    4950msgstr ""
    5051
    51 #: includes/admin/class-kopa-admin-assets.php:131
     52#: includes/admin/class-kopa-admin-assets.php:161
     53#: includes/admin/class-kopa-admin-assets.php:219
     54msgid "Upload"
     55msgstr ""
     56
     57#: includes/admin/class-kopa-admin-assets.php:162
     58#: includes/admin/class-kopa-admin-assets.php:220
     59#: includes/admin/class-kopa-admin-settings.php:653
     60msgid "Remove"
     61msgstr ""
     62
     63#: includes/admin/class-kopa-admin-assets.php:163
     64msgid "Click OK to reset. Any selected settings will be lost!"
     65msgstr ""
     66
     67#: includes/admin/class-kopa-admin-assets.php:164
     68msgid "Click OK to import. Any selected settings will be lost!"
     69msgstr ""
     70
     71#: includes/admin/class-kopa-admin-assets.php:165
     72#: includes/admin/class-kopa-admin-assets.php:178
     73msgid "Are you sure you want to delete?"
     74msgstr ""
     75
     76#: includes/admin/class-kopa-admin-assets.php:175
     77msgid "Warning"
     78msgstr ""
     79
     80#: includes/admin/class-kopa-admin-assets.php:176
     81msgid "Error"
     82msgstr ""
     83
    5284#: includes/admin/class-kopa-admin-assets.php:177
    53 msgid "Upload"
    54 msgstr ""
    55 
    56 #: includes/admin/class-kopa-admin-assets.php:132
    57 #: includes/admin/class-kopa-admin-assets.php:178
    58 #: includes/admin/class-kopa-admin-settings.php:627
    59 msgid "Remove"
    60 msgstr ""
    61 
    62 #: includes/admin/class-kopa-admin-assets.php:133
    63 msgid "Click OK to reset. Any selected settings will be lost!"
    64 msgstr ""
    65 
    66 #: includes/admin/class-kopa-admin-assets.php:134
    67 msgid "Click OK to import. Any selected settings will be lost!"
    68 msgstr ""
    69 
    70 #: includes/admin/class-kopa-admin-assets.php:135
    71 #: includes/admin/class-kopa-admin-assets.php:148
    72 msgid "Are you sure you want to delete?"
    73 msgstr ""
    74 
    75 #: includes/admin/class-kopa-admin-assets.php:145
    76 msgid "Warning"
    77 msgstr ""
    78 
    79 #: includes/admin/class-kopa-admin-assets.php:146
    80 msgid "Error"
    81 msgstr ""
    82 
    83 #: includes/admin/class-kopa-admin-assets.php:147
    8485msgid "Info"
    8586msgstr ""
    8687
    87 #: includes/admin/class-kopa-admin-assets.php:149
     88#: includes/admin/class-kopa-admin-assets.php:179
    8889msgid "Close"
    8990msgstr ""
    9091
    91 #: includes/admin/class-kopa-admin-assets.php:150
     92#: includes/admin/class-kopa-admin-assets.php:180
    9293msgid "Delete"
    9394msgstr ""
    9495
    95 #: includes/admin/class-kopa-admin-assets.php:151
     96#: includes/admin/class-kopa-admin-assets.php:181
    9697msgid "Advanced Settings"
    9798msgstr ""
    9899
    99 #: includes/admin/class-kopa-admin-assets.php:153
    100 #: includes/admin/class-kopa-admin-settings.php:854
     100#: includes/admin/class-kopa-admin-assets.php:183
     101#: includes/admin/class-kopa-admin-settings.php:880
    101102msgid "Name"
    102103msgstr ""
    103104
    104 #: includes/admin/class-kopa-admin-assets.php:154
    105 #: includes/admin/class-kopa-admin-settings.php:855
     105#: includes/admin/class-kopa-admin-assets.php:184
     106#: includes/admin/class-kopa-admin-settings.php:881
    106107msgid "Description"
    107108msgstr ""
    108109
    109 #: includes/admin/class-kopa-admin-assets.php:155
    110 #: includes/admin/class-kopa-admin-settings.php:856
     110#: includes/admin/class-kopa-admin-assets.php:185
     111#: includes/admin/class-kopa-admin-settings.php:882
    111112msgid "Before Widget"
    112113msgstr ""
    113114
    114 #: includes/admin/class-kopa-admin-assets.php:156
    115 #: includes/admin/class-kopa-admin-settings.php:857
     115#: includes/admin/class-kopa-admin-assets.php:186
     116#: includes/admin/class-kopa-admin-settings.php:883
    116117msgid "After Widget"
    117118msgstr ""
    118119
    119 #: includes/admin/class-kopa-admin-assets.php:157
    120 #: includes/admin/class-kopa-admin-settings.php:858
     120#: includes/admin/class-kopa-admin-assets.php:187
     121#: includes/admin/class-kopa-admin-settings.php:884
    121122msgid "Before Title"
    122123msgstr ""
    123124
    124 #: includes/admin/class-kopa-admin-assets.php:158
    125 #: includes/admin/class-kopa-admin-settings.php:859
     125#: includes/admin/class-kopa-admin-assets.php:188
     126#: includes/admin/class-kopa-admin-settings.php:885
    126127msgid "After Title"
    127128msgstr ""
     
    218219msgstr ""
    219220
    220 #: includes/admin/class-kopa-admin-settings.php:99
     221#: includes/admin/class-kopa-admin-settings.php:117
    221222msgid "Action failed. Please refresh the page and retry."
    222223msgstr ""
    223224
    224 #: includes/admin/class-kopa-admin-settings.php:115
     225#: includes/admin/class-kopa-admin-settings.php:133
    225226msgid "Default options restored."
    226227msgstr ""
    227228
    228 #: includes/admin/class-kopa-admin-settings.php:120
     229#: includes/admin/class-kopa-admin-settings.php:138
    229230msgid "Your settings have been saved."
    230231msgstr ""
    231232
    232 #: includes/admin/class-kopa-admin-settings.php:641
     233#: includes/admin/class-kopa-admin-settings.php:667
    233234msgid "View File"
    234235msgstr ""
    235236
    236 #: includes/admin/class-kopa-admin-settings.php:659
     237#: includes/admin/class-kopa-admin-settings.php:685
    237238msgid "preview text"
    238239msgstr ""
    239240
    240 #: includes/admin/layouts/class-kopa-layout-box.php:53
     241#: includes/admin/layouts/class-kopa-layout-box.php:56
    241242msgid "Check if you would like to use custom setting"
    242243msgstr ""
    243244
    244 #: includes/admin/layouts/class-kopa-layout-box.php:65
     245#: includes/admin/layouts/class-kopa-layout-box.php:68
    245246msgid "Select layout"
    246247msgstr ""
    247248
    248 #: includes/admin/layouts/class-kopa-layout-box.php:91
     249#: includes/admin/layouts/class-kopa-layout-box.php:96
    249250msgid "&mdash;Select sidebar&mdash;"
    250251msgstr ""
    251252
    252 #: includes/admin/layouts/class-kopa-layout-box.php:120
    253 #: includes/admin/layouts/class-kopa-layout-post-type.php:49
     253#: includes/admin/layouts/class-kopa-layout-box.php:125
     254#: includes/admin/layouts/class-kopa-layout-post-type.php:53
    254255msgid "Custom Layout"
    255256msgstr ""
  • kopatheme/trunk/readme.txt

    r1456755 r1461229  
    55Requires at least: 3.8
    66Tested up to: 4.5.3
    7 Stable tag: 1.1.4
     7Stable tag: 1.1.5
    88License: GPLv2 or later
    99
     
    2121
    2222== Changelog ==
     23
     24= 1.1.5 =
     25* Add new metabox-field: gallery_sortable
    2326
    2427= 1.1.4 =
Note: See TracChangeset for help on using the changeset viewer.