Beispiel #1
0
 public function render()
 {
     $longurl = new DagdShortenController();
     $text = $longurl->getLongURL($this->route_matches[1]);
     if ($text === null) {
         return error404();
     }
     $qs = build_given_querystring();
     if ($this->route_matches[2]) {
         return $text . '/' . $this->route_matches[2] . $qs;
     } else {
         return $text . $qs;
     }
 }
Beispiel #2
0
 private function redirect_from_shorturl()
 {
     $this->getLongURL($this->route_matches[1]);
     if ($this->long_url) {
         $this->logURLAccess();
         header('X-Original-URL: ' . $this->long_url);
         $qs = build_given_querystring();
         if ($this->route_matches[2]) {
             header('Location: ' . $this->long_url . '/' . $this->route_matches[2] . $qs);
         } else {
             header('Location: ' . $this->long_url . $qs);
         }
         return true;
     } else {
         error404();
         return false;
     }
 }
Beispiel #3
0
$route_matches = null;
$controller_match = null;
$routes = array();
$routes += DaGdConfig::get('general.redirect_map');
if (!is_html_useragent()) {
    $routes += DaGdConfig::get('general.cli_routemap');
}
$routes += DaGdConfig::get('general.routemap');
foreach ($routes as $route => $controller) {
    if (preg_match('#^' . $route . '#', $requested_path, $route_matches)) {
        if (preg_match('#^https?://#', $controller)) {
            // If the "controller" side starts with http://, we can just redirect.
            // This lets us do things like '/foo/(.*)' => 'http://google.com/$1'
            array_shift($route_matches);
            $new_location = preg_replace('@^' . $route . '@', $controller, $requested_path);
            $new_location .= build_given_querystring();
            debug('New Location', $new_location);
            header('Location: ' . $new_location);
            return;
        } else {
            $controller_match = $controller;
            break;
        }
    }
}
$debug = DaGdConfig::get('general.debug');
if (!$route_matches) {
    error404();
    if (!$debug) {
        die;
    }