From f2c67330b4e92f14c820845175618a497e2b86de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20Mu=C3=B1oz?= Date: Tue, 16 Jun 2020 17:07:37 -0500 Subject: [PATCH] New option to include every thread page into the Sitemap --- XF/Sitemap/Thread.php | 38 +++++++++++++++++++ ...map-Thread_SEOUtils-XF-Sitemap-Thread.json | 6 +++ _output/options/SEOUtilsIncludeAllPages.json | 12 ++++++ ...on => SEOUtilsThreadStartDatePerPage.json} | 0 _output/phrases/SEOUtils_enter_thread_id.txt | 1 + .../option.SEOUtilsIncludeAllPages.txt | 1 + ...option.SEOUtilsThreadStartDatePerPage.txt} | 0 ...option_explain.SEOUtilsIncludeAllPages.txt | 3 ++ ...xplain.SEOUtilsThreadStartDatePerPage.txt} | 0 .../public/SEOUtils_thread_view.json | 2 +- addon.json | 8 ++-- 11 files changed, 66 insertions(+), 5 deletions(-) create mode 100644 XF/Sitemap/Thread.php create mode 100644 _output/class_extensions/XF-Sitemap-Thread_SEOUtils-XF-Sitemap-Thread.json create mode 100644 _output/options/SEOUtilsIncludeAllPages.json rename _output/options/{SEOUtils_thread_start_date_per_page.json => SEOUtilsThreadStartDatePerPage.json} (100%) create mode 100644 _output/phrases/SEOUtils_enter_thread_id.txt create mode 100644 _output/phrases/option.SEOUtilsIncludeAllPages.txt rename _output/phrases/{option.SEOUtils_thread_start_date_per_page.txt => option.SEOUtilsThreadStartDatePerPage.txt} (100%) create mode 100644 _output/phrases/option_explain.SEOUtilsIncludeAllPages.txt rename _output/phrases/{option_explain.SEOUtils_thread_start_date_per_page.txt => option_explain.SEOUtilsThreadStartDatePerPage.txt} (100%) diff --git a/XF/Sitemap/Thread.php b/XF/Sitemap/Thread.php new file mode 100644 index 0000000..e6ff006 --- /dev/null +++ b/XF/Sitemap/Thread.php @@ -0,0 +1,38 @@ +app->options()->SEOUtilsIncludeAllPages) { + return $result; + } + + $perPage = max(1, intval($this->app->options()->discussionsPerPage)); + $total = max(0, intval($record->reply_count + 1)); + $totalPages = ceil($total / $perPage); + + if ($totalPages <= 1) { + return $result; + } + + $resultWithPages = [$result]; + + // We create an \XF\Sitemap\Entry for each page of a thread. + for($page = 2; $page <= $totalPages; $page++) + { + $url = $this->app->router('public')->buildLink('canonical:threads', $record, ['page' => $page]); + $resultWithPages[] = \XF\Sitemap\Entry::create($url, [ + 'lastmod' => $record->last_post_date + ]); + } + + return $resultWithPages; + } +} \ No newline at end of file diff --git a/_output/class_extensions/XF-Sitemap-Thread_SEOUtils-XF-Sitemap-Thread.json b/_output/class_extensions/XF-Sitemap-Thread_SEOUtils-XF-Sitemap-Thread.json new file mode 100644 index 0000000..1516deb --- /dev/null +++ b/_output/class_extensions/XF-Sitemap-Thread_SEOUtils-XF-Sitemap-Thread.json @@ -0,0 +1,6 @@ +{ + "from_class": "XF\\Sitemap\\Thread", + "to_class": "SEOUtils\\XF\\Sitemap\\Thread", + "execute_order": 10, + "active": true +} \ No newline at end of file diff --git a/_output/options/SEOUtilsIncludeAllPages.json b/_output/options/SEOUtilsIncludeAllPages.json new file mode 100644 index 0000000..02590f6 --- /dev/null +++ b/_output/options/SEOUtilsIncludeAllPages.json @@ -0,0 +1,12 @@ +{ + "edit_format": "onoff", + "edit_format_params": "", + "data_type": "boolean", + "sub_options": [], + "validation_class": "", + "validation_method": "", + "default_value": "0", + "relations": { + "SEOUtils": 2 + } +} \ No newline at end of file diff --git a/_output/options/SEOUtils_thread_start_date_per_page.json b/_output/options/SEOUtilsThreadStartDatePerPage.json similarity index 100% rename from _output/options/SEOUtils_thread_start_date_per_page.json rename to _output/options/SEOUtilsThreadStartDatePerPage.json diff --git a/_output/phrases/SEOUtils_enter_thread_id.txt b/_output/phrases/SEOUtils_enter_thread_id.txt new file mode 100644 index 0000000..29c80fc --- /dev/null +++ b/_output/phrases/SEOUtils_enter_thread_id.txt @@ -0,0 +1 @@ +Enter a Thread ID \ No newline at end of file diff --git a/_output/phrases/option.SEOUtilsIncludeAllPages.txt b/_output/phrases/option.SEOUtilsIncludeAllPages.txt new file mode 100644 index 0000000..5d3b1be --- /dev/null +++ b/_output/phrases/option.SEOUtilsIncludeAllPages.txt @@ -0,0 +1 @@ +Include all pages in the Sitemap \ No newline at end of file diff --git a/_output/phrases/option.SEOUtils_thread_start_date_per_page.txt b/_output/phrases/option.SEOUtilsThreadStartDatePerPage.txt similarity index 100% rename from _output/phrases/option.SEOUtils_thread_start_date_per_page.txt rename to _output/phrases/option.SEOUtilsThreadStartDatePerPage.txt diff --git a/_output/phrases/option_explain.SEOUtilsIncludeAllPages.txt b/_output/phrases/option_explain.SEOUtilsIncludeAllPages.txt new file mode 100644 index 0000000..051f162 --- /dev/null +++ b/_output/phrases/option_explain.SEOUtilsIncludeAllPages.txt @@ -0,0 +1,3 @@ +By default XenForo only includes the first page of each thread in the sitemap. + +

