PluginProbe
JetFormBuilder — Dynamic Blocks Form Builder / 3.6.6
JetFormBuilder — Dynamic Blocks Form Builder v3.6.6
3.6.6.1 3.6.6 3.6.5.4 3.6.5.3 3.6.5.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 All 134 releases
← All changes | includes/form-manager.php +94 -148 1.1.1 → 3.6.6 View file →
@@ -1,148 +1,94 @@
1 -<?php
2 -
3 -
4 -namespace Jet_Form_Builder;
5 -
6 -use Jet_Form_Builder\Gateways\Gateway_Manager;
7 -use Jet_Form_Builder\Generators\Get_From_DB;
8 -use Jet_Form_Builder\Generators\Get_From_Field;
9 -use Jet_Form_Builder\Generators\Num_Range;
10 -use Jet_Form_Builder\Shortcodes\Manager;
11 -
12 -
13 -// If this file is called directly, abort.
14 -if ( ! defined( 'WPINC' ) ) {
15 - die();
16 -}
17 -
18 -class Form_Manager {
19 - public $generators = false;
20 - public $builder;
21 - private $result_fields = array();
22 -
23 - const NAMESPACE_FIELDS = 'jet-forms/';
24 -
25 - public function __construct() {
26 - if ( Plugin::instance()->allow_gateways ) {
27 - Gateway_Manager::instance();
28 - }
29 -
30 - Manager::instance();
31 - }
32 -
33 - /**
34 - * Returns all instances of options generators classes
35 - *
36 - * @return [type] [description]
37 - */
38 - public function get_options_generators() {
39 -
40 - if ( false === $this->generators ) {
41 -
42 - $instances = array(
43 - new Num_Range(),
44 - new Get_From_DB(),
45 - new Get_From_Field(),
46 - );
47 -
48 - $instances = apply_filters( 'jet-form-builder/forms/options-generators', $instances, $this );
49 -
50 - foreach ( $instances as $instance ) {
51 - if ( $instance->can_generate() ) {
52 - $this->generators[ $instance->get_id() ] = $instance;
53 - }
54 - }
55 -
56 - }
57 -
58 - return $this->generators;
59 - }
60 -
61 - /**
62 - * Returns form fields,
63 - * parsed from post_content
64 - *
65 - * @param $content
66 - *
67 - * @return array[]
68 - */
69 - public function get_fields( $content ) {
70 - return parse_blocks( $content );
71 - }
72 -
73 - public function is_not_field( $block_name ) {
74 - return (
75 - stripos(
76 - $block_name,
77 - self::NAMESPACE_FIELDS
78 - ) === false
79 - );
80 - }
81 -
82 - public function is_field( $block_name, $needle ) {
83 - return stristr( $block_name, $needle );
84 - }
85 -
86 - public function get_form_blocks( $form_id ) {
87 - return $this->get_fields( get_post( $form_id )->post_content );
88 - }
89 -
90 - public function prepare_fields_names( $block_name ) {
91 - return "jet-forms/$block_name";
92 - }
93 -
94 - public function get_only_form_fields( $form_id, $exclude = array(), $recursive = true ) {
95 - $content = $this->get_form_blocks( $form_id );
96 - $exclude = array_map( array( $this, 'prepare_fields_names' ), $exclude );
97 -
98 - $this->result_fields = array();
99 - $this->get_inner_fields( $content, $exclude, $recursive );
100 -
101 - return $this->result_fields;
102 - }
103 -
104 -
105 - private function get_inner_fields( $source, $exclude, $recursive = true ) {
106 - foreach ( $source as $block ) {
107 -
108 - if ( ! $this->is_not_field( $block['blockName'] ) && ! in_array( $block['blockName'], $exclude ) ) {
109 - $this->result_fields[] = $block;
110 - }
111 -
112 - if ( $recursive && ! empty( $block['innerBlocks'] ) ) {
113 - $this->get_inner_fields( $block['innerBlocks'], $exclude, true );
114 - }
115 - }
116 - }
117 -
118 -
119 - /**
120 - * Returns generators list
121 - *
122 - * @return [type] [description]
123 - */
124 - public function get_generators_list() {
125 -
126 - $generators = $this->get_options_generators();
127 - $result = array(
128 - 0 => __( 'Select function...', 'jet-form-builder' ),
129 - );
130 -
131 - foreach ( $generators as $id => $generator ) {
132 - $result[ $id ] = $generator->get_name();
133 - }
134 -
135 - return $result;
136 -
137 - }
138 -
139 - public function field_name( $blockName ) {
140 - return explode( self::NAMESPACE_FIELDS, $blockName )[1];
141 - }
142 -
143 - public function get_form_content( $form_id ) {
144 - return get_post( $form_id )->post_content;
145 - }
146 -
147 -
148 -}
1 +<?php
2 +
3 +
4 +namespace Jet_Form_Builder;
5 +
6 +use Jet_Form_Builder\Blocks\Block_Helper;
7 +use Jet_Form_Builder\Generators\Get_From_DB;
8 +use Jet_Form_Builder\Generators\Get_From_Rest_Api;
9 +use Jet_Form_Builder\Generators\Get_From_Users;
10 +use Jet_Form_Builder\Generators\Get_Related_Posts;
11 +use Jet_Form_Builder\Generators\Num_Range;
12 +use Jet_Form_Builder\Generators\Num_Range_Manual;
13 +
14 +// If this file is called directly, abort.
15 +if ( ! defined( 'WPINC' ) ) {
16 + die();
17 +}
18 +
19 +class Form_Manager {
20 +
21 + public $generators = false;
22 + public $builder;
23 +
24 + const NAMESPACE_FIELDS = 'jet-forms/';
25 +
26 + /**
27 + * Returns all instances of options generators classes
28 + *
29 + * @return [type] [description]
30 + */
31 + public function get_options_generators() {
32 +
33 + if ( false === $this->generators ) {
34 +
35 + $instances = apply_filters(
36 + 'jet-form-builder/forms/options-generators',
37 + array(
38 + new Num_Range(),
39 + new Num_Range_Manual(),
40 + new Get_From_DB(),
41 + new Get_From_Users(),
42 + new Get_Related_Posts(),
43 + new Get_From_Rest_Api(),
44 + ),
45 + $this
46 + );
47 +
48 + $this->generators = array();
49 +
50 + foreach ( $instances as $instance ) {
51 + if ( $instance->can_generate() ) {
52 + $this->generators[ $instance->get_id() ] = $instance;
53 + }
54 + }
55 + }
56 +
57 + return $this->generators;
58 + }
59 +
60 +
61 + /**
62 + * Returns generators list
63 + *
64 + * @return [type] [description]
65 + */
66 + public function get_generators_list() {
67 +
68 + $generators = $this->get_options_generators();
69 + $result = array(
70 + 0 => __( 'Select function...', 'jet-form-builder' ),
71 + );
72 +
73 + foreach ( $generators as $id => $generator ) {
74 + $result[ $id ] = $generator->get_name();
75 + }
76 +
77 + return $result;
78 + }
79 +
80 + public function get_only_form_fields( $form_id ): array {
81 + $content = Block_Helper::get_blocks_by_post( $form_id );
82 +
83 + return Block_Helper::filter_blocks_by_namespace( $content );
84 + }
85 +
86 + public function get_field_by_name( $form_id, $field_name, $blocks = array() ): array {
87 + if ( ! $blocks ) {
88 + $blocks = Block_Helper::get_blocks_by_post( $form_id );
89 + }
90 +
91 + return Block_Helper::find_block_by_name( $field_name, $blocks );
92 + }
93 +
94 +}