Quick Search:

View

Revision:

Diff

Diff from 203 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/osCommerce/branches/hpdl/oscommerce/includes/classes/navigation_history.php

Annotated File View

hpdl
1
1 <?php
2 /*
hpdl
153
3   $Id: navigation_history.php 203 2005-09-23 14:17:59Z hpdl $
hpdl
1
4
5   osCommerce, Open Source E-Commerce Solutions
6   http://www.oscommerce.com
7
hpdl
196
8   Copyright (c) 2005 osCommerce
hpdl
1
9
10   Released under the GNU General Public License
11 */
12
hpdl
203
13   class osC_NavigationHistory {
hpdl
1
14
hpdl
203
15 /* Private variables */
hpdl
1
16
hpdl
203
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       }
hpdl
1
34     }
35
hpdl
203
36 /* Public methods */
37
38     function addCurrentPage() {
hpdl
1
39       global $request_type, $cPath;
40
41       $set = 'true';
hpdl
203
42
43       for ($i=0, $n=sizeof($this->_data); $i<$n; $i++) {
44         if ($this->_data[$i]['page'] == basename($_SERVER['PHP_SELF'])) {
hpdl
1
45           if (isset($cPath)) {
hpdl
203
46             if (!isset($this->_data[$i]['get']['cPath'])) {
hpdl
1
47               continue;
48             } else {
hpdl
203
49               if ($this->_data[$i]['get']['cPath'] == $cPath) {
50                 array_splice($this->_data, ($i+1));
hpdl
1
51                 $set = 'false';
52                 break;
53               } else {
hpdl
203
54                 $old_cPath = explode('_', $this->_data[$i]['get']['cPath']);
hpdl
1
55                 $new_cPath = explode('_', $cPath);
56
57                 for ($j=0, $n2=sizeof($old_cPath); $j<$n2; $j++) {
58                   if ($old_cPath[$j] != $new_cPath[$j]) {
hpdl
203
59                     array_splice($this->_data, ($i));
hpdl
1
60                     $set = 'true';
61                     break 2;
62                   }
63                 }
64               }
65             }
66           } else {
hpdl
203
67             array_splice($this->_data, $i);
hpdl
1
68             $set = 'true';
69             break;
70           }
71         }
72       }
73
74       if ($set == 'true') {
hpdl
203
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         }
hpdl
1
83       }
84     }
85
hpdl
203
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         }
hpdl
1
99       }
100     }
101
hpdl
203
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 = '') {
hpdl
1
121       global $request_type;
122
123       if (is_array($page)) {
hpdl
203
124         $this->_snapshot = array('page' => $page['page'],
125                                  'mode' => $page['mode'],
126                                  'get' => $page['get'],
127                                  'post' => $page['post']);
hpdl
1
128       } else {
hpdl
203
129         $this->_snapshot = array('page' => basename($_SERVER['PHP_SELF']),
130                                  'mode' => $request_type,
131                                  'get' => $_GET,
132                                  'post' => $_POST);
hpdl
1
133       }
hpdl
203
134
135       if (isset($_SESSION['osC_NavigationHistory_snapshot']) === false) {
136         $_SESSION['osC_NavigationHistory_snapshot'] = $this->_snapshot;
137       }
hpdl
1
138     }
139
hpdl
203
140     function hasSnapshot() {
141       return !empty($this->_snapshot);
hpdl
1
142     }
143
hpdl
203
144     function getSnapshot($key) {
145       if (isset($this->_snapshot[$key])) {
146         return $this->_snapshot[$key];
147       }
hpdl
1
148     }
149
hpdl
203
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()) {
hpdl
1
190       global $osC_Session;
191
hpdl
203
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);
196       }
197
198       $string = '';
199
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 . '&';
hpdl
1
204           }
205         }
hpdl
203
206
207         $string = substr($string, 0, -1);
hpdl
1
208       }
209
hpdl
203
210       return $string;
hpdl
1
211     }
212   }
213 ?>