Changeset 3234611
- Timestamp:
- 02/04/2025 11:06:22 AM (14 months ago)
- Location:
- topirank-integration
- Files:
-
- 32 added
- 10 edited
-
tags/1.0.4 (added)
-
tags/1.0.4/admin (added)
-
tags/1.0.4/admin/admin-page.php (added)
-
tags/1.0.4/admin/menu.php (added)
-
tags/1.0.4/assets (added)
-
tags/1.0.4/assets/css (added)
-
tags/1.0.4/assets/css/topirank-admin-style.css (added)
-
tags/1.0.4/assets/css/topirank-editor-style.css (added)
-
tags/1.0.4/assets/css/topirank-normalize.css (added)
-
tags/1.0.4/assets/css/topirank-post-admin-style.css (added)
-
tags/1.0.4/assets/js (added)
-
tags/1.0.4/assets/js/topirank-admin-scripts.js (added)
-
tags/1.0.4/assets/js/topirank-normalize.js (added)
-
tags/1.0.4/includes (added)
-
tags/1.0.4/includes/api-integration.php (added)
-
tags/1.0.4/includes/create-template.php (added)
-
tags/1.0.4/includes/extract-and-create.php (added)
-
tags/1.0.4/includes/file-upload.php (added)
-
tags/1.0.4/includes/helpers.php (added)
-
tags/1.0.4/includes/init.php (added)
-
tags/1.0.4/includes/process-folders.php (added)
-
tags/1.0.4/includes/register-files.php (added)
-
tags/1.0.4/includes/resource-cleaner.php (added)
-
tags/1.0.4/includes/topirank-template.php (added)
-
tags/1.0.4/includes/update-content-and-seo.php (added)
-
tags/1.0.4/includes/update-functionality.php (added)
-
tags/1.0.4/languages (added)
-
tags/1.0.4/languages/topirank-integration-fr_FR.mo (added)
-
tags/1.0.4/languages/topirank-integration-fr_FR.po (added)
-
tags/1.0.4/languages/topirank-integration.pot (added)
-
tags/1.0.4/readme.txt (added)
-
tags/1.0.4/topirank-integration.php (added)
-
trunk/admin/admin-page.php (modified) (2 diffs)
-
trunk/assets/css/topirank-normalize.css (modified) (1 diff)
-
trunk/includes/api-integration.php (modified) (3 diffs)
-
trunk/includes/extract-and-create.php (modified) (1 diff)
-
trunk/includes/file-upload.php (modified) (1 diff)
-
trunk/includes/helpers.php (modified) (1 diff)
-
trunk/includes/init.php (modified) (1 diff)
-
trunk/includes/update-content-and-seo.php (modified) (2 diffs)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/topirank-integration.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
topirank-integration/trunk/admin/admin-page.php
r3220350 r3234611 19 19 <div id="notification" class="notification"></div> 20 20 <div class="topirank_wrap"> 21 <?php topirank_handle_file_upload(); ?>22 21 <form method="POST" enctype="multipart/form-data" action="<?php echo esc_url(admin_url('admin.php?page=topirank_process_upload')); ?>"> 23 <?php wp_nonce_field('topirank_file_upload_action', 'topirank_file_upload_nonce'); ?>24 22 <div class="topirank_main_content_line first_line"> 25 23 <div class="topirank_line_left_column"> … … 100 98 </div> 101 99 </div> 102 </div>103 </div>104 100 <?php 105 101 } -
topirank-integration/trunk/assets/css/topirank-normalize.css
r3220350 r3234611 72 72 .topirank-styles table { 73 73 display: inline-table !important; 74 border-width: 0; 74 75 } 75 76 -
topirank-integration/trunk/includes/api-integration.php
r3220350 r3234611 16 16 ]); 17 17 18 register_rest_route('topirank-integration', '/chunk-size', [ 19 'methods' => 'GET', 20 'callback' => 'topirank_get_chunk_size', 21 'permission_callback' => '__return_true', 22 ]); 23 18 24 register_rest_route('topirank-integration', '/ping', [ 19 25 'methods' => 'GET', … … 24 30 add_action('rest_api_init', 'topirank_custom_rest_route'); 25 31 32 function topirank_get_chunk_size(WP_REST_Request $request) 33 { 34 $upload_max_filesize = ini_get('upload_max_filesize'); 35 $post_max_size = ini_get('post_max_size'); 36 $max_upload_size = wp_convert_hr_to_bytes($upload_max_filesize); 37 $max_post_size = wp_convert_hr_to_bytes($post_max_size); 38 $default_chunk_size = min($max_upload_size, $max_post_size); 39 return new WP_REST_Response(['chunk_size' => intval($default_chunk_size * 0.8)], 200); 40 } 26 41 27 42 … … 80 95 function topirank_handle_rest_file_upload(WP_REST_Request $request) 81 96 { 97 82 98 /* phpcs:disable WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing */ 83 99 84 if (!isset($_FILES['html_archive']) || empty($_FILES['html_archive'])) { 85 return new WP_REST_Response(['message' => 'File not found.'], 400); 100 $file = $_FILES['html_archive']; 101 102 $chunkIndex = intval($request->get_param('chunkIndex')); 103 $totalChunks = intval($request->get_param('totalChunks')); 104 $fileName = sanitize_file_name($request->get_param('fileName')); 105 $replace = isset($request['replace']) && $request['replace'] === 'true'; 106 $selected_style = isset($request['style']) ? sanitize_text_field($request['style']) : 'not set'; 107 108 if (!$file || $file['error'] !== UPLOAD_ERR_OK) { 109 return new WP_REST_Response(['message' => 'Error uploading chunk.'], 400); 86 110 } 87 111 88 $file = [ 89 'name' => isset($_FILES['html_archive']['name']) ? sanitize_file_name(wp_unslash($_FILES['html_archive']['name'])) : '', 90 'type' => isset($_FILES['html_archive']['type']) ? sanitize_mime_type($_FILES['html_archive']['type']) : '', 91 'tmp_name' => isset($_FILES['html_archive']['tmp_name']) ? sanitize_text_field($_FILES['html_archive']['tmp_name']) : '', 92 'error' => isset($_FILES['html_archive']['error']) ? intval($_FILES['html_archive']['error']) : 0, 93 'size' => isset($_FILES['html_archive']['size']) ? intval($_FILES['html_archive']['size']) : 0, 94 ]; 112 $upload_dir = wp_upload_dir(); 113 $base_temp_dir = $upload_dir['basedir'] . '/topirank-temp'; 95 114 96 $replace = isset($request['replace']) && $request['replace'] == 'true'; 97 $selected_style = isset($request['style']) ? $request['style'] : 'not set'; 115 $temp_dir = $base_temp_dir . '/' . md5($fileName); 98 116 99 if (!function_exists('wp_handle_upload')) { 100 require_once ABSPATH . 'wp-admin/includes/file.php'; 117 118 if (!file_exists($temp_dir)) { 119 wp_mkdir_p($temp_dir); 101 120 } 102 121 103 $file_extension = pathinfo($file['name'], PATHINFO_EXTENSION); 104 if ($file_extension !== 'zip') { 105 return new WP_REST_Response(['message' => 'Please upload a ZIP archive.'], 400); 122 $temp_file_path = $temp_dir . '/' . $fileName . '.part'; 123 124 $handle = fopen($temp_file_path, 'ab'); 125 if (!$handle) { 126 return new WP_REST_Response(['message' => 'Error opening temp file.'], 500); 106 127 } 107 128 108 $uploaded_file = wp_handle_upload($file, ['test_form' => false]); 129 $chunk_data = file_get_contents($file['tmp_name']); 130 fwrite($handle, $chunk_data); 131 fclose($handle); 109 132 110 if ($uploaded_file && !isset($uploaded_file['error'])) { 111 $zip_path = $uploaded_file['file']; 112 $upload_dir = wp_upload_dir(); 133 if ($chunkIndex + 1 === $totalChunks) { 134 $final_path = $upload_dir['basedir'] . '/topirank-import-files/' . $fileName; 135 136 if (!file_exists(dirname($final_path))) { 137 wp_mkdir_p(dirname($final_path)); 138 } 139 140 if (!rename($temp_file_path, $final_path)) { 141 return new WP_REST_Response(['message' => 'Failed to finalize file upload.'], 500); 142 } 143 144 $file_extension = pathinfo($final_path, PATHINFO_EXTENSION); 145 if ($file_extension !== 'zip') { 146 return new WP_REST_Response(['message' => 'Please upload a ZIP archive.'], 400); 147 } 148 113 149 $topirank_dir = $upload_dir['basedir'] . '/topirank-import-files'; 114 topirank_recursive_delete($topirank_dir);115 150 if (!file_exists($topirank_dir)) { 116 151 wp_mkdir_p($topirank_dir); 117 152 } 118 153 119 $extracted_path = $topirank_dir . '/' . basename($zip_path, '.zip'); 154 $extracted_path = $topirank_dir . '/' . basename($final_path, '.zip'); 155 156 if (!function_exists('wp_handle_upload')) { 157 require_once ABSPATH . 'wp-admin/includes/file.php'; 158 } 120 159 121 160 remove_filter('content_save_pre', 'wp_filter_post_kses'); 122 161 remove_filter('content_filtered_save_pre', 'wp_filter_post_kses'); 123 162 ob_start(); 124 topirank_extract_and_create_posts($zip_path, $extracted_path, $replace, $selected_style);163 $process_result = topirank_extract_and_create_posts($final_path, $extracted_path, $replace, $selected_style); 125 164 ob_end_clean(); 126 165 add_filter('content_save_pre', 'wp_filter_post_kses'); 127 166 add_filter('content_filtered_save_pre', 'wp_filter_post_kses'); 128 167 129 topirank_recursive_delete($extracted_path); 130 if (file_exists($zip_path)) { 131 wp_delete_file($zip_path); 168 if ($process_result) { 169 wp_delete_file($final_path); 170 topirank_recursive_delete($extracted_path); 171 } else { 172 return new WP_REST_Response(['message' => 'Failed to process the uploaded file.'], 500); 132 173 } 133 174 175 $files = glob($temp_dir . '/*'); 176 foreach ($files as $file) { 177 if (is_file($file)) { 178 unlink($file); 179 } 180 } 181 rmdir($temp_dir); 182 134 183 return new WP_REST_Response(['message' => 'The file has been successfully uploaded and processed.'], 201); 135 } else {136 return new WP_REST_Response(['message' => 'Error loading file: ' . $uploaded_file['error']], 500);137 184 } 185 186 return new WP_REST_Response(['message' => 'Chunk uploaded successfully.'], 200); 138 187 } -
topirank-integration/trunk/includes/extract-and-create.php
r3220350 r3234611 72 72 73 73 topirank_process_folders($extracted_path, $archive_name, $replace, $selected_style, $check_delete); 74 75 return true; 74 76 } 75 77 -
topirank-integration/trunk/includes/file-upload.php
r3220350 r3234611 24 24 function topirank_handle_file_upload() 25 25 { 26 if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['html_archive'])) { 27 28 if ( 29 !isset($_POST['topirank_file_upload_nonce']) || 30 !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['topirank_file_upload_nonce'])), 'topirank_file_upload_action') 31 ) { 32 wp_die(('Security check failed. Please try again.')); 26 if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'POST') { 27 if (!isset($_FILES['html_archive']) || empty($_FILES['html_archive']['tmp_name'])) { 28 echo '<div class="topirank_main_content_line without_space_between"> 29 <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"> 30 <path d="M12 22C17.523 22 22 17.523 22 12C22 6.477 17.523 2 12 2C6.477 2 2 6.477 2 12C2 17.523 6.477 22 12 22Z" stroke="#CF2323" stroke-width="1.5" stroke-linejoin="round"/> 31 <path d="M14.8289 9.17188L9.17188 14.8289M9.17188 9.17188L14.8289 14.8289" stroke="#CF2323" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/> 32 </svg> 33 <div class="topirank_line_title">'; 34 esc_html_e('Invalid file upload.', 'topirank-integration'); 35 echo '</div> 36 </div>'; 37 return; 33 38 } 34 39 -
topirank-integration/trunk/includes/helpers.php
r3220350 r3234611 5 5 function topirank_create_posts_from_html($folder_path, $archive_name, $replace, $selected_style, &$check_delete) 6 6 { 7 set_time_limit(0); 7 8 $wp_filesystem = topirank_get_filesystem(); 8 9 -
topirank-integration/trunk/includes/init.php
r3220350 r3234611 37 37 exit; 38 38 } 39 40 if (41 !isset($_POST['topirank_file_upload_nonce']) ||42 !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['topirank_file_upload_nonce'])), 'topirank_file_upload_action')43 ) {44 wp_die(('Security check failed. Please try again.'));45 }46 39 } 47 40 }); -
topirank-integration/trunk/includes/update-content-and-seo.php
r3225179 r3234611 35 35 $dom = new DOMDocument(); 36 36 37 $encoded_content = mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8');37 $encoded_content = html_entity_decode(htmlspecialchars($content, ENT_QUOTES | ENT_HTML5, 'UTF-8')); 38 38 $dom->loadHTML($encoded_content, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); 39 39 libxml_clear_errors(); … … 155 155 $dom = new DOMDocument(); 156 156 libxml_use_internal_errors(true); 157 $dom->loadHTML( mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8'), LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);157 $dom->loadHTML(html_entity_decode(htmlspecialchars($content, ENT_QUOTES | ENT_HTML5, 'UTF-8')), LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); 158 158 libxml_clear_errors(); 159 159 } -
topirank-integration/trunk/readme.txt
r3225179 r3234611 4 4 Requires at least: 6.0 5 5 Tested up to: 6.7.1 6 Stable tag: 1.0. 36 Stable tag: 1.0.4 7 7 Requires PHP: 7.3 8 8 License: GPLv2 or later … … 58 58 == Changelog == 59 59 60 = 1.0.4 = 61 * Improved large file upload functionality via the application. 62 * Fixed parsing issues with HTML pages. 63 * Resolved timeout error issues. 64 * Optimized parsing speed for better performance. 65 * Fixed various SEO-related bugs. 66 60 67 = 1.0.3 = 61 68 -
topirank-integration/trunk/topirank-integration.php
r3225180 r3234611 3 3 Plugin Name: Topirank Integration 4 4 Description: Plugin for parsing pages 5 Version: 1.0. 35 Version: 1.0.4 6 6 Author: Topirank 7 7 License: GPLv2 or later
Note: See TracChangeset
for help on using the changeset viewer.