Skip to content

Commit

Permalink
Fix cot_structure_children() when category is not exists
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex300 committed Feb 18, 2024
1 parent e51387a commit 5375837
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
14 changes: 12 additions & 2 deletions plugins/recentitems/inc/recentitems.functions.php
Expand Up @@ -328,26 +328,34 @@ function cot_build_recentpages(
if (!empty(Cot::$cfg['plugin']['recentitems']['whitelist'])) {
$whitelist = [];
foreach (preg_split('#\r?\n#', Cot::$cfg['plugin']['recentitems']['whitelist']) as $c) {
$c = trim($c);
if ($c === '') {
continue;
}
$whitelist = array_merge(
$whitelist,
cot_structure_children('page', $c, true, true, $rightprescan)
);
}
} else {
$whitelist = false;
$whitelist = null;
}

// Load all cats and subcats in black list if set
if (!empty(Cot::$cfg['plugin']['recentitems']['blacklist'])) {
$blacklist = [];
foreach (preg_split('#\r?\n#', Cot::$cfg['plugin']['recentitems']['blacklist']) as $c) {
$c = trim($c);
if ($c === '') {
continue;
}
$blacklist = array_merge(
$blacklist,
cot_structure_children('page', $c, true, true, $rightprescan)
);
}
} else {
$blacklist = false;
$blacklist = null;
}

if ($rightprescan || $cat) {
Expand All @@ -365,6 +373,8 @@ function cot_build_recentpages(

if (!empty($catsub)) {
$where['category'] = "p.page_cat IN ('" . implode("','", $catsub) . "')";
} else {
$where['category'] = 'FALSE';
}
} elseif (!empty($whitelist)) {
// Only cats from white list
Expand Down
4 changes: 2 additions & 2 deletions system/common.php
Expand Up @@ -686,8 +686,8 @@ function cot_disable_mqgpc(&$value, $key) {
include $sys['theme_resources'];
// Save overridden strings in $theme_reload global
// Todo more right way
$theme_reload['L'] = @array_diff_assoc($L,$L_tmp);
$theme_reload['R'] = @array_diff_assoc($R,$R_tmp);
$theme_reload['L'] = @array_diff_assoc($L, $L_tmp);
$theme_reload['R'] = @array_diff_assoc($R, $R_tmp);
unset($L_tmp, $R_tmp);
}

Expand Down
16 changes: 10 additions & 6 deletions system/functions.php
Expand Up @@ -1517,11 +1517,15 @@ function cot_structure_children($area, $cat, $allsublev = true, $firstcat = tru
$mtch = '';
$mtchlen = $mtchlvl = 0;

if ($cat != '' && isset(Cot::$structure[$area][$cat])) {
$mtch = Cot::$structure[$area][$cat]['path'] . '.';
$mtchlen = mb_strlen($mtch);
$mtchlvl = mb_substr_count($mtch, ".");
}
if ($cat !== '') {
if (!isset(Cot::$structure[$area][$cat])) {
return [];
}

$mtch = Cot::$structure[$area][$cat]['path'] . '.';
$mtchlen = mb_strlen($mtch);
$mtchlvl = mb_substr_count($mtch, ".");
}

$catsub = [];
if ($firstcat && $cat != '' && (($userrights && cot_auth($area, $cat, 'R')) || !$userrights)) {
Expand All @@ -1530,7 +1534,7 @@ function cot_structure_children($area, $cat, $allsublev = true, $firstcat = tru

foreach (Cot::$structure[$area] as $i => $x) {
if (
($cat == '' || (mb_substr($x['path'], 0, $mtchlen) === $mtch))
($cat === '' || (mb_substr($x['path'], 0, $mtchlen) === $mtch))
&& (($userrights && cot_auth($area, $i, 'R')) || !$userrights)
) {
//$subcat = mb_substr($x['path'], $mtchlen + 1);
Expand Down

0 comments on commit 5375837

Please sign in to comment.