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'
" . (!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