Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
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
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
- Open
/textpattern/publish.php
- Find
header("Content-type: text/html; charset=utf-8");
infunction textpattern()
(around line 645) - 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
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
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
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
Offline
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
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
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
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
Pages: 1