Jump to content

RSS Feed Module


ryan

Recommended Posts

I'll start with saying that I'm not a 'coder' by far and sometimes I have the impression that most people here are and suppose that everybody is one. Being a 'performance artist' you could say I'm the opposite I need nothing else but my body to do my work. www.performan.org

Nevertheless I've used the internet as a means to make my work public, since 1994 when Netscape 1.1 was released with the major introduction of frames. The Jockel Project

Since 1985 I've kept a database of events that I find interesting, in notebooks, in a Commodore 64 environment, in a FoxPro database, in a Filemaker database, as a blog When I Was Buying You a Drink Where Were You? and now finally (and hopefully working from 1 Jan 2014) in a searchable website thanks to ProcessWire.

Apart from that I worked as a cook, a carpenter, a welder, a painter, a teacher, a bus driver, manager of a tattooed pig farm in China and currently at an architecture school operating CNC machines and lasercutters but also unloading wood, card- and fiberboard or simply bricks from delivery trucks.

And more actually I'm painstakingly recovering from a complex leg fracture since the unfortunate meeting of my left leg and a yellow car while driving my bicycle in Antwerp last summer.

So yes, PHP and XML are hard work for me, but I'm willing to learn. And I'm happy to have discovered ProcessWire and appreciate the help I've had so far from anybody responding to posts and questions. Some things just aren't obvious, and even when searching the forums you don't always find what you want. Or sometimes something doesn't even looks like a solution until someone tells you to look at it in a different way - which you did, thank you.

Oh, and if you're looking for some electronics to listen to while you're coding, our complete catalogue of electronic music since 1980 (vintage analog synthesizers, tapeloops and voices only!) is available for free at the Internet Archive.

  • Like 5
Link to comment
Share on other sites

Wonderful story Danny! Hope your leg will be well soon. I'm very curious about the tatooed pigs :)

I was working on a Atom feed only some days ago. Here is my code:

if ($input->urlSegment1 == "atom") {

<?php header("Content-type: text/xml; charset=utf-8") ?>

<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom"> 
    <title><?php echo $page->title ?></title>
    <subtitle><?php echo $page->headline ?></subtitle>
    <link href="<?php echo "http://" . $config->httpHost . $page->url?>" rel="self"/>
    <updated><?php echo date(DateTime::RFC3339, $page->child->created)?></updated>
    <author>
    <name>$page->autor</name>
        <email>$page->email</email>
    </author>
    <id><?php echo "tag:" . $config->httpHost . "," . date("Y-m-d",$page->page->children->first()->created) . ":http://" . $config->httpHost . $page->url ?></id>

    <?php foreach($page->children as $article):?>

    <entry>
        <title><?php echo $article->title ?></title>
        <link type='text/html' href='<?php echo "http://" . $config->httpHost . $article->url?>'/>
        <id><?php echo "tag:" . $config->httpHost . "," . date("Y-m-d",$article->created) . ":http://" . $config->httpHost . $article->url ?></id>
        <updated><?php echo date(DateTime::RFC3339, $article->created)?></updated>
        <author>
            <name>$article->author</name>
        </author>
        <summary><?php echo strip_tags(str_replace(' ', ' ', $article->summary)) ?></summary>
    </entry>

    <?php endforeach?>

</feed>

} else {

// code for the articles listing page  
 

This code assumes that you have a articles listing page with the articles as children, and that the feed url is a urlSegment on this same page. Depending on your situation is just a matter of changing this line foreach($page->children as $article)

Another note on this line:

<summary><?php echo strip_tags(str_replace(' ', ' ', $article->summary)) ?></summary>

I used the strip_tags() and the str_replace() methods because XML doesn't accept any tags or the   entity on the content, and my "summary" field was a rich textarea. The ideal is to have a simple text field for this, and in that case you would have only this:

<summary><?php echo $article->summary ?></summary>
Link to comment
Share on other sites

Thanks. My brief career as Tattoo Pig Farm manager is documented here: DDV in China. And if everything goes as expected I should be halfway the healing process of my leg by now.

My daily RSS feed is based on content from different pages: 'event' pages that match 'day' and 'month' of the date the RSS feed goes out. Basically the same query as the home page. But I guess it should be possible to get that into a summary field using CSS. Something else bothering me is that now all the 'summaries' go out as individual posts whereas I want them all together in one post. I don't want people subscribing to the RSS feed by mail (MailChimp) to wake up with 30 messages every day.

Link to comment
Share on other sites

  • 3 weeks later...

Still wrestling with this.... My daily RSS feed works fine when viewed in a browser or RSS reader, but for some reason MailChimp doesn't pick it up as RSS feed. My five cents is that it doesn't because the posts in my query are not 'new', instead they are a set of existing pages matching search criteria.

    $todayday = date("d");
    $todaymonth = date("m");
    $features = $pages->find("parent=/events/, bfd_day.name=$todayday, bfd_month.name=$todaymonth, sort=bfd_year");

Any ideas someone?

Link to comment
Share on other sites

The link you provided:

http://www.birthfactdeathcalendar.net/bfd_processwire/rss/

doesn't seem to work, but this does:

http://www.birthfactdeathcalendar.net/rss/

Probably a stupid suggestion, but are you submitting the correct one to MailChimp?

I just ran a validator on your feed and it seems to be fine, so no major problems there:

http://validator.w3.org/feed/check.cgi?url=www.birthfactdeathcalendar.net%2Frss%2F

although maybe you could clean up the max-width issue and see if it helps. 

Regardless you should fix the relative urls to absolute, eg: <a href='/events/12-january-1893/'> to <a href='http://www.birthfact...2-january-1893/'> 

I know that FeedBurner is probably going to be another Google casualty soon, but try running your feed through it and giving MailChimp the FeedBurner link to make sure there is no issue with MailChimp accessing the feed or the format of the feed on your server. I know this has helped me in the past. Not a permanent solution, but a good debugging step.

Link to comment
Share on other sites

I moved my site from the working folder upfront and live. And yes I updated the feed @ MailChimp.

Got a new url @ FeedBurner and have set up MailChimp to send at 3.00am in the morning.

Hopefully I'm happy when I check my mail tomorrow morning.

I'll see how it ends up html-wise. I know it's Landrover Owner Style ;)

