Skip to content

Commit

Permalink
urlshort
Browse files Browse the repository at this point in the history
  • Loading branch information
voitto committed Aug 20, 2009
1 parent 638b020 commit a8cf463
Show file tree
Hide file tree
Showing 24 changed files with 916 additions and 0 deletions.
Binary file added db/library/urlshort/.DS_Store
Binary file not shown.
38 changes: 38 additions & 0 deletions db/library/urlshort/readme.txt
@@ -0,0 +1,38 @@
urlShort 1.1.2 http://urlshort.sourceforge.net

urlShort is a simple PHP/MySQL script for creating shortened URLs similar to TinyURL. urlShort offers custom short names and an API for creating shortened URLs. urlShort requires PHP/MySQL and supports mod_rewrite. It is released under the GNU GPL.

-----------------------------------------------------------------------

Changelog:

jQuery call
Install path fix

-----------------------------------------------------------------------

Known Issues:

api.php?short=http://urlshort.com/1 returns 500 HTTP code, should be 200

-----------------------------------------------------------------------

To install:

1. Upload the files to your website. It should either be in your root public_html directory or a subdomain.

2. Create a MySQL database and user for urlShort.

3. Import the urlshort.sql file:

((

mysql -u <urlshort_user> -p <urlshort_db> < urlshort.sql

))

Or using the import tab in phpMyAdmin

4. Edit the configuration file includes/conf.php for your server.

5. Enjoy!
Binary file added db/library/urlshort/upload/.DS_Store
Binary file not shown.
16 changes: 16 additions & 0 deletions db/library/urlshort/upload/.htaccess
@@ -0,0 +1,16 @@
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . ./index.php [L]
</IfModule>

ErrorDocument 403 /403.php
ErrorDocument 404 /404.php
ErrorDocument 410 /410.php
ErrorDocument 500 /500.php
<Files 403.shtml>
order allow,deny
allow from all
</Files>
13 changes: 13 additions & 0 deletions db/library/urlshort/upload/403.php
@@ -0,0 +1,13 @@
<?php include 'includes/header-one.php'; ?>

<body>

<?php include 'includes/header-two.php'; ?>

<p><form>
<h2>Access Denied</h2>
<br/>You don't have permission to access this file. Check your information and try again.<br/>

</form></p>

<?php include 'includes/footer.php'; ?>
13 changes: 13 additions & 0 deletions db/library/urlshort/upload/404.php
@@ -0,0 +1,13 @@
<?php include 'includes/header-one.php'; ?>

<body>

<?php include 'includes/header-two.php'; ?>

<p><form>
<h2>Not Found</h2>
<br/>That shortened URL doesn't exist. Are you sure it's right? Try again.<br/>

</form></p>

<?php include 'includes/footer.php'; ?>
13 changes: 13 additions & 0 deletions db/library/urlshort/upload/410.php
@@ -0,0 +1,13 @@
<?php include 'includes/header-one.php'; ?>

<body>

<?php include 'includes/header-two.php'; ?>

<p><form>
<h2>Removed</h2>
<br/>That shortened URL no longer exists because it has been reported by <b><?php echo $_GET["report"]; ?></b> for a violation of the terms of service. We apologize for any inconvenience.<br/>

</form></p>

<?php include 'includes/footer.php'; ?>
13 changes: 13 additions & 0 deletions db/library/urlshort/upload/500.php
@@ -0,0 +1,13 @@
<?php include 'includes/header-one.php'; ?>

<body>

<?php include 'includes/header-two.php'; ?>

<p><form>
<h2>Server Error</h2>
<br/>It looks like the server is having some troubles. Try reloading the page to see if it comes back. If it does not, please wait and try again later.<br/>

</form></p>

<?php include 'includes/footer.php'; ?>
129 changes: 129 additions & 0 deletions db/library/urlshort/upload/api.php
@@ -0,0 +1,129 @@
<?php

/* urlshort / api.php */
/* api for creation and lookup*/
/* written june 24 2008 by adam */
/* updated may 29 2009 by matt */

error_reporting(0);

require_once 'includes/config.php'; // settings
require_once 'includes/gen.php'; // url generation and location
require_once 'includes/install_path.php';
global $request;
$url = new shorturl();
$msg = '';

