/** * Sanitize code textareas * @since 1.0.2 * @param string $meta Meta value * @param array $field Field config array * @return string Sanitized data */ public static function file($meta, $field) { $_id_name = $field['id'] . '_id'; // get _id old value $_id_old = cmb_Meta_Box::get_data($_id_name); // If specified NOT to save the file ID if (isset($field['save_id']) && !$field['save_id']) { $_new_id = ''; } else { // otherwise get the file ID $_new_id = isset($_POST[$_id_name]) ? $_POST[$_id_name] : null; // If there is no ID saved yet, try to get it from the url if (isset($_POST[$field['id']]) && $_POST[$field['id']] && !$_new_id) { $_new_id = cmb_Meta_Box::image_id_from_url(esc_url_raw($_POST[$field['id']])); } } if ($_new_id && $_new_id != $_id_old) { $updated[] = $_id_name; cmb_Meta_Box::update_data($_new_id, $_id_name); } elseif ('' == $_new_id && $_id_old) { $updated[] = $_id_name; cmb_Meta_Box::remove_data($_id_name, $old); } return self::default_sanitization($meta, $field); }
public static function file($field, $meta, $object_id, $object_type) { $input_type_url = 'hidden'; if ('url' == $field['allow'] || is_array($field['allow']) && in_array('url', $field['allow'])) { $input_type_url = 'text'; } echo '<input class="cmb_upload_file" type="' . $input_type_url . '" size="45" id="', $field['id'], '" name="', $field['id'], '" value="', $meta, '" />'; echo '<input class="cmb_upload_button button" type="button" value="' . __('Add or Upload File', 'cmb') . '" />'; $_id_name = $field['id'] . '_id'; $_id_meta = cmb_Meta_Box::get_data($_id_name); // If there is no ID saved yet, try to get it from the url if ($meta && !$_id_meta) { $_id_meta = cmb_Meta_Box::image_id_from_url(esc_url_raw($meta)); } echo '<input class="cmb_upload_file_id" type="hidden" id="', $_id_name, '" name="', $_id_name, '" value="', $_id_meta, '" />', self::desc(true), '<div id="', $field['id'], '_status" class="cmb_media_status">'; if (!empty($meta)) { if (self::is_valid_img_ext($meta)) { echo '<div class="img_status">'; echo '<img style="max-width: 350px; width: 100%; height: auto;" src="', $meta, '" alt="" />'; echo '<p><a href="#" class="cmb_remove_file_button" rel="', $field['id'], '">' . __('Remove Image', 'cmb') . '</a></p>'; echo '</div>'; } else { // $file_ext = self::get_file_ext( $meta ); $parts = explode('/', $meta); for ($i = 0; $i < count($parts); ++$i) { $title = $parts[$i]; } echo __('File:', 'cmb'), ' <strong>', $title, '</strong> (<a href="', $meta, '" target="_blank" rel="external">' . __('Download', 'cmb') . '</a> / <a href="#" class="cmb_remove_file_button" rel="', $field['id'], '">' . __('Remove', 'cmb') . '</a>)'; } } echo '</div>'; }