PluginProbe
QuadMenu – Mega Menu / 3.3.8
QuadMenu – Mega Menu v3.3.8
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 / redux / ReduxCore / inc / fields / media / field_media.php

field_media.php in QuadMenu – Mega Menu 3.3.8, at redux/ReduxCore/inc/fields/media/field_media.php

251 lines 9.3 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 ReduxFrameworkLegacy
16 * @subpackage Field_Media
17 * @author Daniel J Griffiths (Ghost1227)
18 * @author Dovy Paukstys
19 * @author Kevin Provance (kprovance)
20 * @version 3.0.0
21 */
22
23 // Exit if accessed directly
24 if ( ! defined( 'ABSPATH' ) ) {
25 exit;
26 }
27
28 // Don't duplicate me!
29 if ( ! class_exists( 'ReduxFrameworkLegacy_media' ) ) {
30
31 /**
32 * Main ReduxFrameworkLegacy_media class
33 *
34 * @since 1.0.0
35 */
36 class ReduxFrameworkLegacy_media {
37
38 public $parent;
39 public $field;
40 public $value;
41
42 /**
43 * Field Constructor.
44 * Required - must call the parent constructor, then assign field and value to vars, and obviously call the render field function
45 *
46 * @since 1.0.0
47 * @access public
48 * @return void
49 */
50 function __construct( $field = array(), $value = '', $parent = null ) {
51 $this->parent = $parent;
52 $this->field = $field;
53 $this->value = $value;
54 }
55
56 /**
57 * Field Render Function.
58 * Takes the vars and outputs the HTML for the field in the settings
59 *
60 * @since 1.0.0
61 * @access public
62 * @return void
63 */
64 public function render() {
65
66 // No errors please
67 $defaults = array(
68 'id' => '',
69 'url' => '',
70 'width' => '',
71 'height' => '',
72 'thumbnail' => '',
73 'title' => '',
74 'caption' => '',
75 'alt' => '',
76 'description' => '',
77 );
78
79 $this->value = wp_parse_args( $this->value, $defaults );
80
81 if ( isset( $this->field['mode'] ) && $this->field['mode'] == false ) {
82 $this->field['mode'] = 0;
83 }
84
85 if ( ! isset( $this->field['mode'] ) ) {
86 $this->field['mode'] = 'image';
87 }
88
89 if ( ! isset( $this->field['library_filter'] ) ) {
90 $libFilter = '';
91 } else {
92 if ( ! is_array( $this->field['library_filter'] ) ) {
93 $this->field['library_filter'] = array( $this->field['library_filter'] );
94 }
95
96 $mimeTypes = get_allowed_mime_types();
97
98 $libArray = $this->field['library_filter'];
99
100 $jsonArr = array();
101
102 // Enum mime types
103 foreach ( $mimeTypes as $ext => $type ) {
104 if ( strpos( $ext, '|' ) ) {
105 $expArr = explode( '|', $ext );
106
107 foreach ( $expArr as $ext ) {
108 if ( in_array( $ext, $libArray ) ) {
109 $jsonArr[ $ext ] = $type;
110 }
111 }
112 } elseif ( in_array( $ext, $libArray ) ) {
113 $jsonArr[ $ext ] = $type;
114 }
115 }
116
117 $libFilter = urlencode( json_encode( $jsonArr ) );
118 }
119
120 if ( empty( $this->value ) && ! empty( $this->field['default'] ) ) { // If there are standard values and value is empty
121 if ( is_array( $this->field['default'] ) ) {
122 if ( ! empty( $this->field['default']['id'] ) ) {
123 $this->value['id'] = $this->field['default']['id'];
124 }
125
126 if ( ! empty( $this->field['default']['url'] ) ) {
127 $this->value['url'] = $this->field['default']['url'];
128 }
129 } elseif ( is_numeric( $this->field['default'] ) ) {
130 // Check if it's an attachment ID
131 $this->value['id'] = $this->field['default'];
132 } else { // Must be a URL
133 $this->value['url'] = $this->field['default'];
134 }
135 }
136
137 if ( empty( $this->value['url'] ) && ! empty( $this->value['id'] ) ) {
138 $img = wp_get_attachment_image_src( $this->value['id'], 'full' );
139 $this->value['url'] = $img[0];
140 $this->value['width'] = $img[1];
141 $this->value['height'] = $img[2];
142 }
143
144 $hide = 'hide ';
145
146 if ( ( isset( $this->field['preview'] ) && $this->field['preview'] === false ) ) {
147 $this->field['class'] .= ' noPreview';
148 }
149
150 if ( ( ! empty( $this->field['url'] ) && $this->field['url'] === true ) || isset( $this->field['preview'] ) && $this->field['preview'] === false ) {
151 $hide = '';
152 }
153
154 $placeholder = isset( $this->field['placeholder'] ) ? $this->field['placeholder'] : __( 'No media selected', 'redux-framework' );
155
156 $readOnly = ' readonly="readonly"';
157 if ( isset( $this->field['readonly'] ) && $this->field['readonly'] === false ) {
158 $readOnly = '';
159 }
160
161 echo '<input placeholder="' . $placeholder . '" type="text" class="' . $hide . 'upload large-text ' . $this->field['class'] . '" name="' . $this->field['name'] . $this->field['name_suffix'] . '[url]" id="' . $this->parent->args['opt_name'] . '[' . $this->field['id'] . '][url]" value="' . $this->value['url'] . '"' . $readOnly . '/>';
162 echo '<input type="hidden" class="data" data-mode="' . $this->field['mode'] . '" />';
163 echo '<input type="hidden" class="library-filter" data-lib-filter="' . $libFilter . '" />';
164 echo '<input type="hidden" class="upload-id ' . $this->field['class'] . '" name="' . $this->field['name'] . $this->field['name_suffix'] . '[id]" id="' . $this->parent->args['opt_name'] . '_' . $this->field['id'] . '_id" value="' . $this->value['id'] . '" />';
165 echo '<input type="hidden" class="upload-height" name="' . $this->field['name'] . $this->field['name_suffix'] . '[height]" id="' . $this->parent->args['opt_name'] . '_' . $this->field['id'] . '_height" value="' . $this->value['height'] . '" />';
166 echo '<input type="hidden" class="upload-width" name="' . $this->field['name'] . $this->field['name_suffix'] . '[width]" id="' . $this->parent->args['opt_name'] . '_' . $this->field['id'] . '_width" value="' . $this->value['width'] . '" />';
167 echo '<input type="hidden" class="upload-thumbnail" name="' . $this->field['name'] . $this->field['name_suffix'] . '[thumbnail]" id="' . $this->parent->args['opt_name'] . '_' . $this->field['id'] . '_thumbnail" value="' . $this->value['thumbnail'] . '" />';
168 echo '<input type="hidden" class="upload-title" name="' . $this->field['name'] . $this->field['name_suffix'] . '[title]" id="' . $this->parent->args['opt_name'] . '_' . $this->field['id'] . '_title" value="' . $this->value['title'] . '" />';
169 echo '<input type="hidden" class="upload-caption" name="' . $this->field['name'] . $this->field['name_suffix'] . '[caption]" id="' . $this->parent->args['opt_name'] . '_' . $this->field['id'] . '_caption" value="' . $this->value['caption'] . '" />';
170 echo '<input type="hidden" class="upload-alt" name="' . $this->field['name'] . $this->field['name_suffix'] . '[alt]" id="' . $this->parent->args['opt_name'] . '_' . $this->field['id'] . '_alt" value="' . $this->value['alt'] . '" />';
171 echo '<input type="hidden" class="upload-description" name="' . $this->field['name'] . $this->field['name_suffix'] . '[description]" id="' . $this->parent->args['opt_name'] . '_' . $this->field['id'] . '_description" value="' . $this->value['description'] . '" />';
172
173 // Preview
174 $hide = '';
175
176 if ( ( isset( $this->field['preview'] ) && $this->field['preview'] === false ) || empty( $this->value['url'] ) ) {
177 $hide = 'hide ';
178 }
179
180 if ( empty( $this->value['thumbnail'] ) && ! empty( $this->value['url'] ) ) { // Just in case
181 if ( ! empty( $this->value['id'] ) ) {
182 $image = wp_get_attachment_image_src(
183 $this->value['id'],
184 array(
185 150,
186 150,
187 )
188 );
189
190 if ( empty( $image[0] ) || $image[0] == '' ) {
191 $this->value['thumbnail'] = $this->value['url'];
192 } else {
193 $this->value['thumbnail'] = $image[0];
194 }
195 } else {
196 $this->value['thumbnail'] = $this->value['url'];
197 }
198 }
199
200 echo '<div class="' . $hide . 'screenshot">';
201 echo '<a class="of-uploaded-image" href="' . $this->value['url'] . '" target="_blank">';
202 echo '<img class="redux-option-image" id="image_' . $this->field['id'] . '" src="' . $this->value['thumbnail'] . '" alt="" target="_blank" rel="external" />';
203 echo '</a>';
204 echo '</div>';
205
206 // Upload controls DIV
207 echo '<div class="upload_button_div">';
208
209 // If the user has WP3.5+ show upload/remove button
210 echo '<span class="button media_upload_button" id="' . $this->field['id'] . '-media">' . __( 'Upload', 'redux-framework' ) . '</span>';
211
212 $hide = '';
213 if ( empty( $this->value['url'] ) || $this->value['url'] == '' ) {
214 $hide = ' hide';
215 }
216
217 echo '<span class="button remove-image' . $hide . '" id="reset_' . $this->field['id'] . '" rel="' . $this->field['id'] . '">' . __( 'Remove', 'redux-framework' ) . '</span>';
218
219 echo '</div>';
220 }
221
222 /**
223 * Enqueue Function.
224 * If this field requires any scripts, or css define this function and register/enqueue the scripts/css
225 *
226 * @since 1.0.0
227 * @access public
228 * @return void
229 */
230 public function enqueue() {
231 if ( function_exists( 'wp_enqueue_media' ) ) {
232 wp_enqueue_media();
233 } else {
234 wp_enqueue_script( 'media-upload' );
235 }
236
237 wp_enqueue_script(
238 'redux-field-media-js',
239 ReduxFrameworkLegacy::$_url . 'assets/js/media/media' . ReduxLegacy_Functions::isMin() . '.js',
240 array( 'jquery', 'redux-js' ),
241 time(),
242 true
243 );
244
245 if ( $this->parent->args['dev_mode'] ) {
246 wp_enqueue_style( 'redux-field-media-css' );
247 }
248 }
249 }
250 }
251