When you turn on this option, the sitemap will include all the pages of each thread.

\ No newline at end of file diff --git a/_output/phrases/option_explain.SEOUtils_thread_start_date_per_page.txt b/_output/phrases/option_explain.SEOUtilsThreadStartDatePerPage.txt similarity index 100% rename from _output/phrases/option_explain.SEOUtils_thread_start_date_per_page.txt rename to _output/phrases/option_explain.SEOUtilsThreadStartDatePerPage.txt diff --git a/_output/template_modifications/public/SEOUtils_thread_view.json b/_output/template_modifications/public/SEOUtils_thread_view.json index 930b4e2..7a40ed5 100644 --- a/_output/template_modifications/public/SEOUtils_thread_view.json +++ b/_output/template_modifications/public/SEOUtils_thread_view.json @@ -5,5 +5,5 @@ "enabled": true, "action": "str_replace", "find": "", - "replace": "\n\t\n\n\t$0\n" + "replace": "\n\t\n\n\t$0\n" } \ No newline at end of file diff --git a/addon.json b/addon.json index e86ab82..695baf6 100755 --- a/addon.json +++ b/addon.json @@ -1,14 +1,14 @@ { "legacy_addon_id": "", "title": "SEO Utilities", - "description": "", + "description": "Various options to improve the SEO of your forum", "version_id": 1000070, "version_string": "1.0.0", - "dev": "", - "dev_url": "", + "dev": "JulianD", + "dev_url": "https://xenforo.com/community/members/juliand.33/", "faq_url": "", "support_url": "", "extra_urls": [], "require": [], - "icon": "" + "icon": "fa-chart-line" } \ No newline at end of file