Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
How to use Pretext Callback for custom RSS Feed?
Seems like it should be rather simple. I already have a custom feed setup via a page called rss-feed. How do I output the rss-feed page in place of rss?
register_callback(‘gbb_rss_feed’, ‘pretext’);
function gbb_rss_feed() {
// output rss-feed page if user accessed /rss
}
Offline
#2 2007-12-21 05:31:26
- net-carver
- Archived Plugin Author
- Registered: 2006-03-08
- Posts: 1,648
Re: How to use Pretext Callback for custom RSS Feed?
If it’s a simple matter of re-formatting data then why not register a routine for the rss_entry
event and let the default code take care of building the feed for you.
If you really want to go ahead and replace the default rss routines then yes, I think a pretext callback like this…
register_callback( 'gbb_rss_wrapper' , 'pretext' );
function gbb_rss_wrapper()
{
if(gps('rss'))
exit( gbb_rss_feed() );
}
…might do it.
Edited to add: Of course, you’ll need to make sure that your custom feed routine outputs all the right headers and formats a valid feed. Watch out for lurking whitespace at the start or end of any included php files.
Last edited by net-carver (2007-12-21 05:33:05)
— Steve
Offline
Re: How to use Pretext Callback for custom RSS Feed?
The reason I don’t want to hook into rss_entry is that my feed is completely customized in a way that using a page template makes it really easy to construct the feed itself.
Thank you for the code… however, the function that I don’t know how to write is the gbb_rss_feed() function (that would output the “rss-feed” page).
Also, what does the exit() function do in this context (or in any context)?
Offline
#4 2007-12-21 05:59:05
- net-carver
- Archived Plugin Author
- Registered: 2006-03-08
- Posts: 1,648
Re: How to use Pretext Callback for custom RSS Feed?
Ok,
- Here’s the php.net entry for
exit()
. You might want to bookmark that site or download the manual for future reference — it’s very useful. - Ok, the code for
gbb_rss_feed()
— you could start by looking at thetextpattern/publish/rss.php
file. That’s where the normal php processing code lives.
However, if you are going for a page/form solution you shouldn’t need this, just do what Matthew did in this thread.
(Edited to add missing link to the exit manual entry)
Last edited by net-carver (2007-12-21 06:00:47)
— Steve
Offline
Re: How to use Pretext Callback for custom RSS Feed?
net-carver, thanks for the response! However, I don’t think you understand how truly simple my question is. I have already created the page/form and tested the feed and everything. All I need to know how to do is output the actual section/page/form.
(Sorry, I did mix up my naming in previous post: I have a section called rss-feed that uses a page called rss which uses a plugin called mg_setheader and calls a form called rss-item.)
Thanks, I now understand what exit() does. It seems like I should be calling the textpattern() function or something, like:
exit(textpattern(‘rss-feed’))but obviously that’s not correct.
Offline
#6 2007-12-21 06:40:30
- net-carver
- Archived Plugin Author
- Registered: 2006-03-08
- Posts: 1,648
Re: How to use Pretext Callback for custom RSS Feed?
Yeah, you’re probably right about my not understanding :0)
Try just putting this link in your html head then…
<link rel="alternate" type="application/rss+xml" title="RSS Feed" href="http://YOUR SITE HERE/rss-feed/" />
No need to approach it programmatically if the /rss-feed section is producing valid output.
Regards,
— Steve
Offline
Re: How to use Pretext Callback for custom RSS Feed?
Thanks again, but that’s not it: I have already done that.
Here is my website:
http://www.hookah-cafe.com
Here is my custom feed (it works, try it):
http://www.hookah-cafe.com/rss-feed
Here is the default textpattern feed:
http://www.hookah-cafe.com/rss
When my users go to http://www.hookah-cafe.com/rss I want textpattern to output the custom feed instead of the default feed. (I don’t want to use a redirect)
Offline
#8 2007-12-21 07:13:11
- net-carver
- Archived Plugin Author
- Registered: 2006-03-08
- Posts: 1,648
Re: How to use Pretext Callback for custom RSS Feed?
Ok, now I think I understand (but then again!)
Give this a try: look in textpattern/publish.php
for the preText() routine…
function preText($s,$prefs)
{
extract($prefs);
callback_event('pretext');
# if(gps('rss')) {
# include txpath.'/publish/rss.php';
# exit(rss());
# }
...
Just comment out the code that calls the normal rss routine. Now rename your rss-feeds section to rss and it might just do it. (But that is a guess.)
— Steve
Offline
Re: How to use Pretext Callback for custom RSS Feed?
Modifying config.php is not an option I like. But that’s ok, I think I found the simplest way. (Messy URL’s wont work but I don’t use them…)
Thanks!
register_callback('gbb_rss_feed', 'pretext');
function gbb_rss_feed() {
$req = '';
if ($permlink_mode != "messy") {
$req = serverSet('REQUEST_URI');
extract(chopUrl($req));
}
if (($u1 == 'rss') or gps('rss')) {
// could use something more generic
$_SERVER['REQUEST_URI'] = 'http://www.hookah-cafe.com/rss-feed';
}
}
Offline
#10 2007-12-21 08:09:53
- net-carver
- Archived Plugin Author
- Registered: 2006-03-08
- Posts: 1,648
Re: How to use Pretext Callback for custom RSS Feed?
Yes, that looks even better than my idea.
— Steve
Offline