C:\xampp\htdocs\landing\wp-content\plugins\penci-smart-lists\lib\meta-box\inc\fields\file.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
<?php
/**
 * The file upload file which allows users to upload files via the default HTML <input type="file">.
 *
 * @package Meta Box
 */

/**
 * File field class which uses HTML <input type="file"> to upload file.
 */
class RWMB_File_Field extends RWMB_Field {
    
/**
     * Enqueue scripts and styles.
     */
    
public static function admin_enqueue_scripts() {
        
wp_enqueue_style'rwmb-file'RWMB_CSS_URL 'file.css', array(), RWMB_VER );
        
wp_enqueue_script'rwmb-file'RWMB_JS_URL 'file.js', array( 'jquery-ui-sortable' ), RWMB_VERtrue );

        
self::localize_script'rwmb-file''rwmbFile', array(
            
// Translators: %d is the number of files in singular form.
            
'maxFileUploadsSingle' => __'You may only upload maximum %d file''meta-box' ),
            
// Translators: %d is the number of files in plural form.
            
'maxFileUploadsPlural' => __'You may only upload maximum %d files''meta-box' ),
        ) );
    }

    
/**
     * Add custom actions.
     */
    
public static function add_actions() {
        
add_action'post_edit_form_tag', array( __CLASS__'post_edit_form_tag' ) );
        
add_action'wp_ajax_rwmb_delete_file', array( __CLASS__'ajax_delete_file' ) );
    }

    
/**
     * Add data encoding type for file uploading
     */
    
public static function post_edit_form_tag() {
        echo 
' enctype="multipart/form-data"';
    }

    
/**
     * Ajax callback for deleting files.
     */
    
public static function ajax_delete_file() {
        
$field_id      = (string) filter_inputINPUT_POST'field_id' );
        
$attachment_id = (int) filter_inputINPUT_POST'attachment_id'FILTER_SANITIZE_NUMBER_INT );

        
check_ajax_referer"rwmb-delete-file_{$field_id});
        if ( 
wp_delete_attachment$attachment_id ) ) {
            
wp_send_json_success();
        }
        
wp_send_json_error__'Error: Cannot delete file''meta-box' ) );
    }

    
/**
     * Get field HTML.
     *
     * @param mixed $meta  Meta value.
     * @param array $field Field parameters.
     *
     * @return string
     */
    
public static function html$meta$field ) {
        
$meta      array_filter( (array) $meta );
        
$i18n_more apply_filters'rwmb_file_add_string'_x'+ Add new file''file upload''meta-box' ), $field );
        
$html      self::get_uploaded_files$meta$field );

        
// Show form upload.
        
$html .= sprintf(
            
'<div class="rwmb-file-new">
                <input type="file" name="%s[]" class="rwmb-file-input">
                <a class="rwmb-file-add" href="#"><strong>%s</strong></a>
            </div>'
,
            
$field['file_input_name'],
            
$i18n_more
        
);

        return 
$html;
    }

    
/**
     * Get HTML for uploaded files.
     *
     * @param array $files List of uploaded files.
     * @param array $field Field parameters.
     * @return string
     */
    
protected static function get_uploaded_files$files$field ) {
        
$reorder_nonce wp_create_nonce"rwmb-reorder-files_{$field['id']});
        
$delete_nonce  wp_create_nonce"rwmb-delete-file_{$field['id']});
        
$output        '';

        foreach ( (array) 
$files as $k => $file ) {
            
// Ignore deleted files (if users accidentally deleted files or uses `force_delete` without saving post).
            
if ( get_attached_file$file ) ) {
                
$output .= self::call$field'file_html'$file$k );
            }
        }
        return 
sprintf(
            
'<ul class="rwmb-uploaded" data-field_id="%s" data-delete_nonce="%s" data-reorder_nonce="%s" data-force_delete="%s" data-max_file_uploads="%s" data-mime_type="%s">%s</ul>',
            
$field['id'],
            
$delete_nonce,
            
$reorder_nonce,
            
$field['force_delete'] ? 0,
            
$field['max_file_uploads'],
            
$field['mime_type'],
            
$output
        
);
    }

    
