PluginProbe
Customify / 1.5.1
Customify v1.5.1
2.10.9 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.7.1 1.3.0 1.3.1 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.6.0 1.6.0.1 1.6.5 1.7.0 1.7.1 All 77 releases
customify / features / customizer / controls / class-Pix_Customize_Preset_Control.php

class-Pix_Customize_Preset_Control.php in Customify 1.5.1, at features/customizer/controls/class-Pix_Customize_Preset_Control.php

223 lines 8.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Class Pix_Customize_Preset_Control
5 * A simple Select2 Control
6 */
7 class Pix_Customize_Preset_Control extends Pix_Customize_Control {
8 public $type = 'preset';
9 public $choices_type = 'select';
10 public $description = null;
11
12 /**
13 * Render the control's content.
14 *
15 * @since 3.4.0
16 */
17 public function render_content() {
18
19 switch ( $this->choices_type ) {
20
21 case 'select' : { ?>
22 <label>
23 <?php if ( ! empty( $this->label ) ) { ?>
24 <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
25 <?php }
26 if ( ! empty( $this->description ) ) { ?>
27 <span class="description customize-control-description"><?php echo $this->description; ?></span>
28 <?php } ?>
29
30 <select <?php $this->link(); ?> class="customify_preset select">
31 <?php
32 foreach ( $this->choices as $value => $setts ){
33 if ( ! isset( $setts['options']) || ! isset( $setts['label'] ) ) {
34 continue;
35 }
36 $label = $setts['label'];
37 $options = $setts['options'];
38 $data = ' data-options=\'' . json_encode($options) . '\'';
39 echo '<option value="' . esc_attr( $value ) . '"' . selected( $this->value(), $value, false ) . $data . ' >' . $label . '</option>';
40 } ?>
41 </select>
42 </label>
43 <?php break;
44 }
45
46 case 'radio' : { ?>
47 <label>
48 <?php if ( ! empty( $this->label ) ) { ?>
49 <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
50 <?php }
51 if ( ! empty( $this->description ) ) { ?>
52 <span class="description customize-control-description"><?php echo $this->description; ?></span>
53 <?php } ?>
54
55 <div class="customify_preset radio">
56 <?php
57 foreach ( $this->choices as $value => $setts ){
58 if ( ! isset( $setts['options']) || ! isset( $setts['label'] ) ) {
59 continue;
60 }
61 $color = '';
62 if ( isset( $setts['color'] ) ) {
63 $color .= ' style="background-color: ' . $setts['color'] . '"';
64 }
65
66 $label = $setts['label'];
67 $options = $setts['options'];
68 $data = ' data-options=\'' . json_encode($options) . '\'';?>
69 <input <?php $this->link(); echo 'name="' . $this->setting->id . '" type="radio" value="' . esc_attr( $value ) . '"' . selected( $this->value(), $value, false ) . $data . $color .' >' . $label . '</input>';
70 } ?>
71 </div>
72 </label>
73 <?php break;
74 }
75
76 case 'buttons' : { ?>
77 <label>
78 <?php if ( ! empty( $this->label ) ) { ?>
79 <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
80 <?php }
81 if ( ! empty( $this->description ) ) { ?>
82 <span class="description customize-control-description"><?php echo $this->description; ?></span>
83 <?php } ?>
84
85 <div class="customify_preset radio_buttons">
86 <?php
87 foreach ( $this->choices as $value => $setts ){
88 if ( ! isset( $setts['options']) || ! isset( $setts['label'] ) ) {
89 continue;
90 }
91 $color = '';
92 if ( isset( $setts['color'] ) ) {
93 $color .= ' style="border-left-color: ' . $setts['color'] . '; color: ' . $setts['color'] . ';"';
94 }
95
96 $label = $setts['label'];
97 $options = $setts['options'];
98 $data = ' data-options=\'' . json_encode($options) . '\'';?>
99
100 <fieldset class="customify_radio_button">
101 <input <?php $this->link(); echo 'name="' . $this->setting->id . '" type="radio" value="' . esc_attr( $value ) . '"' . selected( $this->value(), $value, false ) . $data .' />'; ?>
102 <label class="button" for="<?php echo $this->setting->id; ?>" <?php echo $color; ?>>
103 <?php echo $label; ?>
104 </label>
105 </fieldset>
106 <?php } ?>
107 </div>
108 </label>
109 <?php break;
110 }
111
112 case 'awesome' : { ?>
113 <label>
114 <?php if ( ! empty( $this->label ) ) { ?>
115 <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
116 <?php } ?>
117
118 <div class="customify_preset awesome_presets">
119 <?php
120
121 $google_links = array();
122
123 foreach ( $this->choices as $value => $setts ){
124 if ( ! isset( $setts['options']) || ! isset( $setts['label'] ) ) {
125 continue;
126 }
127
128 $preset_style = ' style="background-color: #444;';
129 $preset_name_style = ' style=" color: #000; background-color: #ccc; border-color: #aaa;';
130 $preset_text_color = ' style=" color: #ebebeb';
131
132 $first_font = $second_font = '';
133 if ( isset( $setts['preview'] ) ) {
134
135 if ( isset( $setts['preview']['background-card'] ) ) {
136 $preset_style = ' style="';
137 $preset_style .= 'background-color: ' . $setts['preview']['background-card'] . ';';
138 }
139
140 if ( isset( $setts['preview']['background-label'] ) ) {
141
142 $this_preset_color = $setts['preview']['background-label'];
143
144 if ( $this->isLight( $this_preset_color ) ) {
145 $this_preset_color = '#000000';
146 } else {
147 $this_preset_color = '#ffffff';
148 }
149 $preset_name_style = ' style="';
150 $preset_name_style .= 'color: ' .$this_preset_color . ';background-color: ' . $setts['preview']['background-label'] . '; border-color: ' . $setts['preview']['background-label'];
151 }
152
153 if ( isset( $setts['preview']['color-text'] ) ) {
154 $preset_text_color = ' style="';
155 $preset_text_color .= 'color: ' . $setts['preview']['color-text'] . ';"';
156 }
157
158 if ( isset( $setts['preview']['font-main'] ) ) {
159 $first_font = ' style="font-family: ' . $setts['preview']['font-main'] . '"' ;
160 $google_links[] = str_replace( ' ', '+', $setts['preview']['font-main'] );
161 }
162
163 if ( isset( $setts['preview']['font-alt'] ) ) {
164 $second_font = ' style="font-family: ' . $setts['preview']['font-alt'] . '"' ;
165 $google_links[] = str_replace( ' ', '+', $setts['preview']['font-alt'] );
166 }
167 }
168
169 $preset_style .= '"';
170 $preset_text_color .= '"';
171 $preset_name_style .= '"';
172
173 $label = $setts['label'];
174 $options = $setts['options'];
175 $data = ' data-options=\'' . json_encode($options) . '\'';?>
176 <div class="awesome_preset" <?php echo $preset_text_color; ?>>
177 <input <?php $this->link(); echo 'name="' . $this->setting->id . '" type="radio" value="' . esc_attr( $value ) . '"' . selected( $this->value(), $value, false ) . $data .' >' . '</input>'; ?>
178 <div class="preset-wrap">
179 <div class="preset-color" <?php echo $preset_style; ?>>
180 <span class="first-font" <?php echo $first_font; ?>><?php echo substr( get_bloginfo('name'), 0, 2); ?></span>
181 <span class="secondary-font" <?php echo $second_font; ?>>AaBbCc</span>
182 </div>
183 <div class="preset-name" <?php echo $preset_name_style; ?>>
184 <?php echo $label; ?>
185 </div>
186 </div>
187 </div>
188 <?php }
189
190 // ok now we have our preview fonts, let's ask them from google
191 // note that we request only these chars "AaBbCc" so it should be a small request
192 echo '<link href="//fonts.googleapis.com/css?family=' . implode('|', $google_links ) . '&text=AaBbCc' . substr( get_bloginfo('name'), 0, 2) . '" rel=\'stylesheet\' type=\'text/css\'>';?>
193 </div>
194
195 <?php
196 if ( ! empty( $this->description ) ) { ?>
197 <span class="description customize-control-description"><?php echo $this->description; ?></span>
198 <?php } ?>
199 </label>
200 <?php break;
201 }
202
203 default:
204 break;
205 }
206 }
207
208 /**
209 * Returns whether or not given color is considered "light"
210 * @param string|Boolean $color
211 * @return boolean
212 */
213 public function isLight( $color = FALSE ){
214 // Get our color
215 $color = ($color) ? $color : $this->_hex;
216 // Calculate straight from rbg
217 $r = hexdec($color[0].$color[1]);
218 $g = hexdec($color[2].$color[3]);
219 $b = hexdec($color[4].$color[5]);
220 return (( $r*299 + $g*587 + $b*114 )/1000 > 130);
221 }
222 }
223