Collapse navlink config under heading in backend

Skinning and designing Serendipity (CSS, HTML, Smarty)
Don Chambers
Regular
Posts: 3652
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Collapse navlink config under heading in backend

Post by Don Chambers »

Somebody (Garvin?) added an option to bulletproof's config.inc,php file that collapses selected template options under a heading. How do we do that with temate options that are contained in an array like the navlinks?
=Don=
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Collapse navlink config under heading in backend

Post by garvinhicking »

Don Chambers wrote:Somebody (Garvin?) added an option to bulletproof's config.inc,php file that collapses selected template options under a heading. How do we do that with temate options that are contained in an array like the navlinks?
I don't know if that's really possible. Currently this:

Code: Select all

$template_config_groups = array(
    THEME_COLORSET  => array('colorset', 'userstylesheet', 'layouttype', 'jscolumns'),
    THEME_HEADER    => array('custheader', 'headerimage', 'headertype')
);
so that basically takes the config name of any field you want there; if you want to put navlink1, 2, 3. etc in there, you'd have to append the array with each config option you want...:

Code: Select all

for($i = 0; $i < 5; $i++) {
  $template_config_groups['NAVIGATION'][] = 'navigation' . $i;
}
(something along these lines, untested).

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Don Chambers
Regular
Posts: 3652
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Re: Collapse navlink config under heading in backend

Post by Don Chambers »

So, before bulletproof used global nav, we had this:

Code: Select all

for ($i = 0; $i < $template_loaded_config['amount']; $i++) {
    $navlinks[] = array(
        'title' => $template_loaded_config['navlink' . $i . 'text'],
        'href'  => $template_loaded_config['navlink' . $i . 'url']
    );
    $template_config[] = array(
        'var'           => 'navlink' . $i . 'text',
        'name'          => NAV_LINK_TEXT . ' #' . $i,
        'type'          => 'string',
        'default'       => 'Link #' . $i,
        );
    $template_config[] = array(
        'var'           => 'navlink' . $i . 'url',
        'name'          => NAV_LINK_URL . ' #' . $i,
        'type'          => 'string',
        'default'       => '#',
    );
}
So, I want to collapse these navbar items into a heading, in addition to something like these:

Code: Select all

$template_config_groups = array(
    THEME_COLORSET  => array('colorset', 'userstylesheet', 'layouttype', 'jscolumns'),
    THEME_HEADER    => array('custheader', 'headerimage', 'headertype')
);
I tried this - no error, but it didn't result in any change to the "manage styles" page:

Code: Select all

for ($i = 0; $i < $template_loaded_config['amount']; $i++) {
	$template_config_groups['NAVIGATION'][] = 'navlink' . $i . 'text';
	$template_config_groups['NAVIGATION'][] = 'navlink' . $i . 'url';	
}
Any further suggestions?
=Don=
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: Collapse navlink config under heading in backend

Post by Timbalu »

I expect you want to have a "all option on/off" link to collaps / open the nav part in your templates config?!
This will need the javascript used in Administration->configuration, some links and some css using them. I did this for sliver in a certain way to structure the data for the staticpage backend, which looks very nice and works very well. Have a look over here https://github.com/ophian/Sliver/blob/m ... ackend.tpl
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: Collapse navlink config under heading in backend

Post by Timbalu »

Asking this was quite a good idea Don. We should use it everywhere! [Gavin, Yl?]

To do what you want, you need to use the code like this ...

Code: Select all

$new_tlc = array();
$new_tlc = array_diff($template_loaded_config, $template_config);
$navonly = array();
foreach($new_tlc as $key=>$value)
{
    if (preg_match('#^(amount)#', $key, $matches)===1 || preg_match('#^(navlink+)#', $key, $matches)===1) {
        $navonly[] = $key;  
    }
}
$template_config_groups = array(
    THEME_COLORSET  => array('colorset', 'userstylesheet', 'layouttype', 'jscolumns'),
    THEME_HEADER    => array('custheader', 'headerimage', 'headertype'),
    THEME_NAV       => $navonly
);
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
Don Chambers
Regular
Posts: 3652
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Re: Collapse navlink config under heading in backend

Post by Don Chambers »

Thanks Ian - I have not yet tried your suggestion, but at first look it seems pretty complex. Can you explain exactly what it is doing, and why? Can you also explain how it would change if I had not just a single navlink array, but say navlink1 and navlink2, and wanted them contained under separate headings?
=Don=
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: Collapse navlink config under heading in backend

Post by Timbalu »

Give it a try. That explanation would be the very best.
In short: compare two arrays to the diff array (this is just be done to have a small array containing the navlinks), in there collect amount and navlinks fields to the new array $navonly and pass them to the template config group as the collapsing link THEME NAV.
This makes a config being hidden in collapsable headers at all
i.e. (my Sliver config):

