PDA

View Full Version : RSS Display Box and adding copyright to output file



ajfmrf
01-08-2011, 06:38 AM
RSS Display Box

http://www.dynamicdrive.com/dynamicindex18/rssdisplaybox/index.htm

http://web-user.net/rss/grail3.html

http://web-user.net/rss/rssbox/outputbody.php

I have been trying to add one thing to my feeds,copyright ,info.Every attemp has failed.I have read the simplepie sites info and have been unable to get it to show this information.

This is the output page.http://web-user.net/rss/rssbox/outputbody.php

Could someone help me out before I implode-lol

Also, a quick question.Is there any sample templates for people to look at to get an idea as to what we can do with this script?

I really like this script and am working on redoing the site design to make it more unique.http://web-user.net/rss/grail3.html

Thanks, in advance for the help.

Bud:)

jscheuer1
01-08-2011, 01:21 PM
First of all, I don't know if this is your intention, but you cannot copyright material from a feed other than your own. It's already copyright by them or from the source from which they got it. Unless they require a notice to that effect, you need not bother supplying it. A single statement on the 'top' page that all material is copyright its respective copyright holders is sufficient.

Second, the error is on web-user.net/rss/rssbox/outputbody.php. Since it's parsed by the server before we get to see it, we cannot see or fix its PHP code unless you make a copy of that file as outputbody.txt and provide a link to it. If it has any included code, we may need to see that in text form as well.

ajfmrf
01-10-2011, 12:55 AM
I am trying to get the output copyright from the feed for the source of the feed.Not to copyright the feed for myself.

http://web-user.net/rss/rssbox/outputbody.txt

I tried this and then removed the line
<div class="rsscopyright"><?php echo $feed->get_copyright(); ?></div>

which did not work.:confused:

I have tried a few different versions but nothing works.

Thanks,
Bud

ajfmrf
01-10-2011, 01:01 AM
Such as the date , time and publisher.

I do not see any place that gives information as to how to add to the template to get any more info from the feeds.

I am real new to this so I hope you don't get annoyed with my questions.

Thanks,
Bud

jscheuer1
01-10-2011, 04:04 AM
If I'm annoyed, it's not with you. My tone may have suggested that. If it did I apologize. I was trying to clarify things by making that statement and asking that question. By responding as you did and supplying the text version of the file you have helped clear things up for me. Thank You.

Looking at the file in text form, it's obviously an indirect include for simplepie.inc which has things like:


get_title()
get_description()

etc. defined for any given item. get_copyright() is not defined for the feed, and the feed ($feed) is not passed to outputbody.php anyway. There is a get_feed_copyright() defined for the feed though.

Now, I don't know a whole lot more about PHP than you do, but some. And I do understand scripted languages in general fairly well.

I found that by editing outputbody.php to include the highlighted:


<?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="", $feed){
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 class="rsscopy"><?php echo $feed->get_feed_copyright(); ?></div>
</DIV>
<?php
} //end default template
else if ($template=="titles"){ //"TITLE . . .

And by editing main.php in the same folder around line #40 (near the end) to include the highlighted:


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, $feed); //call custom outputbody() function
}
}

It worked for the demo's NYT feed and caused no error for those feeds that had no copyright data.

It did however attach the copyright info to each item, rather than just once at the end of the feed. Doing the latter is possible, I'm just not sure of the best way to go about it at the moment.

ajfmrf
01-11-2011, 12:05 AM
I will try the code adjustments you posted.

I did not mean to imply you were annoyed John.I apologize for making you feel as if you came across that way.

I have found in the past when I go and ask a question once or twice in a forum that I ,being a novice , sometimes ask too many questions and get a negative response so I just try to break the ice so to speak and make sure I am not annoying anyone lol

Sometimes an answer is right in front of me but I can't see it because I am so focused on getting something to work that I miss a teeny,tiny thing and thats annoying to me-lol

I do appreciate your help John and if I can ever help you ,just holler at me.

