/var/www/hkosl.com/aga/wp-content/themes/fitness-park/inc/customizer/customizer-functions.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
<?php 
/**
 * Customizer Custom Control Class Layout 
*/

if(class_exists'WP_Customize_control')):
    
/**
   * Repeater Custom Control Function
  */
  
class Fitness_Park_Repeater_Controler extends WP_Customize_Control {
    
/**
     * The control type.
     *
     * @access public
     * @var string
    */
    
public $type 'repeater';

    public 
$fp_box_label '';

    public 
$fp_box_add_control '';

    private 
$cats '';

    
/**
     * The fields that each container row will contain.
     *
     * @access public
     * @var array
    */
    
public $fields = array();

    
/**
     * Repeater drag and drop controler
     *
     * @since  1.0.0
    */
    
public function __construct$manager$id$args = array(), $fields = array() ) {
      
$this->fields $fields;
      
$this->fp_box_label $args['fp_box_label'] ;
      
$this->fp_box_add_control $args['fp_box_add_control'];
      
$this->cats get_categories(array( 'hide_empty' => false ));
      
parent::__construct$manager$id$args );
    }

    public function 
render_content() {
      
$values json_decode($this->value());
      
?>
      <span class="customize-control-title"><?php echo esc_html$this->label ); ?></span>
      <?php if($this->description){ ?>
        <span class="description customize-control-description">
        <?php echo wp_kses_post($this->description); ?>
        </span>
      <?php ?>

      <ul class="fp-repeater-field-control-wrap">
        <?php $this->fp_get_fields(); ?>
      </ul>
      <input type="hidden" <?php esc_attr$this->link() ); ?> class="fp-repeater-collector" value="<?php echo esc_attr$this->value() ); ?>" />
      <button type="button" class="button fp-add-control-field"><?php echo esc_html$this->fp_box_add_control ); ?></button>
      <?php
    
}

    private function 
fp_get_fields(){
      
$fields $this->fields;
      
$values json_decode($this->value());
      if(
is_array($values)){
      foreach(
$values as $value){    ?>
        <li class="fp-repeater-field-control">
          <h3 class="fp-repeater-field-title accordion-section-title"><?php echo esc_html$this->fp_box_label ); ?></h3>
          <div class="fp-repeater-fields">
            <?php
              
foreach ($fields as $key => $field) {
              
$class = isset( $field['class'] ) ? $field['class'] : '';
            
?>
              <div class="fp-fields fp-type-<?php echo esc_attr$field['type'] ).' '.esc_attr$class ); ?>">
                <?php
                  $label 
= isset($field['label']) ? $field['label'] : '';
                  
$description = isset($field['description']) ? $field['description'] : '';
                  if(
$field['type'] != 'checkbox'){ ?>
                    <span class="customize-control-title"><?php echo esc_html$label ); ?></span>
                    <span class="description customize-control-description"><?php echo esc_html$description ); ?></span>
                <?php }

                  
$new_value = isset($value->$key) ? $value->$key '';
                  
$default = isset($field['default']) ? $field['default'] : '';

                  switch ( 
$field['type'] ) {
                    case 
'text':
                      echo 
'<input data-default="'.esc_attr($default).'" data-name="'.esc_attr($key).'" type="text" value="'.esc_attr($new_value).'"/>';
                      break;

                    case 
'select':
                      
$options $field['options'];
                      echo 
'<select  data-default="'.esc_attr($default).'"  data-name="'.esc_attr($key).'">';
                            foreach ( 
$options as $option => $val )
                            {
                                
printf('<option value="%s" %s>%s</option>'esc_attr($option), selected($new_value$optionfalse), esc_html($val));
                            }
                      echo 
'</select>';
                      break;

                    case 
'icon':
                      echo 
'<div class="fp-selected-icon">';
                       echo 
'<img src="'.esc_url(get_template_directory_uri()).'/assets/images/'.esc_attr($new_value).'"/>';
                      echo 
'<span><i class="fas fa-angle-down"></i></span>';
                      echo 
'</div>';
                      echo 
'<ul class="fp-icon-list clearfix">';
                      
$fp_icon_array fp_icon_array();
                      foreach (
$fp_icon_array as $fp_icon) {
                        
$icon_class $new_value == $fp_icon 'icon-active' '';
                        echo 
'<li class='.esc_attr$icon_class ).'><img src="'.esc_url(get_template_directory_uri()).'/assets/images/'.esc_attr$fp_icon ).'" /></li>';
                      }
                      echo 
