' . __( 'Layouts could not be updated.', 'option-tree' ) . '
';
+
+ }
+
+ }
+
+ }
+
+ return false;
+ }
+
+}
+
+/**
+ * Setup the default option types.
+ *
+ * The returned option types are filterable so you can add your own.
+ * This is not a task for a beginner as you'll need to add the function
+ * that displays the option to the user and validate the saved data.
+ *
+ * @return array
+ *
+ * @access public
+ * @since 2.0
+ */
+if ( ! function_exists( 'ot_option_types_array' ) ) {
+
+ function ot_option_types_array() {
+
+ return apply_filters( 'ot_option_types_array', array(
+ 'background' => 'Background',
+ 'category-checkbox' => 'Category Checkbox',
+ 'category-select' => 'Category Select',
+ 'checkbox' => 'Checkbox',
+ 'colorpicker' => 'Colorpicker',
+ 'css' => 'CSS',
+ 'custom-post-type-checkbox' => 'Custom Post Type Checkbox',
+ 'custom-post-type-select' => 'Custom Post Type Select',
+ 'list-item' => 'List Item',
+ 'measurement' => 'Measurement',
+ 'page-checkbox' => 'Page Checkbox',
+ 'page-select' => 'Page Select',
+ 'post-checkbox' => 'Post Checkbox',
+ 'post-select' => 'Post Select',
+ 'radio' => 'Radio',
+ 'radio-image' => 'Radio Image',
+ 'select' => 'Select',
+ 'slider' => 'Slider',
+ 'tag-checkbox' => 'Tag Checkbox',
+ 'tag-select' => 'Tag Select',
+ 'taxonomy-checkbox' => 'Taxonomy Checkbox',
+ 'taxonomy-select' => 'Taxonomy Select',
+ 'text' => 'Text',
+ 'textarea' => 'Textarea',
+ 'textarea-simple' => 'Textarea Simple',
+ 'textblock' => 'Textblock',
+ 'textblock-titled' => 'Textblock Titled',
+ 'typography' => 'Typography',
+ 'upload' => 'Upload'
+ ) );
+
+ }
+}
+
+/**
+ * Map old option types for rebuilding XML and Table data.
+ *
+ * @param string $type The old option type
+ * @return string The new option type
+ *
+ * @access public
+ * @since 2.0
+ */
+if ( ! function_exists( 'ot_map_old_option_types' ) ) {
+
+ function ot_map_old_option_types( $type = '' ) {
+
+ if ( ! $type )
+ return 'text';
+
+ $types = array(
+ 'background' => 'background',
+ 'category' => 'category-select',
+ 'categories' => 'category-checkbox',
+ 'checkbox' => 'checkbox',
+ 'colorpicker' => 'colorpicker',
+ 'css' => 'css',
+ 'custom_post' => 'custom-post-type-select',
+ 'custom_posts' => 'custom-post-type-checkbox',
+ 'input' => 'text',
+ 'image' => 'upload',
+ 'measurement' => 'measurement',
+ 'page' => 'page-select',
+ 'pages' => 'page-checkbox',
+ 'post' => 'post-select',
+ 'posts' => 'post-checkbox',
+ 'radio' => 'radio',
+ 'select' => 'select',
+ 'slider' => 'slider',
+ 'tag' => 'tag-select',
+ 'tags' => 'tag-checkbox',
+ 'textarea' => 'textarea',
+ 'textblock' => 'textblock',
+ 'typography' => 'typography',
+ 'upload' => 'upload'
+ );
+
+ if ( isset( $types[$type] ) )
+ return $types[$type];
+
+ return false;
+
+ }
+}
+
+/**
+ * Recognized font families
+ *
+ * Returns an array of all recognized font families.
+ * Keys are intended to be stored in the database
+ * while values are ready for display in html.
+ * Renamed in version 2.0 to avoid name collisions.
+ *
+ * @uses apply_filters()
+ *
+ * @return array
+ *
+ * @access public
+ * @since 1.1.8
+ * @updated 2.0
+ */
+if ( ! function_exists( 'ot_recognized_font_families' ) ) {
+
+ function ot_recognized_font_families( $field_id = '' ) {
+
+ return apply_filters( 'ot_recognized_font_families', array(
+ 'arial' => 'Arial',
+ 'georgia' => 'Georgia',
+ 'helvetica' => 'Helvetica',
+ 'palatino' => 'Palatino',
+ 'tahoma' => 'Tahoma',
+ 'times' => '"Times New Roman", sans-serif',
+ 'trebuchet' => 'Trebuchet',
+ 'verdana' => 'Verdana'
+ ), $field_id );
+
+ }
+
+}
+
+/**
+ * Recognized font sizes
+ *
+ * Returns an array of all recognized font sizes.
+ *
+ * @uses apply_filters()
+ *
+ * @param string $field_id ID that's passed to the filters.
+ * @return array
+ *
+ * @access public
+ * @since 2.0.12
+ */
+if ( ! function_exists( 'ot_recognized_font_sizes' ) ) {
+
+ function ot_recognized_font_sizes( $field_id ) {
+
+ $range = ot_range(
+ apply_filters( 'ot_font_size_low_range', 0, $field_id ),
+ apply_filters( 'ot_font_size_high_range', 150, $field_id ),
+ apply_filters( 'ot_font_size_range_interval', 1, $field_id )
+ );
+
+ $unit = apply_filters( 'ot_font_size_unit_type', 'px', $field_id );
+
+ foreach( $range as $k => $v ) {
+ $range[$k] = $v . $unit;
+ }
+
+ return $range;
+ }
+
+}
+
+/**
+ * Recognized font styles
+ *
+ * Returns an array of all recognized font styles.
+ * Renamed in version 2.0 to avoid name collisions.
+ *
+ * @uses apply_filters()
+ *
+ * @return array
+ *
+ * @access public
+ * @since 1.1.8
+ * @updated 2.0
+ */
+if ( ! function_exists( 'ot_recognized_font_styles' ) ) {
+
+ function ot_recognized_font_styles( $field_id = '' ) {
+
+ return apply_filters( 'ot_recognized_font_styles', array(
+ 'normal' => 'Normal',
+ 'italic' => 'Italic',
+ 'oblique' => 'Oblique',
+ 'inherit' => 'Inherit'
+ ), $field_id );
+
+ }
+
+}
+
+/**
+ * Recognized font variants
+ *
+ * Returns an array of all recognized font variants.
+ * Renamed in version 2.0 to avoid name collisions.
+ *
+ * @uses apply_filters()
+ *
+ * @return array
+ *
+ * @access public
+ * @since 1.1.8
+ * @updated 2.0
+ */
+if ( ! function_exists( 'ot_recognized_font_variants' ) ) {
+
+ function ot_recognized_font_variants( $field_id = '' ) {
+
+ return apply_filters( 'ot_recognized_font_variants', array(
+ 'normal' => 'Normal',
+ 'small-caps' => 'Small Caps',
+ 'inherit' => 'Inherit'
+ ), $field_id );
+
+ }
+
+}
+
+/**
+ * Recognized font weights
+ *
+ * Returns an array of all recognized font weights.
+ * Renamed in version 2.0 to avoid name collisions.
+ *
+ * @uses apply_filters()
+ *
+ * @return array
+ *
+ * @access public
+ * @since 1.1.8
+ * @updated 2.0
+ */
+if ( ! function_exists( 'ot_recognized_font_weights' ) ) {
+
+ function ot_recognized_font_weights( $field_id = '' ) {
+
+ return apply_filters( 'ot_recognized_font_weights', array(
+ 'normal' => 'Normal',
+ 'bold' => 'Bold',
+ 'bolder' => 'Bolder',
+ 'lighter' => 'Lighter',
+ '100' => '100',
+ '200' => '200',
+ '300' => '300',
+ '400' => '400',
+ '500' => '500',
+ '600' => '600',
+ '700' => '700',
+ '800' => '800',
+ '900' => '900',
+ 'inherit' => 'Inherit'
+ ), $field_id );
+
+ }
+
+}
+
+/**
+ * Recognized letter spacing
+ *
+ * Returns an array of all recognized line heights.
+ *
+ * @uses apply_filters()
+ *
+ * @param string $field_id ID that's passed to the filters.
+ * @return array
+ *
+ * @access public
+ * @since 2.0.12
+ */
+if ( ! function_exists( 'ot_recognized_letter_spacing' ) ) {
+
+ function ot_recognized_letter_spacing( $field_id ) {
+
+ $range = ot_range(
+ apply_filters( 'ot_letter_spacing_low_range', -0.1, $field_id ),
+ apply_filters( 'ot_letter_spacing_high_range', 0.1, $field_id ),
+ apply_filters( 'ot_letter_spacing_range_interval', 0.01, $field_id )
+ );
+
+ $unit = apply_filters( 'ot_letter_spacing_unit_type', 'em', $field_id );
+
+ foreach( $range as $k => $v ) {
+ $range[$k] = $v . $unit;
+ }
+
+ return $range;
+ }
+
+}
+
+/**
+ * Recognized line heights
+ *
+ * Returns an array of all recognized line heights.
+ *
+ * @uses apply_filters()
+ *
+ * @param string $field_id ID that's passed to the filters.
+ * @return array
+ *
+ * @access public
+ * @since 2.0.12
+ */
+if ( ! function_exists( 'ot_recognized_line_heights' ) ) {
+
+ function ot_recognized_line_heights( $field_id ) {
+
+ $range = ot_range(
+ apply_filters( 'ot_line_height_low_range', 0, $field_id ),
+ apply_filters( 'ot_line_height_high_range', 150, $field_id ),
+ apply_filters( 'ot_line_height_unit_type', 1, $field_id )
+ );
+
+ $unit = apply_filters( 'ot_line_height_unit_type', 'px', $field_id );
+
+ foreach( $range as $k => $v ) {
+ $range[$k] = $v . $unit;
+ }
+
+ return $range;
+ }
+
+}
+
+/**
+ * Recognized text decorations
+ *
+ * Returns an array of all recognized text decorations.
+ * Keys are intended to be stored in the database
+ * while values are ready for display in html.
+ *
+ * @uses apply_filters()
+ *
+ * @return array
+ *
+ * @access public
+ * @since 2.0.10
+ */
+if ( ! function_exists( 'ot_recognized_text_decorations' ) ) {
+
+ function ot_recognized_text_decorations( $field_id = '' ) {
+
+ return apply_filters( 'ot_recognized_text_decorations', array(
+ 'blink' => 'Blink',
+ 'inherit' => 'Inherit',
+ 'line-through' => 'Line Through',
+ 'none' => 'None',
+ 'overline' => 'Overline',
+ 'underline' => 'Underline'
+ ), $field_id );
+
+ }
+
+}
+
+/**
+ * Recognized text transformations
+ *
+ * Returns an array of all recognized text transformations.
+ * Keys are intended to be stored in the database
+ * while values are ready for display in html.
+ *
+ * @uses apply_filters()
+ *
+ * @return array
+ *
+ * @access public
+ * @since 2.0.10
+ */
+if ( ! function_exists( 'ot_recognized_text_transformations' ) ) {
+
+ function ot_recognized_text_transformations( $field_id = '' ) {
+
+ return apply_filters( 'ot_recognized_text_transformations', array(
+ 'capitalize' => 'Capitalize',
+ 'inherit' => 'Inherit',
+ 'lowercase' => 'Lowercase',
+ 'none' => 'None',
+ 'uppercase' => 'Uppercase'
+ ), $field_id );
+
+ }
+
+}
+
+/**
+ * Recognized background repeat
+ *
+ * Returns an array of all recognized background repeat values.
+ * Renamed in version 2.0 to avoid name collisions.
+ *
+ * @uses apply_filters()
+ *
+ * @return array
+ *
+ * @access public
+ * @since 1.1.8
+ * @updated 2.0
+ */
+if ( ! function_exists( 'ot_recognized_background_repeat' ) ) {
+
+ function ot_recognized_background_repeat( $field_id = '' ) {
+
+ return apply_filters( 'ot_recognized_background_repeat', array(
+ 'no-repeat' => 'No Repeat',
+ 'repeat' => 'Repeat All',
+ 'repeat-x' => 'Repeat Horizontally',
+ 'repeat-y' => 'Repeat Vertically',
+ 'inherit' => 'Inherit'
+ ), $field_id );
+
+ }
+
+}
+
+/**
+ * Recognized background attachment
+ *
+ * Returns an array of all recognized background attachment values.
+ * Renamed in version 2.0 to avoid name collisions.
+ *
+ * @uses apply_filters()
+ *
+ * @return array
+ *
+ * @access public
+ * @since 1.1.8
+ * @updated 2.0
+ */
+if ( ! function_exists( 'ot_recognized_background_attachment' ) ) {
+
+ function ot_recognized_background_attachment( $field_id = '' ) {
+
+ return apply_filters( 'ot_recognized_background_attachment', array(
+ "fixed" => "Fixed",
+ "scroll" => "Scroll",
+ "inherit" => "Inherit"
+ ), $field_id );
+
+ }
+
+}
+
+/**
+ * Recognized background position
+ *
+ * Returns an array of all recognized background position values.
+ * Renamed in version 2.0 to avoid name collisions.
+ *
+ * @uses apply_filters()
+ *
+ * @return array
+ *
+ * @access public
+ * @since 1.1.8
+ * @updated 2.0
+ */
+if ( ! function_exists( 'ot_recognized_background_position' ) ) {
+
+ function ot_recognized_background_position( $field_id = '' ) {
+
+ return apply_filters( 'ot_recognized_background_position', array(
+ "left top" => "Left Top",
+ "left center" => "Left Center",
+ "left bottom" => "Left Bottom",
+ "center top" => "Center Top",
+ "center center" => "Center Center",
+ "center bottom" => "Center Bottom",
+ "right top" => "Right Top",
+ "right center" => "Right Center",
+ "right bottom" => "Right Bottom"
+ ), $field_id );
+
+ }
+
+}
+
+/**
+ * Measurement Units
+ *
+ * Returns an array of all available unit types.
+ * Renamed in version 2.0 to avoid name collisions.
+ *
+ * @uses apply_filters()
+ *
+ * @return array
+ *
+ * @access public
+ * @since 1.1.8
+ * @updated 2.0
+ */
+if ( ! function_exists( 'ot_measurement_unit_types' ) ) {
+
+ function ot_measurement_unit_types( $field_id = '' ) {
+
+ return apply_filters( 'ot_measurement_unit_types', array(
+ 'px' => 'px',
+ '%' => '%',
+ 'em' => 'em',
+ 'pt' => 'pt'
+ ), $field_id );
+
+ }
+
+}
+
+/**
+ * Radio Images default array.
+ *
+ * Returns an array of all available radio images.
+ * You can filter this function to change the images
+ * on a per option basis.
+ *
+ * @uses apply_filters()
+ *
+ * @return array
+ *
+ * @access public
+ * @since 2.0
+ */
+if ( ! function_exists( 'ot_radio_images' ) ) {
+
+ function ot_radio_images( $field_id = '' ) {
+
+ return apply_filters( 'ot_radio_images', array(
+ array(
+ 'value' => 'left-sidebar',
+ 'label' => __( 'Left Sidebar', 'option-tree' ),
+ 'src' => OT_URL . 'assets/images/layout/left-sidebar.png'
+ ),
+ array(
+ 'value' => 'right-sidebar',
+ 'label' => __( 'Right Sidebar', 'option-tree' ),
+ 'src' => OT_URL . 'assets/images/layout/right-sidebar.png'
+ ),
+ array(
+ 'value' => 'full-width',
+ 'label' => __( 'Full Width (no sidebar)', 'option-tree' ),
+ 'src' => OT_URL . 'assets/images/layout/full-width.png'
+ ),
+ array(
+ 'value' => 'dual-sidebar',
+ 'label' => __( 'Dual Sidebar', 'option-tree' ),
+ 'src' => OT_URL . 'assets/images/layout/dual-sidebar.png'
+ ),
+ array(
+ 'value' => 'left-dual-sidebar',
+ 'label' => __( 'Left Dual Sidebar', 'option-tree' ),
+ 'src' => OT_URL . 'assets/images/layout/left-dual-sidebar.png'
+ ),
+ array(
+ 'value' => 'right-dual-sidebar',
+ 'label' => __( 'Right Dual Sidebar', 'option-tree' ),
+ 'src' => OT_URL . 'assets/images/layout/right-dual-sidebar.png'
+ )
+ ), $field_id );
+
+ }
+
+}
+
+/**
+ * Default List Item Settings array.
+ *
+ * Returns an array of the default list item settings.
+ * You can filter this function to change the settings
+ * on a per option basis.
+ *
+ * @uses apply_filters()
+ *
+ * @return array
+ *
+ * @access public
+ * @since 2.0
+ */
+if ( ! function_exists( 'ot_list_item_settings' ) ) {
+
+ function ot_list_item_settings( $id ) {
+
+ $settings = apply_filters( 'ot_list_item_settings', array(
+ array(
+ 'id' => 'image',
+ 'label' => __( 'Image', 'option-tree' ),
+ 'desc' => '',
+ 'std' => '',
+ 'type' => 'upload',
+ 'rows' => '',
+ 'class' => '',
+ 'post_type' => '',
+ 'choices' => array()
+ ),
+ array(
+ 'id' => 'link',
+ 'label' => __( 'Link', 'option-tree' ),
+ 'desc' => '',
+ 'std' => '',
+ 'type' => 'text',
+ 'rows' => '',
+ 'class' => '',
+ 'post_type' => '',
+ 'choices' => array()
+ ),
+ array(
+ 'id' => 'description',
+ 'label' => __( 'Description', 'option-tree' ),
+ 'desc' => '',
+ 'std' => '',
+ 'type' => 'textarea-simple',
+ 'rows' => 10,
+ 'class' => '',
+ 'post_type' => '',
+ 'choices' => array()
+ )
+ ), $id );
+
+ return $settings;
+
+ }
+
+}
+
+/**
+ * Default Slider Settings array.
+ *
+ * Returns an array of the default slider settings.
+ * You can filter this function to change the settings
+ * on a per option basis.
+ *
+ * @uses apply_filters()
+ *
+ * @return array
+ *
+ * @access public
+ * @since 2.0
+ */
+if ( ! function_exists( 'ot_slider_settings' ) ) {
+
+ function ot_slider_settings( $id ) {
+
+ $settings = apply_filters( 'image_slider_fields', array(
+ array(
+ 'name' => 'image',
+ 'type' => 'image',
+ 'label' => __( 'Image', 'option-tree' ),
+ 'class' => ''
+ ),
+ array(
+ 'name' => 'link',
+ 'type' => 'text',
+ 'label' => __( 'Link', 'option-tree' ),
+ 'class' => ''
+ ),
+ array(
+ 'name' => 'description',
+ 'type' => 'textarea',
+ 'label' => __( 'Description', 'option-tree' ),
+ 'class' => ''
+ )
+ ), $id );
+
+ /* fix the array keys, values, and just get it 2.0 ready */
+ foreach( $settings as $_k => $setting ) {
+
+ foreach( $setting as $s_key => $s_value ) {
+
+ if ( 'name' == $s_key ) {
+
+ $settings[$_k]['id'] = $s_value;
+ unset($settings[$_k]['name']);
+
+ } else if ( 'type' == $s_key ) {
+
+ if ( 'input' == $s_value ) {
+
+ $settings[$_k]['type'] = 'text';
+
+ } else if ( 'textarea' == $s_value ) {
+
+ $settings[$_k]['type'] = 'textarea-simple';
+
+ } else if ( 'image' == $s_value ) {
+
+ $settings[$_k]['type'] = 'upload';
+
+ }
+
+ }
+
+ }
+
+ }
+
+ return $settings;
+
+ }
+
+}
+
+/**
+ * Inserts CSS with field_id markers.
+ *
+ * Inserts CSS into a dynamic.css file, placing it between
+ * BEGIN and END field_id markers. Replaces existing marked info,
+ * but still retains surrounding data.
+ *
+ * @param string $field_id The CSS option field ID.
+ * @param array $options The current option_tree array.
+ * @return bool True on write success, false on failure.
+ *
+ * @access public
+ * @since 1.1.8
+ * @updated 2.0.12
+ */
+if ( ! function_exists( 'ot_insert_css_with_markers' ) ) {
+
+ function ot_insert_css_with_markers( $field_id = '', $insertion = '', $meta = false ) {
+
+ /* missing $field_id or $insertion exit early */
+ if ( '' == $field_id || '' == $insertion )
+ return;
+
+ /* path to the dynamic.css file */
+ $filepath = get_stylesheet_directory() . '/dynamic.css';
+
+ /* allow filter on path */
+ $filepath = apply_filters( 'css_option_file_path', $filepath, $field_id );
+
+ /* grab a copy of the paths array */
+ $ot_css_file_paths = get_option( 'ot_css_file_paths', array() );
+
+ /* set the path for this field */
+ $ot_css_file_paths[$field_id] = $filepath;
+
+ /* update the paths */
+ update_option( 'ot_css_file_paths', $ot_css_file_paths );
+
+ /* insert CSS into file */
+ if ( file_exists( $filepath ) ) {
+
+ $insertion = ot_normalize_css( $insertion );
+ $regex = "/{{([a-zA-Z0-9\_\-\#\|\=]+)}}/";
+ $marker = $field_id;
+
+ /* Match custom CSS */
+ preg_match_all( $regex, $insertion, $matches );
+
+ /* Loop through CSS */
+ foreach( $matches[0] as $option ) {
+
+ $value = '';
+ $option_id = str_replace( array( '{{', '}}' ), '', $option );
+ $option_array = explode( '|', $option_id );
+
+ /* get the array value */
+ if ( $meta ) {
+ global $post;
+
+ $value = get_post_meta( $post->ID, $option_array[0], true );
+
+ } else {
+
+ $options = get_option( 'option_tree' );
+
+ if ( isset( $options[$option_array[0]] ) ) {
+
+ $value = $options[$option_array[0]];
+
+ }
+
+ }
+
+ if ( is_array( $value ) ) {
+
+ if ( ! isset( $option_array[1] ) ) {
+
+ /* Measurement */
+ if ( isset( $value[0] ) && isset( $value[1] ) ) {
+
+ /* set $value with measurement properties */
+ $value = $value[0].$value[1];
+
+ /* typography */
+ } 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' ) ) ) {
+ $font = array();
+
+ if ( ! empty( $value['font-color'] ) )
+ $font[] = "color: " . $value['font-color'] . ";";
+
+ if ( ! empty( $value['font-family'] ) ) {
+ foreach ( ot_recognized_font_families( $marker ) as $key => $v ) {
+ if ( $key == $value['font-family'] ) {
+ $font[] = "font-family: " . $v . ";";
+ }
+ }
+ }
+
+ if ( ! empty( $value['font-size'] ) )
+ $font[] = "font-size: " . $value['font-size'] . ";";
+
+ if ( ! empty( $value['font-style'] ) )
+ $font[] = "font-style: " . $value['font-style'] . ";";
+
+ if ( ! empty( $value['font-variant'] ) )
+ $font[] = "font-variant: " . $value['font-variant'] . ";";
+
+ if ( ! empty( $value['font-weight'] ) )
+ $font[] = "font-weight: " . $value['font-weight'] . ";";
+
+ if ( ! empty( $value['letter-spacing'] ) )
+ $font[] = "letter-spacing: " . $value['letter-spacing'] . ";";
+
+ if ( ! empty( $value['line-height'] ) )
+ $font[] = "line-height: " . $value['line-height'] . ";";
+
+ if ( ! empty( $value['text-decoration'] ) )
+ $font[] = "text-decoration: " . $value['text-decoration'] . ";";
+
+ if ( ! empty( $value['text-transform'] ) )
+ $font[] = "text-transform: " . $value['text-transform'] . ";";
+
+ /* set $value with font properties or empty string */
+ $value = ! empty( $font ) ? implode( "\n", $font ) : '';
+
+ /* background */
+ } else if ( ot_array_keys_exists( $value, array( 'background-color', 'background-image', 'background-repeat', 'background-attachment', 'background-position' ) ) ) {
+ $bg = array();
+
+ if ( ! empty( $value['background-color'] ) )
+ $bg[] = $value['background-color'];
+
+ if ( ! empty( $value['background-image'] ) )
+ $bg[] = 'url("' . $value['background-image'] . '")';
+
+ if ( ! empty( $value['background-repeat'] ) )
+ $bg[] = $value['background-repeat'];
+
+ if ( ! empty( $value['background-attachment'] ) )
+ $bg[] = $value['background-attachment'];
+
+ if ( ! empty( $value['background-position'] ) )
+ $bg[] = $value['background-position'];
+
+ /* set $value with background properties or empty string */
+ $value = ! empty( $bg ) ? 'background: ' . implode( " ", $bg ) . ';' : '';
+ }
+
+ } else {
+
+ $value = $value[$option_array[1]];
+
+ }
+
+ }
+
+ /* insert CSS, even if the value is empty */
+ $insertion = stripslashes( str_replace( $option, $value, $insertion ) );
+
+ }
+
+ /* create array from the lines of code */
+ $markerdata = explode( "\n", implode( '', file( $filepath ) ) );
+
+ /* can't write to the file return false */
+ if ( ! $f = @fopen( $filepath, 'w' ) )
+ return false;
+
+ $searching = true;
+ $foundit = false;
+
+ /* has array of lines */
+ if ( ! empty( $markerdata ) ) {
+
+ /* foreach line of code */
+ foreach( $markerdata as $n => $markerline ) {
+
+ /* found begining of marker, set $searching to false */
+ if ( $markerline == "/* BEGIN {$marker} */" )
+ $searching = false;
+
+ /* keep rewrite each line of CSS */
+ if ( $searching == true ) {
+ if ( $n + 1 < count( $markerdata ) )
+ fwrite( $f, "{$markerline}\n" );
+ else
+ fwrite( $f, "{$markerline}" );
+ }
+
+ /* found end marker write code */
+ if ( $markerline == "/* END {$marker} */" ) {
+ fwrite( $f, "/* BEGIN {$marker} */\n" );
+ fwrite( $f, "{$insertion}\n" );
+ fwrite( $f, "/* END {$marker} */\n" );
+ $searching = true;
+ $foundit = true;
+ }
+
+ }
+
+ }
+
+ /* nothing inserted, write code. DO IT, DO IT! */
+ if ( ! $foundit ) {
+ fwrite( $f, "/* BEGIN {$marker} */\n" );
+ fwrite( $f, "{$insertion}\n" );
+ fwrite( $f, "/* END {$marker} */\n" );
+ }
+
+ /* close file */
+ fclose( $f );
+ return true;
+ }
+
+ return false;
+
+ }
+
+}
+
+/**
+ * Remove old CSS.
+ *
+ * Removes CSS when the textarea is empty, but still retains surrounding styles.
+ *
+ * @param string $field_id The CSS option field ID.
+ * @return bool True on write success, false on failure.
+ *
+ * @access public
+ * @since 2.0
+ */
+if ( ! function_exists( 'ot_remove_old_css' ) ) {
+
+ function ot_remove_old_css( $field_id = '' ) {
+
+ /* missing $field_id string */
+ if ( '' == $field_id )
+ return false;
+
+ /* path to the dynamic.css file */
+ $filepath = get_stylesheet_directory() . '/dynamic.css';
+
+ /* allow filter on path */
+ $filepath = apply_filters( 'css_option_file_path', $filepath, $field_id );
+
+ /* remove CSS from file */
+ if ( is_writeable( $filepath ) ) {
+
+ /* get each line in the file */
+ $markerdata = explode( "\n", implode( '', file( $filepath ) ) );
+
+ /* can't write to the file return false */
+ if ( ! $f = @fopen( $filepath, 'w' ) )
+ return false;
+
+ $searching = true;
+
+ /* has array of lines */
+ if ( ! empty( $markerdata ) ) {
+
+ /* foreach line of code */
+ foreach ( $markerdata as $n => $markerline ) {
+
+ /* found begining of marker, set $searching to false */
+ if ( $markerline == "/* BEGIN {$field_id} */" )
+ $searching = false;
+
+ /* $searching is true, keep rewrite each line of CSS */
+ if ( $searching == true ) {
+ if ( $n + 1 < count( $markerdata ) )
+ fwrite( $f, "{$markerline}\n" );
+ else
+ fwrite( $f, "{$markerline}" );
+ }
+
+ /* found end marker delete old CSS */
+ if ( $markerline == "/* END {$field_id} */" ) {
+ fwrite( $f, "" );
+ $searching = true;
+ }
+
+ }
+
+ }
+
+ /* close file */
+ fclose( $f );
+ return true;
+
+ }
+
+ return false;
+
+ }
+
+}
+
+/**
+ * Normalize CSS
+ *
+ * Normalize & Convert all line-endings to UNIX format.
+ *
+ * @param string $css
+ * @return string
+ *
+ * @access public
+ * @since 1.1.8
+ * @updated 2.0
+ */
+if ( ! function_exists( 'ot_normalize_css' ) ) {
+
+ function ot_normalize_css( $css ) {
+
+ /* Normalize & Convert */
+ $css = str_replace( "\r\n", "\n", $css );
+ $css = str_replace( "\r", "\n", $css );
+
+ /* Don't allow out-of-control blank lines */
+ $css = preg_replace( "/\n{2,}/", "\n\n", $css );
+
+ return $css;
+ }
+
+}
+
+/**
+ * Helper function to loop over the option types.
+ *
+ * @param array $type The current option type.
+ *
+ * @return string
+ *
+ * @access public
+ * @since 2.0
+ */
+if ( ! function_exists( 'ot_loop_through_option_types' ) ) {
+
+ function ot_loop_through_option_types( $type = '', $child = false ) {
+
+ $content = '';
+ $types = ot_option_types_array();
+
+ if ( $child )
+ unset($types['list-item']);
+
+ foreach( $types as $key => $value )
+ $content.= '';
+
+ return $content;
+
+ }
+
+}
+
+/**
+ * Helper function to loop over choices.
+ *
+ * @param string $name The form element name.
+ * @param array $choices The array of choices.
+ *
+ * @return string
+ *
+ * @access public
+ * @since 2.0
+ */
+if ( ! function_exists( 'ot_loop_through_choices' ) ) {
+
+ function ot_loop_through_choices( $name, $choices = array() ) {
+
+ $content = '';
+
+ foreach( $choices as $key => $choice )
+ $content.= '
' . ot_choices_view( $name, $key, $choice ) . '
';
+
+ return $content;
+ }
+
+}
+
+/**
+ * Helper function to loop over sub settings.
+ *
+ * @param string $name The form element name.
+ * @param array $settings The array of settings.
+ *
+ * @return string
+ *
+ * @access public
+ * @since 2.0
+ */
+if ( ! function_exists( 'ot_loop_through_sub_settings' ) ) {
+
+ function ot_loop_through_sub_settings( $name, $settings = array() ) {
+
+ $content = '';
+
+ foreach( $settings as $key => $setting )
+ $content.= '
' . ot_settings_view( $name, $key, $setting ) . '
';
+
+ return $content;
+ }
+
+}
+
+/**
+ * Helper function to display sections.
+ *
+ * This function is used in AJAX to add a new section
+ * and when section have already been added and saved.
+ *
+ * @param int $key The array key for the current element.
+ * @param array An array of values for the current section.
+ *
+ * @return void
+ *
+ * @access public
+ * @since 2.0
+ */
+if ( ! function_exists( 'ot_sections_view' ) ) {
+
+ function ot_sections_view( $name, $key, $section = array() ) {
+
+ return '
+
' . __( 'Section Title: Displayed as a menu item on the Theme Options page.', 'option-tree' ) . '
+
+
+
+
+
+
+
+
' . __( 'Section ID: A unique lower case alphanumeric string, underscores allowed.', 'option-tree' ) . '
+
+
+
+
+
+
+
';
+
+ }
+
+}
+
+/**
+ * Helper function to display settings.
+ *
+ * This function is used in AJAX to add a new setting
+ * and when settings have already been added and saved.
+ *
+ * @param int $key The array key for the current element.
+ * @param array An array of values for the current section.
+ *
+ * @return void
+ *
+ * @access public
+ * @since 2.0
+ */
+if ( ! function_exists( 'ot_settings_view' ) ) {
+
+ function ot_settings_view( $name, $key, $setting = array() ) {
+
+ $child = ( strpos( $name, '][settings]') !== false ) ? true : false;
+
+ return '
+
' . __( 'Label: Displayed as the label of a form element on the Theme Options page.', 'option-tree' ) . '
+
+
+
+
+
+
+
+
' . __( 'ID: A unique lower case alphanumeric string, underscores allowed.', 'option-tree' ) . '
+
+
+
+
+
+
+
+
' . __( 'Type: Choose one of the available option types from the dropdown.', 'option-tree' ) . '
+
+
+
+
+
+
+
+
' . __( 'Description: 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' ) . '
+
+
+
+
+
+
+
+
' . __( 'Choices: This will only affect the following option types: Checkbox, Radio, Select & Select Image.', 'option-tree' ) . '
' . __( 'Standard: Setting the standard value for your option only works for some option types. Read the OptionTree->Documentation for more information on which ones.', 'option-tree' ) . '
+
+
+
+
+
+
+
+
' . __( 'Rows: 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' ) . '
+
+
+
+
+
+
+
+
' . __( 'Post Type: 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' ) . '
+
+
+
+
+
+
+
+
' . __( 'Taxonomy: 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' ) . '
+
+
+
+
+
+
+
+
' . __( 'CSS Class: Add and optional class to this option type.', 'option-tree' ) . '
+
+
+
+
+
+
+
+ ' . ( ! $child ? '' : '' );
+
+ }
+
+}
+
+/**
+ * Helper function to display setting choices.
+ *
+ * This function is used in AJAX to add a new choice
+ * and when choices have already been added and saved.
+ *
+ * @param string $name The form element name.
+ * @param array $key The array key for the current element.
+ * @param array An array of values for the current choice.
+ *
+ * @return void
+ *
+ * @access public
+ * @since 2.0
+ */
+if ( ! function_exists( 'ot_choices_view' ) ) {
+
+ function ot_choices_view( $name, $key, $choice = array() ) {
+
+ return '
+
';
+
+ }
+
+}
+
+/**
+ * Helper function to display sections.
+ *
+ * This function is used in AJAX to add a new section
+ * and when section have already been added and saved.
+ *
+ * @param int $key The array key for the current element.
+ * @param array An array of values for the current section.
+ *
+ * @return void
+ *
+ * @access public
+ * @since 2.0
+ */
+if ( ! function_exists( 'ot_contextual_help_view' ) ) {
+
+ function ot_contextual_help_view( $name, $key, $content = array() ) {
+
+ return '
+
' . __( 'Title: Displayed as a contextual help menu item on the Theme Options page.', 'option-tree' ) . '
+
+
+
+
+
+
+
+
' . __( 'ID: A unique lower case alphanumeric string, underscores allowed.', 'option-tree' ) . '
+
+
+
+
+
+
+
+
' . __( 'Content: Enter the HTML content about this contextual help item displayed on the Theme Option page for end users to read.', 'option-tree' ) . '
with \r\n */
+ $string = str_replace( "", "\r\n", $string );
+
+ /* return clean string */
+ return trim( $string );
+
+ }
+
+}
+
+/**
+ * Returns an array of elements from start to limit, inclusive.
+ *
+ * Occasionally zero will be some impossibly large number to
+ * the "E" power when creating a range from negative to positive.
+ * This function attempts to fix that by setting that number back to "0".
+ *
+ * @param string $start First value of the sequence.
+ * @param string $limit The sequence is ended upon reaching the limit value.
+ * @param string $step If a step value is given, it will be used as the increment
+ * between elements in the sequence. step should be given as a
+ * positive number. If not specified, step will default to 1.
+ * @return array
+ *
+ * @access public
+ * @since 2.0.12
+ */
+function ot_range( $start, $limit, $step = 1 ) {
+
+ if ( $step < 0 )
+ $step = 1;
+
+ $range = range( $start, $limit, $step );
+
+ foreach( $range as $k => $v ) {
+ if ( strpos( $v, 'E' ) ) {
+ $range[$k] = 0;
+ }
+ }
+
+ return $range;
+}
+
+/* End of file ot-functions-admin.php */
+/* Location: ./includes/ot-functions-admin.php */
\ No newline at end of file