/**
     * Get HTML for uploaded file.
     *
     * @param int   $file  Attachment (file) ID.
     * @param int   $index File index.
     * @param array $field Field data.
     * @return string
     */
    
protected static function file_html$file$index$field ) {
        
$i18n_delete apply_filters'rwmb_file_delete_string'_x'Delete''file upload''meta-box' ) );
        
$i18n_edit   apply_filters'rwmb_file_edit_string'_x'Edit''file upload''meta-box' ) );
        
$attributes  self::get_attributes$field$file );
        
$path        get_attached_file$file );
        
$icon        wp_get_attachment_image$file, array( 6060 ), true );

        return 
sprintf(
            
'<li class="rwmb-file">
                <div class="rwmb-file-icon"><a href="%s" target="_blank">%s</a></div>
                <div class="rwmb-file-info">
                    <a href="%s" target="_blank" class="rwmb-file-title">%s</a>
                    <p class="rwmb-file-name">%s</p>
                    <p class="rwmb-file-actions">
                        <a href="%s" class="rwmb-file-edit" target="_blank"><span class="dashicons dashicons-edit"></span>%s</a>
                        <a href="#" class="rwmb-file-delete" data-attachment_id="%s"><span class="dashicons dashicons-no-alt"></span>%s</a>
                    </p>
                </div>
                <input type="hidden" name="%s[%s]" value="%s">
            </li>'
,
            
wp_get_attachment_url$file ), $icon,
            
wp_get_attachment_url$file ), get_the_title$file ),
            
basename$path ),
            
get_edit_post_link$file ), $i18n_edit,
            
$file$i18n_delete,
            
$attributes['name'], $index$file
        
);
    }

    
/**
     * Get meta values to save.
     *
     * @param mixed $new     The submitted meta value.
     * @param mixed $old     The existing meta value.
     * @param int   $post_id The post ID.
     * @param array $field   The field parameters.
     *
     * @return array|mixed
     */
    
public static function value$new$old$post_id$field ) {
        
$input $field['file_input_name'];

        
// @codingStandardsIgnoreLine
        
if ( empty( $_FILES$input ] ) ) {
            return 
$new;
        }

        
$new array_filter( (array) $new );

        
// Non-cloneable field.
        
if ( ! $field['clone'] ) {
            
$count self::transform$input );
            for ( 
$i 0$i <= $count$i ++ ) {
                
$attachment media_handle_upload"{$input}_{$i}"$post_id );
                if ( ! 
is_wp_error$attachment ) ) {
                    
$new[] = $attachment;
                }
            }
            return 
$new;
        }


        
// Cloneable field.
        
$counts self::transform_cloneable$input );
        foreach ( 
$counts as $clone_index => $count ) {
            if ( empty( 
$new$clone_index ] ) ) {
                
$new$clone_index ] = array();
            }
            for ( 
$i 0$i <= $count$i ++ ) {
                
$attachment media_handle_upload"{$input}_{$clone_index}_{$i}"$post_id );
                if ( ! 
is_wp_error$attachment ) ) {
                    
$new$clone_index ][] = $attachment;
                }
            }
        }

        return 
$new;
    }

    
/**
     * Transform $_FILES from $_FILES['field']['key']['index'] to $_FILES['field_index']['key'].
     *
     * @param string $input_name The field input name.
     *
     * @return int The number of uploaded files.
     */
    
protected static function transform$input_name ) {
        
// @codingStandardsIgnoreStart
        
foreach ( $_FILES$input_name ] as $key => $list ) {
            foreach ( 
$list as $index => $value ) {
                
$file_key "{$input_name}_{$index}";
                if ( ! isset( 
$_FILES$file_key ] ) ) {
                    
$_FILES$file_key ] = array();
                }
                
$_FILES$file_key ][ $key ] = $value;
            }
        }

        return 
count( (array)$_FILES$input_name ]['name'] );
        
// @codingStandardsIgnoreEnd
    
}

    
/**
     * Transform $_FILES from $_FILES['field']['key']['cloneIndex']['index'] to $_FILES['field_cloneIndex_index']['key'].
     *
     * @param string $input_name The field input name.
     *
     * @return array
     */
    
