コード例 #1
0
ファイル: redirect.php プロジェクト: rfinnie/m29
 * @package M29
 * @author Ryan Finnie <*****@*****.**>
 * @copyright 2012 Ryan Finnie
 * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU GPL version 2
 */
require_once 'config.php';
require_once 'functions.php';
require_once 'M29.php';
$m29 = new M29($config);
if (isset($_SERVER['PATH_INFO'])) {
    $url = $m29->base_url . $_SERVER['PATH_INFO'];
} else {
    http_error(array('reason' => 'serviceError', 'message' => 'Cannot determine the short URL'));
}
try {
    $ret = $m29->process_short_url($url, true);
} catch (M29Exception $e) {
    http_error($e->error);
}
header($_SERVER['SERVER_PROTOCOL'] . ' 301 Moved Permanently');
header("Location: " . $ret['long_url']);
?>
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-type" content="text/html;charset=UTF-8"/>
  <title>301 Moved Permanently</title>
</head>

<body>
<h1>Moved Permanently</h1>
コード例 #2
0
ファイル: api-v1.php プロジェクト: rfinnie/m29
        if ($secondKey_bin) {
            $out = array('kind' => 'urlshortener#url', 'id' => $ret['short_url'], 'longUrl' => $ret['long_url']);
            header("Content-Type: application/json; charset=UTF-8");
            print json_encode($out) . "\n";
        } else {
            $out = array('kind' => 'urlshortener#url', 'id' => $ret['short_url'], 'idIncomplete' => True);
            header("Content-Type: application/json; charset=UTF-8");
            print json_encode($out) . "\n";
        }
    } else {
        http_error(array('reason' => 'required', 'message' => 'Required parameter: longUrl', 'locationType' => 'parameter', 'location' => 'longUrl'), 'json');
    }
} else {
    if (isset($_GET['shortUrl'])) {
        try {
            $ret = $m29->process_short_url($_GET['shortUrl'], false);
        } catch (M29Exception $e) {
            http_error($e->error, 'json');
        }
        $out = array('kind' => 'urlshortener#url', 'id' => $_GET['shortUrl'], 'longUrl' => $ret['long_url'], 'status' => 'OK');
        if (isset($_GET['projection']) && ($_GET['projection'] == 'FULL' || $_GET['projection'] == 'ANALYTICS_CLICKS')) {
            $out['created'] = gmdate('c', $ret['created_at']);
            if ($ret['accessed_at']) {
                $out['lastClick'] = gmdate('c', $ret['accessed_at']);
            }
            $out['analytics'] = array('allTime' => array('shortUrlClicks' => $ret['hits'], 'longUrlClicks' => $ret['hits']));
        }
        header("Content-Type: application/json; charset=UTF-8");
        print json_encode($out) . "\n";
    } else {
        http_error(array('reason' => 'required', 'message' => 'Required parameter: shortUrl', 'locationType' => 'parameter', 'location' => 'shortUrl'), 'json');
コード例 #3
0
ファイル: info.php プロジェクト: rfinnie/m29
 * @package M29
 * @author Ryan Finnie <*****@*****.**>
 * @copyright 2012 Ryan Finnie
 * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU GPL version 2
 */
require_once 'config.php';
require_once 'functions.php';
require_once 'M29.php';
$m29 = new M29($config);
if (isset($_SERVER['PATH_INFO'])) {
    $url = $m29->base_url . $_SERVER['PATH_INFO'];
} else {
    http_error(array('reason' => 'serviceError', 'message' => 'Cannot determine the short URL'));
}
try {
    $ret = $m29->process_short_url($url, false);
} catch (M29Exception $e) {
    http_error($e->error);
}
?>
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>URL Information</title>
<link href='http://fonts.googleapis.com/css?family=Ubuntu+Mono:400,700' rel='stylesheet' type='text/css'>
<link href="<?php 
echo $m29->base_url;
?>
/m29.css" rel="stylesheet" type="text/css"/>
</head>