We had to bring down this service due to abuse.
<?php
/*
ItsyBitsy URLs - an easy way to shrink down very large URLs
Copyright (C) 2006 OpenConcept Consulting (mike@openconcept.ca)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.`
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// Make sure there aren't duplicates
global $run_once;
$bity = (!empty($_GET['bity'])) ? $_GET['bity'] : '';
$public = (!empty($_GET['public'])) ? 1 : 0;
if (!empty(
$bity) && !preg_match("/^(http(s?):\/\/|ftp:\/\/{1})/i", $bity)) {
if (!isset($run_once)) drupal_set_message(t('the URL is invalid'), 'error');
$validURL = false;
$bity = 'http://' . str_replace(array('http://///','http:////','http:///','http://','http:/','http:','htp:///','htp://','htp:/','htp:','htttp:///','htttp://','htttp:/','htttp:'), '', $bity);
} else {
$validURL = true;
}
// Would need to use callback features -- must make module
// $itsy_url_code = arg(2);
$itsy_url_code = (!empty($_GET['bitsy'])) ? $_GET['bitsy'] : $_GET['b'];
?>
<p>Take any long, ugly URL you like and insert it into the form below, then hit the shrink button:</p>
<form action="ity" method="get">
<label for="bity"><strong>Enter your url:</strong></label><br />
<input name="bity" id="bity" type="text" value="<?php echo (!empty($bity)) ? $bity : 'Add your link here!' ?>" size="30" onfocus="if(this.value=='Add your link here!')this.value='';" onblur="if(this.value=='')this.value='Add your link here!';" />
<br /><label class="option"><input type="checkbox" class="form-checkbox" name="public" id="public-status" value="1" checked="checked" /> Public</label>
<input type="submit" name="submit" value="Shrink!" />
</form>
<?php
// global $base_url;
$base_url_redirect = 'http://ox.ca';
if (!empty(
$bity) && $validURL) {
$result = db_query("SELECT url_id, count FROM {itybity}
WHERE url='%s'", $bity);
if (
$found = db_fetch_object($result)) {
$itsy_url = base_convert($found->url_id, 10, 32);
// echo "<p>Itsy Bitsy URL: " . $base_url_redirect . "/itsy?bitsy=$itsy_url </p>";
$shortest_url = $base_url_redirect . '/' . $itsy_url;
echo "<p><strong>Smallest URL: <a xhref=\"$shortest_url\">$shortest_url</strong></p>";
if (!isset(
$run_once)) {
db_query("UPDATE {itybity} SET count=%d, modified=%d WHERE url ='%s'", $found->count+ 1, time(), $bity);
}
} else {
global
$user;
db_query("INSERT INTO {itybity} (url_id, url, created, modified, uid, public)
VALUES('', '%s', '%d', '%d', '%d', '%d')", $bity, time(), time(), $user->uid, $public);
$result = db_query("SELECT url_id FROM {itybity}
WHERE url='%s'", $bity);
if (
$url_id = db_fetch_object($result)) {
$itsy_url = base_convert($url_id->url_id, 10, 32);
// echo "<p>Itsy Bitsy URL: " . $base_url_redirect . "/itsy?bitsy=$itsy_url </p>";
$shortest_url = $base_url_redirect . "/$itsy_url";
echo "<p><strong>Smallest URL: <a xhref=\"$shortest_url\">$shortest_url</strong></p>";
}
}
}
if (!empty(
$itsy_url_code) && !isset($run_once)) {
$url_id = base_convert($itsy_url_code, 32, 10);
$result = db_query("SELECT url, hits FROM {itybity}
WHERE url_id=%d", $url_id);
if (
$found = db_fetch_object($result)) {
db_query("UPDATE {itybity} SET hits=%d WHERE url_id=%d", $found->hits+1);
header('Location: ' . $found->url);
}
}
if (!isset(
$run_once)) { $run_once = true; }
?>
<p align="right"><a xhref="http://www.openconcept.ca/itsy_bitsy_url_source">Source Code</a></p>
?>CREATE TABLE `itybity` ( `url_id` int(11) unsigned NOT NULL auto_increment, `url` text NOT NULL, `created` int(11) unsigned NOT NULL default '0', `modified` int(11) unsigned NOT NULL default '0', `count` int(11) unsigned NOT NULL default '0', `hits` int(11) unsigned NOT NULL default '0', `uid` int(6) unsigned NOT NULL default '0', `public` tinyint(1) NOT NULL default '0', PRIMARY KEY (`url_id`), KEY `url` (`url`(50)) ) ENGINE=MyISAM DEFAULT CHARSET=utf8;



Add new comment