header('HTTP/1.1 500 Internal Server Error');

// if the url has been sent to this script
if ( isset($request->url) && strlen(trim($request->url)) )
{
// escape bad characters from the users url
$longurl = trim(mysql_escape_string($request->url));

// set the protocol to not ok by default
$protocol_ok = false;

// if there's a list of allowed protocols,
// check to make sure its all cool
if ( count($allowed_protocols) )
{
foreach ( $allowed_protocols as $ap )
{
if ( strtolower(substr($longurl, 0, strlen($ap))) == strtolower($ap) )
{
$protocol_ok = true;
break;
}
}
}
else // if there's no protocol list, fuck all that
{
$protocol_ok = true;
}

// add the url to the database
if ( $protocol_ok && $url->add_url($longurl) )
{
if ( REWRITE ) // mod_rewrite style link
{
$url = 'http://'.$_SERVER['SERVER_NAME'].dirname($_SERVER['PHP_SELF']).''.$url->get_id($longurl);
}
else // regular GET style link
{
$url = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF'].'?id='.$url->get_id($longurl);
}
// if good output url
header('HTTP/1.1 200 OK');
$msg = $url;
mysql_close($conn);
}
elseif ( !$protocol_ok )
{
header('HTTP/1.1 500 Internal Server Error');
$msg = 'error - invalid protocol';
mysql_close($conn);
}
else // something broken
{
header('HTTP/1.1 500 Internal Server Error');
$msg = 'error';
mysql_close($conn);
}
}
else
{
header('HTTP/1.1 500 Internal Server Error');
$msg = 'error - invalid long url';
mysql_close($conn);
}

// if the id has been sent to this script

if ( isset($request->custom) && strlen(trim($request->custom)) )
{
// escape bad characters from the users url
$shorturl = trim(mysql_escape_string($request->custom));

$string = "$shorturl";

list($string1,$string2) = explode("$install_path",$string);

$shortid = $string1.$string2;

// return the url for given id (or -1 if the id doesnt exist)

$q2 = 'SELECT url FROM `urls` WHERE `id` LIKE CONVERT(_utf8 \''.$shortid.'\' USING latin1)';

$result2 = mysql_query($q2);

while ($row = mysql_fetch_array($result2, MYSQL_ASSOC)) {
printf($row["url"]);

exit();

}

if ( mysql_num_rows( $result2 ) == $result2 ) {
$fullurl = mysql_result($result2, 1);
}

else{
header('HTTP/1.1 500 Internal Server Error');
$fullurl = 'error - invalid short url';
mysql_close($conn);
}

header('HTTP/1.1 200 OK');
$msg = $fullurl;
mysql_close($conn);

}

/***************************/
// echo the url or error
/***************************/
echo $msg;
mysql_close($conn);
?>
18 changes: 18 additions & 0 deletions db/library/urlshort/upload/api/index.php
@@ -0,0 +1,18 @@
<?php include '../includes/header-one.php'; ?>

<body>

<?php include '../includes/header-two.php'; ?>

<p><form>
<h2>API - <a href="<?php include 'install_path.php'; echo $install_path; ?>api.php">api.php</a></h2>
<br/>You can use our API file to create a shortened URL with our service, or look up the full length URL via a simple URL request.<br/>
<h3>Examples</h3>
<div class="example">
<a href="<?php include 'install_path.php'; echo $install_path; ?>api.php?url=http://urlshort.sourceforge.net/download"><?php include 'install_path.php'; echo $install_path; ?>api.php?url=http://urlshort.sourceforge.net/download</a><br/>
<br/><a href="<?php include 'install_path.php'; echo $install_path; ?>api.php?short=<?php include 'install_path.php'; echo $install_path; ?>1"><?php include 'install_path.php'; echo $install_path; ?>api.php?short=<?php include 'install_path.php'; echo $install_path; ?>1</a><br/>
</div><br/>For more info visit <a href="../example.php">example.php</a>.<br/>

</form></p>

<?php include '../includes/footer.php'; ?>
59 changes: 59 additions & 0 deletions db/library/urlshort/upload/example.php
@@ -0,0 +1,59 @@
<pre>
$longurl = 'http://urlshort.sourceforge.net/download/?version111-zip';

