admin-content.php
5 years ago
folder-deactivate-form.php
5 years ago
folder-popup.php
5 years ago
general-settings.php
5 years ago
help.php
5 years ago
media-replace.php
5 years ago
recommended-plugins.php
5 years ago
update.php
5 years ago
upgrade-table.php
5 years ago
upgrade-to-pro.php
5 years ago
media-replace.php
166 lines
| 1 | <?php |
| 2 | if ( ! defined( 'ABSPATH' ) ) exit; |
| 3 | |
| 4 | if (!current_user_can('upload_files')) |
| 5 | wp_die(esc_html__('You do not have permission to upload files.', 'enable-media-replace')); |
| 6 | |
| 7 | global $wpdb; |
| 8 | |
| 9 | $attachment_id = intval($_GET['attachment_id']); |
| 10 | $attachment = get_post($attachment_id); |
| 11 | |
| 12 | $size = 0; |
| 13 | if(isset($attachment->guid)) { |
| 14 | $size = $this->getFileSize($attachment_id); |
| 15 | } |
| 16 | //$url = wp_get_attachment_url($attachment_id); die; |
| 17 | $guid = $attachment->guid; |
| 18 | $url = wp_get_attachment_url($attachment_id); |
| 19 | if(!empty($url)) { |
| 20 | $guid = $url; |
| 21 | } |
| 22 | $guid = explode(".", $guid); |
| 23 | $ext = array_pop($guid); |
| 24 | $image_meta = wp_get_attachment_metadata($attachment_id); |
| 25 | $thumb = wp_get_attachment_image_src($attachment_id, 'thumbnail'); |
| 26 | $source_type = get_post_mime_type($attachment_id); |
| 27 | $url = ""; |
| 28 | if(isset($thumb[0])) { |
| 29 | $url = $thumb[0]; |
| 30 | } |
| 31 | $file_parts = pathinfo($attachment->guid); |
| 32 | $file_name = $file_parts['basename']; |
| 33 | |
| 34 | $customize_folders = get_option("customize_folders"); |
| 35 | if(isset($customize_folders['show_folder_in_settings']) && $customize_folders['show_folder_in_settings'] == "yes") { |
| 36 | $upgradeURL = admin_url("options-general.php?page=wcp_folders_settings&setting_page=upgrade-to-pro"); |
| 37 | } else { |
| 38 | $upgradeURL = admin_url("admin.php?page=folders-upgrade-to-pro"); |
| 39 | } |
| 40 | $current_date = date_i18n('d/M/Y H:i', strtotime($attachment->post_date) ) |
| 41 | ?> |
| 42 | <div class="wrap"> |
| 43 | <h2><?php esc_html_e("Replace Media", "folders"); ?></h2> |
| 44 | <form enctype="multipart/form-data" method="POST" action="<?php echo esc_url($form_action) ?>"> |
| 45 | <div class="replace-media-page"> |
| 46 | <p><b><?php esc_html_e("Current File", "folders") ?></b>: <?php echo esc_attr($file_name) ?></p> |
| 47 | <p><?php esc_html_e("Upload a new file instead of the current one", "folders") ?></p> |
| 48 | <p><?php printf(__('Maximum file size: <strong>%s</strong>', 'enable-media-replace'), size_format(wp_max_upload_size())) ?></p> |
| 49 | <input type="hidden" name="attachment_id" value="<?php echo esc_attr__($attachment_id) ?>"/> |
| 50 | <input type="hidden" name="ext" id="file_ext" value="<?php echo esc_attr__($ext) ?>"/> |
| 51 | <div class="upload-media-box"> |
| 52 | |
| 53 | </div> |
| 54 | <div class=""> |
| 55 | <div class="current-image-box"> |
| 56 | <div class="file-option"><?php esc_html_e("Current File", "folders") ?></div> |
| 57 | <div class="preview-box"> |
| 58 | <?php if (wp_attachment_is('image', $attachment_id)) { ?> |
| 59 | <?php if(!empty($url)) { ?> |
| 60 | <img src="<?php echo esc_url($url) ?>" /> |
| 61 | <span class="image-size"><?php echo esc_attr($image_meta['width']." PX x ".$image_meta['height'])." PX" ?></span> |
| 62 | <?php } ?> |
| 63 | <?php } else { ?> |
| 64 | <span class="dashicons dashicons-media-document"></span> |
| 65 | <?php } ?> |
| 66 | </div> |
| 67 | <?php if(!empty($size)) { ?> |
| 68 | <div class="file-size"><a target="_blank" href="<?php echo esc_url($upgradeURL) ?>"><?php esc_html_e("Upgrade to Pro", "folders") ?></a> <?php esc_html_e("to compare file size", "folders") ?></div> |
| 69 | <?php } ?> |
| 70 | </div> |
| 71 | <div class="new-image-box"> |
| 72 | <div class="file-option"><?php esc_html_e("New File", "folders") ?></div> |
| 73 | <div class="preview-box"> |
| 74 | <div class="container" > |
| 75 | <div class="container" > |
| 76 | <input type="file" name="new_media_file" id="media_file"> |
| 77 | |
| 78 | <!-- Drag and Drop container--> |
| 79 | <div class="upload-area" id="upload-file"> |
| 80 | <div class="drag-and-drop-title"> |
| 81 | <span><?php echo esc_html_e("Click here to upload file", "folders") ?></span> |
| 82 | </div> |
| 83 | <div class="upgrade-btn-box"> |
| 84 | <a target="_blank" href="<?php echo esc_url($upgradeURL) ?>"><?php esc_html_e("Upgrade to Pro", "folders") ?></a> |
| 85 | </div> |
| 86 | </div> |
| 87 | </div> |
| 88 | </div> |
| 89 | </div> |
| 90 | <div class="file-size hide-it"><a target="_blank" href="<?php echo esc_url($upgradeURL) ?>"><?php esc_html_e("Upgrade to Pro", "folders") ?></a> <?php esc_html_e("to compare file size", "folders") ?></div> |
| 91 | </div> |
| 92 | <div class="clearfix"></div> |
| 93 | </div> |
| 94 | |
| 95 | <div class="file-type warning replace-message"> |
| 96 | <?php esc_html_e("Replacement file is not the same filetype. This might cause unexpected issues", "folders"); ?> |
| 97 | </div> |
| 98 | |
| 99 | <div class="media-bottom-box pro"> |
| 100 | <div class="media-bottom-pro"> |
| 101 | <div class="media-bottom-box-left"> |
| 102 | <div class="media-setting"> |
| 103 | <div class="media-title"><?php esc_html_e("Replacement Options", "folders") ?></div> |
| 104 | <div class="media-form"> |
| 105 | <div class="media-option"> |
| 106 | <label for="replace_only_file"><input type="radio" checked name="replacement_option" value="replace_only_file" id="replace_only_file" /> <?php esc_html_e("Just replace the file", "folders") ?></label> |
| 107 | </div> |
| 108 | <div class="media-note"> |
| 109 | <?php esc_html_e("Note: This option requires you to upload a file of the same type (png) as the one you are replacing. The name of the attachment will stay the same (image.png) no matter what the file you upload is called.", "folders"); ?> |
| 110 | </div> |
| 111 | <div class="media-option"> |
| 112 | <label for="replace_file_with_name"><input type="radio" name="replacement_option" value="replace_file_with_name" id="replace_file_with_name" /> <?php esc_html_e("Replace the file, use new file name and update all links", "folders") ?></label> |
| 113 | </div> |
| 114 | <div class="media-note"> |
| 115 | <?php esc_html_e("Note: If you check this option, the name and type of the file you are about to upload will replace the old file. All links pointing to the current file (image.png) will be updated to point to the new file name. (If any other websites link to the file directly, those links will no longer work. Be careful.)", "folders"); ?> |
| 116 | </div> |
| 117 | </div> |
| 118 | </div> |
| 119 | </div> |
| 120 | <div class="media-bottom-box-right"> |
| 121 | <div class="media-setting"> |
| 122 | <div class="media-title"><?php esc_html_e("Date Options", "folders") ?></div> |
| 123 | <div class="media-form"> |
| 124 | <div class="media-note"> |
| 125 | <?php esc_html_e("When replacing the media, do you want to:", "folders"); ?> |
| 126 | </div> |
| 127 | <ul> |
| 128 | <li> |
| 129 | <label for="replace_date"><input type="radio" name="date_options" value="replace_date" id="replace_date" /> <?php esc_html_e("Replace the date", "folders") ?></label> |
| 130 | </li> |
| 131 | <li> |
| 132 | <label for="keep_date"><input type="radio" checked name="date_options" value="keep_date" id="keep_date" /> <?php esc_html_e("Keep the date", "folders") ?> <small>(<?php echo esc_attr($current_date) ?>)</small></label> |
| 133 | </li> |
| 134 | <li> |
| 135 | <label for="select_custom_date"><input type="radio" name="date_options" value="custom_date" id="select_custom_date" /> <?php esc_html_e("Set a Custom Date", "folders") ?></label> |
| 136 | </li> |
| 137 | </ul> |
| 138 | <div class="custom-date" id="custom-date"> |
| 139 | <label for="custom_date"><?php esc_html_e("Custom date", "folders"); ?></label> |
| 140 | <span class="inline"><input type="text" class="media-date" name="custom_date" value="<?php echo date("F j, Y") ?>" id="custom_date"></span><span class="inline-block">@</span><span class="inline"><input type="text" name="custom_date_hour" class="media-time" value="<?php echo date("m") ?>" id="custom_date_hour"></span><span class="inline-block">:</span><span class="inline"><input type="text" class="media-time" name="custom_date_min" value="<?php echo date("i") ?>" id="custom_date_min"></span> |
| 141 | </div> |
| 142 | <div class="custom-date" id="custom-path"> |
| 143 | <input type="hidden" name="new_folder_option" value="0"> |
| 144 | <label for="new_folder_option"><input type="checkbox" id="new_folder_option" name="new_folder_option" value="1"><?php esc_html_e("Put new Upload in Updated Folder", "folders"); ?></label> |
| 145 | <span class="inline"><input type="text" class="media-date" name="new_folder_path" value="<?php echo date("Y/m") ?>" id="new_folder_path"></span> |
| 146 | </div> |
| 147 | </div> |
| 148 | </div> |
| 149 | </div> |
| 150 | <div class="clear"></div> |
| 151 | </div> |
| 152 | <div class="media-bottom-pro-button"> |
| 153 | <div class="pro-button"> |
| 154 | <a target="_blank" href="<?php echo esc_url($upgradeURL) ?>"><?php esc_html_e("Upgrade to Pro", "folders") ?></a> |
| 155 | </div> |
| 156 | </div> |
| 157 | </div> |
| 158 | |
| 159 | <div class="replace-media-buttons"> |
| 160 | <button type="submit" class="button button-primary" disabled><?php echo esc_html_e("Replace File", "folders") ?></button> |
| 161 | <button type="button" class="button button-secondary" onclick="history.back();"><?php echo esc_html_e("Cancel", "folders") ?></button> |
| 162 | </div> |
| 163 | </div> |
| 164 | </form> |
| 165 | </div> |
| 166 |