1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Palettes plugin.
|
6 |
|
|
*/
|
7 |
|
|
class sweaver_plugin_palettes extends sweaver_plugin {
|
8 |
|
|
|
9 |
|
|
/**
|
10 |
|
|
* Frontend css and js.
|
11 |
|
|
*/
|
12 |
|
|
public function sweaver_form_css_js(&$inline_settings) {
|
13 |
|
|
drupal_add_js(drupal_get_path('module', 'sweaver') .'/plugins/sweaver_plugin_palettes/sweaver_plugin_palettes.js');
|
14 |
|
|
}
|
15 |
|
|
|
16 |
|
|
/**
|
17 |
|
|
* Preprocess page function.
|
18 |
|
|
*/
|
19 |
|
|
function sweaver_preprocess_page(&$vars) {
|
20 |
|
|
// Get active palette.
|
21 |
|
|
$current_style = Sweaver::get_instance()->get_current_style();
|
22 |
|
|
$active_palette = isset($current_style->palette) ? $current_style->palette : '';
|
23 |
|
|
|
24 |
|
|
// Add the correct stylesheet if an active palette is found.
|
25 |
|
|
if (!empty($active_palette)) {
|
26 |
|
|
$theme_key = Sweaver::get_instance()->get_theme_key();
|
27 |
|
|
$info = db_query("SELECT info FROM {system} WHERE name = :theme AND type ='theme'", array(':theme' => $theme_key))->fetchField();
|
28 |
|
|
$theme_info = unserialize($info);
|
29 |
|
|
|
30 |
|
|
if (isset($theme_info['sweaver']['palettes'][$active_palette])) {
|
31 |
|
|
$css = drupal_get_path('theme', $theme_key) . '/' . $theme_info['sweaver']['palettes'][$active_palette]['file'];
|
32 |
|
|
$settings = array(
|
33 |
|
|
'weight' => 1001,
|
34 |
|
|
'preprocess' => TRUE,
|
35 |
|
|
'group' => CSS_THEME,
|
36 |
|
|
);
|
37 |
|
|
drupal_add_css($css, $settings);
|
38 |
|
|
}
|
39 |
|
|
}
|
40 |
|
|
}
|
41 |
|
|
|
42 |
|
|
/**
|
43 |
|
|
* Frontend form.
|
44 |
|
|
*/
|
45 |
|
|
public function sweaver_form() {
|
46 |
|
|
|
47 |
|
|
$current_style = Sweaver::get_instance()->get_current_style();
|
48 |
|
|
$active_palette = isset($current_style->palette) ? $current_style->palette : '';
|
49 |
|
|
|
50 |
|
|
global $base_path;
|
51 |
|
|
$form = array();
|
52 |
|
|
$containers = '';
|
53 |
|
|
$theme_key = Sweaver::get_instance()->get_theme_key();
|
54 |
|
|
$theme_info = sweaver_get_theme_info($theme_key);
|
55 |
|
|
|
56 |
|
|
if (isset($theme_info['sweaver']['palettes'])) {
|
57 |
|
|
|
58 |
|
|
// Combine all properties in containers.
|
59 |
|
|
$i = 0;
|
60 |
|
|
$container_count = 1;
|
61 |
|
|
$container_total = ceil(count($theme_info['sweaver']['palettes'])/5);
|
62 |
|
|
|
63 |
|
|
$containers .= '<div class="container-wrapper">';
|
64 |
|
|
|
65 |
|
|
foreach ($theme_info['sweaver']['palettes'] as $key => $palette) {
|
66 |
|
|
if ($i == 0) {
|
67 |
|
|
// Add first/last classes to the containers.
|
68 |
|
|
$container_class = '';
|
69 |
|
|
if ($container_count == 1) {
|
70 |
|
|
$container_class .= ' container-first';
|
71 |
|
|
}
|
72 |
|
|
if ($container_total == $container_count) {
|
73 |
|
|
$container_class .= ' container-last';
|
74 |
|
|
}
|
75 |
|
|
$containers .= '<div class="container '. $container_class .'"><div class="container-inner">';
|
76 |
|
|
}
|
77 |
|
|
// Add the actual content.
|
78 |
|
|
$extra_class = ($active_palette == $key ? ' active' : '');
|
79 |
|
|
$containers .= '<div id="palette-' . $key .'" class="colors clearfix'. $extra_class .'">';
|
80 |
|
|
|
81 |
|
|
foreach ($palette['colors'] as $color) {
|
82 |
|
|
$containers .= '<div class="color" style="background-color:'. $color .' !important">'. $color .'</div>';
|
83 |
|
|
}
|
84 |
|
|
$containers .= '<div class="name">'. $palette['name'] .'</div>';
|
85 |
|
|
|
86 |
|
|
// Add a hidden field with the path to the css file.
|
87 |
|
|
$containers .= '<div class="file" style="display: none;">'. $base_path . drupal_get_path('theme', $theme_key) .'/'. $palette['file'] .'</div>';
|
88 |
|
|
|
89 |
|
|
// Add a hidden field with the key.
|
90 |
|
|
$containers .= '<div class="key" style="display: none;">'. $key .'</div>';
|
91 |
|
|
$containers .= '</div>';
|
92 |
|
|
$i++;
|
93 |
|
|
// close the container div if necessary.
|
94 |
|
|
if ($i == 5) {
|
95 |
|
|
$containers .= '</div></div>';
|
96 |
|
|
$container_count++;
|
97 |
|
|
$i = 0;
|
98 |
|
|
}
|
99 |
|
|
}
|
100 |
|
|
if ($i != 0) {
|
101 |
|
|
$containers .= '</div></div>';
|
102 |
|
|
}
|
103 |
|
|
$containers .= '</div>';
|
104 |
|
|
|
105 |
|
|
// Add a hidden field that stores the active key to be saved.
|
106 |
|
|
$form['sweaver_plugin_palette'] = array(
|
107 |
|
|
'#type' => 'hidden',
|
108 |
|
|
'#default_value' => $active_palette ? $active_palette : '',
|
109 |
|
|
);
|
110 |
|
|
|
111 |
|
|
$form['markup'] = array(
|
112 |
|
|
'#markup' => $containers,
|
113 |
|
|
);
|
114 |
|
|
}
|
115 |
|
|
|
116 |
|
|
return $form;
|
117 |
|
|
}
|
118 |
|
|
|
119 |
|
|
/**
|
120 |
|
|
* Frontend form submit handler.
|
121 |
|
|
*/
|
122 |
|
|
function sweaver_form_submit($form, &$form_state) {
|
123 |
|
|
$clicked_button = $form_state['clicked_button']['#value'];
|
124 |
|
|
|
125 |
|
|
if (($clicked_button == t('Save and continue') || $clicked_button == t('Save and publish') || $clicked_button == t('Publish style')) && isset($form_state['style_id']) && isset($form_state['values']['sweaver_plugin_palette'])) {
|
126 |
|
|
db_query("UPDATE {sweaver_style_draft} set palette = :palette WHERE style_id = :style_id", array(':palette' => $form_state['values']['sweaver_plugin_palette'], ':style_id' => $form_state['style_id']));
|
127 |
|
|
if ($form_state['publish']) {
|
128 |
|
|
db_query("UPDATE {sweaver_style} set palette = :palette WHERE style_id = :style_id", array(':palette' => $form_state['values']['sweaver_plugin_palette'], ':style_id' => $form_state['style_id']));
|
129 |
|
|
}
|
130 |
|
|
}
|
131 |
|
|
}
|
132 |
|
|
} |