$fh = fopen("<?php include 'install_path.php'; echo $install_path; ?>api.php">api.php?url=$longurl", "r");

while(!feof($fh))
{
echo $output = htmlspecialchars(fgets($fh, 1024));

}

fclose($fh);


THIS CODE PRODUCES THIS:
</pre>
<?php
$longurl = 'http://urlshort.sourceforge.net/download/?version111-zip';

$fh = fopen("<?php include 'install_path.php'; echo $install_path; ?>api.php">api.php?url=$longurl", "r");

while(!feof($fh))
{
echo $output = '<b>'.htmlspecialchars(fgets($fh, 1024)) .'</b>';

}

fclose($fh);
?>
<pre>
AND
$shorturl = '<?php include 'install_path.php'; echo $install_path; ?>api.php">1';

$fh = fopen("<?php include 'install_path.php'; echo $install_path; ?>api.php">api.php?short=$longurl", "r");

while(!feof($fh))
{
echo $output = htmlspecialchars(fgets($fh, 1024));

}

fclose($fh);


THIS CODE PRODUCES THIS:
</pre>
<?php
$shorturl = '<?php include 'install_path.php'; echo $install_path; ?>api.php">1';

$fh = fopen("<?php include 'install_path.php'; echo $install_path; ?>api.php">api.php?short=$shorturl", "r");

while(!feof($fh))
{
echo $output = htmlspecialchars(fgets($fh, 1024));

}

fclose($fh);
?>
Binary file added db/library/urlshort/upload/includes/.DS_Store
Binary file not shown.
20 changes: 20 additions & 0 deletions db/library/urlshort/upload/includes/connection.php
@@ -0,0 +1,20 @@
<?php

/* urlshort / includes / connection.php */
/* form a database connection */

error_reporting(0);
require_once 'config.php';

$conn = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS);

if(!$conn){
// header(s) to send
header('HTTP/1.1 500 Internal Server Error');
mysql_close($conn);

// html or other output to flush to browser
die("error");
mysql_close($conn);
}
?>
23 changes: 23 additions & 0 deletions db/library/urlshort/upload/includes/counter.php
@@ -0,0 +1,23 @@
<?php

/* urlshort / includes / counter.php */
/* get the number of shortened urls each time */
/* written march 21 2009 by matt */
/* updated may 29 2009 by matt */

error_reporting(0);

require_once 'config.php'; // settings

$conn = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS);

mysql_select_db(MYSQL_DB);

$result = mysql_query("SELECT * FROM urls");
$num_rows = mysql_num_rows($result);
$number = $num_rows;
$english_format_number = number_format($number);
echo $english_format_number;

mysql_close($conn);
?>
14 changes: 14 additions & 0 deletions db/library/urlshort/upload/includes/footer.php
@@ -0,0 +1,14 @@
<h4><a href="<?php include 'install_path.php'; echo $install_path; ?>">Home</a> &middot; <a href="<?php include 'install_path.php'; echo $install_path; ?>api">API</a> &middot; <a href="<?php include 'install_path.php'; echo $install_path; ?>boo">Bookmarklet</a> &middot; <a href="#" onclick="if(GSFN) GSFN.show(); return false">Feedback</a><br/><a href="http://urlshort.sourceforge.net/">urlShort</a> is released under the GNU GPL by <a href="http://mavrev.com">Maverick Revolution</a><br/><a href="http://sourceforge.net/projects/urlshort"><img src="http://sflogo.sourceforge.net/sflogo.php?group_id=257180&amp;type=13" width="120" height="30" border="0" alt="Get urlShort at SourceForge.net. Fast, secure and Free Open Source software downloads" /></a></h4>

<style type='text/css'>@import url('http://s3.amazonaws.com/getsatisfaction.com/feedback/feedback.css');</style>
<script src='http://s3.amazonaws.com/getsatisfaction.com/feedback/feedback.js' type='text/javascript'></script>
<script type="text/javascript" charset="utf-8">
var tab_options = {}
tab_options.placement = "hidden"; // left, right, bottom, hidden
tab_options.color = "#eee"; // hex (#FF0000) or color (red)
GSFN.feedback('http://getsatisfaction.com/mavrev/feedback/topics/new?display=overlay&style=idea', tab_options);
</script>

</body>

</html>

0 comments on commit a8cf463

Please sign in to comment.