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