Changeset 534 for trunk/lib/Navigation.inc.php
- Timestamp:
- Jul 27, 2015 7:56:08 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Navigation.inc.php
r523 r534 48 48 'path_delimiter' => ' / ', 49 49 'last_crumb_format' => '%s', 50 'current_page_url' => null, // This should be set at runtime using, e.g., $_SERVER['REQUEST_URI'] 50 51 ); 51 52 public $pages = array(); … … 57 58 { 58 59 $app =& App::getInstance(); 60 61 // Define current_page_url here because _SERVER, not a static scalar, cannot be defined in the defaults above. 62 // Using PHP_SELF for legacy compatability, but it might make sense to override this with REQUEST_URI. 63 // This could be overwritten by passed params. 64 $this->_params['current_page_url'] = $_SERVER['PHP_SELF']; 59 65 60 66 if (isset($params) && is_array($params)) { … … 72 78 * @access public 73 79 * @param string $title The title of the page. 74 * @param string $url The URL to the page. Set to null to use PHP_SELF.80 * @param string $url The URL to the page. Set to null to use REQUEST_URI. 75 81 * @param array $vars Additional page variables. 76 82 */ … … 81 87 'head_title' => $title, 82 88 'body_title' => $title, 83 'url' => is_null($url) ? $ _SERVER['PHP_SELF'] : $url,89 'url' => is_null($url) ? $this->_params['current_page_url'] : $url, 84 90 ); 85 $this->pages[] = array_merge($page, $vars); 91 // An "unformed page element" has settings applied (via ->set()) but no page added (via ->add()). 92 if (empty($this->pages) || isset(end($this->pages)['title'])) { 93 // There are no unformed page elements; add a whole new page. 94 $this->pages[] = array_merge($page, $vars); 95 } else { 96 // Append the new page to the unformed page element. 97 $curr_page =& $this->pages[key($this->pages)]; 98 $curr_page = array_merge($curr_page, $page, $vars); 99 } 86 100 } 87 101 … … 143 157 { 144 158 // Set params of current page. 145 $curr_page =& $this->pages[sizeof($this->pages) - 1]; 159 if (empty($this->pages)) { 160 // If we're setting a value on an empty pages array, we need to add one "unformed" element first. 161 $this->pages[] = array(); 162 } 163 end($this->pages); 164 $curr_page =& $this->pages[key($this->pages)]; 146 165 $curr_page[$key] = $val; 147 166 } … … 157 176 public function get($key, $default='') 158 177 { 159 $curr_page =& $this->pages[sizeof($this->pages) - 1]; 178 end($this->pages); 179 $curr_page =& $this->pages[key($this->pages)]; 160 180 161 181 switch ($key) { … … 375 395 * @access public 376 396 * 377 * @param string $test_uri A URIto test against the current page.397 * @param mixed $test_uri A URI, or an array of URIs, to test against the current page. 378 398 * @param mixed $true_return The value to return if the current page matches the test URI. 379 399 * @param mixed $false_return The value to return if the current page does not match the test URI. … … 387 407 { 388 408 $app =& App::getInstance(); 409 410 // If given an array, test each URI recursively returning TRUE on a first match, or FALSE if none match. 411 if (is_array($test_uri)) { 412 foreach ($test_uri as $uri) { 413 if ($this->currentPage($uri, $true_return, $false_return, $include_query)) { 414 return true; 415 } 416 } 417 return false; 418 } 389 419 390 420 $actual_uri = $include_query ? $_SERVER['REQUEST_URI'] : strtok($_SERVER['REQUEST_URI'], '?');
Note: See TracChangeset
for help on using the changeset viewer.