Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#37 2010-02-15 15:52:52

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: rah_external_output

Nice that you got it working lovetheg :-)

Offline

#38 2010-02-16 14:40:34

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,564
Website GitHub Mastodon

Re: rah_external_output

For those baronial types using jsp for development, the equivalent jsp code of the php in message #36 for pulling rah_external_output into their pages is:

<c:import url="http://www.mysite.com/">
 <c:param name="rah_external_output" value="XXX"/>
</c:import>

Where XXX is the name your gave your snippet in the rah_external_output admin.

Hope that is of help to people.
Phil

Offline

#39 2010-02-16 16:17:42

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: rah_external_output

Thank you for sharing Phil :-)

Maybe some fetching examples won’t hurt. Let’s see; In cURL including can be expanded on an idea like:

<txp:php>
	$curl = curl_init();
	curl_setopt ($curl, CURLOPT_URL, 'http://example.com/?rah_external_output=MyScriptName');
	curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1);
	echo curl_exec ($curl);
	curl_close ($curl);
</txp:php>

cURL is ideal if communicating with the server is required; cURL mimics a real web browser and supports multiple protocols and can send headers.

Example number two. If TXP is used, including can be done with plugins. That way there is no need to look raw PHP. Here is an example that uses rah_function. It tries to include contents of the URL with file_get_contents():

<txp:rah_function call="file_get_contents" url="http://example.com/?rah_external_output=MyScriptName" />

Last edited by Gocom (2010-02-16 16:22:15)

Offline

#40 2010-02-26 06:57:26

mrtunes
Member
From: Toronto, On
Registered: 2007-03-12
Posts: 575
Website

Re: rah_external_output

finally getting around to using this!

i saw an earlier in this thread other people are also using this for ical like applications. the part that i don’t get is how to make it export to a file rather than spit out on the page. i don’t know what i should set for content type, but i imagine it also has something to do with what i put in the presentation form.

BEGIN:VEVENT
DTSTART;VALUE=DATE:20060704
DTEND;VALUE=DATE:20060705
SUMMARY:<txp:body />
X-GOOGLE-CALENDAR-CONTENT-TITLE:<txp:title />
X-GOOGLE-CALENDAR-CONTENT-ICON:http://www.google.com/calendar/images/google-holiday.gif
X-GOOGLE-CALENDAR-CONTENT-URL:<txp:article_image />
X-GOOGLE-CALENDAR-CONTENT-TYPE:image/gif
X-GOOGLE-CALENDAR-CONTENT-WIDTH:276
X-GOOGLE-CALENDAR-CONTENT-HEIGHT:120
END:VEVENT
<txp:rah_external_output name="ical" />

Offline

#41 2010-03-06 20:59:04

mrtunes
Member
From: Toronto, On
Registered: 2007-03-12
Posts: 575
Website

Re: rah_external_output

just wondering if anyone got a chance to take a look at my post above? thanks

EDIT: sniffing around a bit more i was able to find this tool: <a href=”<txp:site_url />?rah_external_output=ical”>download iCal</a>

this seems to make a file out of things you create with rah external output. the only thing missing is it doesn’t give a file name when the user downloads. this is great for so many uses like m3u playlists is one on the top of my head.

i would suggest adding it to the help file.

Last edited by mrtunes (2010-03-06 21:22:21)

Offline

#42 2010-03-06 22:18:55

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,754
Website

Re: rah_external_output

Thinking aloud, I wonder whether jukka’s htaccess trick at the end of rah_sitemap would work here too… if so, then you would link to the file name…


TXP Builders – finely-crafted code, design and txp

Offline

#43 2010-03-07 08:39:15

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,101
Website GitHub Mastodon Twitter

Re: rah_external_output

I’m using this plugin extensively to cross relate our sites.

I wonder if there is some php I could use to prevent white screens when database is unavailable.

something like

<?php if database available // or if no error
 include($DOCUMENT_ROOT . "http://my-txp-site.tld/?rah_external_output=template1"); 
else;
<p>some content here</p>
?>

Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#44 2010-03-07 15:56:25

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: rah_external_output

These are totally just examples. Not tested, probably won’t work.

<?php
	$content = file_get_contents('http://www.example.com?rah_external_output=name');
	if(
		!$content or $content == 'My some error page content here'
	)
		echo 'Some content here';
	else
		echo 'hi';
