Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/clone/wp-conte.../plugins/accelera.../includes/vendor
File: aq_resizer.php
<?php
[0] Fix | Delete
// Exit if accessed directly
[1] Fix | Delete
if ( ! defined( 'ABSPATH' ) ) {
[2] Fix | Delete
exit;
[3] Fix | Delete
}
[4] Fix | Delete
/**
[5] Fix | Delete
* Aqua Resizer plugin
[6] Fix | Delete
* Version 1.2.2
[7] Fix | Delete
*
[8] Fix | Delete
* Dual licensed under the MIT and GPL licenses:
[9] Fix | Delete
* http://www.opensource.org/licenses/mit-license.php
[10] Fix | Delete
* http://sam.zoy.org/wtfpl/
[11] Fix | Delete
*
[12] Fix | Delete
* Thanks to Aqua Resizer Team for some excellent contributions!
[13] Fix | Delete
*
[14] Fix | Delete
*
[15] Fix | Delete
* Title : Aqua Resizer
[16] Fix | Delete
* Description : Resizes WordPress images on the fly
[17] Fix | Delete
* Version : 1.2.2
[18] Fix | Delete
* Author : Syamil MJ
[19] Fix | Delete
* Author URI : http://aquagraphite.com
[20] Fix | Delete
* License : WTFPL - http://sam.zoy.org/wtfpl/
[21] Fix | Delete
* Documentation : https://github.com/sy4mil/Aqua-Resizer/
[22] Fix | Delete
*
[23] Fix | Delete
* @param string $url - (required) must be uploaded using wp media uploader
[24] Fix | Delete
* @param int $width - (required)
[25] Fix | Delete
* @param int $height - (optional)
[26] Fix | Delete
* @param bool $crop - (optional) default to soft crop
[27] Fix | Delete
* @param bool $single - (optional) returns an array if false
[28] Fix | Delete
* @param bool $upscale - (optional) resizes smaller images
[29] Fix | Delete
* @uses wp_upload_dir()
[30] Fix | Delete
* @uses image_resize_dimensions()
[31] Fix | Delete
* @uses wp_get_image_editor()
[32] Fix | Delete
*
[33] Fix | Delete
* @return str|array
[34] Fix | Delete
*/
[35] Fix | Delete
[36] Fix | Delete
if(!class_exists('Aq_Resize')) {
[37] Fix | Delete
class Aq_Exception extends Exception {}
[38] Fix | Delete
[39] Fix | Delete
class Aq_Resize
[40] Fix | Delete
{
[41] Fix | Delete
/**
[42] Fix | Delete
* The singleton instance
[43] Fix | Delete
*/
[44] Fix | Delete
static private $instance = null;
[45] Fix | Delete
[46] Fix | Delete
/**
[47] Fix | Delete
* Should an Aq_Exception be thrown on error?
[48] Fix | Delete
* If false (default), then the error will just be logged.
[49] Fix | Delete
*/
[50] Fix | Delete
public $throwOnError = false;
[51] Fix | Delete
[52] Fix | Delete
/**
[53] Fix | Delete
* No initialization allowed
[54] Fix | Delete
*/
[55] Fix | Delete
private function __construct() {}
[56] Fix | Delete
[57] Fix | Delete
/**
[58] Fix | Delete
* No cloning allowed
[59] Fix | Delete
*/
[60] Fix | Delete
private function __clone() {}
[61] Fix | Delete
[62] Fix | Delete
/**
[63] Fix | Delete
* For your custom default usage you may want to initialize an Aq_Resize object by yourself and then have own defaults
[64] Fix | Delete
*/
[65] Fix | Delete
static public function getInstance() {
[66] Fix | Delete
if(self::$instance == null) {
[67] Fix | Delete
self::$instance = new self;
[68] Fix | Delete
}
[69] Fix | Delete
[70] Fix | Delete
return self::$instance;
[71] Fix | Delete
}
[72] Fix | Delete
[73] Fix | Delete
/**
[74] Fix | Delete
* Run, forest.
[75] Fix | Delete
*/
[76] Fix | Delete
public function process( $url, $width = null, $height = null, $crop = null, $single = true, $upscale = false ) {
[77] Fix | Delete
try {
[78] Fix | Delete
// Validate inputs.
[79] Fix | Delete
if (!$url)
[80] Fix | Delete
throw new Aq_Exception('$url parameter is required');
[81] Fix | Delete
if (!$width)
[82] Fix | Delete
throw new Aq_Exception('$width parameter is required');
[83] Fix | Delete
[84] Fix | Delete
// Caipt'n, ready to hook.
[85] Fix | Delete
if ( true === $upscale ) add_filter( 'image_resize_dimensions', array($this, 'aq_upscale'), 10, 6 );
[86] Fix | Delete
[87] Fix | Delete
// Define upload path & dir.
[88] Fix | Delete
$upload_info = wp_upload_dir();
[89] Fix | Delete
$upload_dir = $upload_info['basedir'];
[90] Fix | Delete
$upload_url = $upload_info['baseurl'];
[91] Fix | Delete
[92] Fix | Delete
$http_prefix = "http://";
[93] Fix | Delete
$https_prefix = "https://";
[94] Fix | Delete
$relative_prefix = "//"; // The protocol-relative URL
[95] Fix | Delete
[96] Fix | Delete
/* if the $url scheme differs from $upload_url scheme, make them match
[97] Fix | Delete
if the schemes differe, images don't show up. */
[98] Fix | Delete
if(!strncmp($url,$https_prefix,strlen($https_prefix))){ //if url begins with https:// make $upload_url begin with https:// as well
[99] Fix | Delete
$upload_url = str_replace($http_prefix,$https_prefix,$upload_url);
[100] Fix | Delete
}
[101] Fix | Delete
elseif(!strncmp($url,$http_prefix,strlen($http_prefix))){ //if url begins with http:// make $upload_url begin with http:// as well
[102] Fix | Delete
$upload_url = str_replace($https_prefix,$http_prefix,$upload_url);
[103] Fix | Delete
}
[104] Fix | Delete
elseif(!strncmp($url,$relative_prefix,strlen($relative_prefix))){ //if url begins with // make $upload_url begin with // as well
[105] Fix | Delete
$upload_url = str_replace(array( 0 => "$http_prefix", 1 => "$https_prefix"),$relative_prefix,$upload_url);
[106] Fix | Delete
}
[107] Fix | Delete
$is_cdn = false;
[108] Fix | Delete
$cdn_url = '';
[109] Fix | Delete
$cdn_url_main = '';
[110] Fix | Delete
[111] Fix | Delete
// Check if $img_url is not local.
[112] Fix | Delete
if ( false === strpos( $url, $upload_url ) ) {
[113] Fix | Delete
$is_cdn = true;
[114] Fix | Delete
$cdn_url_main = $cdn_url = $url;
[115] Fix | Delete
// Return the original array
[116] Fix | Delete
$wp_upload_dir = wp_upload_dir();
[117] Fix | Delete
$dir_baseurl = $wp_upload_dir['baseurl'];
[118] Fix | Delete
$dir_baseurl = explode('/', $dir_baseurl);
[119] Fix | Delete
$dir_name = end($dir_baseurl);
[120] Fix | Delete
$cdn_url = explode($dir_name, $cdn_url);
[121] Fix | Delete
if ( ! isset($cdn_url[1]) ) {
[122] Fix | Delete
$cdn_url = array();
[123] Fix | Delete
$cdn_url[1] = '';
[124] Fix | Delete
}
[125] Fix | Delete
$hybid_url = $upload_url . $cdn_url[1];
[126] Fix | Delete
// this will append crop path in the url to generate the image locally
[127] Fix | Delete
$url = $hybid_url;
[128] Fix | Delete
}
[129] Fix | Delete
// Define path of image.
[130] Fix | Delete
$rel_path = str_replace( $upload_url, '', $url );
[131] Fix | Delete
$img_path = '';
[132] Fix | Delete
if($rel_path){
[133] Fix | Delete
$img_path = $upload_dir . $rel_path;
[134] Fix | Delete
}
[135] Fix | Delete
[136] Fix | Delete
// Check if img path exists, and is an image indeed.
[137] Fix | Delete
if ( ! file_exists( $img_path ) or ! getimagesize( $img_path ) ){
[138] Fix | Delete
// Return the Original CDN array
[139] Fix | Delete
return array (
[140] Fix | Delete
0 => $cdn_url_main,
[141] Fix | Delete
1 => $width,
[142] Fix | Delete
2 => $height
[143] Fix | Delete
);
[144] Fix | Delete
}
[145] Fix | Delete
// Get image info.
[146] Fix | Delete
$info = pathinfo( $img_path );
[147] Fix | Delete
$ext = $info['extension'];
[148] Fix | Delete
list( $orig_w, $orig_h ) = getimagesize( $img_path );
[149] Fix | Delete
[150] Fix | Delete
// Get image size after cropping.
[151] Fix | Delete
$dims = image_resize_dimensions( $orig_w, $orig_h, $width, $height, $crop );
[152] Fix | Delete
if(!empty($dims[4])){
[153] Fix | Delete
$dst_w = $dims[4];
[154] Fix | Delete
}else{
[155] Fix | Delete
$dst_w = '';
[156] Fix | Delete
}
[157] Fix | Delete
if(!empty($dims[5])){
[158] Fix | Delete
$dst_h = $dims[5];
[159] Fix | Delete
}else{
[160] Fix | Delete
$dst_h = '';
[161] Fix | Delete
}
[162] Fix | Delete
[163] Fix | Delete
[164] Fix | Delete
// Return the original image only if it exactly fits the needed measures.
[165] Fix | Delete
if ( ! $dims || ( ( ( null === $height && $orig_w == $width ) xor ( null === $width && $orig_h == $height ) ) xor ( $height == $orig_h && $width == $orig_w ) ) ) {
[166] Fix | Delete
$img_url = $url;
[167] Fix | Delete
$dst_w = $orig_w;
[168] Fix | Delete
$dst_h = $orig_h;
[169] Fix | Delete
} else {
[170] Fix | Delete
// Use this to check if cropped image already exists, so we can return that instead.
[171] Fix | Delete
$suffix = "{$dst_w}x{$dst_h}";
[172] Fix | Delete
$dst_rel_path = str_replace( '.' . $ext, '', $rel_path );
[173] Fix | Delete
$destfilename = "{$upload_dir}{$dst_rel_path}-{$suffix}.{$ext}";
[174] Fix | Delete
[175] Fix | Delete
if ( ! $dims || ( true == $crop && false == $upscale && ( $dst_w < $width || $dst_h < $height ) ) ) {
[176] Fix | Delete
// Can't resize, so return false saying that the action to do could not be processed as planned.
[177] Fix | Delete
throw new Aq_Exception('Unable to resize image because image_resize_dimensions() failed');
[178] Fix | Delete
}
[179] Fix | Delete
// Else check if cache exists.
[180] Fix | Delete
elseif ( file_exists( $destfilename ) && getimagesize( $destfilename ) ) {
[181] Fix | Delete
$img_url = "{$upload_url}{$dst_rel_path}-{$suffix}.{$ext}";
[182] Fix | Delete
}
[183] Fix | Delete
// Else, we resize the image and return the new resized image url.
[184] Fix | Delete
else {
[185] Fix | Delete
[186] Fix | Delete
$editor = wp_get_image_editor( $img_path );
[187] Fix | Delete
[188] Fix | Delete
if ( is_wp_error( $editor ) || is_wp_error( $editor->resize( $width, $height, $crop ) ) ) {
[189] Fix | Delete
[190] Fix | Delete
// Return the Original array
[191] Fix | Delete
return array (
[192] Fix | Delete
0 => $url,
[193] Fix | Delete
1 => $width,
[194] Fix | Delete
2 => $height
[195] Fix | Delete
);
[196] Fix | Delete
}
[197] Fix | Delete
[198] Fix | Delete
$resized_file = $editor->save();
[199] Fix | Delete
[200] Fix | Delete
if ( ! is_wp_error( $resized_file ) ) {
[201] Fix | Delete
$resized_rel_path = str_replace( $upload_dir, '', $resized_file['path'] );
[202] Fix | Delete
$img_url = $upload_url . $resized_rel_path;
[203] Fix | Delete
} else {
[204] Fix | Delete
throw new Aq_Exception('Unable to save resized image file: ' . $resized_file->get_error_message());
[205] Fix | Delete
}
[206] Fix | Delete
[207] Fix | Delete
}
[208] Fix | Delete
}
[209] Fix | Delete
// Check if it is CDN then reglue the url to its original state
[210] Fix | Delete
if ( $is_cdn ) {
[211] Fix | Delete
[212] Fix | Delete
$img_url = explode('/', $img_url);
[213] Fix | Delete
$cdn_url = explode('/', $cdn_url_main);
[214] Fix | Delete
$img_end = end($img_url);
[215] Fix | Delete
$cdn_end = end($cdn_url);
[216] Fix | Delete
$cdn_url_main = str_replace($cdn_end, $img_end, $cdn_url_main);
[217] Fix | Delete
$img_url = $cdn_url_main;
[218] Fix | Delete
}
[219] Fix | Delete
[220] Fix | Delete
// Okay, leave the ship.
[221] Fix | Delete
if ( true === $upscale ) remove_filter( 'image_resize_dimensions', array( $this, 'aq_upscale' ) );
[222] Fix | Delete
[223] Fix | Delete
// Return the output.
[224] Fix | Delete
if ( $single ) {
[225] Fix | Delete
// str return.
[226] Fix | Delete
$image = $img_url;
[227] Fix | Delete
} else {
[228] Fix | Delete
// array return.
[229] Fix | Delete
$image = array (
[230] Fix | Delete
0 => $img_url,
[231] Fix | Delete
1 => $dst_w,
[232] Fix | Delete
2 => $dst_h
[233] Fix | Delete
);
[234] Fix | Delete
}
[235] Fix | Delete
[236] Fix | Delete
return $image;
[237] Fix | Delete
}
[238] Fix | Delete
catch (Aq_Exception $ex) {
[239] Fix | Delete
// Throwing errors for the images stored on CDN #2285
[240] Fix | Delete
/*error_log('Aq_Resize.process() error: ' . $ex->getMessage());*/
[241] Fix | Delete
[242] Fix | Delete
if ($this->throwOnError) {
[243] Fix | Delete
// Bubble up exception.
[244] Fix | Delete
throw $ex;
[245] Fix | Delete
}
[246] Fix | Delete
else {
[247] Fix | Delete
// Return false, so that this patch is backwards-compatible.
[248] Fix | Delete
return false;
[249] Fix | Delete
}
[250] Fix | Delete
}
[251] Fix | Delete
}
[252] Fix | Delete
[253] Fix | Delete
/**
[254] Fix | Delete
* Callback to overwrite WP computing of thumbnail measures
[255] Fix | Delete
*/
[256] Fix | Delete
function aq_upscale( $default, $orig_w, $orig_h, $dest_w, $dest_h, $crop ) {
[257] Fix | Delete
if ( ! $crop ) return null; // Let the wordpress default function handle this.
[258] Fix | Delete
[259] Fix | Delete
// Here is the point we allow to use larger image size than the original one.
[260] Fix | Delete
$aspect_ratio = $orig_w / $orig_h;
[261] Fix | Delete
$new_w = $dest_w;
[262] Fix | Delete
$new_h = $dest_h;
[263] Fix | Delete
[264] Fix | Delete
if ( ! $new_w ) {
[265] Fix | Delete
$new_w = intval( $new_h * $aspect_ratio );
[266] Fix | Delete
}
[267] Fix | Delete
[268] Fix | Delete
if ( ! $new_h ) {
[269] Fix | Delete
$new_h = intval( $new_w / $aspect_ratio );
[270] Fix | Delete
}
[271] Fix | Delete
[272] Fix | Delete
$size_ratio = max( $new_w / $orig_w, $new_h / $orig_h );
[273] Fix | Delete
[274] Fix | Delete
$crop_w = round( $new_w / $size_ratio );
[275] Fix | Delete
$crop_h = round( $new_h / $size_ratio );
[276] Fix | Delete
[277] Fix | Delete
$s_x = floor( ( $orig_w - $crop_w ) / 2 );
[278] Fix | Delete
$s_y = floor( ( $orig_h - $crop_h ) / 2 );
[279] Fix | Delete
[280] Fix | Delete
return array( 0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h );
[281] Fix | Delete
}
[282] Fix | Delete
}
[283] Fix | Delete
}
[284] Fix | Delete
[285] Fix | Delete
[286] Fix | Delete
[287] Fix | Delete
[288] Fix | Delete
[289] Fix | Delete
if(!function_exists('ampforwp_aq_resize')) {
[290] Fix | Delete
[291] Fix | Delete
/**
[292] Fix | Delete
* This is just a tiny wrapper function for the class above so that there is no
[293] Fix | Delete
* need to change any code in your own WP themes. Usage is still the same :)
[294] Fix | Delete
*/
[295] Fix | Delete
function ampforwp_aq_resize( $url, $width = null, $height = null, $crop = null, $single = true, $upscale = false ) {
[296] Fix | Delete
if (empty($url)) {
[297] Fix | Delete
return;
[298] Fix | Delete
}
[299] Fix | Delete
// Disable ampforwp_aq_resize and return images without compressing.
[300] Fix | Delete
// Useful for some who wants to disable when using CDN images
[301] Fix | Delete
$disable_aq_resize = false;
[302] Fix | Delete
if (function_exists('imagify_set_activation') || function_exists('ud_check_stateless_media') || function_exists('webp_express_process_post') || class_exists( 'WP_Offload_Media_Autoloader')) {
[303] Fix | Delete
$disable_aq_resize = true;
[304] Fix | Delete
}
[305] Fix | Delete
$disable_aq_resize = apply_filters('ampforwp_disable_aq_resize', $disable_aq_resize, $url);
[306] Fix | Delete
if (true === $disable_aq_resize ){
[307] Fix | Delete
return $image = array(
[308] Fix | Delete
0 => $url,
[309] Fix | Delete
1 => $width,
[310] Fix | Delete
2 => $height,
[311] Fix | Delete
);
[312] Fix | Delete
}
[313] Fix | Delete
/* WPML Fix */
[314] Fix | Delete
if ( defined( 'ICL_SITEPRESS_VERSION' ) ){
[315] Fix | Delete
global $sitepress;
[316] Fix | Delete
$url = $sitepress->convert_url( $url, $sitepress->get_default_language() );
[317] Fix | Delete
}
[318] Fix | Delete
/* WPML Fix */
[319] Fix | Delete
/* EWWW Image Optimizer (ExactDN) Compatible*/
[320] Fix | Delete
global $exactdn;
[321] Fix | Delete
if ( class_exists( 'ExactDN' ) && $exactdn->get_exactdn_domain() ) {
[322] Fix | Delete
$args = array(
[323] Fix | Delete
'resize' => "$width,$height",
[324] Fix | Delete
);
[325] Fix | Delete
$image = array(
[326] Fix | Delete
0 => $exactdn->generate_url( $url, $args ),
[327] Fix | Delete
1 => $width,
[328] Fix | Delete
2 => $height,
[329] Fix | Delete
);
[330] Fix | Delete
return $image;
[331] Fix | Delete
}
[332] Fix | Delete
/* Jetpack Compatible*/
[333] Fix | Delete
elseif( class_exists( 'Jetpack' ) && Jetpack::is_module_active( 'photon' ) ) {
[334] Fix | Delete
$args = array(
[335] Fix | Delete
'resize' => "$width,$height"
[336] Fix | Delete
);
[337] Fix | Delete
$image = array (
[338] Fix | Delete
0 => jetpack_photon_url( $url, $args ),
[339] Fix | Delete
1 => $width,
[340] Fix | Delete
2 => $height
[341] Fix | Delete
);
[342] Fix | Delete
return $image;
[343] Fix | Delete
}
[344] Fix | Delete
elseif( function_exists('fifu_activate') || is_plugin_active('fifu-premium/fifu-premium.php') ){
[345] Fix | Delete
return fifu_amp_url($url, $width, $height);
[346] Fix | Delete
} else if (function_exists('wpp_get_option')){
[347] Fix | Delete
$image = array(
[348] Fix | Delete
0 => $url,
[349] Fix | Delete
1 => $width,
[350] Fix | Delete
2 => $height,
[351] Fix | Delete
);
[352] Fix | Delete
return $image;
[353] Fix | Delete
}
[354] Fix | Delete
else {
[355] Fix | Delete
$aq_resize = Aq_Resize::getInstance();
[356] Fix | Delete
return $aq_resize->process( $url, $width, $height, $crop, $single, $upscale );
[357] Fix | Delete
}
[358] Fix | Delete
}
[359] Fix | Delete
}
[360] Fix | Delete
[361] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function