diff --git a/data/config.ini b/data/config.ini
index d17b9f29..ec8b4010 100644
--- a/data/config.ini
+++ b/data/config.ini
@@ -32,6 +32,7 @@ usersPerPage=8
postsPerPage=20
logsPerPage=250
tagsPerPage=100
+tagsRelated=15
thumbWidth=150
thumbHeight=150
thumbStyle=outside
diff --git a/public_html/media/js/core.js b/public_html/media/js/core.js
index 7390755a..ef031183 100644
--- a/public_html/media/js/core.js
+++ b/public_html/media/js/core.js
@@ -276,7 +276,8 @@ function attachTagIt(target)
onTagClicked: function(e, ui)
{
var targetTagit = ui.tag.parents('.tagit');
- options = { tag: ui.tagLabel };
+ var context = target.tagit('assignedTags');
+ options = { context: context, tag: ui.tagLabel };
if (targetTagit.siblings('.related-tags:eq(0)').data('for') == options.tag)
{
targetTagit.siblings('.related-tags').slideUp(function()
@@ -289,7 +290,7 @@ function attachTagIt(target)
$.getJSON('/tags-related?json', options, function(data)
{
var list = $('
');
- $.each(data.tags.slice(0, 10), function(i, tag)
+ $.each(data.tags, function(i, tag)
{
var link = $('');
link.attr('href', '/posts/' + tag.name + '/');
diff --git a/src/Controllers/TagController.php b/src/Controllers/TagController.php
index 8e9f4895..bf302c61 100644
--- a/src/Controllers/TagController.php
+++ b/src/Controllers/TagController.php
@@ -73,9 +73,11 @@ class TagController
{
PrivilegesHelper::confirmWithException(Privilege::ListTags);
+ $suppliedContext = (array) InputHelper::get('context');
$suppliedTag = InputHelper::get('tag');
- $tags = TagSearchService::getRelatedTagRows($suppliedTag, 10, 1);
+ $limit = intval($this->config->browsing->tagsRelated);
+ $tags = TagSearchService::getRelatedTagRows($suppliedTag, $suppliedContext, $limit);
$this->context->transport->tags =
array_values(array_map(
diff --git a/src/Models/SearchServices/TagSearchService.php b/src/Models/SearchServices/TagSearchService.php
index ca35e887..365e0a6c 100644
--- a/src/Models/SearchServices/TagSearchService.php
+++ b/src/Models/SearchServices/TagSearchService.php
@@ -9,7 +9,7 @@ class TagSearchService extends AbstractSearchService
$stmt->addColumn(new Sql\AliasFunctor(new Sql\CountFunctor('post_tag.post_id'), 'post_count'));
}
- public static function getRelatedTagRows($parentTagName, $limit)
+ public static function getRelatedTagRows($parentTagName, $context, $limit)
{
$parentTagEntity = TagModel::findByName($parentTagName, false);
if (empty($parentTagEntity))
@@ -24,7 +24,6 @@ class TagSearchService extends AbstractSearchService
->addInnerJoin('post_tag', new Sql\EqualsFunctor('post_tag.tag_id', 'tag.id'))
->setGroupBy('tag.id')
->setOrderBy('post_count', Sql\SelectStatement::ORDER_DESC)
- ->setLimit($limit + 1, 0)
->setCriterion(new Sql\ExistsFunctor((new Sql\SelectStatement)
->setTable('post_tag pt2')
->setCriterion((new Sql\ConjunctionFunctor)
@@ -62,6 +61,8 @@ class TagSearchService extends AbstractSearchService
}
usort($rows, function($a, $b) { return intval($b['sort']) - intval($a['sort']); });
+ $rows = array_filter($rows, function($row) use ($context) { return !in_array($row['name'], $context); });
+ $rows = array_slice($rows, 0, $limit);
return $rows;
}