  |
1 | 1 | | <?php |
| |
2 | 2 | | /* |
  |
3 | | - | $Id: breadcrumb.php 1497 2007-03-29 13:40:05Z hpdl $ |
| |
| 3 | + | $Id: breadcrumb.php 1670 2007-07-20 21:11:18Z hpdl $ |
|
4 | 4 | | |
| |
5 | 5 | | osCommerce, Open Source E-Commerce Solutions |
| |
6 | 6 | | http://www.oscommerce.com |
| |
7 | 7 | | |
  |
8 | | - | Copyright (c) 2006 osCommerce |
| |
| 8 | + | Copyright (c) 2007 osCommerce |
|
9 | 9 | | |
| |
10 | 10 | | This program is free software; you can redistribute it and/or modify |
| |
11 | 11 | | it under the terms of the GNU General Public License v2 (1991) |
| |
12 | 12 | | as published by the Free Software Foundation. |
| |
13 | 13 | | */ |
| |
14 | 14 | | |
  |
15 | | - | class breadcrumb { |
| |
16 | | - | var $_trail; |
| |
| 15 | + | /** |
| |
| 16 | + | * The osC_Breadcrumb class handles the breadcrumb navigation path |
| |
| 17 | + | */ |
|
17 | 18 | | |
  |
18 | | - | function breadcrumb() { |
| |
19 | | - | $this->reset(); |
| |
20 | | - | } |
| |
| 19 | + | class osC_Breadcrumb { |
|
21 | 20 | | |
  |
22 | | - | function reset() { |
| |
23 | | - | $this->_trail = array(); |
| |
| 21 | + | /** |
| |
| 22 | + | * An array containing the breadcrumb navigation path |
| |
| 23 | + | * |
| |
| 24 | + | * @var array |
| |
| 25 | + | * @access private |
| |
| 26 | + | */ |
| |
| 27 | + | |
| |
| 28 | + | private $_path = array(); |
| |
| 29 | + | |
| |
| 30 | + | /** |
| |
| 31 | + | * Resets the breadcrumb navigation path |
| |
| 32 | + | * |
| |
| 33 | + | * @access public |
| |
| 34 | + | */ |
| |
| 35 | + | |
| |
| 36 | + | public function reset() { |
| |
| 37 | + | $this->_path = array(); |
|
24 | 38 | | } |
| |
25 | 39 | | |
  |
26 | | - | function add($title, $link = '') { |
| |
27 | | - | $this->_trail[] = array('title' => $title, 'link' => $link); |
| |
| 40 | + | /** |
| |
| 41 | + | * Adds an entry to the breadcrumb navigation path |
| |
| 42 | + | * |
| |
| 43 | + | * @param string $title The title of the breadcrumb navigation entry |
| |
| 44 | + | * @param string $link The link of the breadcrumb navigation entry |
| |
| 45 | + | * @access public |
| |
| 46 | + | */ |
| |
| 47 | + | |
| |
| 48 | + | public function add($title, $link = null) { |
| |
| 49 | + | $this->_path[] = array('title' => $title, |
| |
| 50 | + | 'link' => $link); |
|
28 | 51 | | } |
| |
29 | 52 | | |
  |
30 | | - | function trail($separator = ' - ') { |
| |
| 53 | + | /** |
| |
| 54 | + | * Returns the breadcrumb navigation path with the entries separated by $separator |
| |
| 55 | + | * |
| |
| 56 | + | * @param string $separator The string value to separate the breadcrumb navigation path entries with |
| |
| 57 | + | * @access public |
| |
| 58 | + | * @return string |
| |
| 59 | + | */ |
| |
| 60 | + | |
| |
| 61 | + | public function getPath($separator = ' - ') { |
|
31 | 62 | | $trail_string = ''; |
| |
32 | 63 | | |
  |
33 | | - | for ($i=0, $n=sizeof($this->_trail); $i<$n; $i++) { |
| |
34 | | - | if (isset($this->_trail[$i]['link']) && !empty($this->_trail[$i]['link'])) { |
| |
35 | | - | $trail_string .= osc_link_object($this->_trail[$i]['link'], $this->_trail[$i]['title']); |
| |
| 64 | + | $trail_size = sizeof($this->_path); |
| |
| 65 | + | $counter = 0; |
| |
| 66 | + | |
| |
| 67 | + | foreach ( $this->_path as $entry ) { |
| |
| 68 | + | $counter++; |
| |
| 69 | + | |
| |
| 70 | + | if ( !empty($entry['link']) ) { |
| |
| 71 | + | $trail_string .= osc_link_object($entry['link'], $entry['title']); |
|
36 | 72 | | } else { |
  |
37 | | - | $trail_string .= $this->_trail[$i]['title']; |
| |
| 73 | + | $trail_string .= $entry['title']; |
|
38 | 74 | | } |
| |
39 | 75 | | |
  |
40 | | - | if (($i+1) < $n) $trail_string .= $separator; |
| |
| 76 | + | if ( $counter < $trail_size ) { |
| |
| 77 | + | $trail_string .= $separator; |
| |
| 78 | + | } |
|
41 | 79 | | } |
| |
42 | 80 | | |
| |
43 | 81 | | return $trail_string; |
| |
44 | 82 | | } |
  |
| 83 | + | |
| |
| 84 | + | /** |
| |
| 85 | + | * Returns the breadcrumb navigation path array |
| |
| 86 | + | * |
| |
| 87 | + | * @access public |
| |
| 88 | + | * @return array |
| |
| 89 | + | */ |
| |
| 90 | + | |
| |
| 91 | + | public function getArray() { |
| |
| 92 | + | return $this->_path; |
| |
| 93 | + | } |
  |
45 | 94 | | } |
| |
46 | 95 | | ?> |