Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 23rd, 2012  |  syntax: None  |  size: 1.08 KB  |  hits: 7  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. public static function uri()
  2. {
  3.         /**
  4.          * A lot of fuzzing around to get to where we want.
  5.         */
  6.         $uri = parse_url($_SERVER['REQUEST_URI']);
  7.         $uri = $uri['path'];
  8.         $uri = trim(str_replace(basename($_SERVER['SCRIPT_NAME']), '', $uri), '/');
  9.         $uri = explode('/', $uri);
  10.  
  11.         /**
  12.          * Count how many slashes there are in the base URL.
  13.         */
  14.         foreach(count_chars(\Rawr\Rawr::get_config_value('url'), 1) as $i => $val)
  15.         {
  16.                 if(chr($i) === "/")
  17.                 {
  18.                         $slashes = $val;
  19.                 }
  20.         }
  21.  
  22.         /*
  23.          * Get rid of both index.php if it's in the request and/or subfolders
  24.          * I'm dumb and hence I have no idea how to make this shorter and sweeter. Maybe in the future.
  25.         */
  26.         if(\Rawr\Rawr::get_config_value('index') === "")
  27.         {
  28.                 if($slashes === 4)
  29.                 {
  30.                         unset($uri[0]);
  31.                 }
  32.  
  33.                 if($slashes === 5)
  34.                 {
  35.                         unset($uri[1]);
  36.                 }
  37.  
  38.                 if($slashes === 6)
  39.                 {
  40.                         unset($uri[2]);
  41.                 }
  42.         }
  43.         else
  44.         {
  45.                 if($slashes === 4)
  46.                 {
  47.                         unset($uri[0], $uri[1]);
  48.                 }
  49.  
  50.                 if($slashes === 5)
  51.                 {
  52.                         unset($uri[0], $uri[1], $uri[2]);
  53.                 }
  54.  
  55.                 if($slashes === 6)
  56.                 {
  57.                         unset($uri[0], $uri[1], $uri[2], $uri[3]);
  58.                 }
  59.         }
  60.  
  61.         /**
  62.          * Shabam!
  63.         */
  64.         return array_values($uri);
  65. }