Quick Search:

Mode

Context

Displaying 3 lines of context. None | Less | More | Full

Other Diffs

Ignore

Blank Lines Whitespace:

Diff

151
 
368
 
368
 
navigation_history.php
_> 11 <?php
  22 /*
<> 3 -  $Id: navigation_history.php 151 2005-08-02 14:33:25Z mattice $
   3+  $Id: navigation_history.php 368 2005-12-22 16:27:23Z hpdl $
44 
  55   osCommerce, Open Source E-Commerce Solutions
  66   http://www.oscommerce.com
  77 
<> 8 -  Copyright (c) 2003 osCommerce
   8+  Copyright (c) 2005 osCommerce
99 
  1010   Released under the GNU General Public License
  1111 */
  1212 
<> 13 -  class navigationHistory {
  14 -    var $path, $snapshot, $set_global;
   13+  class osC_NavigationHistory {
1514 
<> 16 -    function navigationHistory() {
  17 -      $this->reset();
   15+/* Private variables */
1816 
<> 19 -      $this->setGlobal();
  20 -    }
   17+    var $_data = array(),
   18+        $_snapshot = array();
2119 
<> 22 -    function reset() {
  23 -      $this->path = array();
  24 -      $this->snapshot = array();
  25 -    }
   20+/* Class constructor */
2621 
<> 27 -    function add_current_page() {
  28 -      if (PHP_VERSION < 4.1) {
  29 -        global $_SERVER;
   22+    function osC_NavigationHistory($add_current_page = false) {
   23+      if (isset($_SESSION['osC_NavigationHistory_data']) && is_array($_SESSION['osC_NavigationHistory_data']) && (empty($_SESSION['osC_NavigationHistory_data']) === false)) {
   24+        $this->_data =& $_SESSION['osC_NavigationHistory_data'];
3025       }
  3126 
<> 32 -      global $request_type, $cPath;
   27+      if (isset($_SESSION['osC_NavigationHistory_snapshot']) && is_array($_SESSION['osC_NavigationHistory_snapshot']) && (empty($_SESSION['osC_NavigationHistory_snapshot']) === false)) {
   28+        $this->_snapshot =& $_SESSION['osC_NavigationHistory_snapshot'];
   29+      }
3330 
<> 34 -      if ($this->set_global) {
  35 -        global $_GET, $_POST;
   31+      if ($add_current_page === true) {
   32+        $this->addCurrentPage();
3633       }
<>  34+    }
3735 
<>  36+/* Public methods */
   37+
   38+    function addCurrentPage() {
   39+      global $request_type, $cPath;
   40+
3841       $set = 'true';
<> 39 -      for ($i=0, $n=sizeof($this->path); $i<$n; $i++) {
  40 -        if ($this->path[$i]['page'] == basename($_SERVER['PHP_SELF'])) {
   42+
   43+      for ($i=0, $n=sizeof($this->_data); $i<$n; $i++) {
   44+        if ($this->_data[$i]['page'] == basename($_SERVER['PHP_SELF'])) {
4145           if (isset($cPath)) {
<> 42 -            if (!isset($this->path[$i]['get']['cPath'])) {
   46+            if (!isset($this->_data[$i]['get']['cPath'])) {
4347               continue;
  4448             } else {
<> 45 -              if ($this->path[$i]['get']['cPath'] == $cPath) {
  46 -                array_splice($this->path, ($i+1));
   49+              if ($this->_data[$i]['get']['cPath'] == $cPath) {
   50+                array_splice($this->_data, ($i+1));
4751                 $set = 'false';
  4852                 break;
  4953               } else {
<> 50 -                $old_cPath = explode('_', $this->path[$i]['get']['cPath']);
   54+                $old_cPath = explode('_', $this->_data[$i]['get']['cPath']);
5155                 $new_cPath = explode('_', $cPath);
  5256 
  5357                 for ($j=0, $n2=sizeof($old_cPath); $j<$n2; $j++) {
  5458                   if ($old_cPath[$j] != $new_cPath[$j]) {
<> 55 -                    array_splice($this->path, ($i));
   59+                    array_splice($this->_data, ($i));
5660                     $set = 'true';
  5761                     break 2;
  5862                   }
  5963                 }
  6064               }
  6165             }
  6266           } else {
<> 63 -            array_splice($this->path, $i);
   67+            array_splice($this->_data, $i);
6468             $set = 'true';
  6569             break;
  6670           }
  6771         }
  6872       }
  6973 
  7074       if ($set == 'true') {
<> 71 -        $this->path[] = array('page' => basename($_SERVER['PHP_SELF']),
  72 -                              'mode' => $request_type,
  73 -                              'get' => $_GET,
  74 -                              'post' => $_POST);
   75+        $this->_data[] = array('page' => basename($_SERVER['PHP_SELF']),
   76+                               'mode' => $request_type,
   77+                               'get' => $_GET,
   78+                               'post' => $_POST);
   79+
   80+        if (isset($_SESSION['osC_NavigationHistory_data']) === false) {
   81+          $_SESSION['osC_NavigationHistory_data'] = $this->_data;
   82+        }
7583       }
  7684     }
  7785 
<> 78 -    function remove_current_page() {
  79 -      if (PHP_VERSION < 4.1) {
  80 -        global $_SERVER;
   86+    function removeCurrentPage() {
   87+      $last_entry_position = sizeof($this->_data) - 1;
   88+
   89+      if ($this->_data[$last_entry_position]['page'] == basename($_SERVER['PHP_SELF'])) {
   90+        unset($this->_data[$last_entry_position]);
   91+
   92+        if (sizeof($this->_data) > 0) {
   93+          if (isset($_SESSION['osC_NavigationHistory_data']) === false) {
   94+            $_SESSION['osC_NavigationHistory_data'] = $this->_data;
   95+          }
   96+        } else {
   97+          $this->resetPath();
   98+        }
8199       }
<>  100+    }
82101 
<> 83 -      $last_entry_position = sizeof($this->path) - 1;
  84 -      if ($this->path[$last_entry_position]['page'] == basename($_SERVER['PHP_SELF'])) {
  85 -        unset($this->path[$last_entry_position]);
   102+    function hasPath($back = 1) {
   103+      if ( (is_numeric($back) === false) || (is_numeric($back) && ($back < 1)) ) {
   104+        $back = 1;
86105       }
<>  106+
   107+      return isset($this->_data[sizeof($this->_data) - $back]);
87108     }
  88109 
<> 89 -    function set_snapshot($page = '') {
  90 -      if (PHP_VERSION < 4.1) {
  91 -        global $_SERVER;
   110+    function getPathURL($back = 1, $exclude = array()) {
   111+      if ( (is_numeric($back) === false) || (is_numeric($back) && ($back < 1)) ) {
   112+        $back = 1;
92113       }
  93114 
<>  115+      $back = sizeof($this->_data) - $back;
   116+
   117+      return tep_href_link($this->_data[$back]['page'], $this->_parseParameters($this->_data[$back]['get'], $exclude), $this->_data[$back]['mode']);
   118+    }
   119+
   120+    function setSnapshot($page = '') {
94121       global $request_type;
  95122 
<> 96 -      if ($this->set_global) {
  97 -        global $_GET, $_POST;
   123+      if (is_array($page)) {
   124+        $this->_snapshot = array('page' => $page['page'],
   125+                                 'mode' => $page['mode'],
   126+                                 'get' => $page['get'],
   127+                                 'post' => $page['post']);
   128+      } else {
   129+        $this->_snapshot = array('page' => basename($_SERVER['PHP_SELF']),
   130+                                 'mode' => $request_type,
   131+                                 'get' => $_GET,
   132+                                 'post' => $_POST);
98133       }
  99134 
<> 100 -      if (is_array($page)) {
  101 -        $this->snapshot = array('page' => $page['page'],
  102 -                                'mode' => $page['mode'],
  103 -                                'get' => $page['get'],
  104 -                                'post' => $page['post']);
   135+      if (isset($_SESSION['osC_NavigationHistory_snapshot']) === false) {
   136+        $_SESSION['osC_NavigationHistory_snapshot'] = $this->_snapshot;
   137+      }
   138+    }
   139+
   140+    function hasSnapshot() {
   141+      return !empty($this->_snapshot);
   142+    }
   143+
   144+    function getSnapshot($key) {
   145+      if (isset($this->_snapshot[$key])) {
   146+        return $this->_snapshot[$key];
   147+      }
   148+    }
   149+
   150+    function getSnapshotURL($auto_mode = false) {
   151+      if ($this->hasSnapshot()) {
   152+        $target = tep_href_link($this->_snapshot['page'], $this->_parseParameters($this->_snapshot['get']), ($auto_mode === true) ? 'AUTO' : $this->_snapshot['mode']);
105153       } else {
<> 106 -        $this->snapshot = array('page' => basename($_SERVER['PHP_SELF']),
  107 -                                'mode' => $request_type,
  108 -                                'get' => $_GET,
  109 -                                'post' => $_POST);
   154+        $target = tep_href_link(FILENAME_DEFAULT, '', ($auto_mode === true) ? 'AUTO' : $this->_snapshot['mode']);
110155       }
<>  156+
   157+      return $target;
111158     }
  112159 
<> 113 -    function clear_snapshot() {
  114 -      $this->snapshot = array();
   160+    function redirectToSnapshot() {
   161+      $target = $this->getSnapshotURL(true);
   162+
   163+      $this->resetSnapshot();
   164+
   165+      tep_redirect($target);
115166     }
  116167 
<> 117 -    function set_path_as_snapshot($history = 0) {
  118 -      $pos = (sizeof($this->path)-1-$history);
  119 -      $this->snapshot = array('page' => $this->path[$pos]['page'],
  120 -                              'mode' => $this->path[$pos]['mode'],
  121 -                              'get' => $this->path[$pos]['get'],
  122 -                              'post' => $this->path[$pos]['post']);
   168+    function resetPath() {
   169+      $this->_data = array();
   170+
   171+      if (isset($_SESSION['osC_NavigationHistory_data'])) {
   172+        unset($_SESSION['osC_NavigationHistory_data']);
   173+      }
123174     }
  124175 
<> 125 -    function setGlobal() {
  126 -      $this->set_global = (PHP_VERSION < 4.1) ? true : false;
   176+    function resetSnapshot() {
   177+      $this->_snapshot = array();
   178+
   179+      if (isset($_SESSION['osC_NavigationHistory_snapshot'])) {
   180+        unset($_SESSION['osC_NavigationHistory_snapshot']);
   181+      }
127182     }
  128183 
<> 129 -    function debug() {
   184+    function reset() {
   185+      $this->resetPath();
   186+      $this->resetSnapshot();
   187+    }
   188+
   189+    function _parseParameters($array, $additional_exclude = array()) {
130190       global $osC_Session;
  131191 
<> 132 -      for ($i=0, $n=sizeof($this->path); $i<$n; $i++) {
  133 -        echo $this->path[$i]['page'] . '?';
  134 -        while (list($key, $value) = each($this->path[$i]['get'])) {
  135 -          echo $key . '=' . $value . '&';
  136 -        }
  137 -        if (sizeof($this->path[$i]['post']) > 0) {
  138 -          echo '<br>';
  139 -          while (list($key, $value) = each($this->path[$i]['post'])) {
  140 -            echo '&nbsp;&nbsp;<b>' . $key . '=' . $value . '</b><br>';
  141 -          }
  142 -        }
  143 -        echo '<br>';
   192+      $exclude = array('x', 'y', $osC_Session->getName());
   193+
   194+      if (is_array($additional_exclude) && (empty($additional_exclude) === false)) {
   195+        $exclude = array_merge($exclude, $additional_exclude);
144196       }
  145197 
<> 146 -      if (sizeof($this->snapshot) > 0) {
  147 -        echo '<br><br>';
   198+      $string = '';
148199 
<> 149 -        echo $this->snapshot['mode'] . ' ' . $this->snapshot['page'] . '?' . tep_array_to_string($this->snapshot['get'], array($osC_Session->name)) . '<br>';
   200+      if (is_array($array) && (empty($array) === false)) {
   201+        foreach ($array as $key => $value) {
   202+          if (in_array($key, $exclude) === false) {
   203+            $string .= $key . '=' . $value . '&';
   204+          }
   205+        }
   206+
   207+        $string = substr($string, 0, -1);
150208       }
<>  209+
   210+      return $string;
<_ 151211     }
  152212   }
  153213 ?>