first commit

This commit is contained in:
2024-10-28 22:14:22 +01:00
commit b65352c452
40581 changed files with 5712079 additions and 0 deletions

View File

@@ -0,0 +1,79 @@
<?php
/**
* 2007-2022 Apollotheme
*
* NOTICE OF LICENSE
*
* LeoElements is module help you can build content for your shop
*
* DISCLAIMER
*
* @author Apollotheme <apollotheme@gmail.com>
* @copyright 2007-2022 Apollotheme
* @license http://apollotheme.com - prestashop template provider
*/
namespace LeoElements\Core\Base;
use LeoElements\Utils;
use LeoElements\Leo_Helper;
if ( ! defined( '_PS_VERSION_' ) ) {
exit; // Exit if accessed directly
}
/**
* Base App
*
* Base app utility class that provides shared functionality of apps.
*
* @since 1.0.0
*/
abstract class App extends Module {
/**
* Print config.
*
* Used to print the app and its components settings as a JavaScript object.
*
* @param string $handle Optional
*
* @since 1.0.0
* @since 1.0.0 added the `$handle` parameter
* @access protected
*/
final protected function print_config( $handle = null ) {
$name = $this->get_name();
$js_var = 'elementor' . str_replace( ' ', '', ucwords( str_replace( '-', ' ', $name ) ) ) . 'Config';
$config = $this->get_settings() + $this->get_components_config();
if ( ! $handle ) {
$handle = 'elementor-' . $name;
}
Utils::print_js_config( $handle, $js_var, $config );
}
/**
* Get components config.
*
* Retrieves the app components settings.
*
* @since 1.0.0
* @access private
*
* @return array
*/
private function get_components_config() {
$settings = [];
foreach ( $this->get_components() as $id => $instance ) {
$settings[ $id ] = $instance->get_settings();
}
return $settings;
}
}

View File

@@ -0,0 +1,101 @@
<?php
/**
* 2007-2022 Apollotheme
*
* NOTICE OF LICENSE
*
* LeoElements is module help you can build content for your shop
*
* DISCLAIMER
*
* @author Apollotheme <apollotheme@gmail.com>
* @copyright 2007-2022 Apollotheme
* @license http://apollotheme.com - prestashop template provider
*/
namespace LeoElements\Core\Base;
use LeoElements\Core\Base\Module as BaseModule;
use LeoElements\Plugin;
use LeoElements\Leo_Helper;
if ( ! defined( '_PS_VERSION_' ) ) {
exit; // Exit if accessed directly
}
abstract class Background_Task_Manager extends BaseModule {
/**
* @var Background_Task
*/
protected $task_runner;
abstract public function get_action();
abstract public function get_plugin_name();
abstract public function get_plugin_label();
abstract public function get_task_runner_class();
abstract public function get_query_limit();
abstract protected function start_run();
public function on_runner_start() {
$logger = Plugin::$instance->logger->get_logger();
$logger->info( $this->get_plugin_name() . '::' . $this->get_action() . ' Started' );
}
public function on_runner_complete( $did_tasks = false ) {
$logger = Plugin::$instance->logger->get_logger();
$logger->info( $this->get_plugin_name() . '::' . $this->get_action() . ' Completed' );
}
public function get_task_runner() {
if ( empty( $this->task_runner ) ) {
$class_name = $this->get_task_runner_class();
$this->task_runner = new $class_name( $this );
}
return $this->task_runner;
}
// TODO: Replace with a db settings system.
protected function add_flag( $flag ) {
return Leo_Helper::add_option( $this->get_plugin_name() . '_' . $this->get_action() . '_' . $flag, 1 );
}
protected function get_flag( $flag ) {
return Leo_Helper::get_option( $this->get_plugin_name() . '_' . $this->get_action() . '_' . $flag );
}
protected function delete_flag( $flag ) {
return Leo_Helper::delete_option( $this->get_plugin_name() . '_' . $this->get_action() . '_' . $flag );
}
protected function get_start_action_url() {
return wp_nonce_url( add_query_arg( $this->get_action(), 'run' ), $this->get_action() . 'run' );
}
protected function get_continue_action_url() {
return wp_nonce_url( add_query_arg( $this->get_action(), 'continue' ), $this->get_action() . 'continue' );
}
private function continue_run() {
$runner = $this->get_task_runner();
$runner->continue_run();
}
public function __construct() {
if ( empty( Tools::getValue($this->get_action())) ) {
return;
}
if ( 'run' === Tools::getValue($this->get_action()) && check_admin_referer( $this->get_action() . 'run' ) ) {
$this->start_run();
}
if ( 'continue' === Tools::getValue($this->get_action()) && check_admin_referer( $this->get_action() . 'continue' ) ) {
$this->continue_run();
}
wp_safe_redirect( remove_query_arg( [ $this->get_action(), '_wpnonce' ] ) );
die;
}
}

