Mike Gifford's profile picture

Mike Gifford is the founder of OpenConcept Consulting Inc, which he started in 1999. Since then, he has been particularly active in developing and extending open source content management systems to allow people to get closer to their content. Before starting OpenConcept, Mike had worked for a number of national NGOs including Oxfam Canada and Friends of the Earth.

As a techie at heart, Mike likes to get into the code when he gets the chance. Being ultimately concerned about the implementation and implications of the technology, he is able to envision how your website can become a much more powerful communications tool for your organization.

Mike has been involved with accessibility issues since the early 1990's and is a strong advocate for standards based design.

iaapbadge.png

Itsy Bitsy URL Source

March 08, 2006

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'];
?>

Take any long, ugly URL you like and insert it into the form below, then hit the shrink button:

Enter your url:
" size="30" onfocus="if(this.value=='Add your link here!')this.value='';" onblur="if(this.value=='')this.value='Add your link here!';" />
Public

<?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 "

Itsy Bitsy URL: " . $base_url_redirect . "/itsy?bitsy=$itsy_url

";
$shortest_url = $base_url_redirect . '/' . $itsy_url;
echo "

Smallest URL: $shortest_url

";

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 "

Itsy Bitsy URL: " . $base_url_redirect . "/itsy?bitsy=$itsy_url

";
$shortest_url = $base_url_redirect . "/$itsy_url";
echo "

Smallest URL: $shortest_url

";

}

}

}

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; }

?>

Source Code



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;