<?php
/*****************************************************************
Addon Name: sNews 1.7 shortlink fetcher
Description: Get the ShortURL for an sNews article or page
Version: 1.0.0
Released: 9:06 AM Thursday, May 19, 2011
Author: Matt Jones
Author URI: http://mdj.us/
License: Creative Commons Attribution-Share Alike 3.0 United States License
License URI: http://creativecommons.org/licenses/by-sa/3.0/us/
*****************************************************************/

// EDIT THE DATABASE VARIABLES BELOW TO SUIT YOUR SITE
$server = 'localhost';
$dbuser = '';
$dbpass = '';
$dbname = '';
$dbprefix = '';


/*****************************************************************
DO NOT EDIT BELOW UNLESS YOU KNOW WHATCHA DO'N :)
*****************************************************************/

define('_PRE',$dbprefix);
$conn = mysql_connect($server,$dbuser,$dbpass) or die(mysql_error());
mysql_select_db($dbname,$conn);

$geturl = rtrim($_GET['url'],"/");
$bits =  explode("/",$geturl);
$count = count($bits);


$url = $bits[$count-1];

if(get_magic_quotes_gpc()) {
    $url = stripslashes($url);
}
$url = mysql_real_escape_string($url);

$query = 'SELECT id FROM '._PRE.'articles WHERE SEFtitle = \''.$url.'\'';
$result = mysql_query($query);
if (mysql_num_rows($result) != '1') {
    die('URL not found!');
} else {
    $row = mysql_fetch_row($result);
    header("Content-Type: text/plain");
    echo 'http://'.$_SERVER['SERVER_NAME'].'/'.$row[0];
    exit;
}
?>