Plugin Directory

Changeset 2652765


Ignore:
Timestamp:
01/04/2022 07:59:49 PM (4 years ago)
Author:
optipic
Message:

v1.27.0

Location:
optipic
Files:
15 added
4 edited

Legend:

Unmodified
Added
Removed
  • optipic/trunk/includes/functions.php

    r2643600 r2652765  
    22
    33function optipic_version() {
    4     return '1.25.1';
     4    return '1.27.0';
    55}
    66
     
    3636//    die('-------------');
    3737
    38     $optipicSiteID = $optipicSettings['cdn_site_id'];
    39     $autoreplaceActive = $optipicSettings['cdn_autoreplace_active'];
     38    $optipicSiteID = (!empty($optipicSettings['cdn_site_id']))? $optipicSettings['cdn_site_id']: '';
     39    $autoreplaceActive = (!empty($optipicSettings['cdn_autoreplace_active']))? $optipicSettings['cdn_autoreplace_active']: '';
    4040    //$domains = $optipicSettings['domains'];
    4141   
     
    5050    foreach(array('domains', 'exclusions_url', 'whitelist_img_urls', 'srcset_attrs') as $attrName) {
    5151        $list = array();
    52         foreach(explode("\n", $optipicSettings[$attrName]) as $val) {
     52        $attrVal = (!empty($optipicSettings[$attrName]))? $optipicSettings[$attrName]: '';
     53        foreach(explode("\n", $attrVal) as $val) {
    5354            $val = trim($val);
    5455            if($val) {
  • optipic/trunk/includes/optipic-cdn-php/ImgUrlConverter.php

    r2643122 r2652765  
    1717     * Library version number
    1818     */
    19     const VERSION = '1.25';
     19    const VERSION = '1.27';
    2020   
    2121    /**
     
    7171    {
    7272       
    73         if(empty(self::$url)) {
     73        if (empty(self::$url)) {
    7474            self::$url = $_SERVER['REQUEST_URI'];
    7575        }
    76         if(empty(self::$host)) {
     76        if (empty(self::$host)) {
    7777            self::$host = $_SERVER['HTTP_HOST'];
    7878        }
     
    123123       
    124124       
    125         if($detectBaseUrl) {
     125        if ($detectBaseUrl) {
    126126            self::$baseUrl = self::getBaseUrlFromHtml($content);
    127127            if (self::$baseUrl) {
     
    230230            $cdnDomainsForRegexp[] = '\/\/'.preg_quote($cdnDomain, '#');   // plain html
    231231            $cdnDomainsForRegexp[] = '\\/\\/'.preg_quote($cdnDomain, '#'); // html in json
    232            
    233232        }
    234233        $cdnDomainsForRegexp = implode("|", $cdnDomainsForRegexp);
     
    398397            }
    399398            //var_dump($parseUrl);exit;
    400         }
    401         else {
     399        } else {
    402400            $parseUrl = parse_url($urlOriginal);
    403401        }
     
    416414        $ext = self::strtolower(pathinfo($parseUrl['path'], PATHINFO_EXTENSION));
    417415        if (!in_array($ext, array('png', 'jpg', 'jpeg'))) {
     416            return $replaceWithoutOptiPic;
     417        }
     418       
     419        if (self::urlHasPhpScript($urlOriginal)) {
    418420            return $replaceWithoutOptiPic;
    419421        }
     
    520522        }
    521523       
    522         if (self::substr($relativeUrl, 0, strlen($slash))==$slash) {
     524        if (self::substr($relativeUrl, 0, self::strlen($slash))==$slash) {
    523525            return $relativeUrl;
    524526        }
     
    534536       
    535537        // CASE filepath ".img.png" (remove first dot)
    536         if (substr($relativeUrl, 0, 1) == '.' && substr($relativeUrl, 1, 1) != '.') {
    537             $relativeUrl = substr($relativeUrl, 1);
     538        if (self::substr($relativeUrl, 0, 1) == '.' && self::substr($relativeUrl, 1, 1) != '.') {
     539            $relativeUrl = self::substr($relativeUrl, 1);
    538540        }
    539541        // CASE baseUrl "." (remove first dot)
    540         if (strlen($baseUrl)>0 && substr($baseUrl, 0, 1) == '.' && substr($baseUrl, 1, 1) != '.') {
    541             $baseUrl = (strlen($baseUrl)>1)? "".substr($baseUrl, 1): "";
     542        if (self::strlen($baseUrl)>0 && self::substr($baseUrl, 0, 1) == '.' && self::substr($baseUrl, 1, 1) != '.') {
     543            $baseUrl = (self::strlen($baseUrl)>1)? "".self::substr($baseUrl, 1): "";
    542544        }
    543545       
    544546        // CASE /catalog + img.png (/catalogimg.png is wrong)
    545         if (substr($baseUrl, -1)!='/' && substr($relativeUrl, 0, 1) != '/') {
     547        if (self::substr($baseUrl, -1)!='/' && self::substr($relativeUrl, 0, 1) != '/') {
    546548            $tryUrl = str_replace($slash.$slash, $slash, $baseUrl.$slash.$relativeUrl);
    547549            // Try to /catalog/img.png
    548550            if (file_exists(self::getDocumentDoot().$slash.$tryUrl)) {
    549551                return $tryUrl;
    550             }
    551             // Try to /img.png
    552             else {
     552            } else { // Try to /img.png
    553553                $tryUrl = str_replace($slash.$slash, $slash, '/'.$relativeUrl);
    554554                if (file_exists(self::getDocumentDoot().$slash.$tryUrl)) {
     
    732732    public static function substr($string, $offset, $length = null)
    733733    {
    734         return substr($string, $offset, $length);
     734        return (($length===null)? substr($string, $offset): substr($string, $offset, $length));
    735735    }
    736736   
     
    757757         return $_SERVER['DOCUMENT_ROOT'];
    758758    }
     759   
     760   
     761    /**
     762     * Check if URL has php script logic (no static image)
     763     * Examples:
     764     * - /index.php?route=product/image/catalog/payment.png
     765     * - /manager/?a=system/file/edit&file=assets/template/css/../images/lines.png
     766     */
     767    public static function urlHasPhpScript($url)
     768    {
     769        $ext = pathinfo($url, PATHINFO_EXTENSION);
     770        $posQ = stripos($url, '?');
     771       
     772        if (!$posQ) {
     773            $posQ = stripos($url, '&');
     774            if (!$posQ) {
     775                return false;
     776            }
     777        }
     778       
     779        if (!$ext) {
     780            return true;
     781        }
     782       
     783        $posExt = stripos($url, $ext);
     784        if ($posQ < $posExt) {
     785            return true;
     786        }
     787       
     788        return false;
     789    }
    759790}
  • optipic/trunk/optipic.php

    r2643600 r2652765  
    44Plugin URI:  https://optipic.io/en/webp/wordpress/
    55Description:  OptiPic.io - image optimization via smart CDN. The module automates the process of optimizing and compressing all images on the site according to the recommendations of Google PageSpeed Insights.
    6 Version:  1.25.1
     6Version:  1.27.0
    77Author:  OptiPic.io
    88Author URI:  https://optipic.io/en/
  • optipic/trunk/readme.txt

    r2643600 r2652765  
    44Requires at least: 4.0
    55Tested up to: 5.8.2
    6 Stable tag: 1.25.1
     6Stable tag: 1.27.0
    77License: GPL v2 - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
    88
     
    9090= 1.25.1 =
    9191* Optimized images replacing logic.
     92
     93= 1.27.0 =
     94* Optimized images replacing logic.
Note: See TracChangeset for help on using the changeset viewer.