Thanks,

Bud

ajfmrf
01-11-2011, 12:48 AM
You are completely right John .

I worked as you described.

I tried to get a couple of other "things" and got errors again.

I will keep trying and I am sure due to your help at some point I will figure it out.

You would think it would all follow the same wording just changing what you want to get from the feeds but I am not getting it so far.

I find that I always have to go the hard,long way to get things to work.Nothing ever comes easy-lol

Bud

ps-I was hoping getting one thing to work would directly lead to adding/changing more but so far just the one has worked-:confused:

jscheuer1
01-11-2011, 02:37 AM
This may not help, but does explain things a bit:

I was looking at these files some more and now see more of what's happening. The central file in a sense is main.php. It includes (requires actually - a more imperative form of the include directive) outputbody.php and simplepie.inc. So all of the functions on simplepie.inc are available to outputbody.php. However, since outputbody.php has a function on it, outputbody() which is called from main.php, only those objects that are passed to that function may be worked with. That's why I had to pass it the $feed object to get the feed function for copyright to work and to have something to work with.

The docs for simplepie are here:

http://simplepie.org/wiki/reference/start

But those are probably not completely accurate because simplepie has been updated since the version used with this script. They will give you some ideas.

There are also simplepie forums, FAQs and how to material, all available at or with their addresses listed on:

http://tech.groups.yahoo.com/group/simplepie-support/

But by just looking at the code in simplepie.inc you should be able to see what's available. If you want to run something in there for outpubody and are having trouble doing so or doing so in the way you want to, let me know. If you want something that's not in there though, we would have to make a custom function for it. I may or may not be able to help with that.

ajfmrf
01-11-2011, 03:48 AM
So if I find something I would like to experiment with,how do I figure out if it will work with the "feed" part you had me add?Is there a way to figure it out or do I have to try and code it?I try to use the "item" already there with what I find at simplepie and nothing worked but what you did.

I must sound kinda dumb by now,lol:rolleyes:

It is quite confusing on my part so far.I test things by trial and error and always get "error"........

I will try more tomorrow.

Have a great evening John.

Thanks for the help.

Bud

jscheuer1
01-11-2011, 03:21 PM
Well simplepie is organized into sections. There's one section that creates some objects when main.php does:


$feed = new SimplePie();

These objects then all become properties of $feed for that feed.

The SimplePie() function itself is so complex that perhaps not all of its objects become accessible objects of $feed for that feed, but a lot of them do.

The main.php file uses this fact to get the items when it later does:


<?php . . .
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, $feed); //call custom outputbody() function
}
}

?>

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

?>

I simply passed along the $feed so I could use its:


function get_feed_copyright()
{
if (!empty($this->data['info']['copyright']))
{
return $this->data['info']['copyright'];
}
else
{
return false;
}
}

to get the copyright info in outputbody.

There are a lot of these functions you can use in simplepie. Do a search on simplepie.inc for:


function get_feed_

to turn up six I'm sure you can use. These are all in the init() function of the SimplePie() function and should be available to $feed on outbody in our current modified version as should their neighbors in that section. However the ones that aren't get_feed_something might not be all that useful and might cause problems.

On to the functions that can be used with $item. These are all in the section:


class SimplePie_Item

Those which aren't get_something might not be all that useful and might cause problems.

It's likely that in either of these sections we could add get functions if we know the structure of the feed or item well enough to write our get function to look in the right place in the $feed or $item objects respectively. That in combination with following the template of the other get functions should allow us to do this. If we do that correctly and a given feed or item has that information, we can make outputbody use that function to output that information following the template on outbody.php already established with:


<?php echo $item->get_title(); ?>

for items and now:


<?php echo $feed->get_feed_copyright(); ?>

for the feed.

The bottom line though is that we cannot use what isn't there in the simplepie.inc file. Even if it is there, we need to be careful what we do with it if it isn't just a get for fear of messing up the item or the feed in mid parse by outputbody. And, as I say, not all functions are available to all objects, just the ones that were created for those objects in simplepie.inc

