    |
| 1 | + | <?php |
| |
| 2 | + | /* |
| |
| 3 | + | $Id: $ |
| |
| 4 | + | osCommerce, Open Source E-Commerce Solutions |
| |
| 5 | + | http://www.oscommerce.com |
| |
| 6 | + | |
| |
| 7 | + | Copyright (c) 2005 osCommerce |
| |
| 8 | + | |
| |
| 9 | + | Released under the GNU General Public License |
| |
| 10 | + | */ |
| |
| 11 | + | |
| |
| 12 | + | class osC_RecentlyVisited { |
| |
| 13 | + | var $visits = array(); |
| |
| 14 | + | |
| |
| 15 | + | /* Class constructor */ |
| |
| 16 | + | |
| |
| 17 | + | function osC_RecentlyVisited() { |
| |
| 18 | + | if (isset($_SESSION['osC_RecentlyVisited_data']) === false) { |
| |
| 19 | + | $_SESSION['osC_RecentlyVisited_data'] = array(); |
| |
| 20 | + | } |
| |
| 21 | + | |
| |
| 22 | + | $this->visits =& $_SESSION['osC_RecentlyVisited_data']; |
| |
| 23 | + | } |
| |
| 24 | + | |
| |
| 25 | + | function initialize() { |
| |
| 26 | + | global $osC_Product, $osC_Category, $osC_Search; |
| |
| 27 | + | |
| |
| 28 | + | if (SERVICE_RECENTLY_VISITED_SHOW_PRODUCTS == 'True') { |
| |
| 29 | + | if (isset($osC_Product) && is_a($osC_Product, 'osC_Product')) { |
| |
| 30 | + | $this->setProduct($osC_Product->getID()); |
| |
| 31 | + | } |
| |
| 32 | + | } |
| |
| 33 | + | |
| |
| 34 | + | if (SERVICE_RECENTLY_VISITED_SHOW_CATEGORIES == 'True') { |
| |
| 35 | + | if (isset($osC_Category) && is_a($osC_Category, 'osC_Category')) { |
| |
| 36 | + | $this->setCategory($osC_Category->getID()); |
| |
| 37 | + | } |
| |
| 38 | + | } |
| |
| 39 | + | |
| |
| 40 | + | if (SERVICE_RECENTLY_VISITED_SHOW_SEARCHES == 'True') { |
| |
| 41 | + | if (isset($osC_Search) && is_a($osC_Search, 'osC_Search')) { |
| |
| 42 | + | if ($osC_Search->hasKeywords()) { |
| |
| 43 | + | $this->setSearchQuery($osC_Search->getKeywords()); |
| |
| 44 | + | } |
| |
| 45 | + | } |
| |
| 46 | + | } |
| |
| 47 | + | } |
| |
| 48 | + | |
| |
| 49 | + | function setProduct($id) { |
| |
| 50 | + | if (isset($this->visits['products'])) { |
| |
| 51 | + | foreach ($this->visits['products'] as $key => $value) { |
| |
| 52 | + | if ($value['id'] == $id) { |
| |
| 53 | + | unset($this->visits['products'][$key]); |
| |
| 54 | + | break; |
| |
| 55 | + | } |
| |
| 56 | + | } |
| |
| 57 | + | |
| |
| 58 | + | if (sizeof($this->visits['products']) > (SERVICE_RECENTLY_VISITED_MAX_PRODUCTS * 2)) { |
| |
| 59 | + | array_pop($this->visits['products']); |
| |
| 60 | + | } |
| |
| 61 | + | } else { |
| |
| 62 | + | $this->visits['products'] = array(); |
| |
| 63 | + | } |
| |
| 64 | + | |
| |
| 65 | + | array_unshift($this->visits['products'], array('id' => $id)); |
| |
| 66 | + | } |
| |
| 67 | + | |
| |
| 68 | + | function setCategory($id) { |
| |
| 69 | + | if (isset($this->visits['categories'])) { |
| |
| 70 | + | foreach ($this->visits['categories'] as $key => $value) { |
| |
| 71 | + | if ($value['id'] == $id) { |
| |
| 72 | + | unset($this->visits['categories'][$key]); |
| |
| 73 | + | break; |
| |
| 74 | + | } |
| |
| 75 | + | } |
| |
| 76 | + | |
| |
| 77 | + | if (sizeof($this->visits['categories']) > (SERVICE_RECENTLY_VISITED_MAX_CATEGORIES * 2)) { |
| |
| 78 | + | array_pop($this->visits['categories']); |
| |
| 79 | + | } |
| |
| 80 | + | } else { |
| |
| 81 | + | $this->visits['categories'] = array(); |
| |
| 82 | + | } |
| |
| 83 | + | |
| |
| 84 | + | array_unshift($this->visits['categories'], array('id' => $id)); |
| |
| 85 | + | } |
| |
| 86 | + | |
| |
| 87 | + | function setSearchQuery($keywords) { |
| |
| 88 | + | global $osC_Search; |
| |
| 89 | + | |
| |
| 90 | + | if (isset($this->visits['searches'])) { |
| |
| 91 | + | foreach ($this->visits['searches'] as $key => $value) { |
| |
| 92 | + | if ($value['keywords'] == $keywords) { |
| |
| 93 | + | unset($this->visits['searches'][$key]); |
| |
| 94 | + | break; |
| |
| 95 | + | } |
| |
| 96 | + | } |
| |
| 97 | + | |
| |
| 98 | + | if (sizeof($this->visits['searches']) > (SERVICE_RECENTLY_VISITED_MAX_SEARCHES * 2)) { |
| |
| 99 | + | array_pop($this->visits['searches']); |
| |
| 100 | + | } |
| |
| 101 | + | } else { |
| |
| 102 | + | $this->visits['searches'] = array(); |
| |
| 103 | + | } |
| |
| 104 | + | |
| |
| 105 | + | array_unshift($this->visits['searches'], array('keywords' => $keywords, |
| |
| 106 | + | 'results' => $osC_Search->getNumberOfResults() |
| |
| 107 | + | )); |
| |
| 108 | + | } |
| |
| 109 | + | |
| |
| 110 | + | function hasHistory() { |
| |
| 111 | + | if ($this->hasProducts() || $this->hasCategories() || $this->hasSearches()) { |
| |
| 112 | + | return true; |
| |
| 113 | + | } |
| |
| 114 | + | |
| |
| 115 | + | return false; |
| |
| 116 | + | } |
| |
| 117 | + | |
| |
| 118 | + | function hasProducts() { |
| |
| 119 | + | if (isset($this->visits['products']) && (empty($this->visits['products']) === false)) { |
| |
| 120 | + | return true; |
| |
| 121 | + | } |
| |
| 122 | + | |
| |
| 123 | + | return false; |
| |
| 124 | + | } |
| |
| 125 | + | |
| |
| 126 | + | function getProducts() { |
| |
| 127 | + | $history = array(); |
| |
| 128 | + | |
| |
| 129 | + | if (isset($this->visits['products']) && (empty($this->visits['products']) === false)) { |
| |
| 130 | + | $counter = 0; |
| |
| 131 | + | |
| |
| 132 | + | foreach ($this->visits['products'] as $k => $v) { |
| |
| 133 | + | $counter++; |
| |
| 134 | + | |
| |
| 135 | + | $osC_Product = new osC_Product($v['id']); |
| |
| 136 | + | $osC_Category = new osC_Category($osC_Product->getCategoryID()); |
| |
| 137 | + | |
| |
| 138 | + | $history[] = array('name' => $osC_Product->getTitle(), |
| |
| 139 | + | 'id' => $osC_Product->getID(), |
| |
| 140 | + | 'keyword' => $osC_Product->getKeyword(), |
| |
| 141 | + | 'price' => (SERVICE_RECENTLY_VISITED_SHOW_PRODUCT_PRICES == 'True') ? $osC_Product->getPriceFormated(true) : '', |
| |
| 142 | + | 'image' => $osC_Product->getImage(), |
| |
| 143 | + | 'category_name' => $osC_Category->getTitle(), |
| |
| 144 | + | 'category_path' => $osC_Category->getPath() |
| |
| 145 | + | ); |
| |
| 146 | + | |
| |
| 147 | + | if ($counter == SERVICE_RECENTLY_VISITED_MAX_PRODUCTS) { |
| |
| 148 | + | break; |
| |
| 149 | + | } |
| |
| 150 | + | } |
| |
| 151 | + | } |
| |
| 152 | + | |
| |
| 153 | + | return $history; |
| |
| 154 | + | } |
| |
| 155 | + | |
| |
| 156 | + | function hasCategories() { |
| |
| 157 | + | if (isset($this->visits['categories']) && (empty($this->visits['categories']) === false)) { |
| |
| 158 | + | return true; |
| |
| 159 | + | } |
| |
| 160 | + | |
| |
| 161 | + | return false; |
| |
| 162 | + | } |
| |
| 163 | + | |
| |
| 164 | + | function getCategories() { |
| |
| 165 | + | $history = array(); |
| |
| 166 | + | |
| |
| 167 | + | if (isset($this->visits['categories']) && (empty($this->visits['categories']) === false)) { |
| |
| 168 | + | $counter = 0; |
| |
| 169 | + | |
| |
| 170 | + | foreach ($this->visits['categories'] as $k => $v) { |
| |
| 171 | + | $counter++; |
| |
| 172 | + | |
| |
| 173 | + | $osC_Category = new osC_Category($v['id']); |
| |
| 174 | + | |
| |
| 175 | + | if ($osC_Category->hasParent()) { |
| |
| 176 | + | $osC_CategoryParent = new osC_Category($osC_Category->getParent()); |
| |
| 177 | + | } |
| |
| 178 | + | |
| |
| 179 | + | $history[] = array('id' => $osC_Category->getID(), |
| |
| 180 | + | 'name' => $osC_Category->getTitle(), |
| |
| 181 | + | 'path' => $osC_Category->getPath(), |
| |
| 182 | + | 'image' => $osC_Category->getImage(), |
| |
| 183 | + | 'parent_name' => ($osC_Category->hasParent()) ? $osC_CategoryParent->getTitle() : '', |
| |
| 184 | + | 'parent_id' => ($osC_Category->hasParent()) ? $osC_CategoryParent->getID() : '' |
| |
| 185 | + | ); |
| |
| 186 | + | |
| |
| 187 | + | if ($counter == SERVICE_RECENTLY_VISITED_MAX_CATEGORIES) { |
| |
| 188 | + | break; |
| |
| 189 | + | } |
| |
| 190 | + | } |
| |
| 191 | + | } |
| |
| 192 | + | |
| |
| 193 | + | return $history; |
| |
| 194 | + | } |
| |
| 195 | + | |
| |
| 196 | + | function hasSearches() { |
| |
| 197 | + | if (isset($this->visits['searches']) && (empty($this->visits['searches']) === false)) { |
| |
| 198 | + | return true; |
| |
| 199 | + | } |
| |
| 200 | + | |
| |
| 201 | + | return false; |
| |
| 202 | + | } |
| |
| 203 | + | |
| |
| 204 | + | function getSearches() { |
| |
| 205 | + | $history = array(); |
| |
| 206 | + | |
| |
| 207 | + | if (isset($this->visits['searches']) && (empty($this->visits['searches']) === false)) { |
| |
| 208 | + | $counter = 0; |
| |
| 209 | + | |
| |
| 210 | + | foreach ($this->visits['searches'] as $k => $v) { |
| |
| 211 | + | $counter++; |
| |
| 212 | + | |
| |
| 213 | + | $history[] = array('keywords' => $this->visits['searches'][$k]['keywords'], |
| |
| 214 | + | 'results' => $this->visits['searches'][$k]['results'] |
| |
| 215 | + | ); |
| |
| 216 | + | |
| |
| 217 | + | if ($counter == SERVICE_RECENTLY_VISITED_MAX_SEARCHES) { |
| |
| 218 | + | break; |
| |
| 219 | + | } |
| |
| 220 | + | } |
| |
| 221 | + | } |
| |
| 222 | + | |
| |
| 223 | + | return $history; |
| |
| 224 | + | } |
| |
| 225 | + | } |
| |
| 226 | + | ?> |