<?php
     
    //misc.php
        
     
    //
    // This function was built for use with the content shard.  It takes an article
    // title and makes it URL friendly ('GeForce 6800 Review' becomes 'GeForce_6800_Review').
    // It's intended to help create more user-friendly URLs, for use with slickurls (see index.php).
    //
    function make_url_friendly($text )
    {
        $url = htmlspecialchars($text , ENT_QUOTES );
        $url = explode(' ' , $url );
        $underscored = implode('_' , $url );
        return $underscored;
    }
     
     
     
     
    function print_timeused($start, $end)
    {
        list($endmsec, $endsec) = explode(" ", $end);
        list($startmsec, $startsec) = explode(" ", $start);
         
        $endvalue = $endsec + $endmsec;
        $startvalue = $startsec + $startmsec;
         
        $period = $endvalue - $startvalue;
         
        print('It took an amazing ');
        printf("%.4f", $period );
        print(' seconds to render this page.  That\'s fast!');
    }
     
     
    function get_numeric_month($month )
    {
        if (strcmp($month, 'January' ) == 0 )
            return 1;
        if (strcmp($month, 'February' ) == 0 )
            return 2;
        if (strcmp($month, 'March' ) == 0 )
            return 3;
        if (strcmp($month, 'April' ) == 0 )
            return 4;
        if (strcmp($month, 'May' ) == 0 )
            return 5;
        if (strcmp($month, 'June' ) == 0 )
            return 6;
        if (strcmp($month, 'July' ) == 0 )
            return 7;
        if (strcmp($month, 'August' ) == 0 )
            return 8;
        if (strcmp($month, 'September' ) == 0 )
            return 9;
        if (strcmp($month, 'October' ) == 0 )
            return 10;
        if (strcmp($month, 'November' ) == 0 )
            return 11;
        if (strcmp($month, 'December' ) == 0 )
            return 12;
    }
     
     
     
    function days_in_month($month, $year)
    {
        if (checkdate($month, 31, $year)) return 31;
        if (checkdate($month, 30, $year)) return 30;
        if (checkdate($month, 29, $year)) return 29;
        if (checkdate($month, 28, $year)) return 28;
        return 0; // error
    }
     
     
     
     
     
     
    function logHit($username, $shard, $action)
    {
        //initialize strings to nothing.  maybe null is better? also i think they are set by default.
        $id = "";
        $addr = "";
        $refer = "";
         
         
         
        // if indices exist set the variables
        if (array_key_exists('HTTP_REFERER' , $_SERVER ) == TRUE )
            $refer = $_SERVER['HTTP_REFERER'];
        if (array_key_exists('ID' , $_REQUEST ) == TRUE )
            $id = $_REQUEST[ 'ID' ];
        if (array_key_exists('REMOTE_ADDR' , $_SERVER ) == TRUE )
        {
            $addr = $_SERVER[ 'REMOTE_ADDR' ];
            $addr = $addr . " (" . gethostbyaddr($addr ) . ")";
        }
        // insert hit tracking information into the database
        $result = mysql_query("insert into hittracker (date, user, referer, shard, action, objectID, userIP)
            VALUES
            ('".time()."', '$username', '$refer', '$shard', '$action', '$id', '$addr')") or die(mysql_error());
    }
     
     
     
