  |
1 | 1 | | <?php |
| |
2 | 2 | | /* |
  |
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 $ |
|
4 | 4 | | |
| |
5 | 5 | | osCommerce, Open Source E-Commerce Solutions |
| |
6 | 6 | | http://www.oscommerce.com |
| |
7 | 7 | | |
  |
8 | | - | Copyright (c) 2003 osCommerce |
| |
| 8 | + | Copyright (c) 2005 osCommerce |
|
9 | 9 | | |
| |
10 | 10 | | Released under the GNU General Public License |
| |
11 | 11 | | */ |
| |
12 | 12 | | |
  |
13 | | - | class navigationHistory { |
| |
14 | | - | var $path, $snapshot, $set_global; |
| |
| 13 | + | class osC_NavigationHistory { |
|
15 | 14 | | |
  |
16 | | - | function navigationHistory() { |
| |
17 | | - | $this->reset(); |
| |
| 15 | + | /* Private variables */ |
|
18 | 16 | | |
  |
19 | | - | $this->setGlobal(); |
| |
20 | | - | } |
| |
| 17 | + | var $_data = array(), |
| |
| 18 | + | $_snapshot = array(); |
|
21 | 19 | | |
  |
22 | | - | function reset() { |
| |
23 | | - | $this->path = array(); |
| |
24 | | - | $this->snapshot = array(); |
| |
25 | | - | } |
| |
| 20 | + | /* Class constructor */ |
|
26 | 21 | | |
  |
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']; |
|
30 | 25 | | } |
| |
31 | 26 | | |
  |
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 | + | } |
|
33 | 30 | | |
  |
34 | | - | if ($this->set_global) { |
| |
35 | | - | global $_GET, $_POST; |
| |
| 31 | + | if ($add_current_page === true) { |
| |
| 32 | + | $this->addCurrentPage(); |
|
36 | 33 | | } |
  |
| 34 | + | } |
|
37 | 35 | | |
  |
| 36 | + | /* Public methods */ |
| |
| 37 | + | |
| |
| 38 | + | function addCurrentPage() { |
| |
| 39 | + | global $request_type, $cPath; |
| |
| 40 | + | |
|
38 | 41 | | $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'])) { |
|
41 | 45 | | if (isset($cPath)) { |
  |
42 | | - | if (!isset($this->path[$i]['get']['cPath'])) { |
| |
| 46 | + | if (!isset($this->_data[$i]['get']['cPath'])) { |
|
43 | 47 | | continue; |
| |
44 | 48 | | } 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)); |
|
47 | 51 | | $set = 'false'; |
| |
48 | 52 | | break; |
| |
49 | 53 | | } else { |
  |
50 | | - | $old_cPath = explode('_', $this->path[$i]['get']['cPath']); |
| |
| 54 | + | $old_cPath = explode('_', $this->_data[$i]['get']['cPath']); |
|
51 | 55 | | $new_cPath = explode('_', $cPath); |
| |
52 | 56 | | |
| |
53 | 57 | | for ($j=0, $n2=sizeof($old_cPath); $j<$n2; $j++) { |
| |
54 | 58 | | if ($old_cPath[$j] != $new_cPath[$j]) { |
  |
55 | | - | array_splice($this->path, ($i)); |
| |
| 59 | + | array_splice($this->_data, ($i)); |
|
56 | 60 | | $set = 'true'; |
| |
57 | 61 | | break 2; |
| |
58 | 62 | | } |
| |
59 | 63 | | } |
| |
60 | 64 | | } |
| |
61 | 65 | | } |
| |
62 | 66 | | } else { |
  |
63 | | - | array_splice($this->path, $i); |
| |
| 67 | + | array_splice($this->_data, $i); |
|
64 | 68 | | $set = 'true'; |
| |
65 | 69 | | break; |
| |
66 | 70 | | } |
| |
67 | 71 | | } |
| |
68 | 72 | | } |
| |
69 | 73 | | |
| |
70 | 74 | | 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 | + | } |
|
75 | 83 | | } |
| |
76 | 84 | | } |
| |
77 | 85 | | |
  |
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 | + | } |
|
81 | 99 | | } |
  |
| 100 | + | } |
|
82 | 101 | | |
  |
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; |
|
86 | 105 | | } |
  |
| 106 | + | |
| |
| 107 | + | return isset($this->_data[sizeof($this->_data) - $back]); |
|
87 | 108 | | } |
| |
88 | 109 | | |
  |
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; |
|
92 | 113 | | } |
| |
93 | 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 = '') { |
|
94 | 121 | | global $request_type; |
| |
95 | 122 | | |
  |
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); |
|
98 | 133 | | } |
| |
99 | 134 | | |
  |
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']); |
|
105 | 153 | | } 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']); |
|
110 | 155 | | } |
  |
| 156 | + | |
| |
| 157 | + | return $target; |
|
111 | 158 | | } |
| |
112 | 159 | | |
  |
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); |
|
115 | 166 | | } |
| |
116 | 167 | | |
  |
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 | + | } |
|
123 | 174 | | } |
| |
124 | 175 | | |
  |
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 | + | } |
|
127 | 182 | | } |
| |
128 | 183 | | |
  |
129 | | - | function debug() { |
| |
| 184 | + | function reset() { |
| |
| 185 | + | $this->resetPath(); |
| |
| 186 | + | $this->resetSnapshot(); |
| |
| 187 | + | } |
| |
| 188 | + | |
| |
| 189 | + | function _parseParameters($array, $additional_exclude = array()) { |
|
130 | 190 | | global $osC_Session; |
| |
131 | 191 | | |
  |
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 ' <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); |
|
144 | 196 | | } |
| |
145 | 197 | | |
  |
146 | | - | if (sizeof($this->snapshot) > 0) { |
| |
147 | | - | echo '<br><br>'; |
| |
| 198 | + | $string = ''; |
|
148 | 199 | | |
  |
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); |
|
150 | 208 | | } |
  |
| 209 | + | |
| |
| 210 | + | return $string; |
  |
151 | 211 | | } |
| |
152 | 212 | | } |
| |
153 | 213 | | ?> |