Файловый менеджер - Редактировать - /var/www/xthruster/html/wp-content/uploads/flags/traits.tar
Назад
validator.php 0000644 00000002150 14720520565 0007246 0 ustar 00 <?php /** * Validation traits. * * @package \Optml\Inc\Traits * @author Optimole <friends@optimole.com> */ trait Optml_Validator { /** * Check if the value is a valid numeric. * * @param mixed $value The value to check. * * @return bool */ public function is_valid_numeric( $value ) { if ( isset( $value ) && ! empty( $value ) && is_numeric( $value ) ) { return true; } return false; } /** * Check if the URl is a GIF url. * * @param string $url URL to check. * * @return bool Is Gif? */ public function is_valid_gif( $url ) { $type = wp_check_filetype( $url, [ 'gif' => 'image/gif' ] ); if ( empty( $type['ext'] ) ) { return false; } return true; } /** * Check if the url has an accepted mime type extension. * * @param mixed $url The url to check. * * @return bool|string */ public function is_valid_mimetype_from_url( $url, $filters = [] ) { $type = wp_check_filetype( $url, Optml_Config::$all_extensions ); if ( empty( $type['ext'] ) ) { return false; } return Optml_Filters::should_do_extension( $filters, $type['ext'] ); } } dam_offload_utils.php 0000644 00000017604 14720520565 0010746 0 ustar 00 <?php trait Optml_Dam_Offload_Utils { use Optml_Normalizer; /** * Checks that the attachment is a DAM image. * * @param int $post_id The attachment ID. * * @return bool */ private function is_dam_imported_image( $post_id ) { $meta = get_post_meta( $post_id, Optml_Dam::OM_DAM_IMPORTED_FLAG, true ); if ( empty( $meta ) ) { return false; } return true; } /** * Checks if the attachment is offloaded using the old method. * * @param int $id The attachment ID. * * @return bool */ private function is_legacy_offloaded_attachment( $id ) { $id = apply_filters( 'optml_ensure_source_attachment_id', $id ); return ! $this->is_new_offloaded_attachment( $id ) && ! empty( get_post_meta( $id, Optml_Media_Offload::META_KEYS['offloaded'] ) ); } /** * Check if it's a newly offloaded attachment * * @param int $id The attachment ID. * * @return bool */ private function is_new_offloaded_attachment( $id ) { $id = apply_filters( 'optml_ensure_source_attachment_id', $id ); return ! empty( get_post_meta( $id, Optml_Media_Offload::OM_OFFLOADED_FLAG, true ) ); } /** * Get all registered image sizes. * * @return array */ private function get_all_image_sizes() { $additional_sizes = wp_get_additional_image_sizes(); $intermediate = get_intermediate_image_sizes(); $all = []; foreach ( $intermediate as $size ) { if ( isset( $additional_sizes[ $size ] ) ) { $all[ $size ] = [ 'width' => $additional_sizes[ $size ]['width'], 'height' => $additional_sizes[ $size ]['height'], 'crop' => isset( $additional_sizes[ $size ]['crop'] ) ? $additional_sizes[ $size ]['crop'] : false, ]; } else { $all[ $size ] = [ 'width' => (int) get_option( $size . '_size_w' ), 'height' => (int) get_option( $size . '_size_h' ), 'crop' => get_option( $size . '_crop' ), ]; } if ( ! empty( $additional_sizes[ $size ]['crop'] ) ) { $all[ $size ]['crop'] = is_array( $additional_sizes[ $size ]['crop'] ) ? $additional_sizes[ $size ]['crop'] : (bool) $additional_sizes[ $size ]['crop']; } else { $all[ $size ]['crop'] = (bool) get_option( $size . '_crop' ); } } return $all; } /** * Get the dimension from optimized url. * * @param string $url The image url. * * @return array Contains the width and height values in this order. */ private function parse_dimension_from_optimized_url( $url ) { $catch = []; $height = 'auto'; $width = 'auto'; preg_match( '/\/w:(.*)\/h:(.*)\/q:/', $url, $catch ); if ( isset( $catch[1] ) && isset( $catch[2] ) ) { $width = $catch[1]; $height = $catch[2]; } return [ $width, $height ]; } /** * Check if we're in the attachment edit page. * * /wp-admin/post.php?post=<id>&action=edit * * Send whatever comes from the DAM. * * @param int $attachment_id attachment id. * * @return bool */ private function is_attachment_edit_page( $attachment_id ) { if ( ! is_admin() ) { return false; } if ( ! function_exists( 'get_current_screen' ) ) { return false; } $screen = get_current_screen(); if ( ! isset( $screen->base ) ) { return false; } if ( $screen->base !== 'post' ) { return false; } if ( $screen->post_type !== 'attachment' ) { return false; } if ( $screen->id !== 'attachment' ) { return false; } if ( ! isset( $_GET['post'] ) ) { return false; } if ( (int) sanitize_text_field( $_GET['post'] ) !== $attachment_id ) { return false; } return true; } /** * Used to filter the image metadata. Adds optimized image url for all image sizes. * * @param array $metadata The attachment metadata. * @param int $id The attachment id. * * @return mixed */ private function get_altered_metadata_for_remote_images( $metadata, $id ) { $post = get_post( $id ); $sizes_meta = []; // SVG files don't have a width/height so we add a dummy one. These are vector images so it doesn't matter. $is_svg = ( $post->post_mime_type === Optml_Config::$image_extensions['svg'] ); if ( $is_svg ) { $metadata['width'] = 150; $metadata['height'] = 150; } if ( ! isset( $metadata['height'] ) || ! isset( $metadata['width'] ) ) { return $metadata; } $sizes = Optml_App_Replacer::image_sizes(); foreach ( $sizes as $size => $args ) { // check if the image is portrait or landscape using attachment metadata. $dimensions = $this->size_to_dimension( $size, $metadata ); $sizes_meta[ $size ] = [ 'file' => $metadata['file'], 'width' => $dimensions['width'], 'height' => $dimensions['height'], 'mime-type' => $post->post_mime_type, ]; } $metadata['sizes'] = $sizes_meta; return $metadata; } /** * Get the scaled URL. * * @param string $url Original URL. * * @return string */ private function get_scaled_url( $url ) { $extension = pathinfo( $url, PATHINFO_EXTENSION ); return str_replace( '.' . $extension, '-scaled.' . $extension, $url ); } /** * Check if the URL is a scaled image. * * @param string $url The URL to check. * * @return bool */ private function is_scaled_url( $url ) { return strpos( $url, '-scaled.' ) !== false; } /** * Check if the image has been offloaded completely. * * @param int $id The attachment ID. * * @return bool */ private function is_completed_offload( $id ) { // This is the flag that is used to mark the image as offloaded at the end. $completed = ! empty( get_post_meta( $id, Optml_Media_Offload::OM_OFFLOADED_FLAG, true ) ); if ( $completed ) { return true; } // In some rare cases the image is offloaded but the flag is not set so we can alternatively check this using the file path. $meta = wp_get_attachment_metadata( $id ); if ( ! isset( $meta['file'] ) ) { return false; } if ( Optml_Media_Offload::is_uploaded_image( $meta['file'] ) ) { return true; } return false; } /** * Get the attachment ID from URL. * * @param string $input_url The attachment URL. * * @return int */ private function attachment_url_to_post_id( $input_url ) { $cached = Optml_Attachment_Cache::get_cached_attachment_id( $input_url ); if ( $cached !== false ) { return (int) $cached; } $url = $this->strip_image_size( $input_url ); $attachment_id = attachment_url_to_postid( $url ); if ( $attachment_id === 0 && ! $this->is_scaled_url( $url ) ) { $scaled_url = $this->get_scaled_url( $url ); $attachment_id = attachment_url_to_postid( $scaled_url ); } /* * TODO: The logic is a mess, we need to refactor at some point. * Websites may transition between 'www' subdomains and apex domains, potentially breaking references to hosted images. This can cause issues when attempting to match attachment IDs if images are linked using outdated domains. The logic is checking for alternative domains and consider the use of 'scaled' prefixes in image URLs for large images, which might affect ID matching. */ if ( $attachment_id === 0 ) { if ( strpos( $url, 'www.' ) !== false ) { $variant_url = str_replace( 'www.', '', $url ); $attachment_id = attachment_url_to_postid( $variant_url ); } else { $variant_url = str_replace( '://', '://www.', $url ); $attachment_id = attachment_url_to_postid( $variant_url ); } if ( $attachment_id === 0 && ! $this->is_scaled_url( $variant_url ) ) { $scaled_url = $this->get_scaled_url( $variant_url ); $attachment_id = attachment_url_to_postid( $scaled_url ); } } Optml_Attachment_Cache::set_cached_attachment_id( $input_url, $attachment_id ); return $attachment_id; } /** * Strips the image size from the URL. * * @param string $url URL to strip. * * @return string */ private function strip_image_size( $url ) { if ( preg_match( '#(-\d+x\d+(?:_c)?|(@2x))\.(' . implode( '|', array_keys( Optml_Config::$image_extensions ) ) . '){1}$#i', $url, $src_parts ) ) { $url = str_replace( $src_parts[1], '', $url ); } return $url; } } normalizer.php 0000644 00000021002 14720520565 0007440 0 ustar 00 <?php use Optimole\Sdk\Resource\ImageProperty\ResizeTypeProperty; use Optimole\Sdk\ValueObject\Position; /** * Normalization traits. * * @package \Optml\Inc\Traits * @author Optimole <friends@optimole.com> */ trait Optml_Normalizer { /** * Normalize value to boolean. * * @param mixed $value Value to process. * * @return bool */ public function to_boolean( $value ) { if ( in_array( $value, [ 'yes', 'enabled', 'true', '1' ], true ) ) { return true; } if ( in_array( $value, [ 'no', 'disabled', 'false', '0' ], true ) ) { return false; } return boolval( $value ); } /** * Return domain hash. * * @param string $domain Full url. * * @return string Domain hash. */ public function to_domain_hash( $domain ) { $domain_parts = parse_url( $domain ); $domain = isset( $domain_parts['host'] ) ? $domain_parts['host'] : ''; $prefix = substr( $domain, 0, 4 ); if ( $prefix === 'www.' ) { $domain = substr( $domain, 4 ); } return base64_encode( $domain ); } /** * Strip slashes on unicode encoded strings. * * @param string $content Input string. * * @return string Decoded string. */ public function strip_slashes( $content ) { return html_entity_decode( stripslashes( preg_replace( '/\\\u([\da-fA-F]{4})/', '&#x\1;', $content ) ) ); } /** * Normalize value to positive integer. * * @param mixed $value Value to process. * * @return integer */ public function to_positive_integer( $value ) { $integer = (int) $value; return ( $integer > 0 ) ? $integer : 0; } /** * Normalize value to map. * * @param mixed $value Value to process. * @param array $map Associative list from witch to return. * @param mixed $initial Default. * * @return mixed */ public function to_map_values( $value, $map, $initial ) { if ( in_array( $value, $map, true ) ) { return $value; } return $initial; } /** * Normalize value to an accepted quality. * * @param mixed $value Value to process. * * @return mixed */ public function to_accepted_quality( $value ) { if ( is_numeric( $value ) ) { return intval( $value ); } $value = trim( $value ); $accepted_qualities = [ 'eco' => 'eco', 'auto' => 'auto', 'mauto' => 'mauto', 'high_c' => 55, 'medium_c' => 75, 'low_c' => 90, ]; if ( array_key_exists( $value, $accepted_qualities ) ) { return $accepted_qualities[ $value ]; } // Legacy values. return 60; } /** * Normalize value to an accepted minify. * * @param mixed $value Value to process. * * @return mixed */ public function to_accepted_minify( $value ) { if ( is_numeric( $value ) ) { return $this->to_bound_integer( $value, 0, 1 ); } return 'auto'; } /** * Normalize value to an integer within bounds. * * @param mixed $value Value to process. * @param integer $min Lower bound. * @param integer $max Upper bound. * * @return integer */ public function to_bound_integer( $value, $min, $max ) { $integer = absint( $value ); if ( $integer < $min ) { $integer = $min; } if ( $integer > $max ) { $integer = $max; } return $integer; } /** * Convert image size to dimensions. * * This function takes an image size and its metadata, and returns the dimensions * of the image based on the specified size. It handles different cases such as * custom sizes, predefined sizes, and full size. * * @param mixed $size The size of the image. Can be an array of width and height, a predefined size, or 'full'. * @param array $image_meta Metadata of the image, including width and height. * * @return array The dimensions of the image, including width, height, and optional resize parameters. */ public function size_to_dimension( $size, $image_meta ) { // default size $sizes = [ 'width' => isset( $image_meta['width'] ) ? intval( $image_meta['width'] ) : false, 'height' => isset( $image_meta['height'] ) ? intval( $image_meta['height'] ) : false, ]; $image_args = Optml_App_Replacer::image_sizes(); switch ( $size ) { case is_array( $size ): $width = isset( $size[0] ) ? (int) $size[0] : false; $height = isset( $size[1] ) ? (int) $size[1] : false; if ( ! $width || ! $height ) { break; } $image_resized = image_resize_dimensions( $sizes['width'], $sizes['height'], $width, $height ); if ( $image_resized ) { $width = $image_resized[6]; $height = $image_resized[7]; } else { $width = $image_meta['width']; $height = $image_meta['height']; } list( $sizes['width'], $sizes['height'] ) = image_constrain_size_for_editor( $width, $height, $size ); break; case 'full' !== $size && isset( $image_args[ $size ] ): $image_resized = image_resize_dimensions( $sizes['width'], $sizes['height'], $image_args[ $size ]['width'], $image_args[ $size ]['height'], $image_args[ $size ]['crop'] ); if ( $image_resized ) { // This could be false when the requested image size is larger than the full-size image. $sizes['width'] = $image_resized[6]; $sizes['height'] = $image_resized[7]; } // There are cases when the image meta is missing and image size is non existent, see SVG image handling. if ( ! $sizes['width'] || ! $sizes['height'] ) { break; } list( $sizes['width'], $sizes['height'] ) = image_constrain_size_for_editor( $sizes['width'], $sizes['height'], $size, 'display' ); $sizes['resize'] = $this->to_optml_crop( $image_args[ $size ]['crop'] ); break; } return $sizes; } /** * Normalize arguments for crop. * * @param array|bool $crop_args Crop arguments. * * @return array */ public function to_optml_crop( $crop_args = [] ) { $enlarge = false; if ( isset( $crop_args['enlarge'] ) ) { $enlarge = $crop_args['enlarge']; $crop_args = $crop_args['crop']; } if ( $crop_args === true ) { return [ 'type' => ResizeTypeProperty::FILL, 'enlarge' => $enlarge, 'gravity' => Position::CENTER, ]; } if ( $crop_args === false || ! is_array( $crop_args ) || count( $crop_args ) !== 2 ) { return []; } $allowed_x = [ 'left' => true, 'center' => true, 'right' => true, ]; $allowed_y = [ 'top' => true, 'center' => true, 'bottom' => true, ]; $allowed_gravities = [ 'left' => Position::WEST, 'right' => Position::EAST, 'top' => Position::NORTH, 'bottom' => Position::SOUTH, 'lefttop' => Position::NORTH_WEST, 'leftbottom' => Position::SOUTH_WEST, 'righttop' => Position::NORTH_EAST, 'rightbottom' => Position::SOUTH_EAST, 'centertop' => [ 0.5, 0 ], 'centerbottom' => [ 0.5, 1 ], 'leftcenter' => [ 0, 0.5 ], 'rightcenter' => [ 1, 0.5 ], ]; $gravity = Position::CENTER; $key_search = ( $crop_args[0] === true ? '' : ( isset( $allowed_x[ $crop_args[0] ] ) ? $crop_args[0] : '' ) ) . ( $crop_args[1] === true ? '' : ( isset( $allowed_y[ $crop_args[1] ] ) ? $crop_args[1] : '' ) ); if ( array_key_exists( $key_search, $allowed_gravities ) ) { $gravity = $allowed_gravities[ $key_search ]; } return [ 'type' => ResizeTypeProperty::FILL, 'enlarge' => $enlarge, 'gravity' => $gravity, ]; } /** * Normalize arguments for watermark. * * @param array $watermark_args Watermark arguments. * * @return array */ public function to_optml_watermark( $watermark_args = [] ) { $allowed_gravities = [ 'left' => Position::WEST, 'right' => Position::EAST, 'top' => Position::NORTH, 'bottom' => Position::SOUTH, 'left_top' => Position::NORTH_WEST, 'left_bottom' => Position::SOUTH_WEST, 'right_top' => Position::NORTH_EAST, 'right_bottom' => Position::SOUTH_EAST, ]; $gravity = Position::CENTER; if ( isset( $watermark_args['position'] ) && array_key_exists( $watermark_args['position'], $allowed_gravities ) ) { $gravity = $allowed_gravities[ $watermark_args['position'] ]; } return [ 'opacity' => 1, 'position' => $gravity, ]; } /** * If missing, add schema to urls. * * @param string $url Url to check. * * @return string */ public function add_schema( $url ) { $schema_url = $url; $should_add_schema = false; if ( function_exists( 'str_starts_with' ) ) { $should_add_schema = str_starts_with( $schema_url, '//' ); } else { $should_add_schema = substr( $schema_url, 0, strlen( '//' ) ) === '//'; } if ( $should_add_schema ) { $schema_url = is_ssl() ? 'https:' : 'http:' . $schema_url; } return $schema_url; } }
| ver. 1.4 |
Github
|
.
| PHP 7.4.3-4ubuntu2.24 | Генерация страницы: 0 |
proxy
|
phpinfo
|
Настройка