Changeset 475 for trunk/lib/Navigation.inc.php
- Timestamp:
- Apr 26, 2014 3:04:02 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Navigation.inc.php
r468 r475 268 268 269 269 /** 270 * Returns a string if the queried page is the current page. One use is to print 271 * CSS tags if the current page matches a link, such as: 272 * $nav->currentPage('mypage.php', ' id="current"'); 273 * 274 * @access public 275 * 276 * @param mixed $page The URI of the page to query, with PREG express markup, if needed. 277 * @param mixed $return The value to return if the current page matches the page queried. 278 * 279 * @return mixed The value set for $return, TRUE by default. 280 */ 281 public function currentPage($test_uri, $true_return=true, $false_return=false, $strip_query=false) 282 { 283 $actual_uri = $strip_query ? strtok($_SERVER['REQUEST_URI'], '?') : $_SERVER['REQUEST_URI']; 284 $test_uri = $strip_query ? strtok($test_uri, '?') : $test_uri; 285 if (preg_match('/^' . preg_quote(urldecode($test_uri), '/') . '$/i', $actual_uri)) { 270 * Test if the given URI matches the URL of the current page. By default the URI is tested 271 * without concern 272 * One use is to change the returned value for a positive match 273 * so a css class prints for an element representing the current page: 274 * echo $nav->currentPage('/script.php?op=info', ' class="current"', '', true); 275 * The above will match only if the current page (REQUEST_URI) is also '/script.php?op=info', 276 * and will return the string ' class="current"' if it is. 277 * 278 * @access public 279 * 280 * @param string $test_uri A URI to test against the current page. 281 * @param mixed $true_return The value to return if the current page matches the test URI. 282 * @param mixed $false_return The value to return if the current page does not match the test URI. 283 * @param bool $include_query If set true, include the URI query string in the test. 284 * 285 * @return mixed If the test URI matches the current page URI, the value given for $true_return 286 * is returned (true by default), otherwise the value given for $false_return is 287 * returned (false by default). 288 */ 289 public function currentPage($test_uri, $true_return=true, $false_return=false, $include_query=false) 290 { 291 $app =& App::getInstance(); 292 293 $actual_uri = $include_query ? $_SERVER['REQUEST_URI'] : strtok($_SERVER['REQUEST_URI'], '?'); 294 $test_uri = $include_query ? $test_uri : strtok($test_uri, '?'); 295 if (mb_strtolower($test_uri) == mb_strtolower($actual_uri)) { 296 // $app->logMsg(sprintf('Current page (%s) == test URI (%s)', $actual_uri, $test_uri), LOG_DEBUG, __FILE__, __LINE__); 286 297 return $true_return; 287 298 } 299 // $app->logMsg(sprintf('Current page (%s) != test URI (%s)', $actual_uri, $test_uri), LOG_DEBUG, __FILE__, __LINE__); 288 300 return $false_return; 289 301 }
Note: See TracChangeset
for help on using the changeset viewer.