render_styles_fields( 'row', '

' . __( 'Row Styles', 'siteorigin-panels' ) . '

', '', $current, $post_id, $args ); break; case 'cell': $cell_number = isset( $args['index'] ) ? ' ' . ( (int) $args['index'] + 1 ) : ''; $this->render_styles_fields( 'cell', '

' . sprintf( __( 'Cell%s Styles', 'siteorigin-panels' ), $cell_number ) . '

', '', $current, $post_id, $args ); break; case 'widget': $this->render_styles_fields( 'widget', '

' . __( 'Widget Styles', 'siteorigin-panels' ) . '

', '', $current, $post_id, $args ); break; } wp_die(); } /** * Render all the style fields * * @param $section * @param string $before * @param string $after * @param array $current * @param int $post_id * @param array $args Arguments passed by the builder * * @return bool */ function render_styles_fields( $section, $before = '', $after = '', $current = array(), $post_id = 0, $args = array() ) { $fields = array(); $fields = apply_filters( 'siteorigin_panels_' . $section . '_style_fields', $fields, $post_id, $args ); $fields = apply_filters( 'siteorigin_panels_general_style_fields', $fields, $post_id, $args ); if ( empty( $fields ) ) { return false; } $groups = array( 'attributes' => array( 'name' => __( 'Attributes', 'siteorigin-panels' ), 'priority' => 5 ), 'layout' => array( 'name' => __( 'Layout', 'siteorigin-panels' ), 'priority' => 10 ), 'tablet_layout' => array( 'name' => __( 'Tablet Layout', 'siteorigin-panels' ), 'priority' => 11 ), 'mobile_layout' => array( 'name' => __( 'Mobile Layout', 'siteorigin-panels' ), 'priority' => 12 ), 'design' => array( 'name' => __( 'Design', 'siteorigin-panels' ), 'priority' => 15 ), ); if ( ! siteorigin_panels_setting( 'tablet-layout' ) ) { unset( $groups['tablet_layout'] ); } // Check if we need a default group foreach ( $fields as $field_id => $field ) { if ( empty( $field['group'] ) || $field['group'] == 'theme' ) { if ( empty( $groups['theme'] ) ) { $groups['theme'] = array( 'name' => __( 'Theme', 'siteorigin-panels' ), 'priority' => 10 ); } $fields[ $field_id ]['group'] = 'theme'; } } $groups = apply_filters( 'siteorigin_panels_' . $section . '_style_groups', $groups, $post_id, $args ); $groups = apply_filters( 'siteorigin_panels_general_style_groups', $groups, $post_id, $args ); // Sort the style fields and groups by priority uasort( $fields, array( $this, 'sort_fields' ) ); uasort( $groups, array( $this, 'sort_fields' ) ); echo $before; $group_counts = array(); foreach ( $fields as $field_id => $field ) { if ( empty( $group_counts[ $field['group'] ] ) ) { $group_counts[ $field['group'] ] = 0; } $group_counts[ $field['group'] ] ++; } foreach ( $groups as $group_id => $group ) { if ( empty( $group_counts[ $group_id ] ) ) { continue; } ?>

'; switch ( $field['type'] ) { case 'measurement' : if ( ! empty( $field['multiple'] ) ) { ?>
>
$v ) : ?>
$sub_field ) : ?>
render_style_field( $sub_field, isset( $current_styles[ $sub_field_id ] ) ? $current_styles[ $sub_field_id ] : $default, $sub_field_id, $current_styles ); ?>
'; if ( ! empty( $field['description'] ) ) { ?>

