mirror of
https://ghproxy.net/https://github.com/AlxMedia/curver.git
synced 2025-08-28 11:50:25 +08:00
Update to Kirki 4.2.0
This commit is contained in:
parent
cbfd4f27e4
commit
77ecd4ca69
440 changed files with 6230 additions and 5211 deletions
91
functions/kirki/kirki-packages/googlefonts/Gruntfile.js
Normal file
91
functions/kirki/kirki-packages/googlefonts/Gruntfile.js
Normal file
|
@ -0,0 +1,91 @@
|
|||
/* global module */
|
||||
module.exports = function( grunt ) {
|
||||
|
||||
grunt.initConfig( {
|
||||
|
||||
// Get json file from the google-fonts API
|
||||
http: {
|
||||
'google-fonts-alpha': {
|
||||
options: { url: 'https://www.googleapis.com/webfonts/v1/webfonts?sort=alpha&key=AIzaSyCDiOc36EIOmwdwspLG3LYwCg9avqC5YLs' },
|
||||
dest: 'src/webfonts-alpha.json'
|
||||
},
|
||||
'google-fonts-popularity': {
|
||||
options: { url: 'https://www.googleapis.com/webfonts/v1/webfonts?sort=popularity&key=AIzaSyCDiOc36EIOmwdwspLG3LYwCg9avqC5YLs' },
|
||||
dest: 'src/webfonts-popularity.json'
|
||||
},
|
||||
'google-fonts-trending': {
|
||||
options: { url: 'https://www.googleapis.com/webfonts/v1/webfonts?sort=trending&key=AIzaSyCDiOc36EIOmwdwspLG3LYwCg9avqC5YLs' },
|
||||
dest: 'src/webfonts-trending.json'
|
||||
}
|
||||
}
|
||||
} );
|
||||
|
||||
grunt.loadNpmTasks( 'grunt-http' );
|
||||
grunt.registerTask( 'googlefontsProcess', function() {
|
||||
var alphaFonts,
|
||||
popularityFonts,
|
||||
trendingFonts,
|
||||
finalObject = {
|
||||
items: {},
|
||||
order: {
|
||||
alpha: [],
|
||||
popularity: [],
|
||||
trending: []
|
||||
}
|
||||
},
|
||||
finalJSON,
|
||||
i,
|
||||
fontFiles = {},
|
||||
fontNames = [];
|
||||
|
||||
// Get file contents.
|
||||
alphaFonts = grunt.file.readJSON( 'src/webfonts-alpha.json' );
|
||||
popularityFonts = grunt.file.readJSON( 'src/webfonts-popularity.json' );
|
||||
trendingFonts = grunt.file.readJSON( 'src/webfonts-trending.json' );
|
||||
|
||||
// Add the alpha order.
|
||||
for ( i = 0; i < alphaFonts.items.length; i++ ) {
|
||||
finalObject.order.alpha.push( alphaFonts.items[ i ].family );
|
||||
}
|
||||
|
||||
for ( i = 0; i < popularityFonts.items.length; i++ ) {
|
||||
|
||||
// Populate the fonts.
|
||||
finalObject.items[ alphaFonts.items[ i ].family ] = {
|
||||
family: alphaFonts.items[ i ].family,
|
||||
category: alphaFonts.items[ i ].category,
|
||||
variants: alphaFonts.items[ i ].variants.sort()
|
||||
};
|
||||
|
||||
// Add the popularity order.
|
||||
finalObject.order.popularity.push( popularityFonts.items[ i ].family );
|
||||
fontNames.push( popularityFonts.items[ i ].family );
|
||||
}
|
||||
|
||||
// Add the trending order.
|
||||
for ( i = 0; i < trendingFonts.items.length; i++ ) {
|
||||
finalObject.order.trending.push( trendingFonts.items[ i ].family );
|
||||
}
|
||||
|
||||
// Generate the font-files object.
|
||||
for ( i = 0; i < popularityFonts.items.length; i++ ) {
|
||||
fontFiles[ popularityFonts.items[ i ].family ] = popularityFonts.items[ i ].files;
|
||||
}
|
||||
|
||||
// Write the final object to json.
|
||||
finalJSON = JSON.stringify( finalObject );
|
||||
grunt.file.write( 'src/webfonts.json', finalJSON );
|
||||
grunt.file.write( 'src/webfont-names.json', JSON.stringify( fontNames ) );
|
||||
grunt.file.write( 'src/webfont-files.json', JSON.stringify( fontFiles ) );
|
||||
|
||||
// Delete files no longer needed.
|
||||
grunt.file.delete( 'src/webfonts-alpha.json' ); // jshint ignore:line
|
||||
grunt.file.delete( 'src/webfonts-popularity.json' ); // jshint ignore:line
|
||||
grunt.file.delete( 'src/webfonts-trending.json' ); // jshint ignore:line
|
||||
} );
|
||||
grunt.registerTask( 'googlefonts', function() {
|
||||
grunt.task.run( 'http' );
|
||||
grunt.task.run( 'googlefontsProcess' );
|
||||
} );
|
||||
grunt.registerTask( 'default', [ 'googlefonts' ] );
|
||||
};
|
21
functions/kirki/kirki-packages/googlefonts/LICENSE
Normal file
21
functions/kirki/kirki-packages/googlefonts/LICENSE
Normal file
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2019 kirki-framework
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
187
functions/kirki/kirki-packages/googlefonts/src/GoogleFonts.php
Normal file
187
functions/kirki/kirki-packages/googlefonts/src/GoogleFonts.php
Normal file
|
@ -0,0 +1,187 @@
|
|||
<?php
|
||||
/**
|
||||
* Processes typography-related fields
|
||||
* and generates the google-font link.
|
||||
*
|
||||
* @package kirki-framework/googlefonts
|
||||
* @author Themeum
|
||||
* @copyright Copyright (c) 2023, Themeum
|
||||
* @license https://opensource.org/licenses/MIT
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
namespace Kirki;
|
||||
|
||||
/**
|
||||
* Manages the way Google Fonts are enqueued.
|
||||
*/
|
||||
final class GoogleFonts {
|
||||
|
||||
/**
|
||||
* An array of our google fonts.
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @since 1.0.0
|
||||
* @var array
|
||||
*/
|
||||
public static $google_fonts;
|
||||
|
||||
/**
|
||||
* An array of our google font names.
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @since 1.0.2
|
||||
* @var array
|
||||
*/
|
||||
public static $google_font_names;
|
||||
|
||||
/**
|
||||
* The class constructor.
|
||||
*
|
||||
* @access public
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( 'wp_ajax_kirki_fonts_google_all_get', [ $this, 'print_googlefonts_json' ] );
|
||||
add_action( 'wp_ajax_nopriv_kirki_fonts_google_all_get', [ $this, 'print_googlefonts_json' ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints the googlefonts JSON file.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @param bool $die Whether the script should exit or not.
|
||||
* @return void
|
||||
*/
|
||||
public function print_googlefonts_json( $die = true ) {
|
||||
include 'webfonts.json'; // phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude
|
||||
if ( function_exists( 'wp_die' ) && $die ) {
|
||||
wp_die();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the array of googlefonts from the JSON file.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @return array
|
||||
*/
|
||||
public function get_array() {
|
||||
ob_start();
|
||||
include 'webfonts.json'; // phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude
|
||||
return json_decode( ob_get_clean(), true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the array of googlefont names from the JSON file.
|
||||
*
|
||||
* @since 1.0.2
|
||||
* @return array
|
||||
*/
|
||||
public function get_names_array() {
|
||||
ob_start();
|
||||
include 'webfont-names.json'; // phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude
|
||||
return json_decode( ob_get_clean(), true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of all available Google Fonts.
|
||||
*
|
||||
* @access public
|
||||
* @since 1.0.0
|
||||
* @return array All Google Fonts.
|
||||
*/
|
||||
public function get_google_fonts() {
|
||||
|
||||
// Get fonts from cache.
|
||||
self::$google_fonts = get_site_transient( 'kirki_googlefonts_cache' );
|
||||
|
||||
// If cache is populated, return cached fonts array.
|
||||
if ( self::$google_fonts ) {
|
||||
return self::$google_fonts;
|
||||
}
|
||||
|
||||
// If we got this far, cache was empty so we need to get from JSON.
|
||||
$fonts = $this->get_array();
|
||||
|
||||
self::$google_fonts = [];
|
||||
if ( is_array( $fonts ) ) {
|
||||
foreach ( $fonts['items'] as $font ) {
|
||||
self::$google_fonts[ $font['family'] ] = [
|
||||
'label' => $font['family'],
|
||||
'variants' => $font['variants'],
|
||||
'category' => $font['category'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// Apply the 'kirki_fonts_google_fonts' filter.
|
||||
self::$google_fonts = apply_filters( 'kirki_fonts_google_fonts', self::$google_fonts );
|
||||
|
||||
// Save the array in cache.
|
||||
$cache_time = apply_filters( 'kirki_googlefonts_transient_time', HOUR_IN_SECONDS );
|
||||
set_site_transient( 'kirki_googlefonts_cache', self::$google_fonts, $cache_time );
|
||||
|
||||
return self::$google_fonts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of all available Google Font names.
|
||||
*
|
||||
* @access public
|
||||
* @since 1.0.2
|
||||
* @return array All Google Font names.
|
||||
*/
|
||||
public function get_google_font_names() {
|
||||
|
||||
// Get fonts from cache.
|
||||
self::$google_font_names = get_site_transient( 'kirki_googlefont_names_cache' );
|
||||
|
||||
// If cache is populated, return cached fonts array.
|
||||
if ( self::$google_font_names ) {
|
||||
return self::$google_font_names;
|
||||
}
|
||||
|
||||
// If we got this far, cache was empty so we need to get from JSON.
|
||||
self::$google_font_names = $this->get_names_array();
|
||||
|
||||
// Apply the 'kirki_fonts_google_font_names' filter.
|
||||
self::$google_font_names = apply_filters( 'kirki_fonts_google_font_names', self::$google_font_names );
|
||||
|
||||
// Save the array in cache.
|
||||
$cache_time = apply_filters( 'kirki_googlefont_names_transient_time', HOUR_IN_SECONDS );
|
||||
set_site_transient( 'kirki_googlefont_names_cache', self::$google_font_names, $cache_time );
|
||||
|
||||
return self::$google_font_names;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of google-fonts matching our arguments.
|
||||
*
|
||||
* @access public
|
||||
* @since 1.0.0
|
||||
* @param array $args The arguments.
|
||||
* @return array
|
||||
*/
|
||||
public function get_google_fonts_by_args( $args = [] ) {
|
||||
$cache_name = 'kirki_googlefonts_' . md5( wp_json_encode( $args ) );
|
||||
$cache = get_site_transient( $cache_name );
|
||||
if ( $cache ) {
|
||||
return $cache;
|
||||
}
|
||||
|
||||
$args['sort'] = isset( $args['sort'] ) ? $args['sort'] : 'alpha';
|
||||
|
||||
$fonts = $this->get_array();
|
||||
$ordered_fonts = $fonts['order'][ $args['sort'] ];
|
||||
if ( isset( $args['count'] ) ) {
|
||||
$ordered_fonts = array_slice( $ordered_fonts, 0, $args['count'] );
|
||||
set_site_transient( $cache_name, $ordered_fonts, HOUR_IN_SECONDS );
|
||||
return $ordered_fonts;
|
||||
}
|
||||
set_site_transient( $cache_name, $ordered_fonts, HOUR_IN_SECONDS );
|
||||
return $ordered_fonts;
|
||||
}
|
||||
}
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue