Quick Search:

Mode

Context

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

Other Diffs

Ignore

Blank Lines Whitespace:

Diff

199
 
203
 
203
 
navigation_history.php
_> 11 <?php
  22 /*
<> 3 -  $Id: navigation_history.php 199 2005-09-22 15:56:13Z hpdl $
   3+  $Id: navigation_history.php 203 2005-09-23 14:17:59Z hpdl $
44 
  55   osCommerce, Open Source E-Commerce Solutions
  66   http://www.oscommerce.com
     
 !
1010   Released under the GNU General Public License
  1111 */
  1212 
<> 13 -  class navigationHistory {
  14 -    var $path, $snapshot;
   13+  class osC_NavigationHistory {
1514 
<> 16 -    function navigationHistory() {
  17 -      $this->reset();
  18 -    }
   15+/* Private variables */
1916 
<> 20 -    function reset() {
  21 -      $this->path = array();
  22 -      $this->snapshot = array();
   17+    var $_data = array(),
   18+        $_snapshot = array();
   19+
   20+/* Class constructor */
   21+
   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'];
   25+      }
   26+
   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+      }
   30+
   31+      if ($add_current_page === true) {
   32+        $this->addCurrentPage();
   33+      }
2334     }
  2435 
<> 25 -    function add_current_page() {
   36+/* Public methods */
   37+
   38+    function addCurrentPage() {
2639       global $request_type, $cPath;
  2740 
  2841       $set = 'true';
<> 29 -      for ($i=0, $n=sizeof($this->path); $i<$n; $i++) {
  30 -        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'])) {
3145           if (isset($cPath)) {
<> 32 -            if (!isset($this->path[$i]['get']['cPath'])) {
   46+            if (!isset($this->_data[$i]['get']['cPath'])) {
3347               continue;
  3448             } else {
<> 35 -              if ($this->path[$i]['get']['cPath'] == $cPath) {
  36 -                array_splice($this->path, ($i+1));
   49+              if ($this->_data[$i]['get']['cPath'] == $cPath) {
   50+                array_splice($this->_data, ($i+1));
3751                 $set = 'false';
  3852                 break;
  3953               } else {
<> 40 -                $old_cPath = explode('_', $this->path[$i]['get']['cPath']);
   54+                $old_cPath = explode('_', $this->_data[$i]['get']['cPath']);
4155                 $new_cPath = explode('_', $cPath);
  4256 
  4357                 for ($j=0, $n2=sizeof($old_cPath); $j<$n2; $j++) {
  4458                   if ($old_cPath[$j] != $new_cPath[$j]) {
<> 45 -                    array_splice($this->path, ($i));
   59+                    array_splice($this->_data, ($i));
4660                     $set = 'true';
  4761                     break 2;
  4862                   }
  4963                 }
  5064               }
  5165             }
  5266           } else {
<> 53 -            array_splice($this->path, $i);
   67+            array_splice($this->_data, $i);
5468             $set = 'true';
  5569             break;
  5670           }
  5771         }
  5872       }
  5973 
  6074       if ($set == 'true') {
<> 61 -        $this->path[] = array('page' => basename($_SERVER['PHP_SELF']),
  62 -                              'mode' => $request_type,
  63 -                              'get' => $_GET,
  64 -                              '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+        }
6583       }
  6684     }
  6785 
<> 68 -    function remove_current_page() {
  69 -      $last_entry_position = sizeof($this->path) - 1;
  70 -      if ($this->path[$last_entry_position]['page'] == basename($_SERVER['PHP_SELF'])) {
  71 -        unset($this->path[$last_entry_position]);
   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+        }
7299       }
  73100     }
  74101 
<> 75 -    function set_snapshot($page = '') {
   102+    function hasPath($back = 1) {
   103+      if ( (is_numeric($back) === false) || (is_numeric($back) && ($back < 1)) ) {
   104+        $back = 1;
   105+      }
   106+
   107+      return isset($this->_data[sizeof($this->_data) - $back]);
   108+    }
   109+
   110+    function getPathURL($back = 1, $exclude = array()) {
   111+      if ( (is_numeric($back) === false) || (is_numeric($back) && ($back < 1)) ) {
   112+        $back = 1;
   113+      }
   114+
   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 = '') {
76121       global $request_type;
  77122 
  78123       if (is_array($page)) {
<> 79 -        $this->snapshot = array('page' => $page['page'],
  80 -                                'mode' => $page['mode'],
  81 -                                'get' => $page['get'],
  82 -                                'post' => $page['post']);
   124+        $this->_snapshot = array('page' => $page['page'],
   125+                                 'mode' => $page['mode'],
   126+                                 'get' => $page['get'],
   127+                                 'post' => $page['post']);
83128       } else {
<> 84 -        $this->snapshot = array('page' => basename($_SERVER['PHP_SELF']),
  85 -                                'mode' => $request_type,
  86 -                                'get' => $_GET,
  87 -                                'post' => $_POST);
   129+        $this->_snapshot = array('page' => basename($_SERVER['PHP_SELF']),
   130+                                 'mode' => $request_type,
   131+                                 'get' => $_GET,
   132+                                 'post' => $_POST);
88133       }
<>  134+
   135+      if (isset($_SESSION['osC_NavigationHistory_snapshot']) === false) {
   136+        $_SESSION['osC_NavigationHistory_snapshot'] = $this->_snapshot;
   137+      }
89138     }
  90139 
<> 91 -    function clear_snapshot() {
  92 -      $this->snapshot = array();
   140+    function hasSnapshot() {
   141+      return !empty($this->_snapshot);
93142     }
  94143 
<> 95 -    function set_path_as_snapshot($history = 0) {
  96 -      $pos = (sizeof($this->path)-1-$history);
  97 -      $this->snapshot = array('page' => $this->path[$pos]['page'],
  98 -                              'mode' => $this->path[$pos]['mode'],
  99 -                              'get' => $this->path[$pos]['get'],
  100 -                              'post' => $this->path[$pos]['post']);
   144+    function getSnapshot($key) {
   145+      if (isset($this->_snapshot[$key])) {
   146+        return $this->_snapshot[$key];
   147+      }
101148     }
  102149 
<> 103 -    function debug() {
   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']);
   153+      } else {
   154+        $target = tep_href_link(FILENAME_DEFAULT, '', ($auto_mode === true) ? 'AUTO' : $this->_snapshot['mode']);
   155+      }
   156+
   157+      return $target;
   158+    }
   159+
   160+    function redirectToSnapshot() {
   161+      $target = $this->getSnapshotURL(true);
   162+
   163+      $this->resetSnapshot();
   164+
   165+      tep_redirect($target);
   166+    }
   167+
   168+    function resetPath() {
   169+      $this->_data = array();
   170+
   171+      if (isset($_SESSION['osC_NavigationHistory_data'])) {
   172+        unset($_SESSION['osC_NavigationHistory_data']);
   173+      }
   174+    }
   175+
   176+    function resetSnapshot() {
   177+      $this->_snapshot = array();
   178+
   179+      if (isset($_SESSION['osC_NavigationHistory_snapshot'])) {
   180+        unset($_SESSION['osC_NavigationHistory_snapshot']);
   181+      }
   182+    }
   183+
   184+    function reset() {
   185+      $this->resetPath();
   186+      $this->resetSnapshot();
   187+    }
   188+
   189+    function _parseParameters($array, $additional_exclude = array()) {
104190       global $osC_Session;
  105191 
<> 106 -      for ($i=0, $n=sizeof($this->path); $i<$n; $i++) {
  107 -        echo $this->path[$i]['page'] . '?';
  108 -        while (list($key, $value) = each($this->path[$i]['get'])) {
  109 -          echo $key . '=' . $value . '&';
  110 -        }
  111 -        if (sizeof($this->path[$i]['post']) > 0) {
  112 -          echo '<br>';
  113 -          while (list($key, $value) = each($this->path[$i]['post'])) {
  114 -            echo '&nbsp;&nbsp;<b>' . $key . '=' . $value . '</b><br>';
  115 -          }
  116 -        }
  117 -        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);
118196       }
  119197 
<> 120 -      if (sizeof($this->snapshot) > 0) {
  121 -        echo '<br><br>';
   198+      $string = '';
122199 
<> 123 -        echo $this->snapshot['mode'] . ' ' . $this->snapshot['page'] . '?' . tep_array_to_string($this->snapshot['get'], array($osC_Session->getName())) . '<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);
124208       }
<>  209+
   210+      return $string;
<_ 125211     }
  126212   }
  127213 ?>