Changeset 2961663
- Timestamp:
- 09/01/2023 12:18:05 PM (3 years ago)
- Location:
- easyfonts
- Files:
-
- 10 added
- 2 edited
-
tags/1.1.1 (added)
-
tags/1.1.1/assets (added)
-
tags/1.1.1/assets/style.css (added)
-
tags/1.1.1/easyfonts.php (added)
-
tags/1.1.1/inc (added)
-
tags/1.1.1/inc/notices.php (added)
-
tags/1.1.1/inc/options.php (added)
-
tags/1.1.1/lib (added)
-
tags/1.1.1/lib/simple_html_dom.php (added)
-
tags/1.1.1/readme.txt (added)
-
trunk/easyfonts.php (modified) (8 diffs)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
easyfonts/trunk/easyfonts.php
r2871228 r2961663 4 4 Plugin URI: 5 5 Description: Automatically Host existing google fonts locally on your server 6 Version: 1.1. 06 Version: 1.1.1 7 7 Author: Uzair 8 8 Author URI: https://easywpstuff.com … … 66 66 } 67 67 68 function easyfont_process_html_with_dom($content, $callback) { 69 // using simple html dom 70 $html = hgfl_str_get_html($content, false, true, 'UTF-8', false, PHP_EOL, ' '); 71 72 if (empty($html)) { 73 return $content; 74 } 75 76 $callback($html); 77 78 $content = $html->save(); 79 return $content; 80 } 81 68 82 function easyfont_process_content_link_tag($content) { 69 $html = hgfl_str_get_html($content, false, true, 'UTF-8', false, PHP_EOL, ' '); 83 return easyfont_process_html_with_dom($content, function($html) { 70 84 // Check if the 'easyfonts' directory exists and is writable 71 85 $easyfonts_dir = wp_upload_dir() ['basedir'] . '/easyfonts'; … … 116 130 } 117 131 // Return the modified content 118 return $html->save();132 }); 119 133 } 120 134 121 135 function easyfont_process_content_import($content) { 122 136 // using simple html dom 123 $html = hgfl_str_get_html($content, false, true, 'UTF-8', false, PHP_EOL, ' ');137 return easyfont_process_html_with_dom($content, function($html) { 124 138 // Check if the 'easyfonts' directory exists and is writable 125 139 $easyfonts_dir = wp_upload_dir() ['basedir'] . '/easyfonts'; … … 176 190 } 177 191 // Return the modified content 178 return $html->save();179 } 180 function easyfonts_remove_resource_hints($ html) {192 }); 193 } 194 function easyfonts_remove_resource_hints($content) { 181 195 // Load the HTML into the Simple HTML DOM library 182 $dom = hgfl_str_get_html($html, false, true, 'UTF-8', false, PHP_EOL, ' ');196 return easyfont_process_html_with_dom($content, function($html) { 183 197 184 198 // Find all <link> elements with the preload, preconnect, or prefetch attributes 185 $links = $ dom->find('link[rel=preload],link[rel=preconnect],link[rel=dns-prefetch]');199 $links = $html->find('link[rel=preload],link[rel=preconnect],link[rel=dns-prefetch]'); 186 200 187 201 // Loop through the <link> elements … … 195 209 196 210 // Find all <style> elements 197 $styles = $ dom->find('style');211 $styles = $html->find('style'); 198 212 199 213 // Loop through the <style> elements … … 205 219 } 206 220 // Return the modified HTML 207 return $dom->save();208 } 209 210 211 function easyfont_remove_font_scripts($ html) {221 }); 222 } 223 224 225 function easyfont_remove_font_scripts($content) { 212 226 // Load the HTML string into a Simple HTML DOM object 213 $dom = hgfl_str_get_html($html, false, true, 'UTF-8', false, PHP_EOL, ' ');227 return easyfont_process_html_with_dom($content, function($html) { 214 228 215 229 // Find all `script` elements 216 $scripts = $ dom->find('script');230 $scripts = $html->find('script'); 217 231 foreach($scripts as $script) { 218 232 // Check if the `script` element contains the `WebFontConfig` or `webfont.js` strings … … 224 238 225 239 // Return the modified HTML as a string 226 return $dom->save();240 }); 227 241 } 228 242 … … 272 286 273 287 288 function easy_fonts_combined_callback($buffer) { 289 if (get_option('easyfonts_host_google_fonts_locally_link', false)) { 290 $buffer = easyfont_process_content_link_tag($buffer); 291 } 292 293 if (get_option('easyfonts_host_google_fonts_locally_import', false)) { 294 $buffer = easyfont_process_content_import($buffer); 295 } 296 297 if (get_option('easyfonts_remove_inline_css_fontface', false)) { 298 $buffer = easyfont_download_gstatic_fonts($buffer); 299 } 300 301 if (get_option('easyfonts_remove_resource_hints', false)) { 302 $buffer = easyfonts_remove_resource_hints($buffer); 303 } 304 305 if (get_option('easyfonts_remove_inline_script_font', false)) { 306 $buffer = easyfont_remove_font_scripts($buffer); 307 } 308 309 return $buffer; 310 } 311 274 312 function easy_fonts_run_template_redirect() { 275 313 276 if (get_option('easyfonts_host_google_fonts_locally_link', false)) { 277 ob_start( 'easyfont_process_content_link_tag',0, PHP_OUTPUT_HANDLER_REMOVABLE ); 278 } 279 if (get_option('easyfonts_host_google_fonts_locally_import', false)) { 280 ob_start( 'easyfont_process_content_import',0, PHP_OUTPUT_HANDLER_REMOVABLE ); 281 } 314 ob_start('easy_fonts_combined_callback', 0, PHP_OUTPUT_HANDLER_REMOVABLE); 315 add_filter( 'wordpress_prepare_output', 'easyfont_run_after_smart_slider', 11 ); 316 add_filter('groovy_menu_final_output', 'easyfont_run_after_smart_slider', 11); 317 282 318 283 if (get_option('easyfonts_remove_inline_css_fontface', false)) { 284 ob_start( 'easyfont_download_gstatic_fonts',0, PHP_OUTPUT_HANDLER_REMOVABLE ); 285 } 286 287 if (get_option('easyfonts_remove_resource_hints', false)) { 288 ob_start( 'easyfonts_remove_resource_hints',0, PHP_OUTPUT_HANDLER_REMOVABLE ); 289 } 290 291 if (get_option('easyfonts_remove_inline_script_font', false)) { 292 ob_start( 'easyfont_remove_font_scripts',0, PHP_OUTPUT_HANDLER_REMOVABLE ); 293 } 294 //ob_start( 'download_gstatic_fonts',0, PHP_OUTPUT_HANDLER_REMOVABLE ); 295 296 297 } 298 add_action( 'template_redirect', 'easy_fonts_run_template_redirect', 999 ); 299 300 301 add_filter( 'wordpress_prepare_output', 'easyfont_run_after_smart_slider', 11 ); 302 303 add_filter('groovy_menu_final_output', 'easyfont_run_after_smart_slider', 11); 319 } 320 add_action( 'template_redirect', 'easy_fonts_run_template_redirect', -999 ); 321 304 322 305 323 function easyfont_run_after_smart_slider( $buffer ) { -
easyfonts/trunk/readme.txt
r2916680 r2961663 4 4 Tags: googlefonts, fonts, GDRP, dsgvo, google fonts local, fonts locally 5 5 Requires at least: 5.0 6 Tested up to: 6. 2.26 Tested up to: 6.3 7 7 Requires PHP: 5.6 8 Stable tag: 1.1. 08 Stable tag: 1.1.1 9 9 License: GNU General Public License v2 or later 10 10 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 59 59 60 60 == Changelog == 61 = 1.1.1 = 62 * Improvement 61 63 = 1.1.0 = 62 64 * minor issues fixed
Note: See TracChangeset
for help on using the changeset viewer.