Changeset 2442138
- Timestamp:
- 12/18/2020 09:48:25 AM (5 years ago)
- Location:
- wp-roids/trunk
- Files:
-
- 3 edited
-
CHANGELOG.md (modified) (1 diff)
-
readme.txt (modified) (1 diff)
-
wp-roids.php (modified) (2 diffs)
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 1 5 = v3.2.1 = 2 6 -
wp-roids/trunk/readme.txt
r2441989 r2442138 202 202 == Upgrade Notice == 203 203 204 = v3.2.2 = 205 206 Error warning pedantry for PHP DOMDocument 207 204 208 = v3.2.1 = 205 209 -
wp-roids/trunk/wp-roids.php
r2441989 r2442138 97 97 if( $this->settings !== NULL ) 98 98 { 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 ) 103 115 { 104 116 $this->settingCompressImages = FALSE; 105 117 if( is_dir( $this->imgCache ) ) $this->recursiveRemoveDirectory( $this->imgCache ); 106 118 } 119 107 120 if( isset( $this->settings['imgs-quality-jpeg']['value'] ) && intval( $this->settings['imgs-quality-jpeg']['value'] ) !== intval( $this->compressionLevelJpeg ) ) 108 121 { 109 122 $this->compressionLevelJpeg = intval( $this->settings['imgs-quality-jpeg']['value'] ); 110 123 } 124 111 125 if( isset( $this->settings['imgs-quality-png']['value'] ) && intval( $this->settings['imgs-quality-png']['value'] ) !== intval( $this->compressionLevelPng ) ) 112 126 { 113 127 $this->compressionLevelPng = intval( $this->settings['imgs-quality-png']['value'] ); 114 128 } 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 118 140 if( isset( $this->settings['schedule']['value'] ) && $this->settings['schedule']['value'] === 'disabled' ) 119 141 { … … 982 1004 { 983 1005 $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 ) 996 1017 { 997 // see if we have already compressed and cached this image998 $ 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 ) ) 1001 1022 { 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 ) ) 1004 1027 { 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 ) ) 1007 1030 { 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 ) 1009 1033 { 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 } 1021 1052 } 1022 1053 else 1023 1054 { 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!' ); 1025 1056 } 1026 1057 } 1027 1058 else 1028 1059 { 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!' ); 1030 1061 } 1031 1062 } 1032 1063 else 1033 1064 { 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' ); 1035 1066 } 1036 1067 } 1037 1068 else 1038 1069 { 1039 if( $this->debug === TRUE ) $this->writeLog( ' NOTICE: if( ! file_exists( $cachedImage ) ) fail! Returned FALSE! ~ Locally hosted CACHED imagefound' );1070 if( $this->debug === TRUE ) $this->writeLog( 'WARNING: if( file_exists( $filePath ) ) fail! Returned FALSE! ~ Locally hosted image NOT found' ); 1040 1071 } 1041 1072 } 1042 1073 else 1043 1074 { 1044 if( $this->debug === TRUE ) $this->writeLog( ' WARNING: if( file_exists( $filePath ) ) fail! Returned FALSE! ~ Locally hosted image NOTfound' );1075 if( $this->debug === TRUE ) $this->writeLog( 'NOTICE: if( strpos( "src", $this->siteUrl ) !== FALSE ) fail! Returned FALSE! ~ Remotely hosted image found' ); 1045 1076 } 1046 1077 } 1047 1078 else 1048 1079 { 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!' ); 1050 1081 } 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 } 1059 1085 } 1060 1086 else
Note: See TracChangeset
for help on using the changeset viewer.