Jump to content

Selector not working


jsantari
 Share

Recommended Posts

I'm trying to us the MarkupRSS to generate a feed and have a problem with the selector. I've tested the selector with the SelectorTest and it works fine. My output for the rss however only shows channel information using the following based on the example code.

     // retrieve the RSS module
    $rss = $modules->get("MarkupRSS");
 
    // configure the feed. see the actual module file for more optional config options.
    $rss->title = "Latest updates";
    $rss->description = "The most recent vacancies updated on my site";
 
    // find the pages you want to appear in the feed.
    // this can be any group of pages returned by $pages->find() or $page->children(), etc.
    $items = $pages->find("template=vacancy, include=all, limit=10, sort=-modified");
    // send the output of the RSS feed, and you are done
    $rss->render($items);
 
Here is what I get:
 
<rss version="2.0">
<channel>
<title>Latest updates</title>
<description>The most recent vacancies updated on my site</description>
<pubDate>Mon, 05 Aug 2013 16:56:31 -0400</pubDate>
<ttl>60</ttl>
</channel>
</rss>
Link to comment
Share on other sites

If this is in a function like your previous post suggests, then you need to do:

$items = wire('pages')->find ...

If that is not the problem, what happens if you go back to back to the standard:

$items = $pages->find("limit=10, sort=-modified");
 

Does it work like that?

I am also wondering about "include=all". Do you really want items that have been added to the trash to show up in your feed?

Do you have debug on? Any php errors?

Edited by adrian
Link to comment
Share on other sites

The include=all I was just playing with - you are right it wouldn't make sense normally.

With out the template=vacancy I get some weird results for the items.

<rss version="2.0">
<channel>
<title>Latest updates</title>
<description>The most recent vacancies updated on my site</description>
<pubDate>Mon, 05 Aug 2013 17:44:37 -0400</pubDate>
<ttl>60</ttl>
<item>
<title>Selector test</title>
<description>
<![CDATA[ ]]>
</description>
<pubDate>Mon, 05 Aug 2013 15:40:17 -0400</pubDate>
</item>
<item>
<title>vacancies</title>
<description>
<![CDATA[ ]]>
</description>
<pubDate>Mon, 05 Aug 2013 13:14:25 -0400</pubDate>
</item>
<item>
<title>RSS</title>
<description>
<![CDATA[ ]]>
</description>
<pubDate>Mon, 05 Aug 2013 13:13:40 -0400</pubDate>
</item>
</channel>
</rss>
Link to comment
Share on other sites

I can't say I understand why you are getting just those page being detected, especially the selector-test page. It also shouldn't be finding your /rss/ page in the pages list.

Can you please show us exactly the selector you are using, along with a list of the pages that are returned with the selector test tool, or with the following, where {selector} is the selector code you are using:

foreach(wire('pages')->find( {selector} ) as $page){
     echo $page->title . '<br />';
}
 

Maybe also post the complete code that you have in your function.

Also, just for the fun of it, can you see what happens when you don't put the rss render code in a function.

Maybe also write out the page tree for your vacancies pages, including the templates for the parent and child pages.

I am sure we can figure it out.

Link to comment
Share on other sites

Those pages are the last modified/created, and you get them because you're logged in as admin.

"include=all" doesn't only mean you get also pages from the trash but also unpublished and hidden ones.

I would try to test your code for if it finds something, so you can from the start rule out other things

$items = $pages->find("template=vacancy, limit=10, sort=-modified");
if(count($items)) ... else ...

or print out the PageArray result, it should give id's of the pages found 123|2939|2331 

echo $items;

If you search doesn't return anything, and without template=vacancy it does, then that looks like it's wrong something there?

Link to comment
Share on other sites

This code produces the expected results.

 $items = $pages->find("template=vacancy, limit=10, sort=-modified");
 if(count($items)) echo 'Found: '.count($items).' '.$items;
 
It seems that when it's rendered there is a problem.
 
Let me try to explain how I have this setup and show the code being used and the results I am seeing.
 
