Plug:ignatius:phpCMS PostParser
From phpCMS
This article needs additional content.
Please remove this message from the page after completing the article and make also sure that the page has been removed from the listing on the needs content-page.
Contents |
[edit] phpCMS PostParser
[edit] Overview
title : phpCMS PostParser version : 0.1alpha author : (c) 2006 by Thilo Wagner (Ignatius) licence : GPL description : phpCMS version: tested with phpCMS 1.2.x
Please post any errors, discussions etc. about this plugin to the phpCMS forum at http://www.phpcms.de or twagner (at) drachenreiter.de
[edit] License
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
[edit] Download
Download from the phpCMS website at Download -> Plugins
[edit] Plugin description
If a script is integrated directly with {script} placeholder, following happens: phpCMS produces a "php output buffer". After this instead of sending all lines of text to user’s Web browser phpCMS sent to an internal cache (php). After this phpCMS integrates “third party script” by php-order "include" and executes it embedded in phpCMS. By “output buffer” the whole output of “third party script” is intercepted. As soon as “third party script” is worked off, phpCMS reads output buffer and inserts lines of text of “third party script” in same line of phpCMS template, where has been {SCRIPTxxxx} before. After this output buffering of php is finished. Now “third party script” is included in phpCMS template. Unfortunately this "trick" with output Buffer works only with scripts, which are written in php. In other cases it is better, tu use “webgrab”, which is able to include scripts in other programming languages (e.g. Perl).
[edit] Conditions:
If you want to integrate a “third party script” directly with {SCRIPT} placeholder, this script must satisfy some conditions.
1. An included script mustn't use order exit() calls. Therefore script runs as a part of phpCMS and phpCMS still must go on after the end of “third party script”. (e.g. to insert content of output buffer in template and still other things). For this case php-order exit() ends immediately php interpreter and therefore at the moment phpCMS is "stifled" itself, too.
Code of script must be changed, if it uses exit() calls. This case is fortunately rather in php-scripts. If you aren’t fit in php programming or greater changes become necessary in script, it would be a better solution, to integrate script with WebGrab.
2. An included script should not have own HTML header or footer. An example: “third party script” has following code:
Code: <html> <head> <title>SCRIPT01</title> </head> <body bgcolor="#202020"> <p> Hello world! </p> </body> </html>
and phpCMS template’s code is:
Code:
<html>
<head>
<title>phpCMS page</title>
</head>
<body fgcolor="#FF0000">
<!-- start of output data of included script -->
{SCRIPT_01}
<!-- end of output data of included script -->
</body>
</html>
After phpCMS has intercepted output of script and has included into its own template, page becomes following code:
Code: <html> <head> <title>phpCMS page</title> </head> <body fgcolor="#FF0000"> <!-- start of output data of included script --> <html> <head> <title>SCRIPT_01</title> </head> <body bgcolor="#202020"> <p> Hello world! </p> </body> </html> <!-- end of output data of included script --> </body> </html>
Additional HTML header and Footer are actually contained in body part. Of course this is wrong and not in conformity with HTML. You have to provide, embedded script must not write own <head>...</head> part or <body> / </body> tags, but only the part, which should be later in the body part of ready side. Output of embedded script should look in our example so: Code:
<p> Hello world! </p>
You can reach this result by removing all lines from the included script, which unnecessary produce HTML header/footer. Of course it would be optimal, if included script works with own templates, which are to change simply without changing the real script.
3) Please pay attention, that in included script all links (e.g. index.php), which have pointed to "stand allone"-HTML page before, now point to html.file (e.g. index.html). Only so included script remains embedded in phpCMS furthermore, if user clicks on a link in included script.
Often it is enough, if you open script and change all occurrences (e.g. index.php) with look for & replace function in index.html.
Steps no. 2 and no. 3 are often easy to change at simple scripts (e.g.guestbook etc.) and without problems they are to fix in script’s source code.
[edit] Idea of PostParserScript
Steps 2 and 3 become unnecessarily, because 'Ignatius' has programmed a script for phpCMS named PostParser, which will fix both steps automaticly.
PostParserScript will included by {script} placeholder immediate after “third party script“. Afterward it corrects output of “third party script“. It moves output of HTML header and attributes of <body> tags into the right place of the page.
PostParser-script can be configured to replace character strings in output data of included script (e.g. index.php into index.html).
You can forget all problems with steps no. 2 and no. 3. It becomes unnessarily to change code of „third party script“.
In phpCMS template postParser script is included after „third party script“. In our example arises following code:
Code:
<html>
<head>
<title>phpCMS page</title>
</head>
<body fgcolor="#FF0000">
<!-- start of output data of included script -->
{SCRIPT_01}
{SCRIPT_phpcmsPostParser}
<!-- end of output data of included script -->
</body>
</html>
PostParser script doesn't cause any output by itself. It only accesses internal cache, where phpCMS fixes ready page, and solves problems with steps 2 and 3. In our example code is at the end.
Code: <html> <head> <title>phpCMS page</title> <title>SCRIPT_01</title> </head> <body fgcolor="#FF0000" bgcolor="#202020"> <!-- start of output data of included script --> <p> Hello world! </p> <!-- end of output data of included script --> </body> </html>
So postParser script has made following:
- PostParser script removes HTML header and HMTL footer of included „third party script.“
- All tags, which are within HTML header of included „third party script“ are moved to originally HTML header, which is caused by phpCMS template. In our example only <title> </title> tag was moved.
- All attributes of the <body> tag of included „third party script“ are inserted in originally body tag. In our example: bgcolor = "#202020".
In our example there would be two <title> tags in code of header. Of course this would be wrong. But in real application you couldn't insert any header tag into the phpCMS template and your problem would be solved.
(Solution by 'Ignatius' in the phpCMS Support Forum)
[edit] Development status / known bugs
No known bugs at the moment. Found any bugs? Then please contact me!
[edit] Version History
29.03.2006 V0.1alpha
- First public release
Diese Seite in anderen Sprachen: Deutsch
Main Page: Main Page | Top Page: Plugin Documentation MainPage