'</ul>';
                      echo 
'<input data-default="'.esc_attr($default).'" type="hidden" value="'.esc_attr($new_value).'" data-name="'.esc_attr($key).'"/>';
                      break;

                      case 
'url':
                        echo 
'<input data-default="'.esc_attr($default).'" data-name="'.esc_attr($key).'" type="text" value="'.esc_attr($new_value).'"/>';

                        break;

                      case 
'icons':
                        echo 
'<div class="fp-repeater-selected-icon">';
                        echo 
'<i class="'.esc_attr($new_value).'"></i>';
                        echo 
'<span><i class="fa fa-angle-down"></i></span>';
                        echo 
'</div>';
                        echo 
'<ul class="fp-repeater-icon-list clearfix">';
                          
$fp_awesome_icon_array fp_awesome_icon_array();

                          foreach (
$fp_awesome_icon_array as $fp_awesome_icon) {
                            
$icon_class $new_value == $fp_awesome_icon 'icon-active' '';
                            echo 
'<li class='.esc_attr$icon_class ).'><i class="'.esc_attr$fp_awesome_icon ).'"></i></li>';
                          }
                        echo 
'</ul>';
                        echo 
'<input data-default="'.esc_attr($default).'" type="hidden" value="'.esc_attr($new_value).'" data-name="'.esc_attr($key).'"/>';
                        break;

                    default:
                      break;
                  }
                
?>
              </div>
            <?php ?>
            <div class="clearfix fp-repeater-footer">
              <div class="alignright">
                <a class="fp-repeater-field-remove" href="#remove"><?php esc_html_e('Delete''fitness-park'?></a> |
                <a class="fp-repeater-field-close" href="#close"><?php esc_html_e('Close''fitness-park'?></a>
              </div>
            </div>
          </div>
        </li>
      <?php }
      }
    }
  }

   
/**
     * Multiple Gallery Image Upload Custom Control Function
    */
    
class Fitness_Park_Gallery_Control extends WP_Customize_Control{
        public 
$type 'gallery';         
        public function 
render_content() { ?>
        <label>
            <span class="customize-control-title">
                <?php echo esc_html$this->label ); ?>
            </span>

            <?php if($this->description){ ?>
                <span class="description customize-control-description">
                <?php echo wp_kses_post$this->description ); ?>
                </span>
            <?php ?>

            <div class="gallery-screenshot clearfix">
              <?php
                  
{
                  
$ids explode','$this->value() );
                      foreach ( 
$ids as $attachment_id ) {
                          
$img wp_get_attachment_image_src$attachment_id'thumbnail' );
                          echo 
'<div class="screen-thumb"><img src="' esc_url$img[0] ) . '" /></div>';
                      }
                  }
              
?>
            </div>

            <input id="edit-gallery" class="button upload_gallery_button" type="button" value="<?php esc_html_e('Add/Edit Gallery','fitness-park'?>" />
            <input id="clear-gallery" class="button upload_gallery_button" type="button" value="<?php esc_html_e('Clear','fitness-park'?>" />
            <input type="hidden" class="gallery_values" <?php echo esc_url$this->link() ); ?> value="<?php echo esc_attr$this->value() ); ?>">
        </label>
        <?php }
    }

  
/**
   * Multiple Check
  */
   
class fitness_park_multiple_check_control extends WP_Customize_Control {

       
/**
        * The type of customize control being rendered.
        *
        * @since  1.0.0
        * @access public
        * @var    string
        */
       
public $type 'checkbox-multiple';

       
/**
        * Displays the control content.
        *
        * @since  1.0.0
        * @access public
        * @return void
        */
       
public function render_content() {

           if ( empty( 
$this->choices ) )
               return; 
?>
             
           <?php if ( !empty( $this->label ) ) : ?>
               <span class="customize-control-title"><?php echo esc_html$this->label ); ?></span>
           <?php endif; ?>

