first commit
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace Elementor\Modules\AtomicWidgets\Utils\Image;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
class Image_Sizes {
|
||||
const DEFAULT_SIZE = 'large';
|
||||
|
||||
public static function get_keys() {
|
||||
return array_map(
|
||||
fn( $size ) => $size['value'],
|
||||
static::get_all()
|
||||
);
|
||||
}
|
||||
|
||||
public static function get_all(): array {
|
||||
$wp_image_sizes = static::get_wp_image_sizes();
|
||||
|
||||
$image_sizes = [];
|
||||
|
||||
foreach ( $wp_image_sizes as $size_key => $size_attributes ) {
|
||||
|
||||
$control_title = ucwords( str_replace( '_', ' ', $size_key ) );
|
||||
|
||||
if ( is_array( $size_attributes ) ) {
|
||||
$control_title .= sprintf( ' - %d*%d', $size_attributes['width'], $size_attributes['height'] );
|
||||
}
|
||||
|
||||
$image_sizes[] = [
|
||||
'label' => $control_title,
|
||||
'value' => $size_key,
|
||||
];
|
||||
}
|
||||
|
||||
$image_sizes[] = [
|
||||
'label' => esc_html__( 'Full', 'elementor' ),
|
||||
'value' => 'full',
|
||||
];
|
||||
|
||||
return $image_sizes;
|
||||
}
|
||||
|
||||
private static function get_wp_image_sizes() {
|
||||
$default_image_sizes = get_intermediate_image_sizes();
|
||||
$additional_sizes = wp_get_additional_image_sizes();
|
||||
|
||||
$image_sizes = [];
|
||||
|
||||
foreach ( $default_image_sizes as $size ) {
|
||||
$image_sizes[ $size ] = [
|
||||
'width' => (int) get_option( $size . '_size_w' ),
|
||||
'height' => (int) get_option( $size . '_size_h' ),
|
||||
'crop' => (bool) get_option( $size . '_crop' ),
|
||||
];
|
||||
}
|
||||
|
||||
if ( $additional_sizes ) {
|
||||
$image_sizes = array_merge( $image_sizes, $additional_sizes );
|
||||
}
|
||||
|
||||
// /** This filter is documented in wp-admin/includes/media.php */
|
||||
return apply_filters( 'image_size_names_choose', $image_sizes );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Elementor\Modules\AtomicWidgets\Utils\Image;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
class Placeholder_Image {
|
||||
|
||||
public static function get_placeholder_image() {
|
||||
return ELEMENTOR_ASSETS_URL . 'images/placeholder-v4.svg';
|
||||
}
|
||||
|
||||
public static function get_background_placeholder_image() {
|
||||
return ELEMENTOR_ASSETS_URL . 'images/background-placeholder.svg';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Elementor\Modules\AtomicWidgets\Utils;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
class Memo {
|
||||
private array $cache = [];
|
||||
|
||||
public function memoize( string $key, callable $callback ) {
|
||||
return function() use ( $key, $callback ) {
|
||||
if ( array_key_exists( $key, $this->cache ) ) {
|
||||
return $this->cache[ $key ];
|
||||
}
|
||||
|
||||
$this->cache[ $key ] = call_user_func( $callback );
|
||||
return $this->cache[ $key ];
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace Elementor\Modules\AtomicWidgets\Utils;
|
||||
|
||||
use Elementor\Core\Base\Document;
|
||||
use Elementor\Modules\AtomicWidgets\Elements\Base\Atomic_Element_Base;
|
||||
use Elementor\Modules\AtomicWidgets\Elements\Base\Atomic_Widget_Base;
|
||||
use Elementor\Plugin;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
class Utils {
|
||||
public static function is_atomic( $element_instance ): bool {
|
||||
return $element_instance instanceof Atomic_Element_Base ||
|
||||
$element_instance instanceof Atomic_Widget_Base;
|
||||
}
|
||||
|
||||
public static function generate_id( string $prefix = '', $existing_ids = [] ): string {
|
||||
do {
|
||||
$generated = substr(
|
||||
bin2hex( random_bytes( 4 ) ),
|
||||
0,
|
||||
7
|
||||
);
|
||||
|
||||
$id = "$prefix{$generated}";
|
||||
} while ( in_array( $id, $existing_ids, true ) );
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
public static function is_post_published( Document $document ): bool {
|
||||
return $document->get_post()->post_status === Document::STATUS_PUBLISH;
|
||||
}
|
||||
|
||||
public static function traverse_post_elements( string $post_id, callable $callback ): void {
|
||||
$documents = Plugin::$instance->documents;
|
||||
$document = is_preview() ? $documents->get_doc_or_auto_save( $post_id, get_current_user_id() ) : $documents->get( $post_id );
|
||||
|
||||
if ( ! $document ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$elements_data = $document->get_elements_data();
|
||||
|
||||
if ( empty( $elements_data ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
Plugin::$instance->db->iterate_data( $elements_data, function( $element_data ) use ( $callback ) {
|
||||
call_user_func( $callback, $element_data );
|
||||
} );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user