| Server IP : 38.190.208.107 / Your IP : 216.73.217.46 Web Server : nginx/1.28.1 System : Linux ht2026040333114 6.1.0-10-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.37-1 (2023-07-03) x86_64 User : root ( 0) PHP Version : 8.2.28 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv,eval,assert,passthru,system,exec,shell_exec,popen,proc_open MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wwwroot/wp.3/wp-content/plugins/wpforms-lite/src/Integrations/Elementor/ |
Upload File : |
<?php
namespace WPForms\Integrations\Elementor;
use WPForms\Helpers\File;
/**
* ThemesData class for Elementor Modern widget.
*
* @since 1.9.6
*/
abstract class ThemesData {
/**
* Custom themes JSON file path.
*
* Relative to `wp-content/uploads/wpforms` directory.
*
* @since 1.9.6
*
* @var string
*/
private const THEMES_CUSTOM_JSON_PATH = 'themes/elementor/themes-custom.json';
/**
* WPForms themes JSON file path for the lite version.
*
* Relative to the WPForms plugin directory.
*
* @since 1.9.6
*
* @var string
*/
protected const THEMES_WPFORMS_JSON_PATH_LITE = 'assets/lite/js/integrations/elementor/themes.json';
/**
* Custom themes file path.
*
* @since 1.9.6
*
* @var string
*/
private $custom_themes_file_path;
/**
* WPForms themes data.
*
* @since 1.9.6
*
* @var array
*/
protected $wpforms_themes;
/**
* Custom themes data.
*
* @since 1.9.6
*
* @var array
*/
private $custom_themes;
/**
* Return WPForms themes.
*
* @since 1.9.6
*
* @return array
*/
public function get_wpforms_themes(): array {
if ( $this->wpforms_themes !== null ) {
return $this->wpforms_themes;
}
$themes_json = File::get_contents( WPFORMS_PLUGIN_DIR . static::THEMES_WPFORMS_JSON_PATH ) ?? '{}';
$themes = json_decode( $themes_json, true );
$this->wpforms_themes = ! empty( $themes ) ? $themes : [];
return $this->wpforms_themes;
}
/**
* Return custom themes.
*
* @since 1.9.6
*
* @return array
*/
public function get_custom_themes(): array {
if ( $this->custom_themes !== null ) {
return $this->custom_themes;
}
$themes_json = File::get_contents( $this->get_custom_themes_file_path() ) ?? '{}';
$themes = json_decode( $themes_json, true );
$this->custom_themes = ! empty( $themes ) ? $themes : [];
return $this->custom_themes;
}
/**
* Return theme data.
*
* @since 1.9.6
*
* @param string $slug Theme slug.
*
* @return array|null
*/
public function get_theme( string $slug ): ?array {
$wpforms = $this->get_wpforms_themes();
if ( ! empty( $wpforms[ $slug ] ) ) {
return $wpforms[ $slug ];
}
$custom = $this->get_custom_themes();
if ( ! empty( $custom[ $slug ] ) ) {
return $custom[ $slug ];
}
return null;
}
/**
* Get custom themes JSON file path.
*
* @since 1.9.6
*
* @return string|bool File path OR false in the case of permissions error.
*/
public function get_custom_themes_file_path() {
// Caching the file path in the class property.
if ( $this->custom_themes_file_path !== null ) {
return $this->custom_themes_file_path;
}
// Determine a custom themes file path.
$upload_dir = wpforms_upload_dir();
$upload_path = ! empty( $upload_dir['path'] ) ? $upload_dir['path'] : WP_CONTENT_DIR . 'uploads/wpforms/';
$upload_path = trailingslashit( wp_normalize_path( $upload_path ) );
$file_path = $upload_path . self::THEMES_CUSTOM_JSON_PATH;
$dirname = dirname( $file_path );
// If the directory doesn't exist, create it. Also, check for permissions.
if ( ! wp_mkdir_p( $dirname ) ) {
$file_path = false;
}
$this->custom_themes_file_path = $file_path;
return $file_path;
}
/**
* Sanitize custom themes data.
*
* @since 1.9.6
*
* @param array $custom_themes Custom themes data.
*
* @return array
*/
private function sanitize_custom_themes_data( array $custom_themes ): array {
$wpforms = $this->get_wpforms_themes();
$sanitized_themes = [];
// Get the default theme settings.
// If there are no default settings, use an empty array. This should never happen, but just in case.
$default_theme = $wpforms['default'] ?? [];
$default_theme['settings'] = $default_theme['settings'] ?? [];
foreach ( $custom_themes as $slug => $theme ) {
$slug = sanitize_key( $slug );
$sanitized_themes[ $slug ]['name'] = sanitize_text_field( $theme['name'] ?? 'Copy of ' . $default_theme['name'] );
// Fill in missed settings keys with default values.
$settings = wp_parse_args( $theme['settings'] ?? [], $default_theme['settings'] );
// Make sure we will save only settings that are present in the default theme.
$settings = array_intersect_key( $settings, $default_theme['settings'] );
// Sanitize settings.
$sanitized_themes[ $slug ]['settings'] = array_map( 'sanitize_text_field', $settings );
}
return $sanitized_themes;
}
/**
* Update custom themes data.
*
* @since 1.9.6
*
* @param array $custom_themes Custom themes data.
*
* @return bool
*/
public function update_custom_themes_file( array $custom_themes ): bool {
// Sanitize custom themes data to be saved.
$sanitized_themes = $this->sanitize_custom_themes_data( $custom_themes );
// Determine a custom themes file path.
$themes_file = $this->get_custom_themes_file_path();
$json_data = ! empty( $sanitized_themes ) ? wp_json_encode( $sanitized_themes ) : '{}';
// Save custom themes data and return the result.
return File::put_contents( $themes_file, $json_data );
}
}