ajfmrf
01-14-2011, 03:00 AM
Ok, John,maybe you can tell if I am doing something wrong or is firefox my problem.........

I tried two example pages from simplepie and they did not work for me.Here are the pages I made using html and php files ( figured I had it wrong because one did not work.I included the page at Simplepie where I got the pages. and both of my files.

Note, the only difference in my two files in each case is the file type.- php or html-otherwise they are the exact same thing.


example 1

http://simplepie.org/wiki/tutorial/how_to_display_previous_feed_items_like_google_reader

my files:
http://web-user.net/rss/111.php
or
http://web-user.net/rss/111.html




example 2

http://simplepie.org/wiki/setup/sample_page

http://web-user.net/rss/atest.html
http://web-user.net/rss/atest.php

jscheuer1
01-14-2011, 04:41 AM
That's not the rss box script. Start a new thread in the PHP section.


I can tell you that the .html files are showing PHP code as text, so they are obviously meant to be .php pages.

It's the .php files that are most illuminating (web-user.net/rss/111.php):



Warning: require(simplepie.inc) [function.require]: failed to open stream: No such file or directory in /home/bud/public_html/rss/111.php on line 26

Warning: require(simplepie.inc) [function.require]: failed to open stream: No such file or directory in /home/bud/public_html/rss/111.php on line 26

Fatal error: require() [function.require]: Failed opening required 'simplepie.inc' (include_path='.:/usr/lib/php:/usr/local/lib/php:/home/bud/php') in /home/bud/public_html/rss/111.php on line 26

and web-user.net/rss/atest.php:


Fatal error: Call to undefined method SimplePie::set_feed_url() in /home/bud/public_html/rss/atest.php on line 10

These are all server side errors. As such they have nothing to do with the browser.

ajfmrf
01-17-2011, 02:26 AM
I want to thank you for all of your help .

I am way over my head with this rss feeds and php stuff.

I wanted to include a couple other options to dress up what I have been working on.Nothing much,just to make my site better.

However I see now that this siimplepie/php is extremely complicated for a novice like me.I have been looking to see if there are any simple additions I can add to my templates for the rss display boxes but there is nothing out there to help me.

Everything is more then I can figure out.And I am somewhat disappointed that I can't find anything that I can put to use.

The copyright addition you wrote for me did work but it did so in different ways with different feeds.I will need to take another look at this in more detail to see if it is a worthwhile addition that won't take away from my site.

I will try and find more about this templates and continue to mess with things but it hurts my head to do this-lol

No, but seriously, I hope I can find one or two things to glean from the feeds that will make me happy but so far I have not.

Your patience with me is more then I can thank you for.If I can ever repay the favor, just ask me John, I will happily help you out.

Bud

jscheuer1
01-17-2011, 03:17 AM
Well, I did say the copyright would appear with each item, and that we could change that.

I didn't say something in general that applies to the copyright and all other data from any given feed. You get only what the feed is sending, no more, no less. And of that, only what you ask of it. You can manipulate that data via PHP and/or javascript as long as you know what form the data is in, at least enough to know what you want to pick out and use. Like for copyright, you could substitute the symbol for the word copyright if it exists. But, if there is no copyright data, there's nothing you can do other than make your own copyright notice for that feed.

If there's other data you want to pull from the feeds, let me know. I'll see if it's in simplepie.inc. If it's not there, and you know the xml structure of where it is in the feed, we can probably still get it. But I have to know what it is, and it has to be in the feed.

ajfmrf
02-09-2011, 02:51 AM
display box script was an early version and that there has been an updated version released.

Is it possible to use the new version?

I don't know anything about how this would have to be done(updating the script or the version )???

Any info/insight would be appreiated.

Bud

jscheuer1
02-09-2011, 04:28 PM
In my testing I used the latest version here on Dynamic Drive. If there's a later version somewhere else, you could perhaps use it. But it would no longer be a Dynamic Drive scripts help topic.

This script is authored by Dynamic Drive, so if there is an update of it somewhere else, it's probably either illegal, or a wholly different script.

What script are you talking about?

Or are you talking about the updated simplepie? You could try that. Just keep a backup of your current working version. I did, and in my PHP 5.3.0 it doesn't work at all due to repeated use of:


Assigning the return value of new by reference (deprecated)

If you fix that or are using a pre PHP 5 version, there are other errors, now in main.php.

I can easily trace and fix some of those, but the time involved in getting everything updated would be unwarranted. Notably, the copyright function has become a class and is, for the moment at least for me, opaque as to how to get at it in the updated simplepie.inc.

ajfmrf
02-09-2011, 11:16 PM
You are absolutely right.It is the simplepie that I am refering to not the script itself.

I think is bad business to have scripts as examples that do not work properly.

I am not much good at this stuff( any of it-lol-php,javascript,cgi/perl,) and have to tinker with stuff to get it to do as I want and if I am lucky I can get the desired changes to work.Like the rssdisplay boxes.I really love the way they work and am trying to get a webpage set up that I hope will get a few visits on a regular basis.I have a few but no one visits them but me :(

I like 'creating' web pages but it would be nice to have more visitors then I do - lol

Anyway,yes, I guess it is not worth the trouble to see if updating simple pie does anything or not.

I am sure glad I found this website and forum.

John and the others here are extremely knowledgeable and helpful more then any other place I have gone for help.

I only wish I could be as much help to others here in return.

I have windows 7 and use firefox 3.6.13 and can take a look at things for anyone that needs to know about campatiblity issues.

thanks,

Bud

jscheuer1
02-10-2011, 11:38 AM
There are so many scripts in the Dynamic Drive Library, that it would be an entire career just making sure they were all (where applicable) using the latest available third party code, not to mention most up to date methods internally. Dynamic Drive and it's forums are free services, you cannot expect everything to be state of the art. And I'm not Dynamic Drive and cannot perform those activities with my current level of access.

That said, I just took another look at simplepie 1.2 and the copyright info is actually easier to get at and can be had for each item and failing that, for the feed, or simply skipped if there is no copyright info. However, images (or maybe it's links or both) in the descriptions are now more difficult to get (the 'sanitize' functions have been improved, perhaps a good thing). I'll probably play with that some more. And I would need to pare down the simplepie 1.2 files required, the new distribution on that contains way more files than I'm sure are required for this script.

So far changes to main.php (in several places, as function names have changed, and the cache time in simplepie is now in seconds rather than minutes) and outbody.php (for our new version that includes copyright, same reason, and the copyright function's scope has been expanded, it can now target each item, as well as the feed in general).

When and if I have something more concrete, I'll attach a demo archive.

But using the new simplepie, as it comes in the distribution, that would be removing the contents of the RSS Box's simplepie folder and replacing them with the new simplepie's distribution files in its folder named:

rmccue-SimplePie-9a1ebc0

And you must, if using PHP 5 or greater with warnings enabled, PHP 5.? (I have 5.3, by then the warning becomes an outright error), do a global search and replace on the new simplepie.inc file for:


=& new

replace with:


= new

It's unclear to me if making this change will harm PHP 4.x or not, but apparently leaving it in for those versions is OK.

Here are the modified main and outbody files:

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->set_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->set_cache_duration($cachetime * 60);
$feed->set_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, $feed); //call custom outputbody() function
}
}

?>

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

?>

outputbody.php -

<?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="", $feed){
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 class="rsscopy"><?php echo $item->get_copyright()? $item->get_copyright() : $feed->get_copyright(); ?></div>
</DIV>
<?php
} //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>
<?php
} //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>
<?php
} //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/
<?php
}




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

