Changeset 3236026
- Timestamp:
- 02/06/2025 12:58:13 PM (14 months ago)
- Location:
- topirank-integration
- Files:
-
- 32 added
- 7 edited
-
tags/1.0.5 (added)
-
tags/1.0.5/admin (added)
-
tags/1.0.5/admin/admin-page.php (added)
-
tags/1.0.5/admin/menu.php (added)
-
tags/1.0.5/assets (added)
-
tags/1.0.5/assets/css (added)
-
tags/1.0.5/assets/css/topirank-admin-style.css (added)
-
tags/1.0.5/assets/css/topirank-editor-style.css (added)
-
tags/1.0.5/assets/css/topirank-normalize.css (added)
-
tags/1.0.5/assets/css/topirank-post-admin-style.css (added)
-
tags/1.0.5/assets/js (added)
-
tags/1.0.5/assets/js/topirank-admin-scripts.js (added)
-
tags/1.0.5/assets/js/topirank-normalize.js (added)
-
tags/1.0.5/includes (added)
-
tags/1.0.5/includes/api-integration.php (added)
-
tags/1.0.5/includes/create-template.php (added)
-
tags/1.0.5/includes/extract-and-create.php (added)
-
tags/1.0.5/includes/file-upload.php (added)
-
tags/1.0.5/includes/helpers.php (added)
-
tags/1.0.5/includes/init.php (added)
-
tags/1.0.5/includes/process-folders.php (added)
-
tags/1.0.5/includes/register-files.php (added)
-
tags/1.0.5/includes/resource-cleaner.php (added)
-
tags/1.0.5/includes/topirank-template.php (added)
-
tags/1.0.5/includes/update-content-and-seo.php (added)
-
tags/1.0.5/includes/update-functionality.php (added)
-
tags/1.0.5/languages (added)
-
tags/1.0.5/languages/topirank-integration-fr_FR.mo (added)
-
tags/1.0.5/languages/topirank-integration-fr_FR.po (added)
-
tags/1.0.5/languages/topirank-integration.pot (added)
-
tags/1.0.5/readme.txt (added)
-
tags/1.0.5/topirank-integration.php (added)
-
trunk/includes/create-template.php (modified) (5 diffs)
-
trunk/includes/helpers.php (modified) (3 diffs)
-
trunk/includes/register-files.php (modified) (6 diffs)
-
trunk/includes/update-content-and-seo.php (modified) (3 diffs)
-
trunk/includes/update-functionality.php (modified) (1 diff)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/topirank-integration.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
topirank-integration/trunk/includes/create-template.php
r3220350 r3236026 1 1 <?php 2 2 3 if (! defined('ABSPATH')) exit;3 if (!defined('ABSPATH')) exit; 4 4 5 add_filter('theme_p ost_templates', 'topirank_add_custom_post_template');6 function topirank_add_custom_p ost_template($templates)5 add_filter('theme_page_templates', 'topirank_add_custom_page_template'); 6 function topirank_add_custom_page_template($templates) 7 7 { 8 $templates['includes/topirank-template.php'] = 'Topirank Custom Template';8 $templates['includes/topirank-template.php'] = 'Topirank Custom Page Template'; 9 9 return $templates; 10 10 } 11 11 12 13 add_filter('template_include', 'topirank_load_custom_template'); 14 15 function topirank_load_custom_template($template) 12 add_filter('template_include', 'topirank_load_custom_page_template'); 13 function topirank_load_custom_page_template($template) 16 14 { 17 15 global $post; … … 27 25 function topirank_disable_wpautop_on_custom_template($content) 28 26 { 29 if (is_ single() && get_post_meta(get_the_ID(), '_wp_page_template', true) === 'includes/topirank-template.php') {27 if (is_page() && get_post_meta(get_the_ID(), '_wp_page_template', true) === 'includes/topirank-template.php') { 30 28 remove_filter('the_content', 'wpautop'); 31 29 } … … 34 32 add_filter('the_content', 'topirank_disable_wpautop_on_custom_template', 9); 35 33 34 add_filter('use_block_editor_for_post', function ($use_block_editor, $post) { 35 if ($post && $post->post_type === 'page') { 36 $template = get_post_meta($post->ID, '_wp_page_template', true); 37 if ($template === 'includes/topirank-template.php') { 38 return false; 39 } 40 } 41 return $use_block_editor; 42 }, 10, 2); 36 43 37 44 add_action('load-post.php', function () { … … 52 59 } 53 60 54 if (!current_user_can('edit_p ost', $post_id)) {55 wp_die(('You are not allowed to edit this p ost.'));61 if (!current_user_can('edit_page', $post_id)) { 62 wp_die(('You are not allowed to edit this page.')); 56 63 } 57 64 … … 76 83 }); 77 84 }); 78 79 80 81 82 add_filter('use_block_editor_for_post', function ($use_block_editor, $post) {83 if ($post && $post->post_type === 'post') {84 $template = get_post_meta($post->ID, '_wp_page_template', true);85 if ($template === 'includes/topirank-template.php') {86 return false;87 }88 }89 return $use_block_editor;90 }, 10, 2); -
topirank-integration/trunk/includes/helpers.php
r3234611 r3236026 18 18 continue; 19 19 } 20 21 $article_title = preg_replace('/\s{2,}/', ' ', $directory_name);22 20 $file_path = $file->getPathname(); 23 21 $content = $wp_filesystem->get_contents($file_path); 22 $article_title = topirank_extract_title_from_html($file_path); 23 24 if (empty($article_title)) { 25 continue; 26 } 27 24 28 $unique_title = topirank_generate_unique_title($article_title); 25 29 26 30 $args = [ 27 'post_type' => 'p ost',31 'post_type' => 'page', 28 32 'title' => $article_title, 29 33 'post_status' => 'publish', … … 60 64 'post_content' => $content, 61 65 'post_status' => 'publish', 62 'post_type' => 'p ost',66 'post_type' => 'page', 63 67 'post_name' => sanitize_title($article_title), 64 68 ]); … … 184 188 } 185 189 } 190 191 function topirank_extract_title_from_html($file_path) 192 { 193 $content = file_get_contents($file_path); 194 if (!$content) { 195 return null; 196 } 197 198 libxml_use_internal_errors(true); 199 $dom = new DOMDocument(); 200 @$dom->loadHTML($content); 201 libxml_clear_errors(); 202 203 $title_elements = $dom->getElementsByTagName('title'); 204 205 return ($title_elements->length > 0) ? trim($title_elements->item(0)->textContent) : null; 206 } -
topirank-integration/trunk/includes/register-files.php
r3220350 r3236026 51 51 52 52 add_action('template_redirect', function () { 53 if (is_single()) { 54 global $post; 55 56 $archive_name = get_post_meta($post->ID, '_topirank_archive_name', true); 57 if (empty($archive_name)) { 58 return; 59 } 60 wp_enqueue_style( 61 'topirank-normalize', 62 plugins_url('/assets/css/topirank-normalize.css', dirname(__FILE__)), 63 [], 64 time() 65 ); 66 wp_enqueue_script( 67 'set-height-js', 68 plugins_url('/assets/js/topirank-normalize.js', dirname(__FILE__)), 69 [], 70 time(), 71 true 72 ); 73 } 53 54 global $post; 55 56 $archive_name = get_post_meta($post->ID, '_topirank_archive_name', true); 57 if (empty($archive_name)) { 58 return; 59 } 60 wp_enqueue_style( 61 'topirank-normalize', 62 plugins_url('/assets/css/topirank-normalize.css', dirname(__FILE__)), 63 [], 64 time() 65 ); 66 wp_enqueue_script( 67 'set-height-js', 68 plugins_url('/assets/js/topirank-normalize.js', dirname(__FILE__)), 69 [], 70 time(), 71 true 72 ); 74 73 }); 75 74 … … 77 76 function topirank_enqueue_archive_files() 78 77 { 79 if (is_single()) { 80 global $post; 81 82 $archive_name = get_post_meta($post->ID, '_topirank_archive_name', true); 83 if (empty($archive_name)) { 84 return; 85 } 86 87 $upload_dir = wp_upload_dir(); 88 $base_upload_path = $upload_dir['basedir']; 89 $base_upload_url = $upload_dir['baseurl']; 90 91 $css_path = $base_upload_path . '/topirank/css/' . $archive_name; 92 $js_path = $base_upload_path . '/topirank/js/' . $archive_name; 93 94 $css_url = $base_upload_url . '/topirank/css/' . $archive_name; 95 $js_url = $base_upload_url . '/topirank/js/' . $archive_name; 96 97 $post_slugs = get_posts([ 98 'fields' => 'post_name', 99 'posts_per_page' => -1, 100 'post_type' => 'post', 101 ]); 102 103 $post_slugs = wp_list_pluck($post_slugs, 'post_name'); 104 105 if (is_dir($css_path)) { 106 $css_files = glob($css_path . '/*.css'); 107 foreach ($css_files as $css_file) { 108 $file_name = basename($css_file); 109 110 wp_enqueue_style( 111 'topirank-archive-css-' . sanitize_title($file_name), 112 $css_url . '/' . $file_name, 113 [], 114 time() 115 ); 116 } 117 } 118 119 if (is_dir($js_path)) { 120 $js_files = glob($js_path . '/*.js'); 121 $matched_files = []; 122 123 foreach ($js_files as $js_file) { 124 $file_name = basename($js_file, '.js'); 125 $file_name = str_replace('-script', '', $file_name); 126 127 if (strpos($file_name, '-page-') !== false) { 128 $file_slug = explode('-page-', $file_name)[1]; 129 130 if (in_array($file_slug, $post_slugs, true)) { 131 $matched_files[$file_slug] = $js_file; 132 } else { 133 wp_enqueue_script( 134 'topirank-archive-js-' . sanitize_title($file_name), 135 $js_url . '/' . basename($js_file), 136 [], 137 time(), 138 true 139 ); 140 } 78 global $post; 79 80 $archive_name = get_post_meta($post->ID, '_topirank_archive_name', true); 81 if (empty($archive_name)) { 82 return; 83 } 84 85 $upload_dir = wp_upload_dir(); 86 $base_upload_path = $upload_dir['basedir']; 87 $base_upload_url = $upload_dir['baseurl']; 88 89 $css_path = $base_upload_path . '/topirank/css/' . $archive_name; 90 $js_path = $base_upload_path . '/topirank/js/' . $archive_name; 91 92 $css_url = $base_upload_url . '/topirank/css/' . $archive_name; 93 $js_url = $base_upload_url . '/topirank/js/' . $archive_name; 94 95 $post_slugs = get_posts([ 96 'fields' => 'post_name', 97 'posts_per_page' => -1, 98 'post_type' => 'post', 99 ]); 100 101 $post_slugs = wp_list_pluck($post_slugs, 'post_name'); 102 103 if (is_dir($css_path)) { 104 $css_files = glob($css_path . '/*.css'); 105 foreach ($css_files as $css_file) { 106 $file_name = basename($css_file); 107 108 wp_enqueue_style( 109 'topirank-archive-css-' . sanitize_title($file_name), 110 $css_url . '/' . $file_name, 111 [], 112 time() 113 ); 114 } 115 } 116 117 if (is_dir($js_path)) { 118 $js_files = glob($js_path . '/*.js'); 119 $matched_files = []; 120 121 foreach ($js_files as $js_file) { 122 $file_name = basename($js_file, '.js'); 123 $file_name = str_replace('-script', '', $file_name); 124 125 if (strpos($file_name, '-page-') !== false) { 126 $file_slug = explode('-page-', $file_name)[1]; 127 128 if (in_array($file_slug, $post_slugs, true)) { 129 $matched_files[$file_slug] = $js_file; 141 130 } else { 142 131 wp_enqueue_script( … … 148 137 ); 149 138 } 150 } 151 152 $current_post_slug = $post->post_name; 153 if (isset($matched_files[$current_post_slug])) { 139 } else { 154 140 wp_enqueue_script( 155 'topirank-archive-js-' . sanitize_title($ current_post_slug),156 $js_url . '/' . basename($ matched_files[$current_post_slug]),141 'topirank-archive-js-' . sanitize_title($file_name), 142 $js_url . '/' . basename($js_file), 157 143 [], 158 144 time(), … … 161 147 } 162 148 } 149 150 $current_post_slug = $post->post_name; 151 if (isset($matched_files[$current_post_slug])) { 152 wp_enqueue_script( 153 'topirank-archive-js-' . sanitize_title($current_post_slug), 154 $js_url . '/' . basename($matched_files[$current_post_slug]), 155 [], 156 time(), 157 true 158 ); 159 } 163 160 } 164 161 } … … 168 165 global $post; 169 166 170 if ('post.php' === $hook && isset($post)) { 171 $current_template = get_post_meta($post->ID, '_wp_page_template', true); 172 if ($current_template === 'includes/topirank-template.php') { 173 wp_enqueue_style( 174 'my_special_template_admin_css', 175 plugins_url('/assets/css/topirank-post-admin-style.css', dirname(__FILE__)), 176 [], 177 time(), 178 'all' 179 ); 180 } 167 $current_template = get_post_meta($post->ID, '_wp_page_template', true); 168 if ($current_template === 'includes/topirank-template.php') { 169 wp_enqueue_style( 170 'my_special_template_admin_css', 171 plugins_url('/assets/css/topirank-post-admin-style.css', dirname(__FILE__)), 172 [], 173 time(), 174 'all' 175 ); 181 176 } 182 177 } … … 202 197 } 203 198 199 if (get_post_type($post_id) !== 'page') { 200 return $mce_css; 201 } 202 204 203 $template = get_post_meta($post_id, '_wp_page_template', true); 205 204 -
topirank-integration/trunk/includes/update-content-and-seo.php
r3234611 r3236026 68 68 $href = $link->getAttribute('href'); 69 69 if (preg_match('/^(?:\.\.\/)+(.+)\/index\.html$/iu', $href, $matches)) { 70 $encoded_title = $matches[1]; 71 $decoded_title = urldecode($encoded_title); 72 $formatted_title = preg_replace('/\s+/', ' ', str_replace(['-', '_'], ' ', $decoded_title)); 73 $formatted_title = trim($formatted_title); 74 75 if (!empty($formatted_title)) { 76 $link_titles[] = $formatted_title; 70 $encoded_url = $matches[1]; 71 $decoded_url = urldecode($encoded_url); 72 $slug = basename($decoded_url); 73 74 if (!empty($slug)) { 75 $link_slugs[] = $slug; 77 76 $link_elements[] = $link; 78 77 } … … 80 79 } 81 80 82 $unique_ titles = array_unique($link_titles);83 $ title_to_post = [];84 85 if (!empty($unique_ titles)) {86 foreach ($unique_ titles as $unique_title) {81 $unique_slugs = array_unique($link_slugs); 82 $slug_to_post = []; 83 84 if (!empty($unique_slugs)) { 85 foreach ($unique_slugs as $unique_slug) { 87 86 $query = new WP_Query([ 88 ' title' => $unique_title,89 'post_type' => 'post',87 'name' => $unique_slug, 88 'post_type' => 'page', 90 89 'post_status' => 'publish', 91 'fields' => 'ids',90 'fields' => 'ids', 92 91 'posts_per_page' => 1, 93 92 ]); 94 93 $found_post_id = !empty($query->posts) ? $query->posts[0] : null; 95 94 if ($found_post_id) { 96 $ title_to_post[$unique_title] = get_permalink($found_post_id);95 $slug_to_post[$unique_slug] = get_permalink($found_post_id); 97 96 } 98 97 wp_reset_postdata(); … … 101 100 102 101 foreach ($link_elements as $index => $link) { 103 $formatted_ title = $link_titles[$index];104 if (isset($ title_to_post[$formatted_title])) {105 $link->setAttribute('href', $ title_to_post[$formatted_title]);102 $formatted_slug = $link_slugs[$index]; 103 if (isset($slug_to_post[$formatted_slug])) { 104 $link->setAttribute('href', $slug_to_post[$formatted_slug]); 106 105 } 107 106 } -
topirank-integration/trunk/includes/update-functionality.php
r3220350 r3236026 56 56 { 57 57 $args = [ 58 'post_type' => 'p ost',58 'post_type' => 'page', 59 59 'title' => $title, 60 60 'post_status' => 'any', -
topirank-integration/trunk/readme.txt
r3234611 r3236026 4 4 Requires at least: 6.0 5 5 Tested up to: 6.7.1 6 Stable tag: 1.0. 46 Stable tag: 1.0.5 7 7 Requires PHP: 7.3 8 8 License: GPLv2 or later … … 58 58 == Changelog == 59 59 60 = 1.0.5 = 61 * Minor admin panel style fixes. 62 * Minor post style fixes. 63 * Improved template handling. 64 60 65 = 1.0.4 = 61 66 * Improved large file upload functionality via the application. -
topirank-integration/trunk/topirank-integration.php
r3234611 r3236026 3 3 Plugin Name: Topirank Integration 4 4 Description: Plugin for parsing pages 5 Version: 1.0. 45 Version: 1.0.5 6 6 Author: Topirank 7 7 License: GPLv2 or later
Note: See TracChangeset
for help on using the changeset viewer.