'; if ( isset( $field['title'] ) ) { $field_desc = ( isset( $field['desc'] ) ) ? '

' . $field['desc'] . '

' : ''; $output .= '

' . $field['title'] . '

' . $field_desc . '
'; } $output .= ( isset( $field['title'] ) ) ? '
' : ''; $value = ( ! isset( $value ) && isset( $field['default'] ) ) ? $field['default'] : $value; $value = ( isset( $field['value'] ) ) ? $field['value'] : $value; if ( class_exists( $class ) ) { ob_start(); $element = new $class( $field, $value, $unique ); $element->output(); $output .= ob_get_clean(); } else { $output .= '

' . __( 'This field class is not available!', 'cs-framework' ) . '

'; } $output .= ( isset( $field['title'] ) ) ? '
' : ''; $output .= '
'; $output .= ''; return $output; } } if ( ! function_exists( 'cs_encode_string' ) ) { /** * Encode string for backup options. * * @param mixed $string Options to encode. * * @return string */ function cs_encode_string( $string ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.stringFound -- Public API; renaming would break named-argument callers. // Backup format must stay readable by existing exports, so the serialize/base64 pipeline is unchanged. return rtrim( strtr( base64_encode( addslashes( gzcompress( serialize( $string ), 9 ) ) ), '+/', '-_' ), '=' ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode, WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize -- Existing backup export format. } } if ( ! function_exists( 'cs_decode_string' ) ) { /** * Decode string for backup options. * * @param string $string Encoded backup string. * * @return mixed */ function cs_decode_string( $string ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.stringFound -- Public API; renaming would break named-argument callers. // Options are plain arrays, so objects are never allowed when importing a backup. return unserialize( gzuncompress( stripslashes( base64_decode( rtrim( strtr( $string, '-_', '+/' ), '=' ) ) ) ), array( 'allowed_classes' => false ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode, WordPress.PHP.DiscouragedPHPFunctions.serialize_unserialize -- Existing backup import format. } } if ( ! function_exists( 'cs_get_google_fonts' ) ) { /** * Get google font from json file. * * @return object|null */ function cs_get_google_fonts() { global $cs_google_fonts; if ( ! empty( $cs_google_fonts ) ) { return $cs_google_fonts; } else { ob_start(); cs_locate_template( 'fields/typography/google-fonts.json' ); $json = ob_get_clean(); $cs_google_fonts = json_decode( $json ); return $cs_google_fonts; } } } if ( ! function_exists( 'cs_get_icon_fonts' ) ) { /** * Get icon fonts from json file. * * @param string $file JSON file path relative to the framework. * * @return object|null */ function cs_get_icon_fonts( $file ) { ob_start(); cs_locate_template( $file ); $json = ob_get_clean(); return json_decode( $json ); } } if ( ! function_exists( 'cs_array_search' ) ) { /** * Array search key & value. * * @param array $array Array to search. * @param string $key Key to match. * @param mixed $value Value to match. * * @return array */ function cs_array_search( $array, $key, $value ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.arrayFound -- Public API; renaming would break named-argument callers. $results = array(); if ( is_array( $array ) ) { if ( isset( $array[ $key ] ) && $array[ $key ] == $value ) { // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual -- Callers may pass numeric strings or ints; keep loose match. $results[] = $array; } foreach ( $array as $sub_array ) { $results = array_merge( $results, cs_array_search( $sub_array, $key, $value ) ); } } return $results; } } if ( ! function_exists( 'cs_load_option_fields' ) ) { /** * Load options fields. */ function cs_load_option_fields() { $located_fields = array(); foreach ( glob( CS_DIR . '/fields/*/*.php' ) as $cs_field ) { $located_fields[] = basename( $cs_field ); cs_locate_template( str_replace( CS_DIR, '', $cs_field ) ); } $override_name = apply_filters( 'cs_framework_override', 'cs-framework-override' ); $override_dir = get_template_directory() . '/' . $override_name . '/fields'; if ( is_dir( $override_dir ) ) { foreach ( glob( $override_dir . '/*/*.php' ) as $override_field ) { if ( ! in_array( basename( $override_field ), $located_fields, true ) ) { cs_locate_template( str_replace( $override_dir, '/fields', $override_field ) ); } } } do_action( 'cs_load_option_fields' ); } }