Exemple #1
0
 /**
  * Parse the current URI and return the EDK arguments.
  *
  * This returns an ordered array of parameter arrays. Each parameter array
  * contains name, value (or true if no value), true/false depending on
  * whether it was in the pathinfo or querystring.
  *
  * The first two components from path info will be labelled 'a' and 'id'.
  *
  * pathinfo is treated as kburl/index/page(a)/id/name/name
  * e.g.
  * http://killboard/path/to/kb/index/kill_detail/45/unlimited
  * returns {0=>(a, kill_detail, true), 1=>(id, 45, true), 2=>(unlimited,true, true)
  * http://killboard/path/to/kb/index/kill_detail/?id=45&unlimited
  * returns {0=>(a, kill_detail, true), 1=>(id, 45, false), 2=>(unlimited, true, true)
  * http://killboard/path/to/kb/?a=kill_detail&id=45&unlimited
  * returns {0=>(a, kill_detail, false), 1=>(id, 45, false), 2=>(unlimited, true, true)
  *
  * @return array
  */
 public static function parseURI()
 {
     if (isset(self::$args)) {
         return self::$args;
     }
     $args = array();
     $pagefound = false;
     $pathinfo = null;
     if (isset($_SERVER['PATH_INFO'])) {
         $pathinfo = trim($_SERVER['PATH_INFO'], '/');
     }
     if ($pathinfo) {
         $pathparts = explode('/', $pathinfo);
         $pos = 0;
         foreach ($pathparts as $parameter) {
             if ($parameter == '' || is_null($parameter)) {
                 continue;
             } else {
                 if ($pos == 0) {
                     if (is_numeric($parameter)) {
                         $args[] = array('a', 'home', true);
                         $args[] = array($parameter, true, true);
                         $pos++;
                     } else {
                         $args[] = array('a', $parameter, true);
                     }
                     $pagefound = true;
                 } else {
                     $args[] = array($parameter, true, true);
                 }
             }
             $pos++;
         }
     }
     foreach (explode('&', $_SERVER['QUERY_STRING']) as $parameter) {
         if ($parameter == '') {
             continue;
         }
         $parts = explode('=', $parameter);
         if ($parts[0] == 'a') {
             if (!$parts[1]) {
                 continue;
             } else {
                 if ($pathinfo) {
                     // An old broken link. Discard the pathinfo and redirect.
                     header('Location: ' . KB_HOST . '/?' . $_SERVER['QUERY_STRING']);
                     die;
                 } else {
                     $pagefound = true;
                     array_unshift($args, array('a', $parts[1], false));
                 }
             }
         } else {
             if (isset($parts[1])) {
                 $args[] = array($parts[0], $parts[1], false);
             } else {
                 $args[] = array($parts[0], true, false);
             }
         }
     }
     if (!$pagefound) {
         array_unshift($args, array('a', 'home', false));
     }
     if ($args[0][1] == 'index') {
         $args[0][1] = 'home';
     }
     self::$args = $args;
     return $args;
 }