|
@@ -70,19 +70,19 @@ class QDR_TSS_Download {
|
|
|
'id' => null,
|
|
'id' => null,
|
|
|
), $atts, 'qdr_tss_download');
|
|
), $atts, 'qdr_tss_download');
|
|
|
|
|
|
|
|
- // Get media ID from shortcode attribute or URL parameter
|
|
|
|
|
- $media_id = $atts['id'];
|
|
|
|
|
- if (!$media_id && isset($_GET['id'])) {
|
|
|
|
|
- $media_id = intval($_GET['id']);
|
|
|
|
|
|
|
+ // Get fileid from shortcode attribute or URL parameter
|
|
|
|
|
+ $fileid = $atts['id'];
|
|
|
|
|
+ if (!$fileid && isset($_GET['id'])) {
|
|
|
|
|
+ $fileid = sanitize_text_field($_GET['id']);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // If no media ID, show form to enter media ID, password and reference
|
|
|
|
|
- if (!$media_id) {
|
|
|
|
|
|
|
+ // If no fileid, show form to enter fileid, password and reference
|
|
|
|
|
+ if (!$fileid) {
|
|
|
return $this->render_download_form();
|
|
return $this->render_download_form();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // Get media information
|
|
|
|
|
- $item = $this->db_manager->get_item_by_media_id($media_id);
|
|
|
|
|
|
|
+ // Get file information
|
|
|
|
|
+ $item = $this->db_manager->get_item_by_fileid($fileid);
|
|
|
|
|
|
|
|
if (!$item) {
|
|
if (!$item) {
|
|
|
return '<div class="qdr-tss-error">' . __('File not found.', 'qdr-temporary-shared-storage') . '</div>';
|
|
return '<div class="qdr-tss-error">' . __('File not found.', 'qdr-temporary-shared-storage') . '</div>';
|
|
@@ -108,14 +108,14 @@ class QDR_TSS_Download {
|
|
|
// Verify password
|
|
// Verify password
|
|
|
$password = isset($_POST['qdr_tss_password']) ? $_POST['qdr_tss_password'] : '';
|
|
$password = isset($_POST['qdr_tss_password']) ? $_POST['qdr_tss_password'] : '';
|
|
|
if (!wp_check_password($password, $item->password)) {
|
|
if (!wp_check_password($password, $item->password)) {
|
|
|
- return '<div class="qdr-tss-error">' . __('Invalid password.', 'qdr-temporary-shared-storage') . '</div>' . $this->render_download_form($media_id);
|
|
|
|
|
|
|
+ return '<div class="qdr-tss-error">' . __('Invalid password.', 'qdr-temporary-shared-storage') . '</div>' . $this->render_download_form($fileid);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Verify reference if set
|
|
// Verify reference if set
|
|
|
if (!empty($item->reference)) {
|
|
if (!empty($item->reference)) {
|
|
|
$reference = isset($_POST['qdr_tss_reference']) ? $_POST['qdr_tss_reference'] : '';
|
|
$reference = isset($_POST['qdr_tss_reference']) ? $_POST['qdr_tss_reference'] : '';
|
|
|
if ($reference !== $item->reference) {
|
|
if ($reference !== $item->reference) {
|
|
|
- return '<div class="qdr-tss-error">' . __('Invalid reference.', 'qdr-temporary-shared-storage') . '</div>' . $this->render_download_form($media_id);
|
|
|
|
|
|
|
+ return '<div class="qdr-tss-error">' . __('Invalid reference.', 'qdr-temporary-shared-storage') . '</div>' . $this->render_download_form($fileid);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -143,7 +143,7 @@ class QDR_TSS_Download {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // Show download form with media information
|
|
|
|
|
|
|
+ // Show download form with file information
|
|
|
$output = '<div class="qdr-tss-download-info">';
|
|
$output = '<div class="qdr-tss-download-info">';
|
|
|
$output .= '<h2>' . __('File Information', 'qdr-temporary-shared-storage') . '</h2>';
|
|
$output .= '<h2>' . __('File Information', 'qdr-temporary-shared-storage') . '</h2>';
|
|
|
$output .= '<p><strong>' . __('File Name:', 'qdr-temporary-shared-storage') . '</strong> ' . esc_html($item->original_file_name) . '</p>';
|
|
$output .= '<p><strong>' . __('File Name:', 'qdr-temporary-shared-storage') . '</strong> ' . esc_html($item->original_file_name) . '</p>';
|
|
@@ -157,7 +157,7 @@ class QDR_TSS_Download {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$output .= '</div>';
|
|
$output .= '</div>';
|
|
|
- $output .= $this->render_download_form($media_id);
|
|
|
|
|
|
|
+ $output .= $this->render_download_form($fileid);
|
|
|
|
|
|
|
|
return $output;
|
|
return $output;
|
|
|
}
|
|
}
|
|
@@ -166,23 +166,23 @@ class QDR_TSS_Download {
|
|
|
* Render download form.
|
|
* Render download form.
|
|
|
*
|
|
*
|
|
|
* @since 1.0.0
|
|
* @since 1.0.0
|
|
|
- * @param int $media_id Optional. Media ID.
|
|
|
|
|
- * @return string Download form HTML.
|
|
|
|
|
|
|
+ * @param string $fileid Optional. File ID.
|
|
|
|
|
+ * @return string Download form HTML.
|
|
|
*/
|
|
*/
|
|
|
- private function render_download_form($media_id = null) {
|
|
|
|
|
|
|
+ private function render_download_form($fileid = null) {
|
|
|
$form = '<div class="qdr-tss-download-form">';
|
|
$form = '<div class="qdr-tss-download-form">';
|
|
|
$form .= '<form method="post" action="">';
|
|
$form .= '<form method="post" action="">';
|
|
|
|
|
|
|
|
// Add nonce for security
|
|
// Add nonce for security
|
|
|
$form .= wp_nonce_field('qdr_tss_download', 'qdr_tss_nonce', true, false);
|
|
$form .= wp_nonce_field('qdr_tss_download', 'qdr_tss_nonce', true, false);
|
|
|
|
|
|
|
|
- if (!$media_id) {
|
|
|
|
|
|
|
+ if (!$fileid) {
|
|
|
$form .= '<div class="qdr-tss-form-group">';
|
|
$form .= '<div class="qdr-tss-form-group">';
|
|
|
- $form .= '<label for="qdr_tss_media_id">' . __('Media ID', 'qdr-temporary-shared-storage') . '</label>';
|
|
|
|
|
- $form .= '<input type="text" name="id" id="qdr_tss_media_id" required>';
|
|
|
|
|
|
|
+ $form .= '<label for="qdr_tss_fileid">' . __('File ID', 'qdr-temporary-shared-storage') . '</label>';
|
|
|
|
|
+ $form .= '<input type="text" name="id" id="qdr_tss_fileid" required>';
|
|
|
$form .= '</div>';
|
|
$form .= '</div>';
|
|
|
} else {
|
|
} else {
|
|
|
- $form .= '<input type="hidden" name="id" value="' . esc_attr($media_id) . '">';
|
|
|
|
|
|
|
+ $form .= '<input type="hidden" name="id" value="' . esc_attr($fileid) . '">';
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$form .= '<div class="qdr-tss-form-group">';
|
|
$form .= '<div class="qdr-tss-form-group">';
|