Show_hidden not showing levels in between

Discussions and requests related to new CMSimple features, plugins, templates etc. and how to develop.
Please don't ask for support at this forums!
Post Reply
svasti
Posts: 1649
Joined: Wed Dec 17, 2008 5:08 pm

Show_hidden not showing levels in between

Post by svasti » Mon Mar 24, 2014 6:00 pm

Hi the experts

I have several hidden pages on level 3 and would like to show these pages in the menu, if selected. Unfortunately, if parent page on level 2 is also hidden, this parent level page will not appear in the menu. In my fold-out menu, if the parent level doesn't show up, nothing will be shown. :evil:

I just would like a little trick to make hidden parentpages also show up in the menu, if a hidden subpage is selected.

Any idea?

cmb
Posts: 13273
Joined: Tue Jun 21, 2011 11:04 am
Location: Mü-Sa, RLP, DE
Contact:

Re: Show_hidden not showing levels in between

Post by cmb » Mon Mar 24, 2014 6:23 pm

Hm, the current behavior might be regarded as bug. :?

Anyway, in your case you need a customized $hc, I presume. Currently we have the following in cmsimple/cms.php:

Code: Select all

// Compatibility for DHTML menus
$si = -1;
$hc = array();
for ($i = 0; $i < $cl; $i++) {
    if (!hide($i) || ($i == $s && $cf['show_hidden']['pages_toc'] == 'true')) {
        $hc[] = $i;
    }
    if ($i == $s) {
        $si = count($hc);
    }
}
$hl = count($hc); 
The relevant line is the longest; there has to be a third or-clause:

Code: Select all

    if (!hide($i) || ($i == parentOf($s) && $cf['show_hidden']['pages_toc'] == 'true') || ($i == $s && $cf['show_hidden']['pages_toc'] == 'true')) { 
(The code could be somewhat simplified.) As there is no function parentOf($index), you have to define one. The simplest solution is to make use of XH_Pages (available since XH 1.6) and to ignore recursion issues (not needed in your case):

Code: Select all

function parentOf($index)
{
    global $pth;

    include_once $pth['folder']['classes'] . 'Pages.php';
    $pages = new XH_Pages();
    return $pages->parent($index);
} 
Inlining the code would be more efficient, though.
Christoph M. Becker – Plugins for CMSimple_XH

svasti
Posts: 1649
Joined: Wed Dec 17, 2008 5:08 pm

Re: Show_hidden not showing levels in between

Post by svasti » Mon Mar 24, 2014 9:28 pm

cmb wrote:the current behavior might be regarded as bug
I've put in on the roadmap.

However unfortunately your code doesn't seem to do the job, at least not here. (Changed the respective line in cms.php and added the function to functions.php.) Breadcrumbs actually worked correctly with show_hidden even before.

My menu:

Code: Select all

<ul class="menulevel1">
<li class="docs"><a href="/Svasti/?Start">Start</a></li>
<li class="docs"><a href="/Svasti/?Templates_%28Designs%29">Templates (Designs)</a></li>
<li class="docs"><a href="/Svasti/?Kurzanleitung">Kurzanleitung</a>
<ul class="menulevel2">

<ul class="menulevel3">
<li class="sdoc"><span>Miniblog</span></li>
</ul>
</ul>
</li>
</ul>
The hidden parents of Miniblog are still missing.

cmb
Posts: 13273
Joined: Tue Jun 21, 2011 11:04 am
Location: Mü-Sa, RLP, DE
Contact:

Re: Show_hidden not showing levels in between

Post by cmb » Tue Mar 25, 2014 10:57 am

svasti wrote:The hidden parents of Miniblog are still missing.
I had overlooked the $ignoreHidden parameter of XH_Pages::parent(). The following should work:

Code: Select all

function parentOf($index)
{
    global $pth;

    include_once $pth['folder']['classes'] . 'Pages.php';
    $pages = new XH_Pages();
    return $pages->parent($index, false);
}
Christoph M. Becker – Plugins for CMSimple_XH

svasti
Posts: 1649
Joined: Wed Dec 17, 2008 5:08 pm

Re: Show_hidden not showing levels in between

Post by svasti » Tue Mar 25, 2014 11:42 am

I my special case also the parent of the parent is hidden. Unfortunately this most important grandparent is still missing.

cmb
Posts: 13273
Joined: Tue Jun 21, 2011 11:04 am
Location: Mü-Sa, RLP, DE
Contact:

Re: Show_hidden not showing levels in between

Post by cmb » Tue Mar 25, 2014 12:20 pm

Well, then the following will do (although somewhat inefficently):

Code: Select all

/**
 * @return array<int>
 */
function ancestorsOf($index)
{
    global $pth;

    include_once $pth['folder']['classes'] . 'Pages.php';
    $pages = new XH_Pages();
    $result = array();
    while (true) {
        $parent = $pages->parent($index, false);
        if ($parent === null) {
            break;
        }
        $result[] = $parent;
        $index = $parent;
    }
    return $result;
} 
In cmsimple/cms.php:

Code: Select all

    if (!hide($i)
        || $cf['show_hidden']['pages_toc'] == 'true'
        && ($i == $s || in_array($i, ancestorsOf($s)))
    ) {
        $hc[] = $i;
    } 
Christoph M. Becker – Plugins for CMSimple_XH

svasti
Posts: 1649
Joined: Wed Dec 17, 2008 5:08 pm

Re: Show_hidden not showing levels in between

Post by svasti » Tue Mar 25, 2014 12:54 pm

Yep, works, thanx.

Post Reply