  |
1 | 1 | | <?php |
| |
2 | 2 | | /* |
  |
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 $ |
|
4 | 4 | | |
| |
5 | 5 | | osCommerce, Open Source E-Commerce Solutions |
| |
6 | 6 | | http://www.oscommerce.com |
| |
|
|
 |
… |
|
10 | 10 | | Released under the GNU General Public License |
| |
11 | 11 | | */ |
| |
12 | 12 | | |
  |
13 | | - | class navigationHistory { |
| |
14 | | - | var $path, $snapshot; |
| |
| 13 | + | class osC_NavigationHistory { |
|
15 | 14 | | |
  |
16 | | - | function navigationHistory() { |
| |
17 | | - | $this->reset(); |
| |
18 | | - | } |
| |
| 15 | + | /* Private variables */ |
|
19 | 16 | | |
  |
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 | + | } |
|
23 | 34 | | } |
| |
24 | 35 | | |
  |
25 | | - | function add_current_page() { |
| |
| 36 | + | /* Public methods */ |
| |
| 37 | + | |
| |
| 38 | + | function addCurrentPage() { |
|
26 | 39 | | global $request_type, $cPath; |
| |
27 | 40 | | |
| |
28 | 41 | | $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'])) { |
|
31 | 45 | | if (isset($cPath)) { |
  |
32 | | - | if (!isset($this->path[$i]['get']['cPath'])) { |
| |
| 46 | + | if (!isset($this->_data[$i]['get']['cPath'])) { |
|
33 | 47 | | continue; |
| |
34 | 48 | | } 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)); |
|
37 | 51 | | $set = 'false'; |
| |
38 | 52 | | break; |
| |
39 | 53 | | } else { |
  |
40 | | - | $old_cPath = explode('_', $this->path[$i]['get']['cPath']); |
| |
| 54 | + | $old_cPath = explode('_', $this->_data[$i]['get']['cPath']); |
|
41 | 55 | | $new_cPath = explode('_', $cPath); |
| |
42 | 56 | | |
| |
43 | 57 | | for ($j=0, $n2=sizeof($old_cPath); $j<$n2; $j++) { |
| |
44 | 58 | | if ($old_cPath[$j] != $new_cPath[$j]) { |
  |
45 | | - | array_splice($this->path, ($i)); |
| |
| 59 | + | array_splice($this->_data, ($i)); |
|
46 | 60 | | $set = 'true'; |
| |
47 | 61 | | break 2; |
| |
48 | 62 | | } |
| |
49 | 63 | | } |
| |
50 | 64 | | } |
| |
51 | 65 | | } |
| |
52 | 66 | | } else { |
  |
53 | | - | array_splice($this->path, $i); |
| |
| 67 | + | array_splice($this->_data, $i); |
|
54 | 68 | | $set = 'true'; |
| |
55 | 69 | | break; |
| |
56 | 70 | | } |
| |
57 | 71 | | } |
| |
58 | 72 | | } |
| |
59 | 73 | | |
| |
60 | 74 | | 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 | + | } |
|
65 | 83 | | } |
| |
66 | 84 | | } |
| |
67 | 85 | | |
  |
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 | + | } |
|
72 | 99 | | } |
| |
73 | 100 | | } |
| |
74 | 101 | | |
  |
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 = '') { |
|
76 | 121 | | global $request_type; |
| |
77 | 122 | | |
| |
78 | 123 | | 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']); |
|
83 | 128 | | } 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); |
|
88 | 133 | | } |
  |
| 134 | + | |
| |
| 135 | + | if (isset($_SESSION['osC_NavigationHistory_snapshot']) === false) { |
| |
| 136 | + | $_SESSION['osC_NavigationHistory_snapshot'] = $this->_snapshot; |
| |
| 137 | + | } |
|
89 | 138 | | } |
| |
90 | 139 | | |
  |
91 | | - | function clear_snapshot() { |
| |
92 | | - | $this->snapshot = array(); |
| |
| 140 | + | function hasSnapshot() { |
| |
| 141 | + | return !empty($this->_snapshot); |
|
93 | 142 | | } |
| |
94 | 143 | | |
  |
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 | + | } |
|
101 | 148 | | } |
| |
102 | 149 | | |
  |
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()) { |
|
104 | 190 | | global $osC_Session; |
| |
105 | 191 | | |
  |
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 ' <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); |
|
118 | 196 | | } |
| |
119 | 197 | | |
  |
120 | | - | if (sizeof($this->snapshot) > 0) { |
| |
121 | | - | echo '<br><br>'; |
| |
| 198 | + | $string = ''; |
|
122 | 199 | | |
  |
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); |
|
124 | 208 | | } |
  |
| 209 | + | |
| |
| 210 | + | return $string; |
  |
125 | 211 | | } |
| |
126 | 212 | | } |
| |
127 | 213 | | ?> |