1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Page Layout CSS Builder.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
global $theme_key, $theme_name;
|
9 |
|
|
$theme_name = $theme_key;
|
10 |
|
|
$path_to_at_core = drupal_get_path('theme', 'adaptivetheme');
|
11 |
|
|
require_once($path_to_at_core . '/inc/plugins.inc');
|
12 |
|
|
|
13 |
|
|
/**
|
14 |
|
|
* Build Page Layouts
|
15 |
|
|
*
|
16 |
|
|
* Unlike the Panels layouts which hold CSS in their data array the Page layout
|
17 |
|
|
* plugins each include a unique CSS builder function. This is required because
|
18 |
|
|
* page layouts are all bespoke and can accept arbitrary user input for the
|
19 |
|
|
* sidebar widths and must support three value units - pixles, em's and
|
20 |
|
|
* percentages. In other words building a one-size-fits-all builder function
|
21 |
|
|
* would be overly complex and its far more flexible for themers to be able to
|
22 |
|
|
* define thier own.
|
23 |
|
|
*
|
24 |
|
|
* As values come in from the submit function they are dispatched to the right
|
25 |
|
|
* builder function.
|
26 |
|
|
*
|
27 |
|
|
* @param $method, tells the function which layout builder function to call.
|
28 |
|
|
* @param $sidebar_first, an arbitrary numeric value.
|
29 |
|
|
* @param $sidebar_second, an arbitrary numeric value.
|
30 |
|
|
* @param $sidebar_unit, one of px, em or %.
|
31 |
74f6bef0
|
Assos Assos
|
* @param $theme_name, the active theme.
|
32 |
85ad3d82
|
Assos Assos
|
*
|
33 |
|
|
* @see three_col_grail_layout() for an example of a builder function with docs.
|
34 |
|
|
*/
|
35 |
74f6bef0
|
Assos Assos
|
function at_build_page_layout($method, $sidebar_first, $sidebar_second, $sidebar_unit, $theme_name = NULL) {
|
36 |
|
|
// Use the passed in theme_name, else grab it from global $theme_key
|
37 |
|
|
if ($theme_name == NULL) {
|
38 |
|
|
global $theme_key;
|
39 |
|
|
$theme_name = $theme_key;
|
40 |
|
|
}
|
41 |
|
|
|
42 |
85ad3d82
|
Assos Assos
|
$output = '';
|
43 |
|
|
|
44 |
|
|
// We need to invoke at_load_plugins() to get the function names, this is
|
45 |
|
|
// rather expensive but we're in a submit function so IMO this is OK.
|
46 |
|
|
at_load_plugins($theme_name, $plugin_type = 'page_layout');
|
47 |
|
|
|
48 |
74f6bef0
|
Assos Assos
|
$builder_functions = responsive_page_layouts_data_structure($theme_name);
|
49 |
85ad3d82
|
Assos Assos
|
|
50 |
|
|
foreach ($builder_functions as $function_prefix => $redundant_values) {
|
51 |
|
|
if ($method === $function_prefix) {
|
52 |
|
|
$function = $function_prefix . '_layout';
|
53 |
|
|
$output = $function($sidebar_first, $sidebar_second, $sidebar_unit);
|
54 |
|
|
}
|
55 |
|
|
}
|
56 |
|
|
|
57 |
|
|
return $output;
|
58 |
|
|
}
|
59 |
|
|
|
60 |
|
|
/**
|
61 |
|
|
* Panels CSS Builder, programatically builds and optimizes CSS.
|
62 |
|
|
*
|
63 |
|
|
* Adaptivetheme panels layout plugins do not have CSS files, instead the CSS is
|
64 |
|
|
* held in the data structure inside the actual plugin inc file. This data is
|
65 |
|
|
* extracted, compared and output for all panel layouts per device type. The CSS
|
66 |
|
|
* is highly optimized with no repetition of style declarations. The output is
|
67 |
|
|
* embedded within media queries (or not, depending on theme settings) and
|
68 |
|
|
* printed to file.
|
69 |
|
|
*
|
70 |
|
|
* @param $panel_styles
|
71 |
|
|
* @param $device_panels_data
|
72 |
|
|
*
|
73 |
|
|
* @see adaptivetheme_five_5x20_panels_layouts() for an example of the CSS in
|
74 |
|
|
* the data array with good docs and guidelines.
|
75 |
|
|
*/
|
76 |
|
|
function at_build_panels_layout_css($panel_styles, $device_panels_data) {
|
77 |
|
|
$output = '';
|
78 |
|
|
$declarations = $these_groups = $these_selectors_styles = array();
|
79 |
|
|
|
80 |
|
|
foreach ($panel_styles as $panel_subtypes_data) {
|
81 |
|
|
foreach ($panel_subtypes_data as $panel_subtype => $panel_subtype_styles_data) {
|
82 |
|
|
if (in_array($panel_subtype, $device_panels_data)) {
|
83 |
|
|
foreach ($panel_subtype_styles_data as $data_type_array) {
|
84 |
|
|
foreach ($data_type_array as $declaration_type => $declaration_block) {
|
85 |
|
|
foreach ($declaration_block as $selector => $declaration) {
|
86 |
|
|
$selectors[$declaration_type][] = $selector;
|
87 |
|
|
$declarations[$declaration_type] = array($declaration_type => $declaration);
|
88 |
|
|
}
|
89 |
|
|
}
|
90 |
|
|
}
|
91 |
|
|
}
|
92 |
|
|
}
|
93 |
|
|
}
|
94 |
|
|
foreach ($declarations as $type => $groups) {
|
95 |
|
|
foreach ($groups as $group) {
|
96 |
|
|
$these_groups[$group] = $selectors[$type];
|
97 |
|
|
}
|
98 |
|
|
}
|
99 |
|
|
foreach ($these_groups as $css_styles => $selector_array) {
|
100 |
|
|
$merged_css = $css_styles;
|
101 |
|
|
$these_selectors_styles[] = implode(',', $selector_array) . ' {' . $merged_css . '}';
|
102 |
|
|
}
|
103 |
|
|
|
104 |
|
|
$output = implode('', $these_selectors_styles);
|
105 |
|
|
return $output;
|
106 |
|
|
}
|
107 |
|
|
|
108 |
|
|
/**
|
109 |
|
|
* Build font family CSS.
|
110 |
|
|
*
|
111 |
|
|
* @param $element
|
112 |
|
|
* @param $selector
|
113 |
|
|
* @param $font_values
|
114 |
|
|
*/
|
115 |
|
|
function at_build_font_families($element, $selector, $font_values) {
|
116 |
|
|
$output = '';
|
117 |
|
|
|
118 |
|
|
// Format values as valid CSS
|
119 |
|
|
$font_styles = array();
|
120 |
|
|
if (!empty($font_values)) {
|
121 |
|
|
if (isset($font_values['font_size']) && $font_values['font_size'] === '<none>') {
|
122 |
|
|
$font_values['font_size'] = '';
|
123 |
|
|
}
|
124 |
|
|
$font_styles[] = $font_values['font_style'] ? 'font-style:' . $font_values['font_style'] . ';' : '';
|
125 |
|
|
$font_styles[] = $font_values['font_weight'] ? 'font-weight:' . $font_values['font_weight'] . ';' : '';
|
126 |
|
|
$font_styles[] = $font_values['font_size'] ? 'font-size:' . $font_values['font_size'] . ';' : '';
|
127 |
|
|
$font_styles[] = $font_values['font_family'] ? 'font-family:' . $font_values['font_family'] : '';
|
128 |
|
|
}
|
129 |
|
|
$font_styles = implode('', $font_styles);
|
130 |
|
|
|
131 |
|
|
$css = array();
|
132 |
|
|
switch ($element) {
|
133 |
|
|
case $element:
|
134 |
|
|
if ($font_styles) {
|
135 |
|
|
$css[] = $selector . '{' . $font_styles . '}';
|
136 |
|
|
}
|
137 |
|
|
break;
|
138 |
|
|
}
|
139 |
|
|
|
140 |
|
|
$output = implode("\n", $css);
|
141 |
|
|
return $output;
|
142 |
|
|
} |