Back link won't work for converted Template

If you've problems with unsupported - non official ;-) - functionalities use this forum please.
Post Reply
kismert
Posts: 6
Joined: Wed 21. Mar 2007, 17:15

Back link won't work for converted Template

Post by kismert »

Hi,

I am converting a phpwcms site from 1.0.4 to 1.3.

One problem is the 'Back' links in my Sub Menus have stopped working.

I traced the source to this tag in a template:

Code: Select all

{NAV_LIST_CURRENT:1:Back:mainSubMenuCur}
How do I modify this old tag so the Back link functions as before?

Thanks,

-Ken
kismert
Posts: 6
Joined: Wed 21. Mar 2007, 17:15

Fixed, but probably not optimal

Post by kismert »

I traced the problem to the css_level_list function, in front.func.inc.php.

Note that in the tag {NAV_LIST_CURRENT:1:Back:mainSubMenuCur}, the '1' maps to $parent_level, and 'Back' maps to $parent_level_name.

This code snippet is the culprit.

Code: Select all

	if($parent_level) {
		if(!$struct[$level]["acat_redirect"]) {
			$link = 'index.php?';
			if($struct[$level]["acat_alias"]) {
				$link .= html_specialchars($struct[$level]["acat_alias"]);
			} else {
				$link .= 'id='.$level.',0,0,1,0,0';
			}
			$redirect['target'] = '';
		} else {
			$redirect = get_redirect_link($struct[$level]["acat_redirect"], ' ', '');
			$link = $redirect['link'];
		}
The lines '$link .= html_specialchars($struct[$level]["acat_alias"]);' and '$link .= 'id='.$level.',0,0,1,0,0';' both build links to the current page. Thus, clicking on 'Back' takes you to the same page, which makes it appear to do nothing.

To fix this, delete the code above, and insert this switch statement:

Code: Select all

	switch ($parent_level) {
	case 0:
		// back (originally meant 'don't show')
		$show_parent_level = true;
		// stolen from get_index_link_up()
		$cat_id = $GLOBALS['content']['cat_id'];
		$link = 'index.php?id=' . $GLOBALS['content']['struct'][$cat_id]['acat_struct'].',0,0,1,0,0';
		$redirect['target'] = '';
	    break;
	case 1:
		// normal
		$show_parent_level = true;
		if(!$struct[$level]["acat_redirect"]) {
			$link = 'index.php?';
			if($struct[$level]["acat_alias"]) {
				$link .= html_specialchars($struct[$level]["acat_alias"]);
			} else {
				$link .= 'id='.$level.',0,0,1,0,0';
			}
			$redirect['target'] = '';
		} else {
			$redirect = get_redirect_link($struct[$level]["acat_redirect"], ' ', '');
			$link = $redirect['link'];
		}
	    break;
	default:
		// don't show
		$show_parent_level = false;
	}

	// this line replaces 'if($parent_level) {', above
	if ($show_parent_level) {
Note: the last line is required to continue the 'if' statement that the original code started.

A new case, '0', was added, that uses code from the get_index_link_up function to get the proper link back.

In the Template, I now replace the '1' in my tag with '0':

Code: Select all

{NAV_LIST_CURRENT:0:Back:mainSubMenuCur}
Now the back link works. (If you want the original, functionality, use '1'.)

I hate to modify code, but there seemed to be no choice. Is this a bug? If so, I will report it to the bug section.

-Ken
Post Reply