           <?php if ( !empty( $this->description ) ) : ?>
               <span class="description customize-control-description"><?php echo esc_html$this->description ); ?></span>
           <?php endif; ?>

           <?php $multi_values = !is_array$this->value() ) ? explode','$this->value() ) : $this->value(); ?>
           <ul>
               <?php foreach ( $this->choices as $value => $label ) : ?>
                   <li>
                       <label>
                           <input type="checkbox" value="<?php echo esc_attr$value ); ?><?php checkedin_array$value$multi_values ) ); ?> /> 
                           <?php echo esc_html$label ); ?>
                       </label>
                   </li>
               <?php endforeach; ?>
           </ul>
           <input type="hidden" <?php esc_url$this->link() ); ?> value="<?php echo esc_attrimplode','$multi_values ) ); ?>" />
       <?php 
    }
/**
   * Switch Controller ( Enable or Disable )
  */
  
class fitness_park_switch_control extends WP_Customize_Control{

      public 
$type 'switch';

      public 
$switch_label = array();

      public function 
__construct($manager$id$args = array() ){
          
$this->switch_label $args['switch_label'];
          
parent::__construct$manager$id$args );
      }

      public function 
render_content(){
      
?>
          <span class="customize-control-title">
              <?php echo esc_html$this->label ); ?>
          </span>

          <?php if($this->description){ ?>
              <span class="description customize-control-description">
                <?php echo wp_kses_post$this->description ); ?>
              </span>
          <?php ?>

          <?php
              $switch_class 
= ($this->value() == 'enable') ? 'switch-on' '';
              
$switch_label $this->switch_label;
          
?>
          <div class="onoffswitch <?php echo esc_attr$switch_class ); ?>">
              <div class="onoffswitch-inner">
                  <div class="onoffswitch-active">
                      <div class="onoffswitch-switch"><?php echo esc_html$switch_label['enable'] ) ?></div>
                  </div>

                  <div class="onoffswitch-inactive">
                      <div class="onoffswitch-switch"><?php echo esc_html$switch_label['disable'] ) ?></div>
                  </div>
              </div>  
          </div>
          <input <?php $this->link(); ?> type="hidden" value="<?php echo esc_attr($this->value()); ?>"/>
          <?php
      
}
  }

endif;

/**
* repeater icons function
*/
if(!function_exists('fp_icon_array') ){
  function 
fp_icon_array(){
    return array(
"icon-1.png","icon-2.png","icon-3.png","icon-4.png","icon-5.png","icon-6.png","icon-7.png","icon-8.png");
  }
}

/**
* repeater Social icons function.
*/
if(!function_exists('fp_awesome_icon_array') ){
  function 
fp_awesome_icon_array(){
    return array(
"fab fa-facebook","fab fa-youtube","fab fa-instagram","fab fa-twitter","fab fa-google","fab fa-linkedin","fab fa-pinterest","fab fa-dribbble");
  }
}

/**
 * Repeat Fields Sanitization
*/
    
function fitness_park_sanitize_repeater($input){        
      
$input_decoded json_decode$inputtrue );
      
$allowed_html = array(
        
'br' => array(),
        
'em' => array(),
        
'strong' => array(),
        
'a' => array(
          
'href' => array(),
          
'class' => array(),
          
'id' => array(),
          
'target' => array()
        ),
        
'button' => array(
          
'class' => array(),
          
'id' => array()
        )
      ); 

      if(!empty(
$input_decoded)) {
        foreach (
$input_decoded as $boxes => $box ){
          foreach (
$box as $key => $value){
            
$input_decoded[$boxes][$key] = sanitize_text_field$value );
          }
        }
        return 
json_encode($input_decoded);
      }      
      return 
$input;
    }

/**
* select sanitization
*/
function fitness_park_sanitize_select$input$setting ){
   
//input must be a slug: lowercase alphanumeric characters, dashes and underscores are allowed only
  
$input sanitize_key($input);
  
//get the list of possible select options 
  
$choices $setting->manager->get_control$setting->id )->choices;
  
//return input if valid or return default option
  
return ( array_key_exists$input$choices ) ? $input $setting->default );  
}

/**
 * Switch Sanitization Function.
 *
 * @since 1.1
 */
function fitness_park_sanitize_switch($input) {
   
$valid_keys = array(
        
'enable'  => esc_html__'Enable''fitness-park' ),
        
'disable' => esc_html__'Disable''fitness-park' )
   );
   if ( 
array_key_exists$input$valid_keys ) ) {
      return 
$input;
   } else {
      return 
'';
   }
}

/**
 * Sanitize checkbox.
 *
 * @param  $input Whether the checkbox is input.
 */
function fitness_park_sanitize_checkbox$input ) {
  return ( ( isset( 
$input ) && true === $input ) ? true false );
}