PluginProbe
JetFormBuilder — Dynamic Blocks Form Builder / 3.6.2.1
JetFormBuilder — Dynamic Blocks Form Builder v3.6.2.1
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 1.1.2 1.1.3 1.1.4 1.1.5 All 130 releases
jetformbuilder / includes / plugin.php
plugin.php
255 lines 5.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Jet_Form_Builder;
4
5 // If this file is called directly, abort.
6 use Jet_Form_Builder\Actions\Manager as ActionsManager;
7 use Jet_Form_Builder\Admin\Pages\Pages_Manager;
8 use Jet_Form_Builder\Blocks\Conditional_Block\Render_State;
9 use Jet_Form_Builder\Blocks\Dynamic_Value;
10 use Jet_Form_Builder\Classes\Regexp_Tools;
11 use Jet_Form_Builder\Exceptions\Repository_Exception;
12 use Jet_Form_Builder\Form_Messages;
13 use Jet_Form_Builder\Form_Patterns\Manager as PatternsManager;
14 use Jet_Form_Builder\Addons\Manager as AddonsManager;
15 use JFB_Compatibility\Compatibility_Controller;
16 use JFB_Components\Module\Base_Module_After_Install_It;
17 use JFB_Components\Module\Base_Module_Dir_It;
18 use JFB_Components\Module\Base_Module_Handle_It;
19 use JFB_Components\Module\Base_Module_It;
20 use JFB_Components\Module\Base_Module_Url_It;
21 use JFB_Modules\Modules_Controller;
22 use Jet_Form_Builder\Presets\Preset_Manager;
23
24 if ( ! defined( 'WPINC' ) ) {
25 die;
26 }
27
28 /**
29 * @property ActionsManager $actions
30 * @property Form_Manager $form
31 * @property Form_Handler $form_handler
32 * @property Admin\Editor $editor
33 * @property AddonsManager $addons_manager
34 * @property Form_Messages\Msg_Router $msg_router
35 * @property Regexp_Tools $regexp
36 *
37 * Class Plugin
38 * @package Jet_Form_Builder
39 */
40 final class Plugin {
41
42 public $actions;
43 public $form;
44 public $form_handler;
45 public $editor;
46 public $framework;
47 public $addons_manager;
48 public $msg_router;
49 public $regexp;
50
51 private $modules_controller;
52 private $compat_controller;
53
54 public static $instance;
55
56 public function init_plugin() {
57 do_action( 'jet-form-builder/before-init' );
58
59 jet_form_builder()->init_components();
60
61 do_action( 'jet-form-builder/after-init' );
62 }
63
64 /**
65 * Initialize plugin parts
66 *
67 * @return void
68 */
69 public function init_components() {
70 $this->get_modules()->rep_install();
71 $this->get_compat()->rep_install();
72
73 $this->get_modules()->init_hooks();
74 $this->get_compat()->init_hooks();
75
76 $this->msg_router = new Form_Messages\Msg_Router();
77 $this->actions = new Actions\Manager();
78 $this->form = new Form_Manager();
79 $this->form_handler = new Form_Handler();
80 $this->addons_manager = new AddonsManager();
81 $this->regexp = new Regexp_Tools();
82
83 /**
84 * Modules & components
85 */
86 File_Upload::instance();
87 Render_State::instance();
88 new Dynamic_Value();
89
90 /**
91 * REST API
92 */
93 ( new Blocks\Conditional_Block\Rest_Api\Rest_Api_Controller() )->rest_api_init();
94
95 if ( is_admin() ) {
96 Preset_Manager::instance();
97
98 $this->editor = new Admin\Editor();
99 Pages_Manager::instance()->set_up();
100
101 new PatternsManager();
102 } else {
103 $this->form_handler->call_form();
104 }
105 }
106
107 /**
108 * Loads the translation files.
109 *
110 * @return void
111 * @since 1.0.0
112 * @access public
113 */
114 public function init_lang() {
115 load_plugin_textdomain(
116 'jet-form-builder',
117 false,
118 dirname( plugin_basename( JET_FORM_BUILDER__FILE__ ) ) . '/languages'
119 );
120 }
121
122 /**
123 * Returns url to file or dir inside plugin folder
124 *
125 * @param string $path Path inside plugin dir.
126 *
127 * @return string
128 */
129 public function plugin_url( string $path = '' ): string {
130 return JET_FORM_BUILDER_URL . $path;
131 }
132
133 public function plugin_dir( string $path = '' ): string {
134 return JET_FORM_BUILDER_PATH . $path;
135 }
136
137 /**
138 * Returns plugin version
139 */
140 public function get_version(): string {
141 return JET_FORM_BUILDER_VERSION;
142 }
143
144 /**
145 * @param string $name_or_class
146 *
147 * @return Base_Module_It|Base_Module_Handle_It|Base_Module_Url_It|Base_Module_Dir_It|Base_Module_After_Install_It
148 * @throws Exceptions\Repository_Exception
149 */
150 public function module( string $name_or_class ): Base_Module_It {
151 return $this->get_modules()->module( $name_or_class );
152 }
153
154 public function has_module( string $name_or_class ): bool {
155 return $this->get_modules()->has_module( $name_or_class );
156 }
157
158 public function get_modules(): Modules_Controller {
159 if ( is_null( $this->modules_controller ) ) {
160 $this->modules_controller = new Modules_Controller();
161 }
162
163 return $this->modules_controller;
164 }
165
166 /**
167 * @param string $name_or_class
168 *
169 * @return Base_Module_It|Base_Module_Handle_It|Base_Module_Url_It|Base_Module_Dir_It|Base_Module_After_Install_It
170 * @throws Exceptions\Repository_Exception
171 */
172 public function compat( string $name_or_class ): Base_Module_It {
173 return $this->get_compat()->module( $name_or_class );
174 }
175
176 public function has_compat( string $name_or_class ): bool {
177 return $this->get_compat()->has_module( $name_or_class );
178 }
179
180 public function get_compat(): Compatibility_Controller {
181 if ( is_null( $this->compat_controller ) ) {
182 $this->compat_controller = new Compatibility_Controller();
183 }
184
185 return $this->compat_controller;
186 }
187
188 /**
189 * Instance.
190 *
191 * Ensures only one instance of the plugin class is loaded or can be loaded.
192 *
193 * @since 1.0.0
194 * @access public
195 * @static
196 */
197 public static function instance() {
198
199 if ( is_null( self::$instance ) ) {
200 self::$instance = new self();
201 }
202
203 return self::$instance;
204 }
205
206 public static function clear() {
207 self::$instance = null;
208 }
209
210 /**
211 * Register autoloader.
212 */
213 public function register_autoloader() {
214 require JET_FORM_BUILDER_PATH . 'includes' . DIRECTORY_SEPARATOR . 'autoloader.php';
215 Autoloader::run();
216 }
217
218 /**
219 * Backward compatibility to deprecated properties
220 *
221 * @param $name
222 *
223 * @return mixed
224 */
225 public function __get( $name ) {
226 switch ( $name ) {
227 case 'blocks':
228 try {
229 return jet_form_builder()->module( 'blocks' );
230 } catch ( Repository_Exception $exception ) {
231 return null;
232 }
233 case 'allow_gateways':
234 return jet_form_builder()->has_module( 'gateways' );
235 case 'post_type':
236 try {
237 return jet_form_builder()->module( 'post-type' );
238 } catch ( Repository_Exception $exception ) {
239 return null;
240 }
241 }
242
243 return null;
244 }
245
246 public function __isset( $name ) {
247 switch ( $name ) {
248 case 'allow_gateways':
249 return true;
250 }
251 return false;
252 }
253
254 }
255