Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Re: rah_external_output
That was indeed what I was trying to do…. however, if I copy paste a form and add it as a snippet in rah_external_output it uses the form to pull in actual content from the database the snippet is part of… rather I would like to pull in the form code, as code, so that the content is subsequently loaded from the database that pulls in the form through rah_external_output… In that scenario I can use the rah_external_output snippets from the main database as the templates or building blocks for my pages and forms in my related websites…
Offline
Re: rah_external_output
I doubt rah_external_output will help you to achieve easily what are you trying to (although Gocom may have some clever trick under his sleeves). It will require something like rah_external_output sending the plain text (not parsed) for the forms & pages, which then your other related website will need to pick up and parse in real time or maybe, dump it back to the database, and then, parse/render it with the contents. Sounds like an overthought mechanism…
I’ve done something similar (share pages & forms across a few related websites, each one with its own content) a few times in the past.
A multi-site installation may be helpful although it’s not mandatory for this kind of setup.
The main question is: are all these related website going to be hosted on the same server? Not mandatory neither, but sharing pages & forms across websites hosted in different servers may be a bit more trickier (it may probably require mounting a folder from the main website server into every related website hosting).
In any case, the key to get this setup working is using cnk_versioning. a plugin that lets you store pages & forms in the filesystem (making edition/versioning easier), and that there are “dumped back” to database.
So, you could create two folderes (forms/ and pages/) to store all your forms & pages, and then, you could configure cnk_versioning on each website (the main one and the related ones) to look for forms & pages on those two folders. This may be even easier to setup with a few symlinks properly placed.
Taking this one step further, you could store forms & pages on some common folder, but then, on each particular website, create the two necessary folders (again, forms/ and pages/), and from inside those two folders, create symlink only to some (not all) pages & forms that you would like to share across all the websites.
Time to tinker!
Offline
Re: rah_external_output
sidekarsten, I’ve moved our discussion to cnk_versioning thread, to avoid hijacking further this plugin’s thread.
Offline
Re: rah_external_output
Hi.
I have try to get as output an image:
<txp:php>
header("Content-Type: image/jpg");
$image = imagecreate(200,295);
imagejpeg($image);
imagedestroy($image);
</txp:php>
but I obtain always an error: the image contain errors.
Why? If i past this code into a php file it work fine!
Offline
Re: rah_external_output
MarcoK wrote:
I have try to get as output an image:
As a general warning, please avoid creating images on fly. You will at least want a caching mechanism and preferably you would link to actual flat files instead of a PHP page. Initializing a CMS for generating image isn’t the best way to ensure that your website is up and running.
but I obtain always an error: the image contain errors.
The code works correctly for me. I get the intended black box of doom. Uses lot of memory, as could be expected and I certainly wouldn’t use it in real world, but it works. I suggest making sure that the image is created successfully (no feces is hitting the fan), and after that making sure that there is nothing else returning (echoing) anything. No code causing errors (plugins etc), no conflicts with any plugins (no plugins that hook on events, use echo etc, modify page contents on fly), no trailing whitespace coming from any PHP files (no newlines at the end of the file), and no on-fly page compressing is interfering.
header("Content-Type: image/jpg");
I would suggest adding image/jpg to the Content-type field on the editor and removing that line. The plugin sends a content-type header.
Offline
Re: rah_external_output
Thanks
Offline
Re: rah_external_output
Hi Jukka,
I am using this plugin extensively to link content between sites. Thanks! Can you please advice on the php code I need to output some static content should the server has an error (such as database unavailable, 500, etc)
At the moment I am using <?php include($DOCUMENT_ROOT . "http://www.site.tld/?rah_external_output=something"); ?> Ideally it should be something like
if content fetched: include;
else;
some static html here;
Any advice would be appreciated
Last edited by colak (2012-02-10 09:58:56)
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: rah_external_output
colak wrote:
Can you please advice on the php code I need to output some static content should the server has an error (such as database unavailable, 500, etc)
Yiannis, you asked same question two year ago ;-) My past self replied. Quoting my past self, with cURL you can get the HTTP status code returned by the server. E.g.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://example.com/?rah_external_output=snippet');
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$file = curl_exec($ch);
$http = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo $file !== false && $http == '200' ? $file : 'Error appeared. Sad face.';
Above is same deal as in the old reply. Requires cURL.
Last edited by Gocom (2012-02-10 10:52:21)
Offline
Re: rah_external_output
Hi Jukka, Now that you made your time travel I remember about the discussion. Unfortunately then, the code returned an error when used in a txp site. When I use it in an independent php page now, the txp content is not fetched and it shows the alternative html instead.
Last edited by colak (2012-02-10 14:23:43)
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: rah_external_output
colak wrote:
Hi Jukka, Now that you made your time travel I remember about the discussion. Unfortunately then, the code returned an error when used in a txp site.
The database error issues you mentioned shouldn’t have any relation to the code, while the old code doesn’t work (but not because of that). If the errors appeared during saving (via admin-side interface), then the cause assumable might be, for instance, bad escaping in SQL queries ran by the used editor. If you were trying to save the code as a rah_extenal_output’s snippet and used outdated release (pre-v0.4), then the problem would be the editor and SQL statement escaping (which was fixed in v0.4 update).
When I use it in an independent php page now, the txp content is not fetched and it shows the alternative html instead.
If you are trying to use the old code posted back then, it should not work (as it is). Yes, you did read the not correctly. Unlike not-so-popular believe, my just examples, not tested, probably won’t work clauses are true statements and I cowardly stand behind them. The snippet I posted back then has some typos, fatty fingers so to speak.
The newer code I posted today, on the other hand, is functional and works just fine (it’s even tested – rare).
As compatibility goes, it does require up-to-date version of cURL (as in PHP5), privileges to make outbound HTTP (port 80) connections. Also you would want to change the example URL in the snippet (as full URL, string, nothing extra) and make sure that there are no re-directions or incorrect HTTP status codes sent by the target server.
Last edited by Gocom (2012-02-10 15:49:05)
Offline
Re: rah_external_output
If anybody wants to use this plugin to create simple XML that is then parsed by something like smd_xml (like I was), I’ve written up my experience.
Thanks to SOCOM for releasing this killer plugin.
Offline
Re: rah_external_output
Rah_external_output v1.0 is now available. The update includes number of changes. The main thing everyone updating will see is that there is no extra panel anywhere. Now the plugin uses Form partials to operate. Creating new snippets happens from Forms panel, and these snippets are stored as standard forms. All tools that are specific to forms on database level or present on the Forms panel, like the Tag Builder, now work with rah_external_output. Guys that are used to cnk_versioning may like that.
New features include user-configurable HTTP header lines and file extensions. A snippet using .xml extension will now be served as XML document. Lines at the beginning of the snippet staring with a semicolon are sent as headers.
This release is Textpattern 4.5.0 compatible. Older version, including v0.9, do not work with TXP v4.5.0 (or newer).
Full list of changes:
- Removed: Plugin’s own user interface. The plugin now uses
rah_eo_prefixed form partials and integrates with Forms panel. - Removed:
<txp:rah_external_output />tag. As forms are used, normal and more flexible output_form tag can be used. - Removed: Raw PHP support to comply with r3706.
- Added: Ability to set a snippet’s content-type using a file extension in the name.
- Added: Migration assistant script. The script is run automatically on install and migrates rah_external_output snippets from the old interface to Forms.
- Added:
rah_external_output.snippet_endcallback event for developers. - Changed: Returns a 404 page instead of the home page when requesting a nonexistent snippet.
- Changed: Tag trace can no longer be controlled using a URL parameter. A tag trace is added when the snippet name has a
.htmlextension and the site is in debugging mode. - Now requires PHP5 or newer.
- Compatibility with Textpattern v4.5.0.
Last edited by Gocom (2012-07-14 02:15:24)
Offline
Re: rah_external_output
Hi Jukka,
I’m using the plugin and this snippet to provide content across sites.
Can you advice on how that can be replaced using the new version of the plugin?
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: rah_external_output
colak wrote:
Can you advice on how that can be replaced using the new version of the plugin?
The plugin behavior is the same, and old snippets are migrated to Forms during install too. All old snippets will be kept intact and URLs stay the same too. In other words, you shouldn’t have to change anything.
Offline
Re: rah_external_output
The update seemed to work like a dream…. Thanks for all your work Jukka.
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline