File manager - Edit - /home/premiey/www/wp-includes/images/media/library.tar
Back
image-processing-queue/image-processing-queue.php 0000666 00000001354 15165304264 0016226 0 ustar 00 <?php /* * Copyright (c) 2020 Delicious Brains. All rights reserved. * * Released under the GPL license * https://www.opensource.org/licenses/gpl-license.php */ defined( 'WPINC' ) || die; require_once ASTRA_EXT_DIR . 'classes/library/batch-processing/wp-async-request.php'; require_once ASTRA_EXT_DIR . 'classes/library/batch-processing/wp-background-process.php'; require_once ASTRA_EXT_DIR . 'classes/library/image-processing-queue/includes/class-ipq-process.php'; require_once ASTRA_EXT_DIR . 'classes/library/image-processing-queue/includes/class-image-processing-queue.php'; require_once ASTRA_EXT_DIR . 'classes/library/image-processing-queue/includes/ipq-template-functions.php'; Image_Processing_Queue::instance(); image-processing-queue/includes/class-ipq-process.php 0000666 00000005161 15165304264 0017026 0 ustar 00 <?php /** * Background Process for Image Processing Queue * * @package Image-Processing-Queue */ if ( ! class_exists( 'IPQ_Process' ) ) { /** * Custom exception class for IPQ background processing */ class IPQ_Process_Exception extends Exception {} /** * Extends the background processing library and implements image processing routines */ class IPQ_Process extends WP_Background_Process { /** * Action * * @var string */ protected $action = 'image_processing_queue'; /** * Background task to resizes images * * @param mixed $item Image data. * @return bool * @throws IPQ_Process_Exception On error. */ protected function task( $item ) { $defaults = array( 'post_id' => 0, 'width' => 0, 'height' => 0, 'crop' => false, ); $item = wp_parse_args( $item, $defaults ); $post_id = $item['post_id']; $width = $item['width']; $height = $item['height']; $crop = $item['crop']; if ( ! $width && ! $height ) { throw new IPQ_Process_Exception( "Invalid dimensions '{$width}x{$height}'" ); } if ( Image_Processing_Queue::does_size_already_exist_for_image( $post_id, array( $width, $height, $crop ) ) ) { return false; } $image_meta = Image_Processing_Queue::get_image_meta( $post_id ); if ( ! $image_meta ) { return false; } add_filter( 'as3cf_get_attached_file_copy_back_to_local', '__return_true' ); $img_path = Image_Processing_Queue::get_image_path( $post_id ); if ( ! $img_path ) { return false; } $editor = wp_get_image_editor( $img_path ); if ( is_wp_error( $editor ) ) { throw new IPQ_Process_Exception( 'Unable to get WP_Image_Editor for file "' . $img_path . '": ' . $editor->get_error_message() . ' (is GD or ImageMagick installed?)' ); } if ( is_wp_error( $editor->resize( $width, $height, $crop ) ) ) { throw new IPQ_Process_Exception( 'Error resizing image: ' . $editor->get_error_message() ); } $resized_file = $editor->save(); if ( is_wp_error( $resized_file ) ) { throw new IPQ_Process_Exception( 'Unable to save resized image file: ' . $editor->get_error_message() ); } $size_name = Image_Processing_Queue::get_size_name( array( $width, $height, $crop ) ); $image_meta['sizes'][ $size_name ] = array( 'file' => $resized_file['file'], 'width' => $resized_file['width'], 'height' => $resized_file['height'], 'mime-type' => $resized_file['mime-type'], ); wp_update_attachment_metadata( $post_id, $image_meta ); return false; } } } image-processing-queue/includes/class-image-processing-queue.php 0000666 00000016524 15165304264 0021144 0 ustar 00 <?php /** * Image Processing Queue * * @package Image-Processing-Queue */ if ( ! class_exists( 'Image_Processing_Queue' ) ) { /** * Image Processing Queue */ class Image_Processing_Queue { /** * Singleton * * @var Image_Processing_Queue|null */ protected static $instance = null; /** * Whether or not we're updating the backup sizes * * @var bool */ private $is_updating_backup_sizes = false; /** * Instance of the background process class * * @var IPQ_Process|null */ public $process = null; /** * Singleton * * @return Image_Processing_Queue|null */ public static function instance() { if ( is_null( self::$instance ) ) { self::$instance = new self(); } return self::$instance; } /** * Image_Processing_Queue constructor. */ public function __construct() { $this->process = new IPQ_Process(); add_filter( 'update_post_metadata', array( $this, 'filter_update_post_metadata' ), 10, 5 ); } /** * Filter the post meta data for backup sizes * * Unfortunately WordPress core is lacking hooks in its image resizing functions so we are reduced * to this hackery to detect when images are resized and previous versions are relegated to backup sizes. * * @param bool $check * @param int $object_id * @param string $meta_key * @param mixed $meta_value * @param mixed $prev_value * @return bool */ public function filter_update_post_metadata( $check, $object_id, $meta_key, $meta_value, $prev_value ) { if ( '_wp_attachment_backup_sizes' !== $meta_key ) { return $check; } $current_value = get_post_meta( $object_id, $meta_key, true ); if ( ! $current_value ) { $current_value = array(); } $diff = array_diff_key( $meta_value, $current_value ); if ( ! $diff ) { return $check; } $key = key( $diff ); $suffix = substr( $key, strrpos( $key, '-' ) + 1 ); $image_meta = self::get_image_meta( $object_id ); foreach ( $image_meta['sizes'] as $size_name => $size ) { if ( 0 !== strpos( $size_name, 'ipq-' ) ) { continue; } $meta_value[ $size_name . '-' . $suffix ] = $size; unset( $image_meta['sizes'][ $size_name ] ); } if ( ! $this->is_updating_backup_sizes ) { $this->is_updating_backup_sizes = true; update_post_meta( $object_id, '_wp_attachment_backup_sizes', $meta_value ); wp_update_attachment_metadata( $object_id, $image_meta ); return true; } $this->is_updating_backup_sizes = false; return $check; } /** * Check if the image sizes exist and push them to the queue if not. * * @param int $post_id * @param array $sizes */ protected function process_image( $post_id, $sizes ) { $new_item = false; foreach ( $sizes as $size ) { if ( self::does_size_already_exist_for_image( $post_id, $size ) ) { continue; } if ( self::is_size_larger_than_original( $post_id, $size ) ) { continue; } $item = array( 'post_id' => $post_id, 'width' => $size[0], 'height' => $size[1], 'crop' => $size[2], ); $this->process->push_to_queue( $item ); $new_item = true; } if ( $new_item ) { $this->process->save()->dispatch(); } } /** * Get image HTML for a specific context in a theme, specifying the exact sizes * for the image. The first image size is always used as the `src` and the other * sizes are used in the `srcset` if they're the same aspect ratio as the original * image. If any of the image sizes don't currently exist, they are queued for * creation by a background process. Example: * * For echoing - echo ipq_get_theme_image( 1353, array( * array( 600, 400, false ), * array( 1280, 720, false ), * array( 1600, 1067, false ), * ), * array( * 'class' => 'header-banner' * ) * ); * * @param int $post_id Image attachment ID. * @param array $sizes Array of arrays of sizes in the format array(width,height,crop). * @param string $attr Optional. Attributes for the image markup. Default empty. * @return string HTML img element or empty string on failure. */ public function get_image( $post_id, $sizes, $attr = '' ) { $this->process_image( $post_id, $sizes ); return wp_get_attachment_image( $post_id, array( $sizes[0][0], $sizes[0][1] ), false, $attr ); } /** * Get image URL for a specific context in a theme, specifying the exact size * for the image. If the image size does not currently exist, it is queued for * creation by a background process. Example: * * For echoing - echo ipq_get_theme_image_url( 1353, array( 600, 400, false ) ); * * @param int $post_id * @param array $size * * @return string */ public function get_image_url( $post_id, $size ) { $this->process_image( $post_id, array( $size ) ); $size = self::get_size_name( $size ); $src = wp_get_attachment_image_src( $post_id, $size ); if ( isset( $src[0] ) ) { return $src[0]; } return ''; } /** * Get array index name for image size. * * @param array $size array in format array(width,height,crop). * @return string Image size name. */ public static function get_size_name( $size ) { $crop = $size[2] ? 'true' : 'false'; return 'ipq-' . $size[0] . 'x' . $size[1] . '-' . $crop; } /** * Get an image's file path. * * @param int $post_id ID of the image post. * @return false|string */ public static function get_image_path( $post_id ) { return get_attached_file( $post_id ); } /** * Get an image's post meta data. * * @param int $post_id ID of the image post. * @return mixed Post meta field. False on failure. */ public static function get_image_meta( $post_id ) { return wp_get_attachment_metadata( $post_id ); } /** * Update meta data for an image * * @param int $post_id Image ID. * @param array $data Image data. * @return bool|int False if $post is invalid. */ public static function update_image_meta( $post_id, $data ) { return wp_update_attachment_metadata( $post_id, $data ); } /** * Checks if an image size already exists for an image * * @param int $post_id Image ID. * @param array $size array in format array(width,height,crop). * @return bool */ public static function does_size_already_exist_for_image( $post_id, $size ) { $image_meta = self::get_image_meta( $post_id ); $size_name = self::get_size_name( $size ); return isset( $image_meta['sizes'][ $size_name ] ); } /** * Check if an image size is larger than the original. * * @param int $post_id Image ID. * @param array $size array in format array(width,height,crop). * * @return bool */ public static function is_size_larger_than_original( $post_id, $size ) { $image_meta = self::get_image_meta( $post_id ); if ( ! isset( $image_meta['width'] ) || ! isset( $image_meta['height'] ) ) { return true; } if ( $size[0] > $image_meta['width'] || $size[1] > $image_meta['height'] ) { return true; } return false; } } } image-processing-queue/includes/ipq-template-functions.php 0000666 00000003364 15165304264 0020071 0 ustar 00 <?php if ( ! function_exists( 'ipq_get_theme_image' ) ) { /** * Get image HTML for a specific context in a theme, specifying the exact sizes * for the image. The first image size is always used as the `src` and the other * sizes are used in the `srcset` if they're the same aspect ratio as the original * image. If any of the image sizes don't currently exist, they are queued for * creation by a background process. Example: * * For echoing - echo ipq_get_theme_image( 1353, array( * array( 600, 400, false ), * array( 1280, 720, false ), * array( 1600, 1067, false ), * ), * array( * 'class' => 'header-banner' * ) * ); * * @param int $post_id Image attachment ID. * @param array $sizes Array of arrays of sizes in the format array(width,height,crop). * @param string $attr Optional. Attributes for the image markup. Default empty. * * @return string HTML img element or empty string on failure. */ function ipq_get_theme_image( $post_id, $sizes, $attr = '' ) { return Image_Processing_Queue::instance()->get_image( $post_id, $sizes, $attr ); } } if ( ! function_exists( 'ipq_get_theme_image_url' ) ) { /** * Get image URL for a specific context in a theme, specifying the exact size * for the image. If the image size does not currently exist, it is queued for * creation by a background process. Example: * * For echoing - echo ipq_get_theme_image_url( 1353, array( 600, 400, false ) ); * * @param int $post_id * @param array $size * * @return string Img URL */ function ipq_get_theme_image_url( $post_id, $size ) { return Image_Processing_Queue::instance()->get_image_url( $post_id, $size ); } } batch-processing/wp-async-request.php 0000666 00000005614 15165304264 0013757 0 ustar 00 <?php /** * WP Async Request * * @package WP-Background-Processing */ if ( ! class_exists( 'WP_Async_Request' ) ) { /** * Abstract WP_Async_Request class. * * @abstract */ abstract class WP_Async_Request { /** * Prefix * * (default value: 'wp') * * @var string */ protected $prefix = 'wp'; /** * Action * * (default value: 'async_request') * * @var string */ protected $action = 'async_request'; /** * Identifier * * @var mixed */ protected $identifier; /** * Data * * (default value: array()) * * @var array */ protected $data = array(); /** * Initiate new async request */ public function __construct() { $this->identifier = $this->prefix . '_' . $this->action; add_action( 'wp_ajax_' . $this->identifier, array( $this, 'maybe_handle' ) ); add_action( 'wp_ajax_nopriv_' . $this->identifier, array( $this, 'maybe_handle' ) ); } /** * Set data used during the request * * @param array $data Data. * * @return $this */ public function data( $data ) { $this->data = $data; return $this; } /** * Dispatch the async request * * @return array|WP_Error */ public function dispatch() { $url = add_query_arg( $this->get_query_args(), $this->get_query_url() ); $args = $this->get_post_args(); return wp_remote_post( esc_url_raw( $url ), $args ); } /** * Get query args * * @return array */ protected function get_query_args() { if ( property_exists( $this, 'query_args' ) ) { return $this->query_args; } return array( 'action' => $this->identifier, 'nonce' => wp_create_nonce( $this->identifier ), ); } /** * Get query URL * * @return string */ protected function get_query_url() { if ( property_exists( $this, 'query_url' ) ) { return $this->query_url; } return admin_url( 'admin-ajax.php' ); } /** * Get post args * * @return array */ protected function get_post_args() { if ( property_exists( $this, 'post_args' ) ) { return $this->post_args; } return array( 'timeout' => 0.01, 'blocking' => false, 'body' => $this->data, 'cookies' => $_COOKIE, 'sslverify' => apply_filters( 'https_local_ssl_verify', false ), ); } /** * Maybe handle * * Check for correct nonce and pass to handler. */ public function maybe_handle() { // Don't lock up other requests while processing session_write_close(); check_ajax_referer( $this->identifier, 'nonce' ); $this->handle(); wp_die(); } /** * Handle * * Override this method to perform any actions required * during the async request. */ abstract protected function handle(); } } batch-processing/class-wp-background-process-astra-addon.php 0000666 00000002704 15165304264 0020242 0 ustar 00 <?php /** * Database Background Process * * @package Astra * @since 2.1.3 */ if ( class_exists( 'WP_Background_Process' ) ) : /** * Database Background Process * * @since 2.1.3 */ class WP_Background_Process_Astra_Addon extends WP_Background_Process { /** * Database Process * * @var string */ protected $action = 'addon_database_migration'; /** * 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. * * @since 2.1.3 * * @param object $process Queue item object. * @return mixed */ protected function task( $process ) { do_action( 'astra_addon_batch_process_task' . '-' . $process, $process ); if ( function_exists( $process ) ) { call_user_func( $process ); } if ( 'update_db_version' === $process ) { Astra_Addon_Background_Updater::update_db_version(); } return false; } /** * Complete * * Override if applicable, but ensure that the below actions are * performed, or, call parent::complete(). * * @since 2.1.3 */ protected function complete() { error_log( 'Astra Addon: Batch Process Completed!' ); do_action( 'astra_addon_database_migration_complete' ); parent::complete(); } } endif; batch-processing/wp-background-process.php 0000666 00000026256 15165304264 0014754 0 ustar 00 <?php /** * WP Background Process * * @package WP-Background-Processing */ if ( ! class_exists( 'WP_Background_Process' ) ) { /** * Abstract WP_Background_Process class. * * @abstract * @extends WP_Async_Request */ abstract class WP_Background_Process extends WP_Async_Request { /** * Action * * (default value: 'background_process') * * @var string */ protected $action = 'background_process'; /** * Start time of current process. * * (default value: 0) * * @var int */ protected $start_time = 0; /** * Cron_hook_identifier * * @var mixed */ protected $cron_hook_identifier; /** * Cron_interval_identifier * * @var mixed */ protected $cron_interval_identifier; /** * Initiate new background process */ public function __construct() { parent::__construct(); $this->cron_hook_identifier = $this->identifier . '_cron'; $this->cron_interval_identifier = $this->identifier . '_cron_interval'; add_action( $this->cron_hook_identifier, array( $this, 'handle_cron_healthcheck' ) ); add_filter( 'cron_schedules', array( $this, 'schedule_cron_healthcheck' ) ); } /** * Dispatch * * @return void */ public function dispatch() { // Schedule the cron healthcheck. $this->schedule_event(); // Perform remote post. return parent::dispatch(); } /** * Push to queue * * @param mixed $data Data. * * @return $this */ public function push_to_queue( $data ) { $this->data[] = $data; return $this; } /** * Save queue * * @return $this */ public function save() { $key = $this->generate_key(); if ( ! empty( $this->data ) ) { update_site_option( $key, $this->data ); } return $this; } /** * Update queue * * @param string $key Key. * @param array $data Data. * * @return $this */ public function update( $key, $data ) { if ( ! empty( $data ) ) { update_site_option( $key, $data ); } return $this; } /** * Delete queue * * @param string $key Key. * * @return $this */ public function delete( $key ) { delete_site_option( $key ); return $this; } /** * Generate key * * Generates a unique key based on microtime. Queue items are * given a unique key so that they can be merged upon save. * * @param int $length Length. * * @return string */ protected function generate_key( $length = 64 ) { $unique = md5( microtime() . rand() ); $prepend = $this->identifier . '_batch_'; return substr( $prepend . $unique, 0, $length ); } /** * Maybe process queue * * Checks whether data exists within the queue and that * the process is not already running. */ public function maybe_handle() { // Don't lock up other requests while processing session_write_close(); if ( $this->is_process_running() ) { // Background process already running. wp_die(); } if ( $this->is_queue_empty() ) { // No data to process. wp_die(); } check_ajax_referer( $this->identifier, 'nonce' ); $this->handle(); wp_die(); } /** * Is queue empty * * @return bool */ protected function is_queue_empty() { global $wpdb; $wpdb->ast_db_table = $wpdb->options; $wpdb->ast_db_column = 'option_name'; if ( is_multisite() ) { $wpdb->ast_db_table = $wpdb->sitemeta; $wpdb->ast_db_column = 'meta_key'; } $key = $wpdb->esc_like( $this->identifier . '_batch_' ) . '%'; $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->ast_db_table} WHERE {$wpdb->ast_db_column} LIKE %s ", $key ) ); return ( $count > 0 ) ? false : true; } /** * Is process running * * Check whether the current process is already running * in a background process. */ protected function is_process_running() { if ( get_site_transient( $this->identifier . '_process_lock' ) ) { // Process already running. return true; } return false; } /** * Lock process * * Lock the process so that multiple instances can't run simultaneously. * Override if applicable, but the duration should be greater than that * defined in the time_exceeded() method. */ protected function lock_process() { $this->start_time = time(); // Set start time of current process. $lock_duration = ( property_exists( $this, 'queue_lock_time' ) ) ? $this->queue_lock_time : 60; // 1 minute $lock_duration = apply_filters( $this->identifier . '_queue_lock_time', $lock_duration ); set_site_transient( $this->identifier . '_process_lock', microtime(), $lock_duration ); } /** * Unlock process * * Unlock the process so that other instances can spawn. * * @return $this */ protected function unlock_process() { delete_site_transient( $this->identifier . '_process_lock' ); return $this; } /** * Get batch * * @return stdClass Return the first batch from the queue */ protected function get_batch() { global $wpdb; $wpdb->ast_db_table = $wpdb->options; $wpdb->ast_db_column = 'option_name'; $wpdb->ast_db_key_column = 'option_id'; $value_column = 'option_value'; if ( is_multisite() ) { $wpdb->ast_db_table = $wpdb->sitemeta; $wpdb->ast_db_column = 'meta_key'; $wpdb->ast_db_key_column = 'meta_id'; $value_column = 'meta_value'; } $key = $wpdb->esc_like( $this->identifier . '_batch_' ) . '%'; $query = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->ast_db_table} WHERE {$wpdb->ast_db_column} LIKE %s ORDER BY {$wpdb->ast_db_key_column} ASC LIMIT 1", $key ) ); $batch = new stdClass(); $batch->key = $query->{$wpdb->ast_db_column}; $batch->data = maybe_unserialize( $query->$value_column ); return $batch; } /** * Handle * * Pass each queue item to the task handler, while remaining * within server memory and time limit constraints. */ protected function handle() { $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->time_exceeded() || $this->memory_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->time_exceeded() && ! $this->memory_exceeded() && ! $this->is_queue_empty() ); $this->unlock_process(); // Start next batch or complete process. if ( ! $this->is_queue_empty() ) { $this->dispatch(); } else { $this->complete(); } wp_die(); } /** * Memory exceeded * * Ensures the batch process never exceeds 90% * of the maximum WordPress memory. * * @return bool */ protected function memory_exceeded() { $memory_limit = $this->get_memory_limit() * 0.9; // 90% of max memory $current_memory = memory_get_usage( true ); $return = false; if ( $current_memory >= $memory_limit ) { $return = true; } return apply_filters( $this->identifier . '_memory_exceeded', $return ); } /** * Get memory limit * * @return int */ protected function get_memory_limit() { if ( function_exists( 'ini_get' ) ) { $memory_limit = ini_get( 'memory_limit' ); } else { // Sensible default. $memory_limit = '128M'; } if ( ! $memory_limit || -1 === intval( $memory_limit ) ) { // Unlimited, set to 32GB. $memory_limit = '32000M'; } return intval( $memory_limit ) * 1024 * 1024; } /** * Time exceeded. * * Ensures the batch never exceeds a sensible time limit. * A timeout limit of 30s is common on shared hosting. * * @return bool */ protected function time_exceeded() { $finish = $this->start_time + apply_filters( $this->identifier . '_default_time_limit', 20 ); // 20 seconds $return = false; if ( time() >= $finish ) { $return = true; } return apply_filters( $this->identifier . '_time_exceeded', $return ); } /** * Complete. * * Override if applicable, but ensure that the below actions are * performed, or, call parent::complete(). */ protected function complete() { // Unschedule the cron healthcheck. $this->clear_scheduled_event(); } /** * Schedule cron healthcheck * * @param mixed $schedules Schedules. * @return mixed */ public function schedule_cron_healthcheck( $schedules ) { $interval = apply_filters( $this->identifier . '_cron_interval', 5 ); if ( property_exists( $this, 'cron_interval' ) ) { $interval = apply_filters( $this->identifier . '_cron_interval', $this->cron_interval ); } // Adds every 5 minutes to the existing schedules. $schedules[ $this->identifier . '_cron_interval' ] = array( 'interval' => MINUTE_IN_SECONDS * $interval, 'display' => sprintf( /* translators: %d Time interval */ __( 'Every %d Minutes' ), $interval ), ); return $schedules; } /** * 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. exit; } if ( $this->is_queue_empty() ) { // No data to process. $this->clear_scheduled_event(); exit; } $this->handle(); exit; } /** * Schedule event */ protected function schedule_event() { if ( ! wp_next_scheduled( $this->cron_hook_identifier ) ) { wp_schedule_event( time(), $this->cron_interval_identifier, $this->cron_hook_identifier ); } } /** * Clear scheduled event */ protected function clear_scheduled_event() { $timestamp = wp_next_scheduled( $this->cron_hook_identifier ); if ( $timestamp ) { wp_unschedule_event( $timestamp, $this->cron_hook_identifier ); } } /** * Cancel Process * * Stop processing queue items, clear cronjob and delete batch. */ public function cancel_process() { if ( ! $this->is_queue_empty() ) { $batch = $this->get_batch(); $this->delete( $batch->key ); wp_clear_scheduled_hook( $this->cron_hook_identifier ); } } /** * 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 mixed $item Queue item to iterate over. * * @return mixed */ abstract protected function task( $item ); } } module.php 0000666 00000002611 15165313675 0006562 0 ustar 00 <?php namespace Elementor\Modules\Library; use Elementor\Core\Base\Module as BaseModule; use Elementor\Modules\Library\Documents; use Elementor\Plugin; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } /** * Elementor library module. * * Elementor library module handler class is responsible for registering and * managing Elementor library modules. * * @since 2.0.0 */ class Module extends BaseModule { /** * Get module name. * * Retrieve the library module name. * * @since 2.0.0 * @access public * * @return string Module name. */ public function get_name() { return 'library'; } /** * Library module constructor. * * Initializing Elementor library module. * * @since 2.0.0 * @access public */ public function __construct() { Plugin::$instance->documents ->register_document_type( 'not-supported', Documents\Not_Supported::get_class_full_name() ) ->register_document_type( 'page', Documents\Page::get_class_full_name() ) ->register_document_type( 'section', Documents\Section::get_class_full_name() ); $experiments_manager = Plugin::$instance->experiments; // Register `Container` document type only if the experiment is active. if ( $experiments_manager->is_feature_active( 'container' ) ) { Plugin::$instance->documents ->register_document_type( 'container', Documents\Container::get_class_full_name() ); } } } documents/page.php 0000666 00000003521 15165313675 0010213 0 ustar 00 <?php namespace Elementor\Modules\Library\Documents; use Elementor\Core\DocumentTypes\Post; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } /** * Elementor page library document. * * Elementor page library document handler class is responsible for * handling a document of a page type. * * @since 2.0.0 */ class Page extends Library_Document { /** * Get document properties. * * Retrieve the document properties. * * @since 2.0.0 * @access public * @static * * @return array Document properties. */ public static function get_properties() { $properties = parent::get_properties(); $properties['support_wp_page_templates'] = true; $properties['support_kit'] = true; $properties['show_in_finder'] = true; return $properties; } public static function get_type() { return 'page'; } /** * Get document title. * * Retrieve the document title. * * @since 2.0.0 * @access public * @static * * @return string Document title. */ public static function get_title() { return esc_html__( 'Page', 'elementor' ); } public static function get_plural_title() { return esc_html__( 'Pages', 'elementor' ); } public static function get_add_new_title() { return esc_html__( 'Add New Page Template', 'elementor' ); } /** * @since 2.1.3 * @access public */ public function get_css_wrapper_selector() { return 'body.elementor-page-' . $this->get_main_id(); } /** * @since 3.1.0 * @access protected */ protected function register_controls() { parent::register_controls(); Post::register_hide_title_control( $this ); Post::register_style_controls( $this ); } protected function get_remote_library_config() { $config = parent::get_remote_library_config(); $config['type'] = 'page'; $config['default_route'] = 'templates/pages'; return $config; } } documents/library-document.php 0000666 00000003261 15165313675 0012560 0 ustar 00 <?php namespace Elementor\Modules\Library\Documents; use Elementor\Core\Base\Document; use Elementor\Modules\Library\Traits\Library; use Elementor\TemplateLibrary\Source_Local; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } /** * Elementor library document. * * Elementor library document handler class is responsible for handling * a document of the library type. * * @since 2.0.0 */ abstract class Library_Document extends Document { // Library Document Trait use Library; /** * The taxonomy type slug for the library document. */ const TAXONOMY_TYPE_SLUG = 'elementor_library_type'; /** * Get document properties. * * Retrieve the document properties. * * @since 2.0.0 * @access public * @static * * @return array Document properties. */ public static function get_properties() { $properties = parent::get_properties(); $properties['admin_tab_group'] = 'library'; $properties['show_in_library'] = true; $properties['register_type'] = true; $properties['cpt'] = [ Source_Local::CPT ]; return $properties; } /** * Get initial config. * * Retrieve the current element initial configuration. * * Adds more configuration on top of the controls list and the tabs assigned * to the control. This method also adds element name, type, icon and more. * * @since 2.9.0 * @access protected * * @return array The initial config. */ public function get_initial_config() { $config = parent::get_initial_config(); $config['library'] = [ 'save_as_same_type' => true, ]; return $config; } public function get_content( $with_css = false ) { return do_shortcode( parent::get_content( $with_css ) ); } } documents/container.php 0000666 00000001704 15165313675 0011262 0 ustar 00 <?php namespace Elementor\Modules\Library\Documents; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } /** * Elementor container library document. * * Elementor container library document handler class is responsible for * handling a document of a container type. * * @since 2.0.0 */ class Container extends Library_Document { public static function get_properties() { $properties = parent::get_properties(); $properties['support_kit'] = true; return $properties; } /** * Get document name. * * Retrieve the document name. * * @since 2.0.0 * @access public * * @return string Document name. */ public function get_name() { return 'container'; } /** * Get document title. * * Retrieve the document title. * * @since 2.0.0 * @access public * @static * * @return string Document title. */ public static function get_title() { return esc_html__( 'Container', 'elementor' ); } } documents/section.php 0000666 00000001665 15165313675 0010752 0 ustar 00 <?php namespace Elementor\Modules\Library\Documents; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } /** * Elementor section library document. * * Elementor section library document handler class is responsible for * handling a document of a section type. * * @since 2.0.0 */ class Section extends Library_Document { public static function get_properties() { $properties = parent::get_properties(); $properties['support_kit'] = true; $properties['show_in_finder'] = true; return $properties; } public static function get_type() { return 'section'; } /** * Get document title. * * Retrieve the document title. * * @since 2.0.0 * @access public * @static * * @return string Document title. */ public static function get_title() { return esc_html__( 'Section', 'elementor' ); } public static function get_plural_title() { return esc_html__( 'Sections', 'elementor' ); } } documents/not-supported.php 0000666 00000002673 15165313675 0012131 0 ustar 00 <?php namespace Elementor\Modules\Library\Documents; use Elementor\TemplateLibrary\Source_Local; use Elementor\Utils; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } /** * Elementor section library document. * * Elementor section library document handler class is responsible for * handling a document of a section type. * */ class Not_Supported extends Library_Document { /** * Get document properties. * * Retrieve the document properties. * * @access public * @static * * @return array Document properties. */ public static function get_properties() { $properties = parent::get_properties(); $properties['admin_tab_group'] = ''; $properties['register_type'] = false; $properties['is_editable'] = false; $properties['show_in_library'] = false; $properties['show_in_finder'] = false; return $properties; } public static function get_type() { return 'not-supported'; } /** * Get document title. * * Retrieve the document title. * * @access public * @static * * @return string Document title. */ public static function get_title() { return esc_html__( 'Not Supported', 'elementor' ); } public function save_template_type() { // Do nothing. } public function print_admin_column_type() { Utils::print_unescaped_internal_string( self::get_title() ); } public function filter_admin_row_actions( $actions ) { unset( $actions['view'] ); return $actions; } } user-favorites.php 0000666 00000005265 15165313675 0010263 0 ustar 00 <?php namespace Elementor\Modules\Library; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } class User_Favorites { const USER_META_KEY = 'elementor_library_favorites'; /** * @var int */ private $user_id; /** * @var array|null */ private $cache; /** * User_Favorites constructor. * * @param $user_id */ public function __construct( $user_id ) { $this->user_id = $user_id; } /** * @param null $vendor * @param null $resource * @param false $ignore_cache * * @return array */ public function get( $vendor = null, $resource = null, $ignore_cache = false ) { if ( $ignore_cache || empty( $this->cache ) ) { $this->cache = get_user_meta( $this->user_id, self::USER_META_KEY, true ); } if ( ! $this->cache || ! is_array( $this->cache ) ) { return []; } if ( $vendor && $resource ) { $key = $this->get_key( $vendor, $resource ); return isset( $this->cache[ $key ] ) ? $this->cache[ $key ] : []; } return $this->cache; } /** * @param $vendor * @param $resource * @param $id * * @return bool */ public function exists( $vendor, $resource, $id ) { return in_array( $id, $this->get( $vendor, $resource ), true ); } /** * @param $vendor * @param $resource * @param array $value * * @return $this * @throws \Exception */ public function save( $vendor, $resource, $value = [] ) { $all_favorites = $this->get(); $all_favorites[ $this->get_key( $vendor, $resource ) ] = $value; $result = update_user_meta( $this->user_id, self::USER_META_KEY, $all_favorites ); if ( false === $result ) { throw new \Exception( 'Failed to save user favorites.' ); } $this->cache = $all_favorites; return $this; } /** * @param $vendor * @param $resource * @param $id * * @return $this * @throws \Exception */ public function add( $vendor, $resource, $id ) { $favorites = $this->get( $vendor, $resource ); if ( in_array( $id, $favorites, true ) ) { return $this; } $favorites[] = $id; $this->save( $vendor, $resource, $favorites ); return $this; } /** * @param $vendor * @param $resource * @param $id * * @return $this * @throws \Exception */ public function remove( $vendor, $resource, $id ) { $favorites = $this->get( $vendor, $resource ); if ( ! in_array( $id, $favorites, true ) ) { return $this; } $favorites = array_filter( $favorites, function ( $item ) use ( $id ) { return $item !== $id; } ); $this->save( $vendor, $resource, $favorites ); return $this; } /** * @param $vendor * @param $resource * * @return string */ private function get_key( $vendor, $resource ) { return "{$vendor}/{$resource}"; } } traits/library.php 0000666 00000002021 15165313675 0010242 0 ustar 00 <?php namespace Elementor\Modules\Library\Traits; use Elementor\TemplateLibrary\Source_Local; /** * Elementor Library Trait * * This trait is used by all Library Documents and Landing Pages. * * @since 3.1.0 */ trait Library { /** * Print Admin Column Type * * Runs on WordPress' 'manage_{custom post type}_posts_custom_column' hook to modify each row's content. * * @since 3.1.0 * @access public */ public function print_admin_column_type() { $admin_filter_url = admin_url( Source_Local::ADMIN_MENU_SLUG . '&elementor_library_type=' . $this->get_name() ); //PHPCS - Not a user input printf( '<a href="%s">%s</a>', $admin_filter_url, $this->get_title() ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } /** * Save document type. * * Set new/updated document type. * * @since 3.1.0 * @access public */ public function save_template_type() { parent::save_template_type(); wp_set_object_terms( $this->post->ID, $this->get_name(), Source_Local::TAXONOMY_TYPE_SLUG ); } }
| ver. 1.4 |
Github
|
.
| PHP 5.4.45 | Generation time: 0 |
proxy
|
phpinfo
|
Settings