Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2007-04-21 14:17:30

anthonybooth
Member
From: UK
Registered: 2007-01-13
Posts: 21
Website

Create a pure xml page

Is it possible to create an xml page via a pluggin and using a blank section page (no html).
The problem i’m having is when i declare header(‘Content-Type: text/xml’); in my pluggin before creating the xml, the publish.php file overwrites it with it’s own declaration of header(“Content-type: text/html; charset=utf-8”);.
I do not want to modify the publish.php file so i’m stuck.
I want to use the xml with DOM for some ajax instead of using innerHTML and yes the php could be an external file which maybe my only answer but first i want to see if this method is possible.


Forever learning.

Offline

#2 2007-04-21 17:53:52

Bastian
Plugin Author
From: Wuppertal, Germany
Registered: 2005-02-02
Posts: 376
Website

Re: Create a pure xml page

It is possible, i figured out some different solutions.

The one which is easy to implement:
You need a little hack and a plugin and use a section xml to switch to xml:

Hack

  1. Open /textpattern/publish.php
  2. Find header("Content-type: text/html; charset=utf-8"); in function textpattern() (around line 645)
  3. Comment out this line

Plugin

Create a new plugin, which mainly does:

global $pretext;

if($pretext['section'] == 'xml')
	header("Content-type: text/xml");	
else
	header("Content-type: text/html; charset=utf-8");

Create section xml

Use this section for your xml stuff.
Depending on how far you want to get with your AJAX stuff, you will need some additional plugin functions to encode well formated xml out ouf txp:article

Note I use JSON in combo with prototype and that works well with header("Content-type: text/javascript").

Google for header content xml and try a little with your Javascripts.
The correct header for xml is
Content-Type: application/xhtml+xml
but for me it seems like that is header isn’t widely supported

Offline

#3 2007-04-21 18:08:46

Sencer
Archived Developer
From: cgn, de
Registered: 2004-03-23
Posts: 1,803
Website

Re: Create a pure xml page

This can be done with a simple plugin.
You can use output-buffering with a callback function to change the header. Before calling ob_start check all your conditions (section variable or whatever), and in the callbackfuntion only change the Content-Type header.

Offline

#4 2007-04-22 02:49:45

Jeremie
Member
From: Provence, France
Registered: 2004-08-11
Posts: 1,578
Website

Re: Create a pure xml page

Does anyone know of a simple plugin to attribute an article or a section’s page to an xml format? I was looking for this when I wanted TXP to handle my Google sitemap by hand, couldn’t find it.

Offline

#5 2007-04-22 06:06:28

Sencer
Archived Developer
From: cgn, de
Registered: 2004-03-23
Posts: 1,803
Website

Re: Create a pure xml page

It might look like the following (untested code).
llows you to use a tag <txp:abc_setthisheader name="Content-Type" value="text/xml" /> in page or form templates to set http-header-values.

function abc_setthisheader($atts) {
		global $abc_headers;
		extract(lAtts(array(
			'name'  => 'Content-Type',
			'value'  => 'text/xml',
		),$atts));
		$abc_headers[$name] = $value;
		if (!in_array('abc_headercallback', ob_list_handlers() ))
			ob_start('abc_headercallback');
}

function abc_headercallback($buffer) {
		global $abc_headers;
		if (isset($abc_headers) && is_array($abc_headers))
			foreach ($abc_headers as $name => $value)
				header("$name: $value");
		return $buffer;
}

edit: fixed code (assignment of $abc_headers[$name] = $value).

Last edited by Sencer (2007-04-22 07:08:22)

Offline

#6 2007-04-22 06:33:03

Jeremie
Member
From: Provence, France
Registered: 2004-08-11
Posts: 1,578
Website

Re: Create a pure xml page

Thanks Sencer :)

Offline

#7 2007-04-23 08:51:28

Bastian
Plugin Author
From: Wuppertal, Germany
Registered: 2005-02-02
Posts: 376
Website

Re: Create a pure xml page

Hey, Sencer.

That callback stuff is much better then my idea!

Just one question:
What happens if different plugins use the buffer?
Do they interfere?

Offline

#8 2007-04-23 17:18:14

anthonybooth
Member
From: UK
Registered: 2007-01-13
Posts: 21
Website

Re: Create a pure xml page

Thanks Sencer

For the quick response. The ob_start worked well, now on to the next stage.


Forever learning.

Offline

#9 2007-04-23 17:21:56

anthonybooth
Member
From: UK
Registered: 2007-01-13
Posts: 21
Website

Re: Create a pure xml page

Thanks Bastian

For your quick response but i wanted to do this without modifying the publish.php file so i have used Sencer suggestion but again thanks.


Forever learning.

Offline

#10 2007-04-23 20:46:43

Sencer
Archived Developer
From: cgn, de
Registered: 2004-03-23
Posts: 1,803
Website

Re: Create a pure xml page

Bastian wrote:

Just one question:
What happens if different plugins use the buffer?
Do they interfere?

I believe the manual answers your question:

http://php.net/en/ob_start

Output buffers are stackable, that is, you may call ob_start() while another ob_start() is active. Just make sure that you call ob_end_flush() the appropriate number of times. If multiple output callback functions are active, output is being filtered sequentially through each of them in nesting order.

So, it shouldn’t be a problem.

Offline

Board footer

Powered by FluxBB