Thanks again.

Link to comment
Share on other sites

Nope, MailChimp doesn't send http://feeds.feedburner.com/birthfactdeathcalendar either.... While I have one configured in exactly the same way http://wheniwasbuyingyouadrinkwherewereyou.blogspot.com/feeds/posts/default?alt=rss that works fine. But on Blogspot the articles are published as 'new' every day.

Perhaps adding a 'tricked' publish date might help?

Link to comment
Share on other sites

It sounds like the PubDate might be the issue:

http://kb.mailchimp.com/article/ive-posted-new-information-to-my-rss-feed-but-no-campaigns-have-been-sent

This might also be useful:

http://blog.mailchimp.com/rss-to-email-tutorial/

It suggests that it can validate the feed without you needing to wait for it to send, which should help speed up your debug cycle considerably!

Link to comment
Share on other sites

I also think the PubDate is the culprit. I presume the MarkupRSS module gets that date from the creation date (itemDateField) of the post, under 'Render individual RSS item' in the module code.

		if($this->itemDateField && ($ts = $page->getUnformatted($this->itemDateField))) {
			$pubDate = "\t\t<pubDate>" . date(DATE_RFC2822, $ts) . "</pubDate>\n";
		} else {
			$pubDate = '';

So basically I could change that into something based on the search criteria to find the posts that need to go into the daily RSS,

$todayday = date("d");
$todaymonth = date("m");
$features = $pages->find("parent=/events/, bfd_day.name=$todayday, bfd_month.name=$todaymonth, sort=bfd_year");

and somehow insert those as PubDate.

If that makes sense, should I change that in the module itself or in the RSS template? And uhm, it would be nice to direct me towards how as well....

Link to comment
Share on other sites

You certainly don't want to go modifying the module code. I don't actually understand why the pubdate is not being included in the feed in the first place since every PW page has a created timestamp and the module includes this as the default. Are you doing something custom with the output?

Link to comment
Share on other sites

Ok, my RSS feed is NOT a feed of recently CREATED pages. My RSS feed is a list of events where the field 'bfd_day' is today and the field 'bfd_month' is this month, aka the day the RSS feed goes out. The pages can be made anytime beforehand.

Right now I'm making pages for 24 May, they should appear in the RSS feed on 24 May and not in the RSS feed of tomorrow.

So somewhere "$rss->itemDateField = 'created';" should be replaced by a date function 'today' rather than 'created' for each item.

My guess is "$rss->itemDateField = date(DATE_RFC2822);". Trial and error and I'll wait and see again if and what MailChimp will send me at 3.00am in the morning.

Link to comment
Share on other sites

Why not add an additional date field to the template and set that using the code Soma provided:

$rss->itemDateField = 'my-special-date-field';

You could set this date of this field manually when creating the pages.

Does that make sense?

Link to comment
Share on other sites

I tried "$rss->itemDateField = date(DATE_RFC2822);" where I assume "date(DATE_RFC2822)" is today in the format needed for an RSS feed. It would mean that the creation date is tricked into today and the posts look as if they are created today. MailChimp checks the RSS at 3.00am, finds the 'new' pages and sends them out.

The pages found in my array sent to the RSS template lists events that have a 'bfd_day' field that matches today's day and a 'bfd_month' field that matches today's month. The 'bfd_year' field is of course different for every event.

So I don't think it would be necessary to add another field.

Perhaps another approach is this:

$day = $feature->bfd_day->title;
$month = $feature->bfd_month->title;
$year = date("y');
$rss->itemDateField = new DateTime('$year-$month-$day');

What do you coders think of it?

Link to comment
Share on other sites

$rss->itemDateField is for fields and not for code! It's configurable on the module screen (default) and via API.

To do what you want, give every page in the feed the date of today, you could add a property hook to Pages. 

So you can define what, for example, $page->myPubDate will return. Then use that property for itemDateField.

So such a hook would look like this, as also shown in the HelloWorld.module example. In your template code just before you render the feed:

wire()->addHookProperty("Page::myPubDate", null, "addPropertyDate");
function addPropertyDate($event) {
    $event->return = date(DATE_RFC2822);
}

Now after this code a call like 

echo $somepage->myPubDate;

Will return the current date.

SO later in the $rss code you can set:

$rss->itemDateField = "myPubDate";
  • Like 3
Link to comment
Share on other sites

I'm going for a different approach....

Since I was also looking for an easy solution to update my long time blog I figured I could do that by sending my daily ProcessWire query by email to Blogger, set it to automatically post and then let MailChimp and Twitterfeed pick up the Blogger RSS to send it to my MailChimp daily subscriber list, to Twitter and to some Facebook pages. All that can be scheduled to happen say between 1.00 and 2.00am, making people believe I never sleep.

So far so good. In my newsletter template I added

	$to = "performan.org.##mycode##@blogger.com";
	$headers = "From: ddv@birthfactdeathcalendar.net\r\n";
	$headers  = 'MIME-Version: 1.0' . "\r\n";
	$headers .= 'Content-type: text/html; charset=ISO-8859-1' . "\r\n";
	$subject = $jaargang . $jaargangst . " year  -  N° " . $daynumber . " " .  $today;
	$body = "<html><body>" . $headtxt . $counttxt . $bfdtxt . "</body></html>";

where $bfdtxt is the output of my query.

Works fine when the page is loaded in a browser, but only the last '$feature' is featured in the email while all are listed on the webpage.

When I call this page from the 'task scheduler' on my hosting server nothing happens....

If anyone could direct me on the right path that would be great.

Link to comment
Share on other sites

  • 4 months later...

Hi,

I'm trying to set up an RSS feed but I can't figure out how to set up the <dc:creator> tag. I'm currently outputting the author id but I'd like to use either the username or, more preferrably, the full name of the page creator. Could someone help me with outputting the correct name?

Link to comment
Share on other sites

  • 8 months later...

I have also tried get the RSS feeds working, but in my case I have always a problem with the XML-Syntax:

 <?xml version='1.0' encoding='utf-8' ?>
<rss version='2.0' xmlns:dc='http://purl.org/dc/elements/1.1/'>
<channel>
	<title>RSS Feed</title>
	<link>http://www.juergen-kern.at/de/newsfeed/</link>
	<description>This feed shows the most recent items that have been published.</description>
	<pubDate>Wed, 04 Feb 2015 14:37:18 +0100</pubDate>
	<ttl>60</ttl>
</channel>
</rss>

As you can see before the opening XML tag there is a white space and this leads to an error.

I dont know where this whitespace come from because i didnt include a header file or something like that.

It is only a pure php.page (according to the example from Ryan).

Has anyone the same problem?

Link to comment
Share on other sites

  • 1 month later...

Hi there,

it seems I have to choose one field to be the title field for the RSS module, is there a way I can customize this.

Instead of:

$rss->itemTitleField = 'title'; 
$rss->render();

I'd like to do something like

foreach($myPages as $p) {
   $ii =  $i->addNewItem();
  $ii->title = $p->title . $p->author;
}

in other words, put both title and author in the title for the  RSS

would that be possible somehow?

tx - j

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...