Version: 1.0
Type: Class
Category: Other
License: GNU General Public License
Description: A small and quick class to grab top 10 information from www.musicgrab.com
<?php
#####################################################################################
#####################################################################################
#####################################################################################
#####################################################################################
################### ###################
################### Aces XMMS-PHP MP3 Jukebox v0.1.0 ###################
################### -------------------------------- ###################
################### ###################
################### Based on XMMS-Control by Joe Thielen ###################
################### ###################
################### Designed by Ace (ace_jedi_2k1@hotmail.com) ###################
################### ###################
#####################################################################################
#####################################################################################
#####################################################################################
#####################################################################################
### You may use or modify this program for any non-profit use ###
### as long as there is a the copyright notice displayed in a ###
### comment inside the output html ###
### (i.e. <!-- Generated by XMMS-PHP. ###
### http://bassetts.port5.com (C) Ace 2003 -->) ###
#####################################################################################
#####################################################################################
#####################################################################################
#####################################################################################
### ###
### XMMS-PHP 0.1.0 - PHP-based XMMS control, equalizer and playist manager ###
### Copyright (C) 2003 Ace ###
### ###
### 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. ###
### ###
### Ace <ace_jedi_2k1@hotmail.com> ###
### ###
#####################################################################################
#####################################################################################
#####################################################################################
#####################################################################################
############### ###############
############### Music Grab Class ###############
############### Designed by: Ace. ###############
############### <ace_jedi_2k1@hotmail.com> ###############
############### ###############
#####################################################################################
#####################################################################################
#####################################################################################
#####################################################################################
#### ####
#### Usage Example: ####
#### -------------- ####
#### ####
#### ####
#### require("class.musicgrab.php"); ####
#### ####
#### $musicgrab = new music_grab(); ####
#### $musicgrab->select("musicgrab"); ####
#### // $musicgrab->select("listen"); ####
#### ####
#### $musicgrab->connect(); ####
#### ####
#### $musicgrab->getcontent(); ####
#### ####
#### $musicgrab->disconnect(); ####
#### ####
#### $content = $musicgrab->showcontent(); ####
#### echo $content; ####
#### ####
#### ####
#####################################################################################
#####################################################################################
class music_grab
{
var $file = NULL;
var $servercontent = NULL;
var $content = NULL;
var $rf = NULL;
var $grab = NULL;
var $server = NULL;
var $servertype = NULL;
var $errors = NULL;
var $htmlcontent = NULL;
function select($type)
{
switch ($type)
{
case "listen":
$this->server = "http://www.listen.com/hot2day.jsp";
$this->servertype = "listen";
break;
case "musicgrab":
$this->server = "http://www.musicgrab.com/mp3/info/1/0/count/0/10/index.phtml";
$this->servertype = "musicgrab";
break;
default:
$this->errors[] = "<B>Error while trying to SELECT to unknown site!</B><BR /><OL><LI>Are you sure you are connected to the internet?</LI><LI>Are you sure that you have the correct hostname?</LI><LI>Are you sure that the site exists?</LI></OL>";
}
}
function connect()
{
switch ($this->servertype)
{
case "listen":
if ($this->file = @fopen($this->server, "r"))
{
$this->rf = fread($this->file, 100000);
$this->grab = ereg("<!--key guide end-->(.*)<!--## end variable content section -->", $this->rf, $this->servercontent);
}
else
{
$this->errors[] = "<B>Error while trying to CONNECT to site <URL>http://www.listen.com</URL>!</B><BR /><OL><LI>Are you sure you are connected to the internet?</LI><LI>Are you sure that you have the correct hostname?</LI><LI>Are you sure that the site exists?</LI></OL>";
}
break;
case "musicgrab":
if ($this->file = @fopen($this->server, "r"))
{
$this->rf = fread($this->file, 40000);
//$this->grab = ereg("Title / Artist(.*)Result", $this->rf, $this->servercontent);
$this->grab = ereg("1>(.*)Result", $this->rf, $this->servercontent);
}
else
{
$this->errors[] = "<B>Error while trying to CONNECT to site <URL>http://www.musicgrab.com</URL>!</B><BR /><OL><LI>Are you sure you are connected to the internet?</LI><LI>Are you sure that you have the correct hostname?</LI><LI>Are you sure that the site exists?</LI></OL>";
}
break;
default:
$this->errors[] = "<B>Error while trying to CONNECT to specified site!</B><BR /><OL><LI>Are you sure you specified a site?</LI><LI>Are you sure that you chose a known site?</LI></OL>";
}
}
function getcontent()
{
switch ($this->servertype)
{
case "listen":
$this->content = "<TABLE width=\"100%\" bgcolor=\"eccda4\" border=\"1\" bordercolor=\"2e4d7e\">".$this->servercontent[1];
$this->content = str_replace("</TD></TR></TR>", "", $this->content);
$this->content = str_replace("<A HREF=\"", "<A href=\"http://www.listen.com/", $this->content);
$this->content = str_replace("img/pixel_fw.gif", "http://www.listen.com/img/pixel_fw.gif", $this->content);
$this->content = str_replace("img/g_big.gif", "http://www.listen.com/img/g_big.gif", $this->content);
$this->content = str_replace("img/g_hot.gif", "http://www.listen.com/img/g_hot.gif", $this->content);
$this->content = str_replace("img/g_lpick.gif", "http://www.listen.com/img/g_lpick.gif", $this->content);
$this->content .= "</TABLE>";
break;
case "musicgrab":
$this->content = "<FONT face=\"HELVETICA\">1>".$this->servercontent[1];
$this->content = str_replace("1> </SPAN></TD>", "<OL>", $this->content);
$this->content = $this->content."<delimitator></FONT></OL>";
$this->content = str_replace("<TD><SPAN class=\"pagelinktext\">", "<LI>", $this->content);
$this->content = str_replace("</SPAN><SPAN class=\"resultsmall\">", "<FONT size=\"-1\">", $this->content);
$this->content = str_replace(" </SPAN></TD>", "</FONT><UL><LI>", $this->content);
$this->content = str_replace("<TD align=\"right\" nowrap>", "<FONT size=\"-1\">", $this->content);
$this->content = str_replace("</SPAN></TD>", "</FONT>", $this->content);
$this->content = str_replace("</TR>", "</UL>", $this->content);
$this->content = str_replace("<TR valign=\"top\">", "", $this->content);
$this->content = str_replace("<TD align=\"right\"><SPAN class=\"resultnum\">", "", $this->content);
$this->content = str_replace("2> </FONT>", "", $this->content);
$this->content = str_replace("3> </FONT>", "", $this->content);
$this->content = str_replace("4> </FONT>", "", $this->content);
$this->content = str_replace("5> </FONT>", "", $this->content);
$this->content = str_replace("6> </FONT>", "", $this->content);
$this->content = str_replace("7> </FONT>", "", $this->content);
$this->content = str_replace("8> </FONT>", "", $this->content);
$this->content = str_replace("9> </FONT>", "", $this->content);
$this->content = str_replace("10> </FONT>", "", $this->content);
$this->content = str_replace("<A href=\"", "<A href=\"http://www.musicgrab.com/", $this->content);
$this->content = str_replace("onmouseout=\"self.status=''\"", "target=\"_new\"", $this->content);
$this->content = eregi_replace("</TABLE>(.*)<delimitator>","", $this->content);
break;
default:
$this->errors[] = "<B>Error while trying to CONNECT to specified site!</B><BR /><OL><LI>Are you sure you specified a site?</LI><LI>Are you sure that you chose a known site?</LI></OL>";
break;
}
}
function disconnect()
{
if ($this->file)
{
fclose($file);
}
else
{
switch($this->servertype)
{
case "listen":
$this->errors[] = "<B>Error while trying to DISCONNECT from <URL>http://www.listen.com</URL>!</B><BR /><OL><LI>Are you sure that the script CONNECTed properly?</LI><LI>Are you sure you specified a site?</LI><LI>Are you sure that you chose a known site?</LI></OL>";
break;
case "musicgrab":
$this->errors[] = "<B>Error while trying to DISCONNECT from <URL>http://www.musicgrab.com</URL>!</B><BR /><OL><LI>Are you sure that the script CONNECTed properly?</LI><LI>Are you sure you specified a site?</LI><LI>Are you sure that you chose a known site?</LI></OL>";
break;
default:
$this->errors[] = "<B>Error while trying to DISCONNECT from a non-existent connection!</B><BR /><OL><LI>Are you sure that the script CONNECTed properly?</LI><LI>Are you sure you specified a site?</LI><LI>Are you sure that you chose a known site?</LI></OL>";
break;
}
}
}
function showcontent()
{
if ($this->content)
{
return "<BR />".$this->content."<BR />";
}
else
{
$this->errors[] = "<B>No content was returned!</B><BR /><OL><LI>Are you sure that you ran '$musicgrab->select(\"siteidentifier\");', '$musicgrab->connect();', '$musicgrab->getcontent();' and '$musicgrab->disconnect();'?</LI><LI>Are you sure you specified a site?</LI><LI>Are you sure that you chose a known site?</LI></OL>";
}
}
function showerrors()
{
if ($this->errors)
{
if (sizeof($this->errors) > 0)
{
$this->htmlcontent .= "<OL>";
foreach ($this->errors as $error)
{
$this->htmlcontent .= "<LI>".$error."</LI>";
}
$this->htmlcontent .= "</OL>";
}
return "<BLOCKQUOTE><FONT face=\"arial\" size=\"2\" color=\"ff0000\">".
"<B>".count($this->errors)." Errors Caught --</B> ".
"[<FONT color=\"000077\">".$this->htmlcontent."</FONT>]".
"</FONT></BLOCKQUOTE>";
}
}
}
?>