first commit

This commit is contained in:
Ryan Ariana
2024-05-06 11:04:37 +07:00
commit aee061ddba
7322 changed files with 2918816 additions and 0 deletions

View File

@@ -0,0 +1,111 @@
<?php
namespace Elementor\Core\Upgrade;
use Elementor\Core\Base\Background_Task_Manager;
use Elementor\Plugin;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Custom_Tasks_Manager extends Background_Task_Manager {
const TASKS_OPTION_KEY = 'elementor_custom_tasks';
const QUERY_LIMIT = 100;
public function get_name() {
return 'custom-task-manager';
}
public function get_action() {
return 'custom_task_manger';
}
public function get_plugin_name() {
return 'elementor';
}
public function get_plugin_label() {
return esc_html__( 'Elementor', 'elementor' );
}
public function get_task_runner_class() {
return Task::class;
}
public function get_query_limit() {
return self::QUERY_LIMIT;
}
protected function start_run() {
$custom_tasks_callbacks = $this->get_custom_tasks();
if ( empty( $custom_tasks_callbacks ) ) {
return;
}
$task_runner = $this->get_task_runner();
foreach ( $custom_tasks_callbacks as $callback ) {
$task_runner->push_to_queue( [
'callback' => $callback,
] );
}
$this->clear_tasks_requested_to_run();
Plugin::$instance->logger->get_logger()->info( 'Elementor custom task(s) process has been queued.', [
'meta' => [ $custom_tasks_callbacks ],
] );
$task_runner->save()->dispatch();
}
public function get_tasks_class() {
return Custom_Tasks::class;
}
public function get_tasks_requested_to_run() {
return get_option( self::TASKS_OPTION_KEY, [] );
}
public function clear_tasks_requested_to_run() {
return update_option( self::TASKS_OPTION_KEY, [], false );
}
public function add_tasks_requested_to_run( $tasks = [] ) {
$current_tasks = $this->get_tasks_requested_to_run();
$current_tasks = array_merge( $current_tasks, $tasks );
update_option( self::TASKS_OPTION_KEY, $current_tasks, false );
}
private function get_custom_tasks() {
$tasks_requested_to_run = $this->get_tasks_requested_to_run();
$tasks_class = $this->get_tasks_class();
$tasks_reflection = new \ReflectionClass( $tasks_class );
$callbacks = [];
foreach ( $tasks_reflection->getMethods() as $method ) {
$method_name = $method->getName();
if ( in_array( $method_name, $tasks_requested_to_run, true ) ) {
$callbacks[] = [ $tasks_class, $method_name ];
}
}
return $callbacks;
}
public function __construct() {
$task_runner = $this->get_task_runner();
if ( $task_runner->is_running() ) {
return;
}
$this->start_run();
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace Elementor\Core\Upgrade;
use Elementor\Tracker;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Custom_Tasks {
public static function opt_in_recalculate_usage( $updater ) {
return Upgrades::recalc_usage_data( $updater );
}
public static function opt_in_send_tracking_data() {
Tracker::send_tracking_data( true );
}
}

View File

@@ -0,0 +1,96 @@
<?php
namespace Elementor\Core\Upgrade;
use Elementor\Core\Base\DB_Upgrades_Manager;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Manager extends DB_Upgrades_Manager {
/**
* @deprecated 3.17.0
*/
const INSTALLS_HISTORY_META = 'elementor_install_history';
public static function get_install_history_meta() {
return 'elementor_install_history';
}
// todo: remove in future releases
public function should_upgrade() {
if ( ( 'elementor' === $this->get_plugin_name() ) && version_compare( get_option( $this->get_version_option_name() ), '2.4.2', '<' ) ) {
delete_option( 'elementor_log' );
}
return parent::should_upgrade();
}
public function get_name() {
return 'upgrade';
}
public function get_action() {
return 'elementor_updater';
}
public function get_plugin_name() {
return 'elementor';
}
public function get_plugin_label() {
return esc_html__( 'Elementor', 'elementor' );
}
public function get_updater_label() {
return esc_html__( 'Elementor Data Updater', 'elementor' );
}
public function get_new_version() {
return ELEMENTOR_VERSION;
}
public function get_version_option_name() {
return 'elementor_version';
}
public function get_upgrades_class() {
return 'Elementor\Core\Upgrade\Upgrades';
}
public static function get_installs_history() {
return get_option( static::get_install_history_meta(), [] );
}
public static function install_compare( $version, $operator ) {
$installs_history = self::get_installs_history();
return version_compare(
key( $installs_history ),
$version ? $version : '0.0.0', // when no version assigned
$operator
);
}
protected function update_db_version() {
parent::update_db_version();
$installs_history = self::get_installs_history();
$time = time();
$installs_history[ ELEMENTOR_VERSION ] = $time;
$old_version = $this->get_current_version();
// If there was an old version of Elementor, and there's no record for that install yet
if ( $old_version && empty( $installs_history[ $old_version ] ) ) {
$installs_history[ $old_version ] = $installs_history[ ELEMENTOR_VERSION ] - 1;
}
uksort( $installs_history, 'version_compare' );
update_option( static::get_install_history_meta(), $installs_history );
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace Elementor\Core\Upgrade;
use Elementor\Core\Base\Background_Task;
use Elementor\Core\Base\DB_Upgrades_Manager;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Task extends Background_Task {
/**
* @var DB_Upgrades_Manager
*/
protected $manager;
protected function format_callback_log( $item ) {
return $this->manager->get_plugin_label() . '/Tasks - ' . $item['callback'][1];
}
public function set_limit( $limit ) {
$this->manager->set_query_limit( $limit );
}
}

View File

@@ -0,0 +1,24 @@
<?php
namespace Elementor\Core\Upgrade;
use Elementor\Core\Base\Background_Task;
use Elementor\Core\Base\DB_Upgrades_Manager;
defined( 'ABSPATH' ) || exit;
class Updater extends Background_Task {
/**
* @var DB_Upgrades_Manager
*/
protected $manager;
protected function format_callback_log( $item ) {
return $this->manager->get_plugin_label() . '/Upgrades - ' . $item['callback'][1];
}
public function set_limit( $limit ) {
$this->manager->set_query_limit( $limit );
}
}

View File

@@ -0,0 +1,77 @@
<?php
namespace Elementor\Core\Upgrade;
use Elementor\Plugin;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Upgrade_Utils {
/**
* _update_widget_settings
*
* @param string $widget_id widget type id
* @param Updater $updater updater instance
* @param array $changes array containing updating control_ids, callback and other data needed by the callback
*
* @return bool
*/
public static function _update_widget_settings( $widget_id, $updater, $changes ) {
global $wpdb;
$post_ids = $updater->query_col(
'SELECT `post_id`
FROM `' . $wpdb->postmeta . '`
WHERE `meta_key` = "_elementor_data"
AND `meta_value` LIKE \'%"widgetType":"' . $widget_id . '"%\';'
);
if ( empty( $post_ids ) ) {
return false;
}
foreach ( $post_ids as $post_id ) {
$do_update = false;
$document = Plugin::instance()->documents->get( $post_id );
if ( ! $document ) {
continue;
}
$data = $document->get_elements_data();
if ( empty( $data ) ) {
continue;
}
// loop thru callbacks & array
foreach ( $changes as $change ) {
$args = [
'do_update' => &$do_update,
'widget_id' => $widget_id,
'control_ids' => $change['control_ids'],
];
if ( isset( $change['prefix'] ) ) {
$args['prefix'] = $change['prefix'];
$args['new_id'] = $change['new_id'];
}
$data = Plugin::instance()->db->iterate_data( $data, $change['callback'], $args );
if ( ! $do_update ) {
continue;
}
// We need the `wp_slash` in order to avoid the unslashing during the `update_metadata`
$json_value = wp_slash( wp_json_encode( $data ) );
update_metadata( 'post', $post_id, '_elementor_data', $json_value );
}
} // End foreach().
return $updater->should_run_again( $post_ids );
}
}

File diff suppressed because it is too large Load Diff