?>

Above example really isn’t error awere at all. With curl you can return the error code. By modifying that example, we can get something like:

<?php
	$curl = curl_init();
	curl_setopt ($curl, CURLOPT_URL, 'http://example.com/?rah_external_output=MyScriptName');
	curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt($ch, CURLOPT_HEADER, 1);
	curl_setopt($ch, CURLOPT_TIMEOUT, 30);
	$content = curl_exec ($curl);
	$data = curl_getinfo($ch);
	curl_close ($curl);
	if($data['http_code'] != '200')
		echo 'Some content here';
	else
		echo $content;
?>

Last edited by Gocom (2010-03-07 15:58:31)

Offline

#45 2010-03-08 16:27:13

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,101
Website GitHub Mastodon Twitter

Re: rah_external_output

Hi Jukka. Thanks! That was a swift answer. Not sure if it’s working or not (2nd snippet) as it produces database errors.


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#46 2010-03-24 17:04:39

sacripant
Plugin Author
From: Rhône — France
Registered: 2008-06-01
Posts: 479
Website

Re: rah_external_output

Hello and sorry for my bad english,

I want to create a adress book with a Vcard for each item.

In my article form :

<a title="download Vcard" type="text/x-vcard" href="<txp:site_url />?rah_external_output=vcard&amp;id=<txp:article_id />">Add to Adress Book</a>

My external output vcard :

<txp:article_custom id='<txp:adi_gps name="id" />'>BEGIN:VCARD
SOURCE:<txp:site_url />
N:;;;;
ORG;CHARSET=UTF-8:<txp:title />
FN;CHARSET=UTF-8:<txp:title />
EMAIL;INTERNET:<txp:custom_field name="Email" />
TEL;WORK:<txp:custom_field name="Tel"/>
URL;WORK:<txp:custom_field name="Url" />
END:VCARD
</txp:article_custom>

content/type : text/x-vcard

With Safari : No prob, he download a file site_name.vcf and open this file in address book.

With IE : Idem, ni prob.

with Opera : he download a file with name “default” and no extension !

with Firefox : he download a file with random name and “.part” extension !

WHY ? A idea ? Thanks.

Offline

#47 2010-03-24 17:10:42

mrtunes
Member
From: Toronto, On
Registered: 2007-03-12
Posts: 575
Website

Re: rah_external_output

sacripant, that’s similar to my problem above. i couldn’t figure out how the file is actually generated.

Offline

#48 2010-03-25 10:43:16

sacripant
Plugin Author
From: Rhône — France
Registered: 2008-06-01
Posts: 479
Website

Re: rah_external_output

Hello,

I have a solution.
A priori manage only the header content/type is not enough.
You must add the “Content-Disposition” and “filename” with php :

<txp:php>
header('Content-Type: text/x-vcard; charset=utf-8');
header('Content-Disposition: attachment; filename="vcard.vcf"');
</txp:php> <txp:article_custom id='<txp:adi_gps name="id" />'>BEGIN:VCARD
SOURCE:<txp:site_url />
N:;;;;
ORG;CHARSET=UTF-8:<txp:title no_widow="0" />
FN;CHARSET=UTF-8:<txp:title no_widow="0" />
EMAIL;INTERNET:<txp:custom_field name="Email" />
TEL;WORK:<txp:custom_field name="Tel"/>
URL;WORK:<txp:custom_field name="Url" />
END:VCARD
</txp:article_custom>

To add the title to the filename :

<txp:article_custom id='<txp:adi_gps name="id" />'><txp:php>
$a = title (array (
  no_widow => '0'
));
header('Content-Type: text/x-vcard; charset=utf-8');
header('Content-Disposition: attachment; filename="'.$a.'.vcf"');
</txp:php>BEGIN:VCARD
SOURCE:<txp:site_url />
N:;;;;
ORG;CHARSET=UTF-8:<txp:title no_widow="0" />
FN;CHARSET=UTF-8:<txp:title no_widow="0" />
EMAIL;INTERNET:<txp:custom_field name="Email" />
TEL;WORK:<txp:custom_field name="Tel"/>
URL;WORK:<txp:custom_field name="Url" />
END:VCARD
</txp:article_custom>

Is it possible for this plugin to manage “charset” , “Content-Disposition” and “filename” ?
Thanks

Offline

Board footer

Powered by FluxBB