Plugin Directory

Changeset 3268065


Ignore:
Timestamp:
04/07/2025 06:33:34 PM (11 months ago)
Author:
easywpstuff
Message:

update

Location:
easyfonts
Files:
10 added
2 edited

Legend:

Unmodified
Added
Removed
  • easyfonts/trunk/easyfonts.php

    r3252516 r3268065  
    44Plugin URI:
    55Description: Automatically Host existing google fonts locally on your server
    6 Version: 1.1.3
     6Version: 1.1.4
    77Author: Uzair
    88Author URI: https://easywpstuff.com
     
    8383
    8484function easyfont_process_content_link_tag($content) {
    85     return easyfont_process_html_with_dom($content, function($html) {
    86     // Check if the 'easyfonts' directory exists and is writable
    87     $easyfonts_dir = wp_upload_dir() ['basedir'] . '/easyfonts';
    88     if (!wp_mkdir_p($easyfonts_dir)) {
    89         return $content;
    90     }
    91     // Find all <link> tags with a rel attribute of 'stylesheet' and a href attribute that points to a Google Fonts stylesheet
    92     foreach ($html->find('link[rel=stylesheet][href*=fonts.googleapis.com]') as $link) {
    93         $url = $link->href;
    94         if(strpos($url,'//') === 0){
    95                     $url = 'https:'.$url;
    96         }
    97         $decoded_url = rawurldecode(htmlspecialchars_decode($url));
    98         // Generate a local filename for the stylesheet
    99         $filename = hash('sha256', $decoded_url, false);
    100         $filename = substr($filename, 0, 10) . '.css';
    101         if (!file_exists($easyfonts_dir . '/' . $filename)) {
    102             $css = wp_get_remote_file($decoded_url);
    103             if (!preg_match_all('/@font-face\s*\{([^}]+)\}/', $css, $matches)) continue;
    104            
    105             $css = easyfonts_process_font_face_declarations($css, $easyfonts_dir);
    106             // Save the modified stylesheet to the 'wp-content/uploads/easyfonts' directory
    107             file_put_contents($easyfonts_dir . '/' . $filename, $css);
    108         }
    109         $finalbasecss = get_base_url();
    110         // Replace the href attribute with a local reference to the downloaded stylesheet
    111         $link->href = $finalbasecss . '/easyfonts/' . $filename;
    112     }
    113     // Return the modified content
    114    });
     85    return easyfont_process_html_with_dom($content, function($html) use ($content) {
     86
     87        $upload_dir = wp_upload_dir();
     88        $easyfonts_dir = $upload_dir['basedir'] . '/easyfonts';
     89
     90        if (!wp_mkdir_p($easyfonts_dir)) {
     91            return $content;
     92        }
     93
     94        // Filter-based support toggle for Bunny Fonts
     95        $apply_bunnyfonts_filter = apply_filters('easyfonts_bunnyfonts', true);
     96
     97        // List of supported font providers
     98        $font_providers = [
     99            'fonts.googleapis.com',
     100        ];
     101
     102        if ($apply_bunnyfonts_filter) {
     103            $font_providers[] = 'fonts.bunny.net';
     104        }
     105
     106        foreach ($html->find('link[rel=stylesheet]') as $link) {
     107            $href = $link->href;
     108            $matched = false;
     109
     110            foreach ($font_providers as $provider) {
     111                if (strpos($href, $provider) !== false) {
     112                    $matched = true;
     113                    break;
     114                }
     115            }
     116
     117            if (!$matched) continue;
     118
     119            // Normalize URL
     120            if (strpos($href, '//') === 0) {
     121                $href = 'https:' . $href;
     122            }
     123
     124            $decoded_url = rawurldecode(htmlspecialchars_decode($href));
     125            $filename = substr(hash('sha256', $decoded_url), 0, 10) . '.css';
     126            $local_css_path = $easyfonts_dir . '/' . $filename;
     127
     128            if (!file_exists($local_css_path)) {
     129                $css = wp_get_remote_file($decoded_url);
     130                if (!preg_match_all('/@font-face\s*\{([^}]+)\}/', $css, $matches)) continue;
     131
     132                $css = easyfonts_process_font_face_declarations($css, $easyfonts_dir);
     133                file_put_contents($local_css_path, $css);
     134            }
     135
     136            $finalbasecss = get_base_url();
     137            $link->href = $finalbasecss . '/easyfonts/' . $filename;
     138        }
     139
     140        return $html;
     141    });
    115142}
    116143
  • easyfonts/trunk/readme.txt

    r3252516 r3268065  
    66Tested up to: 6.7.2
    77Requires PHP: 5.6
    8 Stable tag: 1.1.3
     8Stable tag: 1.1.4
    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.4 =
     62* Added Support for bunnyfonts
    6163= 1.1.3 =
    6264* Fixed security issues
Note: See TracChangeset for help on using the changeset viewer.