Initial commit

This commit is contained in:
Phyks 2013-10-06 14:00:00 +01:00
commit 83ef0ea335
4 changed files with 277 additions and 0 deletions

63
index.php Normal file
View File

@ -0,0 +1,63 @@
<?php
include('.config/include.php');
if (is_readable($_CONFIG['DATA_DIR'].$_CONFIG['ASSOC_NAME']))
{
$rawData = file_get_contents($_CONFIG['DATA_DIR'].$_CONFIG['ASSOC_NAME']);
$data = unserialize($rawData);
}
else
$data = array();
// If we don't have exactly one $_GET arg, we print a default page
if (count($_GET) > 1 || count($_GET) < 1)
{
if (isset($_GET['add']) && $_GET['url'])
$default_url = htmlspecialchars($_GET['url']);
else
$default_url = "";
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8">
<title>Réduis moi!</title>
<link rel="stylesheet" media="screen" type="text/css" href="misc/design.css" />
<link rel="icon" href="favicon.ico" />
</head>
<body>
<h1>C'est trop long ...</h1>
<form method="post" action="process.php">
<p>
<label for="url">URL : </label><input type="text" size="50" name="url" id="url" value="<?php echo $default_url; ?>"/>
</p>
<p>
<label for="short">Raccourci (optionnel): </label><input type="short" size="50" name="short" id="short"/>
</p>
<p><input type="submit" value="... raccourcir !"/></p>
<p>Ajouter ce lien pour réduire les URL en un seul clic :
<a href="javascript:javascript:(function(){var%20url%20=%20location.href;var%20title%20=%20document.title%20||%20url;window.open('<?php echo $_CONFIG['BASE_URL']; ?>/?add&url='%20+%20encodeURIComponent(url),'_blank','menubar=no,height=390,width=600,toolbar=no,scrollbars=no,status=no,dialog=1');})();">Réduis moi !</a>
</p>
</form>
</body>
</html>
<?php
}
// Else, we redirect the visitor to the right URL
else
{
// We get the shortened url
$get = each($_GET);
$short = $get['key'];
$url = $_CONFIG['BASE_URL'];
foreach($data as $array)
{
if ($array['short'] == $short)
{
$url = $array['url'];
break;
}
}
// $url is now index.php if no element was found, the right url if found
header('location:'.$url);
}
?>

BIN
misc/bg.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

141
misc/design.css Normal file
View File

@ -0,0 +1,141 @@
/* --- STYLES DE BASE --- */
/* Page */
html {
font-size: 100%; /* Évite un bug d'IE 6-7. (1) */
}
body {
margin: 0;
padding: 1em; /* Remettre à zéro si nécessaire. */
font-family: Arial, Helvetica, "Liberation Sans", FreeSans, sans-serif;
font-size: .8em;
line-height: 1.4; /* À adapter au design. (4) */
color: black;
background-color: grey;
background-image: url('bg.png');
}
pre
{
font-size: 10px;
font-style: normal;
line-height: 11px;
font-weight: normal;
font-family: "Courier New", Courier, mono;
text-align: left;
margin-left: 40%;
}
/* Titres */
h1, h2, h3, h4, h5, h6 {
margin: 1em 0 .5em 0; /* Rapproche le titre du texte.*/
line-height: 1.2;
font-weight: bold; /* Valeur par défaut.*/
font-style: normal;
}
h1 {
font-size: 1.75em;
}
h2 {
font-size: 1.5em;
}
h3 {
font-size: 1.25em;
}
h4 {
font-size: 1em;
}
/* Listes */
ul, ol {
margin: .75em 0 .75em 32px;
padding: 0;
}
/* Paragraphes */
p {
margin: .75em 0; /* Marges plus faibles que par défaut.*/
}
address {
margin: .75em 0;
font-style: normal;
}
/* Liens */
a {
text-decoration: underline;
}
a:link {
color : #0000cd;
}
a:visited {
color : #4b0082;
}
a:hover, a:focus, a:active {
color : #dc143c;
}
a img {
border: none;
}
/* Divers éléments de type en-ligne*/
em {
font-style: italic;
}
strong {
font-weight: bold;
}
/* Formulaires */
form, fieldset {
margin: 0;
padding: 0;
}
form
{
border: none;
}
/* Mise en forme simple pour les tableaux */
table {
margin: 0;
border: 1px solid gray; /* Pas de bordure = "none". */
border-collapse: collapse; /* Valeur par défaut: "separate". */
border-spacing: 0;
margin: auto;
}
table td, table th {
padding: 4px; /* Pas de retrait autour du texte = "0". */
border: 1px solid #ccc; /* Pas de bordure = "none". */
vertical-align: top; /* Valeur par défaut: "middle" */
text-align: left;
}
body
{
text-align: center;
}
label /* On affiche les labels sous forme de blocs et mise en page = formulaires alignés */
{
display: block;
}
th
{
background-color: rgba(255,10,255,0.2);
}
td
{
background-color: rgba(255,200,255,0.1);
}
.inline
{
display: inline;
}
.centre
{
text-align:center;
}

73
process.php Normal file
View File

@ -0,0 +1,73 @@
<?php
include('.config/include.php');
// Add a new line to $data
function add($that)
{
global $_CONFIG;
global $data;
if (count($data) >= $_CONFIG['SAVED_URL'])
{
// Delete the first element
array_shift($data);
}
// Add that to the array
array_push($data, $that);
return $data;
}
if(empty($_POST['url']))
{
header('location : message.php?m=1');
}
else
{
if (is_readable($_CONFIG['DATA_DIR'].$_CONFIG['ASSOC_NAME']))
$rawData = file_get_contents($_CONFIG['DATA_DIR'].$_CONFIG['ASSOC_NAME']);
else
{
touch($_CONFIG['DATA_DIR'].$_CONFIG['ASSOC_DIR']);
$rawData = "";
}
if (empty($rawData))
$data = array();
else
$data = unserialize($rawData);
}
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8">
<title>Réduit moi !</title>
<link rel="stylesheet" media="screen" type="text/css" href="misc/design.css" />
<link rel="icon" href="favicon.ico" />
</head>
<body>
<h1>C'était trop long !</h1>
<?php
if (isset($_POST['short']) && $_POST['short'] != "")
$short = htmlspecialchars($_POST['short']);
else
$short = dechex(crc32($_POST['url']));
if (isset($_POST['url']) && $_POST['url'] != "")
{
$url = htmlspecialchars($_POST['url']);
$array = array("url"=>$url, "short"=>$short);
// Add the association at the end of $data array
$data = add($array);
// Save it in the file
file_put_contents($_CONFIG['DATA_DIR'].$_CONFIG['ASSOC_NAME'], serialize($data));
// Echoes the result
$new_url = $_CONFIG['BASE_URL'].'/?'.$short;
?>
<p>Votre raccourci :<br/>
<b><a href="<?php echo $new_url ?>"><?php echo $new_url; ?></a></b></p><p>Réduction de : <?php echo $url; ?> <?php
}
else
{
echo "Url manquant. <a href='index.php'>Retour à l'acceuil</a>.";
}?>
</p>
</body>
</html>