hpdl
|
1
|
1
|
<?php
|
|
2
|
/*
|
mattice
|
151
|
3
|
$Id: navigation_history.php 1498 2007-03-29 14:04:50Z hpdl $
|
hpdl
|
1
|
4
|
|
|
5
|
osCommerce, Open Source E-Commerce Solutions
|
|
6
|
http://www.oscommerce.com
|
|
7
|
|
hpdl
|
368
|
8
|
Copyright (c) 2005 osCommerce
|
hpdl
|
1
|
9
|
|
hpdl
|
1498
|
10
|
This program is free software; you can redistribute it and/or modify
|
|
11
|
it under the terms of the GNU General Public License v2 (1991)
|
|
12
|
as published by the Free Software Foundation.
|
hpdl
|
1
|
13
|
*/
|
|
14
|
|
hpdl
|
368
|
15
|
class osC_NavigationHistory {
|
hpdl
|
1
|
16
|
|
hpdl
|
368
|
17
|
/* Private variables */
|
hpdl
|
1
|
18
|
|
hpdl
|
368
|
19
|
var $_data = array(),
|
|
20
|
$_snapshot = array();
|
hpdl
|
1
|
21
|
|
hpdl
|
368
|
22
|
/* Class constructor */
|
hpdl
|
1
|
23
|
|
hpdl
|
368
|
24
|
function osC_NavigationHistory($add_current_page = false) {
|
|
25
|
if (isset($_SESSION['osC_NavigationHistory_data']) && is_array($_SESSION['osC_NavigationHistory_data']) && (empty($_SESSION['osC_NavigationHistory_data']) === false)) {
|
|
26
|
$this->_data =& $_SESSION['osC_NavigationHistory_data'];
|
hpdl
|
1
|
27
|
}
|
|
28
|
|
hpdl
|
368
|
29
|
if (isset($_SESSION['osC_NavigationHistory_snapshot']) && is_array($_SESSION['osC_NavigationHistory_snapshot']) && (empty($_SESSION['osC_NavigationHistory_snapshot']) === false)) {
|
|
30
|
$this->_snapshot =& $_SESSION['osC_NavigationHistory_snapshot'];
|
|
31
|
}
|
hpdl
|
1
|
32
|
|
hpdl
|
368
|
33
|
if ($add_current_page === true) {
|
|
34
|
$this->addCurrentPage();
|
hpdl
|
1
|
35
|
}
|
hpdl
|
368
|
36
|
}
|
hpdl
|
1
|
37
|
|
hpdl
|
368
|
38
|
/* Public methods */
|
|
39
|
|
|
40
|
function addCurrentPage() {
|
|
41
|
global $request_type, $cPath;
|
|
42
|
|
hpdl
|
1
|
43
|
$set = 'true';
|
hpdl
|
368
|
44
|
|
|
45
|
for ($i=0, $n=sizeof($this->_data); $i<$n; $i++) {
|
hpdl
|
784
|
46
|
if ($this->_data[$i]['page'] == basename($_SERVER['SCRIPT_FILENAME'])) {
|
hpdl
|
1
|
47
|
if (isset($cPath)) {
|
hpdl
|
368
|
48
|
if (!isset($this->_data[$i]['get']['cPath'])) {
|
hpdl
|
1
|
49
|
continue;
|
|
50
|
} else {
|
hpdl
|
368
|
51
|
if ($this->_data[$i]['get']['cPath'] == $cPath) {
|
|
52
|
array_splice($this->_data, ($i+1));
|
hpdl
|
1
|
53
|
$set = 'false';
|
|
54
|
break;
|
|
55
|
} else {
|
hpdl
|
368
|
56
|
$old_cPath = explode('_', $this->_data[$i]['get']['cPath']);
|
hpdl
|
1
|
57
|
$new_cPath = explode('_', $cPath);
|
|
58
|
|
|
59
|
for ($j=0, $n2=sizeof($old_cPath); $j<$n2; $j++) {
|
|
60
|
if ($old_cPath[$j] != $new_cPath[$j]) {
|
hpdl
|
368
|
61
|
array_splice($this->_data, ($i));
|
hpdl
|
1
|
62
|
$set = 'true';
|
|
63
|
break 2;
|
|
64
|
}
|
|
65
|
}
|
|
66
|
}
|
|
67
|
}
|
|
68
|
} else {
|
hpdl
|
368
|
69
|
array_splice($this->_data, $i);
|
hpdl
|
1
|
70
|
$set = 'true';
|
|
71
|
break;
|
|
72
|
}
|
|
73
|
}
|
|
74
|
}
|
|
75
|
|
|
76
|
if ($set == 'true') {
|
hpdl
|
784
|
77
|
$this->_data[] = array('page' => basename($_SERVER['SCRIPT_FILENAME']),
|
hpdl
|
368
|
78
|
'mode' => $request_type,
|
|
79
|
'get' => $_GET,
|
|
80
|
'post' => $_POST);
|
|
81
|
|
|
82
|
if (isset($_SESSION['osC_NavigationHistory_data']) === false) {
|
|
83
|
$_SESSION['osC_NavigationHistory_data'] = $this->_data;
|
|
84
|
}
|
hpdl
|
1
|
85
|
}
|
|
86
|
}
|
|
87
|
|
hpdl
|
368
|
88
|
function removeCurrentPage() {
|
|
89
|
$last_entry_position = sizeof($this->_data) - 1;
|
|
90
|
|
hpdl
|
784
|
91
|
if ($this->_data[$last_entry_position]['page'] == basename($_SERVER['SCRIPT_FILENAME'])) {
|
hpdl
|
368
|
92
|
unset($this->_data[$last_entry_position]);
|
|
93
|
|
|
94
|
if (sizeof($this->_data) > 0) {
|
|
95
|
if (isset($_SESSION['osC_NavigationHistory_data']) === false) {
|
|
96
|
$_SESSION['osC_NavigationHistory_data'] = $this->_data;
|
|
97
|
}
|
|
98
|
} else {
|
|
99
|
$this->resetPath();
|
|
100
|
}
|
hpdl
|
1
|
101
|
}
|
hpdl
|
368
|
102
|
}
|
hpdl
|
1
|
103
|
|
hpdl
|
368
|
104
|
function hasPath($back = 1) {
|
|
105
|
if ( (is_numeric($back) === false) || (is_numeric($back) && ($back < 1)) ) {
|
|
106
|
$back = 1;
|
hpdl
|
1
|
107
|
}
|
hpdl
|
368
|
108
|
|
|
109
|
return isset($this->_data[sizeof($this->_data) - $back]);
|
hpdl
|
1
|
110
|
}
|
|
111
|
|
hpdl
|
368
|
112
|
function getPathURL($back = 1, $exclude = array()) {
|
|
113
|
if ( (is_numeric($back) === false) || (is_numeric($back) && ($back < 1)) ) {
|
|
114
|
$back = 1;
|
hpdl
|
1
|
115
|
}
|
|
116
|
|
hpdl
|
368
|
117
|
$back = sizeof($this->_data) - $back;
|
|
118
|
|
hpdl
|
754
|
119
|
return osc_href_link($this->_data[$back]['page'], $this->_parseParameters($this->_data[$back]['get'], $exclude), $this->_data[$back]['mode']);
|
hpdl
|
368
|
120
|
}
|
|
121
|
|
|
122
|
function setSnapshot($page = '') {
|
hpdl
|
1
|
123
|
global $request_type;
|
|
124
|
|
hpdl
|
368
|
125
|
if (is_array($page)) {
|
|
126
|
$this->_snapshot = array('page' => $page['page'],
|
|
127
|
'mode' => $page['mode'],
|
|
128
|
'get' => $page['get'],
|
|
129
|
'post' => $page['post']);
|
|
130
|
} else {
|
hpdl
|
784
|
131
|
$this->_snapshot = array('page' => basename($_SERVER['SCRIPT_FILENAME']),
|
hpdl
|
368
|
132
|
'mode' => $request_type,
|
|
133
|
'get' => $_GET,
|
|
134
|
'post' => $_POST);
|
hpdl
|
1
|
135
|
}
|
|
136
|
|
hpdl
|
368
|
137
|
if (isset($_SESSION['osC_NavigationHistory_snapshot']) === false) {
|
|
138
|
$_SESSION['osC_NavigationHistory_snapshot'] = $this->_snapshot;
|
|
139
|
}
|
|
140
|
}
|
|
141
|
|
|
142
|
function hasSnapshot() {
|
|
143
|
return !empty($this->_snapshot);
|
|
144
|
}
|
|
145
|
|
|
146
|
function getSnapshot($key) {
|
|
147
|
if (isset($this->_snapshot[$key])) {
|
|
148
|
return $this->_snapshot[$key];
|
|
149
|
}
|
|
150
|
}
|
|
151
|
|
|
152
|
function getSnapshotURL($auto_mode = false) {
|
|
153
|
if ($this->hasSnapshot()) {
|
hpdl
|
754
|
154
|
$target = osc_href_link($this->_snapshot['page'], $this->_parseParameters($this->_snapshot['get']), ($auto_mode === true) ? 'AUTO' : $this->_snapshot['mode']);
|
hpdl
|
1
|
155
|
} else {
|
hpdl
|
754
|
156
|
$target = osc_href_link(FILENAME_DEFAULT, null, ($auto_mode === true) ? 'AUTO' : $this->_snapshot['mode']);
|
hpdl
|
1
|
157
|
}
|
hpdl
|
368
|
158
|
|
|
159
|
return $target;
|
hpdl
|
1
|
160
|
}
|
|
161
|
|
hpdl
|
368
|
162
|
function redirectToSnapshot() {
|
|
163
|
$target = $this->getSnapshotURL(true);
|
|
164
|
|
|
165
|
$this->resetSnapshot();
|
|
166
|
|
hpdl
|
757
|
167
|
osc_redirect($target);
|
hpdl
|
1
|
168
|
}
|
|
169
|
|
hpdl
|
368
|
170
|
function resetPath() {
|
|
171
|
$this->_data = array();
|
|
172
|
|
|
173
|
if (isset($_SESSION['osC_NavigationHistory_data'])) {
|
|
174
|
unset($_SESSION['osC_NavigationHistory_data']);
|
|
175
|
}
|
hpdl
|
1
|
176
|
}
|
|
177
|
|
hpdl
|
368
|
178
|
function resetSnapshot() {
|
|
179
|
$this->_snapshot = array();
|
|
180
|
|
|
181
|
if (isset($_SESSION['osC_NavigationHistory_snapshot'])) {
|
|
182
|
unset($_SESSION['osC_NavigationHistory_snapshot']);
|
|
183
|
}
|
hpdl
|
1
|
184
|
}
|
|
185
|
|
hpdl
|
368
|
186
|
function reset() {
|
|
187
|
$this->resetPath();
|
|
188
|
$this->resetSnapshot();
|
|
189
|
}
|
|
190
|
|
|
191
|
function _parseParameters($array, $additional_exclude = array()) {
|
hpdl
|
1
|
192
|
global $osC_Session;
|
|
193
|
|
hpdl
|
368
|
194
|
$exclude = array('x', 'y', $osC_Session->getName());
|
|
195
|
|
|
196
|
if (is_array($additional_exclude) && (empty($additional_exclude) === false)) {
|
|
197
|
$exclude = array_merge($exclude, $additional_exclude);
|
|
198
|
}
|
|
199
|
|
|
200
|
$string = '';
|
|
201
|
|
|
202
|
if (is_array($array) && (empty($array) === false)) {
|
|
203
|
foreach ($array as $key => $value) {
|
|
204
|
if (in_array($key, $exclude) === false) {
|
|
205
|
$string .= $key . '=' . $value . '&';
|
hpdl
|
1
|
206
|
}
|
|
207
|
}
|
hpdl
|
368
|
208
|
|
|
209
|
$string = substr($string, 0, -1);
|
hpdl
|
1
|
210
|
}
|
|
211
|
|
hpdl
|
368
|
212
|
return $string;
|
hpdl
|
1
|
213
|
}
|
|
214
|
}
|
|
215
|
?>
|