dynamic_css.php
3.74 KB
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
108
109
110
111
112
113
114
115
116
117
118
<?php
function wpcss_get_dynamic_css()
{
$output="";
if(isset($_GET['step_id'])) {
//preview mode
$wpcss_current_settings_array=csshero_get_configuration_array($_GET['step_id']);
}
else
{ //standard mode
$wpcss_current_settings_array=csshero_get_configuration_array();
}
//REORDER
$sortable_array = (array) $wpcss_current_settings_array;
ksort($sortable_array);
$wpcss_current_settings_array=$sortable_array;
//END REORDER
// print_r($wpcss_current_settings_array);die;
//init refactoring array
$wpcss_CSS_generator_array=array();
if ($wpcss_current_settings_array) foreach ($wpcss_current_settings_array as $option_slug=>$new_css_row):
//print_r($new_css_row);
//if (!is_array($new_css_row)) continue; //skip meta tags like theme name and version
$this_selector=$new_css_row->property_target;
$wpcss_CSS_generator_array[$this_selector][]=$new_css_row;
endforeach;
//print_r($wpcss_CSS_generator_array);
///NUOVO ARRAY DI REFACTORING
foreach($wpcss_CSS_generator_array as $this_selector=>$this_properties):
if (($this_selector=='')) continue;
$output.= $this_selector. " {";
foreach ($this_properties as $this_selector_rows): //print_r($this_property_rule);
if (isset($this_selector_rows->media_query) AND $this_selector_rows->media_query!="") continue;
//if ($this_selector_rows->property_value=="") continue;
if (isset($this_selector_rows->needs_important)) $important="!important"; else $important="";
$output.= "\n ".$this_selector_rows->property_name.": ".$this_selector_rows->property_value.$important."; ";
endforeach;
$output.= "\n } \n\n";
endforeach;
//MEDIA QUERY
if ($wpcss_current_settings_array) foreach ($wpcss_current_settings_array as $option_slug=>$new_css_row):
if (!isset( $new_css_row->media_query) OR $new_css_row->media_query=="") continue;
//if ($this_selector_rows->property_value=="") continue; //da riaggiungere e pure bene
$this_selector=$new_css_row->property_target;
if (isset($new_css_row->needs_important)) $important="!important"; else $important="";
$output.= "\n".$new_css_row->media_query." { " .$this_selector. " { ".$new_css_row->property_name.": ".$new_css_row->property_value.$important."; } } ";
endforeach;
return $output;
} //end function
function wpcss_generate_static_css()
{
//CLEAR OLD CACHE
$old_uploaded=get_option('wpcss_static_css_data');
if (is_array($old_uploaded) && isset($old_uploaded['file']) ) unlink($old_uploaded['file']);
//BUILD CACHE
$uploaded= wp_upload_bits( "csshero-style.css", FALSE, wpcss_get_dynamic_css() );
if ($uploaded['error']==FALSE) {
//echo "<h3>Uploaded ok</h3>";
//echo "File URL : ".$uploaded['url'];
wpcss_update_option('wpcss_static_css_data',$uploaded);
} else {
//SOME ERROR GOING ON
echo " <h1 style='text-align:center'>Error saving CSS file:".$uploaded['error']." - Cache disabled.</h1>";
wpcss_update_option('csshero_css_caching',0);
}
} //end function
?>