View File

@@ -0,0 +1,395 @@
<?php
/**
* 2007-2022 Apollotheme
*
* NOTICE OF LICENSE
*
* LeoElements is module help you can build content for your shop
*
* DISCLAIMER
*
* @author Apollotheme <apollotheme@gmail.com>
* @copyright 2007-2022 Apollotheme
* @license http://apollotheme.com - prestashop template provider
*/
namespace LeoElements\Core\Base;
use LeoElements\Plugin;
use LeoElements\Leo_Helper;
/**
* Based on https://github.com/woocommerce/woocommerce/blob/master/includes/abstracts/class-wc-background-process.php
* & https://github.com/woocommerce/woocommerce/blob/master/includes/class-wc-background-updater.php
*/
defined( '_PS_VERSION_' ) || exit;
include_once LEOELEMENTS_PATH . '/includes/libraries/wp-background-process/wp-async-request.php';
include_once LEOELEMENTS_PATH . '/includes/libraries/wp-background-process/wp-background-process.php';
/**
* WC_Background_Process class.
*/
abstract class Background_Task extends \WP_Background_Process {
protected $current_item;
/**
* Dispatch updater.
*
* Updater will still run via cron job if this fails for any reason.
*/
public function dispatch() {
$dispatched = parent::dispatch();
if ( Leo_Helper::is_wp_error( $dispatched ) ) {
wp_die( $dispatched );
}
}
public function query_col( $sql ) {
$wpdb = &$GLOBALS['wpdb'];
// Add Calc.
$item = $this->get_current_item();
if ( empty( $item['total'] ) ) {
$sql = preg_replace( '/^SELECT/', 'SELECT SQL_CALC_FOUND_ROWS', $sql );
}
// Add offset & limit.
$sql = preg_replace( '/;$/', '', $sql );
$sql .= ' LIMIT %d, %d;';
$results = $wpdb->get_col( $wpdb->prepare( $sql, $this->get_current_offset(), $this->get_limit() ) ); // WPCS: unprepared SQL OK.
if ( ! empty( $results ) ) {
$this->set_total();
}
return $results;
}
public function should_run_again( $updated_rows ) {
return count( $updated_rows ) === $this->get_limit();
}
public function get_current_offset() {
$limit = $this->get_limit();
return ( $this->current_item['iterate_num'] - 1 ) * $limit;
}
public function get_limit() {
return $this->manager->get_query_limit();
}
public function set_total() {
$wpdb = &$GLOBALS['wpdb'];
if ( empty( $this->current_item['total'] ) ) {
$total_rows = $wpdb->get_var( 'SELECT FOUND_ROWS();' );
$total_iterates = ceil( $total_rows / $this->get_limit() );
$this->current_item['total'] = $total_iterates;
}
}
/**
* Complete
*
* Override if applicable, but ensure that the below actions are
* performed, or, call parent::complete().
*/
protected function complete() {
$this->manager->on_runner_complete( true );
parent::complete();
}
public function continue_run() {
// Used to fire an action added in WP_Background_Process::_construct() that calls WP_Background_Process::handle_cron_healthcheck().
// This method will make sure the database updates are executed even if cron is disabled. Nothing will happen if the updates are already running.
Leo_Helper::do_action( $this->cron_hook_identifier );
}
/**
* @return mixed
*/
public function get_current_item() {
return $this->current_item;
}
/**
* Get batch.
*
* @return \stdClass Return the first batch from the queue.
*/
protected function get_batch() {
$batch = parent::get_batch();
$batch->data = array_filter( (array) $batch->data );
return $batch;
}
/**
* Handle cron healthcheck
*
* Restart the background process if not already running
* and data exists in the queue.
*/
public function handle_cron_healthcheck() {
if ( $this->is_process_running() ) {
// Background process already running.
return;
}
if ( $this->is_queue_empty() ) {
// No data to process.
$this->clear_scheduled_event();
return;
}
$this->handle();
}
/**
* Schedule fallback event.
*/
protected function schedule_event() {
if ( ! wp_next_scheduled( $this->cron_hook_identifier ) ) {
wp_schedule_event( time() + 10, $this->cron_interval_identifier, $this->cron_hook_identifier );
}
}
/**
* Is the updater running?
*
* @return boolean
*/
public function is_running() {
return false === $this->is_queue_empty();
}
/**
* See if the batch limit has been exceeded.
*
* @return bool
*/
protected function batch_limit_exceeded() {
return $this->time_exceeded() || $this->memory_exceeded();
}
/**
* Handle.
*
* Pass each queue item to the task handler, while remaining
* within server memory and time limit constraints.
*/
protected function handle() {
$this->manager->on_runner_start();
$this->lock_process();
do {
$batch = $this->get_batch();
foreach ( $batch->data as $key => $value ) {
$task = $this->task( $value );
if ( false !== $task ) {
$batch->data[ $key ] = $task;
} else {
unset( $batch->data[ $key ] );
}
if ( $this->batch_limit_exceeded() ) {
// Batch limits reached.
break;
}
}
// Update or delete current batch.
if ( ! empty( $batch->data ) ) {
$this->update( $batch->key, $batch->data );
} else {
$this->delete( $batch->key );
}
} while ( ! $this->batch_limit_exceeded() && ! $this->is_queue_empty() );
$this->unlock_process();
// Start next batch or complete process.
if ( ! $this->is_queue_empty() ) {
$this->dispatch();
} else {
$this->complete();
}
}
/**
* Use the protected `is_process_running` method as a public method.
* @return bool
*/
public function is_process_locked() {
return $this->is_process_running();
}
public function handle_immediately( $callbacks ) {
$this->manager->on_runner_start();
$this->lock_process();
foreach ( $callbacks as $callback ) {
$item = [
'callback' => $callback,
];
do {
$item = $this->task( $item );
} while ( $item );
}
$this->unlock_process();
}
/**
* Task
*
* Override this method to perform any actions required on each
* queue item. Return the modified item for further processing
* in the next pass through. Or, return false to remove the
* item from the queue.
*
* @param array $item
*
* @return array|bool
*/
protected function task( $item ) {
$result = false;
if ( ! isset( $item['iterate_num'] ) ) {
$item['iterate_num'] = 1;
}
$logger = Plugin::$instance->logger->get_logger();
$callback = $this->format_callback_log( $item );
if ( is_callable( $item['callback'] ) ) {
$progress = '';
if ( 1 < $item['iterate_num'] ) {
if ( empty( $item['total'] ) ) {
$progress = sprintf( '(x%s)', $item['iterate_num'] );
} else {
$percent = ceil( $item['iterate_num'] / ( $item['total'] / 100 ) );
$progress = sprintf( '(%s of %s, %s%%)', $item['iterate_num'], $item['total'], $percent );
}
}
$logger->info( sprintf( '%s Start %s', $callback, $progress ) );
$this->current_item = $item;
$result = (bool) call_user_func( $item['callback'], $this );
// get back the updated item.
$item = $this->current_item;
$this->current_item = null;
if ( $result ) {
if ( empty( $item['total'] ) ) {
$logger->info( sprintf( '%s callback needs to run again', $callback ) );
} elseif ( 1 === $item['iterate_num'] ) {
$logger->info( sprintf( '%s callback needs to run more %d times', $callback, $item['total'] - $item['iterate_num'] ) );
}
$item['iterate_num']++;
} else {
$logger->info( sprintf( '%s Finished', $callback ) );
}
} else {
$logger->notice( sprintf( 'Could not find %s callback', $callback ) );
}
return $result ? $item : false;
}
/**
* Schedule cron healthcheck.
*
* @param array $schedules Schedules.
* @return array
*/
public function schedule_cron_healthcheck( $schedules ) {
$interval = Leo_Helper::apply_filters( $this->identifier . '_cron_interval', 5 );
// Adds every 5 minutes to the existing schedules.
$schedules[ $this->identifier . '_cron_interval' ] = array(
'interval' => LEO_MINUTE_IN_SECONDS * $interval,
/* translators: %d: interval */
'display' => sprintf( Leo_Helper::__( 'Every %d minutes', 'elementor' ), $interval ),
);
return $schedules;
}
/**
* See if the batch limit has been exceeded.
*
* @return bool
*/
public function is_memory_exceeded() {
return $this->memory_exceeded();
}
/**
* Delete all batches.
*
* @return self
*/
public function delete_all_batches() {
$wpdb = &$GLOBALS['wpdb'];
$table = $wpdb->options;
$column = 'option_name';
if ( is_multisite() ) {
$table = $wpdb->sitemeta;
$column = 'meta_key';
}
$key = $wpdb->esc_like( $this->identifier . '_batch_' ) . '%';
$wpdb->query( $wpdb->prepare( "DELETE FROM {$table} WHERE {$column} LIKE %s", $key ) ); // @codingStandardsIgnoreLine.
return $this;
}
/**
* Kill process.
*
* Stop processing queue items, clear cronjob and delete all batches.
*/
public function kill_process() {
if ( ! $this->is_queue_empty() ) {
$this->delete_all_batches();
wp_clear_scheduled_hook( $this->cron_hook_identifier );
}
}
protected function format_callback_log( $item ) {
return implode( '::', (array) $item['callback'] );
}
/**
* @var \Elementor\Core\Base\Background_Task_Manager
*/
protected $manager;
public function __construct( $manager ) {
$this->manager = $manager;
// Uses unique prefix per blog so each blog has separate queue.
$this->prefix = 'elementor_' . get_current_blog_id();
$this->action = $this->manager->get_action();
parent::__construct();
}
}

