PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 3.2.5
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v3.2.5
4.7.0 4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 All 111 releases
wp-optimize / vendor / rosell-dk / webp-convert-cloud-service / src / WebPConvertCloudService.php

WebPConvertCloudService.php in WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance 3.2.5, at vendor/rosell-dk/webp-convert-cloud-service/src/WebPConvertCloudService.php

114 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 *
5 * @link https://github.com/rosell-dk/webp-convert-cloud-service
6 * @license MIT
7 */
8
9 namespace WebPConvertCloudService;
10
11 use WebPConvertCloudService\Serve;
12 use WebPConvertCloudService\AccessCheck;
13
14 class WebPConvertCloudService
15 {
16 public $options;
17
18 const ERROR_CONFIGURATION = 0;
19 const ERROR_ACCESS_DENIED = 1;
20 const ERROR_RUNTIME = 2;
21
22 /*
23 example yaml:
24
25 destination-dir: '../conversions'
26 access:
27 allowed-hosts:
28 - bitwise-it.dk
29 allowed-ips:
30 - 127.0.0.1
31 secret: 'my dog is white'
32
33 whitelist:
34 -
35 label: 'rosell.dk'
36 ip: 212.14.2.1
37 secret: 'aoeuth8aoeuh'
38 -
39 label: 'public'
40 secret: '9tita8hoetua'
41
42 webp-convert:
43 quality: 80
44 ...
45 */
46 /*
47 public function loadConfig()
48 {
49 $configDir = __DIR__;
50
51 $parentFolders = explode('/', $configDir);
52 $poppedFolders = [];
53
54 while (!(file_exists(implode('/', $parentFolders) . '/wpc-config.yaml')) && count($parentFolders) > 0) {
55 array_unshift($poppedFolders, array_pop($parentFolders));
56 }
57 if (count($parentFolders) == 0) {
58 self::exitWithError(
59 WebPConvertCloudService::ERROR_SERVER_SETUP,
60 'wpc-config.yaml not found in any parent folders.'
61 );
62 }
63 $configFilePath = implode('/', $parentFolders) . '/wpc-config.yaml';
64
65 try {
66 $options = \Spyc::YAMLLoad($configFilePath);
67 } catch (\Exception $e) {
68 self::exitWithError(WebPConvertCloudService::ERROR_SERVER_SETUP, 'Error parsing wpc-config.yaml.');
69 }
70 }*/
71
72 public static function exitWithError($errorCode, $msg)
73 {
74 $returnObject = [
75 'success' => 0,
76 'errorCode' => $errorCode,
77 'errorMessage' => $msg,
78 ];
79 echo json_encode($returnObject);
80 exit;
81 }
82
83 public static function handleRequest($options)
84 {
85 //$this->options = static::loadConfig();
86 if (!isset($options)) {
87 self::exitWithError(self::ERROR_SERVER_SETUP, 'No options was supplied');
88 }
89
90 $action = (isset($_POST['action']) ? $_POST['action'] : 'convert');
91
92 // Handle actions that does not require access check
93
94 switch ($action) {
95 case 'api-version':
96 echo '2';
97 exit;
98 }
99
100 AccessCheck::runAccessChecks($options);
101
102 // Handle actions that requires access check
103
104 switch ($action) {
105 case 'check-access':
106 echo "You have access!\n";
107 break;
108 case 'convert':
109 Serve::serve($options);
110 break;
111 }
112 }
113 }
114