Jump to content

Load RSS Feeds (MarkupLoadRSS)


ryan

Recommended Posts

The error says that $rss is not an object, so the call $modules->get doesn't return a module instance. Did you install the module after downloading it?

Yes it's installed :

Title 	Markup RSS Feed
Class 	MarkupRSS
File 	/wire /modules /Markup /MarkupRSS.module
ID 	171
Version 	1.0.2
Installed 	1 hour ago
Summary 	Renders an RSS feed. Given a PageArray, renders an RSS feed of them.
Link to comment
Share on other sites

Seems you got your modules confused :-)

  1. This is the module you want: https://github.com/ryancramerdesign/MarkupLoadRSS. MarkupLoadRSS: It reads feeds. http://mods.pw/W
  2. What you have above (part of the core) is: Markup RSS Feed. It generates feeds.

Install #1 and you should be fine. I tested your code and it works.

Edited by kongondo
  • Like 2
Link to comment
Share on other sites

Seems you got your modules confused :-)

  1. This is the module you want: https://github.com/ryancramerdesign/MarkupLoadRSS. MarkupLoadRSS: It reads feeds. http://mods.pw/W
  2. What you have above (part of the core) is: Markup RSS Feed. It generates feeds.

Install #1 and you should be fine. I tested your code and it works.

Oh my....

Installed 4 seconds ago

Thank you very much.

Link to comment
Share on other sites

  • 2 weeks later...

@Marco -

i believe that MarkupRSSEnhanced module does multiple feeds;

i do something like this on my template where i need the feed:

/* FEED GLOBAL SETTINGS
-------------------------------------*/
$rssTitle = isset($rss_title) ? $rss_title : '9th Planet Blog';
$rssDesc  = isset($rss_description) ? $rss_description : 'Official blog of the 9th Planet';
$limit 	  = isset($rss_limit) ? $rss_limit : 10;

/* RSS
-------------------------------------*/
if($input->urlSegment1 == 'rss.xml') {

	$rss = $modules->get("MarkupRSSEnhanced");
	$rss->title = $rssTitle;
	$rss->description = $rssDesc;
	$rss->itemDescriptionField = 'summary';
	$items = $page->children("limit={$limit}, sort=-date");
	$rss->render($items);

	exit();

}

you can also roll your own feed by using like an atom class:

/* ATOM
-------------------------------------*/
if($input->urlSegment1 == 'atom.xml') {

	include("./classes/atom1.class.php");

	$atom = new atom1(
	    $rssTitle,
	    $page->httpUrl . 'atom.xml',
	    $default_author,
	    $page->httpUrl . 'atom.xml'
	);

	$posts = $page->children("limit={$limit}");

	foreach($posts as $post) {
		$atom->addEntry(
			$post->title,
			$post->httpUrl,
			$post->wordLimiter('body', 400),
            $post->getUnformatted('date'),
            $post->id
        );
	}

	header( 'Content-Type: text/xml' );
	print $atom->saveXML();

	exit();
}

i'm using a slightly modified atom class from PHP Cookbook, so i can't post it here, but it's a very simple class which extends DOMDocument...

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

I have a problem with this module (and also atom feed loader module) in a website. 