This thread has been open for some time though, is/are there any feed(s) in particular you're having trouble with?

I figured out how to get images and links (if any) in the descriptions using version 1.2. Use in outputbody.php:


<div class="rssdescription"><?php echo $item->get_content(); ?></div>

instead of:


<div class="rssdescription"><?php echo $item->get_description(); ?></div>

ajfmrf
02-11-2011, 03:58 AM
I tried once to add to a template and got a mess of errors and deleted it completely.

Is there some general rule to making/adding to the templetes ?

I will do the new changes to both files in the next day or two John.

I really do appreciate all the time you are putting into this for me.

I am closing in to the final product of all the questions.requests and help I have asked for and I will send you the results John,if you want to see them before I complete it to see what you think of it.

Thanks,

Bud

jscheuer1
02-12-2011, 02:06 AM
Well errors in javascript, or errors in PHP? Probably the latter.

But in either case, no. There's no real rule of thumb other than what I've been telling you. Follow the established templates, respect the rules of PHP, javascript, HTML, whatever other languages you may be using. And, as far as simplepie goes, use only methods from it that are available. There's some help on that last bit if using the current version:

http://simplepie.org/wiki/setup/start

and:

http://simplepie.org/wiki/

For PHP in general there's always:

http://www.php.net/

I looked into the whole business of what's required in the RSS box's simplepie folder. All you really need in there is simplepie.inc. If using the most recent simplepie.inc and PHP 5 or greater, remember to make the changes to simplepie.inc that I mentioned.

