PHP RSS jQuery News Ticker problems

Hello,
I was setting up / designing a news ticker using PHP that feeds in headlines from an RSS feed.
I asked the author for the files and he asked me to play with them to get them working in all browsers; however, upon uploading the unzipped archive he emailed me I am getting this error that says
[I][B]"Cannot find RSS feed file ‘http://feeds2.feedburner.com/themeforest

Please refer to /readme.txt for configuration instructions. "[/B][/I]

However, that url is a valid url to a valid rss feed.

This is the version I uploaded to my server (HERE). I uploaded it and have no alterations to any of the files.

Here is the working version on their server

I was wondering if someone here at sitepoint would be kind enough to help me get the files working so I can start making them all-browser compatible

Here is the exact zip file that the author emailed me and I was hoping someone could upload it or check mine out and help me get it working as the author had it, [URL=“http://www.jigowatt.co.uk/themeforest/rssnews/?iframe=true&width=90%&height=90%”]here, so then I can help make the changes they requested.

Also the error message, here, says [I]Please refer to /readme.txt for configuration instructions.[/I] I did exactly that in a different directory on my server and encountered an missing class error. :eek: You can see the configured version on my server [URL=“http://team1504.com/ticker/”]here.

Thank you in advance, I hope that you can help me link to the RSS feed so that I can have this news ticker with fading headlines work! :slight_smile:
Please reply with any questions, comments, or solutions.
I can apply and more clarification on my issue and I have provided all the code in the zipped file that I linked earlier in this post.

Thanks and regards,
Team 1504

yes I tried making the selector more specific and it worked! :slight_smile:

:weee:
Thanks for everything and Regards,
Team 1504

You can make the selector more specific, but you need to look at the HTML in view-source and find what makes it unique from the rest of the page.

For example, if it’s inside a span with the class “item”, and those are the only ones like that, you could use
span.item a {
or you might need to be more verbose like
div#headline span.item a {

Yes i have! :slight_smile: sort of
When I add it in with an other page, I think the CSS is too general because it alters the rest of the page.

I know this is not the CSS forum , but do u have any idea on how I can get the styling


a { color: #000; text-decoration: none; }
a:hover { text-decoration: underline; }

In stylesheet.css to apply only to the a’s in the ticker and not all a’s ?

Thanks for all your help! :smiley:

just to make sure. The code you have there
I should replace the begining of the Parse ($rss_url) function which begins at line 133 until the line 145 with the code that you put in the above post.

In other words
Replace this:

function Parse ($rss_url) {
		// Open and load RSS file
		if ($f = @fopen($rss_url, 'r')) {
			$rss_content = '';
			while (!feof($f)) {
				$rss_content .= fgets($f, 4096);
			}
			fclose($f);

			// Parse document encoding
			$result['encoding'] = $this->my_preg_match("'encoding=[\\'\\"](.*?)[\\'\\"]'si", $rss_content);
			// if document codepage is specified, use it
			if ($result['encoding'] != '')

with this

function Parse ($rss_url) {
        // Open and load RSS file
/*
        if ($f = @fopen($rss_url, 'r')) {
            $rss_content = '';
            while (!feof($f)) {
                $rss_content .= fgets($f, 4096);
            }
            fclose($f);
*/
/* begin replacement code */
        if ( function_exists('curl_init') ) {
        $ch = curl_init();
        $timeout = 30; // in seconds, arbitrary, set to zero for no timeout
        curl_setopt ($ch, CURLOPT_URL, $rss_url);
        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);

right?

Thanks for testing it on your server!

Regards,
       Team 1504
        curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
        $rss_content = curl_exec($ch);
        curl_close($ch);
/* end replacement code */
            // Parse document encoding
            $result['encoding'] = $this->my_preg_match("'encoding=[\\'\\"](.*?)[\\'\\"]'si", $rss_content);
            // if document codepage is specified, use it
            if ($result['encoding'] != '')

The best thing is to save a copy of the original for a backup in case you need it. Probably not important for this relatively minor change, but still a good habit to get into.

You could keep the fopen() and add an else to use cURL if that fails, but since you already know it’s not something you will ever need with your current setup it doesn’t make much sense to keep it in.

I don’t like to remove existing code when I hack a file. I like to keep it there in case I want to see what it was later. Thats what the /* … */ does. It “comments out” that part of the code so PHP won’t run it.

Another thing I like to do is put comments around my new code that I added.

It isn’t necessary, but I like to be able to see both what was there and what I added without any room for doubt later.

In the example code I posted I left a little bit of the original code before and after so you could figure out where to put it. It looks like you understand what to change OK. Just save a backup copy to be safe.

Well, it was worth a try. But I can see it’s going to be more involved. The view-source for that page shows

		<h3>Fade Headline Effect (with jQuery Hover)</h3>

        <p></p>
		<div class='bubbleInfo'><div id='news' class='trigger'><div class='title'><b>Latest Headlines</b>&nbsp;|&nbsp;</div><div id='headline'><span class='item'>
					<a href="<?php the_permalink_rss() ?>"><?php the_title_rss() ?></a>
					<span class='popup'><![CDATA[<?php the_excerpt_rss() ?>]]></span>
				</span></div><div style='clear: both;'></div></div></div>        
    <br />
	
        <h3>Slide Headline Effect</h3>
        <p></p>

        <div id="news"><div class='title'><b>Latest Headlines</b>&nbsp;|&nbsp;</div><div id='headline_slide'><span class='item'><a href="<?php the_permalink_rss() ?>"><?php the_title_rss() ?></a></span></div><div style='clear: both;'></div></div>
	</div>

so you can see the PHP code isn’t being parsed.

I’ll move this to the WordPress forum where there’s a better chance someone might already have solved it, and I’l try getting it to work on my localhost test blog when I get a chance (it’s lunch time!)

I copied the files over to my localhost test blog. And tried the Absolute Virtual path first in the script’s rss.php and rss_slide.php files

$feed = 'http://localhost/testblog/?feed=rss2';

It worked fine, but I have allow_url_fopen set to true.
I then tried it using the Relative Physical path, but got the same as you - the PHP wasn’t parsed.

I’m guessing it has something to do with the fact that WordPress uses templating and the rss feed needs to be by an HTTP request because of the “fancy URL” - so include won’t work (at least not easily enough for me to want to figure out how to do it).

Rather than trying to figure out how to re-write everything into a plugin that will work with the WordPress “hooks”, I think the easy way out will be to hack the lastRSS.php file so it uses cURL instead of fopen(). i.e.

	function Parse ($rss_url) {
		// Open and load RSS file
/*
		if ($f = @fopen($rss_url, 'r')) {
			$rss_content = '';
			while (!feof($f)) {
				$rss_content .= fgets($f, 4096);
			}
			fclose($f);
*/
/* begin replacement code */
		if ( function_exists('curl_init') ) {
		$ch = curl_init();
		$timeout = 30; // in seconds, arbitrary, set to zero for no timeout
		curl_setopt ($ch, CURLOPT_URL, $rss_url);
		curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
		$rss_content = curl_exec($ch);
		curl_close($ch);
/* end replacement code */
			// Parse document encoding
			$result['encoding'] = $this->my_preg_match("'encoding=[\\'\\"](.*?)[\\'\\"]'si", $rss_content);
			// if document codepage is specified, use it
			if ($result['encoding'] != '')

I tried it with the include ‘http://…/?feed=…’ syntax and it worked OK for me.

I see by going to http://team1504.com/projects/newsfeed/ that it’s working :weee:

Have you been able to get it into a site page OK too?

Mittineague,
I changed the RSS feed’s relative URL path to the following:

$feed = '../../blog/wp-includes/feed-rss2.php';

However, nothing is being shown or parsed in the script, but the rss feed not found error is not showing…

You can check it out for yourself here

:confused: :frowning: :confused:

Do u have any ideas on why the script is not working?
or suggestions on what I should do. I double-checked to make sure I was not making any stupid mistakes and the current version of the files with the URL to wp-includes is on my server

Thank you for all your help and Regards,
Hear from you soon!
Team 1504

lol supper can be pretty appetizing… :slight_smile:

I began searching through my wp-includes folder and failed to find the wp-rss2.php file :mad:
Here is the listing i made of its contents in my server
In the above link, I highlighted the files that I think may contribute to or be the rssfeed’s php file

They are:
deprecated.php
feed-atom-comments.php
feed-atom.php
feed-rdf.php
feed-rss.php
feed-rss2-comments.php
feed-rss2.php
feed.php
rss-functions.php
rss.php

So would any of those be it? And since I could not find the wp-rss2.php file in /wp-includes/ then should I copy it there, but it is deprecated and only links to the rss php file so probably not right?

The one thing I noticed though is that when I went to some of them in my browser I encountered errors, but my blog and rss feed are working fine.

For exmaple,
In feed-atom-comments.php it was:
Fatal error: Call to undefined function feed_content_type() in /homepages/9/d197248293/htdocs/blog/wp-includes/feed-atom-comments.php on line 8

in feed-atom.rss it was:
Fatal error: Call to undefined function feed_content_type() in /homepages/9/d197248293/htdocs/blog/wp-includes/feed-rss.php on line 8

And in rss.php it was:
Fatal error: Call to undefined function do_action() in /homepages/9/d197248293/htdocs/blog/wp-includes/rss.php on line 18

could I just be seeing these errors because the file permissions are set to 644 and I do not have permission to see what they output?

So that is what I found in /wp-includes/
and I was hoping that you could help me find which file it is or should be

Thanks for all your help, I really appreciate it! :slight_smile:
Hear from you soon

Regards,
Team 1504

The file isn’t wp-rss2.php, it’s feed-rss2.php

I don’t know but I think those errors are because you are going to an “included” file. For example if feed-rss2.php assigns a value to a variable or defines a function or includes other files that do so, all that needs to be “together” so everything know about everything else. If you don’t go to the “main” one you’re only going to get pieces of what’s needed.

hmm so upon looking in team1504.com/blog/wp-content/
I found the following
index.php
a the directories: plugins, themes, upgrade, and uploads

I believe I did the standard installation tho, so shouldn’t the wp-rss2.php file be in the wp-content dir?

In the root directory of my blog, however, I have wp-rss.php and a wp-rss2.php among the folders wp-admin/ , wp-content/ , and wp-includes/
and multiple other files such as the license read-me, and index.php

So since you said wp-rss2.php is deprecated does that mean I should upgrade my wordpress version?
I do also have a wp-rss.php file in the same dir as wp-rss2.php

and both of those files when put into the address bar link to my RSS feed
so http://team1504.com/blog/wp-rss.php
http://team1504.com/blog/wp-rss2.php

I am confused in that I thought I was linking to the location of the wp-rss2.php file with the realtive URL …/…/blog/wp-rss2.php
? :confused:

should I or can I copy and paste the wp-rss2.php file to wp-content and then
link to it using …/…/blog/wp-content/wp-rss2.php ?

Also what is up with the wp-rss.php file, is this the proper file or is it another deprecated file that links?

I hope I cleared things up so that you can help me!

Thanks in advance, good night, and Regards,
Team 1504

Edit: I do have the latest version of wordpress so why should my files be outdated or deprecated ?

Sorry, I wasn’t clear enough before.

There are absolute and relative paths
http://domain.com/file.php ~ …/file.php

And there are virtual and physical paths
http://domain.com/blog/index.php?admin ~ http://domain.com/blog/admin/index.php

AFAIK, the server can deal with virtual paths, but the PHP engine can deal with both virtual and physical paths.

In this case I think you need to use the relative physical path to whatever file outputs the feed. eg. in WordPress something like
…/…/blog/wp-content/feed-rss2.php

Sorry, that was my stupid bonehead mistake. It’s in the wp-includes folder not the wp-content folder :d’oh: I don’t know what I was thinking (actually I do - about getting some supper)

The current version contains files and functions that are deprecated to maintain backwards compatability. That is, themes and plugins that use them will still work (usually) but this is a way of giving people time to fix things so that when WordPress stops having them there for backwards compatability, most things will be ready for the event without total chaos.

Hello,
I updates the php files and added the relative url path.
My RSS feed is located at http://team1504.com/blog/?feed=rss2
Therefore since these php files are located in team1504.com/projects/newsfeed/
the relative url would be:
…/…/blog/?feed=rss2

I even uploaded an html file to the newsfeed directory and gave it the relative link above to see if it would link to my rss feed from that directory.
Here is that file

Here is it’s code:

My problem is that I still get the same error as it can not find the RSS feed in the uploaded script here
Cannot find RSS feed file ‘…/…/blog/?feed=rss2’

:eek:

I even tried using this type of URL inclusion in the php files :

$feed = ("../../blog/?feed=rss2") ;

instead of

$feed = '../../blog/?feed=rss2' ;

and it still did not change anything so I changed it back.

Also I tried the absolute http:// URL just to see if it would work because RSS feed is on my server as well the PHP script. However, that did not work as well so I changed it to the relative …/…/blog/?feed=rss2 URL path.

So did I do the relative URL thing correctly?
or could there be something different that is causing the problem or another solution

I hope you can help me and that I am not making any stupid mistakes.

Thanks for all your help and Regards,
Team 1504

The wp-rss2.php file is deprecated and all it does now is redirect. If you have the default installation set-up try
…/…/blog/wp-includes/feed-rss2.php
if not, wherever the feed-rss2.php file is.

Okay so I figured out that the physical path to my RSS file is both
team1504.com/blog/wp-rss.php
team1504.com/blog/wp-rss2.php

The differences I saw in the rss files was that the prior had more spacing between title and post while the second had less spacing but date of posting.

Therefore the relative path from the /projects/newsfeed/ directory would be
…/…/blog/wp-rss2.php

So i added this new rss feed path to the php files and it worked! :slight_smile: kind of :confused:
[URL=“http://team1504.com/projects/newsfeed/”]
Have a look for yourself here
so what happened is that there is not an error that says the feed can not be found and the headlines bars are appearing; however,
No headlines are appearing… :frowning:

So I believe there is a problem with the PHP parsing the rss feed titles ? That is why nothing is showing up?

Could you help me diagnosis why this is happening and help me solve it?

Thanks for all your help and I hope you can help me get this script working even though the original problem, the feed can not be found, which the topic was based off of has been solved… ?

Regards,
Team 1504

yes i agree the user, guest, or browser should not have to access or write to the folder.

This is the url to my RSS feed http://team1504.com/blog/?feed=rss2

So would the relative url be /blog/?feed=rss2?

sorry if that is a stupid question…
And since both this rss feed, and therefore the blog it originates from, and the news ticker are in the same server it should work. Although they are in different directories in the root of the same folder. And should I have to edit any of the file permissions or is 755 or 666 or 644 good enough?

Thanks will all your help!

Regards and good night,
Team 1504 :slight_smile:

I would consider using a different script or at least not following the instructions to the letter and adding some validation/filtering.

Having allow_url_fopen set to TRUE can introduce security risk. In itself not a problem as long as you’re 100% certain every script is secure.

IMHO it would be better to use cURL instead of fopen().

Also, and most importantly, the script instructs you to create a folder and set it’s permissions to 777. This is a Major security risk. I have yet to see any app that absolutely needed permissions to be 777.

Say for example you fetch a feed that has a script tag in it. This app will put the contents in the folder. The file can be read, written, and executed by anyone. And even if not, the contents will be written to the HTML page - including any script tags.

Excellent app for an XSS attack.