PluginProbe
QuadMenu – Mega Menu / 1.8.9
QuadMenu – Mega Menu v1.8.9
3.3.8 3.3.7 3.3.6 trunk 1.8.4 1.8.5 1.8.7 1.8.8 1.8.9 1.9.0 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 All 88 releases
quadmenu / lib / ReduxCore / inc / fields / background / field_background.php

field_background.php in QuadMenu – Mega Menu 1.8.9, at lib/ReduxCore/inc/fields/background/field_background.php

431 lines 22.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Redux Framework is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * any later version.
8 * Redux Framework is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with Redux Framework. If not, see <http://www.gnu.org/licenses/>.
14 *
15 * @package ReduxFramework
16 * @subpackage Field_Background
17 * @author Dovy Paukstys
18 * @version 3.1.5
19 */
20 // Exit if accessed directly
21 if ( ! defined( 'ABSPATH' ) ) {
22 exit;
23 }
24
25 // Don't duplicate me!
26 if ( ! class_exists( 'ReduxFramework_background' ) ) {
27
28 /**
29 * Main ReduxFramework_background class
30 *
31 * @since 3.1.5
32 */
33 class ReduxFramework_background {
34
35 /**
36 * Field Constructor.
37 * Required - must call the parent constructor, then assign field and value to vars, and obviously call the render field function
38 *
39 * @since 3.1.5
40 * @access public
41 * @return void
42 */
43 function __construct( $field = array(), $value = '', $parent ) {
44
45 $this->parent = $parent;
46 $this->field = $field;
47 $this->value = $value;
48 }
49
50 /**
51 * Field Render Function.
52 * Takes the vars and outputs the HTML for the field in the settings
53 *
54 * @since 1.0.0
55 * @access public
56 * @return void
57 */
58 public function render() {
59
60 $defaults = array(
61 'background-color' => true,
62 'background-repeat' => true,
63 'background-attachment' => true,
64 'background-position' => true,
65 'background-image' => true,
66 'background-gradient' => false,
67 'background-clip' => false,
68 'background-origin' => false,
69 'background-size' => true,
70 'preview_media' => false,
71 'preview' => true,
72 'preview_height' => '200px',
73 'transparent' => true,
74 );
75
76 $this->field = wp_parse_args( $this->field, $defaults );
77
78 // No errors please
79 $defaults = array(
80 'background-color' => '',
81 'background-repeat' => '',
82 'background-attachment' => '',
83 'background-position' => '',
84 'background-image' => '',
85 'background-clip' => '',
86 'background-origin' => '',
87 'background-size' => '',
88 'media' => array(),
89 );
90
91 $this->value = wp_parse_args( $this->value, $defaults );
92
93 $defaults = array(
94 'id' => '',
95 'width' => '',
96 'height' => '',
97 'thumbnail' => '',
98 );
99
100 $this->value['media'] = wp_parse_args( $this->value['media'], $defaults );
101
102 // select2 args
103 if ( isset( $this->field['select2'] ) ) { // if there are any let's pass them to js
104 $select2_params = json_encode( $this->field['select2'] );
105 $select2_params = htmlspecialchars( $select2_params, ENT_QUOTES );
106
107 echo '<input type="hidden" class="select2_params" value="' . $select2_params . '">';
108 }
109
110 if ( $this->field['background-color'] === true ) {
111
112 if ( isset( $this->value['color'] ) && empty( $this->value['background-color'] ) ) {
113 $this->value['background-color'] = $this->value['color'];
114 }
115
116 echo '<input data-id="' . $this->field['id'] . '" name="' . $this->field['name'] . $this->field['name_suffix'] . '[background-color]" id="' . $this->field['id'] . '-color" class="redux-color redux-background-input redux-color-init ' . $this->field['class'] . '" type="text" value="' . $this->value['background-color'] . '" data-default-color="' . ( isset( $this->field['default']['background-color'] ) ? $this->field['default']['background-color'] : "" ) . '" />';
117 echo '<input type="hidden" class="redux-saved-color" id="' . $this->field['id'] . '-saved-color' . '" value="">';
118
119 if ( ! isset( $this->field['transparent'] ) || $this->field['transparent'] !== false ) {
120 $tChecked = "";
121 if ( $this->value['background-color'] == "transparent" ) {
122 $tChecked = ' checked="checked"';
123 }
124 echo '<label for="' . $this->field['id'] . '-transparency" class="color-transparency-check"><input type="checkbox" class="checkbox color-transparency redux-background-input ' . $this->field['class'] . '" id="' . $this->field['id'] . '-transparency" data-id="' . $this->field['id'] . '-color" value="1"' . $tChecked . '> ' . __( 'Transparent', 'redux-framework' ) . '</label>';
125 }
126
127 if ( $this->field['background-repeat'] === true || $this->field['background-position'] === true || $this->field['background-attachment'] === true ) {
128 echo '<br />';
129 }
130 }
131
132
133 if ( $this->field['background-repeat'] === true ) {
134 $array = array(
135 'no-repeat' => 'No Repeat',
136 'repeat' => 'Repeat All',
137 'repeat-x' => 'Repeat Horizontally',
138 'repeat-y' => 'Repeat Vertically',
139 'inherit' => 'Inherit',
140 );
141 echo '<select id="' . $this->field['id'] . '-repeat-select" data-placeholder="' . __( 'Background Repeat', 'redux-framework' ) . '" name="' . $this->field['name'] . $this->field['name_suffix'] . '[background-repeat]" class="redux-select-item redux-background-input redux-background-repeat ' . $this->field['class'] . '">';
142 echo '<option></option>';
143
144 foreach ( $array as $k => $v ) {
145 echo '<option value="' . $k . '"' . selected( $this->value['background-repeat'], $k, false ) . '>' . $v . '</option>';
146 }
147 echo '</select>';
148 }
149
150 if ( $this->field['background-clip'] === true ) {
151 $array = array(
152 'inherit' => 'Inherit',
153 'border-box' => 'Border Box',
154 'content-box' => 'Content Box',
155 'padding-box' => 'Padding Box',
156 );
157 echo '<select id="' . $this->field['id'] . '-clip-select" data-placeholder="' . __( 'Background Clip', 'redux-framework' ) . '" name="' . $this->field['name'] . $this->field['name_suffix'] . '[background-clip]" class="redux-select-item redux-background-input redux-background-clip ' . $this->field['class'] . '">';
158 echo '<option></option>';
159
160 foreach ( $array as $k => $v ) {
161 echo '<option value="' . $k . '"' . selected( $this->value['background-clip'], $k, false ) . '>' . $v . '</option>';
162 }
163 echo '</select>';
164 }
165
166 if ( $this->field['background-origin'] === true ) {
167 $array = array(
168 'inherit' => 'Inherit',
169 'border-box' => 'Border Box',
170 'content-box' => 'Content Box',
171 'padding-box' => 'Padding Box',
172 );
173 echo '<select id="' . $this->field['id'] . '-origin-select" data-placeholder="' . __( 'Background Origin', 'redux-framework' ) . '" name="' . $this->field['name'] . $this->field['name_suffix'] . '[background-origin]" class="redux-select-item redux-background-input redux-background-origin ' . $this->field['class'] . '">';
174 echo '<option></option>';
175
176 foreach ( $array as $k => $v ) {
177 echo '<option value="' . $k . '"' . selected( $this->value['background-origin'], $k, false ) . '>' . $v . '</option>';
178 }
179 echo '</select>';
180 }
181
182 if ( $this->field['background-size'] === true ) {
183 $array = array(
184 'inherit' => 'Inherit',
185 'cover' => 'Cover',
186 'contain' => 'Contain',
187 );
188 echo '<select id="' . $this->field['id'] . '-size-select" data-placeholder="' . __( 'Background Size', 'redux-framework' ) . '" name="' . $this->field['name'] . $this->field['name_suffix'] . '[background-size]" class="redux-select-item redux-background-input redux-background-size ' . $this->field['class'] . '">';
189 echo '<option></option>';
190
191 foreach ( $array as $k => $v ) {
192 echo '<option value="' . $k . '"' . selected( $this->value['background-size'], $k, false ) . '>' . $v . '</option>';
193 }
194 echo '</select>';
195 }
196
197 if ( $this->field['background-attachment'] === true ) {
198 $array = array(
199 'fixed' => 'Fixed',
200 'scroll' => 'Scroll',
201 'inherit' => 'Inherit',
202 );
203 echo '<select id="' . $this->field['id'] . '-attachment-select" data-placeholder="' . __( 'Background Attachment', 'redux-framework' ) . '" name="' . $this->field['name'] . $this->field['name_suffix'] . '[background-attachment]" class="redux-select-item redux-background-input redux-background-attachment ' . $this->field['class'] . '">';
204 echo '<option></option>';
205 foreach ( $array as $k => $v ) {
206 echo '<option value="' . $k . '"' . selected( $this->value['background-attachment'], $k, false ) . '>' . $v . '</option>';
207 }
208 echo '</select>';
209 }
210
211 if ( $this->field['background-position'] === true ) {
212 $array = array(
213 'left top' => 'Left Top',
214 'left center' => 'Left center',
215 'left bottom' => 'Left Bottom',
216 'center top' => 'Center Top',
217 'center center' => 'Center Center',
218 'center bottom' => 'Center Bottom',
219 'right top' => 'Right Top',
220 'right center' => 'Right center',
221 'right bottom' => 'Right Bottom',
222 );
223 echo '<select id="' . $this->field['id'] . '-position-select" data-placeholder="' . __( 'Background Position', 'redux-framework' ) . '" name="' . $this->field['name'] . $this->field['name_suffix'] . '[background-position]" class="redux-select-item redux-background-input redux-background-position ' . $this->field['class'] . '">';
224 echo '<option></option>';
225
226 foreach ( $array as $k => $v ) {
227 echo '<option value="' . $k . '"' . selected( $this->value['background-position'], $k, false ) . '>' . $v . '</option>';
228 }
229 echo '</select>';
230 }
231
232 if ( $this->field['background-image'] === true ) {
233 echo '<br />';
234
235 if ( empty( $this->value ) && ! empty( $this->field['default'] ) ) { // If there are standard values and value is empty
236 if ( is_array( $this->field['default'] ) ) {
237 if ( ! empty( $this->field['default']['media']['id'] ) ) {
238 $this->value['media']['id'] = $this->field['default']['media']['id'];
239 } else if ( ! empty( $this->field['default']['id'] ) ) {
240 $this->value['media']['id'] = $this->field['default']['id'];
241 }
242
243 if ( ! empty( $this->field['default']['url'] ) ) {
244 $this->value['background-image'] = $this->field['default']['url'];
245 } else if ( ! empty( $this->field['default']['media']['url'] ) ) {
246 $this->value['background-image'] = $this->field['default']['media']['url'];
247 } else if ( ! empty( $this->field['default']['background-image'] ) ) {
248 $this->value['background-image'] = $this->field['default']['background-image'];
249 }
250 } else {
251 if ( is_numeric( $this->field['default'] ) ) { // Check if it's an attachment ID
252 $this->value['media']['id'] = $this->field['default'];
253 } else { // Must be a URL
254 $this->value['background-image'] = $this->field['default'];
255 }
256 }
257 }
258
259
260 if ( empty( $this->value['background-image'] ) && ! empty( $this->value['media']['id'] ) ) {
261 $img = wp_get_attachment_image_src( $this->value['media']['id'], 'full' );
262 $this->value['background-image'] = $img[0];
263 $this->value['media']['width'] = $img[1];
264 $this->value['media']['height'] = $img[2];
265 }
266
267 $hide = 'hide ';
268
269 if ( ( isset( $this->field['preview_media'] ) && $this->field['preview_media'] === false ) ) {
270 $this->field['class'] .= " noPreview";
271 }
272
273 if ( ( ! empty( $this->field['background-image'] ) && $this->field['background-image'] === true ) || isset( $this->field['preview'] ) && $this->field['preview'] === false ) {
274 $hide = '';
275 }
276
277 $placeholder = isset( $this->field['placeholder'] ) ? $this->field['placeholder'] : __( 'No media selected', 'redux-framework' );
278
279 echo '<input placeholder="' . $placeholder . '" type="text" class="redux-background-input ' . $hide . 'upload ' . $this->field['class'] . '" name="' . $this->field['name'] . $this->field['name_suffix'] . '[background-image]" id="' . $this->parent->args['opt_name'] . '-' . $this->field['id'] . '-background-image" value="' . $this->value['background-image'] . '" />';
280 echo '<input type="hidden" class="upload-id ' . $this->field['class'] . '" name="' . $this->field['name'] . $this->field['name_suffix'] . '[media][id]" id="' . $this->parent->args['opt_name'] . '-' . $this->field['id'] . '-media-id" value="' . $this->value['media']['id'] . '" />';
281 echo '<input type="hidden" class="upload-height" name="' . $this->field['name'] . $this->field['name_suffix'] . '[media][height]" id="' . $this->parent->args['opt_name'] . '-' . $this->field['id'] . '-media-height" value="' . $this->value['media']['height'] . '" />';
282 echo '<input type="hidden" class="upload-width" name="' . $this->field['name'] . $this->field['name_suffix'] . '[media][width]" id="' . $this->parent->args['opt_name'] . '-' . $this->field['id'] . '-media-width" value="' . $this->value['media']['width'] . '" />';
283 echo '<input type="hidden" class="upload-thumbnail" name="' . $this->field['name'] . $this->field['name_suffix'] . '[media][thumbnail]" id="' . $this->parent->args['opt_name'] . '-' . $this->field['id'] . '-media-thumbnail" value="' . $this->value['media']['thumbnail'] . '" />';
284
285 //Preview
286 $hide = '';
287
288 if ( ( isset( $this->field['preview_media'] ) && $this->field['preview_media'] === false ) || empty( $this->value['background-image'] ) ) {
289 $hide = 'hide ';
290 }
291
292 if ( empty( $this->value['media']['thumbnail'] ) && ! empty( $this->value['background-image'] ) ) { // Just in case
293 if ( ! empty( $this->value['media']['id'] ) ) {
294 $image = wp_get_attachment_image_src( $this->value['media']['id'], array(
295 150,
296 150
297 ) );
298 $this->value['media']['thumbnail'] = $image[0];
299 } else {
300 $this->value['media']['thumbnail'] = $this->value['background-image'];
301 }
302 }
303
304 echo '<div class="' . $hide . 'screenshot">';
305 echo '<a class="of-uploaded-image" href="' . $this->value['background-image'] . '" target="_blank">';
306 echo '<img class="redux-option-image" id="image_' . $this->value['media']['id'] . '" src="' . $this->value['media']['thumbnail'] . '" alt="" target="_blank" rel="external" />';
307 echo '</a>';
308 echo '</div>';
309
310 //Upload controls DIV
311 echo '<div class="upload_button_div">';
312
313 //If the user has WP3.5+ show upload/remove button
314 echo '<span class="button redux-background-upload" id="' . $this->field['id'] . '-media">' . __( 'Upload', 'redux-framework' ) . '</span>';
315
316 $hide = '';
317 if ( empty( $this->value['background-image'] ) || $this->value['background-image'] == '' ) {
318 $hide = ' hide';
319 }
320
321 echo '<span class="button removeCSS redux-remove-background' . $hide . '" id="reset_' . $this->field['id'] . '" rel="' . $this->field['id'] . '">' . __( 'Remove', 'redux-framework' ) . '</span>';
322
323 echo '</div>';
324 }
325
326
327 /**
328 * Preview
329 * */
330 if ( ! isset( $this->field['preview'] ) || $this->field['preview'] !== false ):
331
332 $css = $this->getCSS();
333 if ( empty( $css ) ) {
334 $css = "display:none;";
335 }
336 $css .= "height: " . $this->field['preview_height'] . ";";
337 echo '<p class="clear ' . $this->field['id'] . '_previewer background-preview" style="' . $css . '">&nbsp;</p>';
338
339 endif;
340 }
341
342 /**
343 * Enqueue Function.
344 * If this field requires any scripts, or css define this function and register/enqueue the scripts/css
345 *
346 * @since 1.0.0
347 * @access public
348 * @return void
349 */
350 public function enqueue() {
351 if ( function_exists( 'wp_enqueue_media' ) ) {
352 wp_enqueue_media();
353 } else {
354 if (!wp_script_is ( 'media-upload' )) {
355 wp_enqueue_script( 'media-upload' );
356 }
357 }
358
359 if (!wp_style_is ( 'select2-css' )) {
360 wp_enqueue_style( 'select2-css' );
361 }
362
363 if (!wp_style_is ( 'wp-color-picker' )) {
364 wp_enqueue_style( 'wp-color-picker' );
365 }
366
367 if (!wp_script_is ( 'redux-field-background-js' )) {
368 wp_enqueue_script(
369 'redux-field-background-js',
370 ReduxFramework::$_url . 'inc/fields/background/field_background' . Redux_Functions::isMin() . '.js',
371 array( 'jquery', 'wp-color-picker', 'select2-js', 'redux-js' ),
372 time(),
373 true
374 );
375 }
376
377 if ($this->parent->args['dev_mode']) {
378 if (!wp_style_is ( 'redux-field-background-css' )) {
379 wp_enqueue_style(
380 'redux-field-background-css',
381 ReduxFramework::$_url . 'inc/fields/background/field_background.css',
382 array(),
383 time(),
384 'all'
385 );
386 }
387
388 if (!wp_style_is ( 'redux-color-picker-css' )) {
389 wp_enqueue_style( 'redux-color-picker-css' );
390 }
391 }
392 }
393
394 public static function getCSS( $value = array() ) {
395
396 $css = '';
397
398 if ( ! empty( $value ) && is_array( $value ) ) {
399 foreach ( $value as $key => $value ) {
400 if ( ! empty( $value ) && $key != "media" ) {
401 if ( $key == "background-image" ) {
402 $css .= $key . ":url('" . $value . "');";
403 } else {
404 $css .= $key . ":" . $value . ";";
405 }
406 }
407 }
408 }
409
410 return $css;
411 }
412
413 public function output() {
414 $style = $this->getCSS( $this->value );
415
416 if ( ! empty( $style ) ) {
417
418 if ( ! empty( $this->field['output'] ) && is_array( $this->field['output'] ) ) {
419 $keys = implode( ",", $this->field['output'] );
420 $this->parent->outputCSS .= $keys . "{" . $style . '}';
421 }
422
423 if ( ! empty( $this->field['compiler'] ) && is_array( $this->field['compiler'] ) ) {
424 $keys = implode( ",", $this->field['compiler'] );
425 $this->parent->compilerCSS .= $keys . "{" . $style . '}';
426 }
427 }
428 }
429 }
430 }
431