Subir proyecto
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Jooosi Fon package.
|
||||
*
|
||||
* (c) Joshua Gugun Siagian <suabahasa@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
declare (strict_types=1);
|
||||
namespace JooosiFon\Builder;
|
||||
|
||||
interface BuilderInterface
|
||||
{
|
||||
/**
|
||||
* Get the Builder integration name.
|
||||
*/
|
||||
public function get_name(): string;
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Jooosi Fon package.
|
||||
*
|
||||
* (c) Joshua Gugun Siagian <suabahasa@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
declare (strict_types=1);
|
||||
namespace JooosiFon\Builder\Builderius;
|
||||
|
||||
use JooosiFon\Admin\AdminPage;
|
||||
use JooosiFon\Builder\BuilderInterface;
|
||||
use JooosiFon\Utils\Font;
|
||||
/**
|
||||
* @author Joshua Gugun Siagian <suabahasa@gmail.com>
|
||||
*
|
||||
* @todo Built-in Google Fonts are not disabled.
|
||||
*/
|
||||
class Main implements BuilderInterface
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
add_action('admin_menu', static fn() => AdminPage::add_redirect_submenu_page('builderius'), 1000001);
|
||||
add_action('wp_enqueue_scripts', fn() => $this->enqueue_scripts(), 1000001);
|
||||
}
|
||||
public function get_name(): string
|
||||
{
|
||||
return 'builderius';
|
||||
}
|
||||
public function enqueue_scripts()
|
||||
{
|
||||
if (!wp_script_is('builderius-builder', 'registered')) {
|
||||
return;
|
||||
}
|
||||
$fonts = Font::get_fonts();
|
||||
$inline_script_content = <<<JS
|
||||
const moduleTypography = builderiusBackend.settingsList?.module?.advanced?.typography?.find((item) => item.name === 'font');
|
||||
|
||||
if (moduleTypography) {
|
||||
moduleTypography.options.fontType.values.push('Jooosi Fon');
|
||||
moduleTypography.options.genericFamily.values['Jooosi Fon'] = ['Jooosi Fon'];
|
||||
moduleTypography.options.fontFamily.values['Jooosi Fon.Jooosi Fon'] = jooosiFonBuilderiusFonts;
|
||||
}
|
||||
|
||||
const GlobalTypography = builderiusBackend.settingsList?.global?.advanced?.typography?.find((item) => item.name === 'font');
|
||||
|
||||
if (GlobalTypography) {
|
||||
GlobalTypography.options.fontType.values.push('Jooosi Fon');
|
||||
GlobalTypography.options.genericFamily.values['Jooosi Fon'] = ['Jooosi Fon'];
|
||||
GlobalTypography.options.fontFamily.values['Jooosi Fon.Jooosi Fon'] = jooosiFonBuilderiusFonts;
|
||||
}
|
||||
|
||||
const templateTypography = builderiusBackend.settingsList?.template?.advanced?.typography?.find((item) => item.name === 'font');
|
||||
|
||||
if (templateTypography) {
|
||||
templateTypography.options.fontType.values.push('Jooosi Fon');
|
||||
templateTypography.options.genericFamily.values['Jooosi Fon'] = ['Jooosi Fon'];
|
||||
templateTypography.options.fontFamily.values['Jooosi Fon.Jooosi Fon'] = jooosiFonBuilderiusFonts;
|
||||
}
|
||||
JS;
|
||||
wp_add_inline_script('builderius-builder', 'const jooosiFonBuilderiusFonts = ' . json_encode(array_column($fonts, 'family'), \JSON_THROW_ON_ERROR), 'before');
|
||||
wp_add_inline_script('builderius-builder', $inline_script_content, 'before');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Jooosi Fon package.
|
||||
*
|
||||
* (c) Joshua Gugun Siagian <suabahasa@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
declare (strict_types=1);
|
||||
namespace JooosiFon\Builder\ClassicEditor;
|
||||
|
||||
use JooosiFon\Builder\BuilderInterface;
|
||||
use JooosiFon\Core\Cache;
|
||||
use JooosiFon\Utils\Font;
|
||||
/**
|
||||
* Classic Editor integration.
|
||||
*
|
||||
* @author Joshua Gugun Siagian <suabahasa@gmail.com>
|
||||
*/
|
||||
class Main implements BuilderInterface
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
add_filter('mce_buttons_2', fn($buttons) => $this->filter_mce_buttons($buttons), 1000001);
|
||||
add_filter('tiny_mce_before_init', fn($mceInit, $editor_id) => $this->filter_tiny_mce($mceInit, $editor_id), 1000001, 2);
|
||||
add_filter('mce_css', fn($stylesheets) => $this->filter_mce_css($stylesheets), 1000001);
|
||||
}
|
||||
public function get_name(): string
|
||||
{
|
||||
return 'classic-editor';
|
||||
}
|
||||
public function filter_tiny_mce($mceInit, $editor_id)
|
||||
{
|
||||
$theme_advanced_fonts = '';
|
||||
$fonts = Font::get_fonts();
|
||||
foreach ($fonts as $font) {
|
||||
$theme_advanced_fonts .= sprintf('[Jooosi Fon] %s=%s;', $font['title'], $font['family']);
|
||||
}
|
||||
$mceInit['font_formats'] = $theme_advanced_fonts . 'Andale Mono=andale mono,times; Arial=arial,helvetica,sans-serif; Arial Black=arial black,avant garde; Book Antiqua=book antiqua,palatino; Comic Sans MS=comic sans ms,sans-serif; Courier New=courier new,courier; Georgia=georgia,palatino; Helvetica=helvetica; Impact=impact,chicago; Symbol=symbol; Tahoma=tahoma,arial,helvetica,sans-serif; Terminal=terminal,monaco; Times New Roman=times new roman,times; Trebuchet MS=trebuchet ms,geneva; Verdana=verdana,geneva; Webdings=webdings; Wingdings=wingdings,zapf dingbats';
|
||||
return $mceInit;
|
||||
}
|
||||
public function filter_mce_buttons($buttons)
|
||||
{
|
||||
return array_merge($buttons, ['fontsizeselect', 'fontselect']);
|
||||
}
|
||||
public function filter_mce_css($stylesheets)
|
||||
{
|
||||
$css_url = Cache::get_versioned_cache_url(Cache::CSS_CACHE_FILE);
|
||||
if (is_array($stylesheets)) {
|
||||
$stylesheets[] = $css_url;
|
||||
} else {
|
||||
$stylesheets .= ',' . $css_url;
|
||||
}
|
||||
return $stylesheets;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Jooosi Fon package.
|
||||
*
|
||||
* (c) Joshua Gugun Siagian <suabahasa@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
declare (strict_types=1);
|
||||
namespace JooosiFon\Builder\Elementor;
|
||||
|
||||
use JooosiFon\Admin\AdminPage;
|
||||
use JooosiFon\Builder\BuilderInterface;
|
||||
use JooosiFon\Utils\Config;
|
||||
use JooosiFon\Utils\Font;
|
||||
/**
|
||||
* Elementor integration.
|
||||
*
|
||||
* @author Joshua Gugun Siagian <suabahasa@gmail.com>
|
||||
*/
|
||||
class Main implements BuilderInterface
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
/**
|
||||
* Disable Elementor's built-in Google Fonts.
|
||||
*/
|
||||
if (Config::get('builder_integrations.disable_google_fonts.elementor', \true)) {
|
||||
add_filter('pre_option_elementor_google_font', static fn($pre_option, $option, $default) => '0', 1000001, 3);
|
||||
add_filter('pre_update_option_elementor_google_font', static fn($value, $old_value, $option) => '0', 1000001, 3);
|
||||
}
|
||||
/**
|
||||
* Register fonts with 'custom' category for Atomic Widgets compatibility.
|
||||
* Atomic Widgets (Elementor v4) only supports: system, custom, googlefonts
|
||||
*/
|
||||
add_filter('elementor/fonts/additional_fonts', fn($fonts) => $this->filter_elementor_fonts($fonts), 1000001);
|
||||
add_action('admin_menu', static fn() => AdminPage::add_redirect_submenu_page('elementor'), 1000001);
|
||||
}
|
||||
public function get_name(): string
|
||||
{
|
||||
return 'elementor';
|
||||
}
|
||||
/**
|
||||
* Register fonts with Elementor.
|
||||
* Uses 'custom' category for compatibility with both Classic Editor and Atomic Widgets.
|
||||
*
|
||||
* @param array $elementor_fonts Existing Elementor fonts.
|
||||
* @return array Modified fonts array.
|
||||
*/
|
||||
public function filter_elementor_fonts($elementor_fonts)
|
||||
{
|
||||
$fonts = Font::get_fonts();
|
||||
foreach ($fonts as $font) {
|
||||
// Use 'custom' category for Atomic Widgets v4 compatibility
|
||||
// Atomic Widgets only recognizes: system, custom, googlefonts
|
||||
$elementor_fonts[$font['family']] = 'custom';
|
||||
}
|
||||
return $elementor_fonts;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Jooosi Fon package.
|
||||
*
|
||||
* (c) Joshua Gugun Siagian <suabahasa@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
declare (strict_types=1);
|
||||
namespace JooosiFon\Builder\GeneratePress;
|
||||
|
||||
use JooosiFon\Builder\BuilderInterface;
|
||||
use JooosiFon\Utils\Font;
|
||||
/**
|
||||
* GeneratePress and GenerateBlocks integration.
|
||||
*
|
||||
* @author Joshua Gugun Siagian <suabahasa@gmail.com>
|
||||
*/
|
||||
class Main implements BuilderInterface
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
/**
|
||||
* Disable GeneratePress's built-in Google Fonts.
|
||||
*/
|
||||
add_filter('generate_font_manager_show_google_fonts', static fn() => \false, 1000001, 0);
|
||||
/**
|
||||
* Disable GenerateBlocks's built-in Google Fonts.
|
||||
*/
|
||||
add_filter('generateblocks_option_defaults', fn($value) => $this->filter_generateblocks_option_defaults($value), 1000001, 1);
|
||||
add_filter('option_generateblocks', fn($value, $option) => $this->filter_option_generateblocks($value), 1000001, 2);
|
||||
/**
|
||||
* Add custom font to GeneratePress.
|
||||
* Append the data on the pre_option, and rewrite the data on the option and pre_update_option.
|
||||
*/
|
||||
add_filter('generate_option_defaults', fn($opt) => $this->filter_generate_option_defaults($opt), 1000001);
|
||||
/**
|
||||
* @deprecated version 2.0.11
|
||||
* @see https://github.com/tomusborne/generatepress/blob/e7fbf5693bfe4325a41cae988e3eda16550d4025/inc/defaults.php#L412
|
||||
*/
|
||||
// add_filter('generate_typography_default_fonts', static fn ($fonts) => array_merge($fonts, array_column(Font::get_fonts(), 'family')), 1_000_001);
|
||||
/**
|
||||
* @deprecated version 2.0.46
|
||||
*/
|
||||
// add_filter('pre_option_generate_settings', fn ($value, $option) => $this->generate_settings($value), 1_000_001, 2);
|
||||
// add_filter('option_generate_settings', fn ($value, $option) => $this->generate_settings($value), 1_000_001, 2);
|
||||
// add_filter('pre_update_option_generate_settings', fn ($value, $old_value, $option) => $this->generate_settings($value), 1_000_001, 3);
|
||||
/**
|
||||
* Add custom font to GenerateBlocks.
|
||||
*
|
||||
* @see https://github.com/tomusborne/generateblocks/issues/937
|
||||
*/
|
||||
add_filter('generateblocks_typography_font_family_list', fn($fonts) => $this->generateblocks_typography_font_family_list($fonts), 1000001);
|
||||
}
|
||||
public function get_name(): string
|
||||
{
|
||||
return 'generate-press';
|
||||
}
|
||||
public function generate_settings($opt)
|
||||
{
|
||||
$fonts = Font::get_fonts();
|
||||
if (!is_array($opt)) {
|
||||
$opt = [];
|
||||
}
|
||||
if (!array_key_exists('font_manager', $opt) || !is_array($opt['font_manager'])) {
|
||||
$opt['font_manager'] = [];
|
||||
}
|
||||
foreach ($fonts as $font) {
|
||||
if (!in_array($font['family'], array_column($opt['font_manager'], 'fontFamily'), \true)) {
|
||||
$opt['font_manager'][] = ['fontFamily' => $font['family'], 'googleFont' => \false, 'googleFontApi' => 0];
|
||||
}
|
||||
}
|
||||
return $opt;
|
||||
}
|
||||
public function filter_generateblocks_option_defaults($opt)
|
||||
{
|
||||
if (is_array($opt)) {
|
||||
$opt['disable_google_fonts'] = \true;
|
||||
}
|
||||
return $opt;
|
||||
}
|
||||
public function filter_option_generateblocks($opt)
|
||||
{
|
||||
if (is_array($opt)) {
|
||||
$opt['disable_google_fonts'] = \true;
|
||||
}
|
||||
return $opt;
|
||||
}
|
||||
public function generateblocks_typography_font_family_list($gb_fonts)
|
||||
{
|
||||
$fonts = Font::get_fonts();
|
||||
$jooosi_fonts = array_map(static fn($f) => ['label' => $f['title'], 'value' => $f['family']], $fonts);
|
||||
return array_merge([['label' => 'Jooosi Fon', 'options' => $jooosi_fonts]], is_array($gb_fonts) ? $gb_fonts : iterator_to_array($gb_fonts));
|
||||
}
|
||||
public function filter_generate_option_defaults($opt)
|
||||
{
|
||||
$fonts = Font::get_fonts();
|
||||
if (!array_key_exists('font_manager', $opt) || !is_array($opt['font_manager'])) {
|
||||
$opt['font_manager'] = [];
|
||||
}
|
||||
foreach ($fonts as $font) {
|
||||
if (!in_array($font['family'], array_column($opt['font_manager'], 'fontFamily'), \true)) {
|
||||
$opt['font_manager'][] = ['fontFamily' => $font['family'], 'googleFont' => \false, 'googleFontApi' => 0];
|
||||
}
|
||||
}
|
||||
return $opt;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Jooosi Fon package.
|
||||
*
|
||||
* (c) Joshua Gugun Siagian <suabahasa@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
declare (strict_types=1);
|
||||
namespace JooosiFon\Builder\Gutenberg;
|
||||
|
||||
use JooosiFonDeps\JOOOSI_FON;
|
||||
use JooosiFon\Builder\BuilderInterface;
|
||||
use JooosiFon\Core\Cache;
|
||||
use JooosiFon\Core\Frontpage;
|
||||
use JooosiFon\Utils\Config;
|
||||
use JooosiFon\Utils\Font;
|
||||
use WP_Theme_JSON;
|
||||
use WP_Theme_JSON_Data;
|
||||
/**
|
||||
* Gutenberg integration.
|
||||
*
|
||||
* @see https://developer.wordpress.org/block-editor/how-to-guides/themes/theme-json/
|
||||
* @see https://developer.wordpress.org/block-editor/reference-guides/theme-json-reference/theme-json-living/
|
||||
* @see https://developer.wordpress.org/themes/advanced-topics/theme-json/
|
||||
* @see https://make.wordpress.org/core/2022/10/10/filters-for-theme-json-data/
|
||||
* @see https://make.wordpress.org/core/2021/09/28/implementing-a-webfonts-api-in-wordpress-core/
|
||||
*
|
||||
* @author Joshua Gugun Siagian <suabahasa@gmail.com>
|
||||
*/
|
||||
class Main implements BuilderInterface
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
add_filter('wp_theme_json_data_theme', fn($theme_json) => $this->filter_theme_json_data_theme($theme_json), 1000001);
|
||||
add_filter('f!jooosi/fon/core/cache:build_css.append_content', fn($css, $rows) => $this->filter_append_build_css_content($css, $rows), 1000001, 2);
|
||||
add_filter('f!jooosi/fon/core/cache:build_css.append_content', fn($css, $rows) => $this->filter_ensure_block_editor($css, $rows), 1000001, 2);
|
||||
// add_action('enqueue_block_editor_assets', fn () => $this->enqueue_block_editor_assets(), 1_000_001);
|
||||
// add_action('after_setup_theme', fn () => $this->after_setup_theme(), 1_000_001);
|
||||
add_action('enqueue_block_assets', fn() => $this->enqueue_block_assets(), 1000001);
|
||||
}
|
||||
public function get_name(): string
|
||||
{
|
||||
return 'gutenberg';
|
||||
}
|
||||
/**
|
||||
* @see https://make.wordpress.org/core/2022/10/10/filters-for-theme-json-data/
|
||||
* @param WP_Theme_JSON_Data $theme_json
|
||||
* @return WP_Theme_JSON_Data
|
||||
*/
|
||||
public function filter_theme_json_data_theme($theme_json)
|
||||
{
|
||||
$theme_json_data = $theme_json->get_data();
|
||||
$theme_json_font_families = $theme_json_data['settings']['typography']['fontFamilies']['theme'] ?? [];
|
||||
$font_family_presets = [];
|
||||
foreach (Font::get_fonts() as $font) {
|
||||
/**
|
||||
* @see https://www.w3.org/TR/CSS22/syndata.html#value-def-identifier
|
||||
*/
|
||||
$font_family_presets[] = ['name' => $font['title'], 'slug' => Font::slugify($font['family']), 'fontFamily' => Font::css_variable($font['family'])];
|
||||
}
|
||||
$new_data = ['version' => WP_Theme_JSON::LATEST_SCHEMA, 'settings' => ['typography' => ['fontFamilies' => self::merge_font_family_presets($theme_json_font_families, $font_family_presets)]]];
|
||||
return $theme_json->update_with($new_data);
|
||||
}
|
||||
public function enqueue_block_editor_assets()
|
||||
{
|
||||
$screen = get_current_screen();
|
||||
if (is_admin() && $screen->is_block_editor()) {
|
||||
add_action('admin_head', static function () {
|
||||
add_filter('f!jooosi/fon/api/setting/option:index_options', static function ($options) {
|
||||
Config::propertyAccessor()->setValue($options, 'cache.inline_print', \false);
|
||||
return $options;
|
||||
}, 1000001);
|
||||
Frontpage::enqueue_css_cache();
|
||||
}, 1000001);
|
||||
}
|
||||
}
|
||||
public function after_setup_theme()
|
||||
{
|
||||
// Add support for editor styles.
|
||||
add_theme_support('editor-styles');
|
||||
add_editor_style(Cache::get_versioned_cache_url(Cache::CSS_CACHE_FILE));
|
||||
}
|
||||
public function enqueue_block_assets()
|
||||
{
|
||||
if (is_admin() && file_exists(Cache::get_cache_path(Cache::CSS_CACHE_FILE))) {
|
||||
$handle = JOOOSI_FON::WP_OPTION . '-cache';
|
||||
$version = Cache::get_cache_version(Cache::CSS_CACHE_FILE) ?? JOOOSI_FON::VERSION;
|
||||
wp_enqueue_style($handle, Cache::get_cache_url(Cache::CSS_CACHE_FILE), [], $version);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* ensure the css file is loaded to the block editor, template editor, or site editor
|
||||
*/
|
||||
public function filter_ensure_block_editor($css, $rows): string
|
||||
{
|
||||
return $css . ".wp-block, .editor-styles-wrapper { } \n\n";
|
||||
}
|
||||
/**
|
||||
* Support for a non block-based theme.
|
||||
*/
|
||||
public function filter_append_build_css_content($css, $rows)
|
||||
{
|
||||
if (function_exists('wp_is_block_theme') && wp_is_block_theme()) {
|
||||
return $css;
|
||||
}
|
||||
return $css . self::non_block_based_theme_support_classes();
|
||||
}
|
||||
public static function non_block_based_theme_support_classes(): string
|
||||
{
|
||||
$inline_css = '';
|
||||
$fonts = Font::get_fonts();
|
||||
foreach ($fonts as $font) {
|
||||
$inline_css .= sprintf(".has-%s-font-family {\n", Font::slugify($font['family']));
|
||||
$inline_css .= sprintf("\tfont-family: %s !important;\n", Font::css_variable($font['family']));
|
||||
$inline_css .= "}\n\n";
|
||||
}
|
||||
return $inline_css;
|
||||
}
|
||||
private static function merge_font_family_presets(array $existing, array $incoming): array
|
||||
{
|
||||
$merged = [];
|
||||
$positions = [];
|
||||
foreach (array_merge($existing, $incoming) as $preset) {
|
||||
$slug = is_array($preset) && isset($preset['slug']) && is_string($preset['slug']) ? $preset['slug'] : '';
|
||||
if ($slug === '') {
|
||||
$merged[] = $preset;
|
||||
continue;
|
||||
}
|
||||
if (isset($positions[$slug])) {
|
||||
$merged[$positions[$slug]] = $preset;
|
||||
continue;
|
||||
}
|
||||
$positions[$slug] = count($merged);
|
||||
$merged[] = $preset;
|
||||
}
|
||||
return array_values($merged);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Jooosi Fon package.
|
||||
*
|
||||
* (c) Joshua Gugun Siagian <suabahasa@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
declare (strict_types=1);
|
||||
namespace JooosiFon\Builder;
|
||||
|
||||
use JooosiFonDeps\JOOOSI_FON;
|
||||
use ReflectionClass;
|
||||
use JooosiFonDeps\Symfony\Component\Finder\Finder;
|
||||
/**
|
||||
* @todo Remove all legacy Yabe Webfont hook shims completely in Jooosi Fon 3.0.0.
|
||||
*/
|
||||
class Integration
|
||||
{
|
||||
private static int $registered_count = 0;
|
||||
/**
|
||||
* List of Builders services.
|
||||
*
|
||||
* @var BuilderInterface[]
|
||||
*/
|
||||
private array $builders = [];
|
||||
public function __construct()
|
||||
{
|
||||
$this->scan_builders();
|
||||
$this->register_builders();
|
||||
}
|
||||
public function scan_builders()
|
||||
{
|
||||
// Get cached Builders
|
||||
$transient_name = 'jooosi_fon_scanned_builders_' . JOOOSI_FON::VERSION;
|
||||
/** @var BuilderInterface[]|false $cached */
|
||||
$cached = get_transient($transient_name);
|
||||
if ($cached !== \false) {
|
||||
$this->builders = $cached;
|
||||
return;
|
||||
}
|
||||
$finder = new Finder();
|
||||
$finder->files()->in(__DIR__)->name('*.php');
|
||||
/**
|
||||
* Add additional places to scan for Builders integration.
|
||||
*
|
||||
* @param Finder $finder The Finder instance.
|
||||
*/
|
||||
do_action('a!jooosi/fon/builder/integration:before_scan', $finder);
|
||||
do_action_deprecated('a!yabe/webfont/builder/integration:before_scan', [$finder], '2.1.0', 'a!jooosi/fon/builder/integration:before_scan');
|
||||
foreach ($finder as $file) {
|
||||
$builder_file = $file->getPathname();
|
||||
if (!is_readable($builder_file)) {
|
||||
continue;
|
||||
}
|
||||
require_once $builder_file;
|
||||
}
|
||||
// Find any Builders integration that extends BuilderInterface class
|
||||
$declared_classes = get_declared_classes();
|
||||
foreach ($declared_classes as $declared_class) {
|
||||
if (!class_exists($declared_class)) {
|
||||
continue;
|
||||
}
|
||||
$reflector = new ReflectionClass($declared_class);
|
||||
if (!$reflector->isSubclassOf(\JooosiFon\Builder\BuilderInterface::class)) {
|
||||
continue;
|
||||
}
|
||||
// Get Builders integration detail and push to Integration::$builders to be register later
|
||||
/** @var BuilderInterface $builder */
|
||||
$builder = $reflector->newInstanceWithoutConstructor();
|
||||
$this->builders[$builder->get_name()] = ['name' => $builder->get_name(), 'file_path' => $reflector->getFileName(), 'class_name' => $reflector->getName()];
|
||||
}
|
||||
// Cache the Builders
|
||||
set_transient($transient_name, $this->builders, \DAY_IN_SECONDS);
|
||||
}
|
||||
/**
|
||||
* Register Builders.
|
||||
*/
|
||||
public function register_builders(): void
|
||||
{
|
||||
/**
|
||||
* Filter the Builders before register.
|
||||
*
|
||||
* @param BuilderInterface[] $builders
|
||||
* @return BuilderInterface[]
|
||||
*/
|
||||
/** @var BuilderInterface[] $builders */
|
||||
$builders = apply_filters('f!jooosi/fon/builder/integration:register_builders', $this->builders);
|
||||
$builders = apply_filters_deprecated('f!yabe/webfont/builder/integration:register_builders', [$builders], '2.1.0', 'f!jooosi/fon/builder/integration:register_builders');
|
||||
self::$registered_count = count($builders);
|
||||
foreach ($builders as $builder) {
|
||||
// Create new instance of Builder class
|
||||
/** @var BuilderInterface $builderInstance */
|
||||
$builderInstance = new $builder['class_name']();
|
||||
$this->builders[$builder['name']]['instance'] = $builderInstance;
|
||||
}
|
||||
}
|
||||
public static function get_registered_count(): int
|
||||
{
|
||||
return self::$registered_count;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Jooosi Fon package.
|
||||
*
|
||||
* (c) Joshua Gugun Siagian <suabahasa@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
declare (strict_types=1);
|
||||
namespace JooosiFon\Builder\Kadence;
|
||||
|
||||
use JooosiFonDeps\JOOOSI_FON;
|
||||
use JooosiFon\Builder\BuilderInterface;
|
||||
use JooosiFon\Utils\Font;
|
||||
/**
|
||||
* Kadence integration.
|
||||
*
|
||||
* @author Joshua Gugun Siagian <suabahasa@gmail.com>
|
||||
*/
|
||||
class Main implements BuilderInterface
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
add_filter('kadence_theme_custom_fonts', fn($fonts) => $this->theme_custom_fonts($fonts), 1000001);
|
||||
add_action('enqueue_block_editor_assets', fn() => $this->register_block_editor_assets(), 1000001);
|
||||
/**
|
||||
* Disable Kadence's built-in Google Fonts.
|
||||
*/
|
||||
add_action('customize_controls_enqueue_scripts', fn() => $this->action_theme_customizer_google_fonts(), 1000001);
|
||||
add_action('customize_preview_init', fn() => $this->action_theme_customizer_preview(), 1000001);
|
||||
add_action('enqueue_block_editor_assets', fn() => $this->block_editor_remove_google_fonts(), 1000001);
|
||||
}
|
||||
public function get_name(): string
|
||||
{
|
||||
return 'kadence';
|
||||
}
|
||||
public function action_theme_customizer_google_fonts()
|
||||
{
|
||||
if (wp_script_is('kadence-customizer-controls', 'registered')) {
|
||||
wp_add_inline_script('kadence-customizer-controls', 'kadenceCustomizerControlsData.gfontvars = [];', 'before');
|
||||
}
|
||||
}
|
||||
public function action_theme_customizer_preview()
|
||||
{
|
||||
if (wp_script_is('kadence-webfont-js', 'registered')) {
|
||||
wp_dequeue_script('kadence-webfont-js');
|
||||
}
|
||||
}
|
||||
public function block_editor_remove_google_fonts()
|
||||
{
|
||||
if (wp_script_is('kadence-blocks-js', 'registered')) {
|
||||
wp_add_inline_script('kadence-blocks-js', 'kadence_blocks_params.g_fonts = [];', 'before');
|
||||
wp_add_inline_script('kadence-blocks-js', 'kadence_blocks_params.g_font_names = [];', 'before');
|
||||
}
|
||||
}
|
||||
public function register_block_editor_assets()
|
||||
{
|
||||
if (wp_script_is('kadence-blocks-js', 'registered')) {
|
||||
$jooosi_fonts = [];
|
||||
$fonts = Font::get_fonts();
|
||||
foreach ($fonts as $font) {
|
||||
$jooosi_fonts[] = ['label' => $font['title'], 'value' => $font['family'], 'google' => \false, 'weights' => [['value' => '100', 'label' => 'Thin 100'], ['value' => '200', 'label' => 'Extra-Light 200'], ['value' => '300', 'label' => 'Light 300'], ['value' => '400', 'label' => 'Regular'], ['value' => '500', 'label' => 'Medium 500'], ['value' => '600', 'label' => 'Semi-Bold 600'], ['value' => '700', 'label' => 'Bold 700'], ['value' => '800', 'label' => 'Extra-Bold 800'], ['value' => '900', 'label' => 'Ultra-Bold 900']], 'styles' => [['value' => 'normal', 'label' => 'Normal'], ['value' => 'italic', 'label' => 'Italic']]];
|
||||
}
|
||||
wp_enqueue_script('jooosi-fon-for-kadence-blocks', plugin_dir_url(__FILE__) . 'assets/script/kadence-blocks.js', ['kadence-blocks-js'], JOOOSI_FON::VERSION, \true);
|
||||
wp_localize_script('jooosi-fon-for-kadence-blocks', 'jooosiFonKadenceBlocks', ['fonts' => $jooosi_fonts]);
|
||||
}
|
||||
}
|
||||
public function theme_custom_fonts($kadence_fonts)
|
||||
{
|
||||
$fonts = Font::get_fonts();
|
||||
$v = ['100', '100italic', '200', '200italic', '300', '300italic', 'regular', 'italic', '500', '500italic', '600', '600italic', '700', '700italic', '800', '800italic', '900', '900italic'];
|
||||
foreach ($fonts as $font) {
|
||||
$kadence_fonts[$font['family']] = ['v' => $v];
|
||||
}
|
||||
return $kadence_fonts;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
function jooosi_fon_add_fonts(options) {
|
||||
const { __ } = wp.i18n;
|
||||
const jooosi_fonts = [
|
||||
{
|
||||
type: 'group',
|
||||
label: __('Jooosi Fon', 'jooosi-fon'),
|
||||
options: jooosiFonKadenceBlocks.fonts,
|
||||
},
|
||||
];
|
||||
|
||||
options = jooosi_fonts.concat(options);
|
||||
|
||||
return options;
|
||||
}
|
||||
wp.hooks.addFilter('kadence.typography_options', 'jooosi/fon/add_fonts', jooosi_fon_add_fonts);
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Jooosi Fon package.
|
||||
*
|
||||
* (c) Joshua Gugun Siagian <suabahasa@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
declare (strict_types=1);
|
||||
namespace JooosiFon\Builder\Pinegrow;
|
||||
|
||||
use JooosiFonDeps\JOOOSI_FON;
|
||||
use JooosiFon\Admin\AdminPage;
|
||||
use JooosiFon\Builder\BuilderInterface;
|
||||
use JooosiFon\Core\Cache;
|
||||
use JooosiFon\Utils\Font;
|
||||
/**
|
||||
* Pinegrow integration.
|
||||
*
|
||||
* @author Joshua Gugun Siagian <suabahasa@gmail.com>
|
||||
*/
|
||||
class Main implements BuilderInterface
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
add_action('admin_menu', static fn() => AdminPage::add_redirect_submenu_page('pinegrow-projects'), 1000001);
|
||||
add_action('load-toplevel_page_pinegrow-projects', fn() => $this->init_hooks());
|
||||
}
|
||||
public function get_name(): string
|
||||
{
|
||||
return 'pinegrow';
|
||||
}
|
||||
public function init_hooks(): void
|
||||
{
|
||||
add_action('admin_enqueue_scripts', fn() => $this->enqueue_scripts(), 1000001);
|
||||
}
|
||||
public function enqueue_scripts()
|
||||
{
|
||||
wp_enqueue_script('jooosi-fon-for-pinegrow', plugin_dir_url(__FILE__) . 'assets/script/pinegrow.js', [], JOOOSI_FON::VERSION, \true);
|
||||
wp_localize_script('jooosi-fon-for-pinegrow', 'jooosiFonPinegrow', ['stylesheet_url' => Cache::get_versioned_cache_url(Cache::CSS_CACHE_FILE), 'font_families' => array_map(static fn($f) => ['name' => $f['title'], 'key' => $f['css']['variable'], 'family' => $f['family']], Font::get_fonts())]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
document.addEventListener('DOMContentLoaded', async function () {
|
||||
await new Promise(resolve => {
|
||||
let waitingForEditor = setInterval(() => {
|
||||
|
||||
if (
|
||||
window.frames[0].pinegrow?.getSelectedPage() !== null
|
||||
&& window.frames[0].pinegrow?.getSelectedPage() !== undefined
|
||||
) {
|
||||
clearInterval(waitingForEditor);
|
||||
resolve();
|
||||
}
|
||||
}, 3000);
|
||||
});
|
||||
|
||||
// add stylesheet
|
||||
window.frames[0].pinegrow.getSelectedPage().addStylesheet(window.jooosiFonPinegrow.stylesheet_url);
|
||||
|
||||
// style tab
|
||||
await new Promise(resolve => {
|
||||
let waitingForFontFamily = setInterval(() => {
|
||||
try {
|
||||
if (
|
||||
window.frames[0].$.fn.crsa.defaults.rulesDefinition.sections.text.fields['font-family'] !== null
|
||||
&& window.frames[0].$.fn.crsa.defaults.rulesDefinition.sections.text.fields['font-family'] !== undefined
|
||||
) {
|
||||
clearInterval(waitingForFontFamily);
|
||||
resolve();
|
||||
}
|
||||
} catch (err) { }
|
||||
}, 100);
|
||||
});
|
||||
|
||||
window.frames[0].$.fn.crsa.defaults.rulesDefinition.sections.text.fields['font-family'].options = function () {
|
||||
return window.jooosiFonPinegrow.font_families || [];
|
||||
};
|
||||
|
||||
// design tab
|
||||
await new Promise(resolve => {
|
||||
let waitingForFontLibrary = setInterval(() => {
|
||||
try {
|
||||
if (
|
||||
window.frames[0].pinegrow.fontLibrary !== null
|
||||
&& window.frames[0].pinegrow.fontLibrary !== undefined
|
||||
) {
|
||||
clearInterval(waitingForFontLibrary);
|
||||
resolve();
|
||||
}
|
||||
} catch (err) { }
|
||||
}, 100);
|
||||
});
|
||||
|
||||
const preservedSystemFonts = [];
|
||||
|
||||
window.frames[0].pinegrow.fontLibrary.forEachFont(font => {
|
||||
if (font.type === 'system') {
|
||||
preservedSystemFonts.push(font);
|
||||
}
|
||||
});
|
||||
|
||||
const fontSystemClass = window.frames[0].pinegrow.fontLibrary.getFontClassForType('system');
|
||||
|
||||
window.frames[0].pinegrow.fontLibrary.removeAll();
|
||||
|
||||
window.jooosiFonPinegrow.font_families.forEach(font => {
|
||||
const pfs = new fontSystemClass({
|
||||
type: 'system',
|
||||
family: font.family,
|
||||
usage: 'all',
|
||||
category: 'sans-serif',
|
||||
w: '100, 200, 300, 400, 500, 600, 700, 800, 900'.split(/,\s?/)
|
||||
});
|
||||
|
||||
window.frames[0].pinegrow.fontLibrary.addFont(pfs);
|
||||
});
|
||||
|
||||
preservedSystemFonts.forEach(font => {
|
||||
window.frames[0].pinegrow.fontLibrary.addFont(font);
|
||||
});
|
||||
|
||||
window.frames[0].pinegrow.fontLibrary.save();
|
||||
});
|
||||
Reference in New Issue
Block a user