Version Description
Cleared up instructions in Welcome Panel. Added option to remove version parameter from stylesheet request.
Download this release
Release Info
Developer | DaanvandenBergh |
Plugin | OMGF | GDPR/DSVGO Compliant, Faster Google Fonts. Easy. |
Version | 1.7.9 |
Comparing to | |
See all releases |
Code changes from version 1.6.0 to 1.7.9
- css/hwl-admin.css +8 -1
- css/hwl-admin.min.css +1 -0
- host-webfonts-local.php +146 -56
- includes/ajax/download-fonts.php +25 -4
- includes/ajax/generate-stylesheet.php +3 -3
- includes/caos-webfonts-basic-settings.php +46 -8
- includes/caos-webfonts-style-generation.php +134 -100
- includes/welcome-panel.php +34 -22
- js/hwl-admin.js +207 -93
- readme.md +1 -1
- readme.txt +50 -7
css/hwl-admin.css
CHANGED
@@ -2,9 +2,16 @@
|
|
2 |
* @package: CAOS for Webfonts
|
3 |
* @author: Daan van den Bergh
|
4 |
* @copyright: (c) 2019 Daan van den Bergh
|
5 |
-
* @url: https://dev
|
6 |
*/
|
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
#hwl-results .spinner {
|
9 |
visibility: visible !important;
|
10 |
float: none;
|
2 |
* @package: CAOS for Webfonts
|
3 |
* @author: Daan van den Bergh
|
4 |
* @copyright: (c) 2019 Daan van den Bergh
|
5 |
+
* @url: https://daan.dev
|
6 |
*/
|
7 |
|
8 |
+
#search-field {
|
9 |
+
line-height: 38px;
|
10 |
+
width: 360px;
|
11 |
+
font-size: 20px;
|
12 |
+
padding: 3px 10px;
|
13 |
+
}
|
14 |
+
|
15 |
#hwl-results .spinner {
|
16 |
visibility: visible !important;
|
17 |
float: none;
|
css/hwl-admin.min.css
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
#search-field{line-height:38px;width:360px;font-size:20px;padding:3px 10px}#hwl-results .spinner{visibility:visible !important;float:none}#hwl-results{position:relative}tr.loading td{position:absolute;width:100%;height:100%;left:0;right:0;text-align:center;background-color:rgba(255,255,255,0.5)}.hwl-remove{cursor:pointer}.button-cancel{color:#a00;text-decoration:none;border-color:transparent;box-shadow:none;background:0;border-radius:3px;white-space:nowrap;padding:6px 10px !important}.button-cancel:hover{cursor:pointer;background:#d54e21;color:#fff;border-color:#d54e21}.caos-status-total-bar{height:30px;border-radius:6px;padding:4px 4px 0;background:rgba(0,0,0,0.25);box-shadow:inset 0 1px 2px rgba(0,0,0,0.25),0 1px rgba(255,255,255,0.08)}#caos-status-progress-bar{height:26px;color:#fff;border-radius:4px;white-space:nowrap;line-height:25px;text-align:center;transition:width 1s;-webkit-transition:width 1s;background-color:#0daadb;background-image:linear-gradient(to bottom,rgba(255,255,255,0.3),rgba(255,255,255,0.05));box-shadow:0 0 1px 1px rgba(0,0,0,0.25),inset 0 1px rgba(255,255,255,0.1)}
|
host-webfonts-local.php
CHANGED
@@ -1,13 +1,14 @@
|
|
1 |
<?php
|
2 |
/**
|
|
|
3 |
* Plugin Name: CAOS for Webfonts
|
4 |
-
* Plugin URI: https://dev
|
5 |
-
* Description: Automagically save the fonts you want to use inside your content-folder, generate a
|
6 |
-
*
|
7 |
-
* Version: 1.6.0
|
8 |
* Author: Daan van den Bergh
|
9 |
-
* Author URI: https://dev
|
10 |
* License: GPL2v2 or later
|
|
|
11 |
*/
|
12 |
|
13 |
// Exit if accessed directly
|
@@ -20,15 +21,19 @@ global $wpdb;
|
|
20 |
/**
|
21 |
* Define constants.
|
22 |
*/
|
23 |
-
define('CAOS_WEBFONTS_DB_VERSION', '1.
|
24 |
-
define('CAOS_WEBFONTS_STATIC_VERSION', '1.
|
|
|
25 |
define('CAOS_WEBFONTS_DB_TABLENAME', $wpdb->prefix . 'caos_webfonts');
|
26 |
define('CAOS_WEBFONTS_DB_CHARSET', $wpdb->get_charset_collate());
|
|
|
27 |
define('CAOS_WEBFONTS_FILENAME', 'fonts.css');
|
28 |
define('CAOS_WEBFONTS_CACHE_DIR', esc_attr(get_option('caos_webfonts_cache_dir')) ?: '/cache/caos-webfonts');
|
|
|
|
|
29 |
define('CAOS_WEBFONTS_CURRENT_BLOG_ID', get_current_blog_id());
|
30 |
define('CAOS_WEBFONTS_UPLOAD_DIR', WP_CONTENT_DIR . CAOS_WEBFONTS_CACHE_DIR);
|
31 |
-
define('CAOS_WEBFONTS_UPLOAD_URL',
|
32 |
define('CAOS_WEBFONTS_DISPLAY_OPTION', esc_attr(get_option('caos_webfonts_display_option')) ?: 'auto');
|
33 |
define('CAOS_WEBFONTS_PRELOAD', esc_attr(get_option('caos_webfonts_preload')));
|
34 |
|
@@ -39,12 +44,18 @@ function hwlRegisterSettings() {
|
|
39 |
register_setting('caos-webfonts-basic-settings',
|
40 |
'caos_webfonts_cache_dir'
|
41 |
);
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
register_setting('caos-webfonts-basic-settings',
|
43 |
'caos_webfonts_display_option'
|
44 |
);
|
45 |
register_setting('caos-webfonts-basic-settings',
|
46 |
-
|
47 |
-
|
48 |
}
|
49 |
|
50 |
/**
|
@@ -71,15 +82,29 @@ add_action('admin_menu', 'hwlCreateMenu');
|
|
71 |
*/
|
72 |
function hwlGetContentDirName() {
|
73 |
preg_match('/[^\/]+$/u', WP_CONTENT_DIR, $match);
|
74 |
-
|
75 |
return $match[0];
|
76 |
}
|
77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
/**
|
79 |
* Create table to store downloaded fonts in.
|
80 |
*/
|
81 |
-
function
|
82 |
-
$
|
|
|
83 |
font_id varchar(191) NOT NULL,
|
84 |
font_family varchar(191) NOT NULL,
|
85 |
font_weight mediumint(5) NOT NULL,
|
@@ -91,23 +116,39 @@ function hwlCreateTable() {
|
|
91 |
url_eot varchar(191) NULL,
|
92 |
UNIQUE KEY (font_id)
|
93 |
) " . CAOS_WEBFONTS_DB_CHARSET . ";";
|
|
|
|
|
|
|
|
|
94 |
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
}
|
100 |
|
101 |
/**
|
102 |
* Check current version and execute required db updates.
|
103 |
*/
|
104 |
function hwlRunDbUpdates() {
|
105 |
-
$currentVersion = get_site_option('caos_webfonts_db_version');
|
106 |
-
if (version_compare($currentVersion,
|
107 |
-
|
108 |
}
|
109 |
-
|
110 |
-
|
|
|
111 |
}
|
112 |
add_action('plugins_loaded', 'hwlRunDbUpdates');
|
113 |
|
@@ -120,7 +161,7 @@ function hwlSettingsLink($links) {
|
|
120 |
$adminUrl = admin_url() . 'options-general.php?page=optimize-webfonts';
|
121 |
$settingsLink = "<a href='$adminUrl'>" . __('Settings') . "</a>";
|
122 |
array_push($links, $settingsLink);
|
123 |
-
|
124 |
return $links;
|
125 |
}
|
126 |
$caosLink = plugin_basename(__FILE__);
|
@@ -139,21 +180,20 @@ function hwlSettingsPage() {
|
|
139 |
<h1><?php _e('CAOS for Webfonts', 'host-webfonts-local'); ?></h1>
|
140 |
<p>
|
141 |
<?php _e('Developed by: ', 'host-webfonts-local'); ?>
|
142 |
-
<a title="Buy me a beer!" href="
|
143 |
Daan van den Bergh</a>.
|
144 |
</p>
|
145 |
|
146 |
<div id="hwl-admin-notices"></div>
|
147 |
-
|
148 |
<?php require_once(plugin_dir_path(__FILE__) . 'includes/welcome-panel.php'); ?>
|
149 |
|
150 |
-
<form id="hwl-options-form" name="hwl-options-form" method="post"
|
151 |
<div class="">
|
152 |
-
<h3><?php _e('Generate Stylesheet'); ?></h3>
|
153 |
<?php
|
154 |
-
|
155 |
include(plugin_dir_path(__FILE__) . 'includes/caos-webfonts-style-generation.php');
|
156 |
-
|
157 |
?>
|
158 |
</div>
|
159 |
</form>
|
@@ -162,13 +202,13 @@ function hwlSettingsPage() {
|
|
162 |
<?php
|
163 |
settings_fields('caos-webfonts-basic-settings');
|
164 |
do_settings_sections('caos-webfonts-basic-settings');
|
165 |
-
|
166 |
include(plugin_dir_path(__FILE__) . 'includes/caos-webfonts-basic-settings.php');
|
167 |
-
|
168 |
do_action('hwl_after_settings_form_settings');
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
</form>
|
173 |
</div>
|
174 |
<?php
|
@@ -179,7 +219,7 @@ function hwlSettingsPage() {
|
|
179 |
*/
|
180 |
function hwlGetTotalFonts() {
|
181 |
global $wpdb;
|
182 |
-
|
183 |
try {
|
184 |
return $wpdb->get_results("SELECT * FROM " . CAOS_WEBFONTS_DB_TABLENAME);
|
185 |
} catch (\Exception $e) {
|
@@ -192,7 +232,7 @@ function hwlGetTotalFonts() {
|
|
192 |
*/
|
193 |
function hwlGetDownloadedFonts() {
|
194 |
global $wpdb;
|
195 |
-
|
196 |
try {
|
197 |
return $wpdb->get_results("SELECT * FROM " . CAOS_WEBFONTS_DB_TABLENAME . " WHERE downloaded = 1");
|
198 |
} catch (\Exception $e) {
|
@@ -210,14 +250,38 @@ function hwlGetDownloadStatus() {
|
|
210 |
);
|
211 |
}
|
212 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
213 |
/**
|
214 |
* @return \Exception|false|int
|
215 |
*/
|
216 |
function hwlCleanQueue() {
|
217 |
global $wpdb;
|
218 |
-
|
219 |
try {
|
220 |
-
|
|
|
221 |
} catch (\Exception $e) {
|
222 |
return $e;
|
223 |
}
|
@@ -253,6 +317,34 @@ function hwlAjaxEmptyDir() {
|
|
253 |
}
|
254 |
add_action('wp_ajax_hwlAjaxEmptyDir', 'hwlAjaxEmptyDir');
|
255 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
256 |
/**
|
257 |
* Search Fonts in Google Webfonts Helper
|
258 |
*/
|
@@ -260,12 +352,13 @@ function hwlAjaxSearchGoogleFonts() {
|
|
260 |
try {
|
261 |
$request = curl_init();
|
262 |
$searchQuery = sanitize_text_field($_POST['search_query']);
|
263 |
-
|
264 |
-
|
|
|
265 |
curl_setopt($request, CURLOPT_RETURNTRANSFER, 1);
|
266 |
-
|
267 |
$result = curl_exec($request);
|
268 |
-
|
269 |
curl_close($request);
|
270 |
wp_die($result);
|
271 |
} catch (\Exception $e) {
|
@@ -296,7 +389,7 @@ function hwlFontDisplayOptions() {
|
|
296 |
'Fallback' => 'fallback',
|
297 |
'Optional' => 'optional'
|
298 |
);
|
299 |
-
|
300 |
return $fontDisplay;
|
301 |
}
|
302 |
|
@@ -320,10 +413,7 @@ add_action('wp_ajax_hwlAjaxDownloadFonts', 'hwlAjaxDownloadFonts');
|
|
320 |
* Once the stylesheet is generated. We can enqueue it.
|
321 |
*/
|
322 |
function hwlEnqueueStylesheet() {
|
323 |
-
|
324 |
-
if (file_exists($stylesheet)) {
|
325 |
-
wp_enqueue_style('hwl-style', CAOS_WEBFONTS_UPLOAD_URL . '/' . CAOS_WEBFONTS_FILENAME, array(), CAOS_WEBFONTS_STATIC_VERSION);
|
326 |
-
}
|
327 |
}
|
328 |
add_action('wp_enqueue_scripts', 'hwlEnqueueStylesheet');
|
329 |
|
@@ -333,7 +423,7 @@ add_action('wp_enqueue_scripts', 'hwlEnqueueStylesheet');
|
|
333 |
function hwlEnqueueAdminJs($hook) {
|
334 |
if ($hook == 'settings_page_optimize-webfonts') {
|
335 |
wp_enqueue_script('hwl-admin-js', plugin_dir_url(__FILE__) . 'js/hwl-admin.js', array('jquery'), CAOS_WEBFONTS_STATIC_VERSION, true);
|
336 |
-
wp_enqueue_style('hwl-admin
|
337 |
}
|
338 |
}
|
339 |
add_action('admin_enqueue_scripts', 'hwlEnqueueAdminJs');
|
@@ -343,7 +433,7 @@ add_action('admin_enqueue_scripts', 'hwlEnqueueAdminJs');
|
|
343 |
*/
|
344 |
function hwlDequeueJsCss() {
|
345 |
wp_dequeue_script('hwl-admin-js');
|
346 |
-
wp_dequeue_style('hwl-admin
|
347 |
wp_dequeue_style('hwl-style');
|
348 |
}
|
349 |
register_deactivation_hook(__FILE__, 'hwlDequeueJsCss');
|
@@ -352,18 +442,18 @@ register_deactivation_hook(__FILE__, 'hwlDequeueJsCss');
|
|
352 |
* Prioritize the loading of fonts by adding a resource hint to the document head.
|
353 |
*/
|
354 |
function hwlAddLinkPreload() {
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
|
360 |
$source = $sstyle->src . ($sstyle->ver ? "?ver={$sstyle->ver}" : "");
|
361 |
echo "<link rel='preload' href='{$source}' as='style' />\n";
|
362 |
}
|
363 |
|
364 |
function hwlIsPreloadEnabled() {
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
}
|
369 |
add_action('init', 'hwlIsPreloadEnabled');
|
1 |
<?php
|
2 |
/**
|
3 |
+
* @formatter:off
|
4 |
* Plugin Name: CAOS for Webfonts
|
5 |
+
* Plugin URI: https://daan.dev/wordpress-plugins/host-google-fonts-locally
|
6 |
+
* Description: Automagically save the fonts you want to use inside your content-folder, generate a stylesheet for them and enqueue it in your theme's header.
|
7 |
+
* Version: 1.7.9
|
|
|
8 |
* Author: Daan van den Bergh
|
9 |
+
* Author URI: https://daan.dev
|
10 |
* License: GPL2v2 or later
|
11 |
+
* @formatter:on
|
12 |
*/
|
13 |
|
14 |
// Exit if accessed directly
|
21 |
/**
|
22 |
* Define constants.
|
23 |
*/
|
24 |
+
define('CAOS_WEBFONTS_DB_VERSION', '1.7.0');
|
25 |
+
define('CAOS_WEBFONTS_STATIC_VERSION', '1.7.6');
|
26 |
+
define('CAOS_WEBFONTS_SITE_URL', 'https://daan.dev');
|
27 |
define('CAOS_WEBFONTS_DB_TABLENAME', $wpdb->prefix . 'caos_webfonts');
|
28 |
define('CAOS_WEBFONTS_DB_CHARSET', $wpdb->get_charset_collate());
|
29 |
+
define('CAOS_WEBFONTS_HELPER_URL', 'https://google-webfonts-helper.herokuapp.com/api/fonts/');
|
30 |
define('CAOS_WEBFONTS_FILENAME', 'fonts.css');
|
31 |
define('CAOS_WEBFONTS_CACHE_DIR', esc_attr(get_option('caos_webfonts_cache_dir')) ?: '/cache/caos-webfonts');
|
32 |
+
define('CAOS_WEBFONTS_CDN_URL', esc_attr(get_option('caos_webfonts_cdn_url')));
|
33 |
+
define('CAOS_WEBFONTS_REMOVE_VERSION', esc_attr(get_option('caos_webfonts_remove_version')));
|
34 |
define('CAOS_WEBFONTS_CURRENT_BLOG_ID', get_current_blog_id());
|
35 |
define('CAOS_WEBFONTS_UPLOAD_DIR', WP_CONTENT_DIR . CAOS_WEBFONTS_CACHE_DIR);
|
36 |
+
define('CAOS_WEBFONTS_UPLOAD_URL', hwlGetUploadUrl());
|
37 |
define('CAOS_WEBFONTS_DISPLAY_OPTION', esc_attr(get_option('caos_webfonts_display_option')) ?: 'auto');
|
38 |
define('CAOS_WEBFONTS_PRELOAD', esc_attr(get_option('caos_webfonts_preload')));
|
39 |
|
44 |
register_setting('caos-webfonts-basic-settings',
|
45 |
'caos_webfonts_cache_dir'
|
46 |
);
|
47 |
+
register_setting('caos-webfonts-basic-settings',
|
48 |
+
'caos_webfonts_cdn_url'
|
49 |
+
);
|
50 |
+
register_setting('caos-webfonts-basic-settings',
|
51 |
+
'caos_webfonts_remove_version'
|
52 |
+
);
|
53 |
register_setting('caos-webfonts-basic-settings',
|
54 |
'caos_webfonts_display_option'
|
55 |
);
|
56 |
register_setting('caos-webfonts-basic-settings',
|
57 |
+
'caos_webfonts_preload'
|
58 |
+
);
|
59 |
}
|
60 |
|
61 |
/**
|
82 |
*/
|
83 |
function hwlGetContentDirName() {
|
84 |
preg_match('/[^\/]+$/u', WP_CONTENT_DIR, $match);
|
85 |
+
|
86 |
return $match[0];
|
87 |
}
|
88 |
|
89 |
+
/**
|
90 |
+
* @return string
|
91 |
+
*/
|
92 |
+
function hwlGetUploadUrl() {
|
93 |
+
if (CAOS_WEBFONTS_CDN_URL) {
|
94 |
+
$uploadUrl = '//' . CAOS_WEBFONTS_CDN_URL . '/' . hwlGetContentDirName() . CAOS_WEBFONTS_CACHE_DIR;
|
95 |
+
} else {
|
96 |
+
$uploadUrl = get_site_url(CAOS_WEBFONTS_CURRENT_BLOG_ID, hwlGetContentDirName() . CAOS_WEBFONTS_CACHE_DIR);
|
97 |
+
}
|
98 |
+
|
99 |
+
return $uploadUrl;
|
100 |
+
}
|
101 |
+
|
102 |
/**
|
103 |
* Create table to store downloaded fonts in.
|
104 |
*/
|
105 |
+
function hwlCreateWebfontsTable() {
|
106 |
+
global $wpdb;
|
107 |
+
$sql = "CREATE TABLE IF NOT EXISTS " . CAOS_WEBFONTS_DB_TABLENAME . " (
|
108 |
font_id varchar(191) NOT NULL,
|
109 |
font_family varchar(191) NOT NULL,
|
110 |
font_weight mediumint(5) NOT NULL,
|
116 |
url_eot varchar(191) NULL,
|
117 |
UNIQUE KEY (font_id)
|
118 |
) " . CAOS_WEBFONTS_DB_CHARSET . ";";
|
119 |
+
$wpdb->query($sql);
|
120 |
+
|
121 |
+
add_option('caos_webfonts_db_version', '1.6.1');
|
122 |
+
}
|
123 |
|
124 |
+
/**
|
125 |
+
* Create table to store selected subsets in.
|
126 |
+
*/
|
127 |
+
function hwlCreateSubsetsTable() {
|
128 |
+
global $wpdb;
|
129 |
+
$sql = "CREATE TABLE IF NOT EXISTS " . CAOS_WEBFONTS_DB_TABLENAME . '_subsets' . " (
|
130 |
+
subset_font varchar(32) NOT NULL,
|
131 |
+
subset_family varchar(191) NOT NULL,
|
132 |
+
available_subsets varchar(191) NOT NULL,
|
133 |
+
selected_subsets varchar(191) NOT NULL,
|
134 |
+
UNIQUE KEY (subset_font)
|
135 |
+
) " . CAOS_WEBFONTS_DB_CHARSET . ";";
|
136 |
+
$wpdb->query($sql);
|
137 |
+
|
138 |
+
update_option('caos_webfonts_db_version', '1.7.0');
|
139 |
}
|
140 |
|
141 |
/**
|
142 |
* Check current version and execute required db updates.
|
143 |
*/
|
144 |
function hwlRunDbUpdates() {
|
145 |
+
$currentVersion = get_site_option('caos_webfonts_db_version') ?: '1.0.0';
|
146 |
+
if (version_compare($currentVersion, '1.6.1') < 0) {
|
147 |
+
hwlCreateWebfontsTable();
|
148 |
}
|
149 |
+
if (version_compare($currentVersion, CAOS_WEBFONTS_DB_VERSION) < 0) {
|
150 |
+
hwlCreateSubsetsTable();
|
151 |
+
}
|
152 |
}
|
153 |
add_action('plugins_loaded', 'hwlRunDbUpdates');
|
154 |
|
161 |
$adminUrl = admin_url() . 'options-general.php?page=optimize-webfonts';
|
162 |
$settingsLink = "<a href='$adminUrl'>" . __('Settings') . "</a>";
|
163 |
array_push($links, $settingsLink);
|
164 |
+
|
165 |
return $links;
|
166 |
}
|
167 |
$caosLink = plugin_basename(__FILE__);
|
180 |
<h1><?php _e('CAOS for Webfonts', 'host-webfonts-local'); ?></h1>
|
181 |
<p>
|
182 |
<?php _e('Developed by: ', 'host-webfonts-local'); ?>
|
183 |
+
<a title="Buy me a beer!" href="<?php echo CAOS_WEBFONTS_SITE_URL; ?>/donate/">
|
184 |
Daan van den Bergh</a>.
|
185 |
</p>
|
186 |
|
187 |
<div id="hwl-admin-notices"></div>
|
188 |
+
|
189 |
<?php require_once(plugin_dir_path(__FILE__) . 'includes/welcome-panel.php'); ?>
|
190 |
|
191 |
+
<form id="hwl-options-form" name="hwl-options-form" method="post" style="float: left; width: 60%;">
|
192 |
<div class="">
|
|
|
193 |
<?php
|
194 |
+
|
195 |
include(plugin_dir_path(__FILE__) . 'includes/caos-webfonts-style-generation.php');
|
196 |
+
|
197 |
?>
|
198 |
</div>
|
199 |
</form>
|
202 |
<?php
|
203 |
settings_fields('caos-webfonts-basic-settings');
|
204 |
do_settings_sections('caos-webfonts-basic-settings');
|
205 |
+
|
206 |
include(plugin_dir_path(__FILE__) . 'includes/caos-webfonts-basic-settings.php');
|
207 |
+
|
208 |
do_action('hwl_after_settings_form_settings');
|
209 |
+
|
210 |
+
submit_button();
|
211 |
+
?>
|
212 |
</form>
|
213 |
</div>
|
214 |
<?php
|
219 |
*/
|
220 |
function hwlGetTotalFonts() {
|
221 |
global $wpdb;
|
222 |
+
|
223 |
try {
|
224 |
return $wpdb->get_results("SELECT * FROM " . CAOS_WEBFONTS_DB_TABLENAME);
|
225 |
} catch (\Exception $e) {
|
232 |
*/
|
233 |
function hwlGetDownloadedFonts() {
|
234 |
global $wpdb;
|
235 |
+
|
236 |
try {
|
237 |
return $wpdb->get_results("SELECT * FROM " . CAOS_WEBFONTS_DB_TABLENAME . " WHERE downloaded = 1");
|
238 |
} catch (\Exception $e) {
|
250 |
);
|
251 |
}
|
252 |
|
253 |
+
/**
|
254 |
+
* @return array|\Exception|null|object
|
255 |
+
*/
|
256 |
+
function hwlGetSubsets() {
|
257 |
+
global $wpdb;
|
258 |
+
|
259 |
+
try {
|
260 |
+
return $wpdb->get_results("SELECT * FROM " . CAOS_WEBFONTS_DB_TABLENAME . "_subsets");
|
261 |
+
} catch(\Exception $e) {
|
262 |
+
return $e;
|
263 |
+
}
|
264 |
+
}
|
265 |
+
|
266 |
+
function hwlGetFontsByFamily($family) {
|
267 |
+
global $wpdb;
|
268 |
+
|
269 |
+
try {
|
270 |
+
return $wpdb->get_results("SELECT * FROM " . CAOS_WEBFONTS_DB_TABLENAME . " WHERE font_family = '$family'");
|
271 |
+
} catch(\Exception $e) {
|
272 |
+
return $e;
|
273 |
+
}
|
274 |
+
}
|
275 |
+
|
276 |
/**
|
277 |
* @return \Exception|false|int
|
278 |
*/
|
279 |
function hwlCleanQueue() {
|
280 |
global $wpdb;
|
281 |
+
|
282 |
try {
|
283 |
+
$wpdb->query("TRUNCATE TABLE " . CAOS_WEBFONTS_DB_TABLENAME);
|
284 |
+
$wpdb->query("TRUNCATE TABLE " . CAOS_WEBFONTS_DB_TABLENAME . "_subsets");
|
285 |
} catch (\Exception $e) {
|
286 |
return $e;
|
287 |
}
|
317 |
}
|
318 |
add_action('wp_ajax_hwlAjaxEmptyDir', 'hwlAjaxEmptyDir');
|
319 |
|
320 |
+
/**
|
321 |
+
* Search Subsets in Google Webfonts Helper
|
322 |
+
*/
|
323 |
+
function hwlAjaxSearchFontSubsets() {
|
324 |
+
try {
|
325 |
+
$searchQueries = explode(',', sanitize_text_field($_POST['search_query']));
|
326 |
+
|
327 |
+
foreach ($searchQueries as $searchQuery) {
|
328 |
+
$request = curl_init();
|
329 |
+
curl_setopt($request, CURLOPT_URL, CAOS_WEBFONTS_HELPER_URL . $searchQuery);
|
330 |
+
curl_setopt($request, CURLOPT_RETURNTRANSFER, 1);
|
331 |
+
$result = curl_exec($request);
|
332 |
+
curl_close($request);
|
333 |
+
|
334 |
+
$result = json_decode($result);
|
335 |
+
$response[] = array(
|
336 |
+
'family' => $result->family,
|
337 |
+
'id' => $result->id,
|
338 |
+
'subsets' => $result->subsets
|
339 |
+
);
|
340 |
+
}
|
341 |
+
wp_die(json_encode($response));
|
342 |
+
} catch (\Exception $e) {
|
343 |
+
wp_die($e);
|
344 |
+
}
|
345 |
+
}
|
346 |
+
add_action('wp_ajax_hwlAjaxSearchFontSubsets', 'hwlAjaxSearchFontSubsets');
|
347 |
+
|
348 |
/**
|
349 |
* Search Fonts in Google Webfonts Helper
|
350 |
*/
|
352 |
try {
|
353 |
$request = curl_init();
|
354 |
$searchQuery = sanitize_text_field($_POST['search_query']);
|
355 |
+
$subsets = implode($_POST['search_subsets'], ',');
|
356 |
+
|
357 |
+
curl_setopt($request, CURLOPT_URL, CAOS_WEBFONTS_HELPER_URL . $searchQuery . '?subsets=' . $subsets);
|
358 |
curl_setopt($request, CURLOPT_RETURNTRANSFER, 1);
|
359 |
+
|
360 |
$result = curl_exec($request);
|
361 |
+
|
362 |
curl_close($request);
|
363 |
wp_die($result);
|
364 |
} catch (\Exception $e) {
|
389 |
'Fallback' => 'fallback',
|
390 |
'Optional' => 'optional'
|
391 |
);
|
392 |
+
|
393 |
return $fontDisplay;
|
394 |
}
|
395 |
|
413 |
* Once the stylesheet is generated. We can enqueue it.
|
414 |
*/
|
415 |
function hwlEnqueueStylesheet() {
|
416 |
+
wp_enqueue_style('hwl-style', CAOS_WEBFONTS_UPLOAD_URL . '/' . CAOS_WEBFONTS_FILENAME, array(), (CAOS_WEBFONTS_REMOVE_VERSION) ? null : CAOS_WEBFONTS_STATIC_VERSION);
|
|
|
|
|
|
|
417 |
}
|
418 |
add_action('wp_enqueue_scripts', 'hwlEnqueueStylesheet');
|
419 |
|
423 |
function hwlEnqueueAdminJs($hook) {
|
424 |
if ($hook == 'settings_page_optimize-webfonts') {
|
425 |
wp_enqueue_script('hwl-admin-js', plugin_dir_url(__FILE__) . 'js/hwl-admin.js', array('jquery'), CAOS_WEBFONTS_STATIC_VERSION, true);
|
426 |
+
wp_enqueue_style('hwl-admin-css', plugin_dir_url(__FILE__) . 'css/hwl-admin.css', array(), CAOS_WEBFONTS_STATIC_VERSION);
|
427 |
}
|
428 |
}
|
429 |
add_action('admin_enqueue_scripts', 'hwlEnqueueAdminJs');
|
433 |
*/
|
434 |
function hwlDequeueJsCss() {
|
435 |
wp_dequeue_script('hwl-admin-js');
|
436 |
+
wp_dequeue_style('hwl-admin-css');
|
437 |
wp_dequeue_style('hwl-style');
|
438 |
}
|
439 |
register_deactivation_hook(__FILE__, 'hwlDequeueJsCss');
|
442 |
* Prioritize the loading of fonts by adding a resource hint to the document head.
|
443 |
*/
|
444 |
function hwlAddLinkPreload() {
|
445 |
+
global $wp_styles;
|
446 |
+
|
447 |
+
$handle = 'hwl-style';
|
448 |
+
$sstyle = $wp_styles->registered[$handle];
|
449 |
|
450 |
$source = $sstyle->src . ($sstyle->ver ? "?ver={$sstyle->ver}" : "");
|
451 |
echo "<link rel='preload' href='{$source}' as='style' />\n";
|
452 |
}
|
453 |
|
454 |
function hwlIsPreloadEnabled() {
|
455 |
+
if (CAOS_WEBFONTS_PRELOAD == 'on') {
|
456 |
+
add_action('wp_head', 'hwlAddLinkPreload', 1);
|
457 |
+
}
|
458 |
}
|
459 |
add_action('init', 'hwlIsPreloadEnabled');
|
includes/ajax/download-fonts.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
* @package: CAOS for Webfonts
|
4 |
* @author: Daan van den Bergh
|
5 |
* @copyright: (c) 2019 Daan van den Bergh
|
6 |
-
* @url: https://dev
|
7 |
*/
|
8 |
|
9 |
// Exit if accessed directly
|
@@ -39,13 +39,34 @@ try {
|
|
39 |
/**
|
40 |
* Get the POST data.
|
41 |
*/
|
42 |
-
$selectedFonts = $_POST['
|
|
|
43 |
|
44 |
-
if (!$selectedFonts)
|
45 |
{
|
46 |
-
wp_die(__('No fonts
|
47 |
}
|
48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
/**
|
50 |
* Save used fonts to database.
|
51 |
*/
|
3 |
* @package: CAOS for Webfonts
|
4 |
* @author: Daan van den Bergh
|
5 |
* @copyright: (c) 2019 Daan van den Bergh
|
6 |
+
* @url: https://daan.dev
|
7 |
*/
|
8 |
|
9 |
// Exit if accessed directly
|
39 |
/**
|
40 |
* Get the POST data.
|
41 |
*/
|
42 |
+
$selectedFonts = $_POST['fonts'][0]['caos_webfonts_array'];
|
43 |
+
$subsets = $_POST['subsets'];
|
44 |
|
45 |
+
if (!$selectedFonts || !$subsets)
|
46 |
{
|
47 |
+
wp_die(__('No fonts or subsets selected.', CAOS_ANALYTICS_TRANSLATE_DOMAIN));
|
48 |
}
|
49 |
|
50 |
+
/**
|
51 |
+
* Save used subsets to database for each font.
|
52 |
+
*/
|
53 |
+
foreach ($subsets as $id => $subset)
|
54 |
+
{
|
55 |
+
$availableSubsets = implode($subset['available'], ',');
|
56 |
+
$selectedSubsets = implode($subset['selected'], ',');
|
57 |
+
|
58 |
+
$wpdb->insert(
|
59 |
+
CAOS_WEBFONTS_DB_TABLENAME . '_subsets',
|
60 |
+
array(
|
61 |
+
'subset_font' => $id,
|
62 |
+
'subset_family' => $subset['family'],
|
63 |
+
'available_subsets' => $availableSubsets,
|
64 |
+
'selected_subsets' => $selectedSubsets,
|
65 |
+
)
|
66 |
+
);
|
67 |
+
}
|
68 |
+
|
69 |
+
|
70 |
/**
|
71 |
* Save used fonts to database.
|
72 |
*/
|
includes/ajax/generate-stylesheet.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
* @package: CAOS for Webfonts
|
4 |
* @author: Daan van den Bergh
|
5 |
* @copyright: (c) 2019 Daan van den Bergh
|
6 |
-
* @url: https://dev
|
7 |
*/
|
8 |
|
9 |
// Exit if accessed directly
|
@@ -27,10 +27,10 @@ if (!current_user_can('manage_options'))
|
|
27 |
*/
|
28 |
$fonts[] = "
|
29 |
/** This file is automagically generated by CAOS for Webfonts
|
30 |
-
*
|
31 |
* @author: Daan van den Bergh
|
32 |
* @copyright: (c) 2019 Daan van den Bergh
|
33 |
-
* @url:
|
34 |
*/";
|
35 |
$fontDisplay = CAOS_WEBFONTS_DISPLAY_OPTION;
|
36 |
|
3 |
* @package: CAOS for Webfonts
|
4 |
* @author: Daan van den Bergh
|
5 |
* @copyright: (c) 2019 Daan van den Bergh
|
6 |
+
* @url: https://daan.dev
|
7 |
*/
|
8 |
|
9 |
// Exit if accessed directly
|
27 |
*/
|
28 |
$fonts[] = "
|
29 |
/** This file is automagically generated by CAOS for Webfonts
|
30 |
+
*
|
31 |
* @author: Daan van den Bergh
|
32 |
* @copyright: (c) 2019 Daan van den Bergh
|
33 |
+
* @url: " . CAOS_WEBFONTS_SITE_URL . "
|
34 |
*/";
|
35 |
$fontDisplay = CAOS_WEBFONTS_DISPLAY_OPTION;
|
36 |
|
includes/caos-webfonts-basic-settings.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
* @package: CAOS for Webfonts
|
4 |
* @author: Daan van den Bergh
|
5 |
* @copyright: (c) 2019 Daan van den Bergh
|
6 |
-
* @url: https://dev
|
7 |
*/
|
8 |
|
9 |
// Exit if accessed directly
|
@@ -11,23 +11,61 @@ if (!defined( 'ABSPATH')) exit;
|
|
11 |
?>
|
12 |
<div class="">
|
13 |
<h3><?php _e('Basic Settings'); ?></h3>
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
<table class="form-table">
|
15 |
<tr valign="top">
|
16 |
<th scope="row">
|
17 |
-
<label
|
|
|
|
|
18 |
</th>
|
19 |
<td>
|
20 |
-
<input class="caos_webfonts_cache_dir" type="text" name="caos_webfonts_cache_dir" placeholder="e.g. /cache/caos-webfonts" value="<?php echo CAOS_WEBFONTS_CACHE_DIR; ?>" />
|
21 |
<p class="description">
|
22 |
-
<?php _e("Changes the path where webfonts are cached inside WordPress' content directory (usually <code>wp-content</code>). Defaults to <code>/cache/caos-webfonts</code
|
23 |
</p>
|
24 |
</td>
|
25 |
</tr>
|
26 |
<tr valign="top">
|
27 |
-
<th scope="row"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
<td>
|
29 |
<?php $fontDisplay = hwlFontDisplayOptions(); ?>
|
30 |
-
<select name="caos_webfonts_display_option">
|
31 |
<?php foreach ($fontDisplay as $label => $value): ?>
|
32 |
<option value="<?php echo $value; ?>" <?php echo $value == CAOS_WEBFONTS_DISPLAY_OPTION ? 'selected' : ''; ?>><?php _e($label, 'host-webfonts-local'); ?></option>
|
33 |
<?php endforeach; ?>
|
@@ -41,12 +79,12 @@ if (!defined( 'ABSPATH')) exit;
|
|
41 |
</tr>
|
42 |
<tr valign="top">
|
43 |
<th scope="row">
|
44 |
-
<label>
|
45 |
<?php _e('Enable preload for stylesheet (experimental)', 'host-webfonts-local'); ?>
|
46 |
</label>
|
47 |
</th>
|
48 |
<td>
|
49 |
-
<input class="caos_webfonts_preload" type="checkbox" name="caos_webfonts_preload" <?php echo CAOS_WEBFONTS_PRELOAD == 'on' ? 'checked = "checked"' : ''; ?> />
|
50 |
<p class="description">
|
51 |
<?php _e('If you\'re using a plugin (such as Autoptimize) to load stylesheets in the footer, enable this to preload the fonts.', 'host-webfonts-local'); ?> <a target="_blank" href="https://developers.google.com/web/fundamentals/performance/resource-prioritization#preload"><?php _e('Read more', 'host-webfonts-local'); ?></a>
|
52 |
</p>
|
3 |
* @package: CAOS for Webfonts
|
4 |
* @author: Daan van den Bergh
|
5 |
* @copyright: (c) 2019 Daan van den Bergh
|
6 |
+
* @url: https://daan.dev
|
7 |
*/
|
8 |
|
9 |
// Exit if accessed directly
|
11 |
?>
|
12 |
<div class="">
|
13 |
<h3><?php _e('Basic Settings'); ?></h3>
|
14 |
+
<p class="description">
|
15 |
+
<?php _e('Do not forget to re-generate the stylesheet after changing settings.', 'host-webfonts-local'); ?>
|
16 |
+
</p>
|
17 |
+
<p class="description">
|
18 |
+
<?php _e('* Empty Cache Directory, Download Fonts and Generate Stylesheet after changing this setting.', 'host-webfonts-local'); ?>
|
19 |
+
</p>
|
20 |
<table class="form-table">
|
21 |
<tr valign="top">
|
22 |
<th scope="row">
|
23 |
+
<label for="caos_webfonts_cache_dir">
|
24 |
+
<?php _e('Save webfonts to...', 'host-webfonts-local'); ?>
|
25 |
+
</label>
|
26 |
</th>
|
27 |
<td>
|
28 |
+
<input id="caos_webfonts_cache_dir" class="caos_webfonts_cache_dir" type="text" name="caos_webfonts_cache_dir" placeholder="e.g. /cache/caos-webfonts" value="<?php echo CAOS_WEBFONTS_CACHE_DIR; ?>" />
|
29 |
<p class="description">
|
30 |
+
<?php _e("Changes the path where webfonts are cached inside WordPress' content directory (usually <code>wp-content</code>). Defaults to <code>/cache/caos-webfonts</code>.*", 'host-webfonts-local'); ?>
|
31 |
</p>
|
32 |
</td>
|
33 |
</tr>
|
34 |
<tr valign="top">
|
35 |
+
<th scope="row">
|
36 |
+
<label for="caos_webfonts_cdn_url">
|
37 |
+
<?php _e('Serve fonts from CDN', 'host-webfonts-local'); ?>
|
38 |
+
</label>
|
39 |
+
</th>
|
40 |
+
<td>
|
41 |
+
<input id="caos_webfonts_cdn_url" class="caos_webfonts_cdn_url" type="text" name="caos_webfonts_cdn_url" placeholder="e.g. cdn.mydomain.com" value="<?= CAOS_WEBFONTS_CDN_URL; ?>" />
|
42 |
+
<p class="description">
|
43 |
+
<?php _e("Are you using a CDN? Then enter the URL here.*", 'host-webfonts-local'); ?>
|
44 |
+
</p>
|
45 |
+
</td>
|
46 |
+
</tr>
|
47 |
+
<tr valign="top">
|
48 |
+
<th scope="row">
|
49 |
+
<label for="caos_webfonts_remove_version">
|
50 |
+
<?php _e('Remove version parameter?', 'host-webfonts-local'); ?>
|
51 |
+
</label>
|
52 |
+
</th>
|
53 |
+
<td>
|
54 |
+
<input id="caos_webfonts_remove_version" class="caos_webfonts_remove_version" type="checkbox" name="caos_webfonts_remove_version" <?= CAOS_WEBFONTS_REMOVE_VERSION ? "checked = 'checked'" : ""; ?> />
|
55 |
+
<p class="description">
|
56 |
+
<?php _e('This removes the <code>?ver=x.x.x</code> parameter from the Stylesheet\'s (<code>fonts.css</code>) request.', 'host-webfonts-local'); ?>
|
57 |
+
</p>
|
58 |
+
</td>
|
59 |
+
</tr>
|
60 |
+
<tr valign="top">
|
61 |
+
<th scope="row">
|
62 |
+
<label for="caos_webfonts_display_option">
|
63 |
+
<?php _e('Font-display option', 'host-webfonts-local'); ?>
|
64 |
+
</label>
|
65 |
+
</th>
|
66 |
<td>
|
67 |
<?php $fontDisplay = hwlFontDisplayOptions(); ?>
|
68 |
+
<select id="caos_webfonts_display_option" name="caos_webfonts_display_option">
|
69 |
<?php foreach ($fontDisplay as $label => $value): ?>
|
70 |
<option value="<?php echo $value; ?>" <?php echo $value == CAOS_WEBFONTS_DISPLAY_OPTION ? 'selected' : ''; ?>><?php _e($label, 'host-webfonts-local'); ?></option>
|
71 |
<?php endforeach; ?>
|
79 |
</tr>
|
80 |
<tr valign="top">
|
81 |
<th scope="row">
|
82 |
+
<label for="caos_webfonts_preload">
|
83 |
<?php _e('Enable preload for stylesheet (experimental)', 'host-webfonts-local'); ?>
|
84 |
</label>
|
85 |
</th>
|
86 |
<td>
|
87 |
+
<input class="caos_webfonts_preload" id="caos_webfonts_preload" type="checkbox" name="caos_webfonts_preload" <?php echo CAOS_WEBFONTS_PRELOAD == 'on' ? 'checked = "checked"' : ''; ?> />
|
88 |
<p class="description">
|
89 |
<?php _e('If you\'re using a plugin (such as Autoptimize) to load stylesheets in the footer, enable this to preload the fonts.', 'host-webfonts-local'); ?> <a target="_blank" href="https://developers.google.com/web/fundamentals/performance/resource-prioritization#preload"><?php _e('Read more', 'host-webfonts-local'); ?></a>
|
90 |
</p>
|
includes/caos-webfonts-style-generation.php
CHANGED
@@ -1,72 +1,108 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
-
* @package: CAOS for Webfonts
|
4 |
-
* @author: Daan van den Bergh
|
5 |
* @copyright: (c) 2019 Daan van den Bergh
|
6 |
-
* @url: https://dev
|
7 |
*/
|
8 |
|
9 |
// Exit if accessed directly
|
10 |
-
if (!defined(
|
|
|
|
|
11 |
?>
|
12 |
-
<
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
<th>
|
29 |
-
font-weight
|
30 |
-
</th>
|
31 |
-
<th>
|
32 |
-
|
33 |
-
</th>
|
34 |
-
</tr>
|
35 |
-
<tbody id="hwl-results">
|
36 |
-
<?php
|
37 |
-
$savedFonts = hwlGetTotalFonts();
|
38 |
-
?>
|
39 |
-
<?php if ($savedFonts): ?>
|
40 |
-
<?php foreach ($savedFonts as $font): ?>
|
41 |
<?php
|
42 |
-
$
|
43 |
-
$arrayPath = "caos_webfonts_array][$fontId]";
|
44 |
?>
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
</tr>
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
<tr class="loading" style="display: none;">
|
71 |
<td colspan="3" align="center">
|
72 |
<span class="spinner"></span>
|
@@ -75,46 +111,44 @@ if (!defined( 'ABSPATH')) exit;
|
|
75 |
<tr class="error" style="display: none;">
|
76 |
<td colspan="3" align="center">No fonts available.</td>
|
77 |
</tr>
|
78 |
-
|
79 |
-
</table>
|
80 |
|
81 |
-
<table>
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
id="
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
<div id="caos-status-progress-bar" style="width: <?php echo $width; ?>%;">
|
114 |
-
<span class="caos-status-progress-percentage"><?php echo $width . '%'; ?></span>
|
115 |
</div>
|
116 |
-
</
|
117 |
-
</
|
118 |
-
|
119 |
-
|
120 |
-
</
|
1 |
<?php
|
2 |
/**
|
3 |
+
* @package : CAOS for Webfonts
|
4 |
+
* @author : Daan van den Bergh
|
5 |
* @copyright: (c) 2019 Daan van den Bergh
|
6 |
+
* @url : https://daan.dev
|
7 |
*/
|
8 |
|
9 |
// Exit if accessed directly
|
10 |
+
if (!defined('ABSPATH')) {
|
11 |
+
exit;
|
12 |
+
}
|
13 |
?>
|
14 |
+
<div class="">
|
15 |
+
<h3><?php _e('Generate Stylesheet'); ?></h3>
|
16 |
+
<p class="description">
|
17 |
+
<?php _e('Search for fonts using a comma-separated list (e.g. Open Sans,Roboto,Poppins) and click \'Search\'.', 'host-webfonts-local'); ?>
|
18 |
+
</p>
|
19 |
+
<div class="hwl-search-box">
|
20 |
+
<input type="text" name="search-field"
|
21 |
+
id="search-field" class="form-input-tip ui-autocomplete-input" placeholder="<?php _e('Search... (e.g. Roboto,Open Sans)', 'host-webfonts-local'); ?>"/>
|
22 |
+
<input type="button" onclick="hwlClickSearch()" name="search-btn"
|
23 |
+
id="search-btn" class="button button-primary button-hero" value="<?php _e('Search', 'host-webfonts-local'); ?>"/>
|
24 |
+
</div>
|
25 |
+
<table>
|
26 |
+
<tr id="row" valign="top">
|
27 |
+
<th align="left" colspan="3"><?php _e('Available subsets', 'host-webfonts-local'); ?></th>
|
28 |
+
</tr>
|
29 |
+
<tbody id="hwl-subsets">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
<?php
|
31 |
+
$subsetFonts = hwlGetSubsets();
|
|
|
32 |
?>
|
33 |
+
<?php if ($subsetFonts): ?>
|
34 |
+
<?php foreach ($subsetFonts as $subsetFont): ?>
|
35 |
+
<?php
|
36 |
+
$availableSubsets = explode(',', $subsetFont->available_subsets);
|
37 |
+
$selectedSubsets = explode(',', $subsetFont->selected_subsets);
|
38 |
+
?>
|
39 |
+
<tr valign="top" id="<?php echo $subsetFont->subset_font; ?>">
|
40 |
+
<td>
|
41 |
+
<label>
|
42 |
+
<input readonly type="text" class="hwl-subset-font-family" value="<?php echo $subsetFont->subset_family; ?>"/>
|
43 |
+
</label>
|
44 |
+
</td>
|
45 |
+
<?php foreach ($availableSubsets as $availableSubset): ?>
|
46 |
+
<td>
|
47 |
+
<label>
|
48 |
+
<?php $checked = in_array($availableSubset, $selectedSubsets) ? 'checked="checked"' : ''; ?>
|
49 |
+
<input name="<?php echo $subsetFont->subset_font; ?>" value="<?php echo $availableSubset; ?>" type="checkbox" onclick="hwlGenerateSearchQuery('<?php echo $subsetFont->subset_font; ?>')" <?php echo $checked; ?>/>
|
50 |
+
<?php echo $availableSubset; ?>
|
51 |
+
</label>
|
52 |
+
</td>
|
53 |
+
<?php endforeach; ?>
|
54 |
+
</tr>
|
55 |
+
<?php endforeach; ?>
|
56 |
+
<?php endif; ?>
|
57 |
+
</tbody>
|
58 |
+
</table>
|
59 |
+
<table>
|
60 |
+
<tr valign="top">
|
61 |
+
<th align="left" colspan="3">Available fonts</th>
|
62 |
</tr>
|
63 |
+
</table>
|
64 |
+
<table align="left" id="hwl-results">
|
65 |
+
<?php
|
66 |
+
$savedFonts = hwlGetTotalFonts();
|
67 |
+
?>
|
68 |
+
<?php if ($savedFonts && $subsetFonts): ?>
|
69 |
+
<?php foreach ($subsetFonts as $subsetFont): ?>
|
70 |
+
<tbody id="hwl-section-<?php echo $subsetFont->subset_font; ?>">
|
71 |
+
<?php
|
72 |
+
$fonts = hwlGetFontsByFamily($subsetFont->subset_family);
|
73 |
+
?>
|
74 |
+
<?php foreach ($fonts as $font):
|
75 |
+
$fontId = $font->font_id;
|
76 |
+
$arrayPath = "caos_webfonts_array][$fontId]";
|
77 |
+
?>
|
78 |
+
<tr id="row-<?php echo $fontId; ?>" valign="top">
|
79 |
+
<td>
|
80 |
+
<input readonly type="text" value="<?php echo $font->font_family; ?>" name="<?php echo $arrayPath; ?>[font-family]"/>
|
81 |
+
</td>
|
82 |
+
<td>
|
83 |
+
<input readonly type="text" value="<?php echo $font->font_style; ?>" name="<?php echo $arrayPath; ?>[font-style]"/>
|
84 |
+
</td>
|
85 |
+
<td>
|
86 |
+
<input readonly type="text" value="<?php echo $font->font_weight; ?>" name="<?php echo $arrayPath; ?>[font-weight]"/>
|
87 |
+
</td>
|
88 |
+
<td>
|
89 |
+
<input type="hidden" value="<?php echo $fontId; ?>" name="<?php echo $arrayPath; ?>[id]"/>
|
90 |
+
<input type="hidden" value="<?php echo $font->url_ttf; ?>" name="<?php echo $arrayPath; ?>[url][ttf]"/>
|
91 |
+
<input type="hidden" value="<?php echo $font->url_woff; ?>" name="<?php echo $arrayPath; ?>[url][woff]"/>
|
92 |
+
<input type="hidden" value="<?php echo $font->url_woff2; ?>" name="<?php echo $arrayPath; ?>[url][woff2]"/>
|
93 |
+
<input type="hidden" value="<?php echo $font->url_eot; ?>" name="<?php echo $arrayPath; ?>[url][eot]"/>
|
94 |
+
<div class="hwl-remove">
|
95 |
+
<a onclick="hwlRemoveRow('row-<?php echo $fontId; ?>')">
|
96 |
+
<small>remove</small>
|
97 |
+
</a>
|
98 |
+
</div>
|
99 |
+
</td>
|
100 |
+
</tr>
|
101 |
+
<?php endforeach; ?>
|
102 |
+
</tbody>
|
103 |
+
<?php endforeach; ?>
|
104 |
+
<?php endif; ?>
|
105 |
+
<tbody id="hwl-warning">
|
106 |
<tr class="loading" style="display: none;">
|
107 |
<td colspan="3" align="center">
|
108 |
<span class="spinner"></span>
|
111 |
<tr class="error" style="display: none;">
|
112 |
<td colspan="3" align="center">No fonts available.</td>
|
113 |
</tr>
|
114 |
+
</tbody>
|
115 |
+
</table>
|
116 |
|
117 |
+
<table>
|
118 |
+
<tbody>
|
119 |
+
<tr valign="center" align="center">
|
120 |
+
<td>
|
121 |
+
<input type="button" onclick="hwlDownloadFonts()" name="save-btn"
|
122 |
+
id="save-btn" class="button-primary" value="Download Fonts"/>
|
123 |
+
</td>
|
124 |
+
<td>
|
125 |
+
<input type="button" onclick="hwlGenerateStylesheet()" name="generate-btn"
|
126 |
+
id="generate-btn" class="button-secondary" value="Generate Stylesheet"/>
|
127 |
+
</td>
|
128 |
+
<td>
|
129 |
+
<a onclick="hwlCleanQueue()" name="clean-btn"
|
130 |
+
id="clean-btn" class="button-cancel">Clean Queue</a>
|
131 |
+
</td>
|
132 |
+
<td>
|
133 |
+
<a onclick="hwlEmptyDir()" name="empty-btn"
|
134 |
+
id="empty-btn" class="button-cancel">Empty Cache Directory</a>
|
135 |
+
</td>
|
136 |
+
<td width="20%"></td>
|
137 |
+
</tr>
|
138 |
+
<tr valign="center">
|
139 |
+
<?php
|
140 |
+
$downloaded = hwlGetDownloadStatus()['downloaded'];
|
141 |
+
$total = hwlGetDownloadStatus()['total'];
|
142 |
+
$width = $downloaded && $total ? (100 / $total) * $downloaded : 0;
|
143 |
+
?>
|
144 |
+
<td colspan="5">
|
145 |
+
<div class="caos-status-total-bar" style="">
|
146 |
+
<div id="caos-status-progress-bar" style="width: <?php echo $width; ?>%;">
|
147 |
+
<span class="caos-status-progress-percentage"><?php echo $width . '%'; ?></span>
|
148 |
+
</div>
|
|
|
|
|
149 |
</div>
|
150 |
+
</td>
|
151 |
+
</tr>
|
152 |
+
</tbody>
|
153 |
+
</table>
|
154 |
+
</div>
|
includes/welcome-panel.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
* @package: CAOS for Webfonts
|
4 |
* @author: Daan van den Bergh
|
5 |
* @copyright: (c) 2019 Daan van den Bergh
|
6 |
-
* @url: https://dev
|
7 |
*/
|
8 |
|
9 |
// Exit if accessed directly
|
@@ -17,38 +17,50 @@ if (!defined('ABSPATH')) exit;
|
|
17 |
This will decrease your pageload times, leverage your browser cache, minimize external requests and effectively bring you a perfect score on Pagespeed Insights and Pingdom.
|
18 |
</p>
|
19 |
<div class="welcome-panel-column-container">
|
20 |
-
<div class="welcome-panel-column">
|
21 |
<h3>Quickstart</h3>
|
22 |
<ul>
|
23 |
<li class="welcome-icon dashicons-before dashicons-editor-bold">For all available fonts, check out <a href="https://fonts.google.com/" target="_blank">Google Fonts</a></li>
|
24 |
-
<li class="welcome-icon dashicons-before dashicons-cloud">Search for
|
|
|
25 |
<li class="welcome-icon dashicons-before dashicons-admin-tools">Modify the list by removing the fonts you don't need/want</li>
|
26 |
-
<li class="welcome-icon dashicons-before dashicons-update">Click '
|
27 |
-
<li class="welcome-icon dashicons-before dashicons-art">Click 'Generate Stylesheet'</li>
|
28 |
-
<li class="welcome-icon dashicons-before dashicons-media-text">
|
|
|
29 |
<li class="welcome-icon dashicons-before dashicons-smiley">Done!</li>
|
30 |
-
<li class="welcome-icon dashicons-before dashicons-admin-settings">After changing settings use 'Save & Regenerate'</li>
|
31 |
</ul>
|
32 |
-
<p><a target="_blank" href="
|
33 |
</div>
|
34 |
-
<div class="welcome-panel-column">
|
35 |
<h3>Get a Perfect Score on Pagespeed & Pingdom!</h3>
|
36 |
-
<p><strong>Leverage your browser cache</strong> and <strong>lower pageload times</strong> by hosting analytics.js locally with <a href="
|
37 |
<p><a target="_blank" href="https://wordpress.org/plugins/host-analyticsjs-local">Download now</a></p>
|
38 |
-
<h3>Need help?</h3>
|
39 |
-
<p>First make sure you read the manual thoroughly.</p>
|
40 |
-
<p>Still running into issues? Visit the <a href="https://wordpress.org/plugins/host-webfonts-local/#description">FAQ</a> and <a href="https://wordpress.org/support/plugin/host-webfonts-local/">Support Forum</a> to see if your question has already been answered.</p>
|
41 |
-
<p>If not, ask a question or <a href="https://dev.daanvandenbergh.com/contact" target="_blank">contact me</a>.</p>
|
42 |
-
</div>
|
43 |
-
<div class="welcome-panel-column welcome-panel-last">
|
44 |
<h3>Want to Host other Files Locally?</h3>
|
45 |
<p>Unleash your site's true potential by locally hosting as many files as possible.</p>
|
46 |
-
<p><a target="_blank" href="
|
47 |
-
|
48 |
-
|
49 |
-
<
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
</div>
|
53 |
</div>
|
54 |
</div>
|
3 |
* @package: CAOS for Webfonts
|
4 |
* @author: Daan van den Bergh
|
5 |
* @copyright: (c) 2019 Daan van den Bergh
|
6 |
+
* @url: https://daan.dev
|
7 |
*/
|
8 |
|
9 |
// Exit if accessed directly
|
17 |
This will decrease your pageload times, leverage your browser cache, minimize external requests and effectively bring you a perfect score on Pagespeed Insights and Pingdom.
|
18 |
</p>
|
19 |
<div class="welcome-panel-column-container">
|
20 |
+
<div class="welcome-panel-column" style="width: 32%;">
|
21 |
<h3>Quickstart</h3>
|
22 |
<ul>
|
23 |
<li class="welcome-icon dashicons-before dashicons-editor-bold">For all available fonts, check out <a href="https://fonts.google.com/" target="_blank">Google Fonts</a></li>
|
24 |
+
<li class="welcome-icon dashicons-before dashicons-cloud">Search for for your fonts</li>
|
25 |
+
<li class="welcome-icon dashicons-before dashicons-admin-settings">Select the subsets you need</li>
|
26 |
<li class="welcome-icon dashicons-before dashicons-admin-tools">Modify the list by removing the fonts you don't need/want</li>
|
27 |
+
<li class="welcome-icon dashicons-before dashicons-update">Click 'Download Fonts' and wait for the download to complete</li>
|
28 |
+
<li class="welcome-icon dashicons-before dashicons-art">Click 'Generate Stylesheet' and wait for the process to complete</li>
|
29 |
+
<li class="welcome-icon dashicons-before dashicons-media-text">The stylesheet is generated and added to your theme's header</li>
|
30 |
+
<li class="welcome-icon dashicons-before dashicons-editor-removeformatting">To <i>remove externally hosted Google Fonts</i>, read <a target="_blank" href="<?= CAOS_WEBFONTS_SITE_URL; ?>/how-to/remove-google-fonts-wordpress">this</a>.</li>
|
31 |
<li class="welcome-icon dashicons-before dashicons-smiley">Done!</li>
|
|
|
32 |
</ul>
|
33 |
+
<p><a target="_blank" href="<?= CAOS_WEBFONTS_SITE_URL; ?>/wordpress/host-google-fonts-locally/">Click here</a> for a more comprehensive guide.</p>
|
34 |
</div>
|
35 |
+
<div class="welcome-panel-column" style="width: 32%;">
|
36 |
<h3>Get a Perfect Score on Pagespeed & Pingdom!</h3>
|
37 |
+
<p><strong>Leverage your browser cache</strong> and <strong>lower pageload times</strong> by hosting analytics.js locally with <a href="<?= CAOS_WEBFONTS_SITE_URL; ?>/wordpress-plugins/optimize-analytics-wordpress/" target="_blank">CAOS for Analytics</a>.</p>
|
38 |
<p><a target="_blank" href="https://wordpress.org/plugins/host-analyticsjs-local">Download now</a></p>
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
<h3>Want to Host other Files Locally?</h3>
|
40 |
<p>Unleash your site's true potential by locally hosting as many files as possible.</p>
|
41 |
+
<p><a target="_blank" href="<?= CAOS_WEBFONTS_SITE_URL; ?>/how-to/host-js-locally-crontab/">Read more</a></p>
|
42 |
+
</div>
|
43 |
+
<div class="welcome-panel-column welcome-panel-last" style="width: 34%;">
|
44 |
+
<h3>
|
45 |
+
<?php _e('Need Help?', 'host-webfonts-local'); ?>
|
46 |
+
</h3>
|
47 |
+
<p>
|
48 |
+
<?php _e('Thank you for using CAOS for Webfonts.', 'host-webfonts-local'); ?>
|
49 |
+
</p>
|
50 |
+
<p>
|
51 |
+
<?php _e('I am convinced that knowledge should be free. That\'s why I will never charge you for the plugins I create and I will help you to succeed in your projects through the <a href="' . CAOS_WEBFONTS_SITE_URL . '/how-to/" target="_blank">tutorials</a> on my blog.', 'host-webfonts-local'); ?>
|
52 |
+
</p>
|
53 |
+
<p>
|
54 |
+
<?php _e("However, my time is just as valuable as yours. Consider supporting me by either <a href='" . CAOS_WEBFONTS_SITE_URL . "/donate' target='_blank'>donating</a> or leaving a <a target='_blank' href='https://wordpress.org/support/plugin/host-analyticsjs-local/reviews/?rate=5#new-post'>5-star review</a> on Wordpress.org.", 'host-webfonts-local'); ?>
|
55 |
+
</p>
|
56 |
+
<p>
|
57 |
+
<?php _e('If you\'re running into any issues, please make sure you\'ve read <a href="' . CAOS_WEBFONTS_SITE_URL . '/wordpress-plugins/optimize-analytics-wordpress/" target="_blank">the manual</a> thoroughly. Visit the <a href="https://wordpress.org/plugins/host-analyticsjs-local/#description" target="_blank">FAQ</a> and <a href="https://wordpress.org/support/plugin/host-analyticsjs-local">Support Forum</a> to see if your question has already been answered. If not, ask a question on the Support Forum.', 'host-webfonts-local'); ?>
|
58 |
+
</p>
|
59 |
+
<p>
|
60 |
+
<a target="_blank" class="button button-primary button-hero" href="<?= CAOS_WEBFONTS_SITE_URL; ?>/donate/"><span class="dashicons-before dashicons-heart"> <?php _e('Donate', 'host-webfonts-local'); ?></span></a>
|
61 |
+
<a target="_blank" class="button button-secondary button-hero" href="https://wordpress.org/support/plugin/host-webfonts-local/reviews/?rate=5#new-post"><span class="dashicons-before dashicons-star-filled"> <?php _e('Review', 'host-webfonts-local'); ?></span></a>
|
62 |
+
<a target="_blank" class="button button-secondary button-hero" href="https://twitter.com/Dan0sz"><span class="dashicons-before dashicons-twitter"> <?php _e('Follow', 'host-webfonts-local'); ?></span></a>
|
63 |
+
</p>
|
64 |
</div>
|
65 |
</div>
|
66 |
</div>
|
js/hwl-admin.js
CHANGED
@@ -2,48 +2,109 @@
|
|
2 |
* @package: CAOS for Webfonts
|
3 |
* @author: Daan van den Bergh
|
4 |
* @copyright: (c) 2019 Daan van den Bergh
|
5 |
-
* @url: https://dev
|
6 |
*/
|
|
|
7 |
/**
|
8 |
-
*
|
9 |
*/
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
typingTimer = setTimeout(doneTyping, doneTypingInterval)
|
17 |
-
})
|
18 |
-
// on keydown, clear the countdown
|
19 |
-
$input.on('keydown', function() {
|
20 |
-
clearTimeout(typingTimer)
|
21 |
-
})
|
22 |
|
23 |
/**
|
24 |
-
*
|
|
|
|
|
25 |
*/
|
26 |
-
function
|
27 |
{
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
}
|
32 |
|
33 |
/**
|
34 |
* Triggers the AJAX-request to Google Webfont Helper.
|
35 |
-
*
|
|
|
|
|
36 |
*/
|
37 |
-
function hwlSearchGoogleFonts(
|
38 |
{
|
39 |
-
|
40 |
-
|
41 |
jQuery.ajax({
|
42 |
type: 'POST',
|
43 |
url: ajaxurl,
|
44 |
data: {
|
45 |
action: 'hwlAjaxSearchGoogleFonts',
|
46 |
-
search_query:
|
|
|
47 |
},
|
48 |
dataType: 'json',
|
49 |
beforeSend: function() {
|
@@ -56,7 +117,7 @@ function hwlSearchGoogleFonts($data)
|
|
56 |
loadingDiv.hide()
|
57 |
errorDiv.hide()
|
58 |
if(response['responseText'] !== 'Not found') {
|
59 |
-
|
60 |
} else {
|
61 |
errorDiv.show()
|
62 |
}
|
@@ -69,18 +130,18 @@ function hwlSearchGoogleFonts($data)
|
|
69 |
*
|
70 |
* @param results
|
71 |
*/
|
72 |
-
function
|
73 |
{
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
for(
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
renderedFonts[iii] = `<tr id="row-${font}" valign="top">
|
85 |
<td>
|
86 |
<input readonly type="text" value="${fontFamily}" name="caos_webfonts_array][${font}][font-family]" />
|
@@ -103,39 +164,49 @@ function hwlGenerateResults(results)
|
|
103 |
</td>
|
104 |
</tr>`
|
105 |
}
|
106 |
-
|
|
|
107 |
}
|
108 |
|
109 |
/**
|
110 |
-
*
|
|
|
|
|
111 |
*/
|
112 |
-
function
|
113 |
{
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
}
|
|
|
|
|
|
|
|
|
|
|
138 |
})
|
|
|
|
|
139 |
}
|
140 |
|
141 |
/**
|
@@ -143,23 +214,31 @@ function hwlGenerateStylesheet()
|
|
143 |
*/
|
144 |
function hwlDownloadFonts()
|
145 |
{
|
146 |
-
|
147 |
-
|
|
|
148 |
jQuery.ajax({
|
149 |
type: 'POST',
|
150 |
url: ajaxurl,
|
151 |
data: {
|
152 |
action: 'hwlAjaxDownloadFonts',
|
153 |
-
|
|
|
154 |
},
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
163 |
}
|
164 |
})
|
165 |
}
|
@@ -180,9 +259,11 @@ function hwlGetDownloadStatus()
|
|
180 |
downloaded = response.downloaded;
|
181 |
total = response.total;
|
182 |
progress = (100 / total) * downloaded;
|
|
|
183 |
hwlUpdateStatusBar(progress);
|
184 |
}
|
185 |
-
})
|
|
|
186 |
}
|
187 |
|
188 |
/**
|
@@ -197,6 +278,54 @@ function hwlUpdateStatusBar(progress)
|
|
197 |
jQuery('.caos-status-progress-percentage').html(progress);
|
198 |
}
|
199 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
200 |
/**
|
201 |
* Remove all files within the configured cache dir.
|
202 |
*/
|
@@ -209,14 +338,8 @@ function hwlEmptyDir()
|
|
209 |
action: 'hwlAjaxEmptyDir'
|
210 |
},
|
211 |
success: function() {
|
212 |
-
jQuery('#hwl-admin-notices').append(
|
213 |
-
`<div class="notice notice-success is-dismissible">
|
214 |
-
<p>Cache-dir emptied.</p>
|
215 |
-
</div>`
|
216 |
-
)
|
217 |
hwlCleanQueue()
|
218 |
hwlUpdateStatusBar(0)
|
219 |
-
hwlScrollTop()
|
220 |
}
|
221 |
})
|
222 |
}
|
@@ -234,20 +357,11 @@ function hwlCleanQueue()
|
|
234 |
},
|
235 |
success: function() {
|
236 |
jQuery('.caos-status-progress-percentage').html('0%')
|
237 |
-
jQuery('#hwl-results').empty()
|
238 |
}
|
239 |
})
|
240 |
}
|
241 |
|
242 |
-
/**
|
243 |
-
* After settings have changed, trigger this.
|
244 |
-
*/
|
245 |
-
function hwlRegenerateStylesheet()
|
246 |
-
{
|
247 |
-
hwlDownloadFonts()
|
248 |
-
hwlGenerateStylesheet()
|
249 |
-
}
|
250 |
-
|
251 |
/**
|
252 |
* Scroll to top-effect.
|
253 |
*/
|
@@ -265,9 +379,9 @@ function hwlScrollTop()
|
|
265 |
*/
|
266 |
function hwlSerializeArray(data)
|
267 |
{
|
268 |
-
|
269 |
data.each(function() {
|
270 |
-
|
271 |
jQuery.each(jQuery(this).serializeArray(), function() {
|
272 |
fields[this.name] = this.value
|
273 |
})
|
2 |
* @package: CAOS for Webfonts
|
3 |
* @author: Daan van den Bergh
|
4 |
* @copyright: (c) 2019 Daan van den Bergh
|
5 |
+
* @url: https://daan.dev
|
6 |
*/
|
7 |
+
|
8 |
/**
|
9 |
+
* When user is done typing, trigger search.
|
10 |
*/
|
11 |
+
function hwlClickSearch()
|
12 |
+
{
|
13 |
+
let input = jQuery('#search-field')
|
14 |
+
searchQuery = input.val().replace(/\s/g, '-').toLowerCase()
|
15 |
+
hwlSearchFontSubsets(searchQuery)
|
16 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
/**
|
19 |
+
* Return available subsets for searched font.
|
20 |
+
*
|
21 |
+
* @param queriedFonts
|
22 |
*/
|
23 |
+
function hwlSearchFontSubsets(queriedFonts)
|
24 |
{
|
25 |
+
let searchField = jQuery('#search-field');
|
26 |
+
let searchButton = jQuery('#search-btn');
|
27 |
+
|
28 |
+
jQuery.ajax({
|
29 |
+
type: 'POST',
|
30 |
+
url: ajaxurl,
|
31 |
+
data: {
|
32 |
+
action: 'hwlAjaxSearchFontSubsets',
|
33 |
+
search_query: queriedFonts
|
34 |
+
},
|
35 |
+
dataType: 'json',
|
36 |
+
beforeSend: function() {
|
37 |
+
hwlUpdateInputValue(searchButton, 'Searching...', '0 20px');
|
38 |
+
searchField.val('');
|
39 |
+
},
|
40 |
+
complete: function(response) {
|
41 |
+
hwlUpdateInputValue(searchButton, 'Search', '0 36px');
|
42 |
+
hwlRenderAvailableSubsets(response);
|
43 |
+
}
|
44 |
+
})
|
45 |
+
}
|
46 |
+
|
47 |
+
/**
|
48 |
+
* Print available subsets
|
49 |
+
*
|
50 |
+
* @param response
|
51 |
+
*/
|
52 |
+
function hwlRenderAvailableSubsets(response)
|
53 |
+
{
|
54 |
+
let data = response['responseJSON'];
|
55 |
+
dataLength = data.length;
|
56 |
+
|
57 |
+
for (let ii = 0; ii < dataLength; ii++) {
|
58 |
+
subsets = data[ii]['subsets']
|
59 |
+
family = data[ii]['family'];
|
60 |
+
id = data[ii]['id'];
|
61 |
+
length = subsets.length;
|
62 |
+
renderedSubsets = [];
|
63 |
+
|
64 |
+
for (let iii = 0; iii < length; iii++) {
|
65 |
+
renderedSubsets[iii] = `<td><label><input name="${id}" value="${subsets[iii]}" type="checkbox" onclick="hwlGenerateSearchQuery('${id}')" />${subsets[iii]}</label></td>`;
|
66 |
+
}
|
67 |
+
|
68 |
+
jQuery('#hwl-subsets').append('<tr valign="top" id="' + id + '"><td><input type="text" class="hwl-subset-font-family" value="' + family + '" readonly/></td>' + renderedSubsets + '</tr>');
|
69 |
+
jQuery('#hwl-results').append("<tbody id='" + 'hwl-section-' + id + "'></tbody>");
|
70 |
+
}
|
71 |
+
}
|
72 |
+
|
73 |
+
/**
|
74 |
+
* Generate search query for selected subsets
|
75 |
+
*
|
76 |
+
* @param id
|
77 |
+
*/
|
78 |
+
function hwlGenerateSearchQuery(id)
|
79 |
+
{
|
80 |
+
let subsets = [];
|
81 |
+
checked = jQuery("input[name='" + id + "']:checked");
|
82 |
+
|
83 |
+
jQuery.each(checked, function() {
|
84 |
+
subsets.push(jQuery(this).val());
|
85 |
+
});
|
86 |
+
|
87 |
+
subsets.join()
|
88 |
+
hwlSearchGoogleFonts(id, subsets);
|
89 |
}
|
90 |
|
91 |
/**
|
92 |
* Triggers the AJAX-request to Google Webfont Helper.
|
93 |
+
*
|
94 |
+
* @param id
|
95 |
+
* @param subsets
|
96 |
*/
|
97 |
+
function hwlSearchGoogleFonts(id, subsets)
|
98 |
{
|
99 |
+
let loadingDiv = jQuery('#hwl-warning .loading')
|
100 |
+
let errorDiv = jQuery('#hwl-warning .error')
|
101 |
jQuery.ajax({
|
102 |
type: 'POST',
|
103 |
url: ajaxurl,
|
104 |
data: {
|
105 |
action: 'hwlAjaxSearchGoogleFonts',
|
106 |
+
search_query: id,
|
107 |
+
search_subsets: subsets
|
108 |
},
|
109 |
dataType: 'json',
|
110 |
beforeSend: function() {
|
117 |
loadingDiv.hide()
|
118 |
errorDiv.hide()
|
119 |
if(response['responseText'] !== 'Not found') {
|
120 |
+
hwlRenderAvailableFonts(response)
|
121 |
} else {
|
122 |
errorDiv.show()
|
123 |
}
|
130 |
*
|
131 |
* @param results
|
132 |
*/
|
133 |
+
function hwlRenderAvailableFonts(results)
|
134 |
{
|
135 |
+
let response = JSON.parse(results['responseText'])
|
136 |
+
variants = response['variants']
|
137 |
+
length = variants.length
|
138 |
+
renderedFonts = []
|
139 |
+
for(iii = 0; iii < length; iii++) {
|
140 |
+
fontFamily = variants[iii].fontFamily.replace(/'/g, '')
|
141 |
+
fontId = variants[iii].id
|
142 |
+
font = fontFamily.replace(/\s+/g, '-').toLowerCase() + '-' + variants[iii].id
|
143 |
+
fontWeight = variants[iii].fontWeight
|
144 |
+
fontStyle = variants[iii].fontStyle
|
145 |
renderedFonts[iii] = `<tr id="row-${font}" valign="top">
|
146 |
<td>
|
147 |
<input readonly type="text" value="${fontFamily}" name="caos_webfonts_array][${font}][font-family]" />
|
164 |
</td>
|
165 |
</tr>`
|
166 |
}
|
167 |
+
console.log(fontFamily.replace(/\s+/g, '-').toLowerCase());
|
168 |
+
jQuery('#hwl-section-' + fontFamily.replace(/\s+/g, '-').toLowerCase()).html(renderedFonts)
|
169 |
}
|
170 |
|
171 |
/**
|
172 |
+
* Gathers all information about the subsets
|
173 |
+
*
|
174 |
+
* @returns {{}}
|
175 |
*/
|
176 |
+
function hwlGatherSelectedSubsets()
|
177 |
{
|
178 |
+
rows = jQuery('#hwl-subsets tr');
|
179 |
+
length = rows.length;
|
180 |
+
subsets = {};
|
181 |
+
jQuery(rows).each(function() {
|
182 |
+
id = this.id;
|
183 |
+
checkboxes = jQuery("input[name='" + id + "']");
|
184 |
+
checked = jQuery("input[name='" + id + "']:checked");
|
185 |
+
|
186 |
+
selectedSubsets = [];
|
187 |
+
jQuery.each(checked, function() {
|
188 |
+
selectedSubsets.push(jQuery(this).val());
|
189 |
+
});
|
190 |
+
selectedSubsets.join()
|
191 |
+
|
192 |
+
availableSubsets = [];
|
193 |
+
jQuery.each(checkboxes, function() {
|
194 |
+
availableSubsets.push(jQuery(this).val());
|
195 |
+
});
|
196 |
+
availableSubsets.join()
|
197 |
+
|
198 |
+
family = jQuery(this).find('.hwl-subset-font-family').val();
|
199 |
+
|
200 |
+
subsets[id] = {};
|
201 |
+
subsets[id]['family'] = {};
|
202 |
+
subsets[id]['family'] = family;
|
203 |
+
subsets[id]['selected'] = {};
|
204 |
+
subsets[id]['selected'] = selectedSubsets;
|
205 |
+
subsets[id]['available'] = {};
|
206 |
+
subsets[id]['available'] = availableSubsets;
|
207 |
})
|
208 |
+
|
209 |
+
return subsets;
|
210 |
}
|
211 |
|
212 |
/**
|
214 |
*/
|
215 |
function hwlDownloadFonts()
|
216 |
{
|
217 |
+
let hwlFonts = hwlSerializeArray(jQuery('#hwl-options-form'));
|
218 |
+
let hwlSubsets = hwlGatherSelectedSubsets();
|
219 |
+
let downloadButton = jQuery('#save-btn');
|
220 |
jQuery.ajax({
|
221 |
type: 'POST',
|
222 |
url: ajaxurl,
|
223 |
data: {
|
224 |
action: 'hwlAjaxDownloadFonts',
|
225 |
+
subsets: hwlSubsets,
|
226 |
+
fonts: hwlFonts,
|
227 |
},
|
228 |
+
beforeSend: function() {
|
229 |
+
hwlUpdateStatusBar(0);
|
230 |
+
hwlGetDownloadStatus();
|
231 |
+
hwlUpdateInputValue(downloadButton, 'Downloading...', '0 14px 1px');
|
232 |
+
},
|
233 |
+
success: function() {
|
234 |
+
clearTimeout(downloadStatus);
|
235 |
+
|
236 |
+
hwlUpdateInputValue(downloadButton, 'Done!', '0 41px 1px');
|
237 |
+
hwlUpdateStatusBar(100);
|
238 |
+
|
239 |
+
setTimeout(function() {
|
240 |
+
hwlUpdateInputValue(downloadButton, 'Download Fonts');
|
241 |
+
}, 2500);
|
242 |
}
|
243 |
})
|
244 |
}
|
259 |
downloaded = response.downloaded;
|
260 |
total = response.total;
|
261 |
progress = (100 / total) * downloaded;
|
262 |
+
|
263 |
hwlUpdateStatusBar(progress);
|
264 |
}
|
265 |
+
});
|
266 |
+
downloadStatus = setTimeout(hwlGetDownloadStatus, 1000);
|
267 |
}
|
268 |
|
269 |
/**
|
278 |
jQuery('.caos-status-progress-percentage').html(progress);
|
279 |
}
|
280 |
|
281 |
+
/**
|
282 |
+
* Call the generate-stylesheet script.
|
283 |
+
*/
|
284 |
+
function hwlGenerateStylesheet()
|
285 |
+
{
|
286 |
+
let hwlFonts = hwlSerializeArray(jQuery('#hwl-options-form'))
|
287 |
+
let generateButton = jQuery('#generate-btn');
|
288 |
+
jQuery.ajax({
|
289 |
+
type: 'POST',
|
290 |
+
url: ajaxurl,
|
291 |
+
data: {
|
292 |
+
action: 'hwlAjaxGenerateStyles',
|
293 |
+
selected_fonts: hwlFonts
|
294 |
+
},
|
295 |
+
beforeSend: function() {
|
296 |
+
hwlUpdateInputValue(generateButton, 'Generating...', '0 33px 1px');
|
297 |
+
},
|
298 |
+
success: function() {
|
299 |
+
hwlUpdateInputValue(generateButton, 'Done!', '0 54px 1px');
|
300 |
+
setTimeout(function() {
|
301 |
+
hwlUpdateInputValue(generateButton, 'Generate Stylesheet');
|
302 |
+
}, 2500);
|
303 |
+
},
|
304 |
+
error: function(response) {
|
305 |
+
hwlScrollTop();
|
306 |
+
jQuery('#hwl-admin-notices').append(
|
307 |
+
`<div class="notice notice-error is-dismissible">
|
308 |
+
<p>The stylesheet could not be created: ${response}</p>
|
309 |
+
</div>`
|
310 |
+
);
|
311 |
+
hwlUpdateInputValue(generateButton, 'Generate Stylesheet');
|
312 |
+
}
|
313 |
+
})
|
314 |
+
}
|
315 |
+
|
316 |
+
/**
|
317 |
+
* Updates the value of any input to show status updates
|
318 |
+
*
|
319 |
+
* @param input
|
320 |
+
* @param text
|
321 |
+
* @param padding
|
322 |
+
*/
|
323 |
+
function hwlUpdateInputValue(input, text, padding = '0 10px 1px')
|
324 |
+
{
|
325 |
+
input.val(text);
|
326 |
+
input.css('padding', padding);
|
327 |
+
}
|
328 |
+
|
329 |
/**
|
330 |
* Remove all files within the configured cache dir.
|
331 |
*/
|
338 |
action: 'hwlAjaxEmptyDir'
|
339 |
},
|
340 |
success: function() {
|
|
|
|
|
|
|
|
|
|
|
341 |
hwlCleanQueue()
|
342 |
hwlUpdateStatusBar(0)
|
|
|
343 |
}
|
344 |
})
|
345 |
}
|
357 |
},
|
358 |
success: function() {
|
359 |
jQuery('.caos-status-progress-percentage').html('0%')
|
360 |
+
jQuery('#hwl-results, #hwl-subsets').empty()
|
361 |
}
|
362 |
})
|
363 |
}
|
364 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
365 |
/**
|
366 |
* Scroll to top-effect.
|
367 |
*/
|
379 |
*/
|
380 |
function hwlSerializeArray(data)
|
381 |
{
|
382 |
+
let result = []
|
383 |
data.each(function() {
|
384 |
+
fields = {}
|
385 |
jQuery.each(jQuery(this).serializeArray(), function() {
|
386 |
fields[this.name] = this.value
|
387 |
})
|
readme.md
CHANGED
@@ -28,7 +28,7 @@ This will *decrease your pageload times*, *leverage browser cache*, *minimize DN
|
|
28 |
|
29 |
**Can I buy you a beer?**
|
30 |
|
31 |
-
Yes, please! [Click here to buy me a beer](https://dev
|
32 |
|
33 |
Visit the [FAQ at Wordpress.org](https://wordpress.org/plugins/host-webfonts-local/#faq)
|
34 |
|
28 |
|
29 |
**Can I buy you a beer?**
|
30 |
|
31 |
+
Yes, please! [Click here to buy me a beer](https://daan.dev/donate/ "Let's do shots!")!
|
32 |
|
33 |
Visit the [FAQ at Wordpress.org](https://wordpress.org/plugins/host-webfonts-local/#faq)
|
34 |
|
readme.txt
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
=== CAOS for Webfonts | Host Google Fonts Locally ===
|
2 |
Contributors: DaanvandenBergh
|
3 |
-
Donate link: https://dev
|
4 |
Tags: update, host, save, local, locally, google, fonts, webfonts, minimize, external, requests, leverage, browser, cache
|
5 |
Requires at least: 4.5
|
6 |
-
Tested up to: 5.
|
7 |
-
Stable tag: 1.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -18,23 +18,30 @@ That's why I kept CAOS for Webfonts small and useful. It uses the Google Fonts H
|
|
18 |
|
19 |
This will *decrease your pageload times*, *leverage browser cache*, *minimize DNS requests* and effectively bring you a perfect score on *Pagespeed Insights* and *Pingdom*, without taking toll on the performance of your webserver.
|
20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
== Installation ==
|
22 |
|
23 |
1. Upload the plugin files to the `/wp-content/plugins/host-webfonts-local` directory, or install the plugin through the WordPress plugins screen directly.
|
24 |
1. Activate the plugin through the 'Plugins' screen in WordPress
|
25 |
1. Use the Settings -> Optimize Webfonts screen to configure the plugin
|
26 |
|
27 |
-
For a more comprehensive guide for configuration, click [here](https://dev
|
28 |
|
29 |
== Frequently Asked Questions ==
|
30 |
|
31 |
= I don't know what I'm doing! Can you help? =
|
32 |
|
33 |
-
Of course :) But first calm down and read this [comprehensive guide on how to configure CAOS for Webfonts](https://dev
|
34 |
|
35 |
= I have another file I want to host locally. Could you make a plugin? =
|
36 |
|
37 |
-
Maintaining two plugins besides my daily 9-to-5 job is a handful, so no. If you're looking for a way to host analytics.js locally; please install [CAOS for Analytics](https://wordpress.org/plugins/host-analyticsjs-local/). For anything else, please follow the steps in [this how-to](https://dev
|
38 |
|
39 |
= How come my font isn't available in CAOS for Webfonts? =
|
40 |
|
@@ -42,6 +49,10 @@ This could be for several reasons:
|
|
42 |
1. Have you checked if your font is available on Google Fonts?
|
43 |
1. Is your font listed as an open source font, or is it a premium font? For obvious reasons, CAOS for Webfonts only has access to open source fonts.
|
44 |
|
|
|
|
|
|
|
|
|
45 |
= Does this plugin edit template files? =
|
46 |
|
47 |
No, it does not. It creates a CSS Stylesheet which will be automatically added to your theme's header using a built-in WordPress queueing system.
|
@@ -60,7 +71,7 @@ Yes, it does!
|
|
60 |
|
61 |
= Can I buy you a beer? =
|
62 |
|
63 |
-
Yes, please! [Click here to buy me a beer](https://dev
|
64 |
|
65 |
== Screenshots ==
|
66 |
|
@@ -68,6 +79,38 @@ N/A
|
|
68 |
|
69 |
== Changelog ==
|
70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
= 1.6.0 =
|
72 |
Added experimental option for preload resource hint.
|
73 |
|
1 |
=== CAOS for Webfonts | Host Google Fonts Locally ===
|
2 |
Contributors: DaanvandenBergh
|
3 |
+
Donate link: https://daan.dev/donate/
|
4 |
Tags: update, host, save, local, locally, google, fonts, webfonts, minimize, external, requests, leverage, browser, cache
|
5 |
Requires at least: 4.5
|
6 |
+
Tested up to: 5.1
|
7 |
+
Stable tag: 1.7.9
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
18 |
|
19 |
This will *decrease your pageload times*, *leverage browser cache*, *minimize DNS requests* and effectively bring you a perfect score on *Pagespeed Insights* and *Pingdom*, without taking toll on the performance of your webserver.
|
20 |
|
21 |
+
= Features =
|
22 |
+
- Easily find and download your fonts in multiple subsets,
|
23 |
+
- Generate a stylesheet, which is automatically added to your header using WordPress' wp_head()-function,
|
24 |
+
- Change the caching path (where the fonts and stylesheet are saved) for increased compatibility with Caching- and Security-plugins, such as WP Super Cache, Autoptimize and WordFence,
|
25 |
+
- Control font performance by adding font-display property,
|
26 |
+
- Prioritize fonts with rel='preload'.
|
27 |
+
|
28 |
== Installation ==
|
29 |
|
30 |
1. Upload the plugin files to the `/wp-content/plugins/host-webfonts-local` directory, or install the plugin through the WordPress plugins screen directly.
|
31 |
1. Activate the plugin through the 'Plugins' screen in WordPress
|
32 |
1. Use the Settings -> Optimize Webfonts screen to configure the plugin
|
33 |
|
34 |
+
For a more comprehensive guide for configuration, click [here](https://daan.dev/wordpress/host-google-fonts-locally/).
|
35 |
|
36 |
== Frequently Asked Questions ==
|
37 |
|
38 |
= I don't know what I'm doing! Can you help? =
|
39 |
|
40 |
+
Of course :) But first calm down and read this [comprehensive guide on how to configure CAOS for Webfonts](https://daan.dev/wordpress/host-google-fonts-locally/). If you have any questions afterwards, visit the [Support Forum](https://wordpress.org/support/plugin/host-webfonts-local).
|
41 |
|
42 |
= I have another file I want to host locally. Could you make a plugin? =
|
43 |
|
44 |
+
Maintaining two plugins besides my daily 9-to-5 job is a handful, so no. If you're looking for a way to host analytics.js locally; please install [CAOS for Analytics](https://wordpress.org/plugins/host-analyticsjs-local/). For anything else, please follow the steps in [this how-to](https://daan.dev/how-to/host-js-locally-crontab/).
|
45 |
|
46 |
= How come my font isn't available in CAOS for Webfonts? =
|
47 |
|
49 |
1. Have you checked if your font is available on Google Fonts?
|
50 |
1. Is your font listed as an open source font, or is it a premium font? For obvious reasons, CAOS for Webfonts only has access to open source fonts.
|
51 |
|
52 |
+
= Can I serve the fonts from my CDN? =
|
53 |
+
|
54 |
+
Yes, you can. Enter the url of your CDN and re-download and re-generate the stylesheet. Then the fonts will be saved to and served from your CDN.
|
55 |
+
|
56 |
= Does this plugin edit template files? =
|
57 |
|
58 |
No, it does not. It creates a CSS Stylesheet which will be automatically added to your theme's header using a built-in WordPress queueing system.
|
71 |
|
72 |
= Can I buy you a beer? =
|
73 |
|
74 |
+
Yes, please! [Click here to buy me a beer](https://daan.dev/donate/ "Let's do shots!")!
|
75 |
|
76 |
== Screenshots ==
|
77 |
|
79 |
|
80 |
== Changelog ==
|
81 |
|
82 |
+
= 1.7.9 =
|
83 |
+
Cleared up instructions in Welcome Panel.
|
84 |
+
Added option to remove version parameter from stylesheet request.
|
85 |
+
|
86 |
+
= 1.7.8 =
|
87 |
+
Updated welcome panel.
|
88 |
+
|
89 |
+
= 1.7.7 =
|
90 |
+
Quick-fix for re-triggered SQL queries.
|
91 |
+
|
92 |
+
= 1.7.6 =
|
93 |
+
XSS hardening in stylesheet generation form.
|
94 |
+
|
95 |
+
= 1.7.5 =
|
96 |
+
Added CDN support.
|
97 |
+
|
98 |
+
= 1.7.4 =
|
99 |
+
Fluid progress bar now functions correctly and doesn't make any unnecessary Ajax-requests.
|
100 |
+
Replaced all success-messages with notifications inside the buttons, to increase UX.
|
101 |
+
|
102 |
+
= 1.7.3 =
|
103 |
+
Improved search by adding support for comma-separated lists. Fixed some 404s in welcome panel and minor JavaScript optimizations.
|
104 |
+
|
105 |
+
= 1.7.2 =
|
106 |
+
Minor usability updates.
|
107 |
+
|
108 |
+
= 1.7.0 =
|
109 |
+
Added support for subsets to increase compatibility with other writing.
|
110 |
+
|
111 |
+
= 1.6.1 =
|
112 |
+
Changed domains to new home: daan.dev
|
113 |
+
|
114 |
= 1.6.0 =
|
115 |
Added experimental option for preload resource hint.
|
116 |
|