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,48 @@
<?php
namespace Elementor\Core\Debug\Classes;
use Elementor\Modules\SafeMode\Module as Safe_Mode;
use Elementor\Utils;
class Htaccess extends Inspection_Base {
private $message = '';
public function __construct() {
$this->message = esc_html__( 'Your site\'s .htaccess file appears to be missing.', 'elementor' );
}
public function run() {
$safe_mode_enabled = get_option( Safe_Mode::OPTION_ENABLED, '' );
if ( empty( $safe_mode_enabled ) || is_multisite() ) {
return true;
}
$permalink_structure = get_option( 'permalink_structure' );
if ( empty( $permalink_structure ) || empty( $_SERVER['SERVER_SOFTWARE'] ) ) {
return true;
}
$server = strtoupper( Utils::get_super_global_value( $_SERVER, 'SERVER_SOFTWARE' ) );
if ( strstr( $server, 'APACHE' ) ) {
$htaccess_file = get_home_path() . '.htaccess';
/* translators: %s: Path to .htaccess file. */
$this->message .= ' ' . sprintf( esc_html__( 'File Path: %s', 'elementor' ), $htaccess_file ) . ' ';
return file_exists( $htaccess_file );
}
return true;
}
public function get_name() {
return 'apache-htaccess';
}
public function get_message() {
return $this->message;
}
public function get_help_doc_url() {
return 'https://go.elementor.com/preview-not-loaded/#htaccess';
}
}

View File

@@ -0,0 +1,32 @@
<?php
namespace Elementor\Core\Debug\Classes;
abstract class Inspection_Base {
/**
* @return bool
*/
abstract public function run();
/**
* @return string
*/
abstract public function get_name();
/**
* @return string
*/
abstract public function get_message();
/**
* @return string
*/
public function get_header_message() {
return esc_html__( 'The preview could not be loaded', 'elementor' );
}
/**
* @return string
*/
abstract public function get_help_doc_url();
}

View File

@@ -0,0 +1,28 @@
<?php
namespace Elementor\Core\Debug\Classes;
use Elementor\Modules\SafeMode\Module as Safe_Mode;
class Theme_Missing extends Inspection_Base {
public function run() {
$safe_mode_enabled = get_option( Safe_Mode::OPTION_ENABLED, '' );
if ( ! empty( $safe_mode_enabled ) ) {
return true;
}
$theme = wp_get_theme();
return $theme->exists();
}
public function get_name() {
return 'theme-missing';
}
public function get_message() {
return esc_html__( 'Some of your theme files are missing.', 'elementor' );
}
public function get_help_doc_url() {
return 'https://go.elementor.com/preview-not-loaded/#theme-files';
}
}

View File

