Skip to content

Commit

Permalink
Fix article field-value exclusion setting
Browse files Browse the repository at this point in the history
The "Exclude articles based on fields" setting
was broken in rah_sitemap 3.0.0.

Fixes #11
  • Loading branch information
gocom committed Aug 30, 2023
1 parent 4a13a4d commit c7ecf2a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 9 deletions.
4 changes: 4 additions & 0 deletions README.textile
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ As rah_sitemap integrates well with Textpattern's core, it uses the same URL fun

h2. Changelog

h3. Version 4.0.2 - 2023/08/30

* Fixed: "Exclude articles based on fields" setting, caused by regression in version 3.0.0. Articles can once again be excluded from the feed using field-value filters.

h3. Version 4.0.1 - 2023/02/18

* Fixed: issues with lastmod date generation caused by Textpattern 4.8.8 core issues. Date format string would be passed down to the wrong date function on certain host system, based on it's supported features. Mitigated the issue by using PHP's @date@ function directly instead of Textpattern's @safe_strftime@.
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "rah_sitemap",
"description": "XML sitemap",
"version": "4.0.1",
"version": "4.0.2",
"type": 5,
"author": "Jukka Svahn",
"author_uri": "https://github.com/gocom/rah_sitemap",
Expand Down
49 changes: 41 additions & 8 deletions src/Rah/Sitemap/Record/ArticleRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,26 @@ public function getUrls(int $page): array
*/
private function getWhereStatement(): string
{
$articleFields = [];
$articleFields = $this->getArticleFields();
$sql = ['Status >= 4'];

foreach (do_list(get_pref('rah_sitemap_exclude_fields')) as $field) {
if ($field) {
$f = explode(':', $field);
$n = strtolower(trim($f[0]));
foreach (do_list(get_pref('rah_sitemap_exclude_fields')) as $pair) {
if ($pair) {
$parts = explode(':', $pair, 2);

if (isset($articleFields[$n])) {
$value = doSlash(trim(implode(':', array_slice($f, 1))));
$sql[] = $articleFields[$n]." NOT LIKE '".$value."'";
if (count($parts) === 2) {
$name = strtolower(trim($parts[0]));
$column = $articleFields[$name] ?? null;

if ($column) {
$value = doSlash(trim($parts[1]));

$sql[] = sprintf(
"%s NOT LIKE '%s'",
$column,
$value
);
}
}
}
}
Expand All @@ -117,4 +126,28 @@ private function getWhereStatement(): string

return implode(' and ', $sql);
}

/**
* Gets an array of article field names that can be used for filtering.
*
* Key is lowercase column name, value is database column name in its
* original casing.
*
* @return array<string, string>
*/
private function getArticleFields(): array
{
$columns = (array) @getThings('describe '.safe_pfx('textpattern'));
$fields = [];

foreach ($columns as $name) {
$fields[strtolower($name)] = $name;
}

foreach (getCustomFields() as $id => $name) {
$fields[$name] = 'custom_'.intval($id);
}

return $fields;
}
}

0 comments on commit c7ecf2a

Please sign in to comment.