Plugin Directory

Changeset 2442138


Ignore:
Timestamp:
12/18/2020 09:48:25 AM (5 years ago)
Author:
PhilMeadows
Message:

UPDATE: Error warning pedantry for PHP DOMDocument

Location:
wp-roids/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • wp-roids/trunk/CHANGELOG.md

    r2441989 r2442138  
     1= v3.2.2 =
     2
     3- **Improved:** Error warning pedantry for PHP DOMDocument
     4
    15= v3.2.1 =
    26
  • wp-roids/trunk/readme.txt

    r2441989 r2442138  
    202202== Upgrade Notice ==
    203203
     204= v3.2.2 =
     205
     206Error warning pedantry for PHP DOMDocument
     207
    204208= v3.2.1 =
    205209
  • wp-roids/trunk/wp-roids.php

    r2441989 r2442138  
    9797            if( $this->settings !== NULL )
    9898            {
    99                 if( intval( $this->settings['cache']['disabled'] ) === 1 ) $this->settingCacheHtml = FALSE;
    100                 if( intval( $this->settings['html']['disabled'] ) === 1 ) $this->settingMinifyHtml = FALSE;
    101                 if( intval( $this->settings['defer']['disabled'] ) === 1 ) $this->settingDeferJs = FALSE;
    102                 if( intval( $this->settings['imgs']['disabled'] ) === 1 )
     99                if( isset( $this->settings['cache'] ) && isset( $this->settings['cache']['disabled'] ) && intval( $this->settings['cache']['disabled'] ) === 1 )
     100                {
     101                    $this->settingCacheHtml = FALSE;
     102                }
     103               
     104                if( isset( $this->settings['html'] ) && isset( $this->settings['html']['disabled'] ) && intval( $this->settings['html']['disabled'] ) === 1 )
     105                {
     106                    $this->settingMinifyHtml = FALSE;
     107                }
     108               
     109                if( isset( $this->settings['defer'] ) && isset( $this->settings['defer']['disabled'] ) && intval( $this->settings['defer']['disabled'] ) === 1 )
     110                {
     111                    $this->settingDeferJs = FALSE;
     112                }
     113               
     114                if( isset( $this->settings['imgs'] ) && isset( $this->settings['imgs']['disabled'] ) && intval( $this->settings['imgs']['disabled'] ) === 1 )
    103115                {
    104116                    $this->settingCompressImages = FALSE;
    105117                    if( is_dir( $this->imgCache ) ) $this->recursiveRemoveDirectory( $this->imgCache );
    106118                }
     119                   
    107120                if( isset( $this->settings['imgs-quality-jpeg']['value'] ) && intval( $this->settings['imgs-quality-jpeg']['value'] ) !== intval( $this->compressionLevelJpeg ) )
    108121                {
    109122                    $this->compressionLevelJpeg = intval( $this->settings['imgs-quality-jpeg']['value'] );
    110123                }
     124               
    111125                if( isset( $this->settings['imgs-quality-png']['value'] ) && intval( $this->settings['imgs-quality-png']['value'] ) !== intval( $this->compressionLevelPng ) )
    112126                {
    113127                    $this->compressionLevelPng = intval( $this->settings['imgs-quality-png']['value'] );
    114128                }
    115                 if( intval( $this->settings['cdn']['disabled'] ) === 1 ) $this->settingCacheCdn = FALSE;
    116                
    117                 if( $this->settings['debug']['value'] === 'enabled' ) $this->debug = TRUE;
     129               
     130                if( isset( $this->settings['cdn'] ) && isset( $this->settings['cdn']['disabled'] ) && intval( $this->settings['cdn']['disabled'] ) === 1 )
     131                {
     132                    $this->settingCacheCdn = FALSE;
     133                }
     134               
     135                if( isset( $this->settings['debug'] ) && isset( $this->settings['debug']['value'] ) && $this->settings['debug']['value'] === 'enabled' )
     136                {
     137                    $this->debug = TRUE;
     138                }
     139                   
    118140                if( isset( $this->settings['schedule']['value'] ) && $this->settings['schedule']['value'] === 'disabled' )
    119141                {
     
    9821004                {
    9831005                    $dom = new DOMDocument;
    984                     $dom->loadHTML( $html );
    985                     foreach( $dom->getElementsByTagName( 'img' ) as $node )
    986                     {
    987                         if( $node->hasAttribute( 'src' ) )
    988                         {
    989                             $src = $node->getAttribute( 'src' );
    990                             if( strpos( $src, $this->siteUrl ) !== FALSE )
    991                             {
    992                                 $siteUrl = str_replace( ['https:','http:'], '', $this->siteUrl );
    993                                 $path = rtrim( ABSPATH, '/' );
    994                                 $filePath = str_replace( [$this->siteUrl, $siteUrl], $path, $src );
    995                                 if( file_exists( $filePath ) )
     1006                    libxml_use_internal_errors( TRUE );
     1007                    $domLoaded = $dom->loadHTML( $html );
     1008                    libxml_use_internal_errors( FALSE );
     1009                    if( $domLoaded !== FALSE )
     1010                    {
     1011                        foreach( $dom->getElementsByTagName( 'img' ) as $node )
     1012                        {
     1013                            if( $node->hasAttribute( 'src' ) )
     1014                            {
     1015                                $src = $node->getAttribute( 'src' );
     1016                                if( strpos( $src, $this->siteUrl ) !== FALSE )
    9961017                                {
    997                                     // see if we have already compressed and cached this image
    998                                     $filename = basename( $filePath );
    999                                     $cachedImage = $this->imgCache . '/' . $filename;
    1000                                     if( ! file_exists( $cachedImage ) )
     1018                                    $siteUrl = str_replace( ['https:','http:'], '', $this->siteUrl );
     1019                                    $path = rtrim( ABSPATH, '/' );
     1020                                    $filePath = str_replace( [$this->siteUrl, $siteUrl], $path, $src );
     1021                                    if( file_exists( $filePath ) )
    10011022                                    {
    1002                                         $image = wp_get_image_editor( $filePath );
    1003                                         if( ! is_wp_error( $image ) )
     1023                                        // see if we have already compressed and cached this image
     1024                                        $filename = basename( $filePath );
     1025                                        $cachedImage = $this->imgCache . '/' . $filename;
     1026                                        if( ! file_exists( $cachedImage ) )
    10041027                                        {
    1005                                             $quality = $image->get_quality();
    1006                                             if( is_numeric( $quality ) && intval( $quality ) > $this->compressionLevelJpeg )
     1028                                            $image = wp_get_image_editor( $filePath );
     1029                                            if( ! is_wp_error( $image ) )
    10071030                                            {
    1008                                                 if( substr( $filePath, -4, 4 ) === '.jpg' || substr( $filePath, -5, 5 ) === '.jpeg' )
     1031                                                $quality = $image->get_quality();
     1032                                                if( is_numeric( $quality ) && intval( $quality ) > $this->compressionLevelJpeg )
    10091033                                                {
    1010                                                     $compress = $image->set_quality( $this->compressionLevelJpeg );
    1011                                                 }
    1012                                                 if( substr( $filePath, -4, 4 ) === '.png' )
    1013                                                 {
    1014                                                     $compress = $image->set_quality( $this->compressionLevelPng );
    1015                                                 }
    1016                                                
    1017                                                 if( isset( $compress ) && ! is_wp_error( $compress ) )
    1018                                                 {
    1019                                                     $image->save( $cachedImage );
    1020                                                     if( $this->debug === TRUE ) $this->writeLog( 'I compressed and cached an image! src: "' . $src . '" | xtn: "' . $xtn . '" | filepath: "' . $filePath . '" | original quality: "' . $quality . '" | basename: "' . $filename . '" | cache file: "' . $cachedImage . '"' );
     1034                                                    if( substr( $filePath, -4, 4 ) === '.jpg' || substr( $filePath, -5, 5 ) === '.jpeg' )
     1035                                                    {
     1036                                                        $compress = $image->set_quality( $this->compressionLevelJpeg );
     1037                                                    }
     1038                                                    if( substr( $filePath, -4, 4 ) === '.png' )
     1039                                                    {
     1040                                                        $compress = $image->set_quality( $this->compressionLevelPng );
     1041                                                    }
     1042                                                   
     1043                                                    if( isset( $compress ) && ! is_wp_error( $compress ) )
     1044                                                    {
     1045                                                        $image->save( $cachedImage );
     1046                                                        if( $this->debug === TRUE ) $this->writeLog( 'I compressed and cached an image! src: "' . $src . '" | xtn: "' . $xtn . '" | filepath: "' . $filePath . '" | original quality: "' . $quality . '" | basename: "' . $filename . '" | cache file: "' . $cachedImage . '"' );
     1047                                                    }
     1048                                                    else
     1049                                                    {
     1050                                                        if( $this->debug === TRUE ) $this->writeLog( 'ERROR: if( isset( $compress ) && ! is_wp_error( $compress ) ) fail! Returned FALSE! ~ NOT isset OR WP_Error thrown!' );
     1051                                                    }
    10211052                                                }
    10221053                                                else
    10231054                                                {
    1024                                                     if( $this->debug === TRUE ) $this->writeLog( 'ERROR: if( isset( $compress ) && ! is_wp_error( $compress ) ) fail! Returned FALSE! ~ NOT isset OR WP_Error thrown!' );
     1055                                                    if( $this->debug === TRUE ) $this->writeLog( 'NOTICE:if( is_numeric( $quality ) && intval( $quality ) > $this->compressionLevel ) fail! Returned FALSE! ~Locally hosted image ALREADY compressed beyond threshold!' );
    10251056                                                }
    10261057                                            }
    10271058                                            else
    10281059                                            {
    1029                                                 if( $this->debug === TRUE ) $this->writeLog( 'NOTICE:if( is_numeric( $quality ) && intval( $quality ) > $this->compressionLevel ) fail! Returned FALSE! ~Locally hosted image ALREADY compressed beyond threshold!' );
     1060                                                if( $this->debug === TRUE ) $this->writeLog( 'ERROR: if( ! is_wp_error( $image ) ) fail! Returned FALSE! ~ WP_Error thrown!' );
    10301061                                            }
    10311062                                        }
    10321063                                        else
    10331064                                        {
    1034                                             if( $this->debug === TRUE ) $this->writeLog( 'ERROR: if( ! is_wp_error( $image ) ) fail! Returned FALSE! ~ WP_Error thrown!' );
     1065                                            if( $this->debug === TRUE ) $this->writeLog( 'NOTICE: if( ! file_exists( $cachedImage ) ) fail! Returned FALSE! ~ Locally hosted CACHED image found' );
    10351066                                        }
    10361067                                    }
    10371068                                    else
    10381069                                    {
    1039                                         if( $this->debug === TRUE ) $this->writeLog( 'NOTICE: if( ! file_exists( $cachedImage ) ) fail! Returned FALSE! ~ Locally hosted CACHED image found' );
     1070                                        if( $this->debug === TRUE ) $this->writeLog( 'WARNING: if( file_exists( $filePath ) ) fail! Returned FALSE! ~ Locally hosted image NOT found' );
    10401071                                    }
    10411072                                }
    10421073                                else
    10431074                                {
    1044                                     if( $this->debug === TRUE ) $this->writeLog( 'WARNING: if( file_exists( $filePath ) ) fail! Returned FALSE! ~ Locally hosted image NOT found' );
     1075                                    if( $this->debug === TRUE ) $this->writeLog( 'NOTICE: if( strpos( "src", $this->siteUrl ) !== FALSE ) fail! Returned FALSE! ~ Remotely hosted image found' );
    10451076                                }
    10461077                            }
    10471078                            else
    10481079                            {
    1049                                 if( $this->debug === TRUE ) $this->writeLog( 'NOTICE: if( strpos( "src", $this->siteUrl ) !== FALSE ) fail! Returned FALSE! ~ Remotely hosted image found' );
     1080                                if( $this->debug === TRUE ) $this->writeLog( 'WARNING: if( $node->hasAttribute( "src" ) ) fail! Returned FALSE!' );
    10501081                            }
    1051                         }
    1052                         else
    1053                         {
    1054                             if( $this->debug === TRUE ) $this->writeLog( 'WARNING: if( $node->hasAttribute( "src" ) ) fail! Returned FALSE!' );
    1055                         }
    1056                        
    1057                     } // END foreach( $dom->getElementsByTagName( 'img' ) as $node )
    1058                    
     1082                           
     1083                        } // END foreach( $dom->getElementsByTagName( 'img' ) as $node )
     1084                    }                   
    10591085                }
    10601086                else
Note: See TracChangeset for help on using the changeset viewer.