PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.1.3
JetFormBuilder — Dynamic Blocks Form Builder v3.1.3
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 / includes / classes / builder-helper.php
jetformbuilder / includes / classes Last commit date
arguments 2 years ago arrayable 2 years ago filters 2 years ago http 2 years ago macro-constants 2 years ago post 2 years ago resources 2 years ago theme 2 years ago attributes-trait.php 2 years ago base-attributes-trait.php 2 years ago builder-helper.php 2 years ago compatibility.php 2 years ago date-tools.php 2 years ago gallery.php 2 years ago get-icon-trait.php 2 years ago get-template-trait.php 2 years ago html-attributes-trait.php 2 years ago instance-trait.php 2 years ago macros-parser.php 2 years ago regexp-tools.php 2 years ago tools.php 2 years ago
builder-helper.php
189 lines
1 <?php
2
3
4 namespace Jet_Form_Builder\Classes;
5
6 use Jet_Form_Builder\Blocks\Module;
7 use Jet_Form_Builder\Plugin;
8
9 if ( ! defined( 'WPINC' ) ) {
10 die;
11 }
12
13 class Builder_Helper {
14
15 private static $html_ids = array();
16
17 private static $styled_form_ids = array();
18
19 /**
20 * @param $object_id
21 * @param $args
22 * @param false $checked
23 *
24 * @return string
25 */
26 public function get_custom_template( $object_id, $args, $checked = false ) {
27 if ( ! Compatibility::has_jet_engine() ) {
28 return __( 'Please install JetEngine', 'jet-form-builder' ) . '<br>';
29 }
30
31 $listing_id = ! empty( $args['custom_item_template_id'] ) ? $args['custom_item_template_id'] : false;
32 $listing_id = absint( $listing_id );
33
34 if ( ! $listing_id ) {
35 return __( 'Please select template', 'jet-form-builder' ) . '<br>';
36 }
37
38 global $wp_query;
39 $default_object = $wp_query->queried_object;
40
41 $options_from = ! empty( $args['field_options_from'] ) ? $args['field_options_from'] : 'posts';
42
43 if ( 'terms' === $options_from ) {
44 $object = get_term( $object_id );
45 } else {
46 $object = get_post( $object_id );
47 }
48
49 if ( ! is_object( $object ) ) {
50 return '';
51 }
52
53 $classes = array(
54 'jet-form-builder__field-template',
55 'jet-listing-dynamic-post-' . $object_id,
56 );
57
58 if ( $checked ) {
59 $classes[] = 'jet-form-builder__field-template--checked';
60 }
61
62 $wp_query->queried_object = $object;
63 jet_engine()->listings->data->set_current_object( $object );
64
65 jet_engine()->frontend->set_listing( $listing_id );
66
67 ob_start();
68 $content = jet_engine()->frontend->get_listing_item( $object );
69
70 $content .= ob_get_clean();
71
72 wp_enqueue_script( Module::LISTING_OPTIONS_HANDLE );
73
74 $result = sprintf(
75 '<div class="%3$s" data-value="%1$d">%2$s</div>',
76 esc_attr( $object_id ),
77 apply_filters( 'jet-form-builder/custom-template-content', $content, $object_id, $listing_id ),
78 join( ' ', $classes )
79 );
80
81 $wp_query->queried_object = $default_object;
82 jet_engine()->listings->data->set_current_object( $wp_query->queried_object );
83
84 return $result;
85 }
86
87 /**
88 * @param string $html_id
89 * @param string $for_html
90 *
91 * @return string
92 */
93 public static function get_unique_id( string $html_id, string $for_html = 'input' ): string {
94 if ( ! array_key_exists( $html_id, self::$html_ids ) ) {
95 self::$html_ids[ $html_id ] = array();
96 }
97
98 if ( ! isset( self::$html_ids[ $html_id ][ $for_html ] ) ) {
99 self::$html_ids[ $html_id ][ $for_html ] = 0;
100
101 return $html_id;
102 }
103
104 return sprintf( '%1$s_%2$d', $html_id, ++ self::$html_ids[ $html_id ][ $for_html ] );
105 }
106
107 /**
108 * @since 3.1.0 Add support for WP 5.6
109 * @since 3.0.3
110 *
111 * @see https://github.com/Crocoblock/issues-tracker/issues/2636
112 */
113 public static function enqueue_global_styles() {
114 // support for WP 5.6
115 if ( function_exists( 'wp_enqueue_global_styles' ) ) {
116 wp_enqueue_global_styles();
117 }
118 wp_enqueue_style( 'wp-block-library' );
119 wp_enqueue_style( 'jet-form-builder-frontend' );
120 }
121
122 /**
123 * @param string|int $form_id
124 *
125 * @since 3.0.4
126 */
127 public static function enqueue_style_form( $form_id ) {
128 if ( self::is_enqueued_form_style( $form_id ) ) {
129 return;
130 }
131
132 $form_id = absint( $form_id );
133
134 $result = wp_add_inline_style(
135 'jet-form-builder-frontend',
136 Plugin::instance()->post_type->maybe_get_jet_sm_ready_styles( $form_id )
137 );
138
139 do_action( 'jet-form-builder/enqueue-style' );
140
141 if ( $result ) {
142 self::$styled_form_ids[ $form_id ] = 1;
143 }
144 }
145
146 /**
147 * @param string|int $form_id
148 *
149 * @since 3.0.4
150 */
151 public static function is_enqueued_form_style( $form_id ): bool {
152 $form_id = absint( $form_id );
153
154 return isset( self::$styled_form_ids[ $form_id ] );
155 }
156
157 /**
158 * @since 3.1.0
159 *
160 * @param array<array<string, string>> $attributes
161 *
162 * @return string
163 */
164 public static function attrs( array $attributes ): string {
165 return implode(
166 ' ',
167 self::filter_attrs( $attributes )
168 );
169 }
170
171 /**
172 * @param array<array<string, string>> $attributes
173 *
174 * @return array
175 */
176 public static function filter_attrs( array $attributes ): array {
177 $attributes_stack = array();
178
179 foreach ( $attributes as list( $name, $value ) ) {
180 if ( ! $value ) {
181 continue;
182 }
183 $attributes_stack[] = sprintf( '%1$s="%2$s"', $name, $value );
184 }
185
186 return $attributes_stack;
187 }
188 }
189