I was able to make the module work changing the php version to an older one (maybe 5.3 or 5.4 I don't remember), but my provider (for other problems) needs to run php 5.5 version

When I have this version it doesn't work.

I don't get any errors and if I add 

if($rss->error) { echo "<p>{$rss->error}</p>"; } 

simply it outputs 

Unable to load Atom feed at https://www.youtube.com/feeds/videos.xml?playlist_id=... 

I don't know if the problem is caused by php 5.5 or some other php settings.

EDIT: I have seen that the same script is running fine on another server with php 5.5 so I think the problem is related to php settings.

Do you have an idea how to fix or debug this problem?

Thank you

Link to comment
Share on other sites

Thank you Andrian for the incredible support.

I have contacted my provider suggesting your solution.

I will update this post as soon as I have the confirm that it works. Thank you!

Edit: Finally it works and seems there was a firewall problem.

  • Like 1
Link to comment
Share on other sites

I've got it working and displaying the last 6 items from a test feed in a page using the MarkupLoadRSS module, would it possible to include pagination so you can go to the previous/next 6 results?

And while I'm at it, is it possible to perform search and filters on the feed to get specific results as well?

Link to comment
Share on other sites

I didn't know it was possible. but RSS seems to support pagination;

This is defined in RFC 5005, Feed Paging and Archiving, section 3.

You can use first, previous, next and last as a link relation:

<link rel="next" href="http://example.org/index.atom?page=2"/>

you'd need to hack the module i think though in order to support the pagination.

In terms of filtered feed that sounds riskier, but you can always load the feed with a different page array, shouldn't be any issue, maybe you can explain more about why you need it - i guess you want different feeds with different titles, but want to generate them all off the same page?

Link to comment
Share on other sites

Ok again a new question in the round.

I'm not sure if I should write it into the plugin forum or here, if then please move.

I think I've ever asked 1-2 years ago, probably in a different profile but I know not, and could not find it.

With MarkupLoadRSS I'm writing from an RSS feed on the page.

I would like this but, or an item's it like to spend in a slider and link first intern.

My question would be the following:
How would it do that I disc reading the RSS, then save as a Page?
To affairs it "internally" on and then refer only to the external target?

Link to comment
Share on other sites

I had a test feed in place and working perfectly in a template, as soon as I've put in a new feed Ive received teh error message "Warning: Invalid argument supplied for foreach() in /Applications/MAMP/htdocs/sirius_updated/site/modules/MarkupLoadRSS/MarkupLoadRSS.module on line 330".

The new feed contains CDATA, but I'm judging this shouldn't really be a problem, as there;s a post from the first page that works with this in.

Link to comment
Share on other sites

  • 1 month later...
  • 1 month later...

This module will not throw runtime exceptions so if an error occurs, it's not going to halt the site.

I have this module set up and running on a site, there was an issue with the feed and it wouldn't load, but it also stopped the pages loading as well.

Link to comment
Share on other sites

  • 1 month later...

I just recently found about processwire a few days ago and now I am currently stuck on modules. I followed the directions on installing it and then inserted the example codes into both a blank template and a pre-built template I made and it shows nothing. I also changed the rss link to something from CNN to see if it was just the URL, but it still shows nothing. I'm not sure if it has something to do with the get function. I implemented this sample into a php template.

<?php

$rss = $modules->get("MarkupLoadRSS"); 
$rss->load("http://www.cnn.com/services/rss/");

foreach($rss as $item) { 
echo "<p>";
echo "<a href='{$item->url}'>{$item->title}</a> ";
echo $item->date . "<br /> ";
echo $item->description; 
echo "</p>";
}

?>

 

Please advise

Edited by cstevensjr
Put code in Code Block
Link to comment
Share on other sites

Hi and welcome to PW.

That CNN URL is not a valid feed - it needs to return an XML document, but that one is just a directory of actual feeds - choose one from the list and it should work fine.

What was the other URL you tried before switching to the CNN one?

  • Like 1
Link to comment
Share on other sites

13 hours ago, adrian said:

Hi and welcome to PW.

That CNN URL is not a valid feed - it needs to return an XML document, but that one is just a directory of actual feeds - choose one from the list and it should work fine.

What was the other URL you tried before switching to the CNN one?

So I used this link https://www.us-cert.gov/ncas/alerts.xml with processwire installed with bitnami on my local computer and it worked. However when I go back to my work computer, it still shows blank. Any clues or ideas to why this might be?

Link to comment
Share on other sites

  • 1 month later...
  • 2 weeks later...
On 10/04/2016 at 3:57 AM, Piqsel said:

I would also like to know if its possible to load images with this module?

Yes, change lines 165 & 166 in MarkupLoadRSS.module to to

'stripTags' => false,             // Strip any markup tags that appear in the feed? (default: true)
'encodeEntities' => false,         // Whether to automatically decode and re-encode the entities for all fields (default: true)

Works a treat :-)!

Link to comment
Share on other sites

  • 2 months later...
On 9/8/2016 at 1:32 PM, dab said:

Yes, change lines 165 & 166 in MarkupLoadRSS.module to to


'stripTags' => false,             // Strip any markup tags that appear in the feed? (default: true)
'encodeEntities' => false,         // Whether to automatically decode and re-encode the entities for all fields (default: true)

Works a treat :-)!

It does not work for images in my site

any suggestions? 

Link to comment
Share on other sites

39 minutes ago, grigorisk said:

It does not work for images in my site

any suggestions? 

Firstly, try this module instead: http://modules.processwire.com/modules/markup-rssenhanced/

Secondly, don't edit lines in the module, try passing the options array to the render method so that updates to the module won't break the functionality.

  • Like 1
Link to comment
Share on other sites

  • 1 year later...

I'm currently working on a website where I would like to fetch data from an RSS feed and save them as actual pages inside ProcessWire.

Ideally ProcessWire is an exact copy of the RSS feed. When a new page is added to the RSS feed, the new page would also be added in ProcessWire. Or when a page got removed from the RSS feed, the page should also be delete from within ProcessWire.

I'm using the following setup:

1. Fetch the RSS feed with

$rss = $modules->get('MarkupLoadRSS');
$rss->load('http://www.domain.com/rss');

2. Compage the RSS feed with the pages that are currently save in Processwire

foreach ($rss as $item) {
...
}

3. If page is in RSS feed, but not in ProcessWire, save page

4. If page is in RSS feed and in ProcessWire, update values with data from the RSS feed

5. If page is not in RSS feed, but in ProcessWire, delete page

To get all the pages from the RSS feed, check if it exists and create the page from the API if it doesn't exist, i'm using the code below:

<?php

include './index.php'; // bootstrap PW

$rss = $modules->get('MarkupLoadRSS');
$rss->load('http://www.domain.com/rss');

foreach ($rss as $item) {
    $p = $pages->get("job_id=$item->id"); // get the ide of the job

    if (!$p->id) {
        $p = new Page(); // create new page object
        $p->template = 'job-offer'; // set template
        $p->parent = wire('pages')->get('/vacatures/'); // set the parent
        $p->name = slugify($item->title); // give it a name used in the url for the page
        $p->title = $item->title; // set page title (not neccessary but recommended)

        // added by Ryan: save page in preparation for adding files (#1)

        $p->save();

        // populate fields

        $p->job_id = $item->id;

        $p->save();

        // testing
        echo 'id: ' . $p->id . '<br/>';
        echo 'path: ' . $p->path;
    }
}

So far everything works and the pages got created ?

However I'm having trouble with the logic for points 4 and 5.

- When a page is in the RSS feed and is already add to ProcessWire. Is there a way to find a page and update it's content through the API?
- When a page is not in the RSS feed anymore. Is there a way to delete all pages that are not in the RSS feed?

Thanks!

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
×
×
  • Create New...