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 / media / field_media.php

field_media.php in QuadMenu – Mega Menu 1.8.9, at lib/ReduxCore/inc/fields/media/field_media.php

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