View File

@@ -0,0 +1,150 @@
<?php
/**
* 2007-2022 Apollotheme
*
* NOTICE OF LICENSE
*
* LeoElements is module help you can build content for your shop
*
* DISCLAIMER
*
* @author Apollotheme <apollotheme@gmail.com>
* @copyright 2007-2022 Apollotheme
* @license http://apollotheme.com - prestashop template provider
*/
namespace LeoElements\Core\Base;
use LeoElements\Leo_Helper;
if ( ! defined( '_PS_VERSION_' ) ) {
exit; // Exit if accessed directly
}
/**
* Base Object
*
* Base class that provides basic settings handling functionality.
*
* @since 1.0.0
*/
class Base_Object {
/**
* Settings.
*
* Holds the object settings.
*
* @access private
*
* @var array
*/
private $settings;
/**
* Get Settings.
*
* @since 1.0.0
* @access public
*
* @param string $setting Optional. The key of the requested setting. Default is null.
*
* @return mixed An array of all settings, or a single value if `$setting` was specified.
*/
final public function get_settings( $setting = null ) {
$this->ensure_settings();
return self::get_items( $this->settings, $setting );
}
/**
* Set settings.
*
* @since 1.0.0
* @access public
*
* @param array|string $key If key is an array, the settings are overwritten by that array. Otherwise, the
* settings of the key will be set to the given `$value` param.
*
* @param mixed $value Optional. Default is null.
*/
final public function set_settings( $key, $value = null ) {
$this->ensure_settings();
if ( is_array( $key ) ) {
$this->settings = $key;
} else {
$this->settings[ $key ] = $value;
}
}
/**
* Delete setting.
*
* Deletes the settings array or a specific key of the settings array if `$key` is specified.
* @since 1.0.0
* @access public
*
* @param string $key Optional. Default is null.
*/
public function delete_setting( $key = null ) {
if ( $key ) {
unset( $this->settings[ $key ] );
} else {
$this->settings = [];
}
}
/**
* Get items.
*
* Utility method that receives an array with a needle and returns all the
* items that match the needle. If needle is not defined the entire haystack
* will be returned.
*
* @since 1.0.0
* @access protected
* @static
*
* @param array $haystack An array of items.
* @param string $needle Optional. Needle. Default is null.
*
* @return mixed The whole haystack or the needle from the haystack when requested.
*/
final protected static function get_items( array $haystack, $needle = null ) {
if ( $needle ) {
return isset( $haystack[ $needle ] ) ? $haystack[ $needle ] : null;
}
return $haystack;
}
/**
* Get init settings.
*
* Used to define the default/initial settings of the object. Inheriting classes may implement this method to define
* their own default/initial settings.
*
* @since 1.0.0
* @access protected
*
* @return array
*/
protected function get_init_settings() {
return [];
}
/**
* Ensure settings.
*
* Ensures that the `$settings` member is initialized
*
* @since 1.0.0
* @access private
*/
private function ensure_settings() {
if ( null === $this->settings ) {
$this->settings = $this->get_init_settings();
}
}
}

