Plugin Directory

Changeset 2529383


Ignore:
Timestamp:
05/10/2021 09:54:51 PM (5 years ago)
Author:
loremipsumgraz
Message:

Update to Version 1.2.0

Location:
hardcore-google-fonts-localizer
Files:
323 added
4 edited

Legend:

Unmodified
Added
Removed
  • hardcore-google-fonts-localizer/trunk/admin/class-google-fonts-localizer-admin.php

    r1981281 r2529383  
    33class Google_Fonts_Localizer_Admin
    44{
    5     private static $fontTypes = ['woff2', 'woff', 'ttf', 'svg', 'eot'];
     5    private static $fontTypes = ['woff2', 'woff', 'ttf'];
    66    private static $gFontURL  = 'http://fonts.googleapis.com/css?family=';
    77
     
    2828
    2929    public static function cache_google_fonts(string $url, bool $rebuild) {
    30         $fonts = self::get_google_fonts_urls($url);
    31         $fonts = self::sort_fonts($fonts);
    32         self::download_google_fonts($fonts, $rebuild);
    33     }
    34 
    35     private static function get_google_fonts_urls(string $url)
    36     {
     30        if (preg_match('/^https:\/\/fonts.googleapis.com\/css2/', $url)) {
     31            self::$gFontURL = 'https://fonts.googleapis.com/css2?family=';
     32        }
     33
    3734        $urlParts = parse_url($url);
    38         parse_str($urlParts['query'], $queryParts);
    39         self::$gFontURL .= urlencode($queryParts['family']);
     35        $queryParts = self::parseQuery($urlParts['query']);
     36
     37        foreach ($queryParts['family'] as $family) {
     38            $fonts = self::get_google_fonts_urls($family);
     39            $fonts = self::sort_fonts($fonts);
     40            self::download_google_fonts($fonts, $rebuild);
     41
     42            if($rebuild) {
     43                $rebuild = false;
     44            }
     45        }
     46    }
     47
     48    private static function get_google_fonts_urls(string $family)
     49    {
     50        $parse_url = self::$gFontURL . urlencode($family);
    4051        $fontsDownloadLinks = [];
    4152
    4253        foreach (self::$fontTypes as $fontType) {
    43             $content = self::curlGoogleFont(self::$gFontURL, self::$uaFonts[$fontType]);
    44             $fontsDownloadLinks[$fontType] = self::parseCss($content, $queryParts['family']);
     54            $content = self::curlGoogleFont($parse_url, self::$uaFonts[$fontType]);
     55            $fontsDownloadLinks[$fontType] = self::parseCss($content, $family);
    4556        }
    4657
    4758        return $fontsDownloadLinks;
     59    }
     60
     61    private static function parseQuery($query)
     62    {
     63        $query  = explode('&', $query);
     64        $params = [];
     65        foreach ($query as $param) {
     66            // prevent notice on explode() if $param has no '='
     67            if (strpos($param, '=') === false) {
     68                $param .= '=';
     69            }
     70
     71            list($name, $value) = explode('=', $param, 2);
     72            $params[urldecode($name)][] = urldecode($value);
     73        }
     74        return $params;
    4875    }
    4976
     
    142169
    143170    private static function download_google_fonts(array $fonts, bool $rebuild) {
    144         $cached_fonts = [];
     171        $cached_fonts = get_option('google_fonts_localizer_cache');
     172        if (!$cached_fonts || $rebuild) {
     173            $cached_fonts = [];
     174        }
     175
    145176        $uploads_path = (wp_get_upload_dir())['basedir'] . '/fonts_cache';
    146177        $uploads_url = (wp_get_upload_dir())['baseurl'] . '/fonts_cache';
  • hardcore-google-fonts-localizer/trunk/frontend/class-google-fonts-localizer-frontend.php

    r1981281 r2529383  
    5353                    font-weight: <?php echo $weight; ?>;
    5454                    font-style: <?php echo $style; ?>;
     55                    font-display: swap;
    5556                    src: <?php echo implode(',', $src); ?>;
    5657                    }
  • hardcore-google-fonts-localizer/trunk/google-fonts-localizer.php

    r2011970 r2529383  
    33 * Plugin Name:       Hardcore Google Fonts Localizer
    44 * Description:       A Plugin that enables you to host google fonts on your server with no effort (GDPR safe)
    5  * Version:           1.0.2
     5 * Version:           1.2.0
    66 * Author:            Lorem Ipsum web.solutions GmbH
    77 * Author URI:        https://www.loremipsum.at/
     
    1818load_plugin_textdomain( 'google-fonts-localizer', false, basename( dirname( __FILE__ ) ) . '/languages' );
    1919
    20 define( 'GOOGLE_FONTS_LOCALIZER_PLUGIN_VERSION', '1.0.2' );
     20define( 'GOOGLE_FONTS_LOCALIZER_PLUGIN_VERSION', '1.2.0' );
    2121define( 'GOOGLE_FONTS_LOCALIZER_PLUGIN_FILE', __FILE__);
    2222define( 'GOOGLE_FONTS_LOCALIZER_PLUGIN_TITLE', 'Hardcore Google Fonts Localizer');
  • hardcore-google-fonts-localizer/trunk/readme.txt

    r2011970 r2529383  
    55Tags: GDPR, local fonts
    66Requires at least: 4.8
    7 Tested up to: 5.0.3
    8 Stable tag: 1.0.2
     7Tested up to: 5.7.1
     8Stable tag: 1.2.0
    99Requires PHP: 7.0
    1010
     
    5454
    5555== Changelog ==
     56= 1.2.0 =
     57Updated to changed Google Fonts URLs endpoint
     58Fixed Issue with multiple Font Families
     59
     60= 1.1.0 =
     61Updated to new Google Fonts URLs, added font-display: swap;
     62
    5663= 1.0.2 =
    5764Included JupiterX and Elementor
Note: See TracChangeset for help on using the changeset viewer.