Rebrand plugin with new name and prefixes
This commit is contained in:
Родитель
6ed5982156
Коммит
75120098e4
|
@ -2,4 +2,4 @@ vendor/
|
|||
tools/
|
||||
composer.lock
|
||||
node_modules/
|
||||
wp-sw-cache.zip
|
||||
wp-offline-shell.zip
|
||||
|
|
|
@ -22,7 +22,7 @@ matrix:
|
|||
env: WP_VERSION=latest WP_MULTISITE=1
|
||||
before_script:
|
||||
- ./bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION
|
||||
- "composer install --working-dir=wp-sw-cache"
|
||||
- "composer install --working-dir=wp-offline-shell"
|
||||
- "export DISPLAY=:99.0"
|
||||
- "sh -e /etc/init.d/xvfb start"
|
||||
- sleep 3
|
||||
|
|
2
LICENSE
2
LICENSE
|
@ -1,4 +1,4 @@
|
|||
wp-sw-cache - WordPress Service Worker Cache
|
||||
wp-offline-shell - WordPress Offline Shell
|
||||
Copyright (C) 2016 by its contributors
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
|
|
12
Makefile
12
Makefile
|
@ -4,10 +4,10 @@ WP_CLI = tools/wp-cli.phar
|
|||
PHPUNIT = tools/phpunit.phar
|
||||
|
||||
reinstall: $(WP_CLI)
|
||||
$(WP_CLI) plugin uninstall --deactivate wp-sw-cache --path=$(WORDPRESS_PATH)
|
||||
rm -f wp-sw-cache.zip
|
||||
zip wp-sw-cache.zip -r wp-sw-cache/
|
||||
$(WP_CLI) plugin install --activate wp-sw-cache.zip --path=$(WORDPRESS_PATH)
|
||||
$(WP_CLI) plugin uninstall --deactivate wp-offline-shell --path=$(WORDPRESS_PATH)
|
||||
rm -f wp-offline-shell.zip
|
||||
zip wp-offline-shell.zip -r wp-offline-shell/
|
||||
$(WP_CLI) plugin install --activate wp-offline-shell.zip --path=$(WORDPRESS_PATH)
|
||||
|
||||
test: $(PHPUNIT)
|
||||
$(PHPUNIT)
|
||||
|
@ -19,8 +19,8 @@ node_modules:
|
|||
npm install
|
||||
|
||||
l10n: tools/wordpress-repo
|
||||
php tools/wordpress-repo/tools/i18n/makepot.php wp-plugin wp-sw-cache
|
||||
mv wp-sw-cache.pot wp-sw-cache/lang/service-worker-cache.pot
|
||||
php tools/wordpress-repo/tools/i18n/makepot.php wp-plugin wp-offline-shell
|
||||
mv wp-offline-shell.pot wp-offline-shell/lang/offline-shell.pot
|
||||
|
||||
tools/wordpress-repo:
|
||||
mkdir -p tools
|
||||
|
|
10
README.md
10
README.md
|
@ -1,10 +1,8 @@
|
|||
[![Build Status](https://travis-ci.org/darkwing/wp-sw-cache.svg?branch=master)](https://travis-ci.org/darkwing/wp-sw-cache)
|
||||
[![Build Status](https://travis-ci.org/mozilla/wp-offline-shell.svg?branch=master)](https://travis-ci.org/mozilla/wp-offline-shell)
|
||||
|
||||
# Service Worker Cache
|
||||
# Offline Shell
|
||||
A WordPress plugin for caching theme assets via a service worker for the sake of performance and offline functionality.
|
||||
|
||||
This plugin is currently experimental and should only be used with developers with [Service Worker knowledge](https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API/Using_Service_Workers).
|
||||
|
||||
## Build
|
||||
|
||||
To build the plugin, ensure you have [Composer](https://getcomposer.org/),
|
||||
|
@ -12,7 +10,7 @@ then simply invoke `composer install`.
|
|||
|
||||
## Installation and Usage
|
||||
|
||||
Assuming the build step completed successfully, place the `wp-sw-cache` directory inside your WordPress instance's `wp-content/plugins directory`.
|
||||
Assuming the build step completed successfully, place the `wp-offline-shell` directory inside your WordPress instance's `wp-content/plugins directory`.
|
||||
|
||||
With the plugin in the WordPress directory structure:
|
||||
|
||||
|
@ -48,7 +46,7 @@ make test-sw
|
|||
|
||||
## Contribution and Bugs
|
||||
|
||||
Contributions are welcome! You can file pull requests or or issues at [this repository](https://github.com/darkwing/wp-sw-cache).
|
||||
Contributions are welcome! You can file pull requests or or issues at [this repository](https://github.com/mozilla/wp-offline-shell).
|
||||
|
||||
## Related WordPress Plugins
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ module.exports = function(config) {
|
|||
// list of files / patterns to load in the browser
|
||||
files: [
|
||||
{ pattern: 'tests/service-worker/*.js', included: false },
|
||||
{ pattern: 'wp-sw-cache/lib/*.js', included: false }
|
||||
{ pattern: 'wp-offline-shell/lib/*.js', included: false }
|
||||
],
|
||||
|
||||
// list of files to exclude
|
||||
|
|
10
package.json
10
package.json
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "wp-sw-cache",
|
||||
"version": "0.1.1",
|
||||
"name": "wp-offline-shell",
|
||||
"version": "0.2.0",
|
||||
"description": "A WordPress plugin for selecting theme assets to be cached by service workers",
|
||||
"main": "index.js",
|
||||
"directories": {
|
||||
|
@ -23,7 +23,7 @@
|
|||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/darkwing/wp-sw-cache.git"
|
||||
"url": "git+https://github.com/mozilla/wp-offline-shell.git"
|
||||
},
|
||||
"keywords": [
|
||||
"wordpress",
|
||||
|
@ -34,7 +34,7 @@
|
|||
"author": "David Walsh",
|
||||
"license": "GPL-2.0",
|
||||
"bugs": {
|
||||
"url": "https://github.com/darkwing/wp-sw-cache/issues"
|
||||
"url": "https://github.com/mozilla/wp-offline-shell/issues"
|
||||
},
|
||||
"homepage": "https://github.com/darkwing/wp-sw-cache#readme"
|
||||
"homepage": "https://github.com/mozilla/wp-offline-shell#readme"
|
||||
}
|
||||
|
|
10
readme.txt
10
readme.txt
|
@ -1,10 +1,10 @@
|
|||
=== Plugin Name ===
|
||||
Contributors: davidwalsh83, mozillawebapps
|
||||
Donate link: https://davidwalsh.name
|
||||
Tags: performance, caching, offline
|
||||
Tags: performance, cache, offline
|
||||
Requires at least: 3.0.1
|
||||
Tested up to: 4.4.2
|
||||
Stable tag: 0.1.1
|
||||
Stable tag: 0.2
|
||||
License: GPLv2 or later
|
||||
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
|
||||
|
@ -12,7 +12,7 @@ A WordPress plugin for caching theme assets via a service worker for the sake of
|
|||
|
||||
== Description ==
|
||||
|
||||
Service Worker Cache is a WordPress plugin for using the [ServiceWorker API](https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API/Using_Service_Workers "Learn more") to cache theme files for performance and offline purposes.
|
||||
Offline Shell is a WordPress plugin for using the [ServiceWorker API](https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API/Using_Service_Workers "Learn more") to cache theme files for performance and offline purposes.
|
||||
|
||||
The WordPress admin can select which files to cache, update the cache list at any time, and see their site performance improve while ensuring important assets are available offline.
|
||||
|
||||
|
@ -20,9 +20,9 @@ The WordPress admin can select which files to cache, update the cache list at an
|
|||
|
||||
Installation of the plugin is simple:
|
||||
|
||||
1. Upload the plugin files to the `/wp-content/plugins/wp-sw-cache` directory, or install the plugin through the WordPress plugins screen directly.
|
||||
1. Upload the plugin files to the `/wp-content/plugins/wp-offline-shell` directory, or install the plugin through the WordPress plugins screen directly.
|
||||
2. Activate the plugin through the 'Plugins' screen in WordPress
|
||||
3. Use the Settings->Service Worker Cache screen to configure the plugin
|
||||
3. Use the Settings->Offline Shell screen to configure the plugin
|
||||
4. Check the "Enable Service Worker" checkbox and then select individual files you'd like cached. These assets should be files you use on most pages.
|
||||
|
||||
== Frequently Asked Questions ==
|
||||
|
|
|
@ -8,7 +8,7 @@ if ( ! $_tests_dir ) {
|
|||
require_once $_tests_dir . '/includes/functions.php';
|
||||
|
||||
function _manually_load_plugin() {
|
||||
require dirname( dirname( __FILE__ ) ) . '/wp-sw-cache/wp-sw-cache.php';
|
||||
require dirname( dirname( __FILE__ ) ) . '/wp-offline-shell/wp-offline-shell.php';
|
||||
}
|
||||
tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );
|
||||
|
||||
|
|
|
@ -12,15 +12,15 @@ describe('tests', function() {
|
|||
};
|
||||
self.$debug = 1;
|
||||
|
||||
importScripts('/base/wp-sw-cache/lib/service-worker.js');
|
||||
importScripts('/base/wp-offline-shell/lib/service-worker.js');
|
||||
|
||||
// Override our utility with a different storage object so we can manipulate
|
||||
wpSwCache.storage = localforage.createInstance({ name: storageKey });
|
||||
wpSwCache.cacheName = storageKey;
|
||||
wpOfflineShell.storage = localforage.createInstance({ name: storageKey });
|
||||
wpOfflineShell.cacheName = storageKey;
|
||||
|
||||
// Clean up cache and storage before each test
|
||||
wpSwCache.storage.clear().then(function() {
|
||||
self.caches.delete(wpSwCache.cacheName).then(function(){
|
||||
wpOfflineShell.storage.clear().then(function() {
|
||||
self.caches.delete(wpOfflineShell.cacheName).then(function(){
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
@ -30,14 +30,14 @@ describe('tests', function() {
|
|||
this.timeout(10000);
|
||||
|
||||
// Simulates a basic install -- check cache and localforage
|
||||
wpSwCache.update().then(function() {
|
||||
return self.caches.open(wpSwCache.cacheName).then(function(cache) {
|
||||
wpOfflineShell.update().then(function() {
|
||||
return self.caches.open(wpOfflineShell.cacheName).then(function(cache) {
|
||||
return cache.keys().then(function(keys) {
|
||||
assert.isTrue(keys.length == 2);
|
||||
|
||||
var cacheMatches = 0;
|
||||
var storageMatches = 0;
|
||||
return Promise.all(Object.keys(wpSwCache.urls).map(function(key) {
|
||||
return Promise.all(Object.keys(wpOfflineShell.urls).map(function(key) {
|
||||
return cache.match(key).then(function(result) {
|
||||
var isGood = (result && result.url === key);
|
||||
assert.isTrue(isGood);
|
||||
|
@ -45,8 +45,8 @@ describe('tests', function() {
|
|||
cacheMatches++;
|
||||
}
|
||||
}).then(function() {
|
||||
return wpSwCache.storage.getItem(key).then(function(result) {
|
||||
var isGood = (result && result === wpSwCache.urls[key]);
|
||||
return wpOfflineShell.storage.getItem(key).then(function(result) {
|
||||
var isGood = (result && result === wpOfflineShell.urls[key]);
|
||||
assert.isTrue(isGood);
|
||||
if(isGood) {
|
||||
storageMatches++;
|
||||
|
@ -67,20 +67,20 @@ describe('tests', function() {
|
|||
// Simulates a user caching files, going to admin to remove a file, and seeing that file removed from cache+storage
|
||||
var removedUrl;
|
||||
|
||||
wpSwCache.update().then(function() {
|
||||
removedUrl = Object.keys(wpSwCache.urls)[0];
|
||||
delete wpSwCache.urls[removedUrl];
|
||||
wpOfflineShell.update().then(function() {
|
||||
removedUrl = Object.keys(wpOfflineShell.urls)[0];
|
||||
delete wpOfflineShell.urls[removedUrl];
|
||||
|
||||
// The second "update" call simulates teh SW being re-installed/updated
|
||||
wpSwCache.update().then(function() {
|
||||
return wpSwCache.removeOldUrls();
|
||||
wpOfflineShell.update().then(function() {
|
||||
return wpOfflineShell.removeOldUrls();
|
||||
}).then(function() {
|
||||
// Ensure the URL is no longer in cache
|
||||
return self.caches.open(wpSwCache.cacheName).then(function(cache) {
|
||||
return self.caches.open(wpOfflineShell.cacheName).then(function(cache) {
|
||||
return cache.match(removedUrl).then(function(result) {
|
||||
assert.strictEqual(result, undefined);
|
||||
}).then(function() {
|
||||
return wpSwCache.storage.getItem(removedUrl).then(function(hash) {
|
||||
return wpOfflineShell.storage.getItem(removedUrl).then(function(hash) {
|
||||
assert.strictEqual(hash, undefined);
|
||||
done();
|
||||
});
|
||||
|
@ -91,7 +91,7 @@ describe('tests', function() {
|
|||
});
|
||||
|
||||
it('A URL manually removed from cache after it\'s been cached is re-downloaded and cached', function() {
|
||||
// https://github.com/darkwing/wp-sw-cache/issues/43
|
||||
// https://github.com/mozilla/offline-shell/issues/43
|
||||
|
||||
});
|
||||
|
||||
|
@ -99,18 +99,18 @@ describe('tests', function() {
|
|||
// We don't want to muddle up the user's console if they option isn't on
|
||||
console.log = console.warn = sinon.spy();
|
||||
|
||||
wpSwCache.debug = false;
|
||||
wpSwCache.log('Hello');
|
||||
wpOfflineShell.debug = false;
|
||||
wpOfflineShell.log('Hello');
|
||||
assert.equal(console.log.callCount, 0);
|
||||
|
||||
wpSwCache.debug = true;
|
||||
wpSwCache.log('Hello2');
|
||||
wpOfflineShell.debug = true;
|
||||
wpOfflineShell.log('Hello2');
|
||||
assert.equal(console.log.callCount, 1);
|
||||
});
|
||||
|
||||
it('`shouldBeHandled` works properly', function() {
|
||||
// We only want to cache vanilla URLs -- no credentials, query string, etc.
|
||||
var firstUrl = Object.keys(wpSwCache.urls)[0];
|
||||
var firstUrl = Object.keys(wpOfflineShell.urls)[0];
|
||||
|
||||
var goodRequest = new Request(firstUrl);
|
||||
var badRequest = new Request('https://nothing');
|
||||
|
@ -118,9 +118,9 @@ describe('tests', function() {
|
|||
method: 'POST'
|
||||
});
|
||||
|
||||
assert.isTrue(wpSwCache.shouldBeHandled(goodRequest));
|
||||
assert.isFalse(wpSwCache.shouldBeHandled(badRequest));
|
||||
assert.isFalse(wpSwCache.shouldBeHandled(badRequest2));
|
||||
assert.isTrue(wpOfflineShell.shouldBeHandled(goodRequest));
|
||||
assert.isFalse(wpOfflineShell.shouldBeHandled(badRequest));
|
||||
assert.isFalse(wpOfflineShell.shouldBeHandled(badRequest2));
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -6,21 +6,21 @@ class SW_Tests extends WP_UnitTestCase {
|
|||
parent::setup();
|
||||
|
||||
// Ensure the plugin is enabled
|
||||
update_option('wp_sw_cache_enabled', 1);
|
||||
update_option('offline_shell_enabled', 1);
|
||||
|
||||
// Set which files should be cached
|
||||
update_option('wp_sw_cache_files', array('style.css', 'screenshot.png'));
|
||||
update_option('offline_shell_files', array('style.css', 'screenshot.png'));
|
||||
}
|
||||
|
||||
function test_file_must_exist() {
|
||||
// Step 1: Get the SW content
|
||||
$sw_content_1 = SW_Cache_Main::build_sw();
|
||||
$sw_content_1 = Offline_Shell_Main::build_sw();
|
||||
|
||||
// Step 2: Rename file so to mock that the file has been deleted
|
||||
rename(get_template_directory().'/style.css', get_template_directory().'/style.temp');
|
||||
|
||||
// Step 3: Get SW content
|
||||
$sw_content_2 = SW_Cache_Main::build_sw();
|
||||
$sw_content_2 = Offline_Shell_Main::build_sw();
|
||||
|
||||
// Success means the new SW content is no longer the same
|
||||
$this->assertTrue($sw_content_1 != $sw_content_2);
|
||||
|
@ -31,12 +31,12 @@ class SW_Tests extends WP_UnitTestCase {
|
|||
|
||||
function test_unchanged_files_and_times_generates_same_sw() {
|
||||
// Success means the SW content is the same because nothing has changed
|
||||
$this->assertTrue(SW_Cache_Main::build_sw() === SW_Cache_Main::build_sw());
|
||||
$this->assertTrue(Offline_Shell_Main::build_sw() === Offline_Shell_Main::build_sw());
|
||||
}
|
||||
|
||||
function test_file_changed_generates_new_sw() {
|
||||
// Step 1: Get content
|
||||
$sw_content_1 = SW_Cache_Main::build_sw();
|
||||
$sw_content_1 = Offline_Shell_Main::build_sw();
|
||||
|
||||
// Step 2: Update a file's contents to nudge the modified time
|
||||
$file_to_edit = get_template_directory().'/style.css';
|
||||
|
@ -44,7 +44,7 @@ class SW_Tests extends WP_UnitTestCase {
|
|||
file_put_contents($file_to_edit, 'blah blah');
|
||||
|
||||
// Step 3: Get the new content
|
||||
$sw_content_2 = SW_Cache_Main::build_sw();
|
||||
$sw_content_2 = Offline_Shell_Main::build_sw();
|
||||
|
||||
// Success means the SW content is different because a file has changed
|
||||
$this->assertTrue($sw_content_1 !== $sw_content_2);
|
||||
|
@ -52,30 +52,30 @@ class SW_Tests extends WP_UnitTestCase {
|
|||
|
||||
function test_changed_file_list_generates_new_sw() {
|
||||
// Step 1: Get content
|
||||
$sw_content_1 = SW_Cache_Main::build_sw();
|
||||
$sw_content_1 = Offline_Shell_Main::build_sw();
|
||||
|
||||
// Step 2: Remove the last item from the list
|
||||
$files = get_option('wp_sw_cache_files');
|
||||
$files = get_option('offline_shell_files');
|
||||
$last_file = array_pop($files);
|
||||
update_option('wp_sw_cache_files', $files);
|
||||
update_option('offline_shell_files', $files);
|
||||
|
||||
// Step 3: Get the new content
|
||||
$sw_content_2 = SW_Cache_Main::build_sw();
|
||||
$sw_content_2 = Offline_Shell_Main::build_sw();
|
||||
|
||||
// Success means the content is different because a file has changed
|
||||
$this->assertTrue($sw_content_1 !== $sw_content_2);
|
||||
|
||||
// Cleanup: Put the removed item back
|
||||
$files[] = $last_file;
|
||||
update_option('wp_sw_cache_files', $files);
|
||||
update_option('offline_shell_files', $files);
|
||||
}
|
||||
|
||||
function test_update_runs_on_version_mismatch() {
|
||||
$old_version = '0.0.0';
|
||||
update_option('wp_sw_cache_version', $old_version);
|
||||
update_option('offline_shell_version', $old_version);
|
||||
|
||||
SW_Cache_DB::update();
|
||||
Offline_Shell_DB::update();
|
||||
|
||||
$this->assertTrue($old_version !== get_option('wp_sw_cache_version'));
|
||||
$this->assertTrue($old_version !== get_option('offline_shell_version'));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"name": "darkwing/wp-sw-cache",
|
||||
"name": "mozilla/wp-offline-shell",
|
||||
"description": "A WordPress plugin for caching theme assets.",
|
||||
"authors": [ ],
|
||||
"repositories": [
|
|
@ -3,7 +3,7 @@
|
|||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: WP Service Worker Cache 0.2\n"
|
||||
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/wp-sw-cache\n"
|
||||
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/offline-shell\n"
|
||||
"POT-Creation-Date: 2016-03-04 16:11:55+00:00\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
|
@ -12,58 +12,58 @@ msgstr ""
|
|||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
|
||||
#: wp-sw-cache-admin.php:52
|
||||
#: offline-shell-admin.php:52
|
||||
msgid ""
|
||||
"Service Worker is enabled but no files have been selected for caching. To "
|
||||
"take full advantage of this plugin, <a href=\"%s\">please select files to "
|
||||
"cache</a>."
|
||||
msgstr ""
|
||||
|
||||
#: wp-sw-cache-admin.php:56
|
||||
#: offline-shell-admin.php:56
|
||||
msgid ""
|
||||
"The ServiceWorker API requires a secure origin (HTTPS or localhost). Your "
|
||||
"Service Worker may not work."
|
||||
msgstr ""
|
||||
|
||||
#: wp-sw-cache-admin.php:61
|
||||
#: offline-shell-admin.php:61
|
||||
msgid "WP SW Cache"
|
||||
msgstr ""
|
||||
|
||||
#: wp-sw-cache-admin.php:73
|
||||
#: offline-shell-admin.php:73
|
||||
msgid ""
|
||||
"You've changed themes; please update your <a href=\"%s\">WP ServiceWorker "
|
||||
"Cache options</a>."
|
||||
msgstr ""
|
||||
|
||||
#: wp-sw-cache-admin.php:80
|
||||
#: offline-shell-admin.php:80
|
||||
msgid "A matching minified file was found, deferring to minified asset."
|
||||
msgstr ""
|
||||
|
||||
#: wp-sw-cache-admin.php:99
|
||||
#: offline-shell-admin.php:99
|
||||
msgid "%s is a standard WordPress theme file only used in admin."
|
||||
msgstr ""
|
||||
|
||||
#: wp-sw-cache-admin.php:110
|
||||
#: offline-shell-admin.php:110
|
||||
msgid "%s is likely for legacy Internet Explorer browsers."
|
||||
msgstr ""
|
||||
|
||||
#: wp-sw-cache-admin.php:119
|
||||
#: offline-shell-admin.php:119
|
||||
msgid "woff2 is high performing and woff is a globally supported fallback"
|
||||
msgstr ""
|
||||
|
||||
#: wp-sw-cache-admin.php:127
|
||||
#: offline-shell-admin.php:127
|
||||
msgid "Main or secondary level assets are likely important in most themes"
|
||||
msgstr ""
|
||||
|
||||
#: wp-sw-cache-admin.php:149
|
||||
#: offline-shell-admin.php:149
|
||||
msgid "Your settings have been saved."
|
||||
msgstr ""
|
||||
|
||||
#: wp-sw-cache-admin.php:153
|
||||
#: offline-shell-admin.php:153
|
||||
msgid "WordPress Service Worker Cache"
|
||||
msgstr ""
|
||||
|
||||
#: wp-sw-cache-admin.php:155
|
||||
#: offline-shell-admin.php:155
|
||||
msgid ""
|
||||
"WordPress Service Worker Cache is a utility that harnesses the power of the "
|
||||
"<a href=\"https://serviceworke.rs\" target=\"_blank\">ServiceWorker API</a> "
|
||||
|
@ -71,87 +71,87 @@ msgid ""
|
|||
"viewing."
|
||||
msgstr ""
|
||||
|
||||
#: wp-sw-cache-admin.php:160
|
||||
#: offline-shell-admin.php:160
|
||||
msgid "ServiceWorker Cache Settings"
|
||||
msgstr ""
|
||||
|
||||
#: wp-sw-cache-admin.php:163
|
||||
#: offline-shell-admin.php:163
|
||||
msgid "Enable Service Worker"
|
||||
msgstr ""
|
||||
|
||||
#: wp-sw-cache-admin.php:169
|
||||
#: offline-shell-admin.php:169
|
||||
msgid "Enable Debug Messages"
|
||||
msgstr ""
|
||||
|
||||
#: wp-sw-cache-admin.php:176
|
||||
#: offline-shell-admin.php:176
|
||||
msgid "Theme Files to Cache"
|
||||
msgstr ""
|
||||
|
||||
#: wp-sw-cache-admin.php:178
|
||||
#: offline-shell-admin.php:178
|
||||
msgid ""
|
||||
"Select theme assets (typically JavaScript, CSS, fonts, and image files) that "
|
||||
"are used on a majority of pages."
|
||||
msgstr ""
|
||||
|
||||
#: wp-sw-cache-admin.php:179
|
||||
#: offline-shell-admin.php:179
|
||||
msgid "Select All Files"
|
||||
msgstr ""
|
||||
|
||||
#: wp-sw-cache-admin.php:180
|
||||
#: offline-shell-admin.php:180
|
||||
msgid "Clear All Files"
|
||||
msgstr ""
|
||||
|
||||
#: wp-sw-cache-admin.php:181
|
||||
#: offline-shell-admin.php:181
|
||||
msgid "Files Suggested: "
|
||||
msgstr ""
|
||||
|
||||
#: wp-sw-cache-admin.php:181
|
||||
#: offline-shell-admin.php:181
|
||||
msgid "Suggest Files"
|
||||
msgstr ""
|
||||
|
||||
#: wp-sw-cache-admin.php:181
|
||||
#: offline-shell-admin.php:181
|
||||
msgid "beta"
|
||||
msgstr ""
|
||||
|
||||
#: wp-sw-cache-admin.php:190
|
||||
#: offline-shell-admin.php:190
|
||||
msgid "CSS Files"
|
||||
msgstr ""
|
||||
|
||||
#: wp-sw-cache-admin.php:191
|
||||
#: offline-shell-admin.php:191
|
||||
msgid "JavaScript Files"
|
||||
msgstr ""
|
||||
|
||||
#: wp-sw-cache-admin.php:192
|
||||
#: offline-shell-admin.php:192
|
||||
msgid "Font Files"
|
||||
msgstr ""
|
||||
|
||||
#: wp-sw-cache-admin.php:193
|
||||
#: offline-shell-admin.php:193
|
||||
msgid "Image Files"
|
||||
msgstr ""
|
||||
|
||||
#: wp-sw-cache-admin.php:194
|
||||
#: offline-shell-admin.php:194
|
||||
msgid "Other Files"
|
||||
msgstr ""
|
||||
|
||||
#: wp-sw-cache-admin.php:234
|
||||
#: offline-shell-admin.php:234
|
||||
msgid ""
|
||||
"The following assets, especially <code>.php</code> files, have no value in "
|
||||
"being cached directly by service workers."
|
||||
msgstr ""
|
||||
|
||||
#: wp-sw-cache-admin.php:260
|
||||
#: offline-shell-admin.php:260
|
||||
msgid "No matching files found."
|
||||
msgstr ""
|
||||
|
||||
#: wp-sw-cache-admin.php:264
|
||||
#: offline-shell-admin.php:264
|
||||
msgid "Save Changes"
|
||||
msgstr ""
|
||||
|
||||
#: wp-sw-cache-admin.php:268
|
||||
#: offline-shell-admin.php:268
|
||||
msgid "Click the button below to clear any caches created by this plugin."
|
||||
msgstr ""
|
||||
|
||||
#: wp-sw-cache-admin.php:269
|
||||
#: offline-shell-admin.php:269
|
||||
msgid "Clear Local Cache"
|
||||
msgstr ""
|
||||
|
||||
|
@ -160,7 +160,7 @@ msgid "WP Service Worker Cache"
|
|||
msgstr ""
|
||||
|
||||
#. Plugin URI of the plugin/theme
|
||||
msgid "https://github.com/darkwing/wp-sw-cache"
|
||||
msgid "https://github.com/darkwing/offline-shell"
|
||||
msgstr ""
|
||||
|
||||
#. Description of the plugin/theme
|
|
@ -5,7 +5,7 @@
|
|||
// update what's needed and delete what isn't
|
||||
var storageKey = '$name';
|
||||
|
||||
var wpSwCache = self.wpSwCache = {
|
||||
var wpOfflineShell = self.wpOfflineShell = {
|
||||
// A { url: hash } object which will be used to populate cache
|
||||
// A changed url object will ensure the SW is downloaded when URLs change
|
||||
urls: $urls,
|
||||
|
@ -131,7 +131,7 @@
|
|||
|
||||
// Add debugging functions
|
||||
['log', 'warn'].forEach(function(level) {
|
||||
wpSwCache[level] = function() {
|
||||
wpOfflineShell[level] = function() {
|
||||
if(this.debug) {
|
||||
console[level].apply(console, arguments);
|
||||
}
|
||||
|
@ -139,8 +139,8 @@
|
|||
});
|
||||
|
||||
// Kick off the event listeners
|
||||
self.addEventListener('install', wpSwCache.onInstall.bind(wpSwCache));
|
||||
self.addEventListener('activate', wpSwCache.onActivate.bind(wpSwCache));
|
||||
self.addEventListener('fetch', wpSwCache.onFetch.bind(wpSwCache));
|
||||
self.addEventListener('install', wpOfflineShell.onInstall.bind(wpOfflineShell));
|
||||
self.addEventListener('activate', wpOfflineShell.onActivate.bind(wpOfflineShell));
|
||||
self.addEventListener('fetch', wpOfflineShell.onFetch.bind(wpOfflineShell));
|
||||
|
||||
})(self, localforage);
|
|
@ -1,8 +1,8 @@
|
|||
<?php
|
||||
|
||||
load_plugin_textdomain('service-worker-cache', false, dirname(plugin_basename(__FILE__)).'/lang');
|
||||
load_plugin_textdomain('offline-shell', false, dirname(plugin_basename(__FILE__)).'/lang');
|
||||
|
||||
class SW_Cache_Admin {
|
||||
class Offline_Shell_Admin {
|
||||
private static $instance;
|
||||
|
||||
public function __construct() {
|
||||
|
@ -19,20 +19,20 @@ class SW_Cache_Admin {
|
|||
}
|
||||
|
||||
public function process_options() {
|
||||
if(!isset($_POST['wpswcache_form_submitted'])) {
|
||||
if(!isset($_POST['offline_shell_form_submitted'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Update "enabled" status
|
||||
update_option('wp_sw_cache_enabled', isset($_POST['wp_sw_cache_enabled']) ? intval($_POST['wp_sw_cache_enabled']) : 0);
|
||||
update_option('offline_shell_enabled', isset($_POST['offline_shell_enabled']) ? intval($_POST['offline_shell_enabled']) : 0);
|
||||
|
||||
// Update "debug" status
|
||||
update_option('wp_sw_cache_debug', isset($_POST['wp_sw_cache_debug']) ? intval($_POST['wp_sw_cache_debug']) : 0);
|
||||
update_option('offline_shell_debug', isset($_POST['offline_shell_debug']) ? intval($_POST['offline_shell_debug']) : 0);
|
||||
|
||||
// Update files to cache
|
||||
$files = array();
|
||||
if(isset($_POST['wp_sw_cache_files'])) {
|
||||
foreach($_POST['wp_sw_cache_files'] as $file) {
|
||||
if(isset($_POST['offline_shell_files'])) {
|
||||
foreach($_POST['offline_shell_files'] as $file) {
|
||||
$file = urldecode($file);
|
||||
// Ensure the file actually exists
|
||||
$tfile = get_template_directory().'/'.$file;
|
||||
|
@ -41,42 +41,42 @@ class SW_Cache_Admin {
|
|||
}
|
||||
}
|
||||
}
|
||||
update_option('wp_sw_cache_files', $files);
|
||||
update_option('offline_shell_files', $files);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function on_admin_notices() {
|
||||
if(get_option('wp_sw_cache_enabled') && !count(get_option('wp_sw_cache_files'))) {
|
||||
echo '<div class="update-nag"><p>', sprintf(__('Service Worker is enabled but no files have been selected for caching. To take full advantage of this plugin, <a href="%s">please select files to cache</a>.', 'service-worker-cache'), admin_url('options-general.php?page=wp-sw-cache-options')),'</p></div>';
|
||||
if(get_option('offline_shell_enabled') && !count(get_option('offline_shell_files'))) {
|
||||
echo '<div class="update-nag"><p>', sprintf(__('Offline Shell is enabled but no files have been selected for caching. To take full advantage of this plugin, <a href="%s">please select files to cache</a>.', 'offline-shell'), admin_url('options-general.php?page=offline-shell-options')),'</p></div>';
|
||||
}
|
||||
|
||||
if(get_option('wp_sw_cache_enabled') && ($_SERVER['REQUEST_SCHEME'] != 'https' && strrpos(strtolower($_SERVER['HTTP_HOST']), 'localhost', -strlen($_SERVER['HTTP_HOST']) === false))) {
|
||||
echo '<div class="update-nag"><p>', __('The ServiceWorker API requires a secure origin (HTTPS or localhost). Your Service Worker may not work.', 'service-worker-cache'), '</p></div>';
|
||||
if(get_option('offline_shell_enabled') && ($_SERVER['REQUEST_SCHEME'] != 'https' && strrpos(strtolower($_SERVER['HTTP_HOST']), 'localhost', -strlen($_SERVER['HTTP_HOST']) === false))) {
|
||||
echo '<div class="update-nag"><p>', __('The ServiceWorker API requires a secure origin (HTTPS or localhost). Your Service Worker may not work.', 'offline-shell'), '</p></div>';
|
||||
}
|
||||
}
|
||||
|
||||
public function on_admin_menu() {
|
||||
add_options_page(__('Service Worker Cache', 'service-worker-cache'), __('Service Worker Cache', 'service-worker-cache'), 'manage_options', 'wp-sw-cache-options', array($this, 'options'));
|
||||
add_options_page(__('Offline Shell', 'offline-shell'), __('Offline Shell', 'offline-shell'), 'manage_options', 'offline-shell-options', array($this, 'options'));
|
||||
}
|
||||
|
||||
public function on_switch_theme() {
|
||||
if(get_option('wp_sw_cache_enabled')) {
|
||||
update_option('wp_sw_cache_enabled', SW_Cache_DB::$options['wp_sw_cache_enabled']);
|
||||
update_option('wp_sw_cache_files', SW_Cache_DB::$options['wp_sw_cache_files']);
|
||||
if(get_option('offline_shell_enabled')) {
|
||||
update_option('offline_shell_enabled', Offline_Shell_DB::$options['offline_shell_enabled']);
|
||||
update_option('offline_shell_files', Offline_Shell_DB::$options['offline_shell_files']);
|
||||
add_action('admin_notices', array($this, 'show_switch_theme_message'));
|
||||
}
|
||||
}
|
||||
|
||||
function show_switch_theme_message() {
|
||||
echo '<div class="update-nag"><p>', sprintf(__('You\'ve changed themes; please update your <a href="%s">WP ServiceWorker Cache options</a>.', 'service-worker-cache'), admin_url('options-general.php?page=wp-sw-cache-options')), '</p></div>';
|
||||
echo '<div class="update-nag"><p>', sprintf(__('You\'ve changed themes; please update your <a href="%s">WP ServiceWorker Cache options</a>.', 'offline-shell'), admin_url('options-general.php?page=offline-shell-options')), '</p></div>';
|
||||
}
|
||||
|
||||
function determine_file_recommendation($file_info, $all_files) {
|
||||
if(SW_Cache_Recommender::has_min_file($file_info['name'], $all_files)) {
|
||||
if(Offline_Shell_Recommender::has_min_file($file_info['name'], $all_files)) {
|
||||
return array(
|
||||
'verdict' => false,
|
||||
'message' => __('A matching minified file was found, deferring to minified asset.', 'service-worker-cache')
|
||||
'message' => __('A matching minified file was found, deferring to minified asset.', 'offline-shell')
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -84,38 +84,38 @@ class SW_Cache_Admin {
|
|||
if($file_info['name'] === 'style.css') {
|
||||
return array(
|
||||
'verdict' => true,
|
||||
'message' => sprintf(__('%s is a standard WordPress theme file.', 'service-worker-cache'), 'style.css')
|
||||
'message' => sprintf(__('%s is a standard WordPress theme file.', 'offline-shell'), 'style.css')
|
||||
);
|
||||
}
|
||||
|
||||
// screenshot.{png|gif|jpe?g} and editor-style.css are standard WP files for admin only, so don't use it
|
||||
if(SW_Cache_Recommender::matches_any_regex(
|
||||
if(Offline_Shell_Recommender::matches_any_regex(
|
||||
$file_info['name'],
|
||||
array('/screenshot\.(gif|png|jpg|jpeg|bmp)$/', '/editor-style.css$/')
|
||||
)) {
|
||||
return array(
|
||||
'verdict' => false,
|
||||
'message' => sprintf(__('%s is a standard WordPress theme file only used in admin.', 'service-worker-cache'), $file_info['name'])
|
||||
'message' => sprintf(__('%s is a standard WordPress theme file only used in admin.', 'offline-shell'), $file_info['name'])
|
||||
);
|
||||
}
|
||||
|
||||
// Ignore old IE css and font files
|
||||
if(SW_Cache_Recommender::matches_any_regex(
|
||||
if(Offline_Shell_Recommender::matches_any_regex(
|
||||
$file_info['name'],
|
||||
array('/ie-?\d\.css$/', '/\.eot$/', '/html5-?(shiv)?\.js$/')
|
||||
)) {
|
||||
return array(
|
||||
'verdict' => false,
|
||||
'message' => sprintf(__('%s is likely for legacy Internet Explorer browsers.', 'service-worker-cache'), $file_info['name'])
|
||||
'message' => sprintf(__('%s is likely for legacy Internet Explorer browsers.', 'offline-shell'), $file_info['name'])
|
||||
);
|
||||
}
|
||||
|
||||
// Recommend woff and woff2 fonts
|
||||
// http://caniuse.com/#feat=woff2
|
||||
if(SW_Cache_Recommender::matches_any_regex($file_info['name'], array('/\.woff2?$/'))) {
|
||||
if(Offline_Shell_Recommender::matches_any_regex($file_info['name'], array('/\.woff2?$/'))) {
|
||||
return array(
|
||||
'verdict' => true,
|
||||
'message' => sprintf(__('woff2 is high performing and woff is a globally supported fallback', 'service-worker-cache'), $file_info['name'])
|
||||
'message' => sprintf(__('woff2 is high performing and woff is a globally supported fallback', 'offline-shell'), $file_info['name'])
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -123,7 +123,7 @@ class SW_Cache_Admin {
|
|||
if(in_array($file_info['category'], array('css', 'js', 'image')) && substr_count($file_info['name'], '/') < 2) {
|
||||
return array(
|
||||
'verdict' => true,
|
||||
'message' => __('Main or secondary level assets are likely important in most themes', 'service-worker-cache')
|
||||
'message' => __('Main or secondary level assets are likely important in most themes', 'offline-shell')
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -134,7 +134,7 @@ class SW_Cache_Admin {
|
|||
$submitted = $this->process_options();
|
||||
|
||||
// Get default values for file listing
|
||||
$selected_files = get_option('wp_sw_cache_files');
|
||||
$selected_files = get_option('offline_shell_files');
|
||||
if(!$selected_files) {
|
||||
$selected_files = array();
|
||||
}
|
||||
|
@ -149,48 +149,48 @@ class SW_Cache_Admin {
|
|||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<h1><?php _e('Service Worker Cache', 'service-worker-cache'); ?> <code>v<?php echo get_option('wp_sw_cache_version'); ?></code></h1>
|
||||
<h1><?php _e('Offline Shell', 'offline-shell'); ?> <code>v<?php echo get_option('offline_shell_version'); ?></code></h1>
|
||||
|
||||
<p><?php _e('Service Worker Cache is a utility that harnesses the power of the <a href="https://serviceworke.rs" target="_blank">ServiceWorker API</a> to cache frequently used assets for the purposes of performance and offline viewing.'); ?></p>
|
||||
<p><?php _e('Offline Shell is a utility that harnesses the power of the <a href="https://serviceworke.rs" target="_blank">ServiceWorker API</a> to cache frequently used assets for the purposes of performance and offline viewing.'); ?></p>
|
||||
|
||||
<form method="post" action="">
|
||||
<input type="hidden" name="wpswcache_form_submitted" value="1">
|
||||
<input type="hidden" name="offline_shell_form_submitted" value="1">
|
||||
|
||||
<h2><?php _e('ServiceWorker Cache Settings', 'service-worker-cache'); ?></h2>
|
||||
<h2><?php _e('Offline Shell Settings', 'offline-shell'); ?></h2>
|
||||
<table class="form-table">
|
||||
<tr>
|
||||
<th scope="row"><label for="wp_sw_cache_enabled"><?php _e('Enable Service Worker', 'service-worker-cache'); ?></label></th>
|
||||
<th scope="row"><label for="offline_shell_enabled"><?php _e('Enable Service Worker', 'offline-shell'); ?></label></th>
|
||||
<td>
|
||||
<input type="checkbox" name="wp_sw_cache_enabled" id="wp_sw_cache_enabled" value="1" <?php if(intval(get_option('wp_sw_cache_enabled'))) echo 'checked'; ?> autofocus />
|
||||
<input type="checkbox" name="offline_shell_enabled" id="offline_shell_enabled" value="1" <?php if(intval(get_option('offline_shell_enabled'))) echo 'checked'; ?> autofocus />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><label for="wp_sw_cache_debug"><?php _e('Enable Debug Messages', 'service-worker-cache'); ?></label></th>
|
||||
<th scope="row"><label for="offline_shell_debug"><?php _e('Enable Debug Messages', 'offline-shell'); ?></label></th>
|
||||
<td>
|
||||
<input type="checkbox" name="wp_sw_cache_debug" id="wp_sw_cache_debug" value="1" <?php if(intval(get_option('wp_sw_cache_debug'))) echo 'checked'; ?> />
|
||||
<input type="checkbox" name="offline_shell_debug" id="offline_shell_debug" value="1" <?php if(intval(get_option('offline_shell_debug'))) echo 'checked'; ?> />
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h2><?php _e('Theme Files to Cache', 'service-worker-cache'); ?> (<code><?php echo get_template(); ?></code>)</h2>
|
||||
<h2><?php _e('Theme Files to Cache', 'offline-shell'); ?> (<code><?php echo get_template(); ?></code>)</h2>
|
||||
<p>
|
||||
<?php _e('Select theme assets (typically JavaScript, CSS, fonts, and image files) that are used on a majority of pages.', 'service-worker-cache'); ?>
|
||||
<button type="button" class="button button-primary wp-sw-cache-toggle-all"><?php _e('Select All Files'); ?></button>
|
||||
<button type="button" class="button button-primary wp-sw-cache-clear-all"><?php _e('Clear All Files'); ?></button>
|
||||
<button type="button" class="button button-primary wp-sw-cache-suggest-file" data-suggested-text="<?php echo esc_attr__('Files Suggested: '); ?>"><?php _e('Suggest Files'); ?> <span>(<?php _e('beta'); ?>)</span></button>
|
||||
<?php _e('Select theme assets (typically JavaScript, CSS, fonts, and image files) that are used on a majority of pages.', 'offline-shell'); ?>
|
||||
<button type="button" class="button button-primary offline-shell-toggle-all"><?php _e('Select All Files'); ?></button>
|
||||
<button type="button" class="button button-primary offline-shell-clear-all"><?php _e('Clear All Files'); ?></button>
|
||||
<button type="button" class="button button-primary offline-shell-suggest-file" data-suggested-text="<?php echo esc_attr__('Files Suggested: '); ?>"><?php _e('Suggest Files'); ?> <span>(<?php _e('beta'); ?>)</span></button>
|
||||
</p>
|
||||
|
||||
<div class="wp-sw-cache-file-list">
|
||||
<div class="offline-shell-file-list">
|
||||
<?php
|
||||
$template_abs_path = get_template_directory();
|
||||
$theme_files = wp_get_theme()->get_files(null, 10); // 10 is arbitrary
|
||||
|
||||
$categories = array(
|
||||
array('key' => 'css', 'title' => __('CSS Files', 'service-worker-cache'), 'extensions' => array('css'), 'files' => array()),
|
||||
array('key' => 'js', 'title' => __('JavaScript Files', 'service-worker-cache'), 'extensions' => array('js'), 'files' => array()),
|
||||
array('key' => 'font', 'title' => __('Font Files', 'service-worker-cache'), 'extensions' => array('woff', 'woff2', 'ttf', 'eot'), 'files' => array()),
|
||||
array('key' => 'image', 'title' => __('Image Files', 'service-worker-cache'), 'extensions' => array('svg', 'jpg', 'jpeg', 'gif', 'png', 'webp'), 'files' => array()),
|
||||
array('key' => 'other', 'title' => __('Other Files', 'service-worker-cache'), 'extensions' => array('*'), 'files' => array()) // Needs to be last
|
||||
array('key' => 'css', 'title' => __('CSS Files', 'offline-shell'), 'extensions' => array('css'), 'files' => array()),
|
||||
array('key' => 'js', 'title' => __('JavaScript Files', 'offline-shell'), 'extensions' => array('js'), 'files' => array()),
|
||||
array('key' => 'font', 'title' => __('Font Files', 'offline-shell'), 'extensions' => array('woff', 'woff2', 'ttf', 'eot'), 'files' => array()),
|
||||
array('key' => 'image', 'title' => __('Image Files', 'offline-shell'), 'extensions' => array('svg', 'jpg', 'jpeg', 'gif', 'png', 'webp'), 'files' => array()),
|
||||
array('key' => 'other', 'title' => __('Other Files', 'offline-shell'), 'extensions' => array('*'), 'files' => array()) // Needs to be last
|
||||
);
|
||||
|
||||
// Sort the files and place them in their baskets
|
||||
|
@ -226,7 +226,7 @@ class SW_Cache_Admin {
|
|||
<h3>
|
||||
<?php echo esc_html($category['title']); ?>
|
||||
(<?php echo esc_html(implode(', ', $category['extensions'])); ?>)
|
||||
<a href="" class="wp-sw-cache-file-all">Select All</a>
|
||||
<a href="" class="offline-shell-file-all">Select All</a>
|
||||
</h3>
|
||||
|
||||
<?php if($category['key'] === 'other') { ?>
|
||||
|
@ -238,17 +238,17 @@ class SW_Cache_Admin {
|
|||
<?php foreach($category['files'] as $file) { $file_id++; ?>
|
||||
<tr>
|
||||
<td style="width: 30px;">
|
||||
<input type="checkbox" class="<?php if($file['recommended']['verdict']) { echo 'recommended'; } ?>" name="wp_sw_cache_files[]" id="wp_sw_cache_files['file_<?php echo $file_id; ?>']" value="<?php echo esc_attr(urlencode($file['name'])); ?>" <?php if(in_array($file['name'], $selected_files)) { echo 'checked'; } ?> />
|
||||
<input type="checkbox" class="<?php if($file['recommended']['verdict']) { echo 'recommended'; } ?>" name="offline_shell_files[]" id="offline_shell_files['file_<?php echo $file_id; ?>']" value="<?php echo esc_attr(urlencode($file['name'])); ?>" <?php if(in_array($file['name'], $selected_files)) { echo 'checked'; } ?> />
|
||||
</td>
|
||||
<td>
|
||||
<label for="wp_sw_cache_files['file_<?php echo $file_id; ?>']">
|
||||
<label for="offline_shell_files['file_<?php echo $file_id; ?>']">
|
||||
<?php echo esc_html($file['name']); ?>
|
||||
<span class="wp-sw-cache-file-size"><?php echo ($file['size'] > 0 ? round($file['size']/1024, 2) : 0).'kb'; ?></span>
|
||||
<span class="offline-shell-file-size"><?php echo ($file['size'] > 0 ? round($file['size']/1024, 2) : 0).'kb'; ?></span>
|
||||
<?php if($file['recommended']['message']) { ?>
|
||||
<?php if($file['recommended']['verdict']) { ?>
|
||||
<span class="wp-sw-cache-file-recommended">✔ <?php echo esc_html($file['recommended']['message']); ?></span>
|
||||
<span class="offline-shell-file-recommended">✔ <?php echo esc_html($file['recommended']['message']); ?></span>
|
||||
<?php } else { ?>
|
||||
<span class="wp-sw-cache-file-not-recommended">× <?php echo esc_html($file['recommended']['message']); ?></span>
|
||||
<span class="offline-shell-file-not-recommended">× <?php echo esc_html($file['recommended']['message']); ?></span>
|
||||
<?php } ?>
|
||||
<?php } ?>
|
||||
</label>
|
||||
|
@ -256,7 +256,7 @@ class SW_Cache_Admin {
|
|||
</tr>
|
||||
<?php } ?>
|
||||
</table>
|
||||
<?php } else { ?><p><?php _e('No matching files found.', 'service-worker-cache'); ?></p><?php } ?>
|
||||
<?php } else { ?><p><?php _e('No matching files found.', 'offline-shell'); ?></p><?php } ?>
|
||||
<?php } ?>
|
||||
</div>
|
||||
|
||||
|
@ -266,18 +266,18 @@ class SW_Cache_Admin {
|
|||
</div>
|
||||
|
||||
<style>
|
||||
.wp-sw-cache-suggested {
|
||||
.offline-shell-suggested {
|
||||
background: lightgreen;
|
||||
}
|
||||
|
||||
.wp-sw-cache-suggest-file,
|
||||
.wp-sw-cache-toggle-all,
|
||||
.wp-sw-cache-clear-all {
|
||||
.offline-shell-suggest-file,
|
||||
.offline-shell-toggle-all,
|
||||
.offline-shell-clear-all {
|
||||
float: right;
|
||||
margin-left: 10px !important;
|
||||
}
|
||||
|
||||
.wp-sw-cache-file-list {
|
||||
.offline-shell-file-list {
|
||||
max-height: 300px;
|
||||
background: #fefefe;
|
||||
border: 1px solid #ccc;
|
||||
|
@ -285,15 +285,15 @@ class SW_Cache_Admin {
|
|||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.wp-sw-cache-suggest-file span {
|
||||
.offline-shell-suggest-file span {
|
||||
font-size: smaller;
|
||||
color: #fc0;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.wp-sw-cache-file-size,
|
||||
.wp-sw-cache-file-recommended,
|
||||
.wp-sw-cache-file-not-recommended {
|
||||
.offline-shell-file-size,
|
||||
.offline-shell-file-recommended,
|
||||
.offline-shell-file-not-recommended {
|
||||
font-size: smaller;
|
||||
color: #999;
|
||||
font-size: italic;
|
||||
|
@ -301,11 +301,11 @@ class SW_Cache_Admin {
|
|||
margin-left: 20px;
|
||||
}
|
||||
|
||||
.wp-sw-cache-file-recommended {
|
||||
.offline-shell-file-recommended {
|
||||
color: green;
|
||||
}
|
||||
|
||||
.wp-sw-cache-file-all {
|
||||
.offline-shell-file-all {
|
||||
font-size: 14px;
|
||||
display: inline-block;
|
||||
margin-left: 20px;
|
||||
|
@ -315,7 +315,7 @@ class SW_Cache_Admin {
|
|||
|
||||
<script type="text/javascript">
|
||||
|
||||
jQuery('.wp-sw-cache-suggest-file').on('click', function() {
|
||||
jQuery('.offline-shell-suggest-file').on('click', function() {
|
||||
// TODO: More advanced logic
|
||||
|
||||
var $this = jQuery(this);
|
||||
|
@ -324,7 +324,7 @@ class SW_Cache_Admin {
|
|||
// Suggest main level CSS and JS files
|
||||
var $recommended = jQuery('.files-list input[type="checkbox"].recommended:not(:checked)')
|
||||
.prop('checked', 'checked')
|
||||
.closest('tr').addClass('wp-sw-cache-suggested');
|
||||
.closest('tr').addClass('offline-shell-suggested');
|
||||
|
||||
// Update sugget button now that the process is done
|
||||
$this
|
||||
|
@ -332,15 +332,15 @@ class SW_Cache_Admin {
|
|||
.prop('disabled', 'disabled');
|
||||
});
|
||||
|
||||
jQuery('.wp-sw-cache-toggle-all').on('click', function() {
|
||||
jQuery('.offline-shell-toggle-all').on('click', function() {
|
||||
jQuery('.files-list input[type="checkbox"]').prop('checked', 'checked');
|
||||
});
|
||||
|
||||
jQuery('.wp-sw-cache-clear-all').on('click', function() {
|
||||
jQuery('.offline-shell-clear-all').on('click', function() {
|
||||
jQuery('.files-list input[type="checkbox"]').prop('checked', '');
|
||||
});
|
||||
|
||||
jQuery('.wp-sw-cache-file-all').on('click', function(e) {
|
||||
jQuery('.offline-shell-file-all').on('click', function(e) {
|
||||
e.preventDefault();
|
||||
jQuery(this.parentNode).next('.files-list').find('input[type=checkbox]').prop('checked', 'checked');
|
||||
});
|
|
@ -1,17 +1,17 @@
|
|||
<?php
|
||||
|
||||
class SW_Cache_DB {
|
||||
class Offline_Shell_DB {
|
||||
|
||||
private static $instance;
|
||||
public static $options = array(
|
||||
// For v1 we'll prompt the user enable the plugin manually upon activation
|
||||
'wp_sw_cache_enabled' => 0,
|
||||
'offline_shell_enabled' => 0,
|
||||
// The "style.css" file is a standard WordPress file, so we can safely assume this exists
|
||||
'wp_sw_cache_files' => array('styles.css'),
|
||||
'offline_shell_files' => array('styles.css'),
|
||||
// Create an initial SW version
|
||||
'wp_sw_cache_version' => '0.1.1',
|
||||
'offline_shell_version' => '0.2',
|
||||
// Setting debug initially will help the user understand what the SW is doing via the console
|
||||
'wp_sw_cache_debug' => 0
|
||||
'offline_shell_debug' => 0
|
||||
);
|
||||
|
||||
public function __construct() {
|
||||
|
@ -38,8 +38,8 @@ class SW_Cache_DB {
|
|||
}
|
||||
|
||||
public static function update() {
|
||||
$current_version = self::$options['wp_sw_cache_version'];
|
||||
if($current_version == get_option('wp_sw_cache_version')) {
|
||||
$current_version = self::$options['offline_shell_version'];
|
||||
if($current_version == get_option('offline_shell_version')) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,7 @@ class SW_Cache_DB {
|
|||
add_option($option, $default);
|
||||
}
|
||||
|
||||
update_option('wp_sw_cache_version', $current_version);
|
||||
update_option('offline_shell_version', $current_version);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,13 +1,13 @@
|
|||
<?php
|
||||
|
||||
require_once(plugin_dir_path(__FILE__).'wp-sw-cache.php' );
|
||||
require_once(plugin_dir_path(__FILE__).'wp-sw-cache-db.php');
|
||||
require_once(plugin_dir_path(__FILE__).'wp-sw-cache-recommender.php');
|
||||
require_once(plugin_dir_path(__FILE__).'wp-offline-shell.php' );
|
||||
require_once(plugin_dir_path(__FILE__).'wp-offline-shell-db.php');
|
||||
require_once(plugin_dir_path(__FILE__).'wp-offline-shell-recommender.php');
|
||||
require_once(plugin_dir_path(__FILE__).'vendor/mozilla/wp-sw-manager/class-wp-sw-manager.php');
|
||||
|
||||
class SW_Cache_Main {
|
||||
class Offline_Shell_Main {
|
||||
private static $instance;
|
||||
public static $cache_name = '__wp-sw-cache';
|
||||
public static $cache_name = '__offline-shell';
|
||||
|
||||
public function __construct() {
|
||||
WP_SW_Manager::get_manager()->sw()->add_content(array($this, 'write_sw'));
|
||||
|
@ -25,13 +25,13 @@ class SW_Cache_Main {
|
|||
$urls = array();
|
||||
|
||||
// Get files and validate they are of proper type
|
||||
$files = get_option('wp_sw_cache_files');
|
||||
$files = get_option('offline_shell_files');
|
||||
if(!$files || !is_array($files)) {
|
||||
$files = array();
|
||||
}
|
||||
|
||||
// Ensure that every file requested to be cached still exists
|
||||
if(get_option('wp_sw_cache_enabled')) {
|
||||
if(get_option('offline_shell_enabled')) {
|
||||
foreach($files as $index => $file) {
|
||||
$tfile = get_template_directory().'/'.$file;
|
||||
if(file_exists($tfile)) {
|
||||
|
@ -45,7 +45,7 @@ class SW_Cache_Main {
|
|||
$contents = file_get_contents(dirname(__FILE__).'/lib/service-worker.js');
|
||||
$contents = str_replace('$name', self::$cache_name, $contents);
|
||||
$contents = str_replace('$urls', json_encode($urls), $contents);
|
||||
$contents = str_replace('$debug', intval(get_option('wp_sw_cache_debug')), $contents);
|
||||
$contents = str_replace('$debug', intval(get_option('offline_shell_debug')), $contents);
|
||||
return $contents;
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
class SW_Cache_Recommender {
|
||||
class Offline_Shell_Recommender {
|
||||
private static $instance;
|
||||
|
||||
public function __construct() {
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
/*
|
||||
Plugin Name: Offline Shell
|
||||
Plugin URI: https://github.com/mozilla/offline-shell
|
||||
Description: This WordPress plugin provides a method for caching theme assets via a service worker.
|
||||
Version: 0.2
|
||||
Text Domain: offline-shell
|
||||
Author: David Walsh
|
||||
Author URI: https://davidwalsh.name
|
||||
*/
|
||||
|
||||
require_once(plugin_dir_path(__FILE__).'wp-offline-shell-main.php');
|
||||
require_once(plugin_dir_path(__FILE__).'wp-offline-shell-db.php');
|
||||
|
||||
Offline_Shell_DB::init();
|
||||
Offline_Shell_Main::init();
|
||||
|
||||
if (is_admin()) {
|
||||
require_once(plugin_dir_path(__FILE__).'wp-offline-shell-admin.php');
|
||||
Offline_Shell_Admin::init();
|
||||
}
|
||||
|
||||
register_activation_hook(__FILE__, array('Offline_Shell_DB', 'on_activate'));
|
||||
register_deactivation_hook(__FILE__, array('Offline_Shell_DB', 'on_deactivate'));
|
||||
register_uninstall_hook(__FILE__, array('Offline_Shell_DB', 'on_uninstall'));
|
||||
|
||||
?>
|
|
@ -1,27 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
Plugin Name: Service Worker Cache
|
||||
Plugin URI: https://github.com/darkwing/wp-sw-cache
|
||||
Description: This WordPress plugin provides a method for caching theme assets via a service worker.
|
||||
Version: 0.1.1
|
||||
Text Domain: service-worker-cache
|
||||
Author: David Walsh
|
||||
Author URI: https://davidwalsh.name
|
||||
*/
|
||||
|
||||
require_once(plugin_dir_path(__FILE__).'wp-sw-cache-main.php');
|
||||
require_once(plugin_dir_path(__FILE__).'wp-sw-cache-db.php');
|
||||
|
||||
SW_Cache_DB::init();
|
||||
SW_Cache_Main::init();
|
||||
|
||||
if (is_admin()) {
|
||||
require_once(plugin_dir_path(__FILE__).'wp-sw-cache-admin.php');
|
||||
SW_Cache_Admin::init();
|
||||
}
|
||||
|
||||
register_activation_hook(__FILE__, array('SW_Cache_DB', 'on_activate'));
|
||||
register_deactivation_hook(__FILE__, array('SW_Cache_DB', 'on_deactivate'));
|
||||
register_uninstall_hook(__FILE__, array('SW_Cache_DB', 'on_uninstall'));
|
||||
|
||||
?>
|
Загрузка…
Ссылка в новой задаче