PluginProbe
Customify / 2.1.1
Customify v2.1.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_Background_Control.php

class-Pix_Customize_Background_Control.php in Customify 2.1.1, at features/customizer/controls/class-Pix_Customize_Background_Control.php

253 lines 11.1 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_Background_Control
5 * A simple Color Control
6 */
7 class Pix_Customize_Background_Control extends Pix_Customize_Control {
8 public $type = 'custom_background';
9
10 public $value = array();
11
12 public $field = array(
13 'class' => ''
14 );
15
16 public $field_defaults = array(
17 'background-color' => true,
18 'background-repeat' => true,
19 'background-attachment' => true,
20 'background-position' => true,
21 'background-image' => true,
22 'background-gradient' => false,
23 'background-clip' => false,
24 'background-origin' => false,
25 'background-size' => true,
26 'preview_media' => true,
27 'preview' => true,
28 'preview_height' => '200px',
29 'transparent' => true,
30 );
31
32 /**
33 * Render the control's content.
34 *
35 * @since 3.4.0
36 */
37 public function render_content() {
38
39 // ensure some values
40 $this->value = $this->value();
41 $this->field = array_merge( $this->field, $this->field_defaults );
42
43 if ( $this->field['background-image'] === true ) {
44
45 // NO defaults for now
46 // if ( empty( $this->value ) && ! empty( $this->field['default'] ) ) { // If there are standard values and value is empty
47 // if ( is_array( $this->field['default'] ) ) {
48 // if ( ! empty( $this->field['default']['media']['id'] ) ) {
49 // $this->value['media']['id'] = $this->field['default']['media']['id'];
50 // } else if ( ! empty( $this->field['default']['id'] ) ) {
51 // $this->value['media']['id'] = $this->field['default']['id'];
52 // }
53 //
54 // if ( ! empty( $this->field['default']['url'] ) ) {
55 // $this->value['background-image'] = $this->field['default']['url'];
56 // } else if ( ! empty( $this->field['default']['media']['url'] ) ) {
57 // $this->value['background-image'] = $this->field['default']['media']['url'];
58 // } else if ( ! empty( $this->field['default']['background-image'] ) ) {
59 // $this->value['background-image'] = $this->field['default']['background-image'];
60 // }
61 //
62 // } else {
63 // if ( is_numeric( $this->field['default'] ) ) { // Check if it's an attachment ID
64 // $this->value['media']['id'] = $this->field['default'];
65 // } else { // Must be a URL
66 // $this->value['background-image'] = $this->field['default'];
67 // }
68 // }
69 // }
70
71 if ( empty( $this->value['background-image'] ) && ! empty( $this->value['media']['id'] ) ) {
72 $img = wp_get_attachment_image_src( $this->value['media']['id'], 'full' );
73 $this->value['background-image'] = $img[0];
74 $this->value['media']['width'] = $img[1];
75 $this->value['media']['height'] = $img[2];
76 }
77
78 if ( ! is_array( $this->value ) || ! isset( $this->value['media'] ) || empty( $this->value['media'] ) ) {
79 $this->value = array();
80 $media_array = array(
81 'id' => '',
82 'height' => '',
83 'width' => '',
84 'thumbnail' => ''
85 );
86 $this->value['media'] = $media_array;
87 }
88
89 $hide = 'hide ';
90
91 if ( ( isset( $this->field['preview_media'] ) && $this->field['preview_media'] === false ) ) {
92 $this->field['class'] .= " noPreview";
93 }
94
95 if ( ( ! empty( $this->field['background-image'] ) && $this->field['background-image'] === true ) || isset( $this->field['preview'] ) && $this->field['preview'] === false ) {
96 $hide = '';
97 }
98
99 $placeholder = isset( $this->field['placeholder'] ) ? $this->field['placeholder'] : __( 'No media selected', 'customify' );
100
101
102 if ( ! isset( $this->value['background-image'] ) ) {
103 $this->value['background-image'] = '';
104 }
105
106 echo '<input placeholder="' . $placeholder . '" type="text" class="customify_background_input background-image ' . $hide . 'upload ' . $this->field['class'] . '" name="' . $this->label . '[background-image]" id="' . $this->manager->options_key . '[' . $this->id . '][background-image]" value="' . $this->value['background-image'] . '" data-select_name="background-image" data-customize-setting-link="' . esc_attr( $this->setting->id ) . '[background-image]"/>';
107 echo '<input type="hidden" class="upload-id ' . $this->field['class'] . '" name="' . $this->manager->options_key . '[media][id]" id="' . $this->manager->options_key . '[' . $this->id . '][media][id]" value="' . $this->value['media']['id'] . '" />';
108 echo '<input type="hidden" class="upload-height" name="' . $this->manager->options_key . '[media][height]" id="' . $this->manager->options_key . '[' . $this->id . '][media][height]" value="' . $this->value['media']['height'] . '" />';
109 echo '<input type="hidden" class="upload-width" name="' . $this->manager->options_key . '[media][width]" id="' . $this->manager->options_key . '[' . $this->id . '][media][width]" value="' . $this->value['media']['width'] . '" />';
110 echo '<input type="hidden" class="upload-thumbnail" name="' . $this->manager->options_key . '[media][thumbnail]" id="' . $this->manager->options_key . '[media][thumbnail]" value="' . $this->value['media']['thumbnail'] . '" />';
111
112 //Preview
113 $hide = '';
114
115 if ( ( isset( $this->field['preview_media'] ) && $this->field['preview_media'] === false ) || empty( $this->value['background-image'] ) ) {
116 $hide = 'hide ';
117 }
118
119 if ( empty( $this->value['media']['thumbnail'] ) && ! empty( $this->value['background-image'] ) ) { // Just in case
120 if ( ! empty( $this->value['media']['id'] ) ) {
121 $image = wp_get_attachment_image_src( $this->value['media']['id'], array( 150 ) );
122 $this->value['media']['thumbnail'] = $image[0];
123 } else {
124 $this->value['media']['thumbnail'] = $this->value['background-image'];
125 }
126 }
127
128 echo '<div class="' . $hide . 'preview_screenshot">';
129 echo '<a class="of-uploaded-image" href="' . $this->value['background-image'] . '" target="_blank">';
130 echo '<img class="preview_image" id="image_' . $this->value['media']['id'] . '" src="' . $this->value['media']['thumbnail'] . '" alt="" target="_blank" rel="external" />';
131 echo '</a>';
132 echo '</div>';
133
134 //Upload controls DIV
135 echo '<div class="upload_button_div">';
136
137 //If the user has WP3.5+ show upload/remove button
138 echo '<span class="button background_upload_button" id="' . $this->id . '-media" data-setting_id="' . $this->setting->id . '" >' . __( 'Upload', 'customify' ) . '</span>';
139
140 $hide = '';
141 if ( empty( $this->value['background-image'] ) || $this->value['background-image'] == '' ) {
142 $hide = ' hide';
143 }
144
145 echo '<span class="button remove-image' . $hide . '" id="reset_' . $this->id . '" rel="' . $this->id . '">' . __( 'Remove', 'customify' ) . '</span>';
146
147 echo '</div>';
148 }
149
150 if ( $this->field['background-repeat'] === true ) {
151 $array = array(
152 'no-repeat' => 'No Repeat',
153 'repeat' => 'Repeat All',
154 'repeat-x' => 'Repeat Horizontally',
155 'repeat-y' => 'Repeat Vertically',
156 'inherit' => 'Inherit',
157 );
158
159 echo '<select id="' . $this->id . '-repeat-select" name="' . $this->setting->id . '[background-repeat]" class="customify_background_select ' . $this->field['class'] . ' ' . $hide . '" data-select_name="background-repeat" data-customize-setting-link="' . esc_attr( $this->setting->id ) . '[background-repeat]">';
160 echo '<option></option>';
161 foreach ( $array as $k => $v ) {
162 echo '<option value="' . $k . '"' . selected( $this->value['background-repeat'], $k, false ) . '>' . $v . '</option>';
163 }
164 echo '</select>';
165 }
166
167 if ( $this->field['background-clip'] === true ) {
168 $array = array(
169 'inherit' => 'Inherit',
170 'border-box' => 'Border Box',
171 'content-box' => 'Content Box',
172 'padding-box' => 'Padding Box',
173 );
174 echo '<select id="' . $this->id . '-repeat-select" name="' . $this->setting->id . '[background-clip]" class="customify_background_select ' . $this->field['class'] . ' ' . $hide . '" data-select_name="background-clip" data-customize-setting-link="' . esc_attr( $this->setting->id ) . '[background-clip]">';
175 echo '<option></option>';
176
177 foreach ( $array as $k => $v ) {
178 echo '<option value="' . $k . '"' . selected( $this->value['background-clip'], $k, false ) . '>' . $v . '</option>';
179 }
180 echo '</select>';
181 }
182
183 if ( $this->field['background-origin'] === true ) {
184 $array = array(
185 'inherit' => 'Inherit',
186 'border-box' => 'Border Box',
187 'content-box' => 'Content Box',
188 'padding-box' => 'Padding Box',
189 );
190 echo '<select id="' . $this->id . '-repeat-select" name="' . $this->setting->id . '[background-origin]" class="customify_background_select ' . $this->field['class'] . ' ' . $hide . '" data-select_name="background-origin" data-customize-setting-link="' . esc_attr( $this->setting->id ) . '[background-origin]">';
191 echo '<option></option>';
192
193 foreach ( $array as $k => $v ) {
194 echo '<option value="' . $k . '"' . selected( $this->value['background-origin'], $k, false ) . '>' . $v . '</option>';
195 }
196 echo '</select>';
197 }
198
199 if ( $this->field['background-size'] === true ) {
200 $array = array(
201 'inherit' => 'Inherit',
202 'cover' => 'Cover',
203 'contain' => 'Contain',
204 );
205 echo '<select id="' . $this->id . '-repeat-select" name="' . $this->label . '[background-size]" class="customify_background_select ' . $this->field['class'] . ' ' . $hide . '" data-select_name="background-size" data-customize-setting-link="' . esc_attr( $this->setting->id ) . '[background-size]">';
206 echo '<option></option>';
207
208 foreach ( $array as $k => $v ) {
209 echo '<option value="' . $k . '"' . selected( $this->value['background-size'], $k, false ) . '>' . $v . '</option>';
210 }
211 echo '</select>';
212 }
213
214 if ( $this->field['background-attachment'] === true ) {
215 $array = array(
216 'fixed' => 'Fixed',
217 'scroll' => 'Scroll',
218 'inherit' => 'Inherit',
219 );
220 echo '<select id="' . $this->id . '-attachment-select" name="' . $this->setting->id . '[background-attachment]" class="customify_background_select ' . $this->field['class'] . ' ' . $hide . '" data-select_name="background-attachment" data-customize-setting-link="' . esc_attr( $this->setting->id ) . '[background-attachment]">';
221 echo '<option></option>';
222 foreach ( $array as $k => $v ) {
223 echo '<option value="' . $k . '"' . selected( $this->value['background-attachment'], $k, false ) . '>' . $v . '</option>';
224 }
225 echo '</select>';
226 }
227
228 if ( $this->field['background-position'] === true ) {
229 $array = array(
230 'left top' => 'Left Top',
231 'left center' => 'Left center',
232 'left bottom' => 'Left Bottom',
233 'center top' => 'Center Top',
234 'center center' => 'Center Center',
235 'center bottom' => 'Center Bottom',
236 'right top' => 'Right Top',
237 'right center' => 'Right center',
238 'right bottom' => 'Right Bottom',
239 );
240 echo '<select id="' . $this->id . '-position-select" name="' . $this->setting->id . '[background-position]" class="customify_background_select ' . $this->field['class'] . ' ' . $hide . '" data-select_name="background-position" data-customize-setting-link="' . esc_attr( $this->setting->id ) . '[background-position]">';
241 echo '<option></option>';
242
243 foreach ( $array as $k => $v ) {
244 echo '<option value="' . $k . '"' . selected( $this->value['background-position'], $k, false ) . '>' . $v . '</option>';
245 }
246 echo '</select>';
247 }
248 }
249
250 static function css_output() {
251
252 }
253 }