xtoc and locator

A place to report and discuss bugs - please mention CMSimple-version, server, platform and browser version
Post Reply
milkodb
Posts: 47
Joined: Sun Jun 23, 2013 11:00 pm
Location: Italy

xtoc and locator

Post by milkodb » Wed Feb 05, 2014 12:29 pm

Hi,

Having the need to implement multi-level menu in which the first item in a menu is not linkable I tried to use xtoc 1.0 beta5 activating appropriate features ("li" function ner 5 that combines 3 and 4) .
  • eg:

    myFirstLevelItem ("categorized")
    mySecondLevelItem1 ("categorized") > myThirdLevelItem1 , myThirdLevelItem2 , myThirdLevelItem3
    mySecondLevelItem2 (direct link)
    mySecondLevelItem3 ("categorized") > myThirdLevelItem1 , myThirdLevelItem2
    mySecondLevelItem4 (direct link)

    etc.
The problem is about locator which shows "category_myFirstLevelItem" instead of " myFirstLevelItem " and " category_mySecondLevelItem " instead of " mySecondLevelItem " when a second level item has a further submenu:
  • "Home > category_myFirstLevelItem > "category_mySecondLevelItem1" > myThirdLevelItem1"
So I tried to figure out how to solve the problem and I have tried to understand how the PHP code (I just started) .

I searched the "tplfuncs.php" code and I found the "locator ()" function.
Then I analyzed the xtoc function "xlocator" that serves to eliminate string "category_ " when "home" (the first item in a menu) is defined as label.

At this point I pulled the string "category_" by the results of the standard "locator()" function conditional structure and deleted the link ( <a> ) that would point to pages that should never be displayed .

Finally I put the code in xtoc creating a "xlocator2 ()" ner 9 function which can be used together with 3, 4 (or 5 that combines 3 and 4) and I normally called it from the template.

Code: Select all

<?php echo xlocator2();?>

Code: Select all

// ( 9 ) xlocator2() function: is required for remove "category_" label from titles in the breadcrumb navigation, if "category_" is used for the first voice of some menu. Can be used in combination with function (3), (4) or (5).///

function xlocator2(){ global $title, $h, $s, $f, $c, $l, $tx, $cf; if (hide($s) && $cf['show_hidden']['path_locator'] != 'true') {return $h[$s];}if ($s == 0) {return $h[$s];} elseif ($title != '' && (!isset($h[$s]) || $h[$s] != $title)) {$t = eregi_replace('category_', '', $title);} elseif ($f != '') {return ucfirst($f);} elseif ($s > 0) {$t = ''; $tl = $l[$s];if ($tl > 1) {for ($i = $s - 1; $i >= 0; $i--) {if ($l[$i] < $tl) {$t = eregi_replace('category_', '', $h[$i]) . ' > ' . eregi_replace('category_', '', $t);$tl--;}if ($tl < 2) {break;}}}} else {return '&nbsp;';}if ($cf['locator']['show_homepage'] == 'true') {return a(0, '') . $tx['locator']['home'] . '</a> > ' . $t . (($s > 0 && $h[$s] == $title) ? $h[$s] : '');} else {return $t . (($s > 0 && $h[$s] == $title) ? $h[$s] : '');}}
I guess mine is a trivial solution and there are probably more elegant ways, but it seems to work without any problems and it is possible that this other solution would be useful.

If someone more experienced than me detects any inconsistency or incompatibility or possible drawbacks, of course, let me know.

Thanks
Last edited by milkodb on Tue Feb 18, 2014 6:48 pm, edited 3 times in total.
Milko

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: xtoc and locator

Post by cmb » Wed Feb 05, 2014 3:35 pm

milkodb wrote:I guess mine is a trivial solution and there are probably more elegant ways, but it seems to work without any problems and it is possible that this other solution would be useful.
Thanks for sharing. I have linked to this thread from the CMSimple Wiki. In the section Known bugs there are mentioned respective problems regarding the sitemap in print view. I assume you have that issue, too.

A basic issue regarding such modified toc()s and li()s is that they won't cater for new features of CMSimple(_XH). xtoc was written long ago, and does not cater for the configuration option menu_sdoc=parent, which has been introduced in CMSimple 2.8. Therefore xtoc28 was written (however, it only supports the basic functionality, and not, for instance, categories). CMSimple_XH 1.6 added the possibility to open menu links in new tabs, but that is not catered for by xtoc28.

Unfortunately, there's not much we can do about it, except to make the built-in functions more flexible (either by introducing more callbacks, or perhaps by switching to an object oriented style introducing template methods). For the current state of the built-in functions and what can be done with them, see the XH Wiki.
Christoph M. Becker – Plugins for CMSimple_XH

milkodb
Posts: 47
Joined: Sun Jun 23, 2013 11:00 pm
Location: Italy

Re: xtoc and locator

Post by milkodb » Wed Feb 05, 2014 6:23 pm

In the section Known bugs there are mentioned respective problems regarding the sitemap in print view. I assume you have that issue, too.
Yes CMB, thanks, I read on wiki and of course there is the same problem for me. I think that is the next step but for now I'm happy to finish the site that I'm working to.

I'll try to find a solution as soon as I solved other issues. It 'still a practical way to learn PHP quickly.

Ciao
Milko

Post Reply