I run a mp3 search engine site.I use beemp3 recent searches on my site footer.However it works but after sometime I get error.
I get this error "Fatal error: Call to a member function find() on a non-object in /home/xxxxx/public_html/xxxx/xxxx/includes/functions.php on line 178"
here what i have in functions.php
<?
#################################################################
#Creator: Hav
#
###############################################################
function insert_dl($name, $url) {
$name = mysql_real_escape_string($name);
$url = mysql_real_escape_string($url);
$query = "INSERT INTO downloads SET name = '".$name."', url = '".$url."', ip = '".$_SERVER['REMOTE_ADDR']."'";
mysql_query($query) or die(mysql_error());
}
function getfilesize($url)
{
$ary_header = get_headers($url, 1);
$filesize = $ary_header['Content-Length'];
if (is_array($filesize))
{
$return = $filesize[1];
}
else
{
$return = $filesize;
}
return $return;
}
function expstr($content, $start, $end)
{
if ($content && $start && $end)
{
$r = explode($start, $content);
if (isset($r[1]))
{
$r = explode($end, $r[1]);
return $r[0];
}
return '';
}
}
function seoit($string)
{
$string = str_replace(' ', '-', $string);
$string = trim($string);
$string = strtolower($string);
$string = preg_replace("/[^a-zA-Z0-9\s-]/", "", $string);
return $string;
}
if (!function_exists("openurl")) {
include dirname(__FILE__) . "/Snoopy.class.php";
function openurl($url, $referer = "http://www.google.com/firefox?client=firefox-a&rls=org.mozilla:fr:official"){
$snoopy = new Snoopy;
$snoopy->agent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.9.1.7) Gecko Firefox/3.5.7";
$snoopy->referer = $referer;
if ($snoopy->fetch($url)){
return $snoopy->results;
} else {
return false;
}
}
}
function get_redirect_url($url){
$redirect_url = null;
$url_parts = @parse_url($url);
if (!$url_parts) return false;
if (!isset($url_parts['host'])) return false;
if (!isset($url_parts['path'])) $url_parts['path'] = '/';
$sock = fsockopen($url_parts['host'], (isset($url_parts['port']) ? (int)$url_parts['port'] : 80), $errno, $errstr, 30);
if (!$sock) return false;
$request = "HEAD " . $url_parts['path'] . (isset($url_parts['query']) ? '?'.$url_parts['query'] : '') . " HTTP/1.1\r\n";
$request .= 'Host: ' . $url_parts['host'] . "\r\n";
$request .= "Connection: Close\r\n\r\n";
fwrite($sock, $request);
$response = '';
while(!feof($sock)) $response .= fread($sock, 8192);
fclose($sock);
if (preg_match('/^Location: (.+?)$/m', $response, $matches)){
return trim($matches[1]);
} else {
return false;
}
}
function get_all_redirects($url){
$redirects = array();
while ($newurl = get_redirect_url($url)){
if (in_array($newurl, $redirects)){
break;
}
$redirects[] = $newurl;
$url = $newurl;
}
return $redirects;
}
function get_final_url($url){
$redirects = get_all_redirects($url);
if (count($redirects)>0){
return array_pop($redirects);
} else {
return $url;
}
}
function run_results($search, $page, $type) {
include dirname(__FILE__)."/../config.php";
$total_results = 0;
foreach ($settings['sources'] as $source) {
include dirname(__FILE__)."/../sources/".$source;
}
}
function display_related($search, $limit) {
include dirname(__FILE__)."/../config.php";
$html = @file_get_html('http://beemp3.com/index.php?st=all&q='.str_replace(' ', '+', $search));
$related_area = $html->find('p[class="related"]', 0);
if (isset($related_area)) {
$related= $related_area->find('a');
$count = 0;
foreach ($related as $onesearch) {
$onesearch = expstr($onesearch, '>', '<');
$onesearch2 = seoit($onesearch);
echo '<a href="'.WEB_PATH.'search/mp3/1/'.$onesearch2.'.html" title="'.preg_replace("/[^a-zA-Z0-9\s]/", "", $onesearch).' free mp3 downloads">'.$onesearch.'</a>';
$count++;
if ($count >= $limit) { break; } else { echo ' - ';}
}
}
}
function enc($string)
{
include dirname(__FILE__)."/../config.php";
require_once dirname(__FILE__)."/crypt.php";
$crypt=new crypt($settings['encrypt_key']);
$enc = $crypt->enc($string);
return $enc;
}
function dec($string)
{
include dirname(__FILE__)."/../config.php";
require_once dirname(__FILE__)."/crypt.php";
$crypt=new crypt($settings['encrypt_key']);
$dec = $crypt->dec($string);
return $dec;
}
function beemp3200($limit) {
$html = @file_get_html('http://beemp3.com/');
$last200area = $html->find('div[class="last200"]', 0);
this is line 178-----> $last200 = $last200area->find('a');
if (!isset($limit)) {
$limit = $settings['recentlimit'];
}
$count = 0;
foreach ($last200 as $onesearch) {
$onesearch = expstr($onesearch, '>', '<');
$onesearch2 = seoit($onesearch);
echo '<a href="'.WEB_PATH.'search/mp3/1/'.$onesearch2.'.html" title="'.preg_replace("/[^a-zA-Z0-9\s]/", "", $onesearch).' free mp3 download">'.$onesearch.'</a>';
$count++;
if ($count >= $limit) { break; } else { echo ' - ';}
}
}
function add_tag($tag) {
include dirname(__FILE__)."/../db.php";
mysql_query("INSERT INTO searches SET search = '".mysql_escape_string($tag)."'") or die(mysql_error());
}
?>
this is line 178-----> $last200 = $last200area->find('a');
and I use in Footer as
<div class="last200">
<?
if (($home !== 'true') && ($settings['last20'] == 'true')) {
$limit = '150';
} else {
$limit = $settings['recentlimit'];
}
if ($settings['beemp3200'] == 'true') {
echo '<b><center>Last '.$limit.' MP3 Searches</center></b>';
beemp3200($limit);
} else {
$q4 = mysql_query("SELECT DISTINCT search FROM searches ORDER by search_id DESC LIMIT $limit");
$i = 1;
while($tags = mysql_fetch_array($q4)) {
$tag = $tags[search];
$tag = seoit($tag);
$tag_name = $tags[search];
$tag_name = ucwords($tag_name);
?>
Please help to fix..
Edited by Shrinath, 16 May 2011 - 10:53 AM.













