-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstyle.php
107 lines (77 loc) · 2.83 KB
/
style.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
header("Content-type: text/css; charset: UTF-8");
header('Content-type: text/css');
header('Cache-control: must-revalidate');
include_once __DIR__ . '/inc/macro.php';
include_once __DIR__ . '/inc/color.php';
include_once __DIR__ . '../../../../wp-includes/class-wp-error.php';
include_once __DIR__ . '../../../../wp-admin/includes/class-wp-filesystem-base.php';
include_once __DIR__ . '../../../../wp-admin/includes/class-wp-filesystem-direct.php';
use Mexitek\phpColors\Color;
$wp_filesystem = new WP_Filesystem_Direct(null);
/**
Using GET make it more faster, in the header of theme, no need to use SQL/Classes of wordpress here.
*/
if (isset($_GET['gradients']) && !empty($_GET['gradients']))
$gradients = $_GET['gradients'];
if (empty($gradients))
$gradients = '0'; //default;
if (isset($_GET['is_mobile']) && !empty($_GET['is_mobile']))
$is_mobile= $_GET['is_mobile'];
else
$is_mobile= false;
if (isset($_GET['header']) && !empty($_GET['header']))
{
$header_color = $_GET['header'];
if (substr($header_color, 0, 1) === '#')
$header_color = substr($header_color, 1);
}
if (isset($_GET['canvas']) && !empty($_GET['canvas']))
{
$canvas_color = $_GET['canvas'];
if (substr($canvas_color, 0, 1) === '#')
$canvas_color = substr($canvas_color, 1);
}
if (isset($_GET['highlight']) && !empty($_GET['highlight']))
{
$highlight_color = $_GET['highlight'];
if (substr($highlight_color, 0, 1) === '#')
$highlight_color = substr($highlight_color, 1);
}
class MyCssMacro extends CssMacro
{
public function load_values($filename) {
global $wp_filesystem;
$this->parse_values($wp_filesystem->get_contents($filename));
}
}
$css_macro = new MyCssMacro();
$css_macro->load_values(__DIR__.'/style.ini'); //load default values
if (array_key_exists('import', $css_macro->values))
$import = $css_macro->values['import'];
else
$import = '';
$css_macro->set('gradients', $gradients);
$css_macro->set('is_mobile', $is_mobile);
if (isset($_GET['font_size']) && !empty($_GET['font_size']))
$css_macro->set('font_size', $_GET['font_size']);
if (!empty($header_color))
$css_macro->set('header_back', '#'.$header_color);
if (!empty($canvas_color))
$css_macro->set('canvas_back', '#'.$canvas_color);
else
$canvas_color = $css_macro->values['canvas_back'];
$contrast = $css_macro->values['contrast'];
if (isset($_GET['contrast']) && !empty($_GET['contrast']))
$contrast = $_GET['contrast'];
$co = new Color($canvas_color);
if ($co->isLight())
$contrast = $contrast;
else
$contrast = -$contrast;
$css_macro->contrast = $contrast;
if (!empty($highlight_color))
$css_macro->set('highlight', '#'.$highlight_color);
$file = $wp_filesystem->get_contents(__DIR__.'/css/style.css');
echo $css_macro->generate($file);
?>