Plugin Directory

Changeset 2961663


Ignore:
Timestamp:
09/01/2023 12:18:05 PM (3 years ago)
Author:
easywpstuff
Message:

update

Location:
easyfonts
Files:
10 added
2 edited

Legend:

Unmodified
Added
Removed
  • easyfonts/trunk/easyfonts.php

    r2871228 r2961663  
    44Plugin URI:
    55Description: Automatically Host existing google fonts locally on your server
    6 Version: 1.1.0
     6Version: 1.1.1
    77Author: Uzair
    88Author URI: https://easywpstuff.com
     
    6666}
    6767
     68function 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
    6882function 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) {
    7084    // Check if the 'easyfonts' directory exists and is writable
    7185    $easyfonts_dir = wp_upload_dir() ['basedir'] . '/easyfonts';
     
    116130    }
    117131    // Return the modified content
    118     return $html->save();
     132   });
    119133}
    120134
    121135function easyfont_process_content_import($content) {
    122136    // 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) {
    124138    // Check if the 'easyfonts' directory exists and is writable
    125139    $easyfonts_dir = wp_upload_dir() ['basedir'] . '/easyfonts';
     
    176190    }
    177191    // Return the modified content
    178     return $html->save();
    179 }
    180 function easyfonts_remove_resource_hints($html) {
     192    });
     193}
     194function easyfonts_remove_resource_hints($content) {
    181195  // 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) {
    183197 
    184198  // 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]');
    186200 
    187201  // Loop through the <link> elements
     
    195209 
    196210  // Find all <style> elements
    197   $styles = $dom->find('style');
     211  $styles = $html->find('style');
    198212 
    199213  // Loop through the <style> elements
     
    205219  }
    206220  // Return the modified HTML
    207   return $dom->save();
    208 }
    209 
    210 
    211 function easyfont_remove_font_scripts($html) {
     221  });
     222}
     223
     224
     225function easyfont_remove_font_scripts($content) {
    212226  // 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) {
    214228 
    215229  // Find all `script` elements
    216   $scripts = $dom->find('script');
     230  $scripts = $html->find('script');
    217231  foreach($scripts as $script) {
    218232    // Check if the `script` element contains the `WebFontConfig` or `webfont.js` strings
     
    224238 
    225239  // Return the modified HTML as a string
    226   return $dom->save();
     240   });
    227241}
    228242
     
    272286
    273287
     288function 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
    274312function easy_fonts_run_template_redirect() {
    275313   
    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
    282318   
    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}
     320add_action( 'template_redirect', 'easy_fonts_run_template_redirect', -999 );
     321
    304322
    305323function easyfont_run_after_smart_slider( $buffer ) {
  • easyfonts/trunk/readme.txt

    r2916680 r2961663  
    44Tags: googlefonts, fonts, GDRP, dsgvo, google fonts local, fonts locally
    55Requires at least: 5.0
    6 Tested up to: 6.2.2
     6Tested up to: 6.3
    77Requires PHP: 5.6
    8 Stable tag: 1.1.0
     8Stable tag: 1.1.1
    99License: GNU General Public License v2 or later
    1010License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    5959
    6060== Changelog ==
     61= 1.1.1 =
     62* Improvement
    6163= 1.1.0 =
    6264* minor issues fixed
Note: See TracChangeset for help on using the changeset viewer.