PluginProbe
Customify / 1.2.7
Customify v1.2.7
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 1.2.7, at features/customizer/controls/class-Pix_Customize_Background_Control.php

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