From ac6f01a5242e79b42fe72d8fe1855703c0e08c4e Mon Sep 17 00:00:00 2001 From: Phyks Date: Wed, 9 Oct 2013 14:00:00 +0100 Subject: [PATCH] Refactor --- README.md | 4 ++ misc/bg.png => bg.png | Bin config.example.php | 5 ++ misc/design.css => design.css | 0 index.php | 73 ++++++++++---------- process.php | 121 +++++++++++++++++----------------- 6 files changed, 104 insertions(+), 99 deletions(-) create mode 100644 README.md rename misc/bg.png => bg.png (100%) create mode 100644 config.example.php rename misc/design.css => design.css (100%) diff --git a/README.md b/README.md new file mode 100644 index 0000000..a6fd2e9 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +shortURL +======== + +Forked from http://git.cphyc.me/cgit.cgi/tinyURL diff --git a/misc/bg.png b/bg.png similarity index 100% rename from misc/bg.png rename to bg.png diff --git a/config.example.php b/config.example.php new file mode 100644 index 0000000..7558a0b --- /dev/null +++ b/config.example.php @@ -0,0 +1,5 @@ + 1 || count($_GET) < 1) -{ - if (isset($_GET['add']) && $_GET['url']) +if (count($_GET) != 1) { + if (isset($_GET['add']) && !empty($_GET['url'])) { $default_url = htmlspecialchars($_GET['url']); - else + } + else { $default_url = ""; + } ?> - - - - - Réduis moi! - - - - -

C'est trop long ...

-
-

- -

-

- -

-

-

Ajouter ce lien pour réduire les URL en un seul clic : - Réduis moi ! -

-
- - + + + + + Shorten me + + + +

It's too long…

+
+

+ +

+

+ +

+

+

Add this link to your bookmarks to shorten links in one click ! + Réduis moi ! +

+
+ + = $_CONFIG['SAVED_URL']) - { - // Delete the first element - array_shift($data); - } - // Add that to the array - array_push($data, $that); - return $data; +function add($that) { + global $_CONFIG; + global $data; + if (count($data) >= 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'); +if(empty($_POST['url'])) { + header('location : message.php?m=1'); +} +else { + if (is_readable(DATA_DIR.ASSOC_NAME)) + $rawData = file_get_contents(DATA_DIR.ASSOC_NAME); + else + { + touch(DATA_DIR.ASSOC_DIR); + $rawData = ""; + } + if (empty($rawData)) + $data = array(); + else + $data = unserialize($rawData); } -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); - } ?> - - - Réduit moi ! - - - - -

C'était trop long !

+ + + Shorten me !<title> + <link rel="stylesheet" media="screen" type="text/css" href="design.css" /> + </head> + <body> + <h1>It was too 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; +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(DATA_DIR.ASSOC_NAME, serialize($data)); + // Echoes the result + $new_url = $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> + <p>Your shorten URL:<br/> + <strong><a href="<?php echo $new_url ?>"><?php echo $new_url; ?></a></strong> + </p> + <p>Short link for:<?php echo '<a href="'.$url.'">'.$url.'</a>'; ?></p> +<?php +} +else { + echo "<p>Missing URL. <a href='index.php'>Back to index page</a>.</p>"; +} +?> + </body> </html>