You are here

function shurly_boot in ShURLy 7

Same name and namespace in other branches
  1. 6 shurly.module \shurly_boot()

Implements hook_boot().

File

./shurly.module, line 190
description http://www.youtube.com/watch?v=Qo7qoonzTCE

Code

function shurly_boot() {

  // if the path has any unallowed characters in it (such as slashes),
  // it's not a short URL, so we can bail out and save ourselves a database call
  if (shurly_validate_custom(request_path())) {
    $row = db_query("SELECT rid, destination FROM {shurly} WHERE source = :q AND active = 1", array(
      ':q' => request_path(),
    ))
      ->fetchObject();
    if ($row) {
      shurly_goto($row);
    }
    elseif (variable_get('shurly_redirect_page', FALSE)) {
      $row = db_query("SELECT rid, destination FROM {shurly} WHERE source = :q AND active = 0", array(
        ':q' => $_GET['q'],
      ))
        ->fetchObject();
      if ($row) {
        global $base_url;
        $domain = variable_get('shurly_base', $base_url);
        $row->destination = $domain . '/' . variable_get('shurly_redirect_page', FALSE) . "?d=" . $row->destination;
        shurly_goto($row);
      }
    }
  }
}