1 |
d7f58da2
|
Florent Torregrosa
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Build and save the responsive layout.
|
6 |
|
|
*
|
7 |
|
|
* This is the main submit handler for building the layout.
|
8 |
|
|
* The output is a stylesheet saved to public
|
9 |
|
|
* files - the main responsive layout.
|
10 |
|
|
*/
|
11 |
|
|
function mayo_submit_reponsive($values, $theme_name, $path) {
|
12 |
|
|
global $_path_to_mayo;
|
13 |
|
|
// Set up some paths we use to get and save files
|
14 |
|
|
$path_to_responsive_css = drupal_get_path('theme', $theme_name) . '/css/';
|
15 |
|
|
$path_to_panels_css = $_path_to_mayo . '/layouts/css/';
|
16 |
|
|
|
17 |
|
|
// Get the page layout config array
|
18 |
|
|
$layout_variables = assemble_page_layout();
|
19 |
|
|
|
20 |
|
|
// $layouts will hold all the page level layouts
|
21 |
|
|
$layouts = array();
|
22 |
|
|
|
23 |
|
|
// Initialize the $is_default_layout variable, we use this to test against
|
24 |
|
|
$is_default_layout = 'smalltouch-portrait';
|
25 |
|
|
|
26 |
|
|
// Holds all styles from the responsive stylesheets
|
27 |
|
|
$responsive_styles = array();
|
28 |
|
|
|
29 |
|
|
// Smalltouch Landscape
|
30 |
|
|
if ($values['smalltouch_landscape_layout']) {
|
31 |
|
|
|
32 |
|
|
$device = 'smalltouch_landscape';
|
33 |
|
|
|
34 |
|
|
// Build an array of page layout settings values
|
35 |
|
|
foreach ($layout_variables as $key => $value) {
|
36 |
|
|
if (isset($values["$device" . '_' . "$value"])) {
|
37 |
|
|
$smalltouch_landscape_layout_data[$value] = check_plain($values["$device" . '_' . "$value"]);
|
38 |
|
|
}
|
39 |
|
|
}
|
40 |
|
|
$layout = mayo_build_page_layout($smalltouch_landscape_layout_data['layout'], $smalltouch_landscape_layout_data['sidebar_first'], $smalltouch_landscape_layout_data['sidebar_second'], $smalltouch_landscape_layout_data['sidebar_unit'], $theme_name);
|
41 |
|
|
|
42 |
|
|
$method = $smalltouch_landscape_layout_data['layout'];
|
43 |
|
|
$comment = "/* $device $method */\n";
|
44 |
|
|
$width = "\n" . '#page-wrapper {width:' . $smalltouch_landscape_layout_data['page_width'] . $smalltouch_landscape_layout_data['page_unit'] . '}';
|
45 |
|
|
$media_query = $smalltouch_landscape_layout_data['media_query'];
|
46 |
|
|
|
47 |
|
|
// Build the styles string
|
48 |
|
|
$styles = $width . "\n" . $layout;
|
49 |
|
|
|
50 |
|
|
// CSS wrapped in the media query
|
51 |
|
|
$css = $comment . '@media ' . $media_query . ' {' . $styles . "\n" . '}';
|
52 |
|
|
|
53 |
|
|
// Get and wrap the responsive CSS styles in the relative media query
|
54 |
|
|
$responsive_smalltouch_landscape_css = '';
|
55 |
|
|
$layouts[] = $css;
|
56 |
|
|
}
|
57 |
|
|
|
58 |
|
|
// Tablet Portrait
|
59 |
|
|
if ($values['tablet_portrait_layout']) {
|
60 |
|
|
|
61 |
|
|
$device = 'tablet_portrait';
|
62 |
|
|
|
63 |
|
|
// Build an array of page layout settings values
|
64 |
|
|
foreach ($layout_variables as $key => $value) {
|
65 |
|
|
if (isset($values["$device" . '_' . "$value"])) {
|
66 |
|
|
$tablet_portrait_layout_data[$value] = check_plain($values["$device" . '_' . "$value"]);
|
67 |
|
|
}
|
68 |
|
|
}
|
69 |
|
|
// Workaround upgrade issues for some settings
|
70 |
|
|
if ($tablet_portrait_layout_data['layout'] == 'two_col_stack') {
|
71 |
|
|
$tablet_portrait_layout_data['layout'] = 'two_sidebars_right_stack';
|
72 |
|
|
}
|
73 |
|
|
$layout = mayo_build_page_layout($tablet_portrait_layout_data['layout'], $tablet_portrait_layout_data['sidebar_first'], $tablet_portrait_layout_data['sidebar_second'], $tablet_portrait_layout_data['sidebar_unit'], $theme_name);
|
74 |
|
|
|
75 |
|
|
$method = $tablet_portrait_layout_data['layout'];
|
76 |
|
|
$comment = "/* $device $method */\n";
|
77 |
|
|
$width = "\n" . '#page-wrapper {width:' . $tablet_portrait_layout_data['page_width'] . $tablet_portrait_layout_data['page_unit'] . '}';
|
78 |
|
|
$media_query = $tablet_portrait_layout_data['media_query'];
|
79 |
|
|
|
80 |
|
|
// Build the styles string
|
81 |
|
|
$styles = $width . "\n" . $layout;
|
82 |
|
|
|
83 |
|
|
// CSS wrapped in the media query
|
84 |
|
|
$css = $comment . '@media ' . $media_query . ' {' . $styles . "\n" . '}';
|
85 |
|
|
$layouts[] = $css;
|
86 |
|
|
}
|
87 |
|
|
|
88 |
|
|
// Tablet Landscape
|
89 |
|
|
if ($values['tablet_landscape_layout']) {
|
90 |
|
|
|
91 |
|
|
$device = 'tablet_landscape';
|
92 |
|
|
|
93 |
|
|
// Build an array of page layout settings values
|
94 |
|
|
foreach ($layout_variables as $key => $value) {
|
95 |
|
|
if (isset($values["$device" . '_' . "$value"])) {
|
96 |
|
|
$tablet_landscape_layout_data[$value] = check_plain($values["$device" . '_' . "$value"]);
|
97 |
|
|
}
|
98 |
|
|
}
|
99 |
|
|
// Workaround upgrade issues for some settings
|
100 |
|
|
if ($tablet_portrait_layout_data['layout'] == 'two_col_stack') {
|
101 |
|
|
$tablet_portrait_layout_data['layout'] = 'two_sidebars_right_stack';
|
102 |
|
|
}
|
103 |
|
|
$layout = mayo_build_page_layout($tablet_landscape_layout_data['layout'], $tablet_landscape_layout_data['sidebar_first'], $tablet_landscape_layout_data['sidebar_second'], $tablet_landscape_layout_data['sidebar_unit'], $theme_name);
|
104 |
|
|
|
105 |
|
|
$method = $tablet_landscape_layout_data['layout'];
|
106 |
|
|
$comment = "/* $device $method */\n";
|
107 |
|
|
$width = "\n" . '#page-wrapper {width:' . $tablet_landscape_layout_data['page_width'] . $tablet_landscape_layout_data['page_unit'] . '}';
|
108 |
|
|
$media_query = $tablet_landscape_layout_data['media_query'];
|
109 |
|
|
|
110 |
|
|
// Build the styles string
|
111 |
|
|
$styles = $width . "\n" . $layout;
|
112 |
|
|
|
113 |
|
|
// CSS wrapped in the media query
|
114 |
|
|
$css = $comment . '@media ' . $media_query . ' {' . $styles . "\n" . '}';
|
115 |
|
|
$layouts[] = $css;
|
116 |
|
|
}
|
117 |
|
|
// Standard Layout (bigscreen)
|
118 |
|
|
if ($values['bigscreen_layout']) {
|
119 |
|
|
|
120 |
|
|
$device = 'bigscreen';
|
121 |
|
|
// Build an array of page layout settings values
|
122 |
|
|
foreach ($layout_variables as $key => $value) {
|
123 |
|
|
if (isset($values["$device" . '_' . "$value"])) {
|
124 |
|
|
$bigscreen_layout_data[$value] = check_plain($values["$device" . '_' . "$value"]);
|
125 |
|
|
}
|
126 |
|
|
}
|
127 |
|
|
$layout = mayo_build_page_layout($bigscreen_layout_data['layout'], $bigscreen_layout_data['sidebar_first'], $bigscreen_layout_data['sidebar_second'], $bigscreen_layout_data['sidebar_unit'], $theme_name);
|
128 |
|
|
|
129 |
|
|
$method = $bigscreen_layout_data['layout'];
|
130 |
|
|
$comment = "/* $device $method */";
|
131 |
|
|
$width = "\n" . '#page-wrapper {width:' . $bigscreen_layout_data['page_width'] . $bigscreen_layout_data['page_unit'] . '}';
|
132 |
|
|
$media_query = $bigscreen_layout_data['media_query'];
|
133 |
|
|
|
134 |
|
|
// Standard layout can have a max-width
|
135 |
|
|
$values['bigscreen_set_max_width'] = 0;
|
136 |
|
|
if ($values['bigscreen_set_max_width'] === 1 && $bigscreen_layout_data['page_unit'] === '%') {
|
137 |
|
|
if (!empty($values['bigscreen_max_width'])) {
|
138 |
|
|
$width = "\n" . '#page-wrapper {width:' . $bigscreen_layout_data['page_width'] . $bigscreen_layout_data['page_unit'] . ';max-width:' . $values['bigscreen_max_width'] . $values['bigscreen_max_width_unit'] . '}';
|
139 |
|
|
}
|
140 |
|
|
else {
|
141 |
|
|
$width = "\n" . '#page-wrapper {width:' . $bigscreen_layout_data['page_width'] . $bigscreen_layout_data['page_unit'] . ';max-width:' . $values['bigscreen_max_width'] . $values['bigscreen_max_width_unit'] . '}';
|
142 |
|
|
}
|
143 |
|
|
}
|
144 |
|
|
|
145 |
|
|
// Build the styles string
|
146 |
|
|
$styles = $width . "\n" . $layout;
|
147 |
|
|
$css = $comment . "\n" . '@media ' . $media_query . ' {' . $styles . "\n" . '}';
|
148 |
|
|
|
149 |
|
|
// add $css to the layouts array
|
150 |
|
|
$layouts[] = $css;
|
151 |
|
|
}
|
152 |
|
|
//****** END bigscreen layout ******//
|
153 |
|
|
|
154 |
|
|
// Get and wrap the responsive CSS styles in the relative media query
|
155 |
|
|
// responsive layout
|
156 |
|
|
$responsive_layout_data = implode("\n", $layouts);
|
157 |
|
|
$responsive_layout = $responsive_layout_data;
|
158 |
|
|
|
159 |
|
|
// Aggregate the design stylesheets
|
160 |
|
|
$responsive_css = implode("\n", $responsive_styles);
|
161 |
|
|
|
162 |
|
|
// Regex relative paths. This mimics Drupal core drupal_build_css_cache(), but
|
163 |
|
|
// its not as powerful because assets must be relative to the theme root.
|
164 |
|
|
$_base = base_path() . $path_to_responsive_css;
|
165 |
|
|
_drupal_build_css_path(NULL, $_base);
|
166 |
|
|
$responsive_css = preg_replace_callback('/url\(\s*[\'"]?(?![a-z]+:|\/+)([^\'")]+)[\'"]?\s*\)/i', '_drupal_build_css_path', $responsive_css);
|
167 |
|
|
|
168 |
|
|
// Build a keyed array: file names as key, layout data as value
|
169 |
|
|
$files = array(
|
170 |
|
|
"$theme_name.responsive.layout" => $responsive_layout,
|
171 |
|
|
);
|
172 |
|
|
|
173 |
|
|
// Loop over the array and save each file, and we're done!
|
174 |
|
|
foreach ($files as $key => $value) {
|
175 |
|
|
$filepath = "$path/$key.css";
|
176 |
|
|
file_unmanaged_save_data($value, $filepath, FILE_EXISTS_REPLACE);
|
177 |
|
|
}
|
178 |
|
|
} |