wp/wp-content/themes/IN-MOTION-package-u1/option-tree/includes/ot-functions-admin.php
changeset 0 d970ebf37754
equal deleted inserted replaced
-1:000000000000 0:d970ebf37754
       
     1 <?php if ( ! defined( 'OT_VERSION' ) ) exit( 'No direct script access allowed' );
       
     2 /**
       
     3  * Functions used only while viewing the admin UI.
       
     4  *
       
     5  * Limit loading these function only when needed 
       
     6  * and not in the front end.
       
     7  *
       
     8  * @package   OptionTree
       
     9  * @author    Derek Herman <derek@valendesigns.com>
       
    10  * @copyright Copyright (c) 2012, Derek Herman
       
    11  * @since     2.0
       
    12  */
       
    13 
       
    14 /**
       
    15  * Runs directly after the Theme Options are save.
       
    16  *
       
    17  * @return    void
       
    18  *
       
    19  * @access    public
       
    20  * @since     2.0
       
    21  */
       
    22 if ( ! function_exists( 'ot_after_theme_options_save' ) ) {
       
    23 
       
    24   function ot_after_theme_options_save() {
       
    25   
       
    26     $page = isset( $_REQUEST['page'] ) ? $_REQUEST['page'] : '';
       
    27     $updated = isset( $_REQUEST['settings-updated'] ) && $_REQUEST['settings-updated'] == 'true' ? true : false;
       
    28     
       
    29     /* only execute after the theme options are saved */
       
    30     if ( 'ot-theme-options' == $page && $updated ) {
       
    31       
       
    32       /* grab a copy of the theme options */
       
    33       $options = get_option( 'option_tree' );
       
    34       
       
    35       /* execute the action hook and pass the theme options to it */
       
    36       do_action( 'ot_after_theme_options_save', $options );
       
    37       
       
    38     }
       
    39   
       
    40   }
       
    41 
       
    42 }
       
    43 
       
    44 /**
       
    45  * Validate the options by type before saving.
       
    46  *
       
    47  * This function will run on only some of the option types
       
    48  * as all of them don't need to be validated, just the
       
    49  * ones users are going to input data into; because they
       
    50  * can't be trusted.
       
    51  *
       
    52  * @param     mixed     Setting value
       
    53  * @param     string    Setting type
       
    54  * @param     string    Setting field ID
       
    55  * @return    mixed
       
    56  *
       
    57  * @access    public
       
    58  * @since     2.0
       
    59  */
       
    60 if ( ! function_exists( 'ot_validate_setting' ) ) {
       
    61 
       
    62   function ot_validate_setting( $input, $type, $field_id ) {
       
    63     
       
    64     /* exit early if missing data */
       
    65     if ( ! $input || ! $type || ! $field_id )
       
    66       return $input;
       
    67     
       
    68     $input = apply_filters( 'ot_validate_setting', $input, $type, $field_id );
       
    69     
       
    70     if ( 'background' == $type ) {
       
    71 
       
    72       $input['background-color'] = ot_validate_setting( $input['background-color'], 'colorpicker', $field_id );
       
    73       
       
    74       $input['background-image'] = ot_validate_setting( $input['background-image'], 'upload', $field_id );
       
    75       
       
    76     } else if ( 'colorpicker' == $type ) {
       
    77 
       
    78       /* return empty & set error */
       
    79       if ( 0 === preg_match( '/^#([a-f0-9]{6}|[a-f0-9]{3})$/i', $input ) ) {
       
    80         
       
    81         $input = '';
       
    82         
       
    83         add_settings_error( 'option-tree', 'invalid_hex', __( 'The Colorpicker only allows valid hexadecimal values.', 'option-tree' ), 'error' );
       
    84       
       
    85       }
       
    86     
       
    87     } else if ( in_array( $type, array( 'css', 'text', 'textarea', 'textarea-simple' ) ) ) {
       
    88       
       
    89       if ( ! current_user_can( 'unfiltered_html' ) && OT_ALLOW_UNFILTERED_HTML == false ) {
       
    90       
       
    91         $input = wp_kses_post( $input );
       
    92         
       
    93       }
       
    94             
       
    95     } else if ( 'measurement' == $type ) {
       
    96     
       
    97       $input[0] = sanitize_text_field( $input[0] );
       
    98       
       
    99     } else if ( 'typography' == $type ) {
       
   100       
       
   101       $input['font-color'] = ot_validate_setting( $input['font-color'], 'colorpicker', $field_id );
       
   102     
       
   103     } else if ( 'upload' == $type ) {
       
   104 
       
   105       $input = sanitize_text_field( $input );
       
   106          
       
   107     }
       
   108     
       
   109     $input = apply_filters( 'ot_after_validate_setting', $input, $type, $field_id );
       
   110  
       
   111     return $input;
       
   112     
       
   113   }
       
   114 
       
   115 }
       
   116   
       
   117 /**
       
   118  * Setup the default admin styles
       
   119  *
       
   120  * @return    void
       
   121  *
       
   122  * @access    public
       
   123  * @since     2.0
       
   124  */
       
   125 if ( ! function_exists( 'ot_admin_styles' ) ) {
       
   126 
       
   127   function ot_admin_styles() {
       
   128   
       
   129     wp_enqueue_style( 'ot-admin-css', OT_URL . 'assets/css/ot-admin.css', false, OT_VERSION );
       
   130     
       
   131   }
       
   132   
       
   133 }
       
   134 
       
   135 /**
       
   136  * Setup the default admin scripts
       
   137  *
       
   138  * @uses      add_thickbox()          Include Thickbox for file uploads
       
   139  * @uses      wp_enqueue_script()     Add OptionTree scripts
       
   140  * @uses      wp_localize_script()    Used to include arbitrary Javascript data
       
   141  *
       
   142  * @return    void
       
   143  *
       
   144  * @access    public
       
   145  * @since     2.0
       
   146  */
       
   147 if ( ! function_exists( 'ot_admin_scripts' ) ) {
       
   148 
       
   149   function ot_admin_scripts() {
       
   150 
       
   151     /* enqueue admin scripts */
       
   152     add_thickbox();
       
   153     
       
   154     /* load the colorpicker */
       
   155     wp_enqueue_script( 'ot-colorpicker-js', OT_URL . 'assets/js/ot-colorpicker.js', array( 'jquery' ), OT_VERSION );
       
   156     
       
   157     /* load all the required scripts */
       
   158     wp_enqueue_script( 'ot-admin-js', OT_URL . 'assets/js/ot-admin.js', array( 'jquery', 'jquery-ui-tabs', 'jquery-ui-sortable', 'media-upload', 'thickbox' ), OT_VERSION );
       
   159     
       
   160     /* create localized JS array */
       
   161     $localized_array = array( 
       
   162       'ajax'                  => admin_url( 'admin-ajax.php' ),
       
   163       'upload_text'           => __( 'Send to OptionTree', 'option-tree' ),
       
   164       'remove_media_text'     => __( 'Remove Media', 'option-tree' ),
       
   165       'reset_agree'           => __( 'Are you sure you want to reset back to the defaults?', 'option-tree' ),
       
   166       'remove_no'             => __( 'You can\'t remove this! But you can edit the values.', 'option-tree' ),
       
   167       'remove_agree'          => __( 'Are you sure you want to remove this?', 'option-tree' ),
       
   168       'activate_layout_agree' => __( 'Are you sure you want to activate this layout?', 'option-tree' ),
       
   169       'setting_limit'         => __( 'Sorry, you can\'t have settings three levels deep.', 'option-tree' )
       
   170     );
       
   171     
       
   172     /* localized script attached to 'option_tree' */
       
   173     wp_localize_script( 'ot-admin-js', 'option_tree', $localized_array );
       
   174 
       
   175   }
       
   176   
       
   177 }
       
   178 
       
   179 /**
       
   180  * Returns the ID of a custom post type by post_name.
       
   181  *
       
   182  * @uses        get_results()
       
   183  *
       
   184  * @return      int
       
   185  *
       
   186  * @access      public
       
   187  * @since       2.0
       
   188  */
       
   189 if ( ! function_exists( 'ot_get_media_post_ID' ) ) {
       
   190 
       
   191   function ot_get_media_post_ID() {
       
   192     global $wpdb;
       
   193     
       
   194     return $wpdb->get_var( "SELECT ID FROM $wpdb->posts WHERE `post_name` = 'media' AND `post_type` = 'option-tree' AND `post_status` = 'private'" );
       
   195     
       
   196   }
       
   197 
       
   198 }
       
   199 
       
   200 /**
       
   201  * Register custom post type & create the media post used to attach images.
       
   202  *
       
   203  * @uses        get_results()
       
   204  *
       
   205  * @return      void
       
   206  *
       
   207  * @access      public
       
   208  * @since       2.0
       
   209  */
       
   210 if ( ! function_exists( 'ot_create_media_post' ) ) {
       
   211   
       
   212   function ot_create_media_post() {
       
   213     
       
   214     register_post_type( 'option-tree', array(
       
   215       'labels'              => array( 'name' => __( 'Option Tree', 'option-tree' ) ),
       
   216       'public'              => false,
       
   217       'show_ui'             => false,
       
   218       'capability_type'     => 'post',
       
   219       'exclude_from_search' => true,
       
   220       'hierarchical'        => false,
       
   221       'rewrite'             => false,
       
   222       'supports'            => array( 'title', 'editor' ),
       
   223       'can_export'          => true,
       
   224       'show_in_nav_menus'   => false
       
   225     ) );
       
   226   
       
   227     /* look for custom page */
       
   228     $post_id = ot_get_media_post_ID();
       
   229       
       
   230     /* no post exists */
       
   231     if ( $post_id == 0 ) {
       
   232       
       
   233       /* create post object */
       
   234       $_p = array();
       
   235       $_p['post_title']     = 'Media';
       
   236       $_p['post_status']    = 'private';
       
   237       $_p['post_type']      = 'option-tree';
       
   238       $_p['comment_status'] = 'closed';
       
   239       $_p['ping_status']    = 'closed';
       
   240       
       
   241       /* insert the post into the database */
       
   242       wp_insert_post( $_p );
       
   243       
       
   244     }
       
   245   
       
   246   }
       
   247 
       
   248 }
       
   249 
       
   250 /**
       
   251  * Setup default settings array.
       
   252  *
       
   253  * @return    void
       
   254  *
       
   255  * @access    public
       
   256  * @since     2.0
       
   257  */
       
   258 if ( ! function_exists( 'ot_default_settings' ) ) {
       
   259 
       
   260   function ot_default_settings() {
       
   261     global $wpdb, $table_prefix;
       
   262     
       
   263     if ( ! get_option( 'option_tree_settings' ) ) {
       
   264       
       
   265       $section_count = 0;
       
   266       $settings_count = 0;
       
   267       $settings = array();
       
   268       
       
   269       if ( mysql_num_rows( mysql_query( "SHOW TABLES LIKE '{$table_prefix}option_tree'" ) ) == 1 && $old_settings = $wpdb->get_results( "SELECT * FROM {$table_prefix}option_tree ORDER BY item_sort ASC" ) ) {
       
   270         
       
   271         foreach ( $old_settings as $setting ) {
       
   272           
       
   273           /* heading is a section now */
       
   274           if ( $setting->item_type == 'heading' ) {
       
   275             
       
   276             /* add section to the sections array */
       
   277             $settings['sections'][$section_count]['id'] = $setting->item_id;
       
   278             $settings['sections'][$section_count]['title'] = $setting->item_title;
       
   279             
       
   280             /* save the last section id to use in creating settings */
       
   281             $section = $setting->item_id;
       
   282             
       
   283             /* increment the section count */
       
   284             $section_count++;
       
   285             
       
   286           } else {
       
   287             
       
   288             /* add setting to the settings array */
       
   289             $settings['settings'][$settings_count]['id'] = $setting->item_id;
       
   290             $settings['settings'][$settings_count]['label'] = $setting->item_title;
       
   291             $settings['settings'][$settings_count]['desc'] = $setting->item_desc;
       
   292             $settings['settings'][$settings_count]['section'] = $section;
       
   293             $settings['settings'][$settings_count]['type'] = ot_map_old_option_types( $setting->item_type );
       
   294             $settings['settings'][$settings_count]['std'] = '';
       
   295             $settings['settings'][$settings_count]['class'] = '';
       
   296             
       
   297             /* textarea rows */
       
   298             $rows = '';
       
   299             if ( in_array( $settings['settings'][$settings_count]['type'], array( 'css', 'textarea' ) ) ) {
       
   300               if ( (int) $setting->item_options > 0 ) {
       
   301                 $rows = (int) $setting->item_options;
       
   302               } else {
       
   303                 $rows = 15;
       
   304               }
       
   305             }
       
   306             $settings['settings'][$settings_count]['rows'] = $rows;
       
   307             
       
   308             /* post type */
       
   309             $post_type = '';
       
   310             if ( in_array( $settings['settings'][$settings_count]['type'], array( 'custom-post-type-select', 'custom-post-type-checkbox' ) ) ) {
       
   311               if ( '' != $setting->item_options ) {
       
   312                 $post_type = $setting->item_options;
       
   313               } else {
       
   314                 $post_type = 'post';
       
   315               }
       
   316             }
       
   317             $settings['settings'][$settings_count]['post_type'] = $post_type;
       
   318             
       
   319             /* choices */
       
   320             $choices = array();
       
   321             if ( in_array( $settings['settings'][$settings_count]['type'], array( 'checkbox', 'radio', 'select' ) ) ) {
       
   322               if ( '' != $setting->item_options ) {
       
   323                 $choices = ot_convert_string_to_array( $setting->item_options );
       
   324               }
       
   325             }
       
   326             $settings['settings'][$settings_count]['choices'] = $choices;
       
   327             
       
   328             $settings_count++;
       
   329           }
       
   330         
       
   331         }
       
   332         
       
   333         /* make sure each setting has a section just incase */
       
   334         if ( isset( $settings['sections'] ) && isset( $settings['settings'] ) ) {
       
   335           foreach( $settings['settings'] as $k => $setting ) {
       
   336             if ( '' == $setting['section'] ) {
       
   337               $settings['settings'][$k]['section'] = $settings['sections'][0]['id'];
       
   338             }
       
   339           }
       
   340         }
       
   341           
       
   342       }
       
   343       
       
   344       /* if array if not properly formed create fallback settings array */
       
   345       if ( ! isset( $settings['sections'] ) || ! isset( $settings['settings'] ) ) {
       
   346         
       
   347         $settings = array(
       
   348           'sections' => array(
       
   349             array(
       
   350               'id'        => 'general',
       
   351               'title'     => __( 'General', 'option-tree' )
       
   352             )
       
   353           ),
       
   354           'settings' => array(
       
   355             array(
       
   356               'id'        => 'sample_text',
       
   357               'label'     => __( 'Sample Text Field Label', 'option-tree' ),
       
   358               'desc'      => __( 'Description for the sample text field.', 'option-tree' ),
       
   359               'section'   => 'general',
       
   360               'type'      => 'text',
       
   361               'std'       => '',
       
   362               'class'     => '',
       
   363               'rows'      => '',
       
   364               'post_type' => '',
       
   365               'choices'   => array()
       
   366             )
       
   367           )
       
   368         );
       
   369         
       
   370       }
       
   371       
       
   372       /* update the settings array */
       
   373       update_option( 'option_tree_settings', $settings );
       
   374       
       
   375       /* get option tree array */
       
   376       $options = get_option( 'option_tree' );
       
   377       
       
   378       /* validate options */
       
   379       if ( is_array( $options ) ) {
       
   380 
       
   381         foreach( $settings['settings'] as $setting ) {
       
   382         
       
   383           if ( isset( $options[$setting['id']] ) ) {
       
   384             
       
   385             $content = ot_stripslashes( $options[$setting['id']] );
       
   386             
       
   387             $options[$setting['id']] = ot_validate_setting( $content, $setting['type'], $setting['id'] );
       
   388             
       
   389           }
       
   390         
       
   391         }
       
   392         
       
   393         /* update the option tree array */
       
   394         update_option( 'option_tree', $options );
       
   395         
       
   396       }
       
   397       
       
   398     }
       
   399     
       
   400   }
       
   401 
       
   402 }
       
   403 
       
   404 /**
       
   405  * Helper function to update the CSS option type after save.
       
   406  *
       
   407  * @return    void
       
   408  *
       
   409  * @access    public
       
   410  * @since     2.0
       
   411  */
       
   412 if ( ! function_exists( 'ot_save_css' ) ) {
       
   413 
       
   414   function ot_save_css( $options ) {
       
   415     
       
   416     /* grab a copy of the settings */
       
   417     $settings = get_option( 'option_tree_settings' );
       
   418       
       
   419     /* has settings */
       
   420     if ( isset( $settings['settings'] ) ) {
       
   421         
       
   422       /* loop through sections and insert CSS when needed */
       
   423       foreach( $settings['settings'] as $k => $setting ) {
       
   424         
       
   425         /* is the CSS option type */
       
   426         if ( isset( $setting['type'] ) && 'css' == $setting['type'] ) {
       
   427 
       
   428           /* insert CSS into dynamic.css */
       
   429           if ( isset( $options[$setting['id']] ) && '' !== $options[$setting['id']] ) {
       
   430             
       
   431             ot_insert_css_with_markers( $setting['id'], $options[$setting['id']] );
       
   432           
       
   433           /* remove old CSS from dynamic.css */
       
   434           } else {
       
   435           
       
   436             ot_remove_old_css( $setting['id'] );
       
   437             
       
   438           }
       
   439           
       
   440         }
       
   441       
       
   442       }
       
   443       
       
   444     }
       
   445     
       
   446   }
       
   447 
       
   448 }
       
   449  
       
   450 /**
       
   451  * Helper function to load filters for XML mime type.
       
   452  *
       
   453  * @return    void
       
   454  *
       
   455  * @access    public
       
   456  * @since     2.0
       
   457  */
       
   458 if ( ! function_exists( 'ot_add_xml_to_upload_filetypes' ) ) {
       
   459 
       
   460   function ot_add_xml_to_upload_filetypes() {
       
   461     
       
   462     add_filter( 'upload_mimes', 'ot_upload_mimes' );
       
   463     add_filter( 'wp_mime_type_icon', 'ot_xml_mime_type_icon', 10, 2 );
       
   464   
       
   465   }
       
   466 
       
   467 }
       
   468 
       
   469 /**
       
   470  * Filter 'upload_mimes' and add xml. 
       
   471  *
       
   472  * @param     array     $mimes An array of valid upload mime types
       
   473  * @return    array
       
   474  *
       
   475  * @access    public
       
   476  * @since     2.0
       
   477  */
       
   478 if ( ! function_exists( 'ot_upload_mimes' ) ) {
       
   479 
       
   480   function ot_upload_mimes( $mimes ) {
       
   481   
       
   482     $mimes['xml'] = 'application/xml';
       
   483     
       
   484     return $mimes;
       
   485     
       
   486   }
       
   487 
       
   488 }
       
   489 
       
   490 /**
       
   491  * Filters 'wp_mime_type_icon' and have xml display as a document.
       
   492  *
       
   493  * @param     string    $icon The mime icon
       
   494  * @param     string    $mime The mime type
       
   495  * @return    string
       
   496  *
       
   497  * @access    public
       
   498  * @since     2.0
       
   499  */
       
   500 if ( ! function_exists( 'ot_xml_mime_type_icon' ) ) {
       
   501 
       
   502   function ot_xml_mime_type_icon( $icon, $mime ) {
       
   503   
       
   504     if ( $mime == 'application/xml' || $mime == 'text/xml' )
       
   505       return wp_mime_type_icon( 'document' );
       
   506       
       
   507     return $icon;
       
   508     
       
   509   }
       
   510 
       
   511 }
       
   512 
       
   513 /**
       
   514  * Import before the screen is displayed.
       
   515  *
       
   516  * @return    void
       
   517  *
       
   518  * @access    public
       
   519  * @since     2.0
       
   520  */
       
   521 if ( ! function_exists( 'ot_import' ) ) {
       
   522 
       
   523   function ot_import() {
       
   524     
       
   525     /* check and verify import xml nonce */
       
   526     if ( isset( $_POST['import_xml_nonce'] ) && wp_verify_nonce( $_POST['import_xml_nonce'], 'import_xml_form' ) ) {
       
   527 
       
   528       /* import input value */
       
   529       $file = isset( $_POST['import_xml'] ) ? esc_url( $_POST['import_xml'] ) : '';
       
   530       
       
   531       /* validate xml file */
       
   532       if ( preg_match( "/(.xml)$/i", $file ) && class_exists( 'SimpleXMLElement' ) && function_exists( 'file_get_contents' ) ) {
       
   533       
       
   534         $settings = ot_import_xml( $file );
       
   535         
       
   536       }
       
   537       
       
   538       /* default message */
       
   539       $message = 'failed';
       
   540       
       
   541       /* cleanup, save, & show success message */
       
   542       if ( isset( $settings ) && ! empty( $settings ) ) {
       
   543         
       
   544         /* delete file */
       
   545         if ( $file ) {
       
   546           global $wpdb;
       
   547           $attachmentid = $wpdb->get_var( "SELECT ID FROM {$wpdb->posts} WHERE guid='$file'" );
       
   548           wp_delete_attachment( $attachmentid, true );
       
   549         }
       
   550         
       
   551         /* update settings */
       
   552         update_option( 'option_tree_settings', $settings );
       
   553         
       
   554         /* set message */
       
   555         $message = 'success';
       
   556         
       
   557       }
       
   558       
       
   559       /* redirect */
       
   560       wp_redirect( add_query_arg( array( 'action' => 'import-xml', 'message' => $message ), $_POST['_wp_http_referer'] ) );
       
   561       exit;
       
   562       
       
   563     }
       
   564     
       
   565     /* check and verify import settings nonce */
       
   566     if ( isset( $_POST['import_settings_nonce'] ) && wp_verify_nonce( $_POST['import_settings_nonce'], 'import_settings_form' ) ) {
       
   567 
       
   568       /* textarea value */
       
   569       $textarea = isset( $_POST['import_settings'] ) ? unserialize( base64_decode( $_POST['import_settings'] ) ) : '';
       
   570       
       
   571       /* default message */
       
   572       $message = 'failed';
       
   573       
       
   574       /* is array: save & show success message */
       
   575       if ( is_array( $textarea ) ) {
       
   576         update_option( 'option_tree_settings', $textarea );
       
   577         $message = 'success';
       
   578       }
       
   579       
       
   580       /* redirect */
       
   581       wp_redirect( add_query_arg( array( 'action' => 'import-settings', 'message' => $message ), $_POST['_wp_http_referer'] ) );
       
   582       exit;
       
   583       
       
   584     }
       
   585     
       
   586     /* check and verify import theme options data nonce */
       
   587     if ( isset( $_POST['import_data_nonce'] ) && wp_verify_nonce( $_POST['import_data_nonce'], 'import_data_form' ) ) {
       
   588       
       
   589       /* default message */
       
   590       $message = 'failed';
       
   591       
       
   592       /* textarea value */
       
   593       $options = isset( $_POST['import_data'] ) ? unserialize( base64_decode( $_POST['import_data'] ) ) : '';
       
   594       
       
   595       /* get settings array */
       
   596       $settings = get_option( 'option_tree_settings' );
       
   597       
       
   598       /* has options */
       
   599       if ( is_array( $options ) ) {
       
   600         
       
   601         /* validate options */
       
   602         if ( is_array( $settings ) ) {
       
   603         
       
   604           foreach( $settings['settings'] as $setting ) {
       
   605           
       
   606             if ( isset( $options[$setting['id']] ) ) {
       
   607               
       
   608               $content = ot_stripslashes( $options[$setting['id']] );
       
   609               
       
   610               $options[$setting['id']] = ot_validate_setting( $content, $setting['type'], $setting['id'] );
       
   611               
       
   612             }
       
   613           
       
   614           }
       
   615         
       
   616         }
       
   617         
       
   618         /* update the option tree array */
       
   619         update_option( 'option_tree', $options );
       
   620         
       
   621         $message = 'success';
       
   622         
       
   623       }
       
   624       
       
   625       /* redirect accordingly */
       
   626       wp_redirect( add_query_arg( array( 'action' => 'import-data', 'message' => $message ), $_POST['_wp_http_referer'] ) );
       
   627       exit;
       
   628       
       
   629     }
       
   630     
       
   631     /* check and verify import layouts nonce */
       
   632     if ( isset( $_POST['import_layouts_nonce'] ) && wp_verify_nonce( $_POST['import_layouts_nonce'], 'import_layouts_form' ) ) {
       
   633       
       
   634       /* default message */
       
   635       $message = 'failed';
       
   636       
       
   637       /* textarea value */
       
   638       $layouts = isset( $_POST['import_layouts'] ) ? unserialize( base64_decode( $_POST['import_layouts'] ) ) : '';
       
   639       
       
   640       /* get settings array */
       
   641       $settings = get_option( 'option_tree_settings' );
       
   642       
       
   643       /* has layouts */
       
   644       if ( is_array( $layouts ) ) {
       
   645         
       
   646         /* validate options */
       
   647         if ( is_array( $settings ) ) {
       
   648           
       
   649           foreach( $layouts as $key => $value ) {
       
   650             
       
   651             if ( $key == 'active_layout' )
       
   652               continue;
       
   653               
       
   654             $options = unserialize( base64_decode( $value ) );
       
   655             
       
   656             foreach( $settings['settings'] as $setting ) {
       
   657 
       
   658               if ( isset( $options[$setting['id']] ) ) {
       
   659                 
       
   660                 $content = ot_stripslashes( $options[$setting['id']] );
       
   661                 
       
   662                 $options[$setting['id']] = ot_validate_setting( $content, $setting['type'], $setting['id'] );
       
   663                 
       
   664               }
       
   665             
       
   666             }
       
   667 
       
   668             $layouts[$key] = base64_encode( serialize( $options ) );
       
   669           
       
   670           }
       
   671         
       
   672         }
       
   673         
       
   674         /* update the option tree array */
       
   675         if ( isset( $layouts['active_layout'] ) ) {
       
   676         
       
   677           update_option( 'option_tree', unserialize( base64_decode( $layouts[$layouts['active_layout']] ) ) );
       
   678           
       
   679         }
       
   680         
       
   681         /* update the option tree layouts array */
       
   682         update_option( 'option_tree_layouts', $layouts );
       
   683         
       
   684         $message = 'success';
       
   685         
       
   686       }
       
   687         
       
   688       /* redirect accordingly */
       
   689       wp_redirect( add_query_arg( array( 'action' => 'import-layouts', 'message' => $message ), $_POST['_wp_http_referer'] ) );
       
   690       exit;
       
   691       
       
   692     }
       
   693     
       
   694     return false;
       
   695 
       
   696   }
       
   697   
       
   698 }
       
   699 
       
   700 /**
       
   701  * Export before the screen is displayed.
       
   702  *
       
   703  * @return    void
       
   704  *
       
   705  * @access    public
       
   706  * @since     2.0.8
       
   707  */
       
   708 if ( ! function_exists( 'ot_export' ) ) {
       
   709 
       
   710   function ot_export() {
       
   711     
       
   712     /* check and verify export settings file nonce */
       
   713     if ( isset( $_POST['export_settings_file_nonce'] ) && wp_verify_nonce( $_POST['export_settings_file_nonce'], 'export_settings_file_form' ) ) {
       
   714 
       
   715       ot_export_php_settings_array();
       
   716       
       
   717     }
       
   718     
       
   719   }
       
   720   
       
   721 }
       
   722 
       
   723 /**
       
   724  * Reusable XMl import helper function.
       
   725  *
       
   726  * @param     string    $file The path to the file.
       
   727  * @return    mixed     False or an array of settings.
       
   728  *
       
   729  * @access    public
       
   730  * @since     2.0.8
       
   731  */
       
   732 if ( ! function_exists( 'ot_import_xml' ) ) {
       
   733 
       
   734   function ot_import_xml( $file ) {
       
   735     
       
   736     if ( $rawdata = @file_get_contents( $file ) ) {
       
   737       
       
   738       $section_count = 0;
       
   739       $settings_count = 0;
       
   740       
       
   741       $section = '';
       
   742       
       
   743       $settings = array();
       
   744       $xml = new SimpleXMLElement( $rawdata );
       
   745   
       
   746       foreach ( $xml->row as $value ) {
       
   747         
       
   748         /* heading is a section now */
       
   749         if ( $value->item_type == 'heading' ) {
       
   750           
       
   751           /* add section to the sections array */
       
   752           $settings['sections'][$section_count]['id'] = (string) $value->item_id;
       
   753           $settings['sections'][$section_count]['title'] = (string) $value->item_title;
       
   754           
       
   755           /* save the last section id to use in creating settings */
       
   756           $section = (string) $value->item_id;
       
   757           
       
   758           /* increment the section count */
       
   759           $section_count++;
       
   760           
       
   761         } else {
       
   762           
       
   763           /* add setting to the settings array */
       
   764           $settings['settings'][$settings_count]['id'] = (string) $value->item_id;
       
   765           $settings['settings'][$settings_count]['label'] = (string) $value->item_title;
       
   766           $settings['settings'][$settings_count]['desc'] = (string) $value->item_desc;
       
   767           $settings['settings'][$settings_count]['section'] = $section;
       
   768           $settings['settings'][$settings_count]['type'] = ot_map_old_option_types( (string) $value->item_type );
       
   769           $settings['settings'][$settings_count]['std'] = '';
       
   770           $settings['settings'][$settings_count]['class'] = '';
       
   771           
       
   772           /* textarea rows */
       
   773           $rows = '';
       
   774           if ( in_array( $settings['settings'][$settings_count]['type'], array( 'css', 'textarea' ) ) ) {
       
   775             if ( (int) $value->item_options > 0 ) {
       
   776               $rows = (int) $value->item_options;
       
   777             } else {
       
   778               $rows = 15;
       
   779             }
       
   780           }
       
   781           $settings['settings'][$settings_count]['rows'] = $rows;
       
   782           
       
   783           /* post type */
       
   784           $post_type = '';
       
   785           if ( in_array( $settings['settings'][$settings_count]['type'], array( 'custom-post-type-select', 'custom-post-type-checkbox' ) ) ) {
       
   786             if ( '' != (string) $value->item_options ) {
       
   787               $post_type = (string) $value->item_options;
       
   788             } else {
       
   789               $post_type = 'post';
       
   790             }
       
   791           }
       
   792           $settings['settings'][$settings_count]['post_type'] = $post_type;
       
   793           
       
   794           /* choices */
       
   795           $choices = array();
       
   796           if ( in_array( $settings['settings'][$settings_count]['type'], array( 'checkbox', 'radio', 'select' ) ) ) {
       
   797             if ( '' != (string) $value->item_options ) {
       
   798               $choices = ot_convert_string_to_array( (string) $value->item_options );
       
   799             }
       
   800           }
       
   801           $settings['settings'][$settings_count]['choices'] = $choices;
       
   802           
       
   803           $settings_count++;
       
   804         }
       
   805   
       
   806       }
       
   807       
       
   808       /* make sure each setting has a section just incase */
       
   809       if ( isset( $settings['sections'] ) && isset( $settings['settings'] ) ) {
       
   810         foreach( $settings['settings'] as $k => $setting ) {
       
   811           if ( '' == $setting['section'] ) {
       
   812             $settings['settings'][$k]['section'] = $settings['sections'][0]['id'];
       
   813           }
       
   814         }
       
   815       }
       
   816       
       
   817       return $settings;
       
   818       
       
   819     }
       
   820     
       
   821     return false;
       
   822   }
       
   823 
       
   824 }
       
   825 
       
   826 /**
       
   827  * Export the Theme Mode theme-options.php
       
   828  *
       
   829  * @return    attachment
       
   830  *
       
   831  * @access    public
       
   832  * @since     2.0.8
       
   833  */
       
   834 if ( ! function_exists( 'ot_export_php_settings_array' ) ) {
       
   835 
       
   836   function ot_export_php_settings_array() {
       
   837     
       
   838     $content              = '';
       
   839     $build_settings       = '';
       
   840     $contextual_help      = '';
       
   841     $sections             = '';
       
   842     $settings             = '';
       
   843     $option_tree_settings = get_option( 'option_tree_settings', array() );
       
   844     
       
   845     header( "Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
       
   846     header( "Pragma: no-cache ");
       
   847     header( "Content-Description: File Transfer" );
       
   848     header( 'Content-Disposition: attachment; filename="theme-options.php"');
       
   849     header( "Content-Type: application/octet-stream");
       
   850     header( "Content-Transfer-Encoding: binary" );
       
   851     
       
   852     /* build contextual help content */
       
   853     if ( isset( $option_tree_settings['contextual_help']['content'] ) ) {
       
   854       $help = '';
       
   855       foreach( $option_tree_settings['contextual_help']['content'] as $value ) {
       
   856         $_id = isset( $value['id'] ) ? $value['id'] : '';
       
   857         $_title = isset( $value['title'] ) ? str_replace( "'", "\'", $value['title'] ) : '';
       
   858         $_content = isset( $value['content'] ) ? html_entity_decode(  str_replace( "'", "\'", $value['content'] ) ) : '';
       
   859         $help.= "
       
   860         array(
       
   861           'id'        => '$_id',
       
   862           'title'     => '$_title',
       
   863           'content'   => '$_content'
       
   864         ),";
       
   865       }
       
   866       $help = substr_replace( $help, '' , -1 );
       
   867       $contextual_help = "
       
   868       'content'       => array( $help
       
   869       ),";
       
   870     }
       
   871     
       
   872     /* build contextual help sidebar */
       
   873     if ( isset( $option_tree_settings['contextual_help']['sidebar'] ) ) {
       
   874       $contextual_help.= "
       
   875       'sidebar'       => '" . html_entity_decode(  str_replace( "'", "\'", $option_tree_settings['contextual_help']['sidebar'] ) ) . "'";
       
   876     }
       
   877     
       
   878     /* check that $contexual_help has a value and add to $build_settings */
       
   879     if ( '' != $contextual_help ) {
       
   880       $build_settings.= "
       
   881     'contextual_help' => array( $contextual_help
       
   882     ),";
       
   883     }
       
   884     
       
   885     /* build sections */
       
   886     if ( isset( $option_tree_settings['sections'] ) ) {
       
   887       foreach( $option_tree_settings['sections'] as $value ) {
       
   888         $_id = isset( $value['id'] ) ? $value['id'] : '';
       
   889         $_title = isset( $value['title'] ) ? str_replace( "'", "\'", $value['title'] ) : '';
       
   890         $sections.= "
       
   891       array(
       
   892         'id'          => '$_id',
       
   893         'title'       => '$_title'
       
   894       ),";
       
   895       }
       
   896       $sections = substr_replace( $sections, '' , -1 );
       
   897     }
       
   898     
       
   899     /* check that $sections has a value and add to $build_settings */
       
   900     if ( '' != $sections ) {
       
   901       $build_settings.= "
       
   902     'sections'        => array( $sections
       
   903     )";
       
   904     }
       
   905     
       
   906     /* build settings */
       
   907     if ( isset( $option_tree_settings['settings'] ) ) {
       
   908       foreach( $option_tree_settings['settings'] as $value ) {
       
   909         $_id = isset( $value['id'] ) ? $value['id'] : '';
       
   910         $_label = isset( $value['label'] ) ? str_replace( "'", "\'", $value['label'] ) : '';
       
   911         $_desc = isset( $value['desc'] ) ? str_replace( "'", "\'", $value['desc'] ) : '';
       
   912         $_std = isset( $value['std'] ) ? $value['std'] : '';
       
   913         $_type = isset( $value['type'] ) ? $value['type'] : '';
       
   914         $_section = isset( $value['section'] ) ? $value['section'] : '';
       
   915         $_rows = isset( $value['rows'] ) ? $value['rows'] : '';
       
   916         $_post_type = isset( $value['post_type'] ) ? $value['post_type'] : '';
       
   917         $_taxonomy = isset( $value['taxonomy'] ) ? $value['taxonomy'] : '';
       
   918         $_class = isset( $value['class'] ) ? $value['class'] : '';
       
   919         
       
   920         $choices = '';
       
   921         if ( isset( $value['choices'] ) && ! empty( $value['choices'] ) ) {
       
   922           foreach( $value['choices'] as $choice ) {
       
   923             $_choice_value = isset( $choice['value'] ) ? $choice['value'] : '';
       
   924             $_choice_label = isset( $choice['label'] ) ? str_replace( "'", "\'", $choice['label'] ) : '';
       
   925             $_choice_src = isset( $choice['src'] ) ? str_replace( "'", "\'", $choice['src'] ) : '';
       
   926             $choices.= "
       
   927           array(
       
   928             'value'       => '$_choice_value',
       
   929             'label'       => '$_choice_label',
       
   930             'src'         => '$_choice_src'
       
   931           ),";
       
   932           }
       
   933           $choices = substr_replace( $choices, '' , -1 );
       
   934           $choices = ",
       
   935         'choices'     => array( $choices
       
   936         ),";
       
   937         }
       
   938         
       
   939         $setting_settings = '';
       
   940         if ( isset( $value['settings'] ) && ! empty( $value['settings'] ) ) {
       
   941           foreach( $value['settings'] as $setting ) {
       
   942             $_setting_id = isset( $setting['id'] ) ? $setting['id'] : '';
       
   943             $_setting_label = isset( $setting['label'] ) ? str_replace( "'", "\'", $setting['label'] ) : '';
       
   944             $_setting_desc = isset( $setting['desc'] ) ? str_replace( "'", "\'", $setting['desc'] ) : '';
       
   945             $_setting_std = isset( $setting['std'] ) ? $setting['std'] : '';
       
   946             $_setting_type = isset( $setting['type'] ) ? $setting['type'] : '';
       
   947             $_setting_rows = isset( $setting['rows'] ) ? $setting['rows'] : '';
       
   948             $_setting_post_type = isset( $setting['post_type'] ) ? $setting['post_type'] : '';
       
   949             $_setting_taxonomy = isset( $setting['taxonomy'] ) ? $setting['taxonomy'] : '';
       
   950             $_setting_class = isset( $setting['class'] ) ? $setting['class'] : '';
       
   951             
       
   952             $setting_choices = '';
       
   953             if ( isset( $setting['choices'] ) && ! empty( $setting['choices'] ) ) {
       
   954               foreach( $setting['choices'] as $setting_choice ) {
       
   955                 $_setting_choice_value = isset( $setting_choice['value'] ) ? $setting_choice['value'] : '';
       
   956                 $_setting_choice_label = isset( $setting_choice['label'] ) ? str_replace( "'", "\'", $setting_choice['label'] ) : '';
       
   957                 $_setting_choice_src = isset( $setting_choice['src'] ) ? str_replace( "'", "\'", $setting_choice['src'] ) : '';
       
   958                 $setting_choices.= "
       
   959               array(
       
   960                 'value'       => '$_setting_choice_value',
       
   961                 'label'       => '$_setting_choice_label',
       
   962                 'src'         => '$_setting_choice_src'
       
   963               ),";
       
   964               }
       
   965               $setting_choices = substr_replace( $setting_choices, '' , -1 );
       
   966               $setting_choices = ",
       
   967             'choices'     => array( $setting_choices
       
   968             ),";
       
   969             }
       
   970         
       
   971             $setting_settings.= "
       
   972           array(
       
   973             'id'          => '$_setting_id',
       
   974             'label'       => '$_setting_label',
       
   975             'desc'        => '$_setting_desc',
       
   976             'std'         => '$_setting_std',
       
   977             'type'        => '$_setting_type',
       
   978             'rows'        => '$_setting_rows',
       
   979             'post_type'   => '$_setting_post_type',
       
   980             'taxonomy'    => '$_setting_taxonomy',
       
   981             'class'       => '$_setting_class'$setting_choices
       
   982           ),";
       
   983           }
       
   984           $setting_settings = substr_replace( $setting_settings, '' , -1 );
       
   985           $setting_settings = ",
       
   986         'settings'    => array( $setting_settings
       
   987         )";
       
   988         }
       
   989         
       
   990         $settings.= "
       
   991       array(
       
   992         'id'          => '$_id',
       
   993         'label'       => '$_label',
       
   994         'desc'        => '$_desc',
       
   995         'std'         => '$_std',
       
   996         'type'        => '$_type',
       
   997         'section'     => '$_section',
       
   998         'rows'        => '$_rows',
       
   999         'post_type'   => '$_post_type',
       
  1000         'taxonomy'    => '$_taxonomy',
       
  1001         'class'       => '$_class'$choices$setting_settings
       
  1002       ),";
       
  1003       }
       
  1004       $settings = substr_replace( $settings, '' , -1 );
       
  1005     }
       
  1006     
       
  1007     /* check that $sections has a value and add to $build_settings */
       
  1008     if ( '' != $settings ) {
       
  1009       $build_settings.= ",
       
  1010     'settings'        => array( $settings
       
  1011     )";
       
  1012     }
       
  1013     
       
  1014     $content.= "<?php
       
  1015 /**
       
  1016  * Initialize the options before anything else.
       
  1017  */
       
  1018 add_action( 'admin_init', 'custom_theme_options', 1 );
       
  1019 
       
  1020 /**
       
  1021  * Build the custom settings & update OptionTree.
       
  1022  */
       
  1023 function custom_theme_options() {
       
  1024   /**
       
  1025    * Get a copy of the saved settings array. 
       
  1026    */
       
  1027   \$saved_settings = get_option( 'option_tree_settings', array() );
       
  1028   
       
  1029   /**
       
  1030    * Custom settings array that will eventually be 
       
  1031    * passes to the OptionTree Settings API Class.
       
  1032    */
       
  1033   \$custom_settings = array( $build_settings
       
  1034   );
       
  1035   
       
  1036   /* allow settings to be filtered before saving */
       
  1037   \$custom_settings = apply_filters( 'option_tree_settings_args', \$custom_settings );
       
  1038   
       
  1039   /* settings are not the same update the DB */
       
  1040   if ( \$saved_settings !== \$custom_settings ) {
       
  1041     update_option( 'option_tree_settings', \$custom_settings ); 
       
  1042   }
       
  1043   
       
  1044 }";
       
  1045 
       
  1046     echo $content;
       
  1047     die();
       
  1048   }
       
  1049 
       
  1050 }
       
  1051 
       
  1052 /**
       
  1053  * Save settings array before the screen is displayed.
       
  1054  *
       
  1055  * @return    void
       
  1056  *
       
  1057  * @access    public
       
  1058  * @since     2.0
       
  1059  */
       
  1060 if ( ! function_exists( 'ot_save_settings' ) ) {
       
  1061 
       
  1062   function ot_save_settings() {
       
  1063 
       
  1064     /* check and verify import settings nonce */
       
  1065     if ( isset( $_POST['option_tree_settings_nonce'] ) && wp_verify_nonce( $_POST['option_tree_settings_nonce'], 'option_tree_settings_form' ) ) {
       
  1066 
       
  1067       /* settings value */
       
  1068       $settings = isset( $_POST['option_tree_settings'] ) ? $_POST['option_tree_settings'] : '';
       
  1069       
       
  1070       /* validate sections */
       
  1071       if ( isset( $settings['sections'] ) ) {
       
  1072         
       
  1073         /* fix numeric keys since drag & drop will change them */
       
  1074         $settings['sections'] = array_values( $settings['sections'] );
       
  1075         
       
  1076         /* loop through sections */
       
  1077         foreach( $settings['sections'] as $k => $section ) {
       
  1078           
       
  1079           /* remove from array if missing values */
       
  1080           if ( ! $section['title'] && ! $section['id'] ) {
       
  1081           
       
  1082             unset( $settings['sections'][$k] );
       
  1083             
       
  1084           } else {
       
  1085             
       
  1086             /* validate label */
       
  1087             if ( '' != $section['title'] ) {
       
  1088             
       
  1089              $settings['sections'][$k]['title'] = wp_kses_post( $section['title'] );
       
  1090               
       
  1091             }
       
  1092             
       
  1093             /* missing title set to unfiltered ID */
       
  1094             if ( ! $section['title'] ) {
       
  1095               
       
  1096               $settings['sections'][$k]['title'] = wp_kses_post( $section['id'] );
       
  1097             
       
  1098             /* missing ID set to title */ 
       
  1099             } else if ( ! $section['id'] ) {
       
  1100               
       
  1101               $section['id'] = wp_kses_post( $section['title'] );
       
  1102               
       
  1103             }
       
  1104             
       
  1105             /* sanitize ID once everything has been checked first */
       
  1106             $settings['sections'][$k]['id'] = ot_sanitize_option_id( wp_kses_post( $section['id'] ) );
       
  1107             
       
  1108           }
       
  1109           
       
  1110         }
       
  1111         
       
  1112         $settings['sections'] = ot_stripslashes( $settings['sections'] );
       
  1113       
       
  1114       }
       
  1115       
       
  1116       /* validate settings by looping over array as many times as it takes */
       
  1117       if ( isset( $settings['settings'] ) ) {
       
  1118         
       
  1119         $settings['settings'] = ot_validate_settings_array( $settings['settings'] );
       
  1120         
       
  1121       }
       
  1122       
       
  1123       /* validate contextual_help */
       
  1124       if ( isset( $settings['contextual_help']['content'] ) ) {
       
  1125         
       
  1126         /* fix numeric keys since drag & drop will change them */
       
  1127         $settings['contextual_help']['content'] = array_values( $settings['contextual_help']['content'] );
       
  1128         
       
  1129         /* loop through content */
       
  1130         foreach( $settings['contextual_help']['content'] as $k => $content ) {
       
  1131           
       
  1132           /* remove from array if missing values */
       
  1133           if ( ! $content['title'] && ! $content['id'] ) {
       
  1134           
       
  1135             unset( $settings['contextual_help']['content'][$k] );
       
  1136             
       
  1137           } else {
       
  1138             
       
  1139             /* validate label */
       
  1140             if ( '' != $content['title'] ) {
       
  1141             
       
  1142              $settings['contextual_help']['content'][$k]['title'] = wp_kses_post( $content['title'] );
       
  1143               
       
  1144             }
       
  1145           
       
  1146             /* missing title set to unfiltered ID */
       
  1147             if ( ! $content['title'] ) {
       
  1148               
       
  1149               $settings['contextual_help']['content'][$k]['title'] = wp_kses_post( $content['id'] );
       
  1150             
       
  1151             /* missing ID set to title */ 
       
  1152             } else if ( ! $content['id'] ) {
       
  1153               
       
  1154               $content['id'] = wp_kses_post( $content['title'] );
       
  1155               
       
  1156             }
       
  1157             
       
  1158             /* sanitize ID once everything has been checked first */
       
  1159             $settings['contextual_help']['content'][$k]['id'] = ot_sanitize_option_id( wp_kses_post( $content['id'] ) );
       
  1160             
       
  1161           }
       
  1162           
       
  1163           /* validate textarea description */
       
  1164           if ( isset( $content['content'] ) ) {
       
  1165           
       
  1166             $settings['contextual_help']['content'][$k]['content'] = wp_kses_post( $content['content'] );
       
  1167             
       
  1168           }
       
  1169           
       
  1170         }
       
  1171       
       
  1172       }
       
  1173       
       
  1174       /* validate contextual_help sidebar */
       
  1175       if ( isset( $settings['contextual_help']['sidebar'] ) ) {
       
  1176       
       
  1177         $settings['contextual_help']['sidebar'] = wp_kses_post( $settings['contextual_help']['sidebar'] );
       
  1178         
       
  1179       }
       
  1180       
       
  1181       
       
  1182       $settings['contextual_help'] = ot_stripslashes( $settings['contextual_help'] );
       
  1183       
       
  1184       /* default message */
       
  1185       $message = 'failed';
       
  1186       
       
  1187       /* is array: save & show success message */
       
  1188       if ( is_array( $settings ) ) {
       
  1189         update_option( 'option_tree_settings', $settings );
       
  1190         $message = 'success';
       
  1191       }
       
  1192       
       
  1193       /* redirect */
       
  1194       wp_redirect( add_query_arg( array( 'action' => 'save-settings', 'message' => $message ), $_POST['_wp_http_referer'] ) );
       
  1195       exit;
       
  1196       
       
  1197     }
       
  1198     
       
  1199     return false;
       
  1200 
       
  1201   }
       
  1202   
       
  1203 }
       
  1204 
       
  1205 /**
       
  1206  * Validate the settings array before save.
       
  1207  *
       
  1208  * This function will loop over the settings array as many 
       
  1209  * times as it takes to validate every sub setting.
       
  1210  *
       
  1211  * @param     array     $settings The array of settings.
       
  1212  * @return    array
       
  1213  *
       
  1214  * @access    public
       
  1215  * @since     2.0
       
  1216  */
       
  1217 if ( ! function_exists( 'ot_validate_settings_array' ) ) {
       
  1218 
       
  1219   function ot_validate_settings_array( $settings = array() ) {
       
  1220     
       
  1221     /* validate settings */
       
  1222     if ( count( $settings ) > 0 ) {
       
  1223       
       
  1224       /* fix numeric keys since drag & drop will change them */
       
  1225       $settings = array_values( $settings );
       
  1226       
       
  1227       /* loop through settings */
       
  1228       foreach( $settings as $k => $setting ) {
       
  1229         
       
  1230         
       
  1231         /* remove from array if missing values */
       
  1232         if ( ! $setting['label'] && ! $setting['id'] ) {
       
  1233         
       
  1234           unset( $settings[$k] );
       
  1235           
       
  1236         } else {
       
  1237           
       
  1238           /* validate label */
       
  1239           if ( '' != $setting['label'] ) {
       
  1240           
       
  1241             $settings[$k]['label'] = wp_kses_post( $setting['label'] );
       
  1242             
       
  1243           }
       
  1244           
       
  1245           /* missing label set to unfiltered ID */
       
  1246           if ( ! $setting['label'] ) {
       
  1247             
       
  1248             $settings[$k]['label'] = $setting['id'];
       
  1249           
       
  1250           /* missing ID set to label */ 
       
  1251           } else if ( ! $setting['id'] ) {
       
  1252             
       
  1253             $setting['id'] = wp_kses_post( $setting['label'] );
       
  1254             
       
  1255           }
       
  1256           
       
  1257           /* sanitize ID once everything has been checked first */
       
  1258           $settings[$k]['id'] = ot_sanitize_option_id( wp_kses_post( $setting['id'] ) );
       
  1259           
       
  1260         }
       
  1261         
       
  1262         /* validate description */
       
  1263         if ( '' != $setting['desc']  ) {
       
  1264         
       
  1265           $settings[$k]['desc'] = wp_kses_post( $setting['desc'] );
       
  1266           
       
  1267         }
       
  1268         
       
  1269         /* validate choices */
       
  1270         if ( isset( $setting['choices'] ) ) {
       
  1271           
       
  1272           /* loop through choices */
       
  1273           foreach( $setting['choices'] as $ck => $choice ) {
       
  1274             
       
  1275             /* remove from array if missing values */
       
  1276             if ( ! $choice['label'] && ! $choice['value'] ) {
       
  1277         
       
  1278               unset( $setting['choices'][$ck] );
       
  1279               
       
  1280             } else {
       
  1281               
       
  1282               /* missing label set to unfiltered ID */
       
  1283               if ( ! $choice['label'] ) {
       
  1284                 
       
  1285                 $setting['choices'][$ck]['label'] = wp_kses_post( $choice['value'] );
       
  1286               
       
  1287               /* missing value set to label */ 
       
  1288               } else if ( ! $choice['value'] ) {
       
  1289                 
       
  1290                 $setting['choices'][$ck]['value'] = ot_sanitize_option_id( wp_kses_post( $choice['label'] ) );
       
  1291                 
       
  1292               }
       
  1293               
       
  1294             }
       
  1295             
       
  1296           }
       
  1297           
       
  1298           /* update keys and push new array values */
       
  1299           $settings[$k]['choices'] = array_values( $setting['choices'] );
       
  1300           
       
  1301         }
       
  1302         
       
  1303         /* validate sub settings */
       
  1304         if ( isset( $setting['settings'] ) ) {
       
  1305 
       
  1306           $settings[$k]['settings'] = ot_validate_settings_array( $setting['settings'] );
       
  1307           
       
  1308         }
       
  1309 
       
  1310       }
       
  1311     
       
  1312     }
       
  1313     
       
  1314     /* return array but strip those damn slashes out first!!! */
       
  1315     return ot_stripslashes( $settings );
       
  1316     
       
  1317   }
       
  1318 
       
  1319 }
       
  1320 
       
  1321 /**
       
  1322  * Save layouts array before the screen is displayed.
       
  1323  *
       
  1324  * @return    void
       
  1325  *
       
  1326  * @access    public
       
  1327  * @since     2.0
       
  1328  */
       
  1329 if ( ! function_exists( 'ot_modify_layouts' ) ) {
       
  1330 
       
  1331   function ot_modify_layouts() {
       
  1332 
       
  1333     /* check and verify modify layouts nonce */
       
  1334     if ( isset( $_POST['option_tree_modify_layouts_nonce'] ) && wp_verify_nonce( $_POST['option_tree_modify_layouts_nonce'], 'option_tree_modify_layouts_form' ) ) {
       
  1335       
       
  1336       /* previous layouts value */
       
  1337       $option_tree_layouts = get_option( 'option_tree_layouts' );
       
  1338       
       
  1339       /* new layouts value */
       
  1340       $layouts = isset( $_POST['option_tree_layouts'] ) ? $_POST['option_tree_layouts'] : '';
       
  1341       
       
  1342       /* rebuild layout array */
       
  1343       $rebuild = array();
       
  1344       
       
  1345       /* validate layouts */
       
  1346       if ( is_array( $layouts ) && ! empty( $layouts ) ) {
       
  1347         
       
  1348         /* setup active layout */
       
  1349         if ( isset( $layouts['active_layout'] ) && '' != $layouts['active_layout'] ) {
       
  1350           $rebuild['active_layout'] = $layouts['active_layout'];
       
  1351         }
       
  1352         
       
  1353         /* add new and overwrite active layout */
       
  1354         if ( isset( $layouts['_add_new_layout_'] ) && '' != $layouts['_add_new_layout_'] ) {
       
  1355           $rebuild['active_layout'] = ot_sanitize_layout_id( $layouts['_add_new_layout_'] );
       
  1356           $rebuild[$rebuild['active_layout']] = base64_encode( serialize( get_option( 'option_tree' ) ) );
       
  1357         }
       
  1358         
       
  1359         $first_layout = '';
       
  1360         
       
  1361         /* loop through layouts */
       
  1362         foreach( $layouts as $key => $layout ) {
       
  1363           
       
  1364           /* skip over active layout key */
       
  1365           if ( $key == 'active_layout' )
       
  1366             continue;
       
  1367           
       
  1368           /* check if the key exists then set value */
       
  1369           if ( isset( $option_tree_layouts[$key] ) ) {
       
  1370             $rebuild[$key] = $option_tree_layouts[$key];
       
  1371             if ( '' == $first_layout ) {
       
  1372               $first_layout = $key;
       
  1373             }
       
  1374           }
       
  1375           
       
  1376         }
       
  1377         
       
  1378         
       
  1379         if ( ! isset( $rebuild[$rebuild['active_layout']] ) && '' != $first_layout ) {
       
  1380           $rebuild['active_layout'] = $first_layout;
       
  1381         }
       
  1382         
       
  1383       }
       
  1384       
       
  1385       /* default message */
       
  1386       $message = 'failed';
       
  1387       
       
  1388       /* is array: save & show success message */
       
  1389       if ( count( $rebuild ) > 1 ) {
       
  1390         
       
  1391         /* rebuild the theme options */
       
  1392         $rebuild_option_tree = unserialize( base64_decode( $rebuild[$rebuild['active_layout']] ) );
       
  1393         if ( is_array( $rebuild_option_tree ) ) {
       
  1394           update_option( 'option_tree', $rebuild_option_tree );
       
  1395         }
       
  1396         
       
  1397         /* rebuild the layouts */
       
  1398         update_option( 'option_tree_layouts', $rebuild );
       
  1399         
       
  1400         /* change message */
       
  1401         $message = 'success';
       
  1402         
       
  1403       } else if ( count( $rebuild ) <= 1 ) {
       
  1404         
       
  1405         /* delete layouts option */
       
  1406         delete_option( 'option_tree_layouts' );
       
  1407         
       
  1408         /* change message */
       
  1409         $message = 'deleted';
       
  1410         
       
  1411       }
       
  1412       
       
  1413       /* redirect */
       
  1414       if ( isset( $_REQUEST['page'] ) && $_REQUEST['page'] == 'ot-theme-options' ) {
       
  1415         $query_args = add_query_arg( array( 'settings-updated' => 'layout' ), remove_query_arg( array( 'action', 'message' ), $_POST['_wp_http_referer'] ) );
       
  1416       } else {
       
  1417         $query_args = add_query_arg( array( 'action' => 'save-layouts', 'message' => $message ), $_POST['_wp_http_referer'] );
       
  1418       }
       
  1419       wp_redirect( $query_args );
       
  1420       exit;
       
  1421       
       
  1422     }
       
  1423     
       
  1424     return false;
       
  1425 
       
  1426   }
       
  1427   
       
  1428 }
       
  1429 
       
  1430 /**
       
  1431  * Helper function to display alert messages.
       
  1432  *
       
  1433  * @param     array     Page array
       
  1434  * @return    mixed
       
  1435  *
       
  1436  * @access    public
       
  1437  * @since     2.0
       
  1438  */
       
  1439 if ( ! function_exists( 'ot_alert_message' ) ) {
       
  1440 
       
  1441   function ot_alert_message( $page = array() ) {
       
  1442     
       
  1443     if ( empty( $page ) )
       
  1444       return false;
       
  1445     
       
  1446     $current_page = isset( $_REQUEST['page'] ) ? $_REQUEST['page'] : '';
       
  1447     $action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : '';
       
  1448     $message = isset( $_REQUEST['message'] ) ? $_REQUEST['message'] : '';
       
  1449     
       
  1450     /* theme options messages */
       
  1451     if ( $current_page == 'ot-theme-options' ) {
       
  1452     
       
  1453       if ( isset( $_POST['action'] ) && $_POST['action'] == 'reset' ) {
       
  1454       
       
  1455         return '<div id="message" class="updated fade below-h2"><p>' . $page['reset_message'] . '</p></div>';
       
  1456         
       
  1457       } else if ( isset( $_GET['settings-updated'] ) && $_GET['settings-updated'] == 'true' ) {  
       
  1458        
       
  1459         return '<div id="message" class="updated fade below-h2"><p>' . $page['updated_message'] . '</p></div>';
       
  1460         
       
  1461       } else if ( isset( $_GET['settings-updated'] ) && $_GET['settings-updated'] == 'layout' ) {  
       
  1462        
       
  1463         return '<div id="message" class="updated fade below-h2"><p>' . __( 'Layout activated.', 'option-tree' ) . '</p></div>';
       
  1464         
       
  1465       }
       
  1466       
       
  1467     }
       
  1468     
       
  1469     /* settings messages */
       
  1470     if ( $current_page == 'ot-settings' ) {
       
  1471       
       
  1472       if ( $action == 'save-settings' ) {
       
  1473       
       
  1474         if ( $message == 'success' ) {
       
  1475           
       
  1476           return '<div id="message" class="updated fade below-h2"><p>' . __( 'Settings updated.', 'option-tree' ) . '</p></div>';
       
  1477           
       
  1478         } else if ( $message == 'failed' ) {
       
  1479           
       
  1480           return '<div id="message" class="error fade below-h2"><p>' . __( 'Settings could not be saved.', 'option-tree' ) . '</p></div>';
       
  1481           
       
  1482         }
       
  1483         
       
  1484       } else if ( $action == 'import-xml' || $action == 'import-settings' ) {
       
  1485         
       
  1486         if ( $message == 'success' ) {
       
  1487           
       
  1488           return '<div id="message" class="updated fade below-h2"><p>' . __( 'Settings Imported.', 'option-tree' ) . '</p></div>';
       
  1489           
       
  1490         } else if ( $message == 'failed' ) {
       
  1491           
       
  1492           return '<div id="message" class="error fade below-h2"><p>' . __( 'Settings could not be imported.', 'option-tree' ) . '</p></div>';
       
  1493           
       
  1494         }
       
  1495       } else if ( $action == 'import-data' ) {
       
  1496         
       
  1497         if ( $message == 'success' ) {
       
  1498           
       
  1499           return '<div id="message" class="updated fade below-h2"><p>' . __( 'Data Imported.', 'option-tree' ) . '</p></div>';
       
  1500           
       
  1501         } else if ( $message == 'failed' ) {
       
  1502           
       
  1503           return '<div id="message" class="error fade below-h2"><p>' . __( 'Data could not be imported.', 'option-tree' ) . '</p></div>';
       
  1504           
       
  1505         }
       
  1506       
       
  1507       } else if ( $action == 'import-layouts' ) {
       
  1508         
       
  1509         if ( $message == 'success' ) {
       
  1510           
       
  1511           return '<div id="message" class="updated fade below-h2"><p>' . __( 'Layouts Imported.', 'option-tree' ) . '</p></div>';
       
  1512           
       
  1513         } else if ( $message == 'failed' ) {
       
  1514           
       
  1515           return '<div id="message" class="error fade below-h2"><p>' . __( 'Layouts could not be imported.', 'option-tree' ) . '</p></div>';
       
  1516           
       
  1517         }
       
  1518              
       
  1519       } else if ( $action == 'save-layouts' ) {
       
  1520         
       
  1521         if ( $message == 'success' ) {
       
  1522           
       
  1523           return '<div id="message" class="updated fade below-h2"><p>' . __( 'Layouts Updated.', 'option-tree' ) . '</p></div>';
       
  1524           
       
  1525         } else if ( $message == 'failed' ) {
       
  1526           
       
  1527           return '<div id="message" class="error fade below-h2"><p>' . __( 'Layouts could not be updated.', 'option-tree' ) . '</p></div>';
       
  1528           
       
  1529         }
       
  1530              
       
  1531       }
       
  1532       
       
  1533     }
       
  1534     
       
  1535     return false;
       
  1536   }
       
  1537   
       
  1538 }
       
  1539 
       
  1540 /**
       
  1541  * Setup the default option types.
       
  1542  *
       
  1543  * The returned option types are filterable so you can add your own.
       
  1544  * This is not a task for a beginner as you'll need to add the function
       
  1545  * that displays the option to the user and validate the saved data.
       
  1546  *
       
  1547  * @return    array
       
  1548  *
       
  1549  * @access    public
       
  1550  * @since     2.0
       
  1551  */
       
  1552 if ( ! function_exists( 'ot_option_types_array' ) ) {
       
  1553 
       
  1554   function ot_option_types_array() {
       
  1555   
       
  1556     return apply_filters( 'ot_option_types_array', array( 
       
  1557       'background'                => 'Background',
       
  1558       'category-checkbox'         => 'Category Checkbox',
       
  1559       'category-select'           => 'Category Select',
       
  1560       'checkbox'                  => 'Checkbox',
       
  1561       'colorpicker'               => 'Colorpicker',
       
  1562       'css'                       => 'CSS',
       
  1563       'custom-post-type-checkbox' => 'Custom Post Type Checkbox',
       
  1564       'custom-post-type-select'   => 'Custom Post Type Select',
       
  1565       'list-item'                 => 'List Item',
       
  1566       'measurement'               => 'Measurement',
       
  1567       'page-checkbox'             => 'Page Checkbox',
       
  1568       'page-select'               => 'Page Select',
       
  1569       'post-checkbox'             => 'Post Checkbox',
       
  1570       'post-select'               => 'Post Select',
       
  1571       'radio'                     => 'Radio',
       
  1572       'radio-image'               => 'Radio Image',
       
  1573       'select'                    => 'Select',
       
  1574       'slider'                    => 'Slider',
       
  1575       'tag-checkbox'              => 'Tag Checkbox',
       
  1576       'tag-select'                => 'Tag Select',
       
  1577       'taxonomy-checkbox'         => 'Taxonomy Checkbox',
       
  1578       'taxonomy-select'           => 'Taxonomy Select',
       
  1579       'text'                      => 'Text',
       
  1580       'textarea'                  => 'Textarea',
       
  1581       'textarea-simple'           => 'Textarea Simple',
       
  1582       'textblock'                 => 'Textblock',
       
  1583       'textblock-titled'          => 'Textblock Titled',
       
  1584       'typography'                => 'Typography',
       
  1585       'upload'                    => 'Upload'
       
  1586     ) );
       
  1587     
       
  1588   }
       
  1589 }
       
  1590 
       
  1591 /**
       
  1592  * Map old option types for rebuilding XML and Table data.
       
  1593  *
       
  1594  * @param     string      $type The old option type
       
  1595  * @return    string      The new option type
       
  1596  *
       
  1597  * @access    public
       
  1598  * @since     2.0
       
  1599  */
       
  1600 if ( ! function_exists( 'ot_map_old_option_types' ) ) {
       
  1601 
       
  1602   function ot_map_old_option_types( $type = '' ) {
       
  1603     
       
  1604     if ( ! $type ) 
       
  1605       return 'text';
       
  1606       
       
  1607     $types = array(
       
  1608       'background'	      => 'background',
       
  1609       'category'          => 'category-select',
       
  1610       'categories'        => 'category-checkbox',
       
  1611       'checkbox'          => 'checkbox',
       
  1612       'colorpicker'       => 'colorpicker',
       
  1613       'css'	              => 'css',
       
  1614       'custom_post'       => 'custom-post-type-select',
       
  1615       'custom_posts'      => 'custom-post-type-checkbox',                     
       
  1616       'input'             => 'text',
       
  1617       'image'             => 'upload',
       
  1618       'measurement'       => 'measurement',
       
  1619       'page'              => 'page-select',
       
  1620       'pages'             => 'page-checkbox',
       
  1621       'post'              => 'post-select',
       
  1622       'posts'             => 'post-checkbox',
       
  1623       'radio'             => 'radio',
       
  1624       'select'            => 'select',
       
  1625       'slider'            => 'slider',
       
  1626       'tag'               => 'tag-select',
       
  1627       'tags'              => 'tag-checkbox',
       
  1628       'textarea'          => 'textarea',
       
  1629       'textblock'         => 'textblock',
       
  1630       'typography'	      => 'typography',
       
  1631       'upload'            => 'upload'
       
  1632     );
       
  1633     
       
  1634     if ( isset( $types[$type] ) )
       
  1635       return $types[$type];
       
  1636     
       
  1637     return false;
       
  1638     
       
  1639   }
       
  1640 }
       
  1641 
       
  1642 /**
       
  1643  * Recognized font families
       
  1644  *
       
  1645  * Returns an array of all recognized font families.
       
  1646  * Keys are intended to be stored in the database
       
  1647  * while values are ready for display in html.
       
  1648  * Renamed in version 2.0 to avoid name collisions.
       
  1649  *
       
  1650  * @uses      apply_filters()
       
  1651  *
       
  1652  * @return    array
       
  1653  *
       
  1654  * @access    public
       
  1655  * @since     1.1.8
       
  1656  * @updated   2.0
       
  1657  */
       
  1658 if ( ! function_exists( 'ot_recognized_font_families' ) ) {
       
  1659 
       
  1660   function ot_recognized_font_families( $field_id = '' ) {
       
  1661   
       
  1662     return apply_filters( 'ot_recognized_font_families', array(
       
  1663       'arial'     => 'Arial',
       
  1664       'georgia'   => 'Georgia',
       
  1665       'helvetica' => 'Helvetica',
       
  1666       'palatino'  => 'Palatino',
       
  1667       'tahoma'    => 'Tahoma',
       
  1668       'times'     => '"Times New Roman", sans-serif',
       
  1669       'trebuchet' => 'Trebuchet',
       
  1670       'verdana'   => 'Verdana'
       
  1671     ), $field_id );
       
  1672     
       
  1673   }
       
  1674 
       
  1675 }
       
  1676 
       
  1677 /**
       
  1678  * Recognized font sizes
       
  1679  *
       
  1680  * Returns an array of all recognized font sizes.
       
  1681  *
       
  1682  * @uses      apply_filters()
       
  1683  *
       
  1684  * @param     string  $field_id ID that's passed to the filters.
       
  1685  * @return    array
       
  1686  *
       
  1687  * @access    public
       
  1688  * @since     2.0.12
       
  1689  */
       
  1690 if ( ! function_exists( 'ot_recognized_font_sizes' ) ) {
       
  1691 
       
  1692   function ot_recognized_font_sizes( $field_id ) {
       
  1693   
       
  1694     $range = ot_range( 
       
  1695       apply_filters( 'ot_font_size_low_range', 0, $field_id ), 
       
  1696       apply_filters( 'ot_font_size_high_range', 150, $field_id ), 
       
  1697       apply_filters( 'ot_font_size_range_interval', 1, $field_id )
       
  1698     );
       
  1699     
       
  1700     $unit = apply_filters( 'ot_font_size_unit_type', 'px', $field_id );
       
  1701     
       
  1702     foreach( $range as $k => $v ) {
       
  1703       $range[$k] = $v . $unit;
       
  1704     }
       
  1705     
       
  1706     return $range;
       
  1707   }
       
  1708 
       
  1709 }
       
  1710 
       
  1711 /**
       
  1712  * Recognized font styles
       
  1713  *
       
  1714  * Returns an array of all recognized font styles.
       
  1715  * Renamed in version 2.0 to avoid name collisions.
       
  1716  *
       
  1717  * @uses      apply_filters()
       
  1718  *
       
  1719  * @return    array
       
  1720  *
       
  1721  * @access    public
       
  1722  * @since     1.1.8
       
  1723  * @updated   2.0
       
  1724  */
       
  1725 if ( ! function_exists( 'ot_recognized_font_styles' ) ) {
       
  1726 
       
  1727   function ot_recognized_font_styles( $field_id = '' ) {
       
  1728   
       
  1729     return apply_filters( 'ot_recognized_font_styles', array(
       
  1730       'normal'  => 'Normal',
       
  1731       'italic'  => 'Italic',
       
  1732       'oblique' => 'Oblique',
       
  1733       'inherit' => 'Inherit'
       
  1734     ), $field_id );
       
  1735     
       
  1736   }
       
  1737 
       
  1738 }
       
  1739 
       
  1740 /**
       
  1741  * Recognized font variants
       
  1742  *
       
  1743  * Returns an array of all recognized font variants.
       
  1744  * Renamed in version 2.0 to avoid name collisions.
       
  1745  *
       
  1746  * @uses      apply_filters()
       
  1747  *
       
  1748  * @return    array
       
  1749  *
       
  1750  * @access    public
       
  1751  * @since     1.1.8
       
  1752  * @updated   2.0
       
  1753  */
       
  1754 if ( ! function_exists( 'ot_recognized_font_variants' ) ) {
       
  1755 
       
  1756   function ot_recognized_font_variants( $field_id = '' ) {
       
  1757   
       
  1758     return apply_filters( 'ot_recognized_font_variants', array(
       
  1759       'normal'      => 'Normal',
       
  1760       'small-caps'  => 'Small Caps',
       
  1761       'inherit'     => 'Inherit'
       
  1762     ), $field_id );
       
  1763   
       
  1764   }
       
  1765   
       
  1766 }
       
  1767 
       
  1768 /**
       
  1769  * Recognized font weights
       
  1770  *
       
  1771  * Returns an array of all recognized font weights.
       
  1772  * Renamed in version 2.0 to avoid name collisions.
       
  1773  *
       
  1774  * @uses      apply_filters()
       
  1775  *
       
  1776  * @return    array
       
  1777  *
       
  1778  * @access    public
       
  1779  * @since     1.1.8
       
  1780  * @updated   2.0
       
  1781  */
       
  1782 if ( ! function_exists( 'ot_recognized_font_weights' ) ) {
       
  1783 
       
  1784   function ot_recognized_font_weights( $field_id = '' ) {
       
  1785     
       
  1786     return apply_filters( 'ot_recognized_font_weights', array(
       
  1787       'normal'    => 'Normal',
       
  1788       'bold'      => 'Bold',
       
  1789       'bolder'    => 'Bolder',
       
  1790       'lighter'   => 'Lighter',
       
  1791       '100'       => '100',
       
  1792       '200'       => '200',
       
  1793       '300'       => '300',
       
  1794       '400'       => '400',
       
  1795       '500'       => '500',
       
  1796       '600'       => '600',
       
  1797       '700'       => '700',
       
  1798       '800'       => '800',
       
  1799       '900'       => '900',
       
  1800       'inherit'   => 'Inherit'
       
  1801     ), $field_id );
       
  1802   
       
  1803   }
       
  1804   
       
  1805 }
       
  1806 
       
  1807 /**
       
  1808  * Recognized letter spacing
       
  1809  *
       
  1810  * Returns an array of all recognized line heights.
       
  1811  *
       
  1812  * @uses      apply_filters()
       
  1813  *
       
  1814  * @param     string  $field_id ID that's passed to the filters.
       
  1815  * @return    array
       
  1816  *
       
  1817  * @access    public
       
  1818  * @since     2.0.12
       
  1819  */
       
  1820 if ( ! function_exists( 'ot_recognized_letter_spacing' ) ) {
       
  1821 
       
  1822   function ot_recognized_letter_spacing( $field_id ) {
       
  1823   
       
  1824     $range = ot_range( 
       
  1825       apply_filters( 'ot_letter_spacing_low_range', -0.1, $field_id ), 
       
  1826       apply_filters( 'ot_letter_spacing_high_range', 0.1, $field_id ), 
       
  1827       apply_filters( 'ot_letter_spacing_range_interval', 0.01, $field_id )
       
  1828     );
       
  1829     
       
  1830     $unit = apply_filters( 'ot_letter_spacing_unit_type', 'em', $field_id );
       
  1831     
       
  1832     foreach( $range as $k => $v ) {
       
  1833       $range[$k] = $v . $unit;
       
  1834     }
       
  1835     
       
  1836     return $range;
       
  1837   }
       
  1838 
       
  1839 }
       
  1840 
       
  1841 /**
       
  1842  * Recognized line heights
       
  1843  *
       
  1844  * Returns an array of all recognized line heights.
       
  1845  *
       
  1846  * @uses      apply_filters()
       
  1847  *
       
  1848  * @param     string  $field_id ID that's passed to the filters.
       
  1849  * @return    array
       
  1850  *
       
  1851  * @access    public
       
  1852  * @since     2.0.12
       
  1853  */
       
  1854 if ( ! function_exists( 'ot_recognized_line_heights' ) ) {
       
  1855 
       
  1856   function ot_recognized_line_heights( $field_id ) {
       
  1857   
       
  1858     $range = ot_range( 
       
  1859       apply_filters( 'ot_line_height_low_range', 0, $field_id ), 
       
  1860       apply_filters( 'ot_line_height_high_range', 150, $field_id ), 
       
  1861       apply_filters( 'ot_line_height_unit_type', 1, $field_id )
       
  1862     );
       
  1863     
       
  1864     $unit = apply_filters( 'ot_line_height_unit_type', 'px', $field_id );
       
  1865     
       
  1866     foreach( $range as $k => $v ) {
       
  1867       $range[$k] = $v . $unit;
       
  1868     }
       
  1869     
       
  1870     return $range;
       
  1871   }
       
  1872 
       
  1873 }
       
  1874 
       
  1875 /**
       
  1876  * Recognized text decorations
       
  1877  *
       
  1878  * Returns an array of all recognized text decorations.
       
  1879  * Keys are intended to be stored in the database
       
  1880  * while values are ready for display in html.
       
  1881  *
       
  1882  * @uses      apply_filters()
       
  1883  *
       
  1884  * @return    array
       
  1885  *
       
  1886  * @access    public
       
  1887  * @since     2.0.10
       
  1888  */
       
  1889 if ( ! function_exists( 'ot_recognized_text_decorations' ) ) {
       
  1890   
       
  1891   function ot_recognized_text_decorations( $field_id = '' ) {
       
  1892   
       
  1893     return apply_filters( 'ot_recognized_text_decorations', array(
       
  1894       'blink'         => 'Blink',
       
  1895       'inherit'       => 'Inherit',
       
  1896       'line-through'  => 'Line Through',
       
  1897       'none'          => 'None',
       
  1898       'overline'      => 'Overline',
       
  1899       'underline'     => 'Underline'
       
  1900     ), $field_id );
       
  1901     
       
  1902   }
       
  1903 
       
  1904 }
       
  1905 
       
  1906 /**
       
  1907  * Recognized text transformations
       
  1908  *
       
  1909  * Returns an array of all recognized text transformations.
       
  1910  * Keys are intended to be stored in the database
       
  1911  * while values are ready for display in html.
       
  1912  *
       
  1913  * @uses      apply_filters()
       
  1914  *
       
  1915  * @return    array
       
  1916  *
       
  1917  * @access    public
       
  1918  * @since     2.0.10
       
  1919  */
       
  1920 if ( ! function_exists( 'ot_recognized_text_transformations' ) ) {
       
  1921   
       
  1922   function ot_recognized_text_transformations( $field_id = '' ) {
       
  1923   
       
  1924     return apply_filters( 'ot_recognized_text_transformations', array(
       
  1925       'capitalize'  => 'Capitalize',
       
  1926       'inherit'     => 'Inherit',
       
  1927       'lowercase'   => 'Lowercase',
       
  1928       'none'        => 'None',
       
  1929       'uppercase'   => 'Uppercase'
       
  1930     ), $field_id );
       
  1931     
       
  1932   }
       
  1933 
       
  1934 }
       
  1935 
       
  1936 /**
       
  1937  * Recognized background repeat
       
  1938  *
       
  1939  * Returns an array of all recognized background repeat values.
       
  1940  * Renamed in version 2.0 to avoid name collisions.
       
  1941  *
       
  1942  * @uses      apply_filters()
       
  1943  *
       
  1944  * @return    array
       
  1945  *
       
  1946  * @access    public
       
  1947  * @since     1.1.8
       
  1948  * @updated   2.0
       
  1949  */
       
  1950 if ( ! function_exists( 'ot_recognized_background_repeat' ) ) {
       
  1951   
       
  1952   function ot_recognized_background_repeat( $field_id = '' ) {
       
  1953   
       
  1954     return apply_filters( 'ot_recognized_background_repeat', array(
       
  1955       'no-repeat' => 'No Repeat',
       
  1956       'repeat' 		=> 'Repeat All',
       
  1957       'repeat-x'  => 'Repeat Horizontally',
       
  1958       'repeat-y' 	=> 'Repeat Vertically',
       
  1959       'inherit'   => 'Inherit'
       
  1960     ), $field_id );
       
  1961     
       
  1962   }
       
  1963   
       
  1964 }
       
  1965 
       
  1966 /**
       
  1967  * Recognized background attachment
       
  1968  *
       
  1969  * Returns an array of all recognized background attachment values.
       
  1970  * Renamed in version 2.0 to avoid name collisions.
       
  1971  *
       
  1972  * @uses      apply_filters()
       
  1973  *
       
  1974  * @return    array
       
  1975  *
       
  1976  * @access    public
       
  1977  * @since     1.1.8
       
  1978  * @updated   2.0
       
  1979  */
       
  1980 if ( ! function_exists( 'ot_recognized_background_attachment' ) ) {
       
  1981 
       
  1982   function ot_recognized_background_attachment( $field_id = '' ) {
       
  1983   
       
  1984     return apply_filters( 'ot_recognized_background_attachment', array(
       
  1985       "fixed"   => "Fixed",
       
  1986       "scroll"  => "Scroll",
       
  1987       "inherit" => "Inherit"
       
  1988     ), $field_id );
       
  1989     
       
  1990   }
       
  1991 
       
  1992 }
       
  1993 
       
  1994 /**
       
  1995  * Recognized background position
       
  1996  *
       
  1997  * Returns an array of all recognized background position values.
       
  1998  * Renamed in version 2.0 to avoid name collisions.
       
  1999  *
       
  2000  * @uses      apply_filters()
       
  2001  *
       
  2002  * @return    array
       
  2003  *
       
  2004  * @access    public
       
  2005  * @since     1.1.8
       
  2006  * @updated   2.0
       
  2007  */
       
  2008 if ( ! function_exists( 'ot_recognized_background_position' ) ) {
       
  2009 
       
  2010   function ot_recognized_background_position( $field_id = '' ) {
       
  2011   
       
  2012     return apply_filters( 'ot_recognized_background_position', array(
       
  2013       "left top"      => "Left Top",
       
  2014       "left center"   => "Left Center",
       
  2015       "left bottom"   => "Left Bottom",
       
  2016       "center top"    => "Center Top",
       
  2017       "center center" => "Center Center",
       
  2018       "center bottom" => "Center Bottom",
       
  2019       "right top"     => "Right Top",
       
  2020       "right center"  => "Right Center",
       
  2021       "right bottom"  => "Right Bottom"
       
  2022     ), $field_id );
       
  2023     
       
  2024   }
       
  2025 
       
  2026 }
       
  2027 
       
  2028 /**
       
  2029  * Measurement Units
       
  2030  *
       
  2031  * Returns an array of all available unit types.
       
  2032  * Renamed in version 2.0 to avoid name collisions.
       
  2033  *
       
  2034  * @uses      apply_filters()
       
  2035  *
       
  2036  * @return    array
       
  2037  *
       
  2038  * @access    public
       
  2039  * @since     1.1.8
       
  2040  * @updated   2.0
       
  2041  */
       
  2042 if ( ! function_exists( 'ot_measurement_unit_types' ) ) {
       
  2043   
       
  2044   function ot_measurement_unit_types( $field_id = '' ) {
       
  2045   
       
  2046     return apply_filters( 'ot_measurement_unit_types', array(
       
  2047       'px' => 'px',
       
  2048       '%'  => '%',
       
  2049       'em' => 'em',
       
  2050       'pt' => 'pt'
       
  2051     ), $field_id );
       
  2052     
       
  2053   }
       
  2054 
       
  2055 }
       
  2056 
       
  2057 /**
       
  2058  * Radio Images default array.
       
  2059  *
       
  2060  * Returns an array of all available radio images.
       
  2061  * You can filter this function to change the images
       
  2062  * on a per option basis.
       
  2063  *
       
  2064  * @uses      apply_filters()
       
  2065  *
       
  2066  * @return    array
       
  2067  *
       
  2068  * @access    public
       
  2069  * @since     2.0
       
  2070  */
       
  2071 if ( ! function_exists( 'ot_radio_images' ) ) {
       
  2072   
       
  2073   function ot_radio_images( $field_id = '' ) {
       
  2074   
       
  2075     return apply_filters( 'ot_radio_images', array(
       
  2076       array(
       
  2077         'value'   => 'left-sidebar',
       
  2078         'label'   => __( 'Left Sidebar', 'option-tree' ),
       
  2079         'src'     => OT_URL . 'assets/images/layout/left-sidebar.png'
       
  2080       ),
       
  2081       array(
       
  2082         'value'   => 'right-sidebar',
       
  2083         'label'   => __( 'Right Sidebar', 'option-tree' ),
       
  2084         'src'     => OT_URL . 'assets/images/layout/right-sidebar.png'
       
  2085       ),
       
  2086       array(
       
  2087         'value'   => 'full-width',
       
  2088         'label'   => __( 'Full Width (no sidebar)', 'option-tree' ),
       
  2089         'src'     => OT_URL . 'assets/images/layout/full-width.png'
       
  2090       ),
       
  2091       array(
       
  2092         'value'   => 'dual-sidebar',
       
  2093         'label'   => __( 'Dual Sidebar', 'option-tree' ),
       
  2094         'src'     => OT_URL . 'assets/images/layout/dual-sidebar.png'
       
  2095       ),
       
  2096       array(
       
  2097         'value'   => 'left-dual-sidebar',
       
  2098         'label'   => __( 'Left Dual Sidebar', 'option-tree' ),
       
  2099         'src'     => OT_URL . 'assets/images/layout/left-dual-sidebar.png'
       
  2100       ),
       
  2101       array(
       
  2102         'value'   => 'right-dual-sidebar',
       
  2103         'label'   => __( 'Right Dual Sidebar', 'option-tree' ),
       
  2104         'src'     => OT_URL . 'assets/images/layout/right-dual-sidebar.png'
       
  2105       )
       
  2106     ), $field_id );
       
  2107     
       
  2108   }
       
  2109 
       
  2110 }
       
  2111 
       
  2112 /**
       
  2113  * Default List Item Settings array.
       
  2114  *
       
  2115  * Returns an array of the default list item settings.
       
  2116  * You can filter this function to change the settings
       
  2117  * on a per option basis.
       
  2118  *
       
  2119  * @uses      apply_filters()
       
  2120  *
       
  2121  * @return    array
       
  2122  *
       
  2123  * @access    public
       
  2124  * @since     2.0
       
  2125  */
       
  2126 if ( ! function_exists( 'ot_list_item_settings' ) ) {
       
  2127 
       
  2128   function ot_list_item_settings( $id ) {
       
  2129     
       
  2130     $settings = apply_filters( 'ot_list_item_settings', array(
       
  2131       array(
       
  2132         'id'        => 'image',
       
  2133         'label'     => __( 'Image', 'option-tree' ),
       
  2134         'desc'      => '',
       
  2135         'std'       => '',
       
  2136         'type'      => 'upload',
       
  2137         'rows'      => '',
       
  2138         'class'     => '',
       
  2139         'post_type' => '',
       
  2140         'choices'   => array()
       
  2141       ),
       
  2142       array(
       
  2143         'id'        => 'link',
       
  2144         'label'     => __( 'Link', 'option-tree' ),
       
  2145         'desc'      => '',
       
  2146         'std'       => '',
       
  2147         'type'      => 'text',
       
  2148         'rows'      => '',
       
  2149         'class'     => '',
       
  2150         'post_type' => '',
       
  2151         'choices'   => array()
       
  2152       ),
       
  2153       array(
       
  2154         'id'        => 'description',
       
  2155         'label'     => __( 'Description', 'option-tree' ),
       
  2156         'desc'      => '',
       
  2157         'std'       => '',
       
  2158         'type'      => 'textarea-simple',
       
  2159         'rows'      => 10,
       
  2160         'class'     => '',
       
  2161         'post_type' => '',
       
  2162         'choices'   => array()
       
  2163       )
       
  2164     ), $id );
       
  2165     
       
  2166     return $settings;
       
  2167   
       
  2168   }
       
  2169 
       
  2170 }
       
  2171 
       
  2172 /**
       
  2173  * Default Slider Settings array.
       
  2174  *
       
  2175  * Returns an array of the default slider settings.
       
  2176  * You can filter this function to change the settings
       
  2177  * on a per option basis.
       
  2178  *
       
  2179  * @uses      apply_filters()
       
  2180  *
       
  2181  * @return    array
       
  2182  *
       
  2183  * @access    public
       
  2184  * @since     2.0
       
  2185  */
       
  2186 if ( ! function_exists( 'ot_slider_settings' ) ) {
       
  2187 
       
  2188   function ot_slider_settings( $id ) {
       
  2189     
       
  2190     $settings = apply_filters( 'image_slider_fields', array(
       
  2191       array(
       
  2192         'name'      => 'image',
       
  2193         'type'      => 'image',
       
  2194         'label'     => __( 'Image', 'option-tree' ),
       
  2195         'class'     => ''
       
  2196       ),
       
  2197       array(
       
  2198         'name'      => 'link',
       
  2199         'type'      => 'text',
       
  2200         'label'     => __( 'Link', 'option-tree' ),
       
  2201         'class'     => ''
       
  2202       ),
       
  2203       array(
       
  2204         'name'      => 'description',
       
  2205         'type'      => 'textarea',
       
  2206         'label'     => __( 'Description', 'option-tree' ),
       
  2207         'class'     => ''
       
  2208       )
       
  2209     ), $id );
       
  2210     
       
  2211     /* fix the array keys, values, and just get it 2.0 ready */
       
  2212     foreach( $settings as $_k => $setting ) {
       
  2213     
       
  2214       foreach( $setting as $s_key => $s_value ) {
       
  2215         
       
  2216         if ( 'name' == $s_key ) {
       
  2217         
       
  2218           $settings[$_k]['id'] = $s_value;
       
  2219           unset($settings[$_k]['name']);
       
  2220           
       
  2221         } else if ( 'type' == $s_key ) {
       
  2222           
       
  2223           if ( 'input' == $s_value ) {
       
  2224           
       
  2225             $settings[$_k]['type'] = 'text';
       
  2226             
       
  2227           } else if ( 'textarea' == $s_value ) {
       
  2228           
       
  2229             $settings[$_k]['type'] = 'textarea-simple';
       
  2230             
       
  2231           } else if ( 'image' == $s_value ) {
       
  2232           
       
  2233             $settings[$_k]['type'] = 'upload';
       
  2234             
       
  2235           }
       
  2236           
       
  2237         }
       
  2238         
       
  2239       } 
       
  2240       
       
  2241     }
       
  2242     
       
  2243     return $settings;
       
  2244     
       
  2245   }
       
  2246 
       
  2247 }
       
  2248 
       
  2249 /**
       
  2250  * Inserts CSS with field_id markers.
       
  2251  *
       
  2252  * Inserts CSS into a dynamic.css file, placing it between
       
  2253  * BEGIN and END field_id markers. Replaces existing marked info, 
       
  2254  * but still retains surrounding data.
       
  2255  *
       
  2256  * @param     string  $field_id The CSS option field ID.
       
  2257  * @param     array   $options The current option_tree array.
       
  2258  * @return    bool    True on write success, false on failure.
       
  2259  *
       
  2260  * @access    public
       
  2261  * @since     1.1.8
       
  2262  * @updated   2.0.12
       
  2263  */
       
  2264 if ( ! function_exists( 'ot_insert_css_with_markers' ) ) {
       
  2265 
       
  2266   function ot_insert_css_with_markers( $field_id = '', $insertion = '', $meta = false ) {
       
  2267     
       
  2268     /* missing $field_id or $insertion exit early */
       
  2269     if ( '' == $field_id || '' == $insertion )
       
  2270       return;
       
  2271 
       
  2272     /* path to the dynamic.css file */
       
  2273     $filepath = get_stylesheet_directory() . '/dynamic.css';
       
  2274     
       
  2275     /* allow filter on path */
       
  2276     $filepath = apply_filters( 'css_option_file_path', $filepath, $field_id );
       
  2277     
       
  2278     /* grab a copy of the paths array */
       
  2279     $ot_css_file_paths = get_option( 'ot_css_file_paths', array() );
       
  2280     
       
  2281     /* set the path for this field */
       
  2282     $ot_css_file_paths[$field_id] = $filepath;
       
  2283     
       
  2284     /* update the paths */
       
  2285     update_option( 'ot_css_file_paths', $ot_css_file_paths );
       
  2286     
       
  2287     /* insert CSS into file */
       
  2288     if ( file_exists( $filepath ) ) {
       
  2289       
       
  2290       $insertion   = ot_normalize_css( $insertion );
       
  2291       $regex       = "/{{([a-zA-Z0-9\_\-\#\|\=]+)}}/";
       
  2292       $marker      = $field_id;
       
  2293       
       
  2294       /* Match custom CSS */
       
  2295       preg_match_all( $regex, $insertion, $matches );
       
  2296       
       
  2297       /* Loop through CSS */
       
  2298       foreach( $matches[0] as $option ) {
       
  2299         
       
  2300         $value        = '';
       
  2301         $option_id    = str_replace( array( '{{', '}}' ), '', $option );
       
  2302         $option_array = explode( '|', $option_id );
       
  2303         
       
  2304         /* get the array value */
       
  2305         if ( $meta ) {
       
  2306           global $post;
       
  2307           
       
  2308           $value = get_post_meta( $post->ID, $option_array[0], true );
       
  2309           
       
  2310         } else {
       
  2311         
       
  2312           $options = get_option( 'option_tree' );
       
  2313           
       
  2314           if ( isset( $options[$option_array[0]] ) ) {
       
  2315             
       
  2316             $value = $options[$option_array[0]];
       
  2317   
       
  2318           }
       
  2319           
       
  2320         }
       
  2321         
       
  2322         if ( is_array( $value ) ) {
       
  2323           
       
  2324           if ( ! isset( $option_array[1] ) ) {
       
  2325           
       
  2326             /* Measurement */
       
  2327             if ( isset( $value[0] ) && isset( $value[1] ) ) {
       
  2328               
       
  2329               /* set $value with measurement properties */
       
  2330               $value = $value[0].$value[1];
       
  2331               
       
  2332             /* typography */
       
  2333             } else if ( ot_array_keys_exists( $value, array( 'font-color', 'font-family', 'font-size', 'font-style', 'font-variant', 'font-weight', 'letter-spacing', 'line-height', 'text-decoration', 'text-transform' ) ) ) {
       
  2334               $font = array();
       
  2335               
       
  2336               if ( ! empty( $value['font-color'] ) )
       
  2337                 $font[] = "color: " . $value['font-color'] . ";";
       
  2338               
       
  2339               if ( ! empty( $value['font-family'] ) ) {
       
  2340                 foreach ( ot_recognized_font_families( $marker ) as $key => $v ) {
       
  2341                   if ( $key == $value['font-family'] ) {
       
  2342                     $font[] = "font-family: " . $v . ";";
       
  2343                   }
       
  2344                 }
       
  2345               }
       
  2346               
       
  2347               if ( ! empty( $value['font-size'] ) )
       
  2348                 $font[] = "font-size: " . $value['font-size'] . ";";
       
  2349               
       
  2350               if ( ! empty( $value['font-style'] ) )
       
  2351                 $font[] = "font-style: " . $value['font-style'] . ";";
       
  2352               
       
  2353               if ( ! empty( $value['font-variant'] ) )
       
  2354                 $font[] = "font-variant: " . $value['font-variant'] . ";";
       
  2355               
       
  2356               if ( ! empty( $value['font-weight'] ) )
       
  2357                 $font[] = "font-weight: " . $value['font-weight'] . ";";
       
  2358                 
       
  2359               if ( ! empty( $value['letter-spacing'] ) )
       
  2360                 $font[] = "letter-spacing: " . $value['letter-spacing'] . ";";
       
  2361               
       
  2362               if ( ! empty( $value['line-height'] ) )
       
  2363                 $font[] = "line-height: " . $value['line-height'] . ";";
       
  2364               
       
  2365               if ( ! empty( $value['text-decoration'] ) )
       
  2366                 $font[] = "text-decoration: " . $value['text-decoration'] . ";";
       
  2367               
       
  2368               if ( ! empty( $value['text-transform'] ) )
       
  2369                 $font[] = "text-transform: " . $value['text-transform'] . ";";
       
  2370               
       
  2371               /* set $value with font properties or empty string */
       
  2372               $value = ! empty( $font ) ? implode( "\n", $font ) : '';
       
  2373               
       
  2374             /* background */
       
  2375             } else if ( ot_array_keys_exists( $value, array( 'background-color', 'background-image', 'background-repeat', 'background-attachment', 'background-position' ) ) ) {
       
  2376               $bg = array();
       
  2377               
       
  2378               if ( ! empty( $value['background-color'] ) )
       
  2379                 $bg[] = $value['background-color'];
       
  2380                 
       
  2381               if ( ! empty( $value['background-image'] ) )
       
  2382                 $bg[] = 'url("' . $value['background-image'] . '")';
       
  2383                 
       
  2384               if ( ! empty( $value['background-repeat'] ) )
       
  2385                 $bg[] = $value['background-repeat'];
       
  2386                 
       
  2387               if ( ! empty( $value['background-attachment'] ) )
       
  2388                 $bg[] = $value['background-attachment'];
       
  2389                 
       
  2390               if ( ! empty( $value['background-position'] ) )
       
  2391                 $bg[] = $value['background-position'];
       
  2392               
       
  2393               /* set $value with background properties or empty string */
       
  2394               $value = ! empty( $bg ) ? 'background: ' . implode( " ", $bg ) . ';' : '';
       
  2395             }
       
  2396           
       
  2397           } else {
       
  2398           
       
  2399             $value = $value[$option_array[1]];
       
  2400             
       
  2401           }
       
  2402          
       
  2403         }
       
  2404         
       
  2405         /* insert CSS, even if the value is empty */
       
  2406        	$insertion = stripslashes( str_replace( $option, $value, $insertion ) );
       
  2407        	
       
  2408       }
       
  2409   	
       
  2410       /* create array from the lines of code */
       
  2411       $markerdata = explode( "\n", implode( '', file( $filepath ) ) );
       
  2412       
       
  2413       /* can't write to the file return false */
       
  2414       if ( ! $f = @fopen( $filepath, 'w' ) )
       
  2415         return false;
       
  2416       
       
  2417       $searching = true;
       
  2418       $foundit = false;
       
  2419       
       
  2420       /* has array of lines */
       
  2421       if ( ! empty( $markerdata ) ) {
       
  2422         
       
  2423         /* foreach line of code */
       
  2424         foreach( $markerdata as $n => $markerline ) {
       
  2425           
       
  2426           /* found begining of marker, set $searching to false  */
       
  2427           if ( $markerline == "/* BEGIN {$marker} */" )
       
  2428             $searching = false;
       
  2429           
       
  2430           /* keep rewrite each line of CSS  */
       
  2431           if ( $searching == true ) {
       
  2432             if ( $n + 1 < count( $markerdata ) )
       
  2433               fwrite( $f, "{$markerline}\n" );
       
  2434             else
       
  2435               fwrite( $f, "{$markerline}" );
       
  2436           }
       
  2437           
       
  2438           /* found end marker write code */
       
  2439           if ( $markerline == "/* END {$marker} */" ) {
       
  2440             fwrite( $f, "/* BEGIN {$marker} */\n" );
       
  2441             fwrite( $f, "{$insertion}\n" );
       
  2442             fwrite( $f, "/* END {$marker} */\n" );
       
  2443             $searching = true;
       
  2444             $foundit = true;
       
  2445           }
       
  2446           
       
  2447         }
       
  2448         
       
  2449       }
       
  2450       
       
  2451       /* nothing inserted, write code. DO IT, DO IT! */
       
  2452       if ( ! $foundit ) {
       
  2453         fwrite( $f, "/* BEGIN {$marker} */\n" );
       
  2454         fwrite( $f, "{$insertion}\n" );
       
  2455         fwrite( $f, "/* END {$marker} */\n" );
       
  2456       }
       
  2457       
       
  2458       /* close file */
       
  2459       fclose( $f );
       
  2460       return true;
       
  2461     }
       
  2462     
       
  2463     return false;
       
  2464 
       
  2465   }
       
  2466 
       
  2467 }
       
  2468 
       
  2469 /**
       
  2470  * Remove old CSS.
       
  2471  *
       
  2472  * Removes CSS when the textarea is empty, but still retains surrounding styles.
       
  2473  *
       
  2474  * @param     string  $field_id The CSS option field ID.
       
  2475  * @return    bool    True on write success, false on failure.
       
  2476  *
       
  2477  * @access    public
       
  2478  * @since     2.0
       
  2479  */
       
  2480 if ( ! function_exists( 'ot_remove_old_css' ) ) {
       
  2481 
       
  2482   function ot_remove_old_css( $field_id = '' ) {
       
  2483     
       
  2484     /* missing $field_id string */
       
  2485     if ( '' == $field_id )
       
  2486       return false;
       
  2487     
       
  2488     /* path to the dynamic.css file */
       
  2489     $filepath = get_stylesheet_directory() . '/dynamic.css';
       
  2490     
       
  2491     /* allow filter on path */
       
  2492     $filepath = apply_filters( 'css_option_file_path', $filepath, $field_id );
       
  2493     
       
  2494     /* remove CSS from file */
       
  2495     if ( is_writeable( $filepath ) ) {
       
  2496       
       
  2497       /* get each line in the file */
       
  2498       $markerdata = explode( "\n", implode( '', file( $filepath ) ) );
       
  2499       
       
  2500       /* can't write to the file return false */
       
  2501       if ( ! $f = @fopen( $filepath, 'w' ) )
       
  2502         return false;
       
  2503       
       
  2504       $searching = true;
       
  2505       
       
  2506       /* has array of lines */
       
  2507       if ( ! empty( $markerdata ) ) {
       
  2508         
       
  2509         /* foreach line of code */
       
  2510         foreach ( $markerdata as $n => $markerline ) {
       
  2511           
       
  2512           /* found begining of marker, set $searching to false  */
       
  2513           if ( $markerline == "/* BEGIN {$field_id} */" )
       
  2514             $searching = false;
       
  2515           
       
  2516           /* $searching is true, keep rewrite each line of CSS  */
       
  2517           if ( $searching == true ) {
       
  2518             if ( $n + 1 < count( $markerdata ) )
       
  2519               fwrite( $f, "{$markerline}\n" );
       
  2520             else
       
  2521               fwrite( $f, "{$markerline}" );
       
  2522           }
       
  2523           
       
  2524           /* found end marker delete old CSS */
       
  2525           if ( $markerline == "/* END {$field_id} */" ) {
       
  2526             fwrite( $f, "" );
       
  2527             $searching = true;
       
  2528           }
       
  2529           
       
  2530         }
       
  2531         
       
  2532       }
       
  2533       
       
  2534       /* close file */
       
  2535       fclose( $f );
       
  2536       return true;
       
  2537       
       
  2538     }
       
  2539     
       
  2540     return false;
       
  2541     
       
  2542   }
       
  2543   
       
  2544 }
       
  2545 
       
  2546 /**
       
  2547  * Normalize CSS
       
  2548  *
       
  2549  * Normalize & Convert all line-endings to UNIX format.
       
  2550  *
       
  2551  * @param     string    $css
       
  2552  * @return    string
       
  2553  *
       
  2554  * @access    public
       
  2555  * @since     1.1.8
       
  2556  * @updated   2.0
       
  2557  */
       
  2558 if ( ! function_exists( 'ot_normalize_css' ) ) {
       
  2559 
       
  2560   function ot_normalize_css( $css ) {
       
  2561     
       
  2562     /* Normalize & Convert */
       
  2563     $css = str_replace( "\r\n", "\n", $css );
       
  2564     $css = str_replace( "\r", "\n", $css );
       
  2565     
       
  2566     /* Don't allow out-of-control blank lines */
       
  2567     $css = preg_replace( "/\n{2,}/", "\n\n", $css );
       
  2568     
       
  2569     return $css;
       
  2570   }
       
  2571   
       
  2572 }
       
  2573 
       
  2574 /**
       
  2575  * Helper function to loop over the option types.
       
  2576  *
       
  2577  * @param    array    $type The current option type.
       
  2578  *
       
  2579  * @return   string
       
  2580  *
       
  2581  * @access   public
       
  2582  * @since    2.0
       
  2583  */
       
  2584 if ( ! function_exists( 'ot_loop_through_option_types' ) ) {
       
  2585 
       
  2586   function ot_loop_through_option_types( $type = '', $child = false ) {
       
  2587   
       
  2588     $content = '';
       
  2589     $types = ot_option_types_array();
       
  2590     
       
  2591     if ( $child )
       
  2592       unset($types['list-item']);
       
  2593     
       
  2594     foreach( $types as $key => $value )
       
  2595       $content.= '<option value="' . $key . '" ' . selected( $type, $key, false ) . '>'  . $value . '</option>';
       
  2596     
       
  2597     return $content;
       
  2598     
       
  2599   }
       
  2600   
       
  2601 }
       
  2602 
       
  2603 /**
       
  2604  * Helper function to loop over choices.
       
  2605  *
       
  2606  * @param    string     $name The form element name.
       
  2607  * @param    array      $choices The array of choices.
       
  2608  *
       
  2609  * @return   string
       
  2610  *
       
  2611  * @access   public
       
  2612  * @since    2.0
       
  2613  */
       
  2614 if ( ! function_exists( 'ot_loop_through_choices' ) ) {
       
  2615 
       
  2616   function ot_loop_through_choices( $name, $choices = array() ) {
       
  2617     
       
  2618     $content = '';
       
  2619     
       
  2620     foreach( $choices as $key => $choice )
       
  2621       $content.= '<li class="ui-state-default list-choice">' . ot_choices_view( $name, $key, $choice ) . '</li>';
       
  2622     
       
  2623     return $content;
       
  2624   }
       
  2625   
       
  2626 }
       
  2627 
       
  2628 /**
       
  2629  * Helper function to loop over sub settings.
       
  2630  *
       
  2631  * @param    string     $name The form element name.
       
  2632  * @param    array      $settings The array of settings.
       
  2633  *
       
  2634  * @return   string
       
  2635  *
       
  2636  * @access   public
       
  2637  * @since    2.0
       
  2638  */
       
  2639 if ( ! function_exists( 'ot_loop_through_sub_settings' ) ) {
       
  2640 
       
  2641   function ot_loop_through_sub_settings( $name, $settings = array() ) {
       
  2642     
       
  2643     $content = '';
       
  2644     
       
  2645     foreach( $settings as $key => $setting )
       
  2646       $content.= '<li class="ui-state-default list-sub-setting">' . ot_settings_view( $name, $key, $setting ) . '</li>';
       
  2647     
       
  2648     return $content;
       
  2649   }
       
  2650   
       
  2651 }
       
  2652 
       
  2653 /**
       
  2654  * Helper function to display sections.
       
  2655  *
       
  2656  * This function is used in AJAX to add a new section
       
  2657  * and when section have already been added and saved.
       
  2658  *
       
  2659  * @param    int      $key The array key for the current element.
       
  2660  * @param    array    An array of values for the current section.
       
  2661  *
       
  2662  * @return   void
       
  2663  *
       
  2664  * @access   public
       
  2665  * @since    2.0
       
  2666  */
       
  2667 if ( ! function_exists( 'ot_sections_view' ) ) {
       
  2668 
       
  2669   function ot_sections_view( $name, $key, $section = array() ) {
       
  2670   
       
  2671     return '
       
  2672     <div class="option-tree-setting is-section">
       
  2673       <div class="open">' . ( isset( $section['title'] ) ? esc_attr( $section['title'] ) : 'Section ' . ( $key + 1 ) ) . '</div>
       
  2674       <div class="button-section">
       
  2675         <a href="javascript:void(0);" class="option-tree-setting-edit option-tree-ui-button left-item" title="' . __( 'edit', 'option-tree' ) . '">
       
  2676           <span class="icon pencil">' . __( 'Edit', 'option-tree' ) . '</span>
       
  2677         </a>
       
  2678         <a href="javascript:void(0);" class="option-tree-setting-remove option-tree-ui-button right-item" title="' . __( 'Delete', 'option-tree' ) . '">
       
  2679           <span class="icon trash-can">' . __( 'Delete', 'option-tree' ) . '</span>
       
  2680         </a>
       
  2681       </div>
       
  2682       <div class="option-tree-setting-body">
       
  2683         <div class="format-settings">
       
  2684           <div class="format-setting type-text">
       
  2685             <div class="description">' . __( '<strong>Section Title</strong>: Displayed as a menu item on the Theme Options page.', 'option-tree' ) . '</div>
       
  2686             <div class="format-setting-inner">
       
  2687               <input type="text" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][title]" value="' . ( isset( $section['title'] ) ? esc_attr( $section['title'] ) : '' ) . '" class="widefat option-tree-ui-input option-tree-setting-title section-title" autocomplete="off" />
       
  2688             </div>
       
  2689           </div>
       
  2690         </div>
       
  2691         <div class="format-settings">
       
  2692           <div class="format-setting type-text">
       
  2693             <div class="description">' . __( '<strong>Section ID</strong>: A unique lower case alphanumeric string, underscores allowed.', 'option-tree' ) . '</div>
       
  2694             <div class="format-setting-inner">
       
  2695               <input type="text" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][id]" value="' . ( isset( $section['id'] ) ? esc_attr( $section['id'] ) : '' ) . '" class="widefat option-tree-ui-input section-id" autocomplete="off" />
       
  2696             </div>
       
  2697           </div>
       
  2698         </div>
       
  2699       </div>
       
  2700     </div>';
       
  2701     
       
  2702   }
       
  2703 
       
  2704 }
       
  2705 
       
  2706 /**
       
  2707  * Helper function to display settings.
       
  2708  *
       
  2709  * This function is used in AJAX to add a new setting
       
  2710  * and when settings have already been added and saved.
       
  2711  *
       
  2712  * @param    int      $key The array key for the current element.
       
  2713  * @param    array    An array of values for the current section.
       
  2714  *
       
  2715  * @return   void
       
  2716  *
       
  2717  * @access   public
       
  2718  * @since    2.0
       
  2719  */
       
  2720 if ( ! function_exists( 'ot_settings_view' ) ) {
       
  2721 
       
  2722   function ot_settings_view( $name, $key, $setting = array() ) {
       
  2723     
       
  2724     $child = ( strpos( $name, '][settings]') !== false ) ? true : false;
       
  2725 
       
  2726     return '
       
  2727     <div class="option-tree-setting">
       
  2728       <div class="open">' . ( isset( $setting['label'] ) ? esc_attr( $setting['label'] ) : 'Setting ' . ( $key + 1 ) ) . '</div>
       
  2729       <div class="button-section">
       
  2730         <a href="javascript:void(0);" class="option-tree-setting-edit option-tree-ui-button left-item" title="' . __( 'Edit', 'option-tree' ) . '">
       
  2731           <span class="icon pencil">' . __( 'Edit', 'option-tree' ) . '</span>
       
  2732         </a>
       
  2733         <a href="javascript:void(0);" class="option-tree-setting-remove option-tree-ui-button right-item" title="' . __( 'Delete', 'option-tree' ) . '">
       
  2734           <span class="icon trash-can">' . __( 'Delete', 'option-tree' ) . '</span>
       
  2735         </a>
       
  2736       </div>
       
  2737       <div class="option-tree-setting-body">
       
  2738         <div class="format-settings">
       
  2739           <div class="format-setting type-text wide-desc">
       
  2740             <div class="description">' . __( '<strong>Label</strong>: Displayed as the label of a form element on the Theme Options page.', 'option-tree' ) . '</div>
       
  2741             <div class="format-setting-inner">
       
  2742               <input type="text" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][label]" value="' . ( isset( $setting['label'] ) ? esc_attr( $setting['label'] ) : '' ) . '" class="widefat option-tree-ui-input option-tree-setting-title" autocomplete="off" />
       
  2743             </div>
       
  2744           </div>
       
  2745         </div>
       
  2746         <div class="format-settings">
       
  2747           <div class="format-setting type-text wide-desc">
       
  2748             <div class="description">' . __( '<strong>ID</strong>: A unique lower case alphanumeric string, underscores allowed.', 'option-tree' ) . '</div>
       
  2749             <div class="format-setting-inner">
       
  2750               <input type="text" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][id]" value="' . ( isset( $setting['id'] ) ? esc_attr( $setting['id'] ) : '' ) . '" class="widefat option-tree-ui-input" autocomplete="off" />
       
  2751             </div>
       
  2752           </div>
       
  2753         </div>
       
  2754         <div class="format-settings">
       
  2755           <div class="format-setting type-select wide-desc">
       
  2756             <div class="description">' . __( '<strong>Type</strong>: Choose one of the available option types from the dropdown.', 'option-tree' ) . '</div>
       
  2757             <div class="format-setting-inner">
       
  2758               <select name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][type]" value="' . ( isset( $setting['type'] ) ? esc_attr( $setting['type'] ) : '' ) . '" class="option-tree-ui-select">
       
  2759               ' . ( isset( $setting['type'] ) ? ot_loop_through_option_types( $setting['type'], $child ) : ot_loop_through_option_types( '', $child ) ) . '                     
       
  2760               
       
  2761               </select>
       
  2762             </div>
       
  2763           </div>
       
  2764         </div>
       
  2765         <div class="format-settings">
       
  2766           <div class="format-setting type-textarea wide-desc">
       
  2767             <div class="description">' . __( '<strong>Description</strong>: Enter a detailed description for the users to read on the Theme Options page, HTML is allowed. This is also where you enter content for both the Textblock & Textblock Titled option types.', 'option-tree' ) . '</div>
       
  2768             <div class="format-setting-inner">
       
  2769               <textarea class="textarea" rows="10" cols="40" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][desc]">' . ( isset( $setting['desc'] ) ? esc_html( $setting['desc'] ) : '' ) . '</textarea>
       
  2770             </div>
       
  2771           </div>
       
  2772         </div>
       
  2773         <div class="format-settings">
       
  2774           <div class="format-setting type-textblock wide-desc">
       
  2775             <div class="description">' . __( '<strong>Choices</strong>: This will only affect the following option types: Checkbox, Radio, Select & Select Image.', 'option-tree' ) . '</div>
       
  2776             <div class="format-setting-inner">
       
  2777               <ul class="option-tree-setting-wrap option-tree-sortable" data-name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . ']">
       
  2778                 ' . ( isset( $setting['choices'] ) ? ot_loop_through_choices( $name . '[' . $key . ']', $setting['choices'] ) : '' ) . '
       
  2779               </ul>
       
  2780               <a href="javascript:void(0);" class="option-tree-choice-add option-tree-ui-button hug-left">' . __( 'Add Choice', 'option-tree' ) . '</a>
       
  2781             </div>
       
  2782           </div>
       
  2783         </div>
       
  2784         <div class="format-settings">
       
  2785           <div class="format-setting type-textblock wide-desc">
       
  2786             <div class="description">' . __( '<strong>Settings</strong>: This will only affect the List Item option type.', 'option-tree' ) . '</div>
       
  2787             <div class="format-setting-inner">
       
  2788               <ul class="option-tree-setting-wrap option-tree-sortable" data-name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . ']">
       
  2789                 ' . ( isset( $setting['settings'] ) ? ot_loop_through_sub_settings( $name . '[' . $key . '][settings]', $setting['settings'] ) : '' ) . '
       
  2790               </ul>
       
  2791               <a href="javascript:void(0);" class="option-tree-list-item-setting-add option-tree-ui-button hug-left">' . __( 'Add Setting', 'option-tree' ) . '</a>
       
  2792             </div>
       
  2793           </div>
       
  2794         </div>
       
  2795         <div class="format-settings">
       
  2796           <div class="format-setting type-text wide-desc">
       
  2797             <div class="description">' . __( '<strong>Standard</strong>: Setting the standard value for your option only works for some option types. Read the <code>OptionTree->Documentation</code> for more information on which ones.', 'option-tree' ) . '</div>
       
  2798             <div class="format-setting-inner">
       
  2799               <input type="text" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][std]" value="' . ( isset( $setting['std'] ) ? esc_attr( $setting['std'] ) : '' ) . '" class="widefat option-tree-ui-input" autocomplete="off" />
       
  2800             </div>
       
  2801           </div>
       
  2802         </div>
       
  2803         <div class="format-settings">
       
  2804           <div class="format-setting type-text wide-desc">
       
  2805             <div class="description">' . __( '<strong>Rows</strong>: Enter a numeric value for the number of rows in your textarea. This will only affect the following option types: CSS, Textarea, & Textarea Simple.', 'option-tree' ) . '</div>
       
  2806             <div class="format-setting-inner">
       
  2807               <input type="text" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][rows]" value="' . ( isset( $setting['rows'] ) ? esc_attr( $setting['rows'] ) : '' ) . '" class="widefat option-tree-ui-input" />
       
  2808             </div>
       
  2809           </div>
       
  2810         </div>
       
  2811         <div class="format-settings">
       
  2812           <div class="format-setting type-text wide-desc">
       
  2813             <div class="description">' . __( '<strong>Post Type</strong>: Add a comma separated list of post type like \'post,page\'. This will only affect the following option types: Custom Post Type Checkbox, & Custom Post Type Select.', 'option-tree' ) . '</div>
       
  2814             <div class="format-setting-inner">
       
  2815               <input type="text" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][post_type]" value="' . ( isset( $setting['post_type'] ) ? esc_attr( $setting['post_type'] ) : '' ) . '" class="widefat option-tree-ui-input" autocomplete="off" />
       
  2816             </div>
       
  2817           </div>
       
  2818         </div>
       
  2819         <div class="format-settings">
       
  2820           <div class="format-setting type-text wide-desc">
       
  2821             <div class="description">' . __( '<strong>Taxonomy</strong>: Add a comma separated list of any registered taxonomy like \'category,post_tag\'. This will only affect the following option types: Taxonomy Checkbox, & Taxonomy Select.', 'option-tree' ) . '</div>
       
  2822             <div class="format-setting-inner">
       
  2823               <input type="text" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][taxonomy]" value="' . ( isset( $setting['taxonomy'] ) ? esc_attr( $setting['taxonomy'] ) : '' ) . '" class="widefat option-tree-ui-input" autocomplete="off" />
       
  2824             </div>
       
  2825           </div>
       
  2826         </div>
       
  2827         <div class="format-settings">
       
  2828           <div class="format-setting type-text wide-desc">
       
  2829             <div class="description">' . __( '<strong>CSS Class</strong>: Add and optional class to this option type.', 'option-tree' ) . '</div>
       
  2830             <div class="format-setting-inner">
       
  2831               <input type="text" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][class]" value="' . ( isset( $setting['class'] ) ? esc_attr( $setting['class'] ) : '' ) . '" class="widefat option-tree-ui-input" autocomplete="off" />
       
  2832             </div>
       
  2833           </div>
       
  2834         </div>
       
  2835       </div>
       
  2836     </div>
       
  2837     ' . ( ! $child ? '<input type="hidden" class="hidden-section" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][section]" value="' . ( isset( $setting['section'] ) ? esc_attr( $setting['section'] ) : '' ) . '" />' : '' );
       
  2838   
       
  2839   }
       
  2840 
       
  2841 }
       
  2842 
       
  2843 /**
       
  2844  * Helper function to display setting choices.
       
  2845  *
       
  2846  * This function is used in AJAX to add a new choice
       
  2847  * and when choices have already been added and saved.
       
  2848  *
       
  2849  * @param    string   $name The form element name.
       
  2850  * @param    array    $key The array key for the current element.
       
  2851  * @param    array    An array of values for the current choice.
       
  2852  *
       
  2853  * @return   void
       
  2854  *
       
  2855  * @access   public
       
  2856  * @since    2.0
       
  2857  */
       
  2858 if ( ! function_exists( 'ot_choices_view' ) ) {
       
  2859 
       
  2860   function ot_choices_view( $name, $key, $choice = array() ) {
       
  2861   
       
  2862     return '
       
  2863     <div class="option-tree-setting">
       
  2864       <div class="open">' . ( isset( $choice['label'] ) ? esc_attr( $choice['label'] ) : 'Choice ' . ( $key + 1 ) ) . '</div>
       
  2865       <div class="button-section">
       
  2866         <a href="javascript:void(0);" class="option-tree-setting-edit option-tree-ui-button left-item" title="' . __( 'Edit', 'option-tree' ) . '">
       
  2867           <span class="icon pencil">' . __( 'Edit', 'option-tree' ) . '</span>
       
  2868         </a>
       
  2869         <a href="javascript:void(0);" class="option-tree-setting-remove option-tree-ui-button right-item" title="' . __( 'Delete', 'option-tree' ) . '">
       
  2870           <span class="icon trash-can">' . __( 'Delete', 'option-tree' ) . '</span>
       
  2871         </a>
       
  2872       </div>
       
  2873       <div class="option-tree-setting-body">
       
  2874         <div class="format-settings">
       
  2875           <div class="format-setting-label">
       
  2876             <h5>' . __( 'Label', 'option-tree' ) . '</h5>
       
  2877           </div>
       
  2878           <div class="format-setting type-text wide-desc">
       
  2879             <div class="format-setting-inner">
       
  2880               <input type="text" name="' . esc_attr( $name ) . '[choices][' . esc_attr( $key ) . '][label]" value="' . ( isset( $choice['label'] ) ? esc_attr( $choice['label'] ) : '' ) . '" class="widefat option-tree-ui-input option-tree-setting-title" autocomplete="off" />
       
  2881             </div>
       
  2882           </div>
       
  2883         </div>
       
  2884         <div class="format-settings">
       
  2885           <div class="format-setting-label">
       
  2886             <h5>' . __( 'Value', 'option-tree' ) . '</h5>
       
  2887           </div>
       
  2888           <div class="format-setting type-text wide-desc">
       
  2889             <div class="format-setting-inner">
       
  2890               <input type="text" name="' . esc_attr( $name ) . '[choices][' . esc_attr( $key ) . '][value]" value="' . ( isset( $choice['value'] ) ? esc_attr( $choice['value'] ) : '' ) . '" class="widefat option-tree-ui-input" autocomplete="off" />
       
  2891             </div>
       
  2892           </div>
       
  2893         </div>
       
  2894         <div class="format-settings">
       
  2895           <div class="format-setting-label">
       
  2896             <h5>' . __( 'Image Source (Radio Image only)', 'option-tree' ) . '</h5>
       
  2897           </div>
       
  2898           <div class="format-setting type-text wide-desc">
       
  2899             <div class="format-setting-inner">
       
  2900               <input type="text" name="' . esc_attr( $name ) . '[choices][' . esc_attr( $key ) . '][src]" value="' . ( isset( $choice['src'] ) ? esc_url( $choice['src'] ) : '' ) . '" class="widefat option-tree-ui-input" autocomplete="off" />
       
  2901             </div>
       
  2902           </div>
       
  2903         </div>
       
  2904     </div>';
       
  2905     
       
  2906   }
       
  2907 
       
  2908 }
       
  2909 
       
  2910 /**
       
  2911  * Helper function to display sections.
       
  2912  *
       
  2913  * This function is used in AJAX to add a new section
       
  2914  * and when section have already been added and saved.
       
  2915  *
       
  2916  * @param    int      $key The array key for the current element.
       
  2917  * @param    array    An array of values for the current section.
       
  2918  *
       
  2919  * @return   void
       
  2920  *
       
  2921  * @access   public
       
  2922  * @since    2.0
       
  2923  */
       
  2924 if ( ! function_exists( 'ot_contextual_help_view' ) ) {
       
  2925 
       
  2926   function ot_contextual_help_view( $name, $key, $content = array() ) {
       
  2927   
       
  2928     return '
       
  2929     <div class="option-tree-setting">
       
  2930       <div class="open">' . ( isset( $content['title'] ) ? esc_attr( $content['title'] ) : 'Content ' . ( $key + 1 ) ) . '</div>
       
  2931       <div class="button-section">
       
  2932         <a href="javascript:void(0);" class="option-tree-setting-edit option-tree-ui-button left-item" title="' . __( 'Edit', 'option-tree' ) . '">
       
  2933           <span class="icon pencil">' . __( 'Edit', 'option-tree' ) . '</span>
       
  2934         </a>
       
  2935         <a href="javascript:void(0);" class="option-tree-setting-remove option-tree-ui-button right-item" title="' . __( 'Delete', 'option-tree' ) . '">
       
  2936           <span class="icon trash-can">' . __( 'Delete', 'option-tree' ) . '</span>
       
  2937         </a>
       
  2938       </div>
       
  2939       <div class="option-tree-setting-body">
       
  2940         <div class="format-settings">
       
  2941           <div class="format-setting type-text no-desc">
       
  2942             <div class="description">' . __( '<strong>Title</strong>: Displayed as a contextual help menu item on the Theme Options page.', 'option-tree' ) . '</div>
       
  2943             <div class="format-setting-inner">
       
  2944               <input type="text" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][title]" value="' . ( isset( $content['title'] ) ? esc_attr( $content['title'] ) : '' ) . '" class="widefat option-tree-ui-input option-tree-setting-title" autocomplete="off" />
       
  2945             </div>
       
  2946           </div>
       
  2947         </div>
       
  2948         <div class="format-settings">
       
  2949           <div class="format-setting type-text no-desc">
       
  2950             <div class="description">' . __( '<strong>ID</strong>: A unique lower case alphanumeric string, underscores allowed.', 'option-tree' ) . '</div>
       
  2951             <div class="format-setting-inner">
       
  2952               <input type="text" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][id]" value="' . ( isset( $content['id'] ) ? esc_attr( $content['id'] ) : '' ) . '" class="widefat option-tree-ui-input" autocomplete="off" />
       
  2953             </div>
       
  2954           </div>
       
  2955         </div>
       
  2956         <div class="format-settings">
       
  2957           <div class="format-setting type-textarea no-desc">
       
  2958             <div class="description">' . __( '<strong>Content</strong>: Enter the HTML content about this contextual help item displayed on the Theme Option page for end users to read.', 'option-tree' ) . '</div>
       
  2959             <div class="format-setting-inner">
       
  2960               <textarea class="textarea" rows="15" cols="40" name="' . esc_attr( $name ) . '[' . esc_attr( $key ) . '][content]">' . ( isset( $content['content'] ) ? esc_html( $content['content'] ) : '' ) . '</textarea>
       
  2961             </div>
       
  2962           </div>
       
  2963         </div>
       
  2964       </div>
       
  2965     </div>';
       
  2966     
       
  2967   }
       
  2968 
       
  2969 }
       
  2970 
       
  2971 /**
       
  2972  * Helper function to display sections.
       
  2973  *
       
  2974  * @param     string      $key
       
  2975  * @param     string      $data
       
  2976  * @param     string      $active_layout
       
  2977  *
       
  2978  * @return    void
       
  2979  *
       
  2980  * @access    public
       
  2981  * @since     2.0
       
  2982  */
       
  2983 if ( ! function_exists( 'ot_layouts_view' ) ) {
       
  2984 
       
  2985   function ot_layout_view( $key, $data, $active_layout ) {
       
  2986   
       
  2987     return '
       
  2988     <div class="option-tree-setting">
       
  2989       <div class="open">' . ( isset( $key ) ? esc_attr( $key ) : __( 'Layout', 'option-tree' ) ) . '</div>
       
  2990       <div class="button-section">
       
  2991         <a href="javascript:void(0);" class="option-tree-layout-activate option-tree-ui-button left-item' . ( $active_layout == $key ? ' active' : '' ) . '" title="' . __( 'Activate', 'option-tree' ) . '">
       
  2992           <span class="icon check">' . __( 'Activate', 'option-tree' ) . '</span>
       
  2993         </a>
       
  2994         <a href="javascript:void(0);" class="option-tree-setting-remove option-tree-ui-button right-item" title="'. __( 'Delete', 'option-tree' ) . '">
       
  2995           <span class="icon trash-can">' . __( 'Delete', 'option-tree' ) . '</span>
       
  2996         </a>
       
  2997       </div>
       
  2998       <input type="hidden" name="option_tree_layouts[' . esc_attr( $key ) . ']" value="' . ( isset( $data ) ? $data : '' ) . '" />
       
  2999     </div>';
       
  3000     
       
  3001   }
       
  3002 
       
  3003 }
       
  3004 
       
  3005 /**
       
  3006  * Helper function to display list items.
       
  3007  *
       
  3008  * This function is used in AJAX to add a new list items
       
  3009  * and when they have already been added and saved.
       
  3010  *
       
  3011  * @param     string    $name The form field name.
       
  3012  * @param     int       $key The array key for the current element.
       
  3013  * @param     array     An array of values for the current list item.
       
  3014  *
       
  3015  * @return   void
       
  3016  *
       
  3017  * @access   public
       
  3018  * @since    2.0
       
  3019  */
       
  3020 if ( ! function_exists( 'ot_list_item_view' ) ) {
       
  3021 
       
  3022   function ot_list_item_view( $name, $key, $list_item = array(), $post_id = 0, $get_option = '', $settings = array(), $type = '' ) {
       
  3023     
       
  3024     /* required title setting */
       
  3025     $required_setting = array(
       
  3026       array(
       
  3027         'id'        => 'title',
       
  3028         'label'     => __( 'Title', 'option-tree' ),
       
  3029         'desc'      => '',
       
  3030         'std'       => '',
       
  3031         'type'      => 'text',
       
  3032         'rows'      => '',
       
  3033         'class'     => 'option-tree-setting-title',
       
  3034         'post_type' => '',
       
  3035         'choices'   => array()
       
  3036       )
       
  3037     );
       
  3038     
       
  3039     /* load the old filterable slider settings */
       
  3040     if ( 'slider' == $type ) {
       
  3041       
       
  3042       $settings = ot_slider_settings( $name );
       
  3043     
       
  3044     }
       
  3045       
       
  3046     /* if no settings array load the filterable list item settings */
       
  3047     if ( empty( $settings ) ) {
       
  3048       
       
  3049       $settings = ot_list_item_settings( $name );
       
  3050       
       
  3051     }
       
  3052     
       
  3053     /* merge the two settings array */
       
  3054     $settings = array_merge( $required_setting, $settings );
       
  3055     
       
  3056     echo '
       
  3057     <div class="option-tree-setting">
       
  3058       <div class="open">' . ( isset( $list_item['title'] ) ? esc_attr( $list_item['title'] ) : 'Item ' . ( $key + 1 ) ) . '</div>
       
  3059       <div class="button-section">
       
  3060         <a href="javascript:void(0);" class="option-tree-setting-edit option-tree-ui-button left-item" title="' . __( 'Edit', 'option-tree' ) . '">
       
  3061           <span class="icon pencil">' . __( 'Edit', 'option-tree' ) . '</span>
       
  3062         </a>
       
  3063         <a href="javascript:void(0);" class="option-tree-setting-remove option-tree-ui-button right-item" title="' . __( 'Delete', 'option-tree' ) . '">
       
  3064           <span class="icon trash-can">' . __( 'Delete', 'option-tree' ) . '</span>
       
  3065         </a>
       
  3066       </div>
       
  3067       <div class="option-tree-setting-body">';
       
  3068         
       
  3069       foreach( $settings as $field ) {
       
  3070         
       
  3071         /* set default to standard value */
       
  3072         if ( ! isset( $list_item[$field['id']] ) && isset( $field['std'] ) ) {  
       
  3073           $list_item[$field['id']] = trim( $field['std'] );
       
  3074         }
       
  3075           
       
  3076         /* make life easier */
       
  3077         $_field_name = $get_option ? $get_option . '[' . $name . ']' : $name;
       
  3078              
       
  3079         /* build the arguments array */
       
  3080         $_args = array(
       
  3081           'type'              => $field['type'],
       
  3082           'field_id'          => $name . '_' . $field['id'] . '_' . $key,
       
  3083           'field_name'        => $_field_name . '[' . $key . '][' . $field['id'] . ']',
       
  3084           'field_value'       => isset( $list_item[$field['id']] ) ? $list_item[$field['id']] : '',
       
  3085           'field_desc'        => isset( $field['desc'] ) ? $field['desc'] : '',
       
  3086           'field_std'         => isset( $field['std'] ) ? $field['std'] : '',
       
  3087           'field_rows'        => isset( $field['rows'] ) ? $field['rows'] : 10,
       
  3088           'field_post_type'   => isset( $field['post_type'] ) && ! empty( $field['post_type'] ) ? $field['post_type'] : 'post',
       
  3089           'field_taxonomy'    => isset( $field['taxonomy'] ) && ! empty( $field['taxonomy'] ) ? $field['taxonomy'] : 'category',
       
  3090           'field_class'       => isset( $field['class'] ) ? $field['class'] : '',
       
  3091           'field_choices'     => isset( $field['choices'] ) && ! empty( $field['choices'] ) ? $field['choices'] : array(),
       
  3092           'field_settings'    => isset( $field['settings'] ) && ! empty( $field['settings'] ) ? $field['settings'] : array(),
       
  3093           'post_id'           => $post_id,
       
  3094           'get_option'        => $get_option
       
  3095         );
       
  3096           
       
  3097         /* option label */
       
  3098         echo '<div class="format-settings">';
       
  3099           
       
  3100         /* don't show title with textblocks */
       
  3101         if ( $_args['type'] != 'textblock' ) {
       
  3102           echo '<div class="format-setting-label">';
       
  3103             echo '<h3 class="label">' . esc_attr( $field['label'] ) . '</h3>';
       
  3104           echo '</div>';
       
  3105         }
       
  3106         
       
  3107         /* only allow simple textarea inside a list-item due to known DOM issues with wp_editor() */
       
  3108         if ( $_args['type'] == 'textarea' )
       
  3109           $_args['type'] = 'textarea-simple';
       
  3110           
       
  3111         /* option body, list-item is not allowed inside another list-item */
       
  3112         if ( $_args['type'] !== 'list-item' && $_args['type'] !== 'slider' ) {
       
  3113           echo ot_display_by_type( $_args );
       
  3114         }
       
  3115         
       
  3116         echo '</div>';
       
  3117       
       
  3118       }
       
  3119         
       
  3120     echo
       
  3121       '</div>
       
  3122     </div>';
       
  3123     
       
  3124   }
       
  3125   
       
  3126 }
       
  3127 
       
  3128 /**
       
  3129  * Helper function to display Theme Options layouts form.
       
  3130  *
       
  3131  * @return    string
       
  3132  *
       
  3133  * @access    public
       
  3134  * @since     2.0
       
  3135  */
       
  3136 if ( ! function_exists( 'ot_theme_options_layouts_form' ) ) {
       
  3137 
       
  3138   function ot_theme_options_layouts_form() {
       
  3139     
       
  3140     echo '<form method="post" id="option-tree-options-layouts-form">';
       
  3141         
       
  3142       /* form nonce */
       
  3143       wp_nonce_field( 'option_tree_modify_layouts_form', 'option_tree_modify_layouts_nonce' );
       
  3144         
       
  3145       /* get the saved layouts */
       
  3146       $layouts = get_option( 'option_tree_layouts' );
       
  3147       
       
  3148       /* set active layout */
       
  3149       $active_layout = isset( $layouts['active_layout'] ) ? $layouts['active_layout'] : '';
       
  3150       
       
  3151       /* new layout wrapper */
       
  3152       echo '<div class="option-tree-save-layout">';
       
  3153         
       
  3154         /* add new layout */
       
  3155         echo '<input type="text" name="option_tree_layouts[_add_new_layout_]" value="" class="widefat option-tree-ui-input" autocomplete="off" />';
       
  3156         
       
  3157         echo '<button type="submit" class="option-tree-ui-button blue light save-layout" title="' . __( 'New Layout', 'option-tree' ) . '">' . __( 'New Layout', 'option-tree' ) . '</button>';
       
  3158       
       
  3159       echo '</div>';
       
  3160     
       
  3161       if ( is_array( $layouts ) && count( $layouts ) > 1 ) {
       
  3162         
       
  3163         $active_layout = esc_attr( $layouts['active_layout'] );
       
  3164         
       
  3165         echo '<input type="hidden" id="the_current_layout" value="' . $active_layout . '" />';
       
  3166         
       
  3167         echo '<select name="option_tree_layouts[active_layout]" class="option-tree-ui-select option-tree-active-layout">';
       
  3168     
       
  3169           foreach( $layouts as $key => $data ) { 
       
  3170             
       
  3171             if ( $key == 'active_layout' )
       
  3172               continue;
       
  3173             
       
  3174             echo '<option' . selected( $key, $active_layout, false ) . ' value="' . esc_attr( $key ) . '">' . esc_attr( $key ) . '</option>';
       
  3175           }
       
  3176      		
       
  3177         echo '</select>';
       
  3178      		
       
  3179         foreach( $layouts as $key => $data ) {
       
  3180           
       
  3181           if ( $key == 'active_layout' )
       
  3182               continue;
       
  3183               
       
  3184           echo '<input type="hidden" name="option_tree_layouts[' . $key . ']" value="' . ( isset( $data ) ? $data : '' ) . '" />';
       
  3185           
       
  3186         }
       
  3187    		
       
  3188       }
       
  3189       
       
  3190     echo '</form>';
       
  3191     
       
  3192   }
       
  3193 
       
  3194 }
       
  3195 
       
  3196 /**
       
  3197  * Helper function to validate option ID's
       
  3198  *
       
  3199  * @param     string      $input The string to sanitize.
       
  3200  * @return    string
       
  3201  *
       
  3202  * @access    public
       
  3203  * @since     2.0
       
  3204  */
       
  3205 if ( ! function_exists( 'ot_sanitize_option_id' ) ) {
       
  3206 
       
  3207   function ot_sanitize_option_id( $input ) {
       
  3208   
       
  3209     return preg_replace( '/[^a-z0-9]/', '_', trim( strtolower( $input ) ) );
       
  3210       
       
  3211   }
       
  3212 
       
  3213 }
       
  3214 
       
  3215 /**
       
  3216  * Helper function to validate layout ID's
       
  3217  *
       
  3218  * @param     string      $input The string to sanitize.
       
  3219  * @return    string
       
  3220  *
       
  3221  * @access    public
       
  3222  * @since     2.0
       
  3223  */
       
  3224 if ( ! function_exists( 'ot_sanitize_layout_id' ) ) {
       
  3225 
       
  3226   function ot_sanitize_layout_id( $input ) {
       
  3227   
       
  3228     return preg_replace( '/[^a-z0-9]/', '-', trim( strtolower( $input ) ) );
       
  3229       
       
  3230   }
       
  3231 
       
  3232 }
       
  3233 
       
  3234 /**
       
  3235  * Convert choices array to string
       
  3236  *
       
  3237  * @return    string
       
  3238  *
       
  3239  * @access    public
       
  3240  * @since     2.0
       
  3241  */
       
  3242 if ( ! function_exists( 'ot_convert_array_to_string' ) ) {
       
  3243 
       
  3244   function ot_convert_array_to_string( $input ) {
       
  3245 
       
  3246     if ( is_array( $input ) ) {
       
  3247 
       
  3248       foreach( $input as $k => $choice ) {
       
  3249         $choices[$k] = $choice['value'] . '|' . $choice['label'];
       
  3250         
       
  3251         if ( isset( $choice['src'] ) )
       
  3252           $choices[$k].= '|' . $choice['src'];
       
  3253           
       
  3254       }
       
  3255       
       
  3256       return implode( ',', $choices );
       
  3257     }
       
  3258     
       
  3259     return false;
       
  3260   }
       
  3261 }
       
  3262 
       
  3263 /**
       
  3264  * Convert choices string to array
       
  3265  *
       
  3266  * @return    array
       
  3267  *
       
  3268  * @access    public
       
  3269  * @since     2.0
       
  3270  */
       
  3271 if ( ! function_exists( 'ot_convert_string_to_array' ) ) {
       
  3272 
       
  3273   function ot_convert_string_to_array( $input ) {
       
  3274     
       
  3275     if ( '' !== $input ) {
       
  3276     
       
  3277       /* empty choices array */
       
  3278       $choices = array();
       
  3279       
       
  3280       /* exlode the string into an array */
       
  3281       foreach( explode( ',', $input ) as $k => $choice ) {
       
  3282         
       
  3283         /* if ":" is splitting the string go deeper */
       
  3284         if ( preg_match( '/\|/', $choice ) ) {
       
  3285           $split = explode( '|', $choice );
       
  3286           $choices[$k]['value'] = trim( $split[0] );
       
  3287           $choices[$k]['label'] = trim( $split[1] );
       
  3288           
       
  3289           /* if radio image there are three values */
       
  3290           if ( isset( $split[2] ) )
       
  3291             $choices[$k]['src'] = trim( $split[2] );
       
  3292             
       
  3293         } else {
       
  3294           $choices[$k]['value'] = trim( $choice );
       
  3295           $choices[$k]['label'] = trim( $choice );
       
  3296         }
       
  3297         
       
  3298       }
       
  3299       
       
  3300       /* return a formated choices array */
       
  3301       return $choices;
       
  3302     
       
  3303     }
       
  3304     
       
  3305     return false;
       
  3306     
       
  3307   }
       
  3308 }
       
  3309 
       
  3310 /**
       
  3311  * Helper function - strpos() with arrays.
       
  3312  *
       
  3313  * @param     string    $haystack
       
  3314  * @param     array     $needles
       
  3315  * @return    bool
       
  3316  *
       
  3317  * @access    public
       
  3318  * @since     2.0
       
  3319  */
       
  3320 if ( ! function_exists( 'ot_strpos_array' ) ) {
       
  3321 
       
  3322   function ot_strpos_array( $haystack, $needles = array() ) {
       
  3323   
       
  3324     foreach( $needles as $needle ) {
       
  3325       $pos = strpos( $haystack, $needle );
       
  3326       if ( $pos !== false ) {
       
  3327         return true;
       
  3328       }
       
  3329     }
       
  3330     
       
  3331     return false;
       
  3332   }
       
  3333 
       
  3334 }
       
  3335 
       
  3336 /**
       
  3337  * Helper function - strpos() with arrays.
       
  3338  *
       
  3339  * @param     string    $haystack
       
  3340  * @param     array     $needles
       
  3341  * @return    bool
       
  3342  *
       
  3343  * @access    public
       
  3344  * @since     2.0
       
  3345  */
       
  3346 if ( ! function_exists( 'ot_array_keys_exists' ) ) {
       
  3347   
       
  3348   function ot_array_keys_exists( $array, $keys ) {
       
  3349     
       
  3350     foreach($keys as $k) {
       
  3351       if ( isset($array[$k]) ) {
       
  3352         return true;
       
  3353       }
       
  3354     }
       
  3355     
       
  3356     return false;
       
  3357   }
       
  3358   
       
  3359 }
       
  3360 
       
  3361 /**
       
  3362  * Custom stripslashes from single value or array.
       
  3363  *
       
  3364  * @param       mixed   $input
       
  3365  * @return      mixed
       
  3366  *
       
  3367  * @access      public
       
  3368  * @since       2.0
       
  3369  */
       
  3370 if ( ! function_exists( 'ot_stripslashes' ) ) {
       
  3371 
       
  3372   function ot_stripslashes( $input ) {
       
  3373   
       
  3374     if ( is_array( $input ) ) {
       
  3375     
       
  3376       foreach( $input as &$val ) {
       
  3377       
       
  3378         if ( is_array( $val ) ) {
       
  3379         
       
  3380           $val = ot_stripslashes( $val );
       
  3381           
       
  3382         } else {
       
  3383         
       
  3384           $val = stripslashes( trim( $val ) );
       
  3385           
       
  3386         }
       
  3387         
       
  3388       }
       
  3389       
       
  3390     } else {
       
  3391     
       
  3392       $input = stripslashes( trim( $input ) );
       
  3393       
       
  3394     }
       
  3395     
       
  3396     return $input;
       
  3397     
       
  3398   }
       
  3399 
       
  3400 }
       
  3401 
       
  3402 /**
       
  3403  * Reverse wpautop.
       
  3404  *
       
  3405  * @param     string    $string The string to be filtered
       
  3406  * @return    string
       
  3407  *
       
  3408  * @access    public
       
  3409  * @since     2.0.9
       
  3410  */
       
  3411 if ( ! function_exists( 'ot_reverse_wpautop' ) ) {
       
  3412 
       
  3413   function ot_reverse_wpautop( $string = '' ) {
       
  3414     
       
  3415     /* return if string is empty */
       
  3416     if ( trim( $string ) === '' )
       
  3417   		return '';
       
  3418   		
       
  3419     /* remove all new lines & <p> tags */
       
  3420     $string = str_replace( array( "\n", "<p>" ), "", $string );
       
  3421   
       
  3422     /* replace <br /> with \r */
       
  3423     $string = str_replace( array( "<br />", "<br>", "<br/>" ), "\r", $string );
       
  3424   
       
  3425     /* replace </p> with \r\n */
       
  3426     $string = str_replace( "</p>", "\r\n", $string );
       
  3427     
       
  3428     /* return clean string */
       
  3429     return trim( $string );
       
  3430                 
       
  3431   }
       
  3432 
       
  3433 }
       
  3434 
       
  3435 /**
       
  3436  * Returns an array of elements from start to limit, inclusive.
       
  3437  *
       
  3438  * Occasionally zero will be some impossibly large number to 
       
  3439  * the "E" power when creating a range from negative to positive.
       
  3440  * This function attempts to fix that by setting that number back to "0".
       
  3441  *
       
  3442  * @param     string    $start First value of the sequence.
       
  3443  * @param     string    $limit The sequence is ended upon reaching the limit value.
       
  3444  * @param     string    $step If a step value is given, it will be used as the increment 
       
  3445  *                      between elements in the sequence. step should be given as a 
       
  3446  *                      positive number. If not specified, step will default to 1.
       
  3447  * @return    array
       
  3448  *
       
  3449  * @access    public
       
  3450  * @since     2.0.12
       
  3451  */
       
  3452 function ot_range( $start, $limit, $step = 1 ) {
       
  3453   
       
  3454   if ( $step < 0 )
       
  3455     $step = 1;
       
  3456     
       
  3457   $range = range( $start, $limit, $step );
       
  3458   
       
  3459   foreach( $range as $k => $v ) {
       
  3460     if ( strpos( $v, 'E' ) ) {
       
  3461       $range[$k] = 0;
       
  3462     }
       
  3463   }
       
  3464   
       
  3465   return $range;
       
  3466 }
       
  3467 
       
  3468 /* End of file ot-functions-admin.php */
       
  3469 /* Location: ./includes/ot-functions-admin.php */