View File

@@ -0,0 +1,193 @@
<?php
/**
* 2007-2022 Apollotheme
*
* NOTICE OF LICENSE
*
* LeoElements is module help you can build content for your shop
*
* DISCLAIMER
*
* @author Apollotheme <apollotheme@gmail.com>
* @copyright 2007-2022 Apollotheme
* @license http://apollotheme.com - prestashop template provider
*/
namespace LeoElements\Core\Base;
use LeoElements\Plugin;
use LeoElements\Leo_Helper;
if ( ! defined( '_PS_VERSION_' ) ) {
exit; // Exit if accessed directly
}
abstract class DB_Upgrades_Manager extends Background_Task_Manager {
protected $current_version = null;
abstract public function get_new_version();
abstract public function get_version_option_name();
abstract public function get_upgrades_class();
abstract public function get_updater_label();
public function get_task_runner_class() {
return 'LeoElements\Core\Upgrade\Updater';
}
public function get_query_limit() {
return 100;
}
public function get_current_version() {
if ( null === $this->current_version ) {
$this->current_version = Leo_Helper::get_option( $this->get_version_option_name() );
}
return $this->current_version;
}
public function should_upgrade() {
$current_version = $this->get_current_version();
// It's a new install.
if ( ! $current_version ) {
$this->update_db_version();
return false;
}
return version_compare( $this->get_new_version(), $current_version, '>' );
}
public function on_runner_start() {
parent::on_runner_start();
define( 'IS_LEOELEMENTS_UPGRADE', true );
}
public function on_runner_complete( $did_tasks = false ) {
$logger = Plugin::$instance->logger->get_logger();
$logger->info( 'Elementor data updater process has been completed.', [
'meta' => [
'plugin' => $this->get_plugin_label(),
'from' => $this->current_version,
'to' => $this->get_new_version(),
],
] );
Plugin::$instance->files_manager->clear_cache();
$this->update_db_version();
if ( $did_tasks ) {
$this->add_flag( 'completed' );
}
}
public function admin_notice_start_upgrade() {
$upgrade_link = $this->get_start_action_url();
$message = '<p>' . sprintf( Leo_Helper::__( '%s Your site database needs to be updated to the latest version.', 'elementor' ), $this->get_updater_label() ) . '</p>';
$message .= '<p>' . sprintf( '<a href="%s" class="button-primary">%s</a>', $upgrade_link, Leo_Helper::__( 'Update Now', 'elementor' ) ) . '</p>';
echo '<div class="notice notice-error">' . $message . '</div>';
}
public function admin_notice_upgrade_is_running() {
$upgrade_link = $this->get_continue_action_url();
$message = '<p>' . sprintf( Leo_Helper::__( '%s Database update process is running in the background.', 'elementor' ), $this->get_updater_label() ) . '</p>';
$message .= '<p>' . sprintf( 'Taking a while? <a href="%s" class="button-primary">Click here to run it now</a>', $upgrade_link ) . '</p>';
echo '<div class="notice notice-warning">' . $message . '</div>';
}
public function admin_notice_upgrade_is_completed() {
$this->delete_flag( 'completed' );
$message = '<p>' . sprintf( Leo_Helper::__( '%s The database update process is now complete. Thank you for updating to the latest version!', 'elementor' ), $this->get_updater_label() ) . '</p>';
echo '<div class="notice notice-success">' . $message . '</div>';
}
/**
* @access protected
*/
protected function start_run() {
$updater = $this->get_task_runner();
if ( $updater->is_running() ) {
return;
}
$upgrade_callbacks = $this->get_upgrade_callbacks();
if ( empty( $upgrade_callbacks ) ) {
$this->on_runner_complete();
return;
}
foreach ( $upgrade_callbacks as $callback ) {
$updater->push_to_queue( [
'callback' => $callback,
] );
}
$updater->save()->dispatch();
Plugin::$instance->logger->get_logger()->info( 'Elementor data updater process has been queued.', [
'meta' => [
'plugin' => $this->get_plugin_label(),
'from' => $this->current_version,
'to' => $this->get_new_version(),
],
] );
}
protected function update_db_version() {
Leo_Helper::update_option( $this->get_version_option_name(), $this->get_new_version() );
}
public function get_upgrade_callbacks() {
$prefix = '_v_';
$upgrades_class = $this->get_upgrades_class();
$upgrades_reflection = new \ReflectionClass( $upgrades_class );
$callbacks = [];
foreach ( $upgrades_reflection->getMethods() as $method ) {
$method_name = $method->getName();
if ( false === strpos( $method_name, $prefix ) ) {
continue;
}
if ( ! preg_match_all( "/$prefix(\d+_\d+_\d+)/", $method_name, $matches ) ) {
continue;
}
$method_version = str_replace( '_', '.', $matches[1][0] );
if ( ! version_compare( $method_version, $this->current_version, '>' ) ) {
continue;
}
$callbacks[] = [ $upgrades_class, $method_name ];
}
return $callbacks;
}
public function __construct() {
if ( ! $this->should_upgrade() ) {
return;
}
$updater = $this->get_task_runner();
$this->start_run();
if ( $updater->is_running() ) {
Leo_Helper::add_action( 'admin_notices', [ $this, 'admin_notice_upgrade_is_running' ] );
}
parent::__construct();
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,34 @@
<?php
/**
* 2007-2022 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2022 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;

View File

@@ -0,0 +1,316 @@
<?php
/**
* 2007-2022 Apollotheme
*
* NOTICE OF LICENSE
*
* LeoElements is module help you can build content for your shop
*
* DISCLAIMER
*
* @author Apollotheme <apollotheme@gmail.com>
* @copyright 2007-2022 Apollotheme
* @license http://apollotheme.com - prestashop template provider
*/
namespace LeoElements\Core\Base;
use LeoElements\Leo_Helper;
if ( ! defined( '_PS_VERSION_' ) ) {
exit; // Exit if accessed directly.
}
/**
* Elementor module.
*
* An abstract class that provides the needed properties and methods to
* manage and handle modules in inheriting classes.
*
* @since 1.7.0
* @abstract
*/
abstract class Module extends Base_Object {
/**
* Module class reflection.
*
* Holds the information about a class.
*
* @since 1.7.0
* @access private
*
* @var \ReflectionClass
*/
private $reflection;
/**
* Module components.
*
* Holds the module components.
*
* @since 1.7.0
* @access private
*
* @var array
*/
private $components = [];
/**
* Module instance.
*
* Holds the module instance.
*
* @since 1.7.0
* @access protected
*
* @var Module
*/
protected static $_instances = [];
/**
* Get module name.
*
* Retrieve the module name.
*
* @since 1.7.0
* @access public
* @abstract
*
* @return string Module name.
*/
abstract public function get_name();
/**
* Instance.
*
* Ensures only one instance of the module class is loaded or can be loaded.
*
* @since 1.7.0
* @access public
* @static
*
* @return Module An instance of the class.
*/
public static function instance() {
$class_name = static::class_name();
if ( empty( static::$_instances[ $class_name ] ) ) {
static::$_instances[ $class_name ] = new static();
}
return static::$_instances[ $class_name ];
}
/**
* @since 2.0.0
* @access public
* @static
*/
public static function is_active() {
return true;
}
/**
* Class name.
*
* Retrieve the name of the class.
*
* @since 1.7.0
* @access public
* @static
*/
public static function class_name() {
return get_called_class();
}
/**
* Clone.
*
* Disable class cloning and throw an error on object clone.
*
* The whole idea of the singleton design pattern is that there is a single
* object. Therefore, we don't want the object to be cloned.
*
* @since 1.7.0
* @access public
*/
public function __clone() {
// Cloning instances of the class is forbidden
_doing_it_wrong( __FUNCTION__, Leo_Helper::esc_html__( 'Something went wrong.', 'elementor' ), '1.0.0' );
}
/**
* Wakeup.
*
* Disable unserializing of the class.
*
* @since 1.7.0
* @access public
*/
public function __wakeup() {
// Unserializing instances of the class is forbidden
_doing_it_wrong( __FUNCTION__, Leo_Helper::esc_html__( 'Something went wrong.', 'elementor' ), '1.0.0' );
}
/**
* @since 2.0.0
* @access public
*/
public function get_reflection() {
if ( null === $this->reflection ) {
$this->reflection = new \ReflectionClass( $this );
}
return $this->reflection;
}
/**
* Add module component.
*
* Add new component to the current module.
*
* @since 1.7.0
* @access public
*
* @param string $id Component ID.
* @param mixed $instance An instance of the component.
*/
public function add_component( $id, $instance ) {
$this->components[ $id ] = $instance;
}
/**
* @since 1.0.0
* @access public
* @return Module[]
*/
public function get_components() {
return $this->components;
}
/**
* Get module component.
*
* Retrieve the module component.
*
* @since 1.7.0
* @access public
*
* @param string $id Component ID.
*
* @return mixed An instance of the component, or `false` if the component
* doesn't exist.
*/
public function get_component( $id ) {
if ( isset( $this->components[ $id ] ) ) {
return $this->components[ $id ];
}
return false;
}
/**
* Get assets url.
*
* @since 1.0.0
* @access protected
*
* @param string $file_name
* @param string $file_extension
* @param string $relative_url Optional. Default is null.
* @param string $add_min_suffix Optional. Default is 'default'.
*
* @return string
*/
final protected function get_assets_url( $file_name, $file_extension, $relative_url = null, $add_min_suffix = 'default' ) {
static $is_test_mode = null;
if ( null === $is_test_mode ) {
$is_test_mode = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG || defined( 'LEOELEMENTS_TESTS' ) && LEOELEMENTS_TESTS;
}
if ( ! $relative_url ) {
$relative_url = $this->get_assets_relative_url() . $file_extension . '/';
}
$url = $this->get_assets_base_url() . $relative_url . $file_name;
if ( 'default' === $add_min_suffix ) {
$add_min_suffix = ! $is_test_mode;
}
if ( $add_min_suffix ) {
$url .= '.min';
}
return $url . '.' . $file_extension;
}
/**
* Get js assets url
*
* @since 1.0.0
* @access protected
*
* @param string $file_name
* @param string $relative_url Optional. Default is null.
* @param string $add_min_suffix Optional. Default is 'default'.
*
* @return string
*/
final protected function get_js_assets_url( $file_name, $relative_url = null, $add_min_suffix = 'default' ) {
return $this->get_assets_url( $file_name, 'js', $relative_url, $add_min_suffix );
}
/**
* Get css assets url
*
* @since 1.0.0
* @access protected
*
* @param string $file_name
* @param string $relative_url Optional. Default is null.
* @param string $add_min_suffix Optional. Default is 'default'.
* @param bool $add_direction_suffix Optional. Default is `false`
*
* @return string
*/
final protected function get_css_assets_url( $file_name, $relative_url = null, $add_min_suffix = 'default', $add_direction_suffix = false ) {
static $direction_suffix = null;
if ( ! $direction_suffix ) {
$direction_suffix = Leo_Helper::is_rtl() ? '-rtl' : '';
}
if ( $add_direction_suffix ) {
$file_name .= $direction_suffix;
}
return $this->get_assets_url( $file_name, 'css', $relative_url, $add_min_suffix );
}
/**
* Get assets base url
*
* @since 1.0.0
* @access protected
*
* @return string
*/
protected function get_assets_base_url() {
return LEOELEMENTS_URL;
}
/**
* Get assets relative url
*
* @since 1.0.0
* @access protected
*
* @return string
*/
protected function get_assets_relative_url() {
return 'assets/';
}
}