I have two sites (I'll call one feeder the other reader). On the feeder side I have a page named vacancies with child level pages for each vacancy using the template vacancy. The above find yields the correct page numbers. The vacancies page uses a template named vacancies (just a title). In the vacancies.php template file I have placed this code for the RSS feed.
 
// retrieve the RSS module
$rss = $modules->get("MarkupRSS");
 
// configure the feed. see the actual module file for more optional config options.
$rss->title = "Latest updates";
$rss->description = "The most recent vacancies updated on my site";
 
// find the pages you want to appear in the feed.
// this can be any group of pages returned by $pages->find() or $page->children(), etc.
$items = $pages->find("limit=10, sort=-modified");
//if(count($items)) echo 'Found: '.count($items).' '.$items;
// send the output of the RSS feed, and you are done
$rss->render($items);
 
On the reader side I have a function which dynamically executes an include to read the rss feed, this is the include file.
 
// include vacancies via rss from feeder site
$rss = wire('modules')->get("MarkupLoadRSS");
 
If I call the url http://undpw.local:8888/vacancies directly I get this output.
 
<rss version="2.0">
<channel>
<title>Latest updates</title>
<description>The most recent vacancies updated on my site</description>
<pubDate>Tue, 06 Aug 2013 12:22:38 -0400</pubDate>
<ttl>60</ttl>
<item>
<title>Selector test</title>
<description>
<![CDATA[ ]]>
</description>
<pubDate>Mon, 05 Aug 2013 15:40:17 -0400</pubDate>
</item>
</channel>
</rss>
 
When called via the reader I see this output.
 
<ul class="MarkupLoadRSS">
    <li>
        <a href="http://undpw.local:8888/about/what/">Child page example 1</a> 
        <time datetime="2010-10-25T23:21:34-04:00">October 25, 2010, 11:21 pm</time>
        <div>Ut capio feugiat saepius torqueo olimIn utinam facilisi eum vicis feugait nimisIusto incassum appellatio cui macto genitus vel. Lobortis aliquam luctus,</div>
    </li>
    <li>
        <a href="http://undpw.local:8888/">Home</a> 
        <time datetime="1969-12-31T19:00:00-05:00">December 31, 1969, 7:00 pm</time>
        <div>What is ProcessWire?ProcessWire gives you full control over your fields, templates and markup. It provides a powerful template system that works the way you</div>
    </li>
    <li>
        <a href="http://undpw.local:8888/templates/">Templates</a> 
        <time datetime="2010-10-26T01:59:44-04:00">October 26, 2010, 1:59 am</time>
        <div>The site template files are located in /site/templates/Each of the template files in this site profile includes the header template (head.inc),</div>
    </li>
    <li>
        <a href="http://undpw.local:8888/about/">About</a> 
        <time datetime="2010-10-25T22:39:33-04:00">October 25, 2010, 10:39 pm</time>
        <div>Si lobortis singularis genitus ibidem saluto.Dolore ad nunc, mos accumsan paratus duis suscipit luptatum facilisis macto uxor iaceo quadrum. Demoveo,</div>
    </li>
    <li>
        <a href="http://undpw.local:8888/site-map/">Site Map</a> 
        <time datetime="2010-11-30T21:16:49-05:00">November 30, 2010, 9:16 pm</time>
        <div></div>
    </li>
    <li>
        <a href="http://undpw.local:8888/about/background/">Child page example 2</a> 
        <time datetime="2010-11-29T22:11:36-05:00">November 29, 2010, 10:11 pm</time>
        <div>Pertineo vel dignissim, natu letalis fere odioSi lobortis singularis genitus ibidem salutoMagna in gemino, gilvus iusto capto jugis abdo mos aptent acsi qui.</div>
    </li>
</ul>
 
I have no idea what is going here.
 
 
Link to comment
Share on other sites

The code to render the rss feed should be placed in a template/page called "rss" or similar, not in the template for a "normal" page that includes content that you want in the feed.

Try that and let us know how you go. 

  • Like 1
Link to comment
Share on other sites

I just re-read this bit:

On the reader side I have a function which dynamically executes an include to read the rss feed, this is the include file.

 

// include vacancies via rss from feeder site
$rss = wire('modules')->get("MarkupLoadRSS");
 
If I call the url http://undpw.local:8888/vacancies directly I get this output.

I think I get what you are trying to do, but I don't think this can be done with an include.

You certainly can't call $rss->render on a url like that. It needs to be on a page array.

I think you might be able to make it work with a screenscrape approach. There might be better ways, but I still don't understand the connection between the feeder and reader sites. Are these separate domains? Again I am not really sure what you are after, but simplepie (http://simplepie.org/) might be useful if you are trying to parse an RSS feed from one site and display the results on another.

I think we still need more details to help you to figure out what you are trying to do.

Link to comment
Share on other sites

That is how I originally set things up, then changed to the vacancies.php. I have now created a new page named rss-vacancies which I have set to use a template file named rss.php. The vacancies.php file has been renamed to rss.php. So my include file now contains this to load the rss.

// include vacancies via rss
$rss = wire('modules')->get("MarkupLoadRSS");
 
Now calling this url directly.
 
I see this returned by rss.php
 
<rss version="2.0">
<channel>
<title>Latest updates</title>
<description>The most recent vacancies updated on my site</description>
<pubDate>Tue, 06 Aug 2013 13:34:03 -0400</pubDate>
<ttl>60</ttl>
</channel>
</rss>
 
On the reader end of things I now only get this.
 
<ul class="MarkupLoadRSS">
</ul>
 
 
Link to comment
Share on other sites

I know you are doing some unusual things with the include, but you still can't (unless there is something I am missing about the module), do:

echo $rss->render("http://undpw.local:8888/rss-vacancies");

Try this instead:

$rss->render($items);

You shouldn't need to be echo'ing it either.

At least try this standard approach first so you know the module is working as expected for you. Then perhaps you can figure out and better explain your other needs regarding the two site approach to all this.

Link to comment
Share on other sites

Just saw your second post. Yes they are two domains. Isn't the whole point behind rss to allow you to read rss feeds from other domains?



The code I am using on the reader side is right out of the documentation for MarkupLoadRSS

Example #2: Using the built-in rendering
----------------------------------------

$rss = $modules->get("MarkupLoadRSS");
echo $rss->render("http://www.di.net/articles/rss/");

Link to comment
Share on other sites

Ok, sorry, I thought you were using the feed generator module on the reader side for some reason. My mistake!

It is all starting to make more sense now.

Your code for MarkupLoadRSS (RSS Feed Loader) looks correct - sorry for the confusion there.

So I guess the issue is still the generation of the feed at that url on the other site. I am at a loss for why it is showing selector-test (which it shouldn't) and nothing else. Strangely, when looking at the output for your reader page, it seems like it is actually showing results of pages from the PW default profile (eg: Child page example 1).

Link to comment
Share on other sites

I haven't got many ideas left for you at the moment, but I would try generating your feed using the vanilla example that Ryan's mentions on the module page:

http://modules.processwire.com/modules/markup-rss/

Take the code out of your function and see if that generates the feed xml properly. Also make sure there is nothing else in that rss.php template - no main or head/foot inc files etc. If that works, then you can try adding it back into your function if need be.

Link to comment
Share on other sites

I've found out the whole problem with this. It is caused by the this line of code in the modules renderFeed method.

if(!$page->viewable()) continue;

If I comment the line out then it works fine - looks like a bug of  some type?

Link to comment
Share on other sites

I've found out the whole problem with this. It is caused by the this line of code in the modules renderFeed method.

if(!$page->viewable()) continue;

If I comment the line out then it works fine - looks like a bug of  some type?

Just wondering, are the pages you want to render as RSS hidden and/or unpublished? That line just says move on to the next viewable page...

Edited by kongondo
Link to comment
Share on other sites

Do your pages have title and summary fields?

// ProcessWire field to use for item title (default=title)
$rss->itemTitleField = 'title';

// ProcessWire field to use for item description (default=summary)
$rss->itemDescriptionField = 'summary';


 

Link to comment
Share on other sites

If $page->viewable() is returning false, then it means one of the following:

  • 1. the page it was given is unpublished
  • 2. the page is in the trash
  • 3. the page has no template file
  • 4. the user has no access to it as a result of access control settings in the page's template, or one of it's parent templates.
  • 5. A third party module is overriding the Page::viewable() function and changing the result. 

If you are logged in as superuser, then the page will always be viewable unless in the trash or has no template file. In your case, it sounds to me like it's most likely item 3 or 4 above. First, check that you actually have a /site/templates/vendor.php file. If you do, then look at the parent pages used by your pages using the "vendor" template. Do any of them define access?

  • Like 2
Link to comment
Share on other sites

Thanks Ryan - after hours of trying to figure out what I was missing in access control it turns out to be  something I wouldn't have thought about or noticed until it was working and I tried to link back. So I guess it makes sense for RSS that you would need to have a template to be viewable. Works as expected now.

  • Like 1
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
 Share

  • Recently Browsing   0 members

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