1
0
mirror of https://github.com/Chouchen/shorturl.git synced 2018-06-07 06:34:38 +02:00
shorturl/add.php

44 lines
1.1 KiB
PHP
Raw Permalink Normal View History

2011-01-04 11:19:57 +01:00
<?
2011-02-14 17:49:52 +01:00
/**
*
* File given while using the bookmarklet
* Output some `alert` js
*/
2011-01-04 11:19:57 +01:00
header("Content-type: text/javascript");
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date dans le passé
$s = $_GET['s'];
$url = $_GET['u'];
$title = $_GET['t'];
$version = $_GET['v'];
include 'class/ShortURL.php';
2011-01-07 14:33:44 +01:00
$short = new ShortURL();
2011-01-04 11:19:57 +01:00
if($s=='' || $url==''){
echo 'alert("'.ShortURL::STATE_FIELD_MISSING.'");';
exit;
}
2011-01-07 14:33:44 +01:00
$ret = $short->shortThisUrl($url, $s);
2011-01-04 11:19:57 +01:00
if(is_bool($ret) && !$ret){
echo 'alert("'.ShortURL::STATE_ERROR.'");';
exit;
}
elseif($ret === ShortURL::STATE_ALREADY_EXIST){
echo 'alert("'.$ret.'");';
exit;
}
else{
2011-01-07 15:55:31 +01:00
$URI = $_SERVER['REQUEST_URI'];
$folders = explode('/', $URI);
if(count($folders) > 2){
$folder = '/'.$folders[1].'/';
}else
$folder = '/';
echo 'alert("'.ShortURL::STATE_CREATED.' : http://'.$_SERVER['SERVER_NAME'].$folder.rawurlencode($s).'");window.clipboardData.setData("Text", "http://'.$_SERVER['SERVER_NAME'].$folder.rawurlencode($s).'");';
2011-01-04 11:19:57 +01:00
exit;
}