Changeset 3268778
- Timestamp:
- 04/08/2025 12:27:36 PM (12 months ago)
- Location:
- topirank-integration
- Files:
-
- 32 added
- 10 edited
-
tags/1.1.4 (added)
-
tags/1.1.4/admin (added)
-
tags/1.1.4/admin/admin-page.php (added)
-
tags/1.1.4/admin/menu.php (added)
-
tags/1.1.4/assets (added)
-
tags/1.1.4/assets/css (added)
-
tags/1.1.4/assets/css/topirank-admin-style.css (added)
-
tags/1.1.4/assets/css/topirank-editor-style.css (added)
-
tags/1.1.4/assets/css/topirank-normalize.css (added)
-
tags/1.1.4/assets/css/topirank-post-admin-style.css (added)
-
tags/1.1.4/assets/js (added)
-
tags/1.1.4/assets/js/topirank-admin-scripts.js (added)
-
tags/1.1.4/assets/js/topirank-normalize.js (added)
-
tags/1.1.4/includes (added)
-
tags/1.1.4/includes/api-integration.php (added)
-
tags/1.1.4/includes/create-template.php (added)
-
tags/1.1.4/includes/extract-and-create.php (added)
-
tags/1.1.4/includes/file-upload.php (added)
-
tags/1.1.4/includes/helpers.php (added)
-
tags/1.1.4/includes/init.php (added)
-
tags/1.1.4/includes/process-folders.php (added)
-
tags/1.1.4/includes/register-files.php (added)
-
tags/1.1.4/includes/resource-cleaner.php (added)
-
tags/1.1.4/includes/topirank-template.php (added)
-
tags/1.1.4/includes/update-content-and-seo.php (added)
-
tags/1.1.4/includes/update-functionality.php (added)
-
tags/1.1.4/languages (added)
-
tags/1.1.4/languages/topirank-integration-fr_FR.mo (added)
-
tags/1.1.4/languages/topirank-integration-fr_FR.po (added)
-
tags/1.1.4/languages/topirank-integration.pot (added)
-
tags/1.1.4/readme.txt (added)
-
tags/1.1.4/topirank-integration.php (added)
-
trunk/assets/css/topirank-normalize.css (modified) (1 diff)
-
trunk/assets/js/topirank-normalize.js (modified) (1 diff)
-
trunk/includes/api-integration.php (modified) (1 diff)
-
trunk/includes/extract-and-create.php (modified) (3 diffs)
-
trunk/includes/file-upload.php (modified) (3 diffs)
-
trunk/includes/register-files.php (modified) (5 diffs)
-
trunk/includes/topirank-template.php (modified) (1 diff)
-
trunk/includes/update-content-and-seo.php (modified) (6 diffs)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/topirank-integration.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
topirank-integration/trunk/assets/css/topirank-normalize.css
r3266247 r3268778 12 12 width: 100%; 13 13 left: 0; 14 z-index: 9;15 14 } 16 15 17 .contact-item a {18 color:unset;16 .contact-item a { 17 color: unset; 19 18 } 20 19 -
topirank-integration/trunk/assets/js/topirank-normalize.js
r3220350 r3268778 16 16 resizeObserver.observe(nextElement); 17 17 } 18 18 19 }); 20 21 document.addEventListener("DOMContentLoaded", function () { 22 const progressBar = document.querySelector(".first-progress-bar-default"); 23 const body = document.body; 24 25 if (progressBar && body) { 26 body.insertBefore(progressBar, body.firstChild); 27 } 28 }); 29 30 31 window.addEventListener("load", () => { 32 const content = document.querySelector(".optimized-topirank-template"); 33 if (!content) return; 34 35 const headerRoot = document.querySelector("header") || document.querySelector('[data-elementor-type="header"]'); 36 if (!headerRoot) return; 37 38 const allHeaderElements = [headerRoot, ...headerRoot.querySelectorAll("*")]; 39 const fixedEl = allHeaderElements.find(el => getComputedStyle(el).position === "fixed"); 40 41 if (!fixedEl) return; 42 43 requestAnimationFrame(() => { 44 const headerOffsetTop = fixedEl.getBoundingClientRect().top + window.scrollY; 45 const headerHeight = fixedEl.offsetHeight; 46 const progressBar = document.querySelector(".first-progress-bar-default"); 47 const progressBarHeight = progressBar ? progressBar.offsetHeight : 0; 48 49 const totalOffset = headerOffsetTop + headerHeight - progressBarHeight; 50 51 const contentTop = content.getBoundingClientRect().top + window.scrollY; 52 53 if (contentTop < totalOffset + 10) { 54 content.style.paddingTop = `${totalOffset}px`; 55 } 56 }); 57 }); 58 59 60 61 -
topirank-integration/trunk/includes/api-integration.php
r3266247 r3268778 105 105 $replace = isset($request['replace']) && $request['replace'] === 'true'; 106 106 $selected_style = isset($request['style']) ? sanitize_text_field($request['style']) : 'not set'; 107 $selected_type = isset($request['type']) ? sanitize_key($request['type']) : 'page'; 107 108 108 109 if (!$file || $file['error'] !== UPLOAD_ERR_OK) { -
topirank-integration/trunk/includes/extract-and-create.php
r3266247 r3268778 64 64 topirank_search_files($extracted_path, 'js'), 65 65 $js_destination, 66 $selected_style, 67 function ($file_name) { 68 $sanitized = strtolower(str_replace([' ', '_'], '-', $file_name)); 69 return preg_replace('/-+/', '-', $sanitized); 70 } 66 $selected_style 71 67 ); 72 68 … … 183 179 $wp_filesystem = topirank_get_filesystem(); 184 180 181 $page_js_dir = $destination . '/page-js'; 182 if (strpos($destination, '/js/') !== false && !$wp_filesystem->is_dir($page_js_dir)) { 183 $wp_filesystem->mkdir($page_js_dir, FS_CHMOD_DIR); 184 } 185 185 186 foreach ($files as $file) { 186 187 $file_name = basename($file); … … 188 189 $file_name = $name_transform($file_name); 189 190 } 190 $target = trailingslashit($destination) . $file_name; 191 192 if ( 193 pathinfo($file, PATHINFO_EXTENSION) === 'js' && 194 strpos($file, '/js/') !== false 195 ) { 196 $target = trailingslashit($page_js_dir) . $file_name; 197 } else { 198 $target = trailingslashit($destination) . $file_name; 199 } 191 200 192 201 if ($selected_style === 'wp' && pathinfo($file, PATHINFO_EXTENSION) === 'js') { -
topirank-integration/trunk/includes/file-upload.php
r3234611 r3268778 6 6 { 7 7 ?> 8 <div class="topirank_container"> 9 <div class="topirank_wrap"> 10 <div class="topirank_main_content_line"> 11 <button onclick="window.location.href='<?php echo esc_url(admin_url('admin.php?page=topirank_plugin')); ?>'" class="topirank_solid_button"> 12 <?php esc_html_e('Go Back to Main Page', 'topirank-integration'); ?> 13 </button> 14 </div> 15 <?php 16 topirank_handle_file_upload(); 17 ?> 18 </div> 8 <div class="topirank_container"> 9 <div class="topirank_wrap"> 10 <div class="topirank_main_content_line"> 11 <button onclick="window.location.href='<?php echo esc_url(admin_url('admin.php?page=topirank_plugin')); ?>'" class="topirank_solid_button"> 12 <?php esc_html_e('Go Back to Main Page', 'topirank-integration'); ?> 13 </button> 14 </div> 15 <?php 16 topirank_handle_file_upload(); 17 ?> 19 18 </div> 19 </div> 20 20 21 21 <?php … … 24 24 function topirank_handle_file_upload() 25 25 { 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">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 29 <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"> 30 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"/> … … 32 32 </svg> 33 33 <div class="topirank_line_title">'; 34 esc_html_e('Invalid file upload.', 'topirank-integration');35 echo '</div>34 esc_html_e('Invalid file upload.', 'topirank-integration'); 35 echo '</div> 36 36 </div>'; 37 return; 37 return; 38 } 39 40 $file = isset($_FILES['html_archive']) && is_array($_FILES['html_archive']) 41 ? array_map('sanitize_text_field', $_FILES['html_archive']) 42 : null; 43 44 if (is_array($file) && isset($file['name'], $file['tmp_name'])) { 45 $upload_dir = wp_upload_dir(); 46 $topirank_dir = $upload_dir['basedir'] . '/topirank-import-files'; 47 topirank_recursive_delete($topirank_dir); 48 49 $selected_style = isset($_POST['style']) ? sanitize_text_field(wp_unslash($_POST['style'])) : ''; 50 $selected_type = isset($_POST['type']) ? sanitize_text_field(wp_unslash($_POST['type'])) : 'page'; 51 $replace = ''; 52 53 $file_extension = pathinfo($file['name'], PATHINFO_EXTENSION); 54 55 if (strtolower($file_extension) !== 'zip') { 56 echo '<div class="error notice"><p>'; 57 esc_html_e('Please upload a ZIP archive.', 'topirank-integration'); 58 echo '</p></div>'; 59 return; 60 } 61 62 if (!file_exists($topirank_dir)) { 63 wp_mkdir_p($topirank_dir); 64 } 65 66 $uploaded_file = wp_handle_upload($file, array('test_form' => false)); 67 68 if (isset($uploaded_file['file']) && ! isset($uploaded_file['error'])) { 69 $original_path = $uploaded_file['file']; 70 $zip_path = $topirank_dir . '/' . basename($original_path); 71 72 $wp_filesystem = topirank_get_filesystem(); 73 74 if ($wp_filesystem->move($original_path, $zip_path, true)) { 75 $extracted_path = $topirank_dir . '/' . basename($file['name'], '.zip'); 76 topirank_extract_and_create_posts($zip_path, $extracted_path, $replace, $selected_style, $selected_type); 77 78 if ($wp_filesystem->exists($zip_path)) { 79 $wp_filesystem->delete($zip_path); 80 } 81 } else { 82 echo '<div class="topirank_main_content_line">'; 83 echo '<div class="topirank_line_title">'; 84 esc_html_e('Could not move the uploaded file.', 'topirank-integration'); 85 echo '</div>'; 86 echo '</div>'; 38 87 } 39 40 $file = isset($_FILES['html_archive']) && is_array($_FILES['html_archive']) 41 ? array_map('sanitize_text_field', $_FILES['html_archive']) 42 : null; 43 44 if (is_array($file) && isset($file['name'], $file['tmp_name'])) { 45 $upload_dir = wp_upload_dir(); 46 $topirank_dir = $upload_dir['basedir'] . '/topirank-import-files'; 47 topirank_recursive_delete($topirank_dir); 48 49 $selected_style = isset($_POST['style']) ? sanitize_text_field(wp_unslash($_POST['style'])) : ''; 50 $replace = ''; 51 52 $file_extension = pathinfo($file['name'], PATHINFO_EXTENSION); 53 54 if (strtolower($file_extension) !== 'zip') { 55 echo '<div class="error notice"><p>'; 56 esc_html_e('Please upload a ZIP archive.', 'topirank-integration'); 57 echo '</p></div>'; 58 return; 59 } 60 61 if (!file_exists($topirank_dir)) { 62 wp_mkdir_p($topirank_dir); 63 } 64 65 $uploaded_file = wp_handle_upload($file, array('test_form' => false)); 66 67 if (isset($uploaded_file['file']) && ! isset($uploaded_file['error'])) { 68 $original_path = $uploaded_file['file']; 69 $zip_path = $topirank_dir . '/' . basename($original_path); 70 71 $wp_filesystem = topirank_get_filesystem(); 72 73 if ($wp_filesystem->move($original_path, $zip_path, true)) { 74 $extracted_path = $topirank_dir . '/' . basename($file['name'], '.zip'); 75 topirank_extract_and_create_posts($zip_path, $extracted_path, $replace, $selected_style); 76 77 if ($wp_filesystem->exists($zip_path)) { 78 $wp_filesystem->delete($zip_path); 79 } 80 } else { 81 echo '<div class="topirank_main_content_line">'; 82 echo '<div class="topirank_line_title">'; 83 esc_html_e('Could not move the uploaded file.', 'topirank-integration'); 84 echo '</div>'; 85 echo '</div>'; 86 } 87 } else { 88 echo '<div class="topirank_main_content_line">'; 89 echo '<div class="topirank_line_title">'; 90 if (isset($uploaded_file['error'])) { 91 echo esc_html($uploaded_file['error']); 92 } else { 93 esc_html_e('Upload failed. Please try again.', 'topirank-integration'); 94 } 95 echo '</div>'; 96 echo '</div>'; 97 } 88 } else { 89 echo '<div class="topirank_main_content_line">'; 90 echo '<div class="topirank_line_title">'; 91 if (isset($uploaded_file['error'])) { 92 echo esc_html($uploaded_file['error']); 98 93 } else { 99 esc_html_e('Invalid file upload.', 'topirank-integration');94 esc_html_e('Upload failed. Please try again.', 'topirank-integration'); 100 95 } 96 echo '</div>'; 97 echo '</div>'; 98 } 99 } else { 100 esc_html_e('Invalid file upload.', 'topirank-integration'); 101 101 } 102 } 102 103 } -
topirank-integration/trunk/includes/register-files.php
r3255204 r3268778 1 1 <?php 2 2 if (! defined('ABSPATH')) exit; 3 4 function is_valid_post() 5 { 6 global $post; 7 return is_object($post); 8 } 3 9 4 10 function topirank_enqueue_admin_assets($hook_suffix) … … 51 57 52 58 add_action('template_redirect', function () { 59 if (!is_valid_post()) { 60 return; 61 } 53 62 54 63 global $post; … … 76 85 function topirank_enqueue_archive_files() 77 86 { 87 if (!is_valid_post()) { 88 return; 89 } 90 78 91 global $post; 79 92 … … 117 130 if (is_dir($js_path)) { 118 131 $js_files = glob($js_path . '/*.js'); 119 $current_slug = sanitize_title($post->post_name);120 $clean_archive_name = preg_replace('/--\d+$/', '', $archive_name);121 122 132 foreach ($js_files as $js_file) { 123 124 $file_name = basename($js_file, '.js');125 $file_name = preg_replace('/-script$/', '', $file_name);126 127 if (strpos($file_name, '-page-') === false) {128 wp_enqueue_script(129 'topirank-archive-js-' . sanitize_title($file_name),130 $js_url . '/' . basename($js_file),131 [],132 time(),133 true134 );135 continue;136 }137 138 $file_name = preg_replace('/^' . preg_quote($clean_archive_name, '/') . '/', '', $file_name);139 $file_name = preg_replace('/^-page-/', '', $file_name);140 141 142 if (strpos($file_name, $current_slug) === false) {143 continue;144 }145 146 133 wp_enqueue_script( 147 'topirank-archive-js-' . sanitize_title( $file_name),134 'topirank-archive-js-' . sanitize_title(basename($js_file, '.js')), 148 135 $js_url . '/' . basename($js_file), 149 136 [], … … 152 139 ); 153 140 } 154 } 155 } 156 141 142 $page_js_path = $js_path . '/page-js'; 143 if (is_dir($page_js_path)) { 144 $page_js_files = glob($page_js_path . '/*.js'); 145 $data_id_title = get_post_meta($post->ID, 'data_id_title', true); 146 147 foreach ($page_js_files as $js_file) { 148 $file_name = basename($js_file, '.js'); 149 150 if ($file_name === $data_id_title) { 151 wp_enqueue_script( 152 'topirank-archive-page-js-' . sanitize_title($file_name), 153 $js_url . '/page-js/' . basename($js_file), 154 [], 155 time(), 156 true 157 ); 158 } 159 } 160 } 161 } 162 } 157 163 158 164 159 165 function topirank_admin_styles_for_special_template($hook) 160 166 { 167 if (!is_valid_post()) { 168 return; 169 } 170 161 171 global $post; 162 172 -
topirank-integration/trunk/includes/topirank-template.php
r3220350 r3268778 4 4 /* Template Name: Topirank Post Template */ 5 5 /* Template Post Type: post */ 6 if (is_user_logged_in()) { 7 show_admin_bar(false); 8 add_action('get_header', function () { 9 remove_action('wp_head', '_admin_bar_bump_cb'); 10 }); 11 } 6 12 get_header(); 7 13 $choose_styles = get_post_meta($post->ID, 'choose_styles', true); -
topirank-integration/trunk/includes/update-content-and-seo.php
r3249873 r3268778 18 18 if (preg_match('/<title>(.*?)<\/title>/is', $content, $title_match)) { 19 19 $title = wp_strip_all_tags($title_match[1]); 20 update_post_meta($post_id, '_yoast_wpseo_title', $title);21 20 } else { 22 21 $title = ''; … … 25 24 if (preg_match('/<meta\s+name=["\']description["\']\s+content=["\'](.*?)["\']/is', $content, $description_match)) { 26 25 $description = wp_strip_all_tags($description_match[1]); 27 update_post_meta($post_id, '_yoast_wpseo_metadesc', $description);28 26 } else { 29 27 $description = ''; … … 40 38 41 39 $xpath = new DOMXPath($dom); 40 41 $elements_with_data_id = $xpath->query('//*[@data-id-title]'); 42 if ($elements_with_data_id->length > 0) { 43 $element = $elements_with_data_id->item(0); 44 if ($element instanceof DOMElement) { 45 $data_id_title = $element->getAttribute('data-id-title'); 46 update_post_meta($post_id, 'data_id_title', $data_id_title); 47 } 48 } 42 49 43 50 $fonts_script = $dom->getElementById('fonts-with-script-integrate'); … … 152 159 $image_srcs = $image_matches[1]; 153 160 $upload_dir = wp_upload_dir(); 161 $special_attachment_id = null; 162 163 $matched_src = null; 164 if (preg_match('/<img[^>]*data-image-position=["\']main["\'][^>]*src=["\']([^"\']+)["\']/i', $content, $special_img_match)) { 165 $matched_src = $special_img_match[1]; 166 } 154 167 155 168 foreach ($image_srcs as $image_src) { … … 181 194 $new_url = wp_get_attachment_url($attachment_id); 182 195 $content = str_replace($image_src, $new_url, $content); 183 } 184 } 196 197 if ($image_src === $matched_src) { 198 $special_attachment_id = $attachment_id; 199 } 200 } 201 202 if ($special_attachment_id) { 203 set_post_thumbnail($post_id, $special_attachment_id); 204 $img_url = wp_get_attachment_url($special_attachment_id); 205 206 if (class_exists('WPSEO_Meta')) { 207 WPSEO_Meta::set_value('opengraph-image', $img_url, $post_id); 208 WPSEO_Meta::set_value('twitter-image', $img_url, $post_id); 209 } 210 } 211 } 212 185 213 186 214 wp_update_post([ … … 190 218 ]); 191 219 192 $post_title = get_the_title($post_id);193 $post_title_slug = sanitize_title($post_title);194 195 $thumbnail_query = new WP_Query([196 'title' => $post_title_slug,197 'post_type' => 'attachment',198 'post_status' => 'inherit',199 'fields' => 'ids',200 'posts_per_page' => 1,201 ]);202 $thumbnail_id = !empty($thumbnail_query->posts) ? $thumbnail_query->posts[0] : null;203 220 wp_reset_postdata(); 204 221 205 222 if (class_exists('WPSEO_Meta')) { 206 if ($thumbnail_id) {207 set_post_thumbnail($post_id, $thumbnail_id);208 $thumbnail_url = wp_get_attachment_url($thumbnail_id);209 WPSEO_Meta::set_value('opengraph-image', $thumbnail_url, $post_id);210 }211 223 212 224 if ($title) { 213 225 WPSEO_Meta::set_value('opengraph-title', $title, $post_id); 226 WPSEO_Meta::set_value('twitter-title', $title, $post_id); 227 update_post_meta($post_id, '_yoast_wpseo_title', $title); 214 228 } 215 229 216 230 if ($description) { 217 231 WPSEO_Meta::set_value('opengraph-description', $description, $post_id); 232 WPSEO_Meta::set_value('twitter-description', $description, $post_id); 233 update_post_meta($post_id, '_yoast_wpseo_metadesc', $description); 218 234 } 219 235 } -
topirank-integration/trunk/readme.txt
r3266247 r3268778 4 4 Requires at least: 6.0 5 5 Tested up to: 6.7.2 6 Stable tag: 1.1. 36 Stable tag: 1.1.4 7 7 Requires PHP: 7.3 8 8 License: GPLv2 or later … … 57 57 58 58 == Changelog == 59 60 = 1.1.4 = 61 * Fixed an issue with the progress bar display. 62 * Fixed SEO image rendering. 63 * Fixed JS file loading. 64 * Improved support for two page types. 65 * Improved rendering of new widgets on pages. 59 66 60 67 = 1.1.3 = -
topirank-integration/trunk/topirank-integration.php
r3266247 r3268778 3 3 Plugin Name: Topirank Integration 4 4 Description: Plugin for parsing pages 5 Version: 1.1. 35 Version: 1.1.4 6 6 Author: Topirank 7 7 License: GPLv2 or later
Note: See TracChangeset
for help on using the changeset viewer.