Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions serendipity_event_freetag/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
4.1: Match related entries by amount of shared tags

4.0:
* Avoid more warnings under PHP 8.x
* Drop outdated option to create a technorati link
Expand Down
10 changes: 6 additions & 4 deletions serendipity_event_freetag/serendipity_event_freetag.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function introspect(&$propbag)
'smarty' => '2.6.7',
'php' => '7.0'
));
$propbag->add('version', '4.0');
$propbag->add('version', '4.1');
$propbag->add('event_hooks', array(
'frontend_fetchentries' => true,
'frontend_fetchentry' => true,
Expand Down Expand Up @@ -415,17 +415,19 @@ function getRelatedEntries($tags, $postID) {
$tags[$idx] = serendipity_db_escape_string($tag);
}

$q = "SELECT DISTINCT e1.entryid,
$q = "SELECT e1.entryid,
e2.title,
e2.timestamp
e2.timestamp,
COUNT(e2.id) AS shared_tags
FROM {$serendipity['dbPrefix']}entrytags AS e1
LEFT JOIN {$serendipity['dbPrefix']}entries AS e2
ON e1.entryid = e2.id
WHERE e1.tag IN ('" . implode("', '", $tags) . "')
AND e1.entryid != " . (int)$postID . "
AND e2.isdraft = 'false'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if 'false' (as string) works everywhere as expected. The column seems to be stored as bool, so maybe query for bool or e2.isdraft IN ('false', false, 0)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer not to change it, as I just copied it from the old SQL and we are not aware of a problem with this. The = 'false' comparison surprisingly works in SQLite, MariaDB and PostgreSQL, I tested it now with a test draft entry :) Changing it might introduce an issue somewhere - the approach with the IN seems like it should cover the possible difference with e.g. sqlite if it stored a string in there, but NULL might become a problem.

" . (!serendipity_db_bool($serendipity['showFutureEntries']) ? " AND e2.timestamp <= " . time() : '') . "
ORDER BY e2.timestamp DESC
GROUP BY e1.entryid, e2.title, e2.timestamp
ORDER BY shared_tags DESC, e2.timestamp DESC
LIMIT " . $this->get_config('show_related_count', 10);

$result = serendipity_db_query($q, false, 'assoc', false, 'entryid', 'title');
Expand Down