Make WordPress Themes

source: fresh-lite/1.4/cyberchimps/options/options-init.php

Last change on this file was 101655, checked in by themedropbox, 7 years ago

New version of Fresh Lite - 1.4

File size: 52.8 KB
Line 
;
;
;
;
;
;
;
;
;
;
;
;
;
;
319                                                                                                break;
320                                                                                        default:
321                                                                                                $cc_section_link = '';
322                                                                                }       
323                                                                                $jquery_click_section_hook = '';
324
325                                                                                if ($i == 0) 
326                                                                                {
327                                                                                        echo 
328                                                                                        '<li class="active">
329                                                                                                <a href="#'.$section['id'].'" role="tab" data-toggle="tab">   
330                                                                                                '.$section['title'].'
331                                                                                                </a>';
332                                                                                        echo $cc_section_link;
333                                                                                        echo '</li>';
334                                                                                } else{
335                                                                                        echo 
336                                                                                        '<li>
337                                                                                                <a href="#'.$section['id'].'" role="tab" data-toggle="tab">   
338                                                                                                '.$section['title'].'
339                                                                                                </a>';
340                                                                                        echo $cc_section_link;
341                                                                                        echo '</li>';
342                                                                                }
343                                                                                $i++;
344                                                                        } // end of foreach
345                                                        echo '</ul>';
346                                                }
347
348                                                echo '<div class="tab-content">';
349                                                        $j = 0;
350                                                                foreach((array)$wp_settings_sections[$heading['id']] as $section)
351                                                                { 
352                                                                        if ($j == 0) 
353                                                                        {
354                                                                                echo '<div class="tab-pane active" id="' . $section['id'].'">';
355                                                                        } 
356                                                                        else if ($section['id']== 'cyberchimps_blog_options_section')
357                                                                        {
358                                                                        }
359                                                                        else
360                                                                        {
361                                                                                echo '<div class="tab-pane" id="' . $section['id'].'">';
362                                                                        }
363                                                                        $j++;
364               
365                                                                        // wrapper div of all field-container divs
366                                                                        echo '<div class="field-container-wrapper" id="wrapper_'.$section['id'].'">';
367
368                                                                                //Hook before section options
369                                                                                do_action( $jquery_click_section_hook . '_before' );
370                                                                                call_user_func( $section['callback'], $section );
371
372                                                                                if( isset( $wp_settings_fields ) && isset( $wp_settings_fields[$heading['id']] ) && isset( $wp_settings_fields[$heading['id']][$section['id']] ) ) 
373                                                                                { ?>
374                                                                                <?php if ($jquery_click_hook == "cyberchimps_blog_heading")
375                                                                                                { ?>                                                                                                   
376                                                                                                        <h3 class="blog_section_titles"><?php echo $section['title']; ?> </h3>
377                                                                                                        <?php //echo $cc_section_link; ?>
378                                                                                <?php   }  ?>
379                                                        <?php           cyberchimps_do_settings_fields( $heading['id'], $section['id'] );
380                                                                                }
381
382                                                                                //Hook after section options
383                                                                                do_action( $jquery_click_section_hook . '_after' );
384
385                                                                        echo '</div>'; // .field-container ends
386
387                                                                        echo '</div>'; // end of .tab-pane
388                                                                } //end of foreach
389
390                                                echo '</div>'; // end of cc-content-section
391       
392                                                echo '</li>';
393
394                                $count_right_items++;
395                                } // end of main foreach $headings_list
396
397?>
398                                </ul>
399                       
400                        <!-- span 9 -->
401                        <div class="clear"></div>
402                </div>
403                <!-- cc-footer -->
404                <!-- start footer -->
405        <div>
406                <!--  <div class="cc-footer">
407                        <div class="span4">
408                                                        </div>
409                        <!-- col-md-3 -->
410                        <!--  <div class="span8">
411                                <div class="footer-links">
412                                        <input type="submit" id="cyberchimps_options_submit" class="btn btn-primary" name="update" value="<?php esc_attr_e( 'Save Options', 'cyberchimps_core' ); ?>"/>
413                                        <button class="reset-button btn" name="reset" onclick="return confirm( '<?php print esc_js( __( 'Click OK to reset. Any theme settings will be lost!',
414                                                                                                                                        'cyberchimps_core' ) ); ?>' );">
415                                                <?php esc_attr_e( 'Restore Defaults', 'cyberchimps_core' ); ?>
416                                        </button>
417                                </div>
418                                <!-- footer-links -->
419                        <!--  </div>
420                        <!-- span 9 -->
421                        <!--  <div class="clear"></div>
422                </div>-->
423                <!-- cc-footer -->
424        </div>
425               
426        </div>  <!-- row fluid -->
427        <!-- end main content -->
428
429        <!-- start footer -->
430        <div class="row-fluid">
431                <div class="cc-footer">
432                        <!--  <div class="span3">
433                                <div class="cc-logo">
434                                        <a href="http://cyberchimps.com" title="<?php esc_attr_e( 'CyberChimps WordPress Themes', 'cyberchimps_core' ); ?>"><img
435                                                        src="<?php echo get_template_directory_uri(); ?>/cyberchimps/options/lib/images/options/chimp.png"
436                                                        alt="<?php esc_attr_e( 'CyberChimps WordPress Themes', 'cyberchimps_core' ); ?>"/><span>CyberChimps</span></a>
437                                </div>
438                                <!-- cc-logo -->
439                        <!--  </div>-->
440                        <!-- span3 -->
441                        <div class="span12">
442                                <!--<div class="cc-social-contavadn/e-shopperpro2 (pull request #9)
443
444Template changes for WooCommerceiner">
445                                        <div class="cc-social twitter">
446                                                <a href="https://twitter.com/cyberchimps" class="twitter-follow-button" data-show-count="false" data-size="small">Follow @cyberchimps</a>
447                                                <script>!function (d, s, id) {
448                                                                var js, fjs = d.getElementsByTagName(s)[0];
449                                                                if (!d.getElementById(id)) {
450                                                                        js = d.createElement(s);
451                                                                        js.id = id;
452                                                                        js.src = "//platform.twitter.com/widgets.js";
453                                                                        fjs.parentNode.insertBefore(js, fjs);
454                                                                }
455                                                        }(document, "script", "twitter-wjs");</script>
456                                        </div>
457                                        <!-- cc-scoial -->
458                                        <!--<div class="cc-social facebook">
459                                                <iframe
460                                                        src="https://themes.trac.wordpress.org//www.facebook.com/plugins/like.php?href=http%3A%2F%2Fcyberchimps.com%2F&amp;send=false&amp;layout=button_count&amp;width=200&amp;show_faces=false&amp;action=like&amp;colorscheme=light&amp;font&amp;height=21"
461                                                        scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:200px; height:21px;" allowTransparency="true"></iframe>
462                                        </div>
463                                        <!-- cc-scoial -->
464                                <!--</div>
465                                <!-- cc-social-container -->
466                                <div class="footer-links">
467                                        <?php if (has_filter("cyberchimps_demodata")) {  ?> 
468                                                <a class="btn" href="<?php echo apply_filters( 'cyberchimps_demodata', 'http://cyberchimps.com'); ?>" title="<?php esc_attr_e( 'Theme Demo Data', 'cyberchimps_core' ); ?>" target="_blank">
469                                <?php _e( 'Theme Demo Data', 'cyberchimps_core' ); ?></a>                                       
470                                        <?php }?>
471                                        <a class="btn" href="https://cyberchimps.com/contact/" title="Need Customization" target="_blank"><?php _e( 'Need Customization?', 'cyberchimps_core' ); ?></a>                                                 
472                                        <a class="btn " href="<?php echo apply_filters( 'cyberchimps_rating_link', 'http://cyberchimps.com/forum'); ?>" title="<?php esc_attr_e( 'Leave a star rating', 'cyberchimps_core' ); ?>" target="_blank">
473<?php _e( 'Leave a star rating', 'cyberchimps_core' ); ?></a>
474
475                                        <input type="submit" id="cyberchimps_options_submit" class="btn" name="update" value="<?php esc_attr_e( 'Save Options', 'cyberchimps_core' ); ?>"/>
476                                        <button class="reset-button btn" name="reset" onclick="return confirm( '<?php print esc_js( __( 'Click OK to reset. Any theme settings will be lost!',
477                                                                                                                                        'cyberchimps_core' ) ); ?>' );">
478                                                <?php esc_attr_e( 'Restore Defaults', 'cyberchimps_core' ); ?>
479                                        </button>
480                                        <?php if (has_filter("cyberchimps_gopro")) {  ?> 
481                                        <a class="btn" href="<?php echo apply_filters( 'cyberchimps_gopro', 'http://cyberchimps.com'); ?>" title="<?php esc_attr_e( 'Why Go Pro?', 'cyberchimps_core' ); ?>" target="_blank">
482<?php _e( 'Why Go Pro?', 'cyberchimps_core' ); ?></a>
483                                <?php }?>
484                                </div>
485                                <!-- footer-links -->
486                        </div>
487                        <!-- span 9 -->
488                        <div class="clear"></div>
489                </div>
490                <!-- cc-footer -->
491        </div>
492        <!-- row fluid -->
493        <!-- end footer -->
494
495        </form>
496
497        </div>
498        <!-- container-fluid -->
499        </div><!-- wrap -->
500<?php
501}
502
503/**
504 * forked version of core function do_settings_sections()
505 * modified core code call cyberchimps_do_settings_fields() and apply markup for section title and description
506 * returns mixed data
507 */
508function cyberchimps_do_settings_sections( $page ) {
509        global $wp_settings_sections, $wp_settings_fields;
510
511        if( !isset( $wp_settings_sections ) || !isset( $wp_settings_sections[$page] ) ) {
512                return;
513        }
514
515        foreach( (array)$wp_settings_sections[$page] as $section ) {
516                $jquery_click_section_hook = '';
517                $jquery_click_section_hook = preg_replace( '/[^a-zA-Z0-9._\-]/', '', strtolower( $section['id'] ) );
518
519                echo '<div class="section-group" id="' . esc_attr( $jquery_click_section_hook ) . '">';
520                if( $section['title'] ) {
521                        echo "<h3><span class='glyphicon glyphicon-chevron-down'></span> {$section['title']}</h3>\n";
522                }
523
524                // wrapper div of all field-container divs
525                echo '<div class="field-container-wrapper">';
526
527                //Hook before section options
528                do_action( $jquery_click_section_hook . '_before' );
529
530                call_user_func( $section['callback'], $section );
531
532                if( isset( $wp_settings_fields ) && isset( $wp_settings_fields[$page] ) && isset( $wp_settings_fields[$page][$section['id']] ) ) {
533                        cyberchimps_do_settings_fields( $page, $section['id'] );
534                }
535
536                //Hook after section options
537                do_action( $jquery_click_section_hook . '_after' );
538
539                echo '</div>'; // .field-container ends
540                echo '<div class="clear"></div></div>';
541        }
542}
543
544/**
545 * forked version of core function do_settings_fields()
546 * modified core code to remove table cell markup and apply custom markup
547 * returns mixed data
548 */
549function cyberchimps_do_settings_fields( $page, $section ) {
550        global $wp_settings_fields;
551
552        if( !isset( $wp_settings_fields ) || !isset( $wp_settings_fields[$page] ) || !isset( $wp_settings_fields[$page][$section] ) ) {
553                return;
554        }
555
556        foreach( (array)$wp_settings_fields[$page][$section] as $field ) {
557                call_user_func( $field['callback'], $field['args'] );
558        }
559}
560
561function cyberchimps_get_headings() {
562        $headings_list = array();
563
564        // pull in both default sections and users custom sections
565        return apply_filters( 'cyberchimps_heading_list', $headings_list );
566}
567
568function cyberchimps_get_sections() {
569        $sections_list = array();
570
571        // pull in both default sections and users custom sections
572        return apply_filters( 'cyberchimps_section_list', $sections_list );
573}
574
575function cyberchimps_get_fields() {
576        $fields_list = array();
577
578        // pull in both default fields and users custom fields
579        return apply_filters( 'cyberchimps_field_list', $fields_list );
580}
581
582function cyberchimps_create_sections( $sections ) {
583        if( empty( $sections ) ) {
584                return false;
585        }
586
587        // add in error checking and proper validation, escaping, and translation calls
588        foreach( $sections as $section ) {
589                if( cyberchimps_section_exists( $section['heading'], $section['id'] ) ) {
590                        continue;
591                }
592                else {
593                        add_settings_section(
594                                $section['id'],
595                                $section['label'],
596                                'cyberchimps_sections_callback',
597                                $section['heading']
598                        );
599                }
600        }
601}
602
603function cyberchimps_drag_drop_field( $value ) {
604
605        // Set directory uri
606        $directory_uri = get_template_directory_uri();
607
608        $option_name = 'cyberchimps_options';
609        $settings    = get_option( $option_name );
610
611        $val    = '';
612        $output = '';
613
614        // If the option is already saved, ovveride $val
615        if( ( $value['type'] != 'heading' ) && ( $value['type'] != 'info' ) ) {
616                if( isset( $settings[( $value['id'] )] ) ) {
617
618                        // Assign empty array if the array returns null
619                        if( $settings[( $value['id'] )] != "" ) {
620                                $val = $settings[( $value['id'] )];
621                        }
622                        else {
623                                $val = null;
624                        }
625                        // Striping slashes of non-array options
626                        if( !is_array( $val ) ) {
627                                $val = stripslashes( $val );
628                        }
629                }
630        }
631        // Set default value to $val
632        if( empty( $val ) ) {
633                if( isset( $value['std'] ) ) {
634                        if( is_array( $value['std'] ) ) {
635                                $val = array_keys( $value['std'] );
636                        }
637                        else {
638                                $val = array_keys( explode( $value['std'] ) );
639                        }
640                }
641        }
642
643        $output .= "<div class='section_order' id=" . esc_attr( $value['id'] ) . ">";
644        $output .= "<div class='left_list span5'>";
645        $output .= "<div class='inactive'>Inactive Elements</div>";
646        $output .= "<div class='list_items'>";
647        if( is_array( $val ) ) {
648                foreach( $value['options'] as $key => $option ) {
649                        if( in_array( $key, $val ) ) {
650                                continue;
651                        }
652                        $output .= "<div class='list_item'>";
653                        $output .= '<span class="glyphicon glyphicon-remove action"></span>';
654                        $output .= "<span data-key='{$key}'>{$option}</span>";
655                        $output .= "<span id='{$key}_img'></span>";
656                        $output .= "</div>";
657                }
658        }
659        $output .= "</div>";
660        $output .= "</div>";
661        $output .= '<div class="options-arrow span1 hidden-phone"><span class="glyphicon glyphicon-arrow-right"></span></div>';
662        $output .= "<div class='right_list span5'>";
663        $output .= "<div class='active'>Active Elements</div>";
664        $output .= "<div class='drag'>Drag & Drop Elements</div>";
665        $output .= "<div class='list_items'>";
666        if( is_array( $val ) ) {
667                foreach( $val as $key ) {
668                        if( !array_key_exists( $key, $value['options'] ) ) {
669                                continue;
670                        }
671                        $output .= "<div class='list_item'>";
672                        $output .= '<span class="glyphicon glyphicon-remove action"></span>';
673                        $output .= "<span data-key='{$key}'>{$value['options'][$key]}</span>";
674                        $output .= "<span id='{$key}_img'></span>";
675                        $output .= "</div>";
676                }
677        }
678        $output .= "</div>";
679        $output .= "<input class='blog-section-order-tracker' type='hidden'  name='cyberchimps_options[blog_section_order_tracker]' />";
680        $output .= "</div>";
681        $output .= '<div id="values" data-key="' . $option_name . '"></div>';
682        $output .= '<div class="clear"></div>';
683        $output .= "</div>";
684
685        echo $output;
686}
687
688function cyberchimps_sections_callback( $section_passed ) {
689        $sections = cyberchimps_get_sections();
690
691        if( empty( $sections ) && empty( $section_passed ) ) {
692                return false;
693        }
694
695        foreach( $sections as $section ) {
696                if( $section_passed['id'] == $section['id'] ) {
697                        echo '<p>';
698                        if( isset( $section['description'] ) ) {
699                                echo $section['description'];
700                        }
701                        echo '</p>';
702                }
703        }
704}
705
706/**
707 * custom function that checks if the section has been run through add_settings_section() function
708 * returns bool value true if section exists and false if it does not
709 */
710function cyberchimps_section_exists( $heading, $section ) {
711        global $wp_settings_sections;
712
713        if( isset( $wp_settings_sections[$heading][$section] ) ) {
714                return true;
715        }
716
717        return false;
718}
719
720function cyberchimps_create_fields( $fields ) {
721        if( empty( $fields ) ) {
722                return false;
723        }
724
725        // loop through and create each field
726        foreach( $fields as $field_args ) {
727                $field_defaults = array(
728                        'id'       => false,
729                        'name'     => __( 'Default Field', 'cyberchimps_core' ),
730                        'callback' => 'cyberchimps_fields_callback',
731                        'section'  => 'cyberchimps_default_section',
732                        'heading'  => 'cyberchimps_default_heading',
733                );
734                $field_args     = wp_parse_args( $field_args, $field_defaults );
735
736                if( empty( $field_args['id'] ) ) {
737                        continue;
738                }
739                elseif( !cyberchimps_section_exists( $field_args['heading'], $field_args['section'] ) ) {
740                        continue;
741                }
742                else {
743                        add_settings_field(
744                                $field_args['id'],
745                                $field_args['name'],
746                                $field_args['callback'],
747                                $field_args['heading'],
748                                $field_args['section'],
749                                $field_args
750                        );
751                }
752        }
753}
754
755function cyberchimps_fields_callback( $value ) {
756        global $allowedtags;
757
758        $option_name = 'cyberchimps_options';
759        $settings    = get_option( $option_name );
760
761        $val          = '';
762        $select_value = '';
763        $checked      = '';
764        $output       = '';
765
766        // Set default value to $val
767        if( isset( $value['std'] ) ) {
768                $val = $value['std'];
769        }
770
771        // If the option is already saved, ovveride $val
772        if( ( $value['type'] != 'heading' ) && ( $value['type'] != 'info' ) ) {
773                if( isset( $settings[( $value['id'] )] ) ) {
774                        $val = $settings[( $value['id'] )];
775                        // Striping slashes of non-array options
776                        if( !is_array( $val ) ) {
777                                $val = stripslashes( $val );
778                        }
779                }
780        }
781        // If there is no class set make it blank
782        if( !isset( $value['class'] ) ) {
783                $value['class'] = '';
784        }
785
786        // If there is a description save it for labels
787        $explain_value = '';
788        if( isset( $value['desc'] ) ) {
789                $explain_value = $value['desc'];
790        }
791
792        // add extra field wrapper class
793        $wrapper_class = ( $value['class'] ) ? ' ' . $value['class'] . '-container' : '';
794
795        // field wrapper
796        $output .= '<div class="field-container' . $wrapper_class . '">';
797
798        // Output field name
799        if( $value['name'] && $value['type'] != 'info' && $value['type'] != 'welcome' && $value['type'] != 'toggle' ) {
800                $output .= '<label for="' . esc_attr( $value['id'] ) . '">' . $value['name'] . '</label>';
801        }
802
803        switch( $value['type'] ) {
804
805                // Basic text input
806                case 'text':
807                        $output .= '<input id="' . esc_attr( $value['id'] ) . '" class="of-input ' . esc_attr( $value['class'] ) . '" name="' . esc_attr( $option_name . '[' . $value['id'] . ']' ) . '" type="text" value="' . esc_attr( $val ) . '" />';
808                        break;
809
810                // Same as text but allows some basic a, href, title, br, em and strong html, check the sanitization
811                case 'text_html':
812                        $output .= '<input id="' . esc_attr( $value['id'] ) . '" class="of-input ' . esc_attr( $value['class'] ) . '" name="' . esc_attr( $option_name . '[' . $value['id'] . ']' ) . '" type="text" value="' . esc_attr( $val ) . '" />';
813                        break;
814
815                // Textarea
816                case 'textarea':
817                        $rows = '8';
818
819                        if( isset( $value['settings']['rows'] ) ) {
820                                $custom_rows = $value['settings']['rows'];
821                                if( is_numeric( $custom_rows ) ) {
822                                        $rows = $custom_rows;
823                                }
824                        }
825
826                        $val = stripslashes( $val );
827                        $output .= '<textarea id="' . esc_attr( $value['id'] ) . '" class="of-input" name="' . esc_attr( $option_name . '[' . $value['id'] . ']' ) . '" rows="' . $rows . '">' . esc_textarea( $val ) . '</textarea>';
828                        break;
829
830                // Unfiltered Textarea
831                case 'unfiltered_textarea':
832                        $rows = '8';
833
834                        if( isset( $value['settings']['rows'] ) ) {
835                                $custom_rows = $value['settings']['rows'];
836                                if( is_numeric( $custom_rows ) ) {
837                                        $rows = $custom_rows;
838                                }
839                        }
840
841                        $val = stripslashes( $val );
842                        $output .= '<textarea id="' . esc_attr( $value['id'] ) . '" class="of-input ' . esc_attr( $value['class'] ) . '" name="' . esc_attr( $option_name . '[' . $value['id'] . ']' ) . '" rows="'
843                                .
844                                $rows .
845                                '">' .
846                                esc_textarea(
847                                        $val ) . '</textarea>';
848                        break;
849
850                // css Textarea
851                case 'csstextarea':
852                        $rows = '8';
853
854                        if( isset( $value['settings']['rows'] ) ) {
855                                $custom_rows = $value['settings']['rows'];
856                                if( is_numeric( $custom_rows ) ) {
857                                        $rows = $custom_rows;
858                                }
859                        }
860
861                        $val = stripslashes( $val );
862                        $output .= '<textarea id="' . esc_attr( $value['id'] ) . '" class="of-input" name="' . esc_attr( $option_name . '[' . $value['id'] . ']' ) . '" rows="' . $rows . '">' . strip_tags( $val ) . '</textarea>';
863                        $output .= '<div id="custom-css-msg"></div>';
864                        break;
865
866                // Select Box
867                case 'select':
868                        $output .= '<select class="of-input ' . esc_attr( $value['class'] ) . '" name="' . esc_attr( $option_name . '[' . $value['id'] . ']' ) . '" id="' . esc_attr( $value['id'] ) . '">';
869
870                        foreach( $value['options'] as $key => $option ) {
871                                $selected = '';
872                                if( $val != '' ) {
873                                        $selected = selected( $val, $key, false );
874                                }
875                                $output .= '<option value="' . esc_attr( $key ) . '" ' . $selected . '>' . esc_html( $option ) . '</option>';
876                        }
877                        $output .= '</select>';
878                        break;
879
880                // Radio Box
881                case "radio":
882                        $name = $option_name . '[' . $value['id'] . ']';
883                        $val  = ( $val != '' ) ? $val : $value['std'];
884                        foreach( $value['options'] as $key => $option ) {
885                                $id = $option_name . '-' . $value['id'] . '-' . $key;
886                                $output .= '<div class="radio-container ' . esc_attr( $value['class'] ) . '"><input class="of-input of-radio" type="radio" name="' . esc_attr( $name ) . '" id="' . esc_attr( $id ) . '" value="' . esc_attr( $key ) . '" ' . checked( $val, $key, false ) . ' /><label for="' . esc_attr( $id ) . '" class="of-radio">' . esc_html( $option ) . '</label></div>';
887                        }
888                        break;
889
890                // Image Selectors
891                case "images":
892                        $name = $option_name . '[' . $value['id'] . ']';
893                        $output .= '<div class="images-radio-container">';
894                        foreach( $value['options'] as $key => $option ) {
895                                $selected = '';
896                                $checked  = '';
897                                if( $val != '' ) {
898                                        if( $val == $key ) {
899                                                $selected = ' of-radio-img-selected';
900                                                $checked  = ' checked="checked"';
901                                        }
902                                }
903                                $output .= '<div class="images-radio-subcontainer"><input type="radio" id="' . esc_attr( $value['id'] . '_' . $key ) . '" class="of-radio-img-radio" value="' . esc_attr( $key ) . '" name="' . esc_attr( $name ) . '" ' . $checked . ' />';
904                                $output .= '<div class="of-radio-img-label">' . esc_html( $key ) . '</div>';
905                                $output .= '<img src="' . esc_url( $option ) . '" alt="' . $option . '" class="of-radio-img-img' . $selected . '" onclick="document.getElementById(\'' . esc_attr( $value['id'] . '_' . $key ) . '\').checked=true;" /></div>';
906                        }
907                        $output .= '</div>';
908                        break;
909
910                // Checkbox
911                case "checkbox":
912                        $output .= '<div class="checkbox-container"><input id="' . esc_attr( $value['id'] ) . '" class="checkbox of-input" type="checkbox" name="' . esc_attr( $option_name . '[' . $value['id'] . ']' ) . '" ' . checked( $val, 1, false ) . ' />';
913                        $output .= '<label class="right-label" for="' . esc_attr( $value['id'] ) . '">' . wp_kses( $explain_value, $allowedtags ) . '</label></div>';
914                        break;
915
916                // Multicheck
917                case "multicheck":
918                        foreach( $value['options'] as $key => $option ) {
919                                $checked = '';
920                                $label   = $option;
921                                $option  = preg_replace( '/[^a-zA-Z0-9._\-]/', '', strtolower( $key ) );
922
923                                $id   = $option_name . '-' . $value['id'] . '-' . $option;
924                                $name = $option_name . '[' . $value['id'] . '][' . $option . ']';
925
926                                if( isset( $val[$option] ) ) {
927                                        $checked = checked( $val[$option], 1, false );
928                                }
929
930                                $output .= '<div class="checkbox-container"><input id="' . esc_attr( $id ) . '" class="checkbox of-input" type="checkbox" name="' . esc_attr( $name ) . '" ' . $checked . ' /><label for="' . esc_attr( $id ) . '" class="right-label">' . esc_html( $label ) . '</label></div>';
931                        }
932                        break;
933
934                // Toggle Switch
935                case "toggle":
936                        $checked = "";
937                        if( $val ) {
938                                $checked = 'checked="checked"';
939                        }
940                        $output .= '<div class="toggle-container" id="' . esc_attr( $value['id'] ) . '_container"><label for="' . esc_attr( $value['id'] ) . '">' . $value['name'] . '</label><input id="' . esc_attr( $value['id'] ) . '"' . $checked . 'class="checkbox-toggle of-input" type="checkbox" name="' . esc_attr( $option_name . '[' . $value['id'] . ']' ) . '" ' . checked( $val, 1, false ) . ' /></div>';
941                        break;
942
943                // Color picker
944                case "color":
945                        $output .= '<div class="input-prepend ' . $value['class'] . '"><div id="' . esc_attr( $value['id'] . '_picker' ) . '" class="add-on colorSelector"><div style="' . esc_attr( 'background-color:' . $val ) . '"></div></div>';
946                        $output .= '<input class="of-color" name="' . esc_attr( $option_name . '[' . $value['id'] . ']' ) . '" id="' . esc_attr( $value['id'] ) . '" type="text" value="' . esc_attr( $val ) . '" /></div>';
947                        break;
948
949                // Uploader
950                case "upload":
951                        $output .= cyberchimps_medialibrary_uploader( $value['class'], $value['id'], $val, null, $explain_value );
952                        break;
953
954                // Typography
955                case 'typography':
956
957                        unset( $font_size, $font_style, $font_face, $font_color );
958
959                        $typography_defaults = array(
960                                'size'  => '',
961                                'face'  => '',
962                                'style' => '',
963                                'color' => ''
964                        );
965
966                        $typography_stored = wp_parse_args( $val, $typography_defaults );
967
968                        $typography_options = array(
969                                'sizes'  => cyberchimps_recognized_font_sizes(),
970                                'faces'  => cyberchimps_recognized_font_faces(),
971                                'styles' => cyberchimps_recognized_font_styles(),
972                                'color'  => true
973                        );
974
975                        if( isset( $value['options'] ) ) {
976                                $typography_options = wp_parse_args( $value['options'], $typography_options );
977                        }
978
979                        // Font Size
980                        if( $typography_options['sizes'] ) {
981                                $font_size = '<select class="of-typography of-typography-size" name="' . esc_attr( $option_name . '[' . $value['id'] . '][size]' ) . '" id="' . esc_attr( $value['id'] . '_size' ) . '">';
982                                $sizes     = $typography_options['sizes'];
983                                foreach( $sizes as $i ) {
984                                        $size = $i . 'px';
985                                        $font_size .= '<option value="' . esc_attr( $size ) . '" ' . selected( $typography_stored['size'], $size, false ) . '>' . esc_html( $size ) . '</option>';
986                                }
987                                $font_size .= '</select>';
988                        }
989
990                        // Font Face
991                        if( $typography_options['faces'] ) {
992                                $font_face = '<select class="of-typography of-typography-face" name="' . esc_attr( $option_name . '[' . $value['id'] . '][face]' ) . '" id="' . esc_attr( $value['id'] . '_face' ) . '">';
993                                $faces     = $typography_options['faces'];
994                                foreach( $faces as $key => $face ) {
995                                        $font_face .= '<option value="' . esc_attr( $key ) . '" ' . selected( $typography_stored['face'], $key, false ) . '>' . esc_html( $face ) . '</option>';
996                                }
997                                $font_face .= '</select>';
998                        }
999
1000                        // Font Styles
1001                        if( $typography_options['styles'] ) {
1002                                $font_style = '<select class="of-typography of-typography-style" name="' . $option_name . '[' . $value['id'] . '][style]" id="' . $value['id'] . '_style">';
1003                                $styles     = $typography_options['styles'];
1004                                foreach( $styles as $key => $style ) {
1005                                        $font_style .= '<option value="' . esc_attr( $key ) . '" ' . selected( $typography_stored['style'], $key, false ) . '>' . $style . '</option>';
1006                                }
1007                                $font_style .= '</select>';
1008                        }
1009
1010                        // Font Color
1011                        if( $typography_options['color'] ) {
1012                                $font_color = '<div class="input-prepend of-typography"><div id="' . esc_attr( $value['id'] ) . '_color_picker" class="add-on colorSelector"><div style="' . esc_attr( 'background-color:' . $typography_stored['color'] ) . '"></div></div>';
1013                                $font_color .= '<input class="of-color of-typography of-typography-color" name="' . esc_attr( $option_name . '[' . $value['id'] . '][color]' ) . '" id="' . esc_attr( $value['id'] . '_color' ) . '" type="text" value="' . esc_attr( $typography_stored['color'] ) . '" /></div>';
1014                        }
1015
1016                        // Allow modification/injection of typography fields
1017                        $typography_fields = compact( 'font_size', 'font_face', 'font_style', 'font_color' );
1018                        $typography_fields = apply_filters( 'cyberchimps_typography_fields', $typography_fields, $typography_stored, $option_name, $value );
1019                        $output .= implode( '', $typography_fields );
1020
1021                        break;
1022
1023                // Background
1024                case 'background':
1025
1026                        $background = $val;
1027
1028                        // Background Color
1029                        $output .= '<div class="input-prepend"><div id="' . esc_attr( $value['id'] ) . '_color_picker" class="add-on colorSelector"><div style="' . esc_attr( 'background-color:' . $background['color'] ) . '"></div></div>';
1030                        $output .= '<input class="of-color of-background of-background-color" name="' . esc_attr( $option_name . '[' . $value['id'] . '][color]' ) . '" id="' . esc_attr( $value['id'] . '_color' ) . '" type="text" value="' . esc_attr( $background['color'] ) . '" /></div>';
1031
1032                        // Background Image - New AJAX Uploader using Media Library
1033                        if( !isset( $background['image'] ) ) {
1034                                $background['image'] = '';
1035                        }
1036
1037                        $output .= cyberchimps_medialibrary_uploader( $value['class'], $value['id'], $background['image'], null, '', 0, 'image' );
1038                        $class = 'of-background-properties';
1039                        if( '' == $background['image'] ) {
1040                                $class .= ' hide';
1041                        }
1042                        $output .= '<div class="' . esc_attr( $class ) . '">';
1043
1044                        // Background Repeat
1045                        $output .= '<select class="of-background of-background-repeat" name="' . esc_attr( $option_name . '[' . $value['id'] . '][repeat]' ) . '" id="' . esc_attr( $value['id'] . '_repeat' ) . '">';
1046                        $repeats = cyberchimps_recognized_background_repeat();
1047
1048                        foreach( $repeats as $key => $repeat ) {
1049                                $output .= '<option value="' . esc_attr( $key ) . '" ' . selected( $background['repeat'], $key, false ) . '>' . esc_html( $repeat ) . '</option>';
1050                        }
1051                        $output .= '</select>';
1052
1053                        // Background Position
1054                        $output .= '<select class="of-background of-background-position" name="' . esc_attr( $option_name . '[' . $value['id'] . '][position]' ) . '" id="' . esc_attr( $value['id'] . '_position' ) . '">';
1055                        $positions = cyberchimps_recognized_background_position();
1056
1057                        foreach( $positions as $key => $position ) {
1058                                $output .= '<option value="' . esc_attr( $key ) . '" ' . selected( $background['position'], $key, false ) . '>' . esc_html( $position ) . '</option>';
1059                        }
1060                        $output .= '</select>';
1061
1062                        // Background Attachment
1063                        $output .= '<select class="of-background of-background-attachment" name="' . esc_attr( $option_name . '[' . $value['id'] . '][attachment]' ) . '" id="' . esc_attr( $value['id'] . '_attachment' ) . '">';
1064                        $attachments = cyberchimps_recognized_background_attachment();
1065
1066                        foreach( $attachments as $key => $attachment ) {
1067                                $output .= '<option value="' . esc_attr( $key ) . '" ' . selected( $background['attachment'], $key, false ) . '>' . esc_html( $attachment ) . '</option>';
1068                        }
1069                        $output .= '</select>';
1070                        $output .= '</div>';
1071
1072                        break;
1073
1074                // Editor
1075                case 'editor':
1076                        $output .= '<div class="explain">' . wp_kses( $explain_value, $allowedtags ) . '</div>' . "\n";
1077                        echo $output;
1078                        $textarea_name           = esc_attr( $option_name . '[' . $value['id'] . ']' );
1079                        $default_editor_settings = array(
1080                                'textarea_name' => $textarea_name,
1081                                'media_buttons' => false,
1082                                'tinymce'       => array( 'plugins' => 'wordpress' )
1083                        );
1084                        $editor_settings         = array();
1085                        if( isset( $value['settings'] ) ) {
1086                                $editor_settings = $value['settings'];
1087                        }               
1088                       
1089                        $editor_settings = array_merge( $default_editor_settings, $editor_settings );
1090                        wp_editor( $val, $value['id'], $editor_settings );
1091                        $output = '';
1092                        break;
1093
1094                // Info
1095                case "info":
1096                        $id    = '';
1097                        $class = 'section';
1098                        if( isset( $value['id'] ) ) {
1099                                $id = 'id="' . esc_attr( $value['id'] ) . '" ';
1100                        }
1101                        if( isset( $value['type'] ) ) {
1102                                $class .= ' section-' . $value['type'];
1103                        }
1104                        if( isset( $value['class'] ) ) {
1105                                $class .= ' ' . $value['class'];
1106                        }
1107
1108                        $output .= '<div ' . $id . 'class="' . esc_attr( $class ) . '">' . "\n";
1109                        if( isset( $value['name'] ) ) {
1110                                $output .= '<h4 class="heading">' . esc_html( $value['name'] ) . '</h4>' . "\n";
1111                        }
1112                        if( $value['desc'] ) {
1113                                $output .= apply_filters( 'cyberchimps_sanitize_info', $value['desc'] ) . "\n";
1114                        }
1115                        $output .= '</div>' . "\n";
1116                        break;
1117
1118                // Welcome
1119                case "welcome":
1120                        $id    = '';
1121                        $class = 'section';
1122                        if( isset( $value['id'] ) ) {
1123                                $id = 'id="' . esc_attr( $value['id'] ) . '" ';
1124                        }
1125                        if( isset( $value['type'] ) ) {
1126                                $class .= ' section-' . $value['type'];
1127                        }
1128                        if( isset( $value['class'] ) ) {
1129                                $class .= ' ' . $value['class'];
1130                        }
1131                        $output .= '<div ' . $id . 'class="' . esc_attr( $class ) . '">' . "\n";
1132                        if( isset( $value['name'] ) ) {
1133                                $output .= '<h4 class="heading">' . esc_html( apply_filters( 'cyberchimps_help_sub_heading', $value['name'] ) ) . '</h4>' . "\n";
1134                        }
1135                        $output .= apply_filters( 'cyberchimps_sanitize_info', apply_filters( 'cyberchimps_help_description', '' ) ) . "\n";
1136
1137                        $output .= '</div>' . "\n";
1138                        break;
1139
1140                case "export":
1141                        $output .= "<textarea rows='10'>" . esc_html( serialize( $settings ) ) . "</textarea>";
1142                        $output .= '<br/><a class="btn btn-info export-option" href="data:text/octet-stream;charset=utf-8,' . esc_html( serialize( $settings ) ) . '" download="theme-option-backup.txt">Download</a>';
1143                        break;
1144
1145                case "import":
1146                        $output .= "<textarea name='import' rows='10'></textarea>";
1147                        $output .= "<br/><input type='file' id='import_file' name='import_file' />";
1148                        break;
1149        }
1150
1151        if( ( $value['type'] != "heading" ) && ( $value['type'] != "info" ) && ( $value['type'] != "welcome" ) && ( $value['type'] != "upload" ) ) {
1152                if( ( $value['type'] != "checkbox" ) && ( $value['type'] != "editor" ) ) {
1153                        $output .= '<div class="desc">' . wp_kses( $explain_value, $allowedtags ) . '</div>' . "\n";
1154                }
1155        }
1156
1157        // end field wrapper
1158        $output .= '</div>';
1159
1160        echo $output;
1161}
1162
1163/**
1164 * Validate options
1165 *
1166 * Validate theme options before updating to database.
1167 */
1168function cyberchimps_options_validate( $input ) {
1169
1170        global $wp_filesystem;
1171        /*
1172         * Import functionality
1173         *
1174         * Both the copy/paste and file upload options are active. First it checks for file, if any file is uploaded then
1175         * it processes that. Otherwise it checks if anything is sent with the textarea for the import.
1176         */
1177
1178        // Check if any file is uplaoded
1179        if( isset( $_FILES['import_file'] ) && $_FILES['import_file']['name'] ) {
1180
1181                // Initialise WP filesystem.
1182                WP_Filesystem( request_filesystem_credentials( 'options.php', '', false, false, null ) );
1183
1184                // Get the text of the uploaded file and trim it to remove space from either end.
1185                $import_file_text = trim( $wp_filesystem->get_contents( $_FILES['import_file']['tmp_name'] ) );
1186
1187                if( $import_file_text ) {
1188                        $string = stripslashes( $import_file_text );
1189
1190                        // check string is serialized and unserialize it
1191                        if( is_serialized( $string ) ) {
1192                                $try = unserialize( ( $string ) );
1193                        }
1194
1195                        // make sure $try is set with the unserialized data
1196                        if( $try ) {
1197                                add_settings_error( 'cyberchimps_options', 'imported_success', __( 'Options Imported', 'cyberchimps_core' ), 'updated fade' );
1198
1199                                return $try;
1200                        }
1201                        else {
1202                                add_settings_error( 'cyberchimps_options', 'imported_failed', __( 'Invalid Data for Import', 'cyberchimps_core' ), 'error fade' );
1203                        }
1204                }
1205        }
1206        // If no file is uploaded then check for the texarea field for improt option.
1207        else {
1208                if( isset( $_POST['import'] ) ) {
1209                        if( trim( $_POST['import'] ) ) {
1210
1211                                $string = stripslashes( trim( $_POST['import'] ) );
1212
1213                                // check string is serialized and unserialize it
1214                                if( is_serialized( $string ) ) {
1215                                        $try = unserialize( ( $string ) );
1216                                }
1217
1218                                // make sure $try is set with the unserialized data
1219                                if( $try ) {
1220                                        add_settings_error( 'cyberchimps_options', 'imported_success', __( 'Options Imported', 'cyberchimps_core' ), 'updated fade' );
1221
1222                                        return $try;
1223                                }
1224                                else {
1225                                        add_settings_error( 'cyberchimps_options', 'imported_failed', __( 'Invalid Data for Import', 'cyberchimps_core' ), 'error fade' );
1226                                }
1227                        }
1228                }
1229        }
1230
1231        /*
1232         * Restore Defaults.
1233         *
1234         * In the event that the user clicked the "Restore Defaults"
1235         * button, the options defined in the theme's options.php
1236         * file will be added to the option for the active theme.
1237         */
1238        if( isset( $_POST['reset'] ) ) {
1239                add_settings_error( 'cyberchimps_options', 'restore_defaults', __( 'Default options restored.', 'cyberchimps_core' ), 'updated fade' );
1240
1241                return cyberchimps_get_default_values();
1242        }
1243
1244        /*
1245         * Update Settings
1246         *
1247         * This used to check for $_POST['update'], but has been updated
1248         * to be compatible with the theme customizer introduced in WordPress 3.4
1249         */
1250        else {
1251                $clean   = array();
1252                $options = cyberchimps_get_fields();
1253                foreach( $options as $option ) {
1254                        if( !isset( $option['id'] ) ) {
1255                                continue;
1256                        }
1257
1258                        if( !isset( $option['type'] ) ) {
1259                                continue;
1260                        }
1261
1262                        $id = preg_replace( '/[^a-zA-Z0-9._\-]/', '', strtolower( $option['id'] ) );
1263
1264                        // Set upload to false if it wasn't sent in the $_POST
1265                        if( 'info' == $option['type'] && !isset( $input[$id] ) ) {
1266                                $input[$id] = false;
1267                        }
1268
1269                        // Set upload to false if it wasn't sent in the $_POST
1270                        if( 'upload' == $option['type'] && !isset( $input[$id] ) ) {
1271                                $input[$id] = false;
1272                        }
1273
1274                        // Set radio to false if it wasn't sent in the $_POST
1275                        if( 'radio' == $option['type'] && !isset( $input[$id] ) ) {
1276                                $input[$id] = false;
1277                        }
1278
1279                        // Set toggle to false if it wasn't sent in the $_POST
1280                        if( 'toggle' == $option['type'] && !isset( $input[$id] ) ) {
1281                                $input[$id] = false;
1282                        }
1283
1284                        // Set checkbox to false if it wasn't sent in the $_POST
1285                        if( 'checkbox' == $option['type'] && !isset( $input[$id] ) ) {
1286                                $input[$id] = false;
1287                        }
1288
1289                        // Set checkbox to false if it wasn't sent in the $_POST
1290                        if( 'images' == $option['type'] && !isset( $input[$id] ) ) {
1291                                $input[$id] = false;
1292                        }
1293
1294                        // Set each item in the multicheck to false if it wasn't sent in the $_POST
1295                        if( 'multicheck' == $option['type'] && !isset( $input[$id] ) ) {
1296                                foreach( $option['options'] as $key => $value ) {
1297                                        $input[$id][$key] = false;
1298                                }
1299                        }
1300
1301                        // Catch any other id's that have not been set and set them to false. For some themes we remove options and we don't want them causing a problem
1302                        if( !isset( $input[$id] ) ) {
1303                                $input[$id] = false;
1304                        }
1305
1306                        // For a value to be submitted to database it must pass through a sanitization filter
1307                        if( has_filter( 'cyberchimps_sanitize_' . $option['type'] ) ) {
1308                                $clean[$id] = apply_filters( 'cyberchimps_sanitize_' . $option['type'], $input[$id], $option );
1309                        }
1310                }
1311
1312                do_action( 'cyberchimps_options_before_save', $input );
1313
1314                add_settings_error( 'cyberchimps_options', 'save_options', __( 'Options saved.', 'cyberchimps_core' ), 'updated fade' );
1315
1316                return $clean;
1317        }
1318}
1319
1320/**
1321 * Format Configuration Array.
1322 *
1323 * Get an array of all default values as set in
1324 * options.php. The 'id','std' and 'type' keys need
1325 * to be defined in the configuration array. In the
1326 * event that these keys are not present the option
1327 * will not be included in this function's output.
1328 *
1329 * @return    array     Rey-keyed options configuration array.
1330 *
1331 * @access    private
1332 */
1333function cyberchimps_get_default_values() {
1334        $output = array();
1335        $config = cyberchimps_get_fields();
1336        foreach( (array)$config as $option ) {
1337                if( !isset( $option['id'] ) ) {
1338                        continue;
1339                }
1340                if( !isset( $option['std'] ) ) {
1341                        continue;
1342                }
1343                if( !isset( $option['type'] ) ) {
1344                        continue;
1345                }
1346                if( has_filter( 'cyberchimps_sanitize_' . $option['type'] ) ) {
1347                        $output[$option['id']] = apply_filters( 'cyberchimps_sanitize_' . $option['type'], $option['std'], $option );
1348                }
1349        }
1350
1351        return $output;
1352}
1353
1354/**
1355 * Add Theme Options menu item to Admin Bar.
1356 */
1357function cyberchimps_admin_bar() {
1358        global $wp_admin_bar;
1359
1360        $wp_admin_bar->add_menu( array(
1361                                         'parent' => 'appearance',
1362                                         'id'     => 'cyberchimps_options_page',
1363                                         'title'  => __( 'Theme Options', 'cyberchimps_core' ),
1364                                         'href'   => admin_url( 'themes.php?page=cyberchimps-theme-options' )
1365                                 ) );
1366}
1367
1368/** Sticky Header **/
1369add_action( 'wp_footer', 'cyberchimps_fixed_menu_onscroll' );
1370function cyberchimps_fixed_menu_onscroll()
1371{
1372   
1373        if( cyberchimps_get_option( 'sticky_header', 'checked' ) ) {
1374           
1375        ?>
1376                <script type="text/javascript">
1377                jQuery(document).ready(function($){
1378                        $(window).scroll(function()  {
1379                        if ($(this).scrollTop() > 0) {
1380                        $('#header_section').addClass("sticky-header");
1381                       
1382                        }
1383                        else{
1384                        $('#header_section').removeClass("sticky-header");
1385                       
1386                        }
1387                        });
1388                });
1389                </script>
1390        <?php
1391        }
1392}
Note: See TracBrowser for help on using the repository browser.