PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.0.8
JetFormBuilder — Dynamic Blocks Form Builder v3.0.8
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 / form-break.php
jetformbuilder / includes Last commit date
actions 3 years ago addons 3 years ago admin 3 years ago blocks 3 years ago classes 3 years ago compatibility 3 years ago db-queries 3 years ago dev-mode 3 years ago exceptions 3 years ago form-actions 3 years ago form-messages 3 years ago form-patterns 3 years ago form-response 3 years ago gateways 3 years ago generators 3 years ago integrations 3 years ago migrations 3 years ago post-meta 3 years ago presets 3 years ago request 3 years ago rest-api 3 years ago shortcodes 3 years ago wp-cli 3 years ago autoloader.php 3 years ago file-upload.php 3 years ago form-break.php 3 years ago form-handler.php 3 years ago form-manager.php 3 years ago live-form.php 3 years ago plugin.php 3 years ago post-type.php 3 years ago
form-break.php
281 lines
1 <?php
2
3
4 namespace Jet_Form_Builder;
5
6 use Jet_Form_Builder\Blocks\Block_Helper;
7 use Jet_Form_Builder\Classes\Get_Template_Trait;
8 use Jet_Form_Builder\Classes\Tools;
9
10 class Form_Break {
11
12 use Get_Template_Trait;
13
14 private $pages = 0;
15 private $form_breaks = array();
16 private $count_form_breaks = null;
17 private $current_page = 1;
18 private $current_form_break = 0;
19 private $is_editor = false;
20 private $progress_type = 'default';
21 private $has_start = false;
22
23 /**
24 * @since 3.0.1
25 *
26 * @var int
27 */
28 private $page_offset = 75;
29
30 public function get_pages() {
31 return $this->pages;
32 }
33
34 public function get_breaks() {
35 return $this->form_breaks;
36 }
37
38 public function get_count_breaks() {
39 if ( is_null( $this->count_form_breaks ) ) {
40 $this->count_form_breaks = count( $this->form_breaks );
41 }
42
43 return $this->count_form_breaks;
44 }
45
46 public function get_current() {
47 return $this->current_page;
48 }
49
50 public function set_progress_type( $type ) {
51 if ( ! is_string( $type ) ) {
52 return;
53 }
54 $this->progress_type = $type;
55 }
56
57 public function set_editor_mode( $is_editor ) {
58 if ( ! $is_editor ) {
59 $this->is_editor = false;
60 $this->pages = 0;
61 $this->form_breaks = array();
62 $this->count_form_breaks = 0;
63
64 return $this;
65 }
66
67 $this->is_editor = true;
68 $this->pages = 2;
69 $this->form_breaks = array(
70 array(
71 'label' => 'Start Page',
72 ),
73 array(
74 'label' => 'Second Page',
75 ),
76 array(
77 'label' => 'Last Page',
78 ),
79 );
80
81 return $this;
82 }
83
84 public function add_progress( $last_progress ) {
85 $this->form_breaks[] = $last_progress;
86
87 return $this;
88 }
89
90
91 public function set_pages( $blocks, $last_page_from_blocks = true ) {
92 $count_blocks = count( $blocks );
93 $last_break = false;
94
95 foreach ( $blocks as $index => $field ) {
96 if ( 'core/block' === $field['blockName'] ) {
97 $this->set_pages( $field['innerBlocks'] ?? array(), false );
98
99 continue;
100 }
101 if ( 'form-break-start' === Block_Helper::delete_namespace( $field ) ) {
102 $this->has_start = true;
103
104 continue;
105
106 } elseif ( 'form-break-field' !== Block_Helper::delete_namespace( $field ) ) {
107 continue;
108 }
109 $form_break = Plugin::instance()->blocks->get_field_attrs( $field['blockName'], $field['attrs'] );
110
111 if ( $last_page_from_blocks && $index + 1 === $count_blocks ) {
112 $last_break = $form_break;
113 unset( $blocks[ $index ] );
114 continue;
115 }
116
117 $this->pages ++;
118 $this->form_breaks[] = $form_break;
119 }
120 if ( $last_page_from_blocks && ! empty( $this->form_breaks ) ) {
121 $this->form_breaks[] = $last_break ? $last_break : array( 'label' => __( 'Last Page' ) );
122 }
123
124 return $blocks;
125 }
126
127 public function with_progress_wrapper( $content, $additional_classes = array() ) {
128 $type = $this->progress_type ?: 'default';
129
130 $classes = array_merge(
131 array(
132 'jet-form-builder-progress-pages',
133 "jfb-progress-type--$type",
134 ),
135 $additional_classes
136 );
137
138 return sprintf(
139 '<div class="%1$s" data-type="%2$s">%3$s</div>',
140 implode( ' ', $classes ),
141 $type,
142 $content
143 );
144 }
145
146 public function render_default_progress() {
147 ob_start();
148 include Tools::get_global_template( 'fields/progress-bar.php' );
149
150 return ob_get_clean();
151 }
152
153 public function render_progress( $type = '', $additional_classes = array() ) {
154 if ( $type ) {
155 $this->set_progress_type( $type );
156 }
157
158 switch ( $this->progress_type ) {
159 case 'default':
160 $content = $this->render_default_progress();
161 break;
162 default:
163 $content = apply_filters( "jet-form-builder/render/progress-bar/$this->progress_type", '', $this );
164 break;
165 }
166
167 return $this->with_progress_wrapper( $content, $additional_classes );
168 }
169
170 public function get_progress_item_class( $index ) {
171 $classes = array( 'jet-form-builder-progress-pages__item--wrapper' );
172
173 if ( $this->is_editor ) {
174 if ( 0 === $index ) {
175 $classes[] = 'passed-page';
176 }
177 if ( 1 === $index ) {
178 $classes[] = 'active-page';
179 }
180 } elseif ( $index === $this->current_form_break ) {
181 $classes[] = 'active-page';
182 } elseif ( $index < $this->current_form_break ) {
183 $classes[] = 'passed-page';
184 }
185
186 return implode( ' ', $classes );
187 }
188
189 /**
190 * Maybe start new page
191 *
192 * @param bool $force_first
193 *
194 * @return string
195 */
196 public function maybe_start_page( $force_first = false ) {
197 if ( 0 >= $this->pages || $this->is_has_start() ) {
198 return '';
199 }
200
201 if ( $force_first ) {
202 $this->current_page = 1;
203 $this->current_form_break = 0;
204 } else {
205 $this->current_page ++;
206 $this->current_form_break ++;
207 }
208
209 ob_start();
210 do_action( 'jet-form-builder/before-page-start', $this );
211
212 $hidden_class = '';
213
214 if ( 1 < $this->current_page ) {
215 $hidden_class = 'jet-form-builder-page--hidden';
216 }
217
218 include Tools::get_global_template( 'common/start-page.php' );
219
220 do_action( 'jet-form-builder/after-page-start', $this );
221
222 return ob_get_clean();
223 }
224
225 /**
226 * Maybe start new page
227 *
228 * @param $is_last
229 * @param $field
230 *
231 * @return string
232 */
233 public function maybe_end_page( $is_last = false, $field = false ) {
234 if ( 0 >= $this->pages ) {
235 return '';
236 }
237
238 if ( ! $is_last && 'form-break-field' !== Block_Helper::delete_namespace( $field ) ) {
239 return '';
240 }
241
242 ob_start();
243 do_action( 'jet-form-builder/before-page-end', $this );
244
245 include Tools::get_global_template( 'common/end-page.php' );
246
247 do_action( 'jet-form-builder/after-page-end', $this );
248
249 return ob_get_clean();
250 }
251
252 /**
253 * @return bool
254 */
255 public function is_has_start(): bool {
256 $has_start = $this->has_start;
257 $this->has_start = false;
258
259 return $has_start;
260 }
261
262 /**
263 * @since 3.0.1
264 *
265 * @return int
266 */
267 public function get_page_offset(): int {
268 return $this->page_offset;
269 }
270
271 /**
272 * @since 3.0.1
273 *
274 * @param int $offset
275 */
276 public function set_page_offset( int $offset ) {
277 $this->page_offset = $offset;
278 }
279
280 }
281