  |
1 | 1 | | <?php |
| |
2 | 2 | | /* |
  |
3 | | - | $Id: breadcrumb.php 1860 2009-03-06 23:25:01Z hpdl $ |
| |
| 3 | + | $Id: breadcrumb.php 1861 2009-03-06 23:26:28Z hpdl $ |
|
4 | 4 | | |
| |
5 | 5 | | osCommerce, Open Source E-Commerce Solutions |
| |
6 | 6 | | http://www.oscommerce.com |
| |
|
|
 |
… |
|
16 | 16 | | * The osC_Breadcrumb class handles the breadcrumb navigation path |
| |
17 | 17 | | */ |
| |
18 | 18 | | |
  |
19 | | - | class osC_Breadcrumb { |
| |
| 19 | + | class osC_Breadcrumb implements iterator { |
|
20 | 20 | | |
| |
21 | 21 | | /** |
| |
22 | 22 | | * An array containing the breadcrumb navigation path |
| |
|
|
 |
… |
|
28 | 28 | | private $_path = array(); |
| |
29 | 29 | | |
| |
30 | 30 | | /** |
  |
| 31 | + | * The string to separate the breadcrumb entries with |
| |
| 32 | + | * |
| |
| 33 | + | * @var string |
| |
| 34 | + | * @access private |
| |
| 35 | + | */ |
| |
| 36 | + | |
| |
| 37 | + | private $_separator = ' » '; |
| |
| 38 | + | |
| |
| 39 | + | /** |
|
31 | 40 | | * Resets the breadcrumb navigation path |
| |
32 | 41 | | * |
| |
33 | 42 | | * @access public |
| |
|
|
 |
… |
|
46 | 55 | | */ |
| |
47 | 56 | | |
| |
48 | 57 | | public function add($title, $link = null) { |
  |
49 | | - | $this->_path[] = array('title' => $title, |
| |
50 | | - | 'link' => $link); |
| |
| 58 | + | if ( !empty($link) ) { |
| |
| 59 | + | $title = osc_link_object($link, $title); |
| |
| 60 | + | } |
| |
| 61 | + | |
| |
| 62 | + | $this->_path[] = $title; |
|
51 | 63 | | } |
| |
52 | 64 | | |
| |
53 | 65 | | /** |
| |
|
|
 |
… |
|
58 | 70 | | * @return string |
| |
59 | 71 | | */ |
| |
60 | 72 | | |
  |
61 | | - | public function getPath($separator = ' - ') { |
| |
62 | | - | $trail_string = ''; |
| |
63 | | - | |
| |
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']); |
| |
72 | | - | } else { |
| |
73 | | - | $trail_string .= $entry['title']; |
| |
74 | | - | } |
| |
75 | | - | |
| |
76 | | - | if ( $counter < $trail_size ) { |
| |
77 | | - | $trail_string .= $separator; |
| |
78 | | - | } |
| |
| 73 | + | public function getPath($separator = null) { |
| |
| 74 | + | if ( is_null($separator) ) { |
| |
| 75 | + | $separator = $this->_separator; |
|
79 | 76 | | } |
| |
80 | 77 | | |
  |
81 | | - | return $trail_string; |
| |
| 78 | + | return implode($separator, $this->_path); |
|
82 | 79 | | } |
| |
83 | 80 | | |
| |
84 | 81 | | /** |
| |
|
|
 |
… |
|
91 | 88 | | public function getArray() { |
| |
92 | 89 | | return $this->_path; |
| |
93 | 90 | | } |
  |
| 91 | + | |
| |
| 92 | + | /** |
| |
| 93 | + | * Returns the breadcrumb separator |
| |
| 94 | + | * |
| |
| 95 | + | * @access public |
| |
| 96 | + | * @return string |
| |
| 97 | + | */ |
| |
| 98 | + | |
| |
| 99 | + | public function getSeparator() { |
| |
| 100 | + | return $this->_separator; |
| |
| 101 | + | } |
| |
| 102 | + | |
| |
| 103 | + | /** |
| |
| 104 | + | * Sets the breadcrumb string separator |
| |
| 105 | + | * |
| |
| 106 | + | * @param string $separator The string to separator breadcrumb entries with |
| |
| 107 | + | * @access public |
| |
| 108 | + | * @return string |
| |
| 109 | + | */ |
| |
| 110 | + | |
| |
| 111 | + | public function setSeparator($separator) { |
| |
| 112 | + | $this->_separator = $separator; |
| |
| 113 | + | } |
| |
| 114 | + | |
| |
| 115 | + | /** |
| |
| 116 | + | * Overloaded rewind iterator function |
| |
| 117 | + | * |
| |
| 118 | + | * @access public |
| |
| 119 | + | */ |
| |
| 120 | + | |
| |
| 121 | + | public function rewind() { |
| |
| 122 | + | return reset($this->_path); |
| |
| 123 | + | } |
| |
| 124 | + | |
| |
| 125 | + | /** |
| |
| 126 | + | * Overloaded current iterator function |
| |
| 127 | + | * |
| |
| 128 | + | * @access public |
| |
| 129 | + | */ |
| |
| 130 | + | |
| |
| 131 | + | public function current() { |
| |
| 132 | + | return current($this->_path); |
| |
| 133 | + | } |
| |
| 134 | + | |
| |
| 135 | + | /** |
| |
| 136 | + | * Overloaded key iterator function |
| |
| 137 | + | * |
| |
| 138 | + | * @access public |
| |
| 139 | + | */ |
| |
| 140 | + | |
| |
| 141 | + | public function key() { |
| |
| 142 | + | return key($this->_path); |
| |
| 143 | + | } |
| |
| 144 | + | |
| |
| 145 | + | /** |
| |
| 146 | + | * Overloaded next iterator function |
| |
| 147 | + | * |
| |
| 148 | + | * @access public |
| |
| 149 | + | */ |
| |
| 150 | + | |
| |
| 151 | + | public function next() { |
| |
| 152 | + | return next($this->_path); |
| |
| 153 | + | } |
| |
| 154 | + | |
| |
| 155 | + | /** |
| |
| 156 | + | * Overloaded valid iterator function |
| |
| 157 | + | * |
| |
| 158 | + | * @access public |
| |
| 159 | + | */ |
| |
| 160 | + | |
| |
| 161 | + | public function valid() { |
| |
| 162 | + | return ( current($this->_path) !== false ); |
| |
| 163 | + | } |
  |
94 | 164 | | } |
| |
95 | 165 | | ?> |