jscheuer1
02-12-2011, 04:48 AM
OK, as promised (sort of), here's an archive of a working demo:

http://home.comcast.net/~jscheuer1/side/rss_box_sp_1_2.zip

Unfortunately I have no access at the moment to a public area with PHP, otherwise I would also include a link to a live demo.

Note: I worked out the possible disparity between PHP versions, visa vis 4.x versus 5.x by including two versions of simplepie.inc and testing for the PHP version number as to which the script should use (from main.php):


if((int)phpversion() > 4){
require('../simplepie/simplepie.inc'); //Specify path to simplepie.inc on your server (by default located inside "simplepie" directory)
} else {
require('../simplepie/simplepie_p4.inc'); //Specify path to simplepie_4.inc (only needed for PHP versions less than 5) on your server (by default located inside "simplepie" directory)
}

ajfmrf
02-13-2011, 12:55 AM
OK, as promised (sort of), here's an archive of a working demo:

http://home.comcast.net/~jscheuer1/side/rss_box_sp_1_2.zip

Unfortunately I have no access at the moment to a public area with PHP, otherwise I would also include a link to a live demo.

Note: I worked out the possible disparity between PHP versions, visa vis 4.x versus 5.x by including two versions of simplepie.inc and testing for the PHP version number as to which the script should use (from main.php):


if((int)phpversion() > 4){
require('../simplepie/simplepie.inc'); //Specify path to simplepie.inc on your server (by default located inside "simplepie" directory)
} else {
require('../simplepie/simplepie_p4.inc'); //Specify path to simplepie_4.inc (only needed for PHP versions less than 5) on your server (by default located inside "simplepie" directory)
}


So I would replace this



require('../simplepie/simplepie.inc'); //Specify path to simplepie.inc on your server (by default located inside "simplepie" directory)

with the code you have above.And I can put simplepie_4 in the same folder as the other simplepie just with the new name for the other version.


Cool, I will try and get this done in a day or two and I will let you know the results on my end.

Thanks again John.

Bud

jscheuer1
02-13-2011, 09:10 PM
Assuming you've been faithfully following all of the other updates to get RSS box to work with simplepie 1.2, yes.

Or just use the archive from my last post as a template. Use its simplepie files as well.

ajfmrf
02-16-2011, 02:48 AM
I have never heard of that?

I am unable to open it.What is used to open that type of file and what is it anyway???

Bud

ps-I am trying to make the changes you have mentioned John and am having issues(php) but have yet to mess with anything.