Skip to content
Merged
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
57 changes: 46 additions & 11 deletions system/ee/ExpressionEngine/Addons/channel/mod.channel.php
Original file line number Diff line number Diff line change
Expand Up @@ -4179,8 +4179,10 @@ public function close_ul($parent_id, $depth = 0)
}

/**
* Channel "category_heading" tag
*/
* Parse the Channel "category_heading" tag.
*
* @return string
*/
public function category_heading()
{
if ($this->query_string == '' && !ee()->TMPL->fetch_param('category_url_title') && !ee()->TMPL->fetch_param('category_id')) {
Expand Down Expand Up @@ -4216,6 +4218,8 @@ public function category_heading()
$qstring = reduce_double_slashes(str_replace($match[0], '', $qstring));
}

$parent_only = (ee()->TMPL->fetch_param('parent_only') == 'yes');

// Is the category being specified by name?
if (
(
Expand Down Expand Up @@ -4269,6 +4273,20 @@ public function category_heading()

$valid_cats = array_unique($valid_cats);

if ($category_group = ee()->TMPL->fetch_param('category_group')) {
if (substr($category_group, 0, 4) == 'not ') {
$category_group_ids = explode('|', substr($category_group, 4));
$valid_cats = array_diff($valid_cats, $category_group_ids);
}

if (substr($category_group, 0, 4) != 'not ') {
$category_group_ids = explode('|', $category_group);
$valid_cats = array_intersect($valid_cats, $category_group_ids);
}

$valid_cats = array_filter($valid_cats, 'is_numeric');
}

if (count($valid_cats) == 0) {
$valid = 'n';
}
Expand All @@ -4291,21 +4309,37 @@ public function category_heading()
$cut_qstring = ee()->TMPL->fetch_param('category_url_title');
}

$result = ee()->db->query("SELECT cat_id FROM exp_categories
WHERE cat_url_title='" . ee()->db->escape_str($cut_qstring) . "'
AND group_id IN ('" . implode("','", $valid_cats) . "')");
ee()->db->select('cat_id');
ee()->db->where('cat_url_title', $cut_qstring);
ee()->db->where_in('group_id', $valid_cats);
ee()->db->order_by('cat_id', 'ASC');
ee()->db->limit(1);

if ($parent_only) {
ee()->db->where('parent_id', 0);
}

if ($result->num_rows() == 1) {
$result = ee()->db->get('categories');

if ($result->num_rows() > 0) {
$qstring = !ee()->TMPL->fetch_param('category_url_title')
? str_replace($cut_qstring, 'C' . $result->row('cat_id'), $qstring)
: 'C' . $result->row('cat_id');
} else {
// give it one more try using the whole $qstring
$result = ee()->db->query("SELECT cat_id FROM exp_categories
WHERE cat_url_title='" . ee()->db->escape_str($qstring) . "'
AND group_id IN ('" . implode("','", $valid_cats) . "')");
ee()->db->select('cat_id');
ee()->db->where('cat_url_title', $qstring);
ee()->db->where_in('group_id', $valid_cats);
ee()->db->order_by('cat_id', 'ASC');
ee()->db->limit(1);

if ($parent_only) {
ee()->db->where('parent_id', 0);
}

$result = ee()->db->get('categories');

if ($result->num_rows() == 1) {
if ($result->num_rows() > 0) {
$qstring = 'C' . $result->row('cat_id') ;
}
}
Expand Down Expand Up @@ -4339,7 +4373,8 @@ public function category_heading()
$query = ee()->db->query("SELECT c.cat_name, c.parent_id, c.cat_url_title, c.cat_description, c.cat_image {$field_sqla}
FROM exp_categories AS c
{$field_sqlb}
WHERE c.cat_id = '" . ee()->db->escape_str($cat_id) . "'");
WHERE c.cat_id = '" . ee()->db->escape_str($cat_id) . "'
" . ($parent_only ? 'AND c.parent_id = 0' : ''));

if ($query->num_rows() == 0) {
return ee()->TMPL->no_results();
Expand Down
Loading
Loading