| 1 |
<?php |
| 2 |
namespace Elementor\Core\Common; |
| 3 |
|
| 4 |
use Elementor\Core\Base\App as BaseApp; |
| 5 |
use Elementor\Core\Common\Modules\Ajax\Module as Ajax; |
| 6 |
use Elementor\Core\Common\Modules\Finder\Module as Finder; |
| 7 |
use Elementor\Core\Common\Modules\Connect\Module as Connect; |
| 8 |
use Elementor\Core\Common\Modules\EventTracker\Module as Event_Tracker; |
| 9 |
use Elementor\Core\Common\Modules\EventsManager\Module as Events_Manager; |
| 10 |
use Elementor\Core\Files\Uploads_Manager; |
| 11 |
use Elementor\Icons_Manager; |
| 12 |
use Elementor\Plugin; |
| 13 |
use Elementor\Utils; |
| 14 |
|
| 15 |
if ( ! defined( 'ABSPATH' ) ) { |
| 16 |
exit; // Exit if accessed directly. |
| 17 |
} |
| 18 |
|
| 19 |
/** |
| 20 |
* App |
| 21 |
* |
| 22 |
* Elementor's common app that groups shared functionality, components and configuration |
| 23 |
* |
| 24 |
* @since 2.3.0 |
| 25 |
*/ |
| 26 |
class App extends BaseApp { |
| 27 |
|
| 28 |
private $templates = []; |
| 29 |
|
| 30 |
/** |
| 31 |
* App constructor. |
| 32 |
* |
| 33 |
* @since 2.3.0 |
| 34 |
* @access public |
| 35 |
*/ |
| 36 |
public function __construct() { |
| 37 |
$this->add_default_templates(); |
| 38 |
|
| 39 |
add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'register_scripts' ], 9 ); |
| 40 |
add_action( 'admin_enqueue_scripts', [ $this, 'register_scripts' ], 9 ); |
| 41 |
add_action( 'wp_enqueue_scripts', [ $this, 'register_scripts' ], 9 ); |
| 42 |
|
| 43 |
add_action( 'elementor/editor/before_enqueue_styles', [ $this, 'register_styles' ] ); |
| 44 |
add_action( 'admin_enqueue_scripts', [ $this, 'register_styles' ] ); |
| 45 |
add_action( 'wp_enqueue_scripts', [ $this, 'register_styles' ], 9 ); |
| 46 |
|
| 47 |
add_action( 'elementor/editor/footer', [ $this, 'print_templates' ] ); |
| 48 |
add_action( 'admin_footer', [ $this, 'print_templates' ] ); |
| 49 |
add_action( 'wp_footer', [ $this, 'print_templates' ] ); |
| 50 |
} |
| 51 |
|
| 52 |
/** |
| 53 |
* Init components |
| 54 |
* |
| 55 |
* Initializing common components. |
| 56 |
* |
| 57 |
* @since 2.3.0 |
| 58 |
* @access public |
| 59 |
*/ |
| 60 |
public function init_components() { |
| 61 |
$this->add_component( 'ajax', new Ajax() ); |
| 62 |
|
| 63 |
if ( current_user_can( 'manage_options' ) ) { |
| 64 |
if ( ! is_customize_preview() ) { |
| 65 |
$this->add_component( 'finder', new Finder() ); |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
$this->add_component( 'connect', new Connect() ); |
| 70 |
|
| 71 |
$this->add_component( 'event-tracker', new Event_Tracker() ); |
| 72 |
|
| 73 |
Plugin::$instance->experiments->add_feature( Events_Manager::get_experimental_data() ); |
| 74 |
|
| 75 |
if ( Plugin::$instance->experiments->is_feature_active( Events_Manager::EXPERIMENT_NAME ) ) { |
| 76 |
$this->add_component( 'events-manager', new Events_Manager() ); |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
/** |
| 81 |
* Get name. |
| 82 |
* |
| 83 |
* Retrieve the app name. |
| 84 |
* |
| 85 |
* @since 2.3.0 |
| 86 |
* @access public |
| 87 |
* |
| 88 |
* @return string Common app name. |
| 89 |
*/ |
| 90 |
public function get_name() { |
| 91 |
return 'common'; |
| 92 |
} |
| 93 |
|
| 94 |
/** |
| 95 |
* Register scripts. |
| 96 |
* |
| 97 |
* Register common scripts. |
| 98 |
* |
| 99 |
* @since 2.3.0 |
| 100 |
* @access public |
| 101 |
*/ |
| 102 |
public function register_scripts() { |
| 103 |
wp_register_script( |
| 104 |
'elementor-common-modules', |
| 105 |
$this->get_js_assets_url( 'common-modules' ), |
| 106 |
[], |
| 107 |
ELEMENTOR_VERSION, |
| 108 |
true |
| 109 |
); |
| 110 |
|
| 111 |
wp_register_script( |
| 112 |
'backbone-marionette', |
| 113 |
$this->get_js_assets_url( 'backbone.marionette', 'assets/lib/backbone/' ), |
| 114 |
[ |
| 115 |
'backbone', |
| 116 |
], |
| 117 |
'2.4.5.e1', |
| 118 |
true |
| 119 |
); |
| 120 |
|
| 121 |
wp_register_script( |
| 122 |
'backbone-radio', |
| 123 |
$this->get_js_assets_url( 'backbone.radio', 'assets/lib/backbone/' ), |
| 124 |
[ |
| 125 |
'backbone', |
| 126 |
], |
| 127 |
'1.0.4', |
| 128 |
true |
| 129 |
); |
| 130 |
|
| 131 |
wp_register_script( |
| 132 |
'elementor-dialog', |
| 133 |
$this->get_js_assets_url( 'dialog', 'assets/lib/dialog/' ), |
| 134 |
[ |
| 135 |
'jquery-ui-position', |
| 136 |
], |
| 137 |
'4.9.0', |
| 138 |
true |
| 139 |
); |
| 140 |
|
| 141 |
wp_enqueue_script( |
| 142 |
'elementor-common', |
| 143 |
$this->get_js_assets_url( 'common' ), |
| 144 |
[ |
| 145 |
'jquery', |
| 146 |
'jquery-ui-draggable', |
| 147 |
'backbone-marionette', |
| 148 |
'backbone-radio', |
| 149 |
'elementor-common-modules', |
| 150 |
'elementor-web-cli', |
| 151 |
'elementor-dialog', |
| 152 |
'wp-api-request', |
| 153 |
'elementor-dev-tools', |
| 154 |
], |
| 155 |
ELEMENTOR_VERSION, |
| 156 |
true |
| 157 |
); |
| 158 |
|
| 159 |
wp_set_script_translations( 'elementor-common', 'elementor' ); |
| 160 |
|
| 161 |
$this->print_config(); |
| 162 |
|
| 163 |
// Used for external plugins. |
| 164 |
do_action( 'elementor/common/after_register_scripts', $this ); |
| 165 |
} |
| 166 |
|
| 167 |
/** |
| 168 |
* Register styles. |
| 169 |
* |
| 170 |
* Register common styles. |
| 171 |
* |
| 172 |
* @since 2.3.0 |
| 173 |
* @access public |
| 174 |
*/ |
| 175 |
public function register_styles() { |
| 176 |
wp_register_style( |
| 177 |
'elementor-icons', |
| 178 |
$this->get_css_assets_url( 'elementor-icons', 'assets/lib/eicons/css/' ), |
| 179 |
[], |
| 180 |
Icons_Manager::ELEMENTOR_ICONS_VERSION |
| 181 |
); |
| 182 |
|
| 183 |
wp_enqueue_style( |
| 184 |
'elementor-common', |
| 185 |
$this->get_css_assets_url( 'common', null, 'default', true ), |
| 186 |
[ |
| 187 |
'elementor-icons', |
| 188 |
], |
| 189 |
ELEMENTOR_VERSION |
| 190 |
); |
| 191 |
|
| 192 |
wp_enqueue_style( |
| 193 |
'e-theme-ui-light', |
| 194 |
$this->get_css_assets_url( 'theme-light' ), |
| 195 |
[], |
| 196 |
ELEMENTOR_VERSION |
| 197 |
); |
| 198 |
} |
| 199 |
|
| 200 |
/** |
| 201 |
* Add template. |
| 202 |
* |
| 203 |
* @since 2.3.0 |
| 204 |
* @access public |
| 205 |
* |
| 206 |
* @param string $template Can be either a link to template file or template |
| 207 |
* HTML content. |
| 208 |
* @param string $type Optional. Whether to handle the template as path |
| 209 |
* or text. Default is `path`. |
| 210 |
*/ |
| 211 |
public function add_template( $template, $type = 'path' ) { |
| 212 |
if ( 'path' === $type ) { |
| 213 |
ob_start(); |
| 214 |
|
| 215 |
include $template; |
| 216 |
|
| 217 |
$template = ob_get_clean(); |
| 218 |
} |
| 219 |
|
| 220 |
$this->templates[] = $template; |
| 221 |
} |
| 222 |
|
| 223 |
/** |
| 224 |
* Print Templates |
| 225 |
* |
| 226 |
* Prints all registered templates. |
| 227 |
* |
| 228 |
* @since 2.3.0 |
| 229 |
* @access public |
| 230 |
*/ |
| 231 |
public function print_templates() { |
| 232 |
foreach ( $this->templates as $template ) { |
| 233 |
echo $template; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 234 |
} |
| 235 |
} |
| 236 |
|
| 237 |
/** |
| 238 |
* Get init settings. |
| 239 |
* |
| 240 |
* Define the default/initial settings of the common app. |
| 241 |
* |
| 242 |
* @since 2.3.0 |
| 243 |
* @access protected |
| 244 |
* |
| 245 |
* @return array |
| 246 |
*/ |
| 247 |
protected function get_init_settings() { |
| 248 |
$active_experimental_features = Plugin::$instance->experiments->get_active_features(); |
| 249 |
$all_experimental_features = Plugin::$instance->experiments->get_features(); |
| 250 |
|
| 251 |
$active_experimental_features = array_fill_keys( array_keys( $active_experimental_features ), true ); |
| 252 |
$all_experimental_features = array_map( |
| 253 |
function( $feature ) { |
| 254 |
return Plugin::$instance->experiments->is_feature_active( $feature['name'] ); |
| 255 |
}, |
| 256 |
$all_experimental_features |
| 257 |
); |
| 258 |
|
| 259 |
$config = [ |
| 260 |
'version' => ELEMENTOR_VERSION, |
| 261 |
'isRTL' => is_rtl(), |
| 262 |
'isDebug' => ( defined( 'WP_DEBUG' ) && WP_DEBUG ), |
| 263 |
'isElementorDebug' => Utils::is_elementor_debug(), |
| 264 |
'activeModules' => array_keys( $this->get_components() ), |
| 265 |
'experimentalFeatures' => $active_experimental_features, |
| 266 |
'allExperimentalFeatures' => $all_experimental_features, |
| 267 |
'urls' => [ |
| 268 |
'assets' => ELEMENTOR_ASSETS_URL, |
| 269 |
'rest' => get_rest_url(), |
| 270 |
], |
| 271 |
'filesUpload' => [ |
| 272 |
'unfilteredFiles' => Uploads_Manager::are_unfiltered_uploads_enabled(), |
| 273 |
], |
| 274 |
'editor_events' => Events_Manager::get_editor_events_config(), |
| 275 |
]; |
| 276 |
|
| 277 |
/** |
| 278 |
* Localize common settings. |
| 279 |
* |
| 280 |
* Filters the editor localized settings. |
| 281 |
* |
| 282 |
* @since 1.0.0 |
| 283 |
* |
| 284 |
* @param array $config Common configuration. |
| 285 |
*/ |
| 286 |
return apply_filters( 'elementor/common/localize_settings', $config ); |
| 287 |
} |
| 288 |
|
| 289 |
/** |
| 290 |
* Add default templates. |
| 291 |
* |
| 292 |
* Register common app default templates. |
| 293 |
* |
| 294 |
* @since 2.3.0 |
| 295 |
* @access private |
| 296 |
*/ |
| 297 |
private function add_default_templates() { |
| 298 |
$default_templates = [ |
| 299 |
'includes/editor-templates/library-layout.php', |
| 300 |
]; |
| 301 |
|
| 302 |
foreach ( $default_templates as $template ) { |
| 303 |
$this->add_template( ELEMENTOR_PATH . $template ); |
| 304 |
} |
| 305 |
} |
| 306 |
} |
| 307 |
|