sanitize_style_fields( 'widget', $panels_data['widgets'][ $i ]['panels_info']['style'] ); } } if ( ! empty( $panels_data['grids'] ) ) { // The rows for ( $i = 0; $i < count( $panels_data['grids'] ); $i ++ ) { if ( empty( $panels_data['grids'][ $i ]['style'] ) ) { continue; } $panels_data['grids'][ $i ]['style'] = $this->sanitize_style_fields( 'row', $panels_data['grids'][ $i ]['style'] ); } } if ( ! empty( $panels_data['grid_cells'] ) ) { // And finally, the cells for ( $i = 0; $i < count( $panels_data['grid_cells'] ); $i ++ ) { if ( empty( $panels_data['grid_cells'][ $i ]['style'] ) ) { continue; } $panels_data['grid_cells'][ $i ]['style'] = $this->sanitize_style_fields( 'cell', $panels_data['grid_cells'][ $i ]['style'] ); } } return $panels_data; } /** * Sanitize style fields. * * @param $section * @param $styles * * @return array Sanitized styles */ function sanitize_style_fields( $section, $styles, $sub_field = array() ) { // Use the filter to get the fields for this section. if ( empty( $sub_field ) ) { if ( empty( $fields_cache[ $section ] ) ) { // This filter doesn't pass in the arguments $post_id and $args // Plugins looking to extend fields, should always add their fields if these are empty $fields_cache[ $section ] = array(); $fields_cache[ $section ] = apply_filters( 'siteorigin_panels_' . $section . '_style_fields', $fields_cache[ $section ], false, false ); $fields_cache[ $section ] = apply_filters( 'siteorigin_panels_general_style_fields', $fields_cache[ $section ], false, false ); } $fields = $fields_cache[ $section ]; } else { $fields = $sub_field; } if ( empty( $fields ) ) { return array(); } $return = array(); foreach ( $fields as $k => $field ) { // Skip this if no field type is set if ( empty( $field['type'] ) ) { continue; } // Sub fields prefix the parent field name. if ( ! empty( $sub_field ) ) { $k = $section . '_' . $k; } // Handle the special case of a checkbox if ( $field['type'] == 'checkbox' ) { $return[ $k ] = ! empty( $styles[ $k ] ) ? true : ''; continue; } // Ignore this if we don't even have a value for the style, unless 'image' field which might have a fallback. if ( ! isset( $styles[ $k ] ) || ( $field['type'] != 'image' && $styles[ $k ] == '' ) ) { continue; } switch ( $field['type'] ) { case 'color' : $color = $styles[ $k ]; if ( preg_match( '|^#([A-Fa-f0-9]{3,8})$|', $color ) ) { $return[ $k ] = $color; } else { $return[ $k ] = ''; } break; case 'image' : $return[ $k ] = ! empty( $styles[ $k ] ) ? sanitize_text_field( $styles[ $k ] ) : false; $fallback_name = $k . '_fallback'; if ( empty( $styles[ $k ] ) && empty( $styles[ $fallback_name ] ) ) { break; } $return[ $fallback_name ] = ! empty( $styles[ $fallback_name ] ) ? esc_url_raw( $styles[ $fallback_name ] ) : false; break; case 'url' : $return[ $k ] = esc_url_raw( $styles[ $k ] ); break; case 'measurement' : $measurements = array_map( 'preg_quote', $this->measurements_list() ); if ( ! empty( $field['multiple'] ) ) { if ( preg_match_all( '/(?:(-?[0-9\.,]+).*?(' . implode( '|', $measurements ) . ')+)/', $styles[ $k ], $match ) ) { $return[ $k ] = $styles[ $k ]; } else { $return[ $k ] = ''; } } else { if ( preg_match( '/([-?0-9\.,]+).*?(' . implode( '|', $measurements ) . ')/', $styles[ $k ], $match ) ) { $return[ $k ] = $match[1] . $match[2]; } else { $return[ $k ] = ''; } } break; case 'select' : case 'radio' : if ( ! empty( $styles[ $k ] ) && in_array( $styles[ $k ], array_keys( $field['options'] ) ) ) { $return[ $k ] = $styles[ $k ]; } break; case 'toggle' : $return[ $k ] = $styles[ $k ]; $return[ $k ] = ! empty( $styles[ $k ] ) ? true : ''; if ( ! empty( $field['fields'] ) ) { $return = $return + $this->sanitize_style_fields( $k, $styles, $field['fields'] ); } default: // Just pass the value through. $return[ $k ] = $styles[ $k ]; break; } } return $return; } /** * Convert the single string attribute of the grid style into an array. * * @param $panels_data * * @return mixed */ function convert_data( $panels_data ) { if ( empty( $panels_data ) || empty( $panels_data['grids'] ) || ! is_array( $panels_data['grids'] ) ) { return $panels_data; } foreach( $panels_data['grids'] as & $grid ) { if ( ! is_array( $grid ) || empty( $grid ) || empty( $grid['style'] ) ) { continue; } if ( is_string( $grid['style'] ) ) { $grid['style'] = array( $grid['style'] ); } } return $panels_data; } /** * Migrate deprecated styles. * * @param $style array The currently selected styles. * @param $post_id int The id of the current post. * @param $args array An array containing builder Arguments. * * @return array */ function style_migration( $style, $post_id, $type, $args ) { if ( isset( $style['background_display'] ) && $style['background_display'] == 'parallax-original' ) { $style['background_display'] = 'parallax'; } return $style; } /** * Get list of supported mesurements * * @return array */ function measurements_list() { $measurements = array( 'px', '%', 'in', 'cm', 'mm', 'em', 'ex', 'pt', 'pc', 'rem' ); // Allow themes and plugins to trim or enhance the list. return apply_filters( 'siteorigin_panels_style_get_measurements_list', $measurements ); } /** * User sort function to sort by the priority key value. * * @param $a * @param $b * * @return int */ static function sort_fields( $a, $b ) { return ( ( isset( $a['priority'] ) ? $a['priority'] : 10 ) > ( isset( $b['priority'] ) ? $b['priority'] : 10 ) ) ? 1 : - 1; } } // Initialise all the default styling SiteOrigin_Panels_Styles::single();