File "class-acf-field-file.php"
Full path: /home/kosmetik/public_html/wp-content/plugins/advanced-custom-fields/includes/fields/class-acf-field-file.php
File
size: 7.35 B
MIME-type: text/x-php
Charset: utf-8
Download Open Edit Advanced Editor Back
<?php
if (!class_exists('acf_field_file')) {
class acf_field_file extends acf_field
{
function initialize()
{
$this->name = 'file';
$this->label = __('File', 'acf');
$this->category = 'content';
$this->defaults = array('return_format' => 'array', 'library' => 'all', 'min_size' => 0, 'max_size' => 0, 'mime_types' => '');
add_filter('get_media_item_args', array($this, 'get_media_item_args'));
}
function input_admin_enqueue_scripts()
{
acf_localize_text(array('Select File' => __('Select File', 'acf'), 'Edit File' => __('Edit File', 'acf'), 'Update File' => __('Update File', 'acf')));
}
function render_field($field)
{
$uploader = acf_get_setting('uploader');
$uploader = acf_maybe_get($field, 'uploader', $uploader);
if ($uploader == 'wp') {
acf_enqueue_uploader();
}
$o = array('icon' => '', 'title' => '', 'url' => '', 'filename' => '', 'filesize' => '');
$div = array('class' => 'acf-file-uploader', 'data-library' => $field['library'], 'data-mime_types' => $field['mime_types'], 'data-uploader' => $uploader);
if ($field['value']) {
$attachment = acf_get_attachment($field['value']);
if ($attachment) {
$div['class'] .= ' has-value';
$o['icon'] = $attachment['icon'];
$o['title'] = $attachment['title'];
$o['url'] = $attachment['url'];
$o['filename'] = $attachment['filename'];
if ($attachment['filesize']) {
$o['filesize'] = size_format($attachment['filesize']);
}
}
}
?>
<div <?php
acf_esc_attr_e($div);
?>>
<?php
acf_hidden_input(array('name' => $field['name'], 'value' => $field['value'], 'data-name' => 'id'));
?>
<div class="show-if-value file-wrap">
<div class="file-icon">
<img data-name="icon" src="<?php
echo esc_url($o['icon']);
?>" alt=""/>
</div>
<div class="file-info">
<p>
<strong data-name="title"><?php
echo esc_html($o['title']);
?></strong>
</p>
<p>
<strong><?php
_e('File name', 'acf');
?>:</strong>
<a data-name="filename" href="<?php
echo esc_url($o['url']);
?>" target="_blank"><?php
echo esc_html($o['filename']);
?></a>
</p>
<p>
<strong><?php
_e('File size', 'acf');
?>:</strong>
<span data-name="filesize"><?php
echo esc_html($o['filesize']);
?></span>
</p>
</div>
<div class="acf-actions -hover">
<?php
if ($uploader != 'basic') {
?>
<a class="acf-icon -pencil dark" data-name="edit" href="#" title="<?php
_e('Edit', 'acf');
?>"></a>
<?php
}
?>
<a class="acf-icon -cancel dark" data-name="remove" href="#" title="<?php
_e('Remove', 'acf');
?>"></a>
</div>
</div>
<div class="hide-if-value">
<?php
if ($uploader == 'basic') {
?>
<?php
if ($field['value'] && !is_numeric($field['value'])) {
?>
<div class="acf-error-message"><p><?php
echo acf_esc_html($field['value']);
?></p></div>
<?php
}
?>
<label class="acf-basic-uploader">
<?php
acf_file_input(array('name' => $field['name'], 'id' => $field['id']));
?>
</label>
<?php
} else {
?>
<p><?php
_e('No file selected', 'acf');
?> <a data-name="add" class="acf-button button" href="#"><?php
_e('Add File', 'acf');
?></a></p>
<?php
}
?>
</div>
</div>
<?php
}
function render_field_settings($field)
{
$clear = array('min_size', 'max_size');
foreach ($clear as $k) {
if (empty($field[$k])) {
$field[$k] = '';
}
}
acf_render_field_setting($field, array('label' => __('Return Value', 'acf'), 'instructions' => __('Specify the returned value on front end', 'acf'), 'type' => 'radio', 'name' => 'return_format', 'layout' => 'horizontal', 'choices' => array('array' => __('File Array', 'acf'), 'url' => __('File URL', 'acf'), 'id' => __('File ID', 'acf'))));
acf_render_field_setting($field, array('label' => __('Library', 'acf'), 'instructions' => __('Limit the media library choice', 'acf'), 'type' => 'radio', 'name' => 'library', 'layout' => 'horizontal', 'choices' => array('all' => __('All', 'acf'), 'uploadedTo' => __('Uploaded to post', 'acf'))));
acf_render_field_setting($field, array('label' => __('Minimum', 'acf'), 'instructions' => __('Restrict which files can be uploaded', 'acf'), 'type' => 'text', 'name' => 'min_size', 'prepend' => __('File size', 'acf'), 'append' => 'MB'));
acf_render_field_setting($field, array('label' => __('Maximum', 'acf'), 'instructions' => __('Restrict which files can be uploaded', 'acf'), 'type' => 'text', 'name' => 'max_size', 'prepend' => __('File size', 'acf'), 'append' => 'MB'));
acf_render_field_setting($field, array('label' => __('Allowed file types', 'acf'), 'instructions' => __('Comma separated list. Leave blank for all types', 'acf'), 'type' => 'text', 'name' => 'mime_types'));
}
function format_value($value, $post_id, $field)
{
if (empty($value)) {
return false;
}
if (!is_numeric($value)) {
return false;
}
$value = intval($value);
if ($field['return_format'] == 'url') {
return wp_get_attachment_url($value);
} elseif ($field['return_format'] == 'array') {
return acf_get_attachment($value);
}
return $value;
}
function get_media_item_args($vars)
{
$vars['send'] = true;
return $vars;
}
function update_value($value, $post_id, $field)
{
if (empty($value)) {
return $value;
}
$attachment_id = acf_idval($value);
acf_connect_attachment_to_post($attachment_id, $post_id);
return $attachment_id;
}
function validate_value($valid, $value, $field, $input)
{
if (empty($value)) {
return $valid;
}
if (is_numeric($value)) {
return $valid;
}
if (!is_string($value)) {
return $valid;
}
$file = null;
parse_str($value, $file);
if (empty($file)) {
return $valid;
}
$errors = acf_validate_attachment($file, $field, 'basic_upload');
if (!empty($errors)) {
$valid = implode("\n", $errors);
}
return $valid;
}
}
acf_register_field_type('acf_field_file');
}