Quick Search:

View

Revision:

Diff

Diff from 1497 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 1497 2007-03-29 13:40:05Z 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
hpdl
1497
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
203
15   class osC_NavigationHistory {
hpdl
1
16
hpdl
203
17 /* Private variables */
hpdl
1
18
hpdl
203
19     var $_data = array(),
20         $_snapshot = array();
21
22 /* Class constructor */
23
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'];
27       }
28
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       }
32
33       if ($add_current_page === true) {
34         $this->addCurrentPage();
35       }
hpdl
1
36     }
37
hpdl
203
38 /* Public methods */
39
40     function addCurrentPage() {
hpdl
1
41       global $request_type, $cPath;
42
43       $set = 'true';
hpdl
203
44
45       for ($i=0, $n=sizeof($this->_data); $i<$n; $i++) {
hpdl
783
46         if ($this->_data[$i]['page'] == basename($_SERVER['SCRIPT_FILENAME'])) {
hpdl
1
47           if (isset($cPath)) {
hpdl
203
48             if (!isset($this->_data[$i]['get']['cPath'])) {
hpdl
1
49               continue;
50             } else {
hpdl
203
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
203
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
203
61                     array_splice($this->_data, ($i));
hpdl
1
62                     $set = 'true';
63                     break 2;
64                   }
65                 }
66               }
67             }
68           } else {
hpdl
203
69             array_splice($this->_data, $i);
hpdl
1
70             $set = 'true';
71             break;
72           }
73         }
74       }
75
76       if ($set == 'true') {
hpdl
783
77         $this->_data[] = array('page' => basename($_SERVER['SCRIPT_FILENAME']),
hpdl
203
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
203
88     function removeCurrentPage() {
89       $last_entry_position = sizeof($this->_data) - 1;
90
hpdl
783
91       if ($this->_data[$last_entry_position]['page'] == basename($_SERVER['SCRIPT_FILENAME'])) {
hpdl
203
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       }
102     }
103
hpdl
203
104     function hasPath($back = 1) {
105       if ( (is_numeric($back) === false) || (is_numeric($back) && ($back < 1)) ) {
106         $back = 1;
107       }
108
109       return isset($this->_data[sizeof($this->_data) - $back]);
110     }
111
112     function getPathURL($back = 1, $exclude = array()) {
113       if ( (is_numeric($back) === false) || (is_numeric($back) && ($back < 1)) ) {
114         $back = 1;
115       }
116
117       $back = sizeof($this->_data) - $back;
118
hpdl
686
119       return osc_href_link($this->_data[$back]['page'], $this->_parseParameters($this->_data[$back]['get'], $exclude), $this->_data[$back]['mode']);
hpdl
203
120     }
121
122     function setSnapshot($page = '') {
hpdl
1
123       global $request_type;
124
125       if (is_array($page)) {
hpdl
203
126         $this->_snapshot = array('page' => $page['page'],
127                                  'mode' => $page['mode'],
128                                  'get' => $page['get'],
129                                  'post' => $page['post']);
hpdl
1
130       } else {
hpdl
783
131         $this->_snapshot = array('page' => basename($_SERVER['SCRIPT_FILENAME']),
hpdl
203
132                                  'mode' => $request_type,
133                                  'get' => $_GET,
134                                  'post' => $_POST);
hpdl
1
135       }
hpdl
203
136
137       if (isset($_SESSION['osC_NavigationHistory_snapshot']) === false) {
138         $_SESSION['osC_NavigationHistory_snapshot'] = $this->_snapshot;
139       }
hpdl
1
140     }
141
hpdl
203
142     function hasSnapshot() {
143       return !empty($this->_snapshot);
hpdl
1
144     }
145
hpdl
203
146     function getSnapshot($key) {
147       if (isset($this->_snapshot[$key])) {
148         return $this->_snapshot[$key];
149       }
hpdl
1
150     }
151
hpdl
203
152     function getSnapshotURL($auto_mode = false) {
153       if ($this->hasSnapshot()) {
hpdl
686
154         $target = osc_href_link($this->_snapshot['page'], $this->_parseParameters($this->_snapshot['get']), ($auto_mode === true) ? 'AUTO' : $this->_snapshot['mode']);
hpdl
203
155       } else {
hpdl
686
156         $target = osc_href_link(FILENAME_DEFAULT, null, ($auto_mode === true) ? 'AUTO' : $this->_snapshot['mode']);
hpdl
203
157       }
158
159       return $target;
160     }
161
162     function redirectToSnapshot() {
163       $target = $this->getSnapshotURL(true);
164
165       $this->resetSnapshot();
166
hpdl
725
167       osc_redirect($target);
hpdl
203
168     }
169
170     function resetPath() {
171       $this->_data = array();
172
173       if (isset($_SESSION['osC_NavigationHistory_data'])) {
174         unset($_SESSION['osC_NavigationHistory_data']);
175       }
176     }
177
178     function resetSnapshot() {
179       $this->_snapshot = array();
180
181       if (isset($_SESSION['osC_NavigationHistory_snapshot'])) {
182         unset($_SESSION['osC_NavigationHistory_snapshot']);
183       }
184     }
185
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
203
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
203
208
209         $string = substr($string, 0, -1);
hpdl
1
210       }
211
hpdl
203
212       return $string;
hpdl
1
213     }
214   }
215 ?>