This commit is contained in:
KhaiNguyen
2020-02-13 10:39:37 +07:00
commit 59401cb805
12867 changed files with 4646216 additions and 0 deletions

View File

@@ -0,0 +1,519 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
/**
* Author: Arlo Carreon <http://arlocarreon.com>
* Info: http://mexitek.github.io/phpColors/
* License: http://arlo.mit-license.org/
*
* @modified by js_composer
* @since 4.8
*/
class Vc_Color_Helper {
/**
* A color utility that helps manipulate HEX colors
* @var string
*/
private $hex;
private $hsl;
private $rgb;
/**
* Auto darkens/lightens by 10% for sexily-subtle gradients.
* Set this to FALSE to adjust automatic shade to be between given color
* and black (for darken) or white (for lighten)
*/
const DEFAULT_ADJUST = 10;
/**
* Instantiates the class with a HEX value
*
* @param string $hex
*
* @throws Exception "Bad color format".
*/
public function __construct( $hex ) {
// Strip # sign is present
$color = str_replace( '#', '', $hex );
// Make sure it's 6 digits
if ( strlen( $color ) === 3 ) {
$color = $color[0] . $color[0] . $color[1] . $color[1] . $color[2] . $color[2];
} elseif ( strlen( $color ) !== 6 ) {
throw new Exception( 'HEX color needs to be 6 or 3 digits long' );
}
$this->hsl = self::hexToHsl( $color );
$this->hex = $color;
$this->rgb = self::hexToRgb( $color );
}
/**
* @param $val
* @param int $max
* @return mixed
*/
public static function clamp( $val, $max = 1 ) {
return min( max( $val, 0 ), $max );
}
// ====================
// = Public Interface =
// ====================
/**
* Given a HEX string returns a HSL array equivalent.
*
* @param string $color
*
* @return array HSL associative array
* @throws \Exception
*/
public static function hexToHsl( $color ) {
// Sanity check
$color = self::check_hex_private( $color );
// Convert HEX to DEC
$R = hexdec( $color[0] . $color[1] );
$G = hexdec( $color[2] . $color[3] );
$B = hexdec( $color[4] . $color[5] );
$HSL = array();
$var_R = ( $R / 255.0 );
$var_G = ( $G / 255.0 );
$var_B = ( $B / 255.0 );
$var_Min = min( $var_R, $var_G, $var_B );
$var_Max = max( $var_R, $var_G, $var_B );
$del_Max = floatval( $var_Max - $var_Min );
$L = ( $var_Max + $var_Min ) / 2.0;
$H = 0.0;
$S = 0.0;
if ( $del_Max > 0 ) {
if ( $L < 0.5 ) {
$S = $del_Max / ( $var_Max + $var_Min );
} else {
$S = $del_Max / ( 2 - $var_Max - $var_Min );
}
switch ( $var_Max ) {
case $var_R:
$H = ( $var_G - $var_B ) / $del_Max + ( $var_G < $var_B ? 6 : 0 );
break;
case $var_G:
$H = ( $var_B - $var_R ) / $del_Max + 2;
break;
case $var_B:
$H = ( $var_R - $var_G ) / $del_Max + 4;
break;
}
$H /= 6;
}
$HSL['H'] = ( $H * 360.0 );
$HSL['S'] = $S;
$HSL['L'] = $L;
return $HSL;
}
/**
* Given a HSL associative array returns the equivalent HEX string
*
* @param array $hsl
*
* @return string HEX string
* @throws Exception "Bad HSL Array".
*/
public static function hslToHex( $hsl = array() ) {
// Make sure it's HSL
if ( empty( $hsl ) || ! isset( $hsl['H'] ) || ! isset( $hsl['S'] ) || ! isset( $hsl['L'] ) ) {
throw new Exception( 'Param was not an HSL array' );
}
list( $H, $S, $L ) = array(
fmod( $hsl['H'], 360 ) / 360.0,
$hsl['S'],
$hsl['L'],
);
if ( ! $S ) {
$r = $L * 255.0;
$g = $L * 255.0;
$b = $L * 255.0;
} else {
if ( $L < 0.5 ) {
$var_2 = $L * ( 1.0 + $S );
} else {
$var_2 = ( $L + $S ) - ( $S * $L );
}
$var_1 = 2.0 * $L - $var_2;
$r = self::clamp( round( 255.0 * self::huetorgb_private( $var_1, $var_2, $H + ( 1 / 3 ) ) ), 255 );
$g = self::clamp( round( 255.0 * self::huetorgb_private( $var_1, $var_2, $H ) ), 255 );
$b = self::clamp( round( 255.0 * self::huetorgb_private( $var_1, $var_2, $H - ( 1 / 3 ) ) ), 255 );
}
// Convert to hex
$r = dechex( $r );
$g = dechex( $g );
$b = dechex( $b );
// Make sure we get 2 digits for decimals
$r = ( strlen( '' . $r ) === 1 ) ? '0' . $r : $r;
$g = ( strlen( '' . $g ) === 1 ) ? '0' . $g : $g;
$b = ( strlen( '' . $b ) === 1 ) ? '0' . $b : $b;
return $r . $g . $b;
}
/**
* Given a HEX string returns a RGB array equivalent.
*
* @param string $color
*
* @return array RGB associative array
* @throws \Exception
*/
public static function hexToRgb( $color ) {
// Sanity check
$color = self::check_hex_private( $color );
// Convert HEX to DEC
$R = hexdec( $color[0] . $color[1] );
$G = hexdec( $color[2] . $color[3] );
$B = hexdec( $color[4] . $color[5] );
$RGB['R'] = $R;
$RGB['G'] = $G;
$RGB['B'] = $B;
return $RGB;
}
/**
* Given an RGB associative array returns the equivalent HEX string
*
* @param array $rgb
*
* @return string RGB string
* @throws Exception "Bad RGB Array".
*/
public static function rgbToHex( $rgb = array() ) {
// Make sure it's RGB
if ( empty( $rgb ) || ! isset( $rgb['R'] ) || ! isset( $rgb['G'] ) || ! isset( $rgb['B'] ) ) {
throw new Exception( 'Param was not an RGB array' );
}
// Convert RGB to HEX
$hex[0] = dechex( $rgb['R'] );
if ( 1 === strlen( $hex[0] ) ) {
$hex[0] .= $hex[0];
}
$hex[1] = dechex( $rgb['G'] );
if ( 1 === strlen( $hex[1] ) ) {
$hex[1] .= $hex[1];
}
$hex[2] = dechex( $rgb['B'] );
if ( 1 === strlen( $hex[2] ) ) {
$hex[2] .= $hex[2];
}
return implode( '', $hex );
}
/**
* Given a HEX value, returns a darker color. If no desired amount provided, then the color halfway between
* given HEX and black will be returned.
*
* @param int $amount
*
* @return string Darker HEX value
* @throws \Exception
*/
public function darken( $amount = self::DEFAULT_ADJUST ) {
// Darken
$darkerHSL = $this->darken_private( $this->hsl, $amount );
// Return as HEX
return self::hslToHex( $darkerHSL );
}
/**
* Given a HEX value, returns a lighter color. If no desired amount provided, then the color halfway between
* given HEX and white will be returned.
*
* @param int $amount
*
* @return string Lighter HEX value
* @throws \Exception.
*/
public function lighten( $amount = self::DEFAULT_ADJUST ) {
// Lighten
$lighterHSL = $this->lighten_private( $this->hsl, $amount );
// Return as HEX
return self::hslToHex( $lighterHSL );
}
/**
* Given a HEX value, returns a mixed color. If no desired amount provided, then the color mixed by this ratio
*
* @param string $hex2 Secondary HEX value to mix with
* @param int $amount = -100..0..+100
*
* @return string mixed HEX value
* @throws \Exception
*/
public function mix( $hex2, $amount = 0 ) {
$rgb2 = self::hexToRgb( $hex2 );
$mixed = $this->mix_private( $this->rgb, $rgb2, $amount );
// Return as HEX
return self::rgbToHex( $mixed );
}
/**
* Creates an array with two shades that can be used to make a gradient
*
* @param int $amount Optional percentage amount you want your contrast color
*
* @return array An array with a 'light' and 'dark' index
* @throws \Exception
*/
public function makeGradient( $amount = self::DEFAULT_ADJUST ) {
// Decide which color needs to be made
if ( $this->isLight() ) {
$lightColor = $this->hex;
$darkColor = $this->darken( $amount );
} else {
$lightColor = $this->lighten( $amount );
$darkColor = $this->hex;
}
// Return our gradient array
return array(
'light' => $lightColor,
'dark' => $darkColor,
);
}
/**
* Returns whether or not given color is considered "light"
*
* @param string|Boolean $color
*
* @return boolean
*/
public function isLight( $color = false ) {
// Get our color
$color = ( $color ) ? $color : $this->hex;
// Calculate straight from rbg
$r = hexdec( $color[0] . $color[1] );
$g = hexdec( $color[2] . $color[3] );
$b = hexdec( $color[4] . $color[5] );
return ( ( $r * 299 + $g * 587 + $b * 114 ) / 1000 > 130 );
}
/**
* Returns whether or not a given color is considered "dark"
*
* @param string|Boolean $color
*
* @return boolean
*/
public function isDark( $color = false ) {
// Get our color
$color = ( $color ) ? $color : $this->hex;
// Calculate straight from rbg
$r = hexdec( $color[0] . $color[1] );
$g = hexdec( $color[2] . $color[3] );
$b = hexdec( $color[4] . $color[5] );
return ( ( $r * 299 + $g * 587 + $b * 114 ) / 1000 <= 130 );
}
/**
* Returns the complimentary color
* @return string Complementary hex color
* @throws \Exception
*/
public function complementary() {
// Get our HSL
$hsl = $this->hsl;
// Adjust Hue 180 degrees
$hsl['H'] += ( $hsl['H'] > 180 ) ? - 180 : 180;
// Return the new value in HEX
return self::hslToHex( $hsl );
}
/**
* Returns your color's HSL array
*/
public function getHsl() {
return $this->hsl;
}
/**
* Returns your original color
*/
public function getHex() {
return $this->hex;
}
/**
* Returns your color's RGB array
*/
public function getRgb() {
return $this->rgb;
}
// ===========================
// = Private Functions Below =
// ===========================
/**
* Darkens a given HSL array
*
* @param array $hsl
* @param int $amount
*
* @return array $hsl
*/
private function darken_private( $hsl, $amount = self::DEFAULT_ADJUST ) {
// Check if we were provided a number
if ( $amount ) {
$hsl['L'] = ( $hsl['L'] * 100 ) - $amount;
$hsl['L'] = ( $hsl['L'] < 0 ) ? 0 : $hsl['L'] / 100;
} else {
// We need to find out how much to darken
$hsl['L'] = $hsl['L'] / 2;
}
return $hsl;
}
/**
* Lightens a given HSL array
*
* @param array $hsl
* @param int $amount
*
* @return array $hsl
*/
private function lighten_private( $hsl, $amount = self::DEFAULT_ADJUST ) {
// Check if we were provided a number
if ( $amount ) {
$hsl['L'] = ( $hsl['L'] * 100.0 ) + $amount;
$hsl['L'] = ( $hsl['L'] > 100.0 ) ? 1.0 : $hsl['L'] / 100.0;
} else {
// We need to find out how much to lighten
$hsl['L'] += ( 1.0 - $hsl['L'] ) / 2.0;
}
return $hsl;
}
/**
* Mix 2 rgb colors and return an rgb color
*
* @param array $rgb1
* @param array $rgb2
* @param int $amount ranged -100..0..+100
*
* @return array $rgb
*
* ported from http://phpxref.pagelines.com/nav.html?includes/class.colors.php.source.html
*/
private function mix_private( $rgb1, $rgb2, $amount = 0 ) {
$r1 = ( $amount + 100 ) / 100;
$r2 = 2 - $r1;
$rmix = ( ( $rgb1['R'] * $r1 ) + ( $rgb2['R'] * $r2 ) ) / 2;
$gmix = ( ( $rgb1['G'] * $r1 ) + ( $rgb2['G'] * $r2 ) ) / 2;
$bmix = ( ( $rgb1['B'] * $r1 ) + ( $rgb2['B'] * $r2 ) ) / 2;
return array(
'R' => $rmix,
'G' => $gmix,
'B' => $bmix,
);
}
/**
* Given a Hue, returns corresponding RGB value
*
* @param int $v1
* @param int $v2
* @param int $vH
*
* @return int
*/
private static function huetorgb_private( $v1, $v2, $vH ) {
if ( $vH < 0 ) {
$vH ++;
}
if ( $vH > 1 ) {
$vH --;
}
if ( ( 6 * $vH ) < 1 ) {
return ( $v1 + ( $v2 - $v1 ) * 6 * $vH );
}
if ( ( 2 * $vH ) < 1 ) {
return $v2;
}
if ( ( 3 * $vH ) < 2 ) {
return ( $v1 + ( $v2 - $v1 ) * ( ( 2 / 3 ) - $vH ) * 6 );
}
return $v1;
}
/**
* You need to check if you were given a good hex string
*
* @param string $hex
*
* @return string Color
* @throws Exception "Bad color format".
*/
private static function check_hex_private( $hex ) {
// Strip # sign is present
$color = str_replace( '#', '', $hex );
// Make sure it's 6 digits
if ( strlen( $color ) === 3 ) {
$color = $color[0] . $color[0] . $color[1] . $color[1] . $color[2] . $color[2];
} elseif ( strlen( $color ) !== 6 ) {
throw new Exception( 'HEX color needs to be 6 or 3 digits long' );
}
return $color;
}
}

