Skip to content

Commit

Permalink
New option to include every thread page into the Sitemap
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianD committed Jun 16, 2020
1 parent 4563db3 commit f2c6733
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 5 deletions.
38 changes: 38 additions & 0 deletions XF/Sitemap/Thread.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace SEOUtils\XF\Sitemap;

class Thread extends XFCP_Thread
{
public function getEntry($record)
{
/** @var \XF\Entity\Thread $record */

$result = parent::getEntry($record);

if (is_array($result) || !$this->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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"from_class": "XF\\Sitemap\\Thread",
"to_class": "SEOUtils\\XF\\Sitemap\\Thread",
"execute_order": 10,
"active": true
}
12 changes: 12 additions & 0 deletions _output/options/SEOUtilsIncludeAllPages.json
Original file line number Diff line number Diff line change
@@ -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
}
}
1 change: 1 addition & 0 deletions _output/phrases/SEOUtils_enter_thread_id.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Enter a Thread ID
1 change: 1 addition & 0 deletions _output/phrases/option.SEOUtilsIncludeAllPages.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Include all pages in the Sitemap
3 changes: 3 additions & 0 deletions _output/phrases/option_explain.SEOUtilsIncludeAllPages.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
By default XenForo only includes the first page of each thread in the sitemap.

<p>When you turn on this option, the sitemap will include all the pages of each thread.</p>
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"enabled": true,
"action": "str_replace",
"find": "<a href=\"{{ link('threads', $thread) }}\" class=\"u-concealed\"><xf:date time=\"{$thread.post_date}\" /></a>",
"replace": "<xf:if is=\"$xf.options.SEOUtils_thread_start_date_per_page.enabled && \n\t($xf.options.SEOUtils_thread_start_date_per_page.thread_ids is empty ||\n\t\t($xf.options.SEOUtils_thread_start_date_per_page.thread_ids is not empty && $xf.options.SEOUtils_thread_start_date_per_page.thread_ids == $thread.thread_id)\n\t)\">\n\t<a href=\"{{ link('threads', $thread, {'page': $page}) }}\" class=\"u-concealed\"><xf:date time=\"{$firstPost.post_date}\" /></a>\n<xf:else />\n\t$0\n</xf:if>"
"replace": "<xf:if is=\"$xf.options.SEOUtilsThreadStartDatePerPage.enabled && \n\t($xf.options.SEOUtilsThreadStartDatePerPage.thread_ids is empty ||\n\t\t($xf.options.SEOUtilsThreadStartDatePerPage.thread_ids is not empty && $xf.options.SEOUtilsThreadStartDatePerPage.thread_ids == $thread.thread_id)\n\t)\">\n\t<a href=\"{{ link('threads', $thread, {'page': $page}) }}\" class=\"u-concealed\"><xf:date time=\"{$firstPost.post_date}\" /></a>\n<xf:else />\n\t$0\n</xf:if>"
}
8 changes: 4 additions & 4 deletions addon.json
Original file line number Diff line number Diff line change
@@ -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"
}

0 comments on commit f2c6733

Please sign in to comment.