PluginProbe
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce / 3.3.0
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce v3.3.0
3.3.0 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.1 trunk 1.0.4 1.1.0 1.1.0.1 1.1.1 1.1.10 1.1.11 1.1.12 1.1.13 1.1.14 1.1.15 1.1.16 1.1.17 1.1.18 1.1.19 1.1.2 All 162 releases
cartflows / modules / beaver-builder / classes / class-cartflows-bb-helper.php

class-cartflows-bb-helper.php in CartFlows – Funnel Builder & Checkout Plugin for WooCommerce 3.3.0, at modules/beaver-builder/classes/class-cartflows-bb-helper.php

172 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Custom modules
4 *
5 * @package BB Helper
6 */
7
8 // Exit if accessed directly.
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit;
11 }
12
13 if ( ! class_exists( 'Cartflows_BB_Helper' ) ) {
14 /**
15 * This class initializes BB Ultimate Addon Helper
16 *
17 * @class Cartflows_BB_Helper
18 */
19 class Cartflows_BB_Helper {
20
21 /**
22 * Current step type var
23 *
24 * @since 1.6.15
25 * @var object $step_type
26 */
27 public static $step_type;
28
29 /**
30 * Get current post step type
31 *
32 * @since 1.6.15
33 * @var function cartflows_bb_step_type
34 */
35 public static function cartflows_bb_step_type() {
36
37 if ( ! isset( self::$step_type ) ) {
38 self::$step_type = get_post_meta( get_the_id(), 'wcf-step-type', true );
39 }
40
41 return self::$step_type;
42 }
43
44 /**
45 * Initializes an array to replace recursive function
46 *
47 * @param string $color returns the bas values.
48 *
49 * @param array $opacity returns the replacements values.
50 * @param array $is_array returns the replacements values.
51 */
52 public static function cartflows_bb_hex2rgba( $color, $opacity = false, $is_array = false ) {
53
54 $default = $color;
55
56 // Return default if no color provided.
57 if ( empty( $color ) ) {
58 return $default;
59 }
60
61 // Sanitize $color if "#" is provided.
62 if ( '#' == $color[0] ) {
63 $color = substr( $color, 1 );
64 }
65
66 // Check if color has 6 or 3 characters and get values.
67 if ( 6 == strlen( $color ) ) {
68 $hex = array( $color[0] . $color[1], $color[2] . $color[3], $color[4] . $color[5] );
69 } elseif ( 3 == strlen( $color ) ) {
70 $hex = array( $color[0] . $color[0], $color[1] . $color[1], $color[2] . $color[2] );
71 } else {
72 return $default;
73 }
74
75 // Convert hexadec to rgb.
76 $rgb = array_map( 'hexdec', $hex );
77
78 // Check if opacity is set(rgba or rgb).
79 if ( false !== $opacity && '' !== $opacity ) {
80 if ( abs( $opacity ) > 1 ) {
81
82 $opacity = $opacity / 100;
83 }
84 $output = 'rgba(' . implode( ',', $rgb ) . ',' . $opacity . ')';
85 } else {
86 $output = 'rgb(' . implode( ',', $rgb ) . ')';
87 }
88
89 if ( $is_array ) {
90 return $rgb;
91 } else {
92
93 return $output;
94 }
95 }
96
97 /**
98 * Initializes an array to replace recursive function
99 *
100 * @param var $settings returns the bas values.
101 *
102 * @param array $name returns the replacements values.
103 * @param array $opc returns the replacements values.
104 */
105 public static function cartflows_bb_colorpicker( $settings, $name = '', $opc = false ) {
106
107 $hex_color = '';
108 $opacity = '';
109 $hex_color = $settings->$name;
110
111 if ( '' != $hex_color && 'r' != $hex_color[0] && 'R' != $hex_color[0] ) {
112
113 if ( true == $opc && isset( $settings->{ $name . '_opc' } ) ) {
114 if ( '' !== $settings->{ $name . '_opc' } ) {
115 $opacity = $settings->{ $name . '_opc' };
116 $rgba = self::cartflows_bb_hex2rgba( $hex_color, $opacity / 100 );
117 return $rgba;
118 }
119 }
120
121 if ( '#' != $hex_color[0] ) {
122
123 return '#' . $hex_color;
124 }
125 }
126
127 return $hex_color;
128
129 }
130
131 /**
132 * Provide option to parse a color code.
133 *
134 * @param var $code Returns a hex value for color from rgba or #hex color.
135 * @return string - hex value for the color
136 */
137 public static function cartflows_bb_parse_color_to_hex( $code = '' ) {
138 $color = '';
139 $hex = '';
140 if ( '' != $code ) {
141 if ( false !== strpos( $code, 'rgba' ) ) {
142 $code = ltrim( $code, 'rgba(' );
143 $code = rtrim( $code, ')' );
144 $rgb = explode( ',', $code );
145 $hex .= str_pad( dechex( $rgb[0] ), 2, '0', STR_PAD_LEFT );
146 $hex .= str_pad( dechex( $rgb[1] ), 2, '0', STR_PAD_LEFT );
147 $hex .= str_pad( dechex( $rgb[2] ), 2, '0', STR_PAD_LEFT );
148 $color = $hex;
149 } else {
150 $color = ltrim( $code, '#' );
151 }
152 }
153 return $color;
154 }
155
156 /**
157 * Check for the Beaver Builder's setting page.
158 *
159 * @since 1.6.x
160 * @var function wcf_is_bb_setting_page
161 */
162 public static function wcf_is_bb_setting_page() {
163
164 if ( is_admin() && isset( $_GET['page'] ) && 'fl-builder-settings' === sanitize_text_field( $_GET['page'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
165 return true;
166 }
167
168 return false;
169 }
170 }
171 }
172