View File

@@ -0,0 +1,322 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
class vcImageFilter {
/**
* @var resource
*/
private $image;
/**
* run constructor
*
* @param resource &$image GD image resource
*/
public function __construct( &$image ) {
$this->image = $image;
}
/**
* Get the current image resource
*
* @return resource
*/
public function getImage() {
return $this->image;
}
public function sepia() {
imagefilter( $this->image, IMG_FILTER_GRAYSCALE );
imagefilter( $this->image, IMG_FILTER_COLORIZE, 100, 50, 0 );
return $this;
}
public function sepia2() {
imagefilter( $this->image, IMG_FILTER_GRAYSCALE );
imagefilter( $this->image, IMG_FILTER_BRIGHTNESS, - 10 );
imagefilter( $this->image, IMG_FILTER_CONTRAST, - 20 );
imagefilter( $this->image, IMG_FILTER_COLORIZE, 60, 30, - 15 );
return $this;
}
public function sharpen() {
$gaussian = array(
array(
1.0,
1.0,
1.0,
),
array(
1.0,
- 7.0,
1.0,
),
array(
1.0,
1.0,
1.0,
),
);
imageconvolution( $this->image, $gaussian, 1, 4 );
return $this;
}
public function emboss() {
$gaussian = array(
array(
- 2.0,
- 1.0,
0.0,
),
array(
- 1.0,
1.0,
1.0,
),
array(
0.0,
1.0,
2.0,
),
);
imageconvolution( $this->image, $gaussian, 1, 5 );
return $this;
}
public function cool() {
imagefilter( $this->image, IMG_FILTER_MEAN_REMOVAL );
imagefilter( $this->image, IMG_FILTER_CONTRAST, - 50 );
return $this;
}
public function light() {
imagefilter( $this->image, IMG_FILTER_BRIGHTNESS, 10 );
imagefilter( $this->image, IMG_FILTER_COLORIZE, 100, 50, 0, 10 );
return $this;
}
public function aqua() {
imagefilter( $this->image, IMG_FILTER_COLORIZE, 0, 70, 0, 30 );
return $this;
}
public function fuzzy() {
$gaussian = array(
array(
1.0,
1.0,
1.0,
),
array(
1.0,
1.0,
1.0,
),
array(
1.0,
1.0,
1.0,
),
);
imageconvolution( $this->image, $gaussian, 9, 20 );
return $this;
}
public function boost() {
imagefilter( $this->image, IMG_FILTER_CONTRAST, - 35 );
imagefilter( $this->image, IMG_FILTER_BRIGHTNESS, 10 );
return $this;
}
public function gray() {
imagefilter( $this->image, IMG_FILTER_CONTRAST, - 60 );
imagefilter( $this->image, IMG_FILTER_GRAYSCALE );
return $this;
}
public function antique() {
imagefilter( $this->image, IMG_FILTER_BRIGHTNESS, 0 );
imagefilter( $this->image, IMG_FILTER_CONTRAST, - 30 );
imagefilter( $this->image, IMG_FILTER_COLORIZE, 75, 50, 25 );
return $this;
}
public function blackwhite() {
imagefilter( $this->image, IMG_FILTER_GRAYSCALE );
imagefilter( $this->image, IMG_FILTER_BRIGHTNESS, 10 );
imagefilter( $this->image, IMG_FILTER_CONTRAST, - 20 );
return $this;
}
public function boost2() {
imagefilter( $this->image, IMG_FILTER_CONTRAST, - 35 );
imagefilter( $this->image, IMG_FILTER_COLORIZE, 25, 25, 25 );
return $this;
}
public function blur() {
imagefilter( $this->image, IMG_FILTER_SELECTIVE_BLUR );
imagefilter( $this->image, IMG_FILTER_GAUSSIAN_BLUR );
imagefilter( $this->image, IMG_FILTER_CONTRAST, - 15 );
imagefilter( $this->image, IMG_FILTER_SMOOTH, - 2 );
return $this;
}
public function vintage() {
imagefilter( $this->image, IMG_FILTER_BRIGHTNESS, 10 );
imagefilter( $this->image, IMG_FILTER_GRAYSCALE );
imagefilter( $this->image, IMG_FILTER_COLORIZE, 40, 10, - 15 );
return $this;
}
public function concentrate() {
imagefilter( $this->image, IMG_FILTER_GAUSSIAN_BLUR );
imagefilter( $this->image, IMG_FILTER_SMOOTH, - 10 );
return $this;
}
public function hermajesty() {
imagefilter( $this->image, IMG_FILTER_BRIGHTNESS, - 10 );
imagefilter( $this->image, IMG_FILTER_CONTRAST, - 5 );
imagefilter( $this->image, IMG_FILTER_COLORIZE, 80, 0, 60 );
return $this;
}
public function everglow() {
imagefilter( $this->image, IMG_FILTER_BRIGHTNESS, - 30 );
imagefilter( $this->image, IMG_FILTER_CONTRAST, - 5 );
imagefilter( $this->image, IMG_FILTER_COLORIZE, 30, 30, 0 );
return $this;
}
public function freshblue() {
imagefilter( $this->image, IMG_FILTER_CONTRAST, - 5 );
imagefilter( $this->image, IMG_FILTER_COLORIZE, 20, 0, 80, 60 );
return $this;
}
public function tender() {
imagefilter( $this->image, IMG_FILTER_CONTRAST, 5 );
imagefilter( $this->image, IMG_FILTER_COLORIZE, 80, 20, 40, 50 );
imagefilter( $this->image, IMG_FILTER_COLORIZE, 0, 40, 40, 100 );
imagefilter( $this->image, IMG_FILTER_SELECTIVE_BLUR );
return $this;
}
public function dream() {
imagefilter( $this->image, IMG_FILTER_COLORIZE, 150, 0, 0, 50 );
imagefilter( $this->image, IMG_FILTER_NEGATE );
imagefilter( $this->image, IMG_FILTER_COLORIZE, 0, 50, 0, 50 );
imagefilter( $this->image, IMG_FILTER_NEGATE );
imagefilter( $this->image, IMG_FILTER_GAUSSIAN_BLUR );
return $this;
}
public function frozen() {
imagefilter( $this->image, IMG_FILTER_BRIGHTNESS, - 15 );
imagefilter( $this->image, IMG_FILTER_COLORIZE, 0, 0, 100, 50 );
imagefilter( $this->image, IMG_FILTER_COLORIZE, 0, 0, 100, 50 );
imagefilter( $this->image, IMG_FILTER_GAUSSIAN_BLUR );
return $this;
}
public function forest() {
imagefilter( $this->image, IMG_FILTER_COLORIZE, 0, 0, 150, 50 );
imagefilter( $this->image, IMG_FILTER_NEGATE );
imagefilter( $this->image, IMG_FILTER_COLORIZE, 0, 0, 150, 50 );
imagefilter( $this->image, IMG_FILTER_NEGATE );
imagefilter( $this->image, IMG_FILTER_SMOOTH, 10 );
return $this;
}
public function rain() {
imagefilter( $this->image, IMG_FILTER_GAUSSIAN_BLUR );
imagefilter( $this->image, IMG_FILTER_MEAN_REMOVAL );
imagefilter( $this->image, IMG_FILTER_NEGATE );
imagefilter( $this->image, IMG_FILTER_COLORIZE, 0, 80, 50, 50 );
imagefilter( $this->image, IMG_FILTER_NEGATE );
imagefilter( $this->image, IMG_FILTER_SMOOTH, 10 );
return $this;
}
public function orangepeel() {
imagefilter( $this->image, IMG_FILTER_COLORIZE, 100, 20, - 50, 20 );
imagefilter( $this->image, IMG_FILTER_SMOOTH, 10 );
imagefilter( $this->image, IMG_FILTER_BRIGHTNESS, - 10 );
imagefilter( $this->image, IMG_FILTER_CONTRAST, 10 );
imagegammacorrect( $this->image, 1, 1.2 );
return $this;
}
public function darken() {
imagefilter( $this->image, IMG_FILTER_GRAYSCALE );
imagefilter( $this->image, IMG_FILTER_BRIGHTNESS, - 50 );
return $this;
}
public function summer() {
imagefilter( $this->image, IMG_FILTER_COLORIZE, 0, 150, 0, 50 );
imagefilter( $this->image, IMG_FILTER_NEGATE );
imagefilter( $this->image, IMG_FILTER_COLORIZE, 25, 50, 0, 50 );
imagefilter( $this->image, IMG_FILTER_NEGATE );
return $this;
}
public function retro() {
imagefilter( $this->image, IMG_FILTER_GRAYSCALE );
imagefilter( $this->image, IMG_FILTER_COLORIZE, 100, 25, 25, 50 );
return $this;
}
public function country() {
imagefilter( $this->image, IMG_FILTER_BRIGHTNESS, - 30 );
imagefilter( $this->image, IMG_FILTER_COLORIZE, 50, 50, 50, 50 );
imagegammacorrect( $this->image, 1, 0.3 );
return $this;
}
public function washed() {
imagefilter( $this->image, IMG_FILTER_BRIGHTNESS, 30 );
imagefilter( $this->image, IMG_FILTER_NEGATE );
imagefilter( $this->image, IMG_FILTER_COLORIZE, - 50, 0, 20, 50 );
imagefilter( $this->image, IMG_FILTER_NEGATE );
imagefilter( $this->image, IMG_FILTER_BRIGHTNESS, 10 );
imagegammacorrect( $this->image, 1, 1.2 );
return $this;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,819 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
/**
* @param $attributes
* @return bool
* @throws \Exception
*/
function wpb_map( $attributes ) {
return vc_map( $attributes );
}
/**
* Lean map shortcodes
*
* @param $tag
* @param null $settings_function
* @param null $settings_file
* @since 4.9
*
*/
function vc_lean_map( $tag, $settings_function = null, $settings_file = null ) {
WPBMap::leanMap( $tag, $settings_function, $settings_file );
}
/**
* @param $attributes
*
* @return bool
* @throws \Exception
* @since 4.2
*/
function vc_map( $attributes ) {
if ( ! isset( $attributes['base'] ) ) {
throw new Exception( esc_html__( 'Wrong vc_map object. Base attribute is required', 'js_composer' ) );
}
return WPBMap::map( $attributes['base'], $attributes );
}
/**
* @param $shortcode
*
* @since 4.2
*/
function vc_remove_element( $shortcode ) {
WPBMap::dropShortcode( $shortcode );
}
/**
* Add new shortcode param.
*
* @param $shortcode - tag for shortcode
* @param $attributes - attribute settings
* @throws \Exception
* @since 4.2
*
*/
function vc_add_param( $shortcode, $attributes ) {
WPBMap::addParam( $shortcode, $attributes );
}
/**
* Mass shortcode params adding function
*
* @param $shortcode - tag for shortcode
* @param $attributes - list of attributes arrays
* @throws \Exception
* @since 4.3
*
*/
function vc_add_params( $shortcode, $attributes ) {
if ( is_array( $attributes ) ) {
foreach ( $attributes as $attr ) {
vc_add_param( $shortcode, $attr );
}
}
}
/**
* Shorthand function for WPBMap::modify
*
* @param string $name
* @param string $setting
* @param string $value
*
* @return array|bool
* @throws \Exception
* @since 4.2
*/
function vc_map_update( $name = '', $setting = '', $value = '' ) {
return WPBMap::modify( $name, $setting, $value );
}
/**
* Shorthand function for WPBMap::mutateParam
*
* @param $name
* @param array $attribute
*
* @return bool
* @throws \Exception
* @since 4.2
*/
function vc_update_shortcode_param( $name, $attribute = array() ) {
return WPBMap::mutateParam( $name, $attribute );
}
/**
* Shorthand function for WPBMap::dropParam
*
* @param $name
* @param $attribute_name
*
* @return bool
* @since 4.2
*/
function vc_remove_param( $name = '', $attribute_name = '' ) {
return WPBMap::dropParam( $name, $attribute_name );
}
if ( ! function_exists( 'vc_set_as_theme' ) ) {
/**
* Sets plugin as theme plugin.
*
* @internal param bool $disable_updater - If value is true disables auto updater options.
*
* @since 4.2
*/
function vc_set_as_theme() {
vc_manager()->setIsAsTheme( true );
}
}
if ( ! function_exists( 'vc_is_as_theme' ) ) {
/**
* Is VC as-theme-plugin.
* @return bool
* @since 4.2
*/
function vc_is_as_theme() {
return vc_manager()->isAsTheme();
}
}
if ( ! function_exists( 'vc_is_updater_disabled' ) ) {
/**
* @return bool
* @since 4.2
*/
function vc_is_updater_disabled() {
return vc_manager()->isUpdaterDisabled();
}
}
if ( ! function_exists( 'vc_default_editor_post_types' ) ) {
/**
* Returns list of default post type.
* @return array
* @since 4.2
*/
function vc_default_editor_post_types() {
return vc_manager()->editorDefaultPostTypes();
}
}
if ( ! function_exists( 'vc_set_default_editor_post_types' ) ) {
/**
* Set post types for VC editor.
* @param array $list - list of valid post types to set
* @since 4.2
*
*/
function vc_set_default_editor_post_types( array $list ) {
vc_manager()->setEditorDefaultPostTypes( $list );
}
}
if ( ! function_exists( ( 'vc_editor_post_types' ) ) ) {
/**
* Returns list of post types where VC editor is enabled.
* @return array
* @since 4.2
*/
function vc_editor_post_types() {
return vc_manager()->editorPostTypes();
}
}
if ( ! function_exists( ( 'vc_editor_set_post_types' ) ) ) {
/**
* Set list of post types where VC editor is enabled.
* @param array $post_types
* @throws \Exception
* @since 4.4
*
*/
function vc_editor_set_post_types( array $post_types ) {
vc_manager()->setEditorPostTypes( $post_types );
}
}
if ( ! function_exists( 'vc_mode' ) ) {
/**
* Return current VC mode.
* @return string
* @see Vc_Mapper::$mode
* @since 4.2
*/
function vc_mode() {
return vc_manager()->mode();
}
}
if ( ! function_exists( 'vc_set_shortcodes_templates_dir' ) ) {
/**
* Sets directory where WPBakery Page Builder should look for template files for content elements.
* @param string - full directory path to new template directory with trailing slash
* @since 4.2
*
*/
function vc_set_shortcodes_templates_dir( $dir ) {
vc_manager()->setCustomUserShortcodesTemplateDir( $dir );
}
}
if ( ! function_exists( 'vc_shortcodes_theme_templates_dir' ) ) {
/**
* Get custom theme template path
* @param $template - filename for template
*
* @return string
* @since 4.2
*
*/
function vc_shortcodes_theme_templates_dir( $template ) {
return vc_manager()->getShortcodesTemplateDir( $template );
}
}
/**
* @param bool $value
*
* @todo check usage.
*
* @since 4.3
*/
function set_vc_is_inline( $value = true ) {
_deprecated_function( 'set_vc_is_inline', '5.2 (will be removed in 5.3)' );
global $vc_is_inline;
$vc_is_inline = $value;
}
/**
* Disable frontend editor for VC
* @param bool $disable
* @since 4.3
*
*/
function vc_disable_frontend( $disable = true ) {
vc_frontend_editor()->disableInline( $disable );
}
/**
* Check is front end enabled.
* @return bool
* @throws \Exception
* @since 4.3
*/
function vc_enabled_frontend() {
return vc_frontend_editor()->frontendEditorEnabled();
}
if ( ! function_exists( 'vc_add_default_templates' ) ) {
/**
* Add custom template in default templates list
*
* @param array $data | template data (name, content, custom_class, image_path)
*
* @return bool
* @since 4.3
*/
function vc_add_default_templates( $data ) {
return visual_composer()->templatesPanelEditor()->addDefaultTemplates( $data );
}
}
/**
* @param $shortcode
* @param string $field_prefix
* @param string $group_prefix
* @param null $change_fields
* @param null $dependency
* @return array
* @throws \Exception
*/
function vc_map_integrate_shortcode( $shortcode, $field_prefix = '', $group_prefix = '', $change_fields = null, $dependency = null ) {
if ( is_string( $shortcode ) ) {
$shortcode_data = WPBMap::getShortCode( $shortcode );
} else {
$shortcode_data = $shortcode;
}
if ( is_array( $shortcode_data ) && ! empty( $shortcode_data ) ) {
/**
* @var WPBakeryShortCodeFishBones $shortcode
*/
$params = isset( $shortcode_data['params'] ) && ! empty( $shortcode_data['params'] ) ? $shortcode_data['params'] : false;
if ( is_array( $params ) && ! empty( $params ) ) {
$keys = array_keys( $params );
$count = count( $keys );
for ( $i = 0; $i < $count; $i ++ ) {
$param = &$params[ $keys[ $i ] ]; // Note! passed by reference to automatically update data
if ( isset( $change_fields ) ) {
$param = vc_map_integrate_include_exclude_fields( $param, $change_fields );
if ( empty( $param ) ) {
continue;
}
}
if ( ! empty( $group_prefix ) ) {
if ( isset( $param['group'] ) ) {
$param['group'] = $group_prefix . ': ' . $param['group'];
} else {
$param['group'] = $group_prefix;
}
}
if ( ! empty( $field_prefix ) && isset( $param['param_name'] ) ) {
$param['param_name'] = $field_prefix . $param['param_name'];
if ( isset( $param['dependency'] ) && is_array( $param['dependency'] ) && isset( $param['dependency']['element'] ) ) {
$param['dependency']['element'] = $field_prefix . $param['dependency']['element'];
}
$param = vc_map_integrate_add_dependency( $param, $dependency );
} elseif ( ! empty( $dependency ) ) {
$param = vc_map_integrate_add_dependency( $param, $dependency );
}
$param['integrated_shortcode'] = is_array( $shortcode ) ? $shortcode['base'] : $shortcode;
$param['integrated_shortcode_field'] = $field_prefix;
}
}
return is_array( $params ) ? array_filter( $params ) : array();
}
return array();
}
/**
* Used to filter params (include/exclude)
*
* @param $param
* @param $change_fields
*
* @return array|null
* @internal
*
*/
function vc_map_integrate_include_exclude_fields( $param, $change_fields ) {
if ( is_array( $change_fields ) ) {
if ( isset( $change_fields['exclude'] ) && in_array( $param['param_name'], $change_fields['exclude'], true ) ) {
$param = null;
return $param; // to prevent group adding to $param
} elseif ( isset( $change_fields['exclude_regex'] ) ) {
if ( is_array( $change_fields['exclude_regex'] ) && ! empty( $change_fields['exclude_regex'] ) ) {
$break_foreach = false;
foreach ( $change_fields['exclude_regex'] as $regex ) {
/** @noinspection PhpUsageOfSilenceOperatorInspection */
// @codingStandardsIgnoreLine
if ( @preg_match( $regex, null ) ) {
if ( preg_match( $regex, $param['param_name'] ) ) {
$param = null;
$break_foreach = true;
}
}
if ( $break_foreach ) {
break;
}
}
if ( $break_foreach ) {
return $param; // to prevent group adding to $param
}
} elseif ( is_string( $change_fields['exclude_regex'] ) && strlen( $change_fields['exclude_regex'] ) > 0 ) {
/** @noinspection PhpUsageOfSilenceOperatorInspection */
// @codingStandardsIgnoreLine
if ( @preg_match( $change_fields['exclude_regex'], null ) ) {
if ( preg_match( $change_fields['exclude_regex'], $param['param_name'] ) ) {
$param = null;
return $param; // to prevent group adding to $param
}
}
}
}
if ( isset( $change_fields['include_only'] ) && ! in_array( $param['param_name'], $change_fields['include_only'], true ) ) {
// if we want to enclude only some fields
$param = null;
return $param; // to prevent group adding to $param
} elseif ( isset( $change_fields['include_only_regex'] ) ) {
if ( is_array( $change_fields['include_only_regex'] ) && ! empty( $change_fields['include_only_regex'] ) ) {
$break_foreach = false;
foreach ( $change_fields['include_only_regex'] as $regex ) {
/** @noinspection PhpUsageOfSilenceOperatorInspection */
// @codingStandardsIgnoreLine
if ( false === @preg_match( $regex, null ) ) {
// Regular expression is invalid, (don't remove @).
} else {
if ( ! preg_match( $regex, $param['param_name'] ) ) {
$param = null;
$break_foreach = true;
}
}
if ( $break_foreach ) {
break;
}
}
if ( $break_foreach ) {
return $param; // to prevent group adding to $param
}
} elseif ( is_string( $change_fields['include_only_regex'] ) && strlen( $change_fields['include_only_regex'] ) > 0 ) {
/** @noinspection PhpUsageOfSilenceOperatorInspection */
// @codingStandardsIgnoreLine
if ( false === @preg_match( $change_fields['include_only_regex'], null ) ) {
// Regular expression is invalid, (don't remove @).
} else {
if ( ! preg_match( $change_fields['include_only_regex'], $param['param_name'] ) ) {
$param = null;
return $param; // to prevent group adding to $param
}
}
}
}
}
return $param;
}
/**
* @param $param
* @param $dependency
*
* @return array
* @internal used to add dependency to existed param
*
*/
function vc_map_integrate_add_dependency( $param, $dependency ) {
// activator must be used for all elements who doesn't have 'dependency'
if ( ! empty( $dependency ) && ( ! isset( $param['dependency'] ) || empty( $param['dependency'] ) ) ) {
if ( is_array( $dependency ) ) {
$param['dependency'] = $dependency;
}
}
return $param;
}
/**
* @param $base_shortcode
* @param $integrated_shortcode
* @param string $field_prefix
* @return array
* @throws \Exception
*/
function vc_map_integrate_get_params( $base_shortcode, $integrated_shortcode, $field_prefix = '' ) {
$shortcode_data = WPBMap::getShortCode( $base_shortcode );
$params = array();
if ( is_array( $shortcode_data ) && is_array( $shortcode_data['params'] ) && ! empty( $shortcode_data['params'] ) ) {
foreach ( $shortcode_data['params'] as $param ) {
if ( is_array( $param ) && isset( $param['integrated_shortcode'] ) && $integrated_shortcode === $param['integrated_shortcode'] ) {
if ( ! empty( $field_prefix ) ) {
if ( isset( $param['integrated_shortcode_field'] ) && $field_prefix === $param['integrated_shortcode_field'] ) {
$params[] = $param;
}
} else {
$params[] = $param;
}
}
}
}
return $params;
}
/**
* @param $base_shortcode
* @param $integrated_shortcode
* @param string $field_prefix
* @return array
* @throws \Exception
*/
function vc_map_integrate_get_atts( $base_shortcode, $integrated_shortcode, $field_prefix = '' ) {
$params = vc_map_integrate_get_params( $base_shortcode, $integrated_shortcode, $field_prefix );
$atts = array();
if ( is_array( $params ) && ! empty( $params ) ) {
foreach ( $params as $param ) {
$value = '';
if ( isset( $param['value'] ) ) {
if ( isset( $param['std'] ) ) {
$value = $param['std'];
} elseif ( is_array( $param['value'] ) ) {
reset( $param['value'] );
$value = current( $param['value'] );
} else {
$value = $param['value'];
}
}
$atts[ $param['param_name'] ] = $value;
}
}
return $atts;
}
/**
* @param $base_shortcode
* @param $integrated_shortcode
* @param $atts
* @param string $field_prefix
* @return array
* @throws \Exception
*/
function vc_map_integrate_parse_atts( $base_shortcode, $integrated_shortcode, $atts, $field_prefix = '' ) {
$params = vc_map_integrate_get_params( $base_shortcode, $integrated_shortcode, $field_prefix );
$data = array();
if ( is_array( $params ) && ! empty( $params ) ) {
foreach ( $params as $param ) {
if ( isset( $atts[ $param['param_name'] ] ) ) {
$value = $atts[ $param['param_name'] ];
}
if ( isset( $value ) ) {
$key = $param['param_name'];
if ( strlen( $field_prefix ) > 0 ) {
$key = substr( $key, strlen( $field_prefix ) );
}
$data[ $key ] = $value;
}
}
}
return $data;
}
/**
* @param bool $label
* @return mixed|void
*/
function vc_map_add_css_animation( $label = true ) {
$data = array(
'type' => 'animation_style',
'heading' => esc_html__( 'CSS Animation', 'js_composer' ),
'param_name' => 'css_animation',
'admin_label' => $label,
'value' => '',
'settings' => array(
'type' => 'in',
'custom' => array(
array(
'label' => esc_html__( 'Default', 'js_composer' ),
'values' => array(
esc_html__( 'Top to bottom', 'js_composer' ) => 'top-to-bottom',
esc_html__( 'Bottom to top', 'js_composer' ) => 'bottom-to-top',
esc_html__( 'Left to right', 'js_composer' ) => 'left-to-right',
esc_html__( 'Right to left', 'js_composer' ) => 'right-to-left',
esc_html__( 'Appear from center', 'js_composer' ) => 'appear',
),
),
),
),
'description' => esc_html__( 'Select type of animation for element to be animated when it "enters" the browsers viewport (Note: works only in modern browsers).', 'js_composer' ),
);
return apply_filters( 'vc_map_add_css_animation', $data, $label );
}
/**
* Get settings of the mapped shortcode.
*
* @param $tag
*
* @return array|null - settings or null if shortcode not mapped
* @throws \Exception
* @since 4.4.3
*/
function vc_get_shortcode( $tag ) {
return WPBMap::getShortCode( $tag );
}
/**
* Remove all mapped shortcodes and the moment when function is called.
*
* @since 4.5
*/
function vc_remove_all_elements() {
WPBMap::dropAllShortcodes();
}
/**
* Function to get defaults values for shortcode.
* @param $tag - shortcode tag
*
* @return array - list of param=>default_value
* @throws \Exception
* @since 4.6
*
*/
function vc_map_get_defaults( $tag ) {
$shortcode = vc_get_shortcode( $tag );
$params = array();
if ( is_array( $shortcode ) && isset( $shortcode['params'] ) && ! empty( $shortcode['params'] ) ) {
$params = vc_map_get_params_defaults( $shortcode['params'] );
}
return $params;
}
/**
* @param $params
*
* @return array
* @since 4.12
*/
function vc_map_get_params_defaults( $params ) {
$resultParams = array();
foreach ( $params as $param ) {
if ( isset( $param['param_name'] ) && 'content' !== $param['param_name'] ) {
$value = '';
if ( isset( $param['std'] ) ) {
$value = $param['std'];
} elseif ( isset( $param['value'] ) ) {
if ( is_array( $param['value'] ) ) {
$value = current( $param['value'] );
if ( is_array( $value ) ) {
// in case if two-dimensional array provided (vc_basic_grid)
$value = current( $value );
}
// return first value from array (by default)
} else {
$value = $param['value'];
}
}
$resultParams[ $param['param_name'] ] = apply_filters( 'vc_map_get_param_defaults', $value, $param );
}
}
return $resultParams;
}
/**
* @param $tag - shortcode tag3
* @param array $atts - shortcode attributes
*
* @return array - return merged values with provided attributes (
* 'a'=>1,'b'=>2 + 'b'=>3,'c'=>4 --> 'a'=>1,'b'=>3 )
*
* @throws \Exception
* @see vc_shortcode_attribute_parse - return union of provided attributes (
* 'a'=>1,'b'=>2 + 'b'=>3,'c'=>4 --> 'a'=>1,
* 'b'=>3, 'c'=>4 )
*/
function vc_map_get_attributes( $tag, $atts = array() ) {
$atts = shortcode_atts( vc_map_get_defaults( $tag ), $atts, $tag );
return apply_filters( 'vc_map_get_attributes', $atts, $tag );
}
/**
* @param $name
* @return mixed|string
*/
function vc_convert_vc_color( $name ) {
$colors = array(
'blue' => '#5472d2',
'turquoise' => '#00c1cf',
'pink' => '#fe6c61',
'violet' => '#8d6dc4',
'peacoc' => '#4cadc9',
'chino' => '#cec2ab',
'mulled-wine' => '#50485b',
'vista-blue' => '#75d69c',
'orange' => '#f7be68',
'sky' => '#5aa1e3',
'green' => '#6dab3c',
'juicy-pink' => '#f4524d',
'sandy-brown' => '#f79468',
'purple' => '#b97ebb',
'black' => '#2a2a2a',
'grey' => '#ebebeb',
'white' => '#ffffff',
);
$name = str_replace( '_', '-', $name );
if ( isset( $colors[ $name ] ) ) {
return $colors[ $name ];
}
return '';
}
/**
* Extract width/height from string
*
* @param string $dimensions WxH
*
* @return mixed array(width, height) or false
* @since 4.7
*
*/
function vc_extract_dimensions( $dimensions ) {
$dimensions = str_replace( ' ', '', $dimensions );
$matches = null;
if ( preg_match( '/(\d+)x(\d+)/', $dimensions, $matches ) ) {
return array(
$matches[1],
$matches[2],
);
}
return false;
}
/**
* @param string $asset
*
* @return array|string
*/
function vc_get_shared( $asset = '' ) {
switch ( $asset ) {
case 'colors':
$asset = VcSharedLibrary::getColors();
break;
case 'colors-dashed':
$asset = VcSharedLibrary::getColorsDashed();
break;
case 'icons':
$asset = VcSharedLibrary::getIcons();
break;
case 'sizes':
$asset = VcSharedLibrary::getSizes();
break;
case 'button styles':
case 'alert styles':
$asset = VcSharedLibrary::getButtonStyles();
break;
case 'message_box_styles':
$asset = VcSharedLibrary::getMessageBoxStyles();
break;
case 'cta styles':
$asset = VcSharedLibrary::getCtaStyles();
break;
case 'text align':
$asset = VcSharedLibrary::getTextAlign();
break;
case 'cta widths':
case 'separator widths':
$asset = VcSharedLibrary::getElementWidths();
break;
case 'separator styles':
$asset = VcSharedLibrary::getSeparatorStyles();
break;
case 'separator border widths':
$asset = VcSharedLibrary::getBorderWidths();
break;
case 'single image styles':
$asset = VcSharedLibrary::getBoxStyles();
break;
case 'single image external styles':
$asset = VcSharedLibrary::getBoxStyles( array(
'default',
'round',
) );
break;
case 'toggle styles':
$asset = VcSharedLibrary::getToggleStyles();
break;
case 'animation styles':
$asset = VcSharedLibrary::getAnimationStyles();
break;
}
return $asset;
}
/**
* Helper function to register new shortcode attribute hook.
*
* @param $name - attribute name
* @param $form_field_callback - hook, will be called when settings form is shown and attribute added to shortcode
* param list
* @param $script_url - javascript file url which will be attached at the end of settings form.
*
* @return bool
* @since 4.4
*/
function vc_add_shortcode_param( $name, $form_field_callback, $script_url = null ) {
return WpbakeryShortcodeParams::addField( $name, $form_field_callback, $script_url );
}
/**
* Call hook for attribute.
*
* @param $name - attribute name
* @param $param_settings - attribute settings from shortcode
* @param $param_value - attribute value
* @param $tag - attribute tag
*
* @return mixed|string - returns html which will be render in hook
* @since 4.4
*/
function vc_do_shortcode_param_settings_field( $name, $param_settings, $param_value, $tag ) {
return WpbakeryShortcodeParams::renderSettingsField( $name, $param_settings, $param_value, $tag );
}

View File

@@ -0,0 +1,622 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
/**
* WPBakery WPBakery Page Builder Main manager.
*
* @package WPBakeryPageBuilder
* @since 4.2
*/
if ( ! function_exists( 'vc_manager' ) ) {
/**
* WPBakery Page Builder manager.
* @return Vc_Manager
* @since 4.2
*/
function vc_manager() {
return Vc_Manager::getInstance();
}
}
if ( ! function_exists( 'visual_composer' ) ) {
/**
* WPBakery Page Builder instance.
* @return Vc_Base
* @since 4.2
*/
function visual_composer() {
return vc_manager()->vc();
}
}
if ( ! function_exists( 'vc_mapper' ) ) {
/**
* Shorthand for Vc Mapper.
* @return Vc_Mapper
* @since 4.2
*/
function vc_mapper() {
return vc_manager()->mapper();
}
}
if ( ! function_exists( 'vc_settings' ) ) {
/**
* Shorthand for WPBakery Page Builder settings.
* @return Vc_Settings
* @since 4.2
*/
function vc_settings() {
return vc_manager()->settings();
}
}
if ( ! function_exists( 'vc_license' ) ) {
/**
* Get License manager
* @return Vc_License
* @since 4.2
*/
function vc_license() {
return vc_manager()->license();
}
}
if ( ! function_exists( 'vc_automapper' ) ) {
/**
* @return Vc_Automapper
* @since 4.2
*/
function vc_automapper() {
return vc_manager()->automapper();
}
}
if ( ! function_exists( 'vc_frontend_editor' ) ) {
/**
* Shorthand for VC frontend editor
* @return Vc_Frontend_Editor
* @since 4.2
*/
function vc_frontend_editor() {
return vc_manager()->frontendEditor();
}
}
if ( ! function_exists( 'vc_backend_editor' ) ) {
/**
* Shorthand for VC frontend editor
* @return Vc_Backend_Editor
* @since 4.2
*/
function vc_backend_editor() {
return vc_manager()->backendEditor();
}
}
if ( ! function_exists( 'vc_updater' ) ) {
/**
* @return Vc_Updater
* @since 4.2
*/
function vc_updater() {
return vc_manager()->updater();
}
}
if ( ! function_exists( 'vc_is_network_plugin' ) ) {
/**
* Vc is network plugin or not.
* @return bool
* @since 4.2
*/
function vc_is_network_plugin() {
return vc_manager()->isNetworkPlugin();
}
}
if ( ! function_exists( 'vc_path_dir' ) ) {
/**
* Get file/directory path in Vc.
*
* @param string $name - path name
* @param string $file
*
* @return string
* @since 4.2
*/
function vc_path_dir( $name, $file = '' ) {
return vc_manager()->path( $name, $file );
}
}
if ( ! function_exists( 'vc_asset_url' ) ) {
/**
* Get full url for assets.
*
* @param string $file
*
* @return string
* @since 4.2
*/
function vc_asset_url( $file ) {
return vc_manager()->assetUrl( $file );
}
}
if ( ! function_exists( 'vc_upload_dir' ) ) {
/**
* Temporary files upload dir;
* @return string
* @since 4.2
*/
function vc_upload_dir() {
return vc_manager()->uploadDir();
}
}
if ( ! function_exists( 'vc_template' ) ) {
/**
* @param $file
*
* @return string
* @since 4.2
*/
function vc_template( $file ) {
return vc_path_dir( 'TEMPLATES_DIR', $file );
}
}
if ( ! function_exists( 'vc_post_param' ) ) {
/**
* Get param value from $_POST if exists.
*
* @param $param
* @param $default
*
* @param bool $check
* @return null|string - null for undefined param.
* @since 4.2
*/
function vc_post_param( $param, $default = null, $check = false ) {
if ( 'admin' === $check ) {
check_admin_referer();
} elseif ( 'ajax' === $check ) {
check_ajax_referer();
}
return isset( $_POST[ $param ] ) ? $_POST[ $param ] : $default;
}
}
if ( ! function_exists( 'vc_get_param' ) ) {
/**
* Get param value from $_GET if exists.
*
* @param string $param
* @param $default
*
* @param bool $check
* @return null|string - null for undefined param.
* @since 4.2
*/
function vc_get_param( $param, $default = null, $check = false ) {
if ( 'admin' === $check ) {
check_admin_referer();
} elseif ( 'ajax' === $check ) {
check_ajax_referer();
}
// @codingStandardsIgnoreLine
return isset( $_GET[ $param ] ) ? $_GET[ $param ] : $default;
}
}
if ( ! function_exists( 'vc_request_param' ) ) {
/**
* Get param value from $_REQUEST if exists.
*
* @param $param
* @param $default
*
* @param bool $check
* @return null|string - null for undefined param.
* @since 4.4
*/
function vc_request_param( $param, $default = null, $check = false ) {
if ( 'admin' === $check ) {
check_admin_referer();
} elseif ( 'ajax' === $check ) {
check_ajax_referer();
}
// @codingStandardsIgnoreLine
return isset( $_REQUEST[ $param ] ) ? $_REQUEST[ $param ] : $default;
}
}
if ( ! function_exists( 'vc_is_frontend_editor' ) ) {
/**
* @return bool
* @since 4.2
*/
function vc_is_frontend_editor() {
return 'admin_frontend_editor' === vc_mode();
}
}
if ( ! function_exists( 'vc_is_page_editable' ) ) {
/**
* @return bool
* @since 4.2
*/
function vc_is_page_editable() {
return 'page_editable' === vc_mode();
}
}
if ( ! function_exists( 'vc_action' ) ) {
/**
* Get VC special action param.
* @return string|null
* @since 4.2
*/
function vc_action() {
$vc_action = wp_strip_all_tags( vc_request_param( 'vc_action' ) );
return $vc_action;
}
}
if ( ! function_exists( 'vc_is_inline' ) ) {
/**
* Get is inline or not.
* @return bool
* @since 4.2
*/
function vc_is_inline() {
global $vc_is_inline;
if ( is_null( $vc_is_inline ) ) {
$vc_is_inline = ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) ) && 'vc_inline' === vc_action() || ! is_null( vc_request_param( 'vc_inline' ) ) || 'true' === vc_request_param( 'vc_editable' );
}
return $vc_is_inline;
}
}
if ( ! function_exists( 'vc_is_frontend_ajax' ) ) {
/**
* @return bool
* @since 4.2
*/
function vc_is_frontend_ajax() {
return 'true' === vc_post_param( 'vc_inline' ) || vc_get_param( 'vc_inline' );
}
}
/**
* @depreacted since 4.8 ( use vc_is_frontend_editor )
* @return bool
* @since 4.2
*/
function vc_is_editor() {
return vc_is_frontend_editor();
}
/**
* @param $value
* @param bool $encode
*
* @return string
* @since 4.2
*/
function vc_value_from_safe( $value, $encode = false ) {
// @codingStandardsIgnoreLine
$value = preg_match( '/^#E\-8_/', $value ) ? rawurldecode( base64_decode( preg_replace( '/^#E\-8_/', '', $value ) ) ) : $value;
if ( $encode ) {
$value = htmlentities( $value, ENT_COMPAT, 'UTF-8' );
}
return $value;
}
/**
* @param bool $disable
* @since 4.2
*
*/
function vc_disable_automapper( $disable = true ) {
vc_automapper()->setDisabled( $disable );
}
/**
* @return bool
* @since 4.2
*/
function vc_automapper_is_disabled() {
return vc_automapper()->disabled();
}
/**
* @param $param
* @param $value
*
* @return mixed|string
* @since 4.2
*/
function vc_get_dropdown_option( $param, $value ) {
if ( '' === $value && is_array( $param['value'] ) ) {
$value = array_shift( $param['value'] );
}
if ( is_array( $value ) ) {
reset( $value );
$value = isset( $value['value'] ) ? $value['value'] : current( $value );
}
$value = preg_replace( '/\s/', '_', $value );
return ( '' !== $value ? $value : '' );
}
/**
* @param $prefix
* @param $color
*
* @return string
* @since 4.2
*/
function vc_get_css_color( $prefix, $color ) {
$rgb_color = preg_match( '/rgba/', $color ) ? preg_replace( array(
'/\s+/',
'/^rgba\((\d+)\,(\d+)\,(\d+)\,([\d\.]+)\)$/',
), array(
'',
'rgb($1,$2,$3)',
), $color ) : $color;
$string = $prefix . ':' . $rgb_color . ';';
if ( $rgb_color !== $color ) {
$string .= $prefix . ':' . $color . ';';
}
return $string;
}
/**
* @param $param_value
* @param string $prefix
*
* @return string
* @since 4.2
*/
function vc_shortcode_custom_css_class( $param_value, $prefix = '' ) {
$css_class = preg_match( '/\s*\.([^\{]+)\s*\{\s*([^\}]+)\s*\}\s*/', $param_value ) ? $prefix . preg_replace( '/\s*\.([^\{]+)\s*\{\s*([^\}]+)\s*\}\s*/', '$1', $param_value ) : '';
return $css_class;
}
/**
* @param $subject
* @param $property
* @param bool|false $strict
*
* @return bool
* @since 4.9
*/
function vc_shortcode_custom_css_has_property( $subject, $property, $strict = false ) {
$styles = array();
$pattern = '/\{([^\}]*?)\}/i';
preg_match( $pattern, $subject, $styles );
if ( array_key_exists( 1, $styles ) ) {
$styles = explode( ';', $styles[1] );
}
$new_styles = array();
foreach ( $styles as $val ) {
$val = explode( ':', $val );
if ( is_array( $property ) ) {
foreach ( $property as $prop ) {
$pos = strpos( $val[0], $prop );
$full = ( $strict ) ? ( 0 === $pos && strlen( $val[0] ) === strlen( $prop ) ) : true;
if ( false !== $pos && $full ) {
$new_styles[] = $val;
}
}
} else {
$pos = strpos( $val[0], $property );
$full = ( $strict ) ? ( 0 === $pos && strlen( $val[0] ) === strlen( $property ) ) : true;
if ( false !== $pos && $full ) {
$new_styles[] = $val;
}
}
}
return ! empty( $new_styles );
}
/**
* Plugin name for VC.
*
* @return string
* @since 4.2
*/
function vc_plugin_name() {
return vc_manager()->pluginName();
}
/**
* @param $filename
*
* @return bool|mixed|string
* @since 4.4.3 used in vc_base when getting an custom css output
*
*/
function vc_file_get_contents( $filename ) {
global $wp_filesystem;
if ( empty( $wp_filesystem ) ) {
require_once ABSPATH . '/wp-admin/includes/file.php';
WP_Filesystem( false, false, true );
}
/** @var WP_Filesystem_Base $wp_filesystem */
$output = '';
if ( is_object( $wp_filesystem ) ) {
$output = $wp_filesystem->get_contents( $filename );
}
if ( ! $output ) {
// @codingStandardsIgnoreLine
$output = file_get_contents( $filename );
}
return $output;
}
/**
* HowTo: vc_role_access()->who('administrator')->with('editor')->can('frontend_editor');
* @return Vc_Role_Access;
* @since 4.8
*/
function vc_role_access() {
return vc_manager()->getRoleAccess();
}
/**
* Get access manager for current user.
* HowTo: vc_user_access()->->with('editor')->can('frontend_editor');
* @return Vc_Current_User_Access;
* @since 4.8
*/
function vc_user_access() {
return vc_manager()->getCurrentUserAccess();
}
/**
* @return array
* @throws \Exception
*/
function vc_user_roles_get_all() {
require_once vc_path_dir( 'SETTINGS_DIR', 'class-vc-roles.php' );
$vc_roles = new Vc_Roles();
$capabilities = array();
foreach ( $vc_roles->getParts() as $part ) {
$partObj = vc_user_access()->part( $part );
$capabilities[ $part ] = array(
'state' => $partObj->getState(),
'state_key' => $partObj->getStateKey(),
'capabilities' => $partObj->getAllCaps(),
);
}
return $capabilities;
}
/**
* @param $data
*
* @return string
*/
function vc_generate_nonce( $data ) {
return wp_create_nonce( is_array( $data ) ? ( 'vc-nonce-' . implode( '|', $data ) ) : ( 'vc-nonce-' . $data ) );
}
/**
* @param $nonce
* @param $data
*
* @return bool
*/
function vc_verify_nonce( $nonce, $data ) {
return (bool) wp_verify_nonce( $nonce, ( is_array( $data ) ? ( 'vc-nonce-' . implode( '|', $data ) ) : ( 'vc-nonce-' . $data ) ) );
}
/**
* @param $nonce
*
* @return bool
*/
function vc_verify_admin_nonce( $nonce = '' ) {
return (bool) vc_verify_nonce( ! empty( $nonce ) ? $nonce : vc_request_param( '_vcnonce' ), 'vc-admin-nonce' );
}
/**
* @param $nonce
*
* @return bool
*/
function vc_verify_public_nonce( $nonce = '' ) {
return (bool) vc_verify_nonce( ( ! empty( $nonce ) ? $nonce : vc_request_param( '_vcnonce' ) ), 'vc-public-nonce' );
}
/**
* @param $type
* @return bool|mixed|void
* @throws \Exception
*/
function vc_check_post_type( $type ) {
if ( empty( $type ) ) {
$type = get_post_type();
}
$valid = apply_filters( 'vc_check_post_type_validation', null, $type );
if ( is_null( $valid ) ) {
if ( is_multisite() && is_super_admin() ) {
return true;
}
$state = vc_user_access()->part( 'post_types' )->getState();
if ( null === $state ) {
return in_array( $type, vc_default_editor_post_types(), true );
} elseif ( true === $state && ! in_array( $type, vc_default_editor_post_types(), true ) ) {
$valid = false;
} else {
$valid = vc_user_access()->part( 'post_types' )->can( $type )->get();
}
}
return $valid;
}
/**
* @param $shortcode
* @return bool|mixed|void
*/
function vc_user_access_check_shortcode_edit( $shortcode ) {
$do_check = apply_filters( 'vc_user_access_check-shortcode_edit', null, $shortcode );
if ( is_null( $do_check ) ) {
$state_check = vc_user_access()->part( 'shortcodes' )->checkStateAny( true, 'edit', null )->get();
if ( $state_check ) {
return true;
} else {
return vc_user_access()->part( 'shortcodes' )->canAny( $shortcode . '_all', $shortcode . '_edit' )->get();
}
} else {
return $do_check;
}
}
/**
* @param $shortcode
* @return bool|mixed|void
* @throws \Exception
*/
function vc_user_access_check_shortcode_all( $shortcode ) {
$do_check = apply_filters( 'vc_user_access_check-shortcode_all', null, $shortcode );
if ( is_null( $do_check ) ) {
return vc_user_access()->part( 'shortcodes' )->checkStateAny( true, 'custom', null )->can( $shortcode . '_all' )->get();
} else {
return $do_check;
}
}
/**
* htmlspecialchars_decode_deep
* Call the htmlspecialchars_decode to a gived multilevel array
*
* @param mixed $value The value to be stripped.
*
* @return mixed Stripped value.
* @since 4.8
*
*/
function vc_htmlspecialchars_decode_deep( $value ) {
if ( is_array( $value ) ) {
$value = array_map( 'vc_htmlspecialchars_decode_deep', $value );
} elseif ( is_object( $value ) ) {
$vars = get_object_vars( $value );
foreach ( $vars as $key => $data ) {
$value->{$key} = vc_htmlspecialchars_decode_deep( $data );
}
} elseif ( is_string( $value ) ) {
$value = htmlspecialchars_decode( $value );
}
return $value;
}
/**
* @param $str
* @return mixed
*/
function vc_str_remove_protocol( $str ) {
return str_replace( array(
'https://',
'http://',
), '//', $str );
}