$option_name = $split[0]; $option_settings = $option_settings_list[ $option_name ] = vc_param_options_get_settings( $option_name, $settings['options'] ); if ( isset( $option_settings['type'] ) && 'checkbox' === $option_settings['type'] ) { $option_value = array_map( 'vc_param_options_parse_values', preg_split( '/\,/', $split[1] ) ); } else { $option_value = rawurldecode( $split[1] ); } $options[ $option_name ] = $option_value; } } if ( isset( $settings['options'] ) ) { foreach ( $settings['options'] as $setting_option ) { if ( 'separator' !== $setting_option['type'] && isset( $setting_option['value'] ) && empty( $options[ $setting_option['name'] ] ) ) { $options[ $setting_option['name'] ] = 'checkbox' === $setting_option['type'] ? preg_split( '/\,/', $setting_option['value'] ) : $setting_option['value']; } if ( isset( $setting_option['name'] ) && isset( $options[ $setting_option['name'] ] ) && isset( $setting_option['value_type'] ) ) { if ( 'integer' === $setting_option['value_type'] ) { $options[ $setting_option['name'] ] = (int) $options[ $setting_option['name'] ]; } elseif ( 'float' === $setting_option['value_type'] ) { $options[ $setting_option['name'] ] = (float) $options[ $setting_option['name'] ]; } elseif ( 'boolean' === $setting_option['value_type'] ) { $options[ $setting_option['name'] ] = (boolean) $options[ $setting_option['name'] ]; } } } } return $options; } /** * Convert string to a valid css class name. * * @since 4.3 * * @param string $class * * @return string */ function vc_build_safe_css_class( $class ) { return preg_replace( '/\W+/', '', strtolower( str_replace( ' ', '_', strip_tags( $class ) ) ) ); } /** * Include template from templates dir. * * @since 4.3 * * @param $template * @param array $variables - passed variables to the template. * * @param bool $once * * @return mixed */ function vc_include_template( $template, $variables = array(), $once = false ) { is_array( $variables ) && extract( $variables ); if ( $once ) { return require_once vc_template( $template ); } else { return require vc_template( $template ); } } /** * Output template from templates dir. * * @since 4.4 * * @param $template * @param array $variables - passed variables to the template. * * @param bool $once * * @return string */ function vc_get_template( $template, $variables = array(), $once = false ) { ob_start(); vc_include_template( $template, $variables, $once ); return ob_get_clean(); } /** * if php version < 5.3 this function is required. */ if ( ! function_exists( 'lcfirst' ) ) { /** * @param $str * * @since 4.3, fix #1093 * @return mixed */ function lcfirst( $str ) { $str[0] = function_exists( 'mb_strtolower' ) ? mb_strtolower( $str[0] ) : strtolower( $str[0] ); return $str; } } /** * VC Convert a value to studly caps case. * * @since 4.3 * * @param string $value * * @return string */ function vc_studly( $value ) { $value = ucwords( str_replace( array( '-', '_', ), ' ', $value ) ); return str_replace( ' ', '', $value ); } /** * VC Convert a value to camel case. * * @since 4.3 * * @param string $value * * @return string */ function vc_camel_case( $value ) { return lcfirst( vc_studly( $value ) ); } /** * Enqueue icon element font * @todo move to separate folder * @since 4.4 * * @param $font */ function vc_icon_element_fonts_enqueue( $font ) { switch ( $font ) { case 'fontawesome': wp_enqueue_style( 'font-awesome' ); break; case 'openiconic': wp_enqueue_style( 'vc_openiconic' ); break; case 'typicons': wp_enqueue_style( 'vc_typicons' ); break; case 'entypo': wp_enqueue_style( 'vc_entypo' ); break; case 'linecons': wp_enqueue_style( 'vc_linecons' ); break; case 'monosocial': wp_enqueue_style( 'vc_monosocialiconsfont' ); break; case 'material': wp_enqueue_style( 'vc_material' ); break; default: do_action( 'vc_enqueue_font_icon_element', $font ); // hook to custom do enqueue style } } /** * Function merges defaults attributes in attributes by keeping it values * * Example * array defaults | array attributes | result array * 'color'=>'black', - 'color'=>'black', * 'target'=>'_self', 'target'=>'_blank', 'target'=>'_blank', * - 'link'=>'google.com' 'link'=>'google.com' * * @since 4.4 * * @param array $defaults * @param array $attributes * * @return array - merged attributes * * @see vc_map_get_attributes */ function vc_shortcode_attribute_parse( $defaults = array(), $attributes = array() ) { $atts = $attributes + shortcode_atts( $defaults, $attributes ); return $atts; } function vc_get_shortcode_regex( $tagregexp = '' ) { if ( 0 === strlen( $tagregexp ) ) { return get_shortcode_regex(); } return '\\[' // Opening bracket . '(\\[?)' // 1: Optional second opening bracket for escaping shortcodes: [[tag]] . "($tagregexp)" // 2: Shortcode name . '(?![\\w-])' // Not followed by word character or hyphen . '(' // 3: Unroll the loop: Inside the opening shortcode tag . '[^\\]\\/]*' // Not a closing bracket or forward slash . '(?:' . '\\/(?!\\])' // A forward slash not followed by a closing bracket . '[^\\]\\/]*' // Not a closing bracket or forward slash . ')*?' . ')' . '(?:' . '(\\/)' // 4: Self closing tag ... . '\\]' // ... and closing bracket . '|' . '\\]' // Closing bracket . '(?:' . '(' // 5: Unroll the loop: Optionally, anything between the opening and closing shortcode tags . '[^\\[]*+' // Not an opening bracket . '(?:' . '\\[(?!\\/\\2\\])' // An opening bracket not followed by the closing shortcode tag . '[^\\[]*+' // Not an opening bracket . ')*+' . ')' . '\\[\\/\\2\\]' // Closing shortcode tag . ')?' . ')' . '(\\]?)'; } /** * Used to send warning message * * @since 4.5 * * @param $message * * @return string */ function vc_message_warning( $message ) { return '

' . $message . '

'; } /** * Extract video ID from youtube url * * @param string $url Youtube url * * @return string */ function vc_extract_youtube_id( $url ) { parse_str( parse_url( $url, PHP_URL_QUERY ), $vars ); if ( ! isset( $vars['v'] ) ) { return ''; } return $vars['v']; } function vc_taxonomies_types() { global $vc_taxonomies_types; if ( is_null( $vc_taxonomies_types ) ) { $vc_taxonomies_types = get_taxonomies( array( 'public' => true ), 'objects' ); } return $vc_taxonomies_types; } /** * Since * * @since 4.5.3 * * @param $term * * @return array */ function vc_get_term_object( $term ) { $vc_taxonomies_types = vc_taxonomies_types(); return array( 'label' => $term->name, 'value' => $term->term_id, 'group_id' => $term->taxonomy, 'group' => isset( $vc_taxonomies_types[ $term->taxonomy ], $vc_taxonomies_types[ $term->taxonomy ]->labels, $vc_taxonomies_types[ $term->taxonomy ]->labels->name ) ? $vc_taxonomies_types[ $term->taxonomy ]->labels->name : __( 'Taxonomies', 'js_composer' ), ); } /** * Extract width/height from string * * @param string $dimensions WxH * * @since 4.7 * * @return mixed array(width, height) or false */ function vcExtractDimensions( $dimensions ) { $dimensions = str_replace( ' ', '', $dimensions ); $matches = null; if ( preg_match( '/(\d+)x(\d+)/', $dimensions, $matches ) ) { return array( $matches[1], $matches[2], ); } return false; } /** * Check if element has specific class * * E.g. f('foo', 'foo bar baz') -> true * * @param string $class Class to check for * @param string $classes Classes separated by space(s) * * @return bool */ function vc_has_class( $class, $classes ) { return in_array( $class, explode( ' ', strtolower( $classes ) ) ); } /** * Remove specific class from classes string * * E.g. f('foo', 'foo bar baz') -> 'bar baz' * * @param string $class Class to remove * @param string $classes Classes separated by space(s) * * @return string */ function vc_remove_class( $class, $classes ) { $list_classes = explode( ' ', strtolower( $classes ) ); $key = array_search( $class, $list_classes, true ); if ( false === $key ) { return $classes; } unset( $list_classes[ $key ] ); return implode( ' ', $list_classes ); } /** * Convert array of named params to string version * All values will be escaped * * E.g. f(array('name' => 'foo', 'id' => 'bar')) -> 'name="foo" id="bar"' * * @param $attributes * * @return string */ function vc_stringify_attributes( $attributes ) { $atts = array(); foreach ( $attributes as $name => $value ) { $atts[] = $name . '="' . esc_attr( $value ) . '"'; } return implode( ' ', $atts ); } function vc_is_responsive_disabled() { $disable_responsive = vc_settings()->get( 'not_responsive_css' ); return '1' === $disable_responsive; } /** * Do shortcode single render point * * @param $atts * @param null $content * @param null $tag * * @return string */ function vc_do_shortcode( $atts, $content = null, $tag = null ) { return Vc_Shortcodes_Manager::getInstance()->getElementClass( $tag )->output( $atts, $content ); } /** * Return random string * * @param int $length * * @return string */ function vc_random_string( $length = 10 ) { $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $len = strlen( $characters ); $str = ''; for ( $i = 0; $i < $length; $i ++ ) { $str .= $characters[ rand( 0, $len - 1 ) ]; } return $str; } function vc_slugify( $str ) { $str = strtolower( $str ); $str = html_entity_decode( $str ); $str = preg_replace( '/[^\w ]+/', '', $str ); $str = preg_replace( '/ +/', '-', $str ); return $str; }