protected static function transform_cloneable$input_name ) {
        
// @codingStandardsIgnoreStart
        
foreach ( $_FILES$input_name ] as $key => $list ) {
            foreach ( 
$list as $clone_index => $clone_values ) {
                foreach ( 
$clone_values as $index => $value ) {
                    
$file_key "{$input_name}_{$clone_index}_{$index}";

                    if ( ! isset( 
$_FILES$file_key ] ) ) {
                        
$_FILES$file_key ] = array();
                    }
                    
$_FILES$file_key ][ $key ] = $value;
                }
            }
        }

        
$counts = array();
        foreach ( 
$_FILES$input_name ]['name'] as $clone_index => $clone_values ) {
            
$counts$clone_index ] = count( (array)$clone_values );
        }
        return 
$counts;
        
// @codingStandardsIgnoreEnd
    
}

    
/**
     * Normalize parameters for field.
     *
     * @param array $field Field parameters.
     * @return array
     */
    
public static function normalize$field ) {
        
$field             parent::normalize$field );
        
$field             wp_parse_args$field, array(
            
'std'              => array(),
            
'force_delete'     => false,
            
'max_file_uploads' => 0,
            
'mime_type'        => '',
        ) );
        
$field['multiple'] = true;

        
$field['file_input_name'] = '_file_' $field['id'];

        return 
$field;
    }

    
/**
     * Get the field value. Return meaningful info of the files.
     *
     * @param  array    $field   Field parameters.
     * @param  array    $args    Not used for this field.
     * @param  int|null $post_id Post ID. null for current post. Optional.
     *
     * @return mixed Full info of uploaded files
     */
    
public static function get_value$field$args = array(), $post_id null ) {
        
$value parent::get_value$field$args$post_id );
        if ( ! 
$field['clone'] ) {
            
$value self::call'files_info'$field$value$args );
        } else {
            
$return = array();
            foreach ( 
$value as $subvalue ) {
                
$return[] = self::call'files_info'$field$subvalue$args );
            }
            
$value $return;
        }
        if ( isset( 
$args['limit'] ) ) {
            
$value array_slice$value0intval$args['limit'] ) );
        }
        return 
$value;
    }

    
/**
     * Get uploaded files information.
     *
     * @param array $field Field parameters.
     * @param array $files Files IDs.
     * @param array $args  Additional arguments (for image size).
     * @return array
     */
    
public static function files_info$field$files$args ) {
        
$return = array();
        foreach ( (array) 
$files as $file ) {
            
$info self::call$field'file_info'$file$args );
            if ( 
$info ) {
                
$return$file ] = $info;
            }
        }
        return 
$return;
    }

    
/**
     * Get uploaded file information.
     *
     * @param int   $file Attachment file ID (post ID). Required.
     * @param array $args Array of arguments (for size).
     *
     * @return array|bool False if file not found. Array of (id, name, path, url) on success.
     */
    
public static function file_info$file$args = array() ) {
        
$path get_attached_file$file );
        if ( ! 
$path ) {
            return 
false;
        }

        return 
wp_parse_args( array(
            
'ID'    => $file,
            
'name'  => basename$path ),
            
'path'  => $path,
            
'url'   => wp_get_attachment_url$file ),
            
'title' => get_the_title$file ),
        ), 
wp_get_attachment_metadata$file ) );
    }

    
/**
     * Format value for the helper functions.
     *
     * @param array        $field Field parameters.
     * @param string|array $value The field meta value.
     * @return string
     */
    
public static function format_value$field$value ) {
        if ( ! 
$field['clone'] ) {
            return 
self::call'format_single_value'$field$value );
        }
        
$output '<ul>';
        foreach ( 
$value as $subvalue ) {
            
$output .= '<li>' self::call'format_single_value'$field$subvalue ) . '</li>';
        }
        
$output .= '</ul>';
        return 
$output;
    }

    
/**
     * Format a single value for the helper functions.
     *
     * @param array $field Field parameters.
     * @param array $value The value.
     * @return string
     */
    
public static function format_single_value$field$value ) {
        
$output '<ul>';
        foreach ( 
$value as $file ) {
            
$output .= sprintf'<li><a href="%s" target="_blank">%s</a></li>'$file['url'], $file['title'] );
        }
        
$output .= '</ul>';
        return 
$output;
    }
}
x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586