If this is your first visit, check our documentation. To post, register or login.
Forums / Code Matters / Bug Reports / zen_back_link: addon problem when current page removed

zen_back_link: addon problem when current page removed

Started by lat9 on 28 Aug 2011, 10:08 AM · Views: 1,117

Results 1 to 3 of 3
28 Aug 2011, 10:08 AM
#1
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,146
Plugin Contributions:
56

Post #1 by lat9

Running ZC 1.3.9h with various add-ons.

I'm playing with the ask_a_question add-on and figured that there was no good reason to keep that page in the navigation history, so I updated the header_php.php file for the ask_a_question page to remove the page from the navigation history:

$_SESSION['navigation']->remove_current_page();

So far, so good. The problem is that the function zen_back_link makes the "assumption" that the current page is in the navigation history and falls down the default "back-button" path in this case, resulting in the HTTP_REFERER being used; this unfortunately results in the "back" button for the ask_a_question "success" path going back the the ask_a_question page (erggh).

Anyway, here's an updated version of zen_back_link() that is "aware" of the fact that the current page might not be present in the history list:

////
// Set back button
  function zen_back_link($link_only = false) {
	// ----
	// If the last page in the navigation history is the current page, then "back" is the previous
	// page; otherwise, the current page has been removed from the navigation, so the "back" target
	// is the last page in the navigation history.
	//
	$back = sizeof($_SESSION['navigation']->path) - 1;
	if ($back > 0 && $_SESSION['navigation']->path[$back]['page'] == $_GET['main_page']) {
	  $back--;
	}
//    if (sizeof($_SESSION['navigation']->path)-2 >= 0) {
//      $back = sizeof($_SESSION['navigation']->path)-2;
    if ($back >= 0) {
      $link = zen_href_link($_SESSION['navigation']->path[$back]['page'], zen_array_to_string($_SESSION['navigation']->path[$back]['get'], array('action')), $_SESSION['navigation']->path[$back]['mode']);
    } else {
      if (isset($_SERVER['HTTP_REFERER']) && preg_match("~^".HTTP_SERVER."~i", $_SERVER['HTTP_REFERER']) ) {
      //if (isset($_SERVER['HTTP_REFERER']) && strstr($_SERVER['HTTP_REFERER'], str_replace(array('http://', 'https://'), '', HTTP_SERVER) ) ) {
        $link= $_SERVER['HTTP_REFERER'];
      } else {
        $link = zen_href_link(FILENAME_DEFAULT);
      }
      $_SESSION['navigation'] = new navigationHistory;
    }
	
    if ($link_only == true) {
      return $link;
    } else {
      return '<a href="' . $link . '">';
    }
  }
2 Sep 2011, 8:54 PM
#2
wilt avatar

wilt

Oji-san

Join Date:
Jun 2003
Location:
Newcastle UK
Posts:
1,950
Plugin Contributions:
3

Post #2 by wilt

Hi,

Not sure why you removed the page from the history in the first place, regardless this is not something we will be addressing at the moment, given it relates to an addon, and not core functionality.

5 Sep 2011, 12:19 PM
#3
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,146
Plugin Contributions:
56

Post #3 by lat9

Although this problem surfaced when I was configuring an add-on, I believe that it is a core-file issue. There are places in the stock Zen-cart install where the page "should" be removed from the navigation (like the logoff page) and the behavior of zen_back_link will continue to produce interesting results until it is corrected.