<?php
/****************************************\
* Omnimaga URL Shortener 1.0             *
* For use on omnimaga.org and ourl.ca    *
* By juju2143                            *
\****************************************/
if(isset($_GET['source'])) die(highlight_file(__FILE__true));
?>
<html>
<head>
<title>Omnimaga URL Shortener</title>
</head>
<body>
<h1>Omnimaga URL Shortener</h1>
<form action="" method="POST">
Input Omnimaga URL: <input type="text" name="url" value="<? 
if(isset($_POST['url']))
{
    echo 
$_POST['url'];
}
else
{
    echo 
"http://www.omnimaga.org/index.php?";
}
?>" size="75" />
<br/><button type="submit">Shorten!</button>
</form>
<?php
if(isset($_POST['url']))
{
    
$parts preg_split("/[\/?;&]/"$_POST['url']);
    
$url $_POST['url'];
    if(
$parts[2] == "www.omnimaga.org" || $parts[2] == "omnimaga.org" && $parts[3] == "index.php")
    {
        if(
substr($parts[4], 05) == "topic")
        {
            
$part preg_replace("/.msg/""/"substr($parts[4], 6));
            
$url "http://ourl.ca/".$part;
        }
        elseif(
$parts[4] == "action=dlattach")
        {
            
$url "http://ourl.ca/a/".substr($parts[5], 6, -2)."/".substr($parts[6], 7);
        }
        elseif(
$parts[4] == "action=downloads")
        {
            if(
$parts[5] == "sa=view")
            {
                
$url "http://ourl.ca/f/".substr($parts[6], 5);
            }
            elseif(
$parts[5] == "sa=downfile")
            {
                
$url "http://ourl.ca/d/".substr($parts[6], 3);
            }
        }
    }
    echo 
"<p/>Shortened URL: <input type=\"text\" value=\"".$url."\" onclick=\"this.focus(); this.select()\" size=\"75\" readonly />";
    echo 
"<!--Debug info: <br/><pre>";
    
var_dump($parts);
    echo 
"</pre>-->";
}
?>
<p/><a href="?source">Netham45, feel free to steal my source :)</a> | <a href="http://omnimaga.org">Omnimaga</a>
</body>
</html>