<?

/*************************************************************************\

  PHP HotScripts.com class. Retrieves project rating, votes and hits.
  Copyright (C) 2001 - Paul Gareau <paul@xhawk.net>

  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

\*************************************************************************/

class hotscripts
{
    var $rating;
    var $votes;
    var $hits;
    var $page;

    /**
     * Object constructor: Set rating, votes and hits from hotscripts.com detail page
     *
     * @param    $id (int) project id
     * @return    nothing
     * @author    Paul Gareau <paul@xhawk.net>
     */

    function hotscripts($id)
    {
        $this->page = "http://www.hotscripts.com/Detailed/$id.html";
        $page = fopen ("$this->page", "r");

        while (! feof($page))
        {
            $line = fgets($page, 15360); // read first 15k

            if (eregi("Hits:(.+[^(</td>)])</td>", $line, $out))
            {
                $this->hits = trim($out[1]);
            }
            if (eregi("<b>(.+)</b> \(out of 5\)", $line, $out))
            {
                $this->rating = trim($out[1]);
            }

            // this is the last thing to check for so we break when we find it
            if (eregi("Number of Ratings:(.+)Votes", $line, $out))
            {
                $this->votes = trim($out[1]);
                break;
            }
        }
        fclose($page);
    }

    /**
     * Display results in html table matching hotscripts.com theme
     *
     * @param    none
     * @return    $html (string) html to display results
     * @author    Paul Gareau <paul@xhawk.net>
     */

    function display()
    {
        $rating = ($this->rating) ? $this->rating.'/5' : 'Not yet rated';
        $votes = ($this->votes) ? $this->votes : 0;
        $hits = ($this->hits) ? $this->hits : 0;

        $html = "
                <table border=\"0\" cellPadding=\"1\" cellSpacing=\"0\" BGCOLOR=\"#800000\" width=\"140\"><tr><td>
                <font face=\"verdana,arial,helvetica\" size=\"2\" color=\"#ffffff\">
                <a href='$this->page' style='text-decoration: none; color: white'><b>HotScripts.com</b></a>
                </font>
                </td></tr><tr><td>
                <table border=\"0\" cellPadding=\"2\" cellSpacing=\"0\" width=\"100%\">
                <tr><td BGCOLOR=\"#FFFFDF\"><font face=\"arial,verdana,helvetica\" size=\"2\" color='#000000'><b>Rating:</b></font></td>
                <td BGCOLOR=\"#FFFFDF\"><font face=\"arial,verdana,helvetica\" size=\"2\" color='#000000'>$rating</font></td></tr>
                <tr><td BGCOLOR=\"#FFFFDF\"><font face=\"arial,verdana,helvetica\" size=\"2\" color='#000000'><b>Votes:</b></font></td>
                <td BGCOLOR=\"#FFFFDF\"><font face=\"arial,verdana,helvetica\" size=\"2\" color='#000000'>$votes</font></td></tr>
                <tr><td BGCOLOR=\"#FFFFDF\"><font face=\"arial,verdana,helvetica\" size=\"2\" color='#000000'><b>Hits:</b></font></td>
                <td BGCOLOR=\"#FFFFDF\"><font face=\"arial,verdana,helvetica\" size=\"2\" color='#000000'>$hits</font></td></tr>
                </td></tr></table>
                </td></tr></table>
                ";

        return $html;
    }
}

?>
