PDA

View Full Version : Resolved rssdisplaybox Fatal error: Call to a member function set_feed_url()



student101
06-14-2018, 11:59 AM
1) Script Title:
rssdisplaybox

2) Script URL (on DD):
http://www.dynamicdrive.com/dynamicindex18/rssdisplaybox/

3) Describe problem:

I kept getting location of cache folder errors
now the local errors are

PHP Fatal error: Call to a member function get_permalink() on a non-object in outputbody.php on line 11

the online errors
rssdisplaybox (http://dentonmedia.co.za/rssdisplaybox/)
or
demo (http://dentonmedia.co.za/rssdisplaybox/demo.htm)


Fatal error: Call to a member function set_feed_url() on null in

Any ideas or fix? please

DyDr
06-14-2018, 03:35 PM
The first (local) error is because $item is a value but it isn't an object. The next (online) errors are because $feed is a null value. Posting your custom outputbody.php and main.php code and what version of SimplePie would help.

These errors are related to the SimplePie php statements. It would take someone familiar with SimplePie to directly help (I stopped looking at the code after scrolling through the 2nd 3000+ line file.) You could ask on the SimplePie support forum.

I did see that the code is using indirect (variable) referencing. This is one of the things that changed in php7. What version of php are you using on the online system, as this code may need to be updated to run under php7, so that it returns the correct values to the calling code?

Edit: and since you are getting different errors on your local and online systems, what php version are you using on your local system?

student101
06-15-2018, 07:08 AM
Thanks for your reply!

Online
PHP 5.6.36

Local with XAMPP
PHP 5.4.19




************************************************************
- Dynamic Drive note: This version of SimplePie contained inside rssdisplaybox.zip is 1.0 beta3.2, downloaded Dec 2nd, 2006
- /demo/ directory removed from default package
- SimplePie site: http://simplepie.org
************************************************************

original rssdisplaybox with simplepie.inc (http://dentonmedia.co.za/rssdisplaybox1/demo.htm)


Deprecated: Non-static method SimplePie_Misc::fix_protocol() should not be called statically, assuming $this from incompatible context in

main.php (dentonmedia.co.za/rssdisplaybox1/rssbox/main.php)

<?php
//Function for ouputting the body of each RSS item displayed (inside loop)- DynamicDrive.com

require('../simplepie/simplepie.inc'); //Specify path to simplepie.inc on your server (by default located inside "simplepie" directory)
$feed = new SimplePie();
$feed->cache_location('cache'); //Specify path to cache directory on your server relative to this file
$feed->handle_content_type();
require('outputbody.php'); //Path to custom "outputbody.php" file relative to this file

//Specify list of RSS URLs
$rsslist=array(
"cssdrive" => "http://www.cssdrive.com/index.php/news/rss_2.0/",
"bbc" => "http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/front_page/rss.xml",
"nytimes" => "http://www.nytimes.com/services/xml/rss/nyt/HomePage.xml",
"dynamicdrive" => "http://www.dynamicdrive.com/export.php?type=new" //no trailing comma after last RSS URL!!
);

////Beginners don't need to configure past here. Edit outputbody.php to format the output of each RSS item's body ////////////////////

$rssid=$_GET['id'];
$rssurl=isset($rsslist[$rssid])? $rsslist[$rssid] : die("<b>Error:</b> Can't find requested RSS in list.");
$cachetime=isset($_GET["cachetime"])? (int)$_GET["cachetime"] : 30; //Get cachetime. Default to 30 if not specified
$feednumber=isset($_GET["limit"])? (int)$_GET["limit"] : ""; //Get number of items to fetch. If not specified (""), all is fetched.

$templatename=isset($_GET["template"])? $_GET["template"] : ""; //get name of template, which is used by if/else logic within function outputbody()
if ($templatename!="" && !preg_match("/^(\w|-)+$/i", $templatename)) //Template name can only contain alphanumeric characters, underscore or dash (-)
die ("<b>Error:</b> Template name can only consist of alphanumeric characters, underscore or dash");

$feed->cache_max_minutes($cachetime);
$feed->feed_url($rssurl);
$feed->init();
$max = $feed->get_item_quantity($feednumber);


function outputitems(){
global $feed, $feednumber, $templatename;
$max = $feed->get_item_quantity($feednumber);
for ($x = 0; $x < $max; $x++){
$item = $feed->get_item($x);
outputbody($item, $templatename); //call custom outputbody() function
}
}

?>
<?php
if ($feed->data){
outputitems();
}
?>


Error: Can't find requested RSS in list.

outputbody.php (dentonmedia.co.za/rssdisplaybox1/rssbox/outputbody.php)

<?
//Function for ouputting the body of each RSS item displayed (inside loop)- DynamicDrive.com
//For syntax pf bpdu, see: http://simplepie.org/docs/installation/from-scratch/ and http://simplepie.org/docs/reference/
//Function by default defines 3 different body outputs (templates). Modify or add additional templates as desired


function outputbody($item, $template=""){
if ($template=="" || $template=="default"){ //DEFAULT TEMPLATE
?>
<DIV class="rsscontainer">
<div class="rsstitle"><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a></div>
<div class="rssdate"><?php echo $item->get_date('d M Y g:i a'); ?></div>
<div class="rssdescription"><?php echo $item->get_description(); ?></div>
</DIV>
<?
} //end default template
else if ($template=="titles"){ //"TITLES" TEMPLATE
?>
<DIV class="rsscontainer">
<div class="rsstitle"><a href="<?php echo $item->get_permalink(); ?>" target="_new"><?php echo $item->get_title(); ?></a></div>
<div>Category: <?php echo $item->get_category(); ?></div>
</DIV>
<?
} //end titles template
else if ($template=="titlesdates"){ //"TITLESDATES" TEMPLATE
?>
<DIV class="rsscontainer">
<span class="rsstitle"><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a></span>
<span class="rssdate"><?php echo $item->get_date('m/d/y g:i a'); ?></span>
</DIV>
<?
} //end titlesdates template
else if ($template=="mytemplatename"){ //"mytemplatename" TEMPLATE
?>
//DEFINE ADDITIONAL CUSTOM TEMPLATE(s) USING SAME LOGIC STRUCTURE AS ABOVE
//For syntax of template body, see SimplePie docs: http://simplepie.org/docs/installation/from-scratch/ and http://simplepie.org/docs/reference/
<?
}




else
die ("No template exists with such name!");
} //Closing function bracket
?>

Blank page






rssdisplaybox with autoloader.php

rssdisplaybox with orginal simplepie 1.5 with autoloader.php (http://dentonmedia.co.za/rssdisplaybox/)
main.php (dentonmedia.co.za/rssdisplaybox/rssbox/main.php)

<?php
//Function for ouputting the body of each RSS item displayed (inside loop)- DynamicDrive.com

require('../simplepie/autoloader.php'); //Specify path to simplepie.inc on your server (by default located inside "simplepie" directory)
$feed = new SimplePie();
$feed->enable_cache(false); //Specify caching true/false (unquoted)
$feed->set_cache_location('../../cache');
//$feed->cache_location('cache'); //Specify path to cache directory on your server relative to this file
$feed->handle_content_type();
require('outputbody.php'); //Path to custom "outputbody.php" file relative to this file

/*$rsslist->set_feed_url('http://simplepie.org/blog/feed/');*/

$rsslist->set_feed_url(array(
"cssdrive" => "http://www.cssdrive.com/index.php/news/rss_2.0/",
"bbc" => "http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/front_page/rss.xml",
"nytimes" => "http://www.nytimes.com/services/xml/rss/nyt/HomePage.xml",
"dynamicdrive" => "http://www.dynamicdrive.com/export.php?type=new" //no trailing comma after last RSS URL!!
));

$feed->set_feed_url(array(
"cssdrive" => "http://www.cssdrive.com/index.php/news/rss_2.0/",
"bbc" => "http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/front_page/rss.xml",
"nytimes" => "http://www.nytimes.com/services/xml/rss/nyt/HomePage.xml",
"dynamicdrive" => "http://www.dynamicdrive.com/export.php?type=new" //no trailing comma after last RSS URL!!
));

////Beginners don't need to configure past here. Edit outputbody.php to format the output of each RSS item's body ////////////////////

$rssid=$_GET['id'];
$rssurl=isset($rsslist[$rssid])? $rsslist[$rssid] : die("<b>Error:</b> Can't find requested RSS in list.");
$cachetime=isset($_GET["cachetime"])? (int)$_GET["cachetime"] : 30; //Get cachetime. Default to 30 if not specified
$feednumber=isset($_GET["limit"])? (int)$_GET["limit"] : ""; //Get number of items to fetch. If not specified (""), all is fetched.

$templatename=isset($_GET["template"])? $_GET["template"] : ""; //get name of template, which is used by if/else logic within function outputbody()
if ($templatename!="" && !preg_match("/^(\w|-)+$/i", $templatename)) //Template name can only contain alphanumeric characters, underscore or dash (-)
die ("<b>Error:</b> Template name can only consist of alphanumeric characters, underscore or dash");

$feed->cache_max_minutes($cachetime);
$feed->feed_url($rssurl);
$feed->init();
$max = $feed->get_item_quantity($feednumber);


function outputitems(){
global $feed, $feednumber, $templatename;
$max = $feed->get_item_quantity($feednumber);
for ($x = 0; $x < $max; $x++){
$item = $feed->get_item($x);
outputbody($item, $templatename); //call custom outputbody() function
}
}

?>

<?php
if ($feed->data){
outputitems();
}
?>


Fatal error: Call to a member function set_feed_url() on null in main.php on line 14
outputbody.php (dentonmedia.co.za/rssdisplaybox/rssbox/outputbody.php)

same as outputbody.php

Blank page

student101
06-15-2018, 07:11 AM
installing new xampp with php 7 to test

DyDr
06-15-2018, 04:50 PM
For the code using the latest SimplePie version, this is nonsense logic.

$feed is the instance of SimplePie. You would call the SimplePie methods using $feed->method_name_here...()

$rsslist should be an array of the rss feed ids and urls, like in the 1st code. The rest of the code should get the appropriate URL from the $rsslist array and call the SimplePie methods with that URL.

AFAIK, to convert the 1st code to use the latest SimplePie, after you make the autoloader change, you should only need to change the names of the SimplePie methods that are being called. I don't specifically know what these are, but I did see a list of old/new names on the SimplePie web site. The logic being used in the 1st code, related to $feed and $rsslist should remain the same.

Edit: The blank page may be due to the errors occurring in the code, but could be due to the short opening php tags - <? You should always use full opening php tags - <?php

student101
06-16-2018, 05:29 PM
WORKING!!

Thanks ALL for your help here!!



Commented out the orange all working



$rssid=$_GET['id'];
//$rssurl=isset($rsslist->$rssid)? $rsslist->$rssid : die("<b>Error:</b> Can't find requested RSS in list.");
$cachetime=isset($_GET["cachetime"])? (int)$_GET["cachetime"] : 30; //Get cachetime. Default to 30 if not specified
$feednumber=isset($_GET["limit"])? (int)$_GET["limit"] : ""; //Get number of items to fetch. If not specified (""), all is fetched.

$templatename=isset($_GET["template"])? $_GET["template"] : ""; //get name of template, which is used by if/else logic within function outputbody()
if ($templatename!="" && !preg_match("/^(\w|-)+$/i", $templatename)) //Template name can only contain alphanumeric characters, underscore or dash (-)
die ("<b>Error:</b> Template name can only consist of alphanumeric characters, underscore or dash");

//$rsslist->cache_max_minutes($cachetime);
//$rsslist->feed_url($rssurl);
$rsslist->init();
$max = $rsslist->get_item_quantity($feednumber);

?>