Code: Select all

$template_config_groups = array(
    THEME_WELCOME   => array('about'),
    THEME_LAYOUT    => array('sidebars', 'webfonts', 'userstylesheet', 'use_slivers_JQueryMin', 'use_google_analytics', 'google_id', 'layouttype', 'firbtitle', 'firbdescr'),
    THEME_ENTRIES   => array('date_format', 'entryfooterpos', 'footerauthor', 'send2printer', 'footercategories', 'footertimestamp', 'footercomments', 'footertrackbacks', 'altcommtrack', 'show_sticky_entry_footer', 'show_sticky_entry_heading', 'prev_next_style', 'show_pagination'),
    THEME_SIDENAV   => array('sitenavpos', 'sitenavstyle', 'sitenav_footer', 'sitenav_quicksearch', 'sitenav_sidebar_title'),
    THEME_NAV       => $navonly
);
Maybe I misunderstood, but why should you want to have each navlink under a seperate header?
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
Don Chambers
Regular
Posts: 3652
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Re: Collapse navlink config under heading in backend

Post by Don Chambers »

Timbalu wrote:Maybe I misunderstood, but why should you want to have each navlink under a seperate header?
Not each navlink... multiple navbars, and other config items that are arrays and structured much like the navbars are. Pretty sure I can figure it out though. Will play with this and get back to you.
=Don=
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: Collapse navlink config under heading in backend

Post by Timbalu »

Yes, that is what I showed you with my sliver group config. There you can sort and hide as much as you like, very easy. Only the navlinks need this special array handlings as not found in the templates config any more.
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
Don Chambers
Regular
Posts: 3652
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Re: Collapse navlink config under heading in backend

Post by Don Chambers »

Seems to work great - so what do I need to add for a second navbar (ie, navlink1, navlink2...)
=Don=
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: Collapse navlink config under heading in backend

Post by Timbalu »

Where is the config of that second navbar located?
Is the amount of that second navbar static or dynamic?
Try to give me an example please.
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
Don Chambers
Regular
Posts: 3652
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Re: Collapse navlink config under heading in backend

Post by Don Chambers »

Dynamic, just like the first one. is it just a second foreach loop with a new $key?
=Don=
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: Collapse navlink config under heading in backend

Post by Timbalu »

Is it build by the global core code or by your templates config? Nearby example please.
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
Don Chambers
Regular
Posts: 3652
Joined: Mon Feb 13, 2006 2:40 am
Location: Chicago, IL, USA
Contact:

Re: Collapse navlink config under heading in backend

Post by Don Chambers »

It is identical to the first one... I have navlinks1 & navlinks2. Two navigation bars configured by the template:

Code: Select all

$navlinks1 = array();
for ($i = 0; $i < $template_loaded_config['navlink1_amount']; $i++) {
    $navlinks1[] = array(
        'title' => $template_loaded_config['navlink1' . $i . 'text'],
        'href'  => $template_loaded_config['navlink1' . $i . 'url']
    );
    $template_config[] = array(
        'var'           => 'navlink1' . $i . 'text',
        'name'          => NAV_LINK_TEXT . ' #' . $i,
        'type'          => 'string',
        'default'       => 'Link #' . $i,
        );
    $template_config[] = array(
        'var'           => 'navlink1' . $i . 'url',
        'name'          => NAV_LINK_URL . ' #' . $i,
        'type'          => 'string',
        'default'       => '#',
    );
}
There is a second navbar, the difference is a "2" for each instance of a "1" above. It works with a second foreach loop, but I was wondering if that was the most efficient way.
=Don=
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: Collapse navlink config under heading in backend

Post by Timbalu »

Now that one gets complicated...!

To clear things up:
In my enviroment I don't use the old code any more in the templates config and Serendipity core >= 1.6 adds the navigation config items magically into the $template_config array and into $template_loaded_config, which is the later one being used. This is done by

Code: Select all

$template_global_config = array('navigation' => true);
Now, if I add that old code part for a second navbar into the templates config, it is showed properly, but has not been checked by the options table ($template_loaded_config). That is differing to the origin core one, which is enhanced compared to the old code!

Now we could build a recursive function to check all these inner $template_config arrays to add the second navbar items into a $nav2only array to get handled and collapsed the same way as before - somehow...

...but....

Before I try to get this managed, did you really check if two navbars build in this way do work properly if one is build by core and one by your templates config? Is the options table doing well with that? What about changing amount and items, erasing, etc?

@Garvin
could we use that one in this case?

Code: Select all

    // Forward thinking. ;-)
    serendipity_plugin_api::hook_event('backend_templates_globalthemeoptions', $template_config, $supported);
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
Post Reply