@@ -0,0 +1,144 @@
<?php
namespace Elementor\Core\Debug;
use Elementor\Settings;
use Elementor\Tools;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Inspector {
protected $is_enabled = false;
protected $log = [];
/**
* @since 2.1.2
* @access public
*/
public function __construct() {
$is_debug = ( defined( 'WP_DEBUG' ) && WP_DEBUG );
$option = get_option( 'elementor_enable_inspector', null );
$this->is_enabled = is_null( $option ) ? $is_debug : 'enable' === $option;
if ( $this->is_enabled ) {
add_action( 'admin_bar_menu', [ $this, 'add_menu_in_admin_bar' ], 201 );
}
add_action( 'elementor/admin/after_create_settings/' . Tools::PAGE_ID, [ $this, 'register_admin_tools_fields' ], 50 );
}
/**
* @since 2.1.3
* @access public
*/
public function is_enabled() {
return $this->is_enabled;
}
/**
* @since 2.1.3
* @access public
*/
public function register_admin_tools_fields( Tools $tools ) {
$tools->add_fields( Settings::TAB_GENERAL, 'tools', [
'enable_inspector' => [
'label' => esc_html__( 'Debug Bar', 'elementor' ),
'field_args' => [
'type' => 'select',
'std' => $this->is_enabled ? 'enable' : '',
'options' => [
'' => esc_html__( 'Disable', 'elementor' ),
'enable' => esc_html__( 'Enable', 'elementor' ),
],
'desc' => esc_html__( 'Debug Bar adds an admin bar menu that lists all the templates that are used on a page that is being displayed.', 'elementor' ),
],
],
] );
}
/**
* @since 2.1.2
* @access public
*/
public function parse_template_path( $template ) {
// `untrailingslashit` for windows path style.
if ( 0 === strpos( $template, untrailingslashit( ELEMENTOR_PATH ) ) ) {
return 'Elementor - ' . basename( $template );
}
if ( 0 === strpos( $template, get_stylesheet_directory() ) ) {
return wp_get_theme()->get( 'Name' ) . ' - ' . basename( $template );
}
$plugins_dir = dirname( ELEMENTOR_PATH );
if ( 0 === strpos( $template, $plugins_dir ) ) {
return ltrim( str_replace( $plugins_dir, '', $template ), '/\\' );
}
return str_replace( WP_CONTENT_DIR, '', $template );
}
/**
* @since 2.1.2
* @access public
*/
public function add_log( $module, $title, $url = '' ) {
if ( ! $this->is_enabled ) {
return;
}
if ( ! isset( $this->log[ $module ] ) ) {
$this->log[ $module ] = [];
}
$this->log[ $module ][] = [
'title' => $title,
'url' => $url,
];
}
/**
* @since 2.1.2
* @access public
*/
public function add_menu_in_admin_bar( \WP_Admin_Bar $wp_admin_bar ) {
if ( empty( $this->log ) ) {
return;
}
$wp_admin_bar->add_node( [
'id' => 'elementor_inspector',
'title' => esc_html__( 'Elementor Debugger', 'elementor' ),
] );
foreach ( $this->log as $module => $log ) {
$module_id = sanitize_key( $module );
$wp_admin_bar->add_menu( [
'id' => 'elementor_inspector_' . $module_id,
'parent' => 'elementor_inspector',
'title' => $module,
] );
foreach ( $log as $index => $row ) {
$url = $row['url'];
unset( $row['url'] );
$wp_admin_bar->add_menu( [
'id' => 'elementor_inspector_log_' . $module_id . '_' . $index,
'parent' => 'elementor_inspector_' . $module_id,
'href' => $url,
'title' => implode( ' > ', $row ),
'meta' => [
'target' => '_blank',
],
] );
}
}
}
}

View File

@@ -0,0 +1,54 @@
<?php
namespace Elementor\Core\Debug;
use Elementor\Core\Debug\Classes\Inspection_Base;
use Elementor\Core\Debug\Classes\Theme_Missing;
use Elementor\Core\Debug\Classes\Htaccess;
class Loading_Inspection_Manager {
public static $_instance = null;
public static function instance() {
if ( null === self::$_instance ) {
self::$_instance = new Loading_Inspection_Manager();
}
return self::$_instance;
}
/** @var Inspection_Base[] */
private $inspections = [];
public function register_inspections() {
$this->inspections['theme-missing'] = new Theme_Missing();
$this->inspections['htaccess'] = new Htaccess();
}
/**
* @param Inspection_Base $inspection
*/
public function register_inspection( $inspection ) {
$this->inspections[ $inspection->get_name() ] = $inspection;
}
public function run_inspections() {
$debug_data = [
'message' => esc_html__( "Were sorry, but something went wrong. Click on 'Learn more' and follow each of the steps to quickly solve it.", 'elementor' ),
'header' => esc_html__( 'The preview could not be loaded', 'elementor' ),
'doc_url' => 'https://go.elementor.com/preview-not-loaded/',
];
foreach ( $this->inspections as $inspection ) {
if ( ! $inspection->run() ) {
$debug_data = [
'message' => $inspection->get_message(),
'header' => $inspection->get_header_message(),
'doc_url' => $inspection->get_help_doc_url(),
'error' => true,
];
break;
}
}
return $debug_data;
}
}