-
Notifications
You must be signed in to change notification settings - Fork 3
/
Processor.php
executable file
·92 lines (73 loc) · 2.35 KB
/
Processor.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
84
85
86
87
88
89
90
91
92
<?php
class Processor extends PluginObject {
public $type;
public $style;
public $updated_style;
public $message = array();
private $request_array;
function __construct( $style ) {
$this->request_array = $_POST;
$this->style = $style;
$this->type = isset( $this->request_array['request'] ) ? $this->request_array['request'] : null;
if ( isset( $this->type ) ) {
$this->message["placement"] = $this->type;
$this->{"_init_".$this->type}();
$this->updated_style = true;
}
}
private function _init_compile() {
require_once( "Compiler.php" );
$compress = isset($this->request_array["compress"]) ? $this->request_array["compress"] : false;
$this->compiler = new Compiler( $this->style, $this->request_array["css_text"], $compress);
try {
$this->compiler->compile();
} catch (Exception $e) {
$this->message["text"] = "<strong>Error:</strong> Compile failed: ".$e->getMessage();
$this->message["type"] = "error";
}
if ( $this->compiler->is_compiled() ) {
$this->message["text"] = "CSS compiled successfully.";
$this->message["type"] = "updated";
$this->_save_css_version();
$this->_save_new_style_hash();
}
}
private function _save_css_version() {
self::_set_wp_option("css-version", time());
}
private function _save_new_style_hash() {
$style = self::_get_wp_option("asset");
$this->style->css->hash = $this->style->css->generate_hash();
$style["css"]["hash"] = $this->style->css->hash;
self::_set_wp_option( "asset", $style );
}
private function _init_save() {
$this->style = new SettingsStyle( $this->request_array );
$this->_set_frontend_views( $this->request_array['view'] );
$this->_save();
}
private function _save() {
self::_set_wp_option( "asset", $this->style->become_array() );
self::_set_wp_option( "public-view", $this->public_view );
self::_set_wp_option( "admin-view", $this->admin_view );
$this->message["text"] = "Settings saved successfully.";
$this->message["type"] = "updated";
}
private function _set_frontend_views( $view_type ) {
switch ( $view_type ) {
case "css":
case "less":
$this->admin_view = $view_type;
$this->public_view = $view_type;
break;
case "variable":
$this->admin_view = "less";
$this->public_view = "css";
break;
default:
$this->admin_view = "css";
$this->public_view = "css";
}
}
}
?>