Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.0] Add prepared statements for mod tags popular #25043

Merged
merged 14 commits into from Jul 23, 2019
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 18 additions & 12 deletions modules/mod_tags_popular/Helper/TagsPopularHelper.php
Expand Up @@ -14,6 +14,7 @@
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Helper\ContentHelper;
use Joomla\Database\ParameterType;

/**
* Helper for mod_tags_popular
Expand All @@ -35,26 +36,26 @@ public static function getList(&$params)
{
$db = Factory::getDbo();
$user = Factory::getUser();
$groups = implode(',', $user->getAuthorisedViewLevels());
$groups = $user->getAuthorisedViewLevels();
$timeframe = $params->get('timeframe', 'alltime');
$maximum = $params->get('maximum', 5);
$order_value = $params->get('order_value', 'title');
$nowDate = Factory::getDate()->toSql();
$nullDate = $db->quote($db->getNullDate());
$nullDate = $db->getNullDate();

$query = $db->getQuery(true)
->select(
array(
'MAX(' . $db->quoteName('tag_id') . ') AS tag_id',
' COUNT(*) AS count', 'MAX(t.title) AS title',
' COUNT(*) AS count', 'MAX(' . $db->quoteName('t.title') . ') AS title',
'MAX(' . $db->quoteName('t.access') . ') AS access',
'MAX(' . $db->quoteName('t.alias') . ') AS alias',
'MAX(' . $db->quoteName('t.params') . ') AS params',
)
)
->group($db->quoteName(array('tag_id', 'title', 'access', 'alias')))
HLeithner marked this conversation as resolved.
Show resolved Hide resolved
->from($db->quoteName('#__contentitem_tag_map', 'm'))
->where($db->quoteName('t.access') . ' IN (' . $groups . ')');
->whereIn($db->quoteName('t.access'), $groups);

// Only return published tags
$query->where($db->quoteName('t.published') . ' = 1 ');
Expand All @@ -64,7 +65,7 @@ public static function getList(&$params)

if ($parentTags)
{
$query->where($db->quoteName('t.parent_id') . ' IN (' . implode(',', $parentTags) . ')');
$query->whereIn($db->quoteName('t.parent_id'), $parentTags);
}

// Optionally filter on language
Expand All @@ -77,15 +78,16 @@ public static function getList(&$params)
$language = ContentHelper::getCurrentLanguage();
}

$query->where($db->quoteName('t.language') . ' IN (' . $db->quote($language) . ', ' . $db->quote('*') . ')');
$query->whereIn($db->quoteName('t.language'), [$language, '*'], ParameterType::STRING);
}

if ($timeframe !== 'alltime')
{
$query->where($db->quoteName('tag_date') . ' > ' . $query->dateAdd($db->quote($nowDate), '-1', strtoupper($timeframe)));
$query->where($db->quoteName('tag_date') . ' > ' . $query->dateAdd(':nowDate1', '-1', strtoupper($timeframe)))
->bind(':nowDate1', $nowDate);
}

$query->join('INNER', $db->quoteName('#__tags', 't') . ' ON ' . $db->quoteName('tag_id') . ' = t.id')
$query->join('INNER', $db->quoteName('#__tags', 't') . ' ON ' . $db->quoteName('tag_id') . ' = ' . $db->quoteName('t.id'))
HLeithner marked this conversation as resolved.
Show resolved Hide resolved
->join(
'INNER',
$db->quoteName('#__ucm_content', 'c') . ' ON ' . $db->quoteName('m.core_content_id') . ' = ' . $db->quoteName('c.core_content_id')
Expand All @@ -95,10 +97,14 @@ public static function getList(&$params)

// Only return tags connected to published articles
$query->where($db->quoteName('c.core_state') . ' = 1')
->where('(' . $db->quoteName('c.core_publish_up') . ' = ' . $nullDate
. ' OR ' . $db->quoteName('c.core_publish_up') . ' <= ' . $db->quote($nowDate) . ')')
->where('(' . $db->quoteName('c.core_publish_down') . ' = ' . $nullDate
. ' OR ' . $db->quoteName('c.core_publish_down') . ' >= ' . $db->quote($nowDate) . ')');
->where('(' . $db->quoteName('c.core_publish_up') . ' = :nullDate2'
. ' OR ' . $db->quoteName('c.core_publish_up') . ' <= :nowDate2)')
->where('(' . $db->quoteName('c.core_publish_down') . ' = :nullDate3'
. ' OR ' . $db->quoteName('c.core_publish_down') . ' >= :nowDate3)')
->bind(':nullDate2', $nullDate)
->bind(':nowDate2', $nowDate)
->bind(':nullDate3', $nullDate)
->bind(':nowDate3', $nowDate);

// Set query depending on order_value param
if ($order_value === 'rand()')
Expand Down