Skip to content

Commit

Permalink
Changed out the favicon for one not containing gemerson (just a trial…
Browse files Browse the repository at this point in the history
… at this point), fleshed some tricks to enable copying of the link, unfortunately it's looking like we're probably going to have to use flash, furthered the MVC cause, as well as moved some layout stuff out into separate stylesheets, also added forced line breaks on recents page.
  • Loading branch information
Benjamin committed Feb 11, 2009
1 parent b166f0f commit b6b435b
Show file tree
Hide file tree
Showing 17 changed files with 178 additions and 107 deletions.
31 changes: 5 additions & 26 deletions create.php
Original file line number Diff line number Diff line change
@@ -1,39 +1,20 @@
<?php /* controller/model */ ?>
<?php
require("library.php");
require("models/library.php");

$url = trim($_REQUEST["url"]);

//check to see if they're giving us a gemerit link, first
if (!(preg_match("/http:\/\/gemerit.com\/[0-9abcdef]+$/", $url))) {
if (!(preg_match("/http:\/\/gemerit.com\/[0-9abcdef]+$/", $url)) && strlen($url) > 0) {

//we're going to preppend http if they gave us a url that doesn't already have it
if (!preg_match("/^https?:\/\//", $url))
$url = "http://" . $url;

//attempt to retrieve the item
$query = "SELECT id FROM urls where url = '" .
addslashes($url) . "';";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
//attempt shorten
$hexCode = createLink($url);

//if it's not there we need to insert and retrieve
if (mysql_num_rows($result) == 0)
{
//insert
$query = "INSERT INTO urls (url) VALUES ('" .
addslashes($url) . "');";
mysql_query($query) or die('Query failed: ' . mysql_error());

//get back the thing we just inserted
$query = "SELECT id FROM urls where url = '" .
addslashes($url) . "';";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
}

//get results in easy to use array format
$resultArray = mysql_fetch_assoc($result);

$url = "http://" . $_SERVER["SERVER_NAME"] . "/" . dechex($resultArray["id"]);
$url = "http://" . $_SERVER["SERVER_NAME"] . "/" . $hexCode;

//Special iPhone Twitterific integration pending more work
if (stristr($_SERVER["HTTP_USER_AGENT"], "iPhone")) {
Expand All @@ -43,6 +24,4 @@

//push to view
require("views/createSuccess.php");

mysql_close($link);
?>
Binary file modified favicon.ico
Binary file not shown.
12 changes: 2 additions & 10 deletions get.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
<?php
require("library.php");
require("models/library.php");

//do our search
$query = "SELECT url FROM urls where id = " . hexdec($_REQUEST["hash"]) . ";";

$result = mysql_query($query) or die('Query failed: ' . mysql_error());
$resultArray = mysql_fetch_assoc($result);

//cleanup our URL
$url = stripslashes($resultArray["url"]);
$url = getLink($_REQUEST["hash"]);

//check for attempt at making a loop, this is the only hardcoded url in the project
if (!(preg_match("/gemerit\.com\/[0-9abcdef]+$/", $url)))
header( 'Location: ' . $url, true);
else
echo($url);
mysql_close($link);
?>
Binary file added img/copy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion index.htm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
<head>
<title>Gemer It: URL Shortening Service</title>
<meta name="viewport" content="width=630" />
<link rel="stylesheet" type="text/css" href="style/style.css" />
<link rel="stylesheet" type="text/css" href="style/global.css" />
<link rel="stylesheet" type="text/css" href="style/index.css" />
<meta name="version" content="1.11 beta">
</head>
<body>
<form name="gemerForm" method="get" action="create.php">
Expand Down
11 changes: 0 additions & 11 deletions library.php

This file was deleted.

6 changes: 6 additions & 0 deletions models/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
$DB_USER = "database username";
$DB_PASS = "super secret password";
$DB_HOST = "database server";
$DB_NAME = "database name";
?>
90 changes: 90 additions & 0 deletions models/library.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?
function dbConnect() {
require("config.php");

$link = mysql_connect($DB_HOST, $DB_USER, $DB_PASS)
or die('Could not connect: ' . mysql_error());
mysql_select_db($DB_NAME)
or die('Could not select database');
return $link;
}

function dbDisconnect($link) {
mysql_close($link);
}

//
// Create Link function
//
function createLink($url) {
$link = dbConnect();

//attempt to retrieve the item
$query = "SELECT id FROM urls where url = '" .
addslashes($url) . "';";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

//if it's not there we need to insert and retrieve
if (mysql_num_rows($result) == 0)
{
//insert
$query = "INSERT INTO urls (url) VALUES ('" .
addslashes($url) . "');";
mysql_query($query) or die('Query failed: ' . mysql_error());

//get back the thing we just inserted
$query = "SELECT id FROM urls where url = '" .
addslashes($url) . "';";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
}

//get results in easy to use array format
$resultArray = mysql_fetch_assoc($result);

dbDisconnect($link);
return dechex($resultArray["id"]);
}

//
// Get Link function
//
function getLink($hash) {
$link = dbConnect();

//do our search
$query = "SELECT url FROM urls where id = " . hexdec($hash) . ";";

$result = mysql_query($query) or die('Query failed: ' . mysql_error());
$resultArray = mysql_fetch_assoc($result);

//cleanup our URL
$url = stripslashes($resultArray["url"]);

dbDisconnect($link);
return $url;
}

//
// Get Recent Links function
//
function getRecents($count) {
$link = dbConnect();

$recentShortens = array();

$query = "SELECT id, url FROM urls ORDER BY id DESC LIMIT " . $count . ";";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

$i = 0;
while ($resultArray = mysql_fetch_array($result, MYSQL_ASSOC)) {
$recentShortens[$i] = $resultArray;
//add the hash too.
$recentShortens[$i]["hash"] = dechex($resultArray["id"]);
$i++;
}

dbDisconnect($link);
return $recentShortens;
}

?>
7 changes: 2 additions & 5 deletions recents.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
<?php /* controller/model */ ?>
<?php
require("library.php");
require("models/library.php");

$query = "SELECT id, url FROM urls ORDER BY id DESC LIMIT 20;";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
$recents = getRecents(20);

//push to view
require("views/recents.php");

mysql_close($link);
?>
Empty file added style/createSuccess.css
Empty file.
26 changes: 26 additions & 0 deletions style/global.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
html, body {
font-size: 1.0em;
font-family: Helvetica, Verdana, Arial, sans-serif;
}

a, a:visited {
font-weight: 900;
color: #676767;
text-decoration: none;
}

a:hover {
color: #666;
text-decoration: underline;
}

div.container {
text-align: center;
max-width: 600px;
margin-top: 30px;
margin-left: auto;
margin-right: auto;
}



14 changes: 14 additions & 0 deletions style/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
div.explanations h2, div.explanations p {
text-align: left;
}

div.urlSection input[type="text"] {
color: #676767;
font-size: 18pt;
padding: 0.2em 0.4em 0.2em 0.4em;
width: 100%;
}

div.urlSection input[type="submit"]{
font-size: 18pt;
}
11 changes: 11 additions & 0 deletions style/recents.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
table.results {
vertical-align: middle;
border-spacing: 2px 2px;
border-color: gray;
border-collapse: separate;
}

td.id {
text-align: center;
min-width: 75px;
}
45 changes: 0 additions & 45 deletions style/style.css

This file was deleted.

Binary file added swf/clipboard.swf
Binary file not shown.
10 changes: 8 additions & 2 deletions views/createSuccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<html>
<head>
<title>Gemer It: Results</title>
<link rel="stylesheet" type="text/css" href="style/style.css" />
<link rel="stylesheet" type="text/css" href="style/global.css" />
<meta name="viewport" content="width=630" />
<script type="text/javascript" >
<script type="text/javascript">
var link = "<?php echo($url); ?>";
</script>
</head>
Expand All @@ -13,6 +13,12 @@
<h2>Your Link Is:</h2>
<p id="link">
<span><?php echo($url); ?></span>
<!--
<div class="flashBox">
<embed src="http://gemerit.com/swf/clipboard.swf" flashvars="txtToCopy=<?php echo $url; ?>" width="60" height="30">
</embed>
</div>
-->
</p>

<?php
Expand Down
18 changes: 11 additions & 7 deletions views/recents.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<html>
<head>
<title>Gemer It: Recent Links</title>
<link rel="stylesheet" type="text/css" href="style/style.css" />
<link rel="stylesheet" type="text/css" href="style/global.css" />
<link rel="stylesheet" type="text/css" href="style/recents.css" />
<meta name="viewport" content="width=630" />
</head>
<body>
Expand All @@ -15,15 +16,18 @@
<th>URL</th>
</tr>
<?php
//if I were less lazy this would build an array and that would keep this controller/model seepage
while ($resultArray = mysql_fetch_array($result, MYSQL_ASSOC)) {
$hash = dechex($resultArray["id"]);
$url = $resultArray["url"];
foreach ($recents as $recent) {
?>
<tr>
<td class='id'><?php echo($hash); ?></td>
<td class='id'><?php echo($recent["hash"]); ?></td>
<td class='url'>
<a href='<?php echo($url); ?>'><?php echo($url); ?></a>
<a href='<?php echo($recent["url"]); ?>'>
<?php
//use chunk_split to split up the string into segments of 76 chars each
//this allows linebreaking, which makes it look much much nicer.
echo(chunk_split($recent["url"]));
?>
</a>
</td>
</tr>
<?php
Expand Down

0 comments on commit b6b435b

Please sign in to comment.