PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.6.4.2
JetFormBuilder — Dynamic Blocks Form Builder v3.6.4.2
3.6.5.1 3.6.5 3.6.4.2 3.6.4.1 3.6.4 3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / modules / framework / blocks-style-manager / field-handlers / base.php
jetformbuilder / modules / framework / blocks-style-manager / field-handlers Last commit date
base.php 3 months ago border.php 3 months ago dimensions.php 3 months ago range.php 3 months ago typography.php 3 months ago
base.php
118 lines
1 <?php
2 namespace Crocoblock\Blocks_Style\Field_Handlers;
3
4 class Base {
5
6 protected $raw_value = '';
7
8 /**
9 * Constructor
10 *
11 * @param string $raw_value Raw value to be parsed.
12 */
13 public function __construct( $raw_value = '' ) {
14 $this->raw_value = $raw_value;
15 }
16
17 /**
18 * Get the parsed value.
19 *
20 * @return array
21 */
22 public function get_parsed_value() {
23 return array(
24 'value' => $this->raw_value,
25 );
26 }
27
28 /**
29 * String with CSS variable macros.
30 * Should be rewritten in the classes with multiple parameters
31 * returned by get_parsed_value() method.
32 */
33 public function css_var_value_format() {
34 return '{{VALUE}}';
35 }
36
37 /**
38 * Replace data in the string with CSS variable macros.
39 *
40 * @param string $string String with macros.
41 * @param array $data Data to replace in the string.
42 *
43 * @return array
44 */
45 public function parse_variable( $variable = array() ) {
46
47 $prefix = isset($variable['prefix']) ? $variable['prefix'] : '';
48 $name = isset($variable['name']) ? $variable['name'] : false;
49 $full_name = isset($variable['full_name']) ? $variable['full_name'] : $prefix . '-' . $name;
50
51 if ( ! $full_name ) {
52 return array();
53 }
54
55 if ( isset( $variable['suffix'] ) ) {
56 $full_name .= $variable['suffix'];
57 }
58
59 $parsed_values = $this->get_parsed_value();
60 $result = array();
61
62 if ( ! empty( $parsed_values['value'] ) ) {
63 $result[] = $full_name . ':' . $parsed_values['value'];
64 } else {
65 $values = self::replace_data( $this->css_var_value_format(), $parsed_values );
66 $values = trim( $values );
67
68 if ( ! empty( $values ) ) {
69 $result[] = $full_name . ':' . $values;
70 }
71 }
72
73 return $result;
74 }
75
76 /**
77 * Parses data with macros.
78 *
79 * @param string $data Data to parse.
80 * @param array $macros Macros to replace.
81 * @return string Parsed data.
82 */
83 public static function replace_data( $data = '', $macros = array() ) {
84
85 if ( empty( $data ) || ! is_string( $data ) ) {
86 return '';
87 }
88
89 if ( ! empty( $macros ) && is_array( $macros ) ) {
90 $data = preg_replace_callback(
91 '/\{\{\s*([\w-]+)\s*\}\}/',
92 function ( $matches ) use ( $macros ) {
93 $key = strtolower( $matches[1] );
94 return isset( $macros[ $key ] ) ? $macros[ $key ] : '';
95 },
96 $data
97 );
98 }
99
100 return trim( $data );
101 }
102
103 /**
104 * Get CSS rule string with replaced macros.
105 *
106 * @param string $rule_string String with CSS rule and macros.
107 * @return string Parsed CSS rule.
108 */
109 public function get_css_rule( $rule_string = '' ) {
110 $parsed_values = $this->get_parsed_value();
111
112 if ( empty( $parsed_values ) || ! is_array( $parsed_values ) ) {
113 return '';
114 }
115
116 return self::replace_data( $rule_string, $parsed_values );
117 }
118 }