forked from rosell-dk/webp-express
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webp-express.php
83 lines (70 loc) · 2.46 KB
/
webp-express.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
/**
* Plugin Name: WebP Express
* Plugin URI: https://github.com/rosell-dk/webp-express
* Description: Serve autogenerated WebP images instead of jpeg/png to browsers that supports WebP. Works on anything (media library images, galleries, theme images etc).
* Version: 0.12.2
* Author: Bjørn Rosell
* Author URI: https://www.bitwise-it.dk
* License: GPL2
* Network: true
*/
/*
Note: Perhaps create a plugin page on my website?, ie https://www.bitwise-it.dk/software/wordpress/webp-express
*/
define('WEBPEXPRESS_PLUGIN', __FILE__);
define('WEBPEXPRESS_PLUGIN_DIR', __DIR__);
use \WebPExpress\Option;
spl_autoload_register('webpexpress_autoload');
function webpexpress_autoload($class) {
//echo $class . "\n<br>";
if (strpos($class, 'WebPExpress\\') === 0) {
//echo WEBPEXPRESS_PLUGIN_DIR . '/lib/classes/' . substr($class, 12) . '.php' . "\n<br><br>";
require_once WEBPEXPRESS_PLUGIN_DIR . '/lib/classes/' . substr($class, 12) . '.php';
}
}
if (is_admin()) {
include __DIR__ . '/lib/admin.php';
}
//add_action( 'wp_ajax_foobar', 'my_ajax_foobar_handler' );
function webp_express_process_post() {
// strip query string
$requestUriNoQS = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
if (!preg_match('/webp-express-web-service$/', $requestUriNoQS)) {
return;
}
//include __DIR__ . '/lib/wpc.php';
include __DIR__ . '/web-service/wpc.php';
die();
}
add_action( 'init', 'webp_express_process_post' );
if (Option::getOption('webp-express-alter-html', false)) {
require_once __DIR__ . '/lib/classes/AlterHtmlInit.php';
\WebPExpress\AlterHtmlInit::setHooks();
}
/*
function webpexpress_addWebPJs() {
$url = plugins_url('webpjs/webpjs-0.0.2.min.js', __FILE__);
$script = <<<EOD
<script>
(function(){
var WebP=new Image();
WebP.onload=WebP.onerror=function(){
if(WebP.height!=2){
var sc=document.createElement('script');
sc.type='text/javascript';
sc.async=true;
var s=document.getElementsByTagName('script')[0];
sc.src='$url';
s.parentNode.insertBefore(sc,s);
}
};
WebP.src='data:image/webp;base64,UklGRjoAAABXRUJQVlA4IC4AAACyAgCdASoCAAIALmk0mk0iIiIiIgBoSygABc6WWgAA/veff/0PP8bA//LwYAAA';
})();
</script>
EOD;
echo $script;
}
add_action( 'wp_head', 'webpexpress_addWebPJs');
*/
//add_action( 'template_redirect', 'webp_express_template_redirect' );