Thread: zen_back_link

Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    3,509
    Plugin Contributions
    33

    Default zen_back_link

    The function zen_back_link, in /includes/functions/functions_general.php, does not account for pages (like password_forgotten) that remove themselves from the navigation history ($_SESSION['navigation']->remove_current_page()). If, for example, you use a stock v150 installation and go to Home, New Products, Login, Password Forgotten and then press the back button you will be taken to the new_products page instead of the login page.

    Here's a rewrite (including my previously-reported validation issue) that corrects this problem:

    Code:
    ////
    // Set back button
      function zen_back_link($link_only = false) {
    /*-BOF rewrite lat9
        if (sizeof($_SESSION['navigation']->path)-2 >= 0) {
          $back = sizeof($_SESSION['navigation']->path)-2;
          $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;
        }
    */
        $link = '';
        $nav_size = sizeof ($_SESSION['navigation']->path);
        if ($nav_size != 0) {
          $back = $nav_size - 1;
          if ($_SESSION['navigation']->path[$back]['page'] != $current_page || ($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']);       
          }
        }
        
        if ($link == '') {
          if (isset($_SERVER['HTTP_REFERER']) && preg_match("~^".HTTP_SERVER."~i", $_SERVER['HTTP_REFERER']) ) {
            $link= $_SERVER['HTTP_REFERER'];
          } else {
            $link = zen_href_link(FILENAME_DEFAULT);
          }
          $_SESSION['navigation'] = new navigationHistory;
        }
      
        $link = str_replace('&', '&', $link);  //-lat9- Validation issue
        if ($link_only == true) {
          return $link;
        } else {
          return '<a href="' . $link . '">';
        }
      }

  2. #2
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    3,509
    Plugin Contributions
    33

    Default Re: zen_back_link

    I messed that up; size vs. index of arrays (arggh). Changes are highlighted in red. Note that the result still might be incorrect if the navigation history in the session is empty and the HTTP_REFERER is the current page.

    Code:
    ////
    // Set back button
      function zen_back_link($link_only = false) {
    /*-BOF rewrite lat9
        if (sizeof($_SESSION['navigation']->path)-2 >= 0) {
          $back = sizeof($_SESSION['navigation']->path)-2;
          $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;
        }
    */
        $link = '';
        $nav_last = sizeof ($_SESSION['navigation']->path) - 1;
        if ($nav_last > 0) {
          $back = $nav_last - 1;
          if ($_SESSION['navigation']->path[$back]['page'] != $current_page_base || (--$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']);       
          }
        }
        
        if ($link == '') {
          if (isset($_SERVER['HTTP_REFERER']) && preg_match("~^".HTTP_SERVER."~i", $_SERVER['HTTP_REFERER']) ) {
            $link= $_SERVER['HTTP_REFERER'];
          } else {
            $link = zen_href_link(FILENAME_DEFAULT);
          }
          $_SESSION['navigation'] = new navigationHistory;
        }
      
        $link = str_replace('&', '&amp;', $link);  //-lat9- Validation issue
        if ($link_only == true) {
          return $link;
        } else {
          return '<a href="' . $link . '">';
        }
      }

 

 

Similar Threads

  1. A question about zen_back_link
    By yellow1912 in forum General Questions
    Replies: 6
    Last Post: 28 Jan 2008, 09:27 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •