Including 3rd party php scripts
From phpCMS
Contents |
[edit] Including third party PHP scripts
[edit] General information about dynamic scripts
You can include as many dynamic scripts in a phpCMS content file as you need.
Existing scripts can often easily be integrated into a phpCMS project. But sometimes major modifications might be necessary, e.g. if the script to be included uses exit() calls.
To integrate a script into a phpCMS powered web site, you have to define the script's output location in the template for the relevant (group of) pages and in the content file of the page(s) where you want the output of the script to appear.
[edit] The definition within a template
In the template file you add a placeholder where the script output should be displayed later. This placeholder will be filled with content after the script has been executed. A placeholder for scripts has always the prefix SCRIPT. After the prefix follows an unique identifier per script output. An example:
{SCRIPT_NO1}
{SCRIPT_2}
[edit] The definition within a content file
In every content file based on that template you can now define the script(s) that you want to display its/their output where the placeholder(s) is/are. These scripts can be different ones for every content file, but their output will be shown at the same location in all of the pages. You could integrate a guestbook on one page:
{SCRIPT_NO1} ./guestbook.php
and a forum plus the daily news on another one:
{SCRIPT_NO1} /forum/forum.php?showlogin
{SCRIPT_2} $home/news/daily.php
Please note the parameter passed to the first script in the second case.
In the first example the script guestbook.php is located in the same directory as the content file; in the second one the script forum.php is located in the directory /forum/ located under the document root, and the script daily.php in the directory /news/ located underneath the home directory of your project as defined in the project file.
If there is no script output wanted for one page, you simply do not enter a SCRIPT placeholder in its content file.
[edit] Passing parameters to a script
You can pass parameters to a script in two ways:
- directly in the content file when calling the script
- indirectly via a parameter passed to the content file.
[edit] Passing parameters directly
This was shown in the example above:
{SCRIPT_NO1} /forum/forum.php?showlogin
where 'showlogin' is the parameter passed to the script forum.php located in the /forum directory.
[edit] Passing parameters indirectly
If you have a content file demo.htm with the line
{SCRIPT_MYSCRIPT} /foo/somescript.php
and you call the content file with demo.htm?blah=blubb then you will find the variable $blah with the content 'blubb' inside of somescript.php, exactly as if you had called somescript.php?blah=blubb.
With that method pay attention though if you have inserted more then one script in your content file as in the example above:
{SCRIPT_NO1} /forum/forum.php?showlogin
{SCRIPT_2} $home/news/daily.php
as the parameters passed to the content file when calling it will be passed to all those scripts. When e.g. calling the content file with demo.htm?blah=blubb as above then you will find the variable $blah with the content 'blubb' inside of forum.php and daily.php, exactly as if you had called them as forum.php?showlogin&blah=blubb and daily.php?blah=blubb. So name the parameters/variables in the scripts in such a way that there is no conflict.
[edit] Customizing a script for phpCMS
As mentioned above, you might encounter problems when including scripts.
- If a script contains the display part of its result, you will have to eliminate the whole <head>...</head> part plus the <body> and </body> tags as they are already contained in your header and footer templates.
- When a script displays a form for the user to fill out, you will have to adapt the destination of the form data, which might be another script. In that case you replace that with a different content file (.htm) created for that matter and containing a SCRIPT placeholder for the original destination script.
- As mentioned above, a further problem are exit() calls within scripts, which will end the whole PHP session including the phpCMS parser. Unfortunately there is no general solution for this issue. You will have to analyze the script carefully to find a work-around.
- A similar problem is the PHP header() function if used in a script. It sends raw, i.e. in no way formatted HTML headers to the browser, thus disrupting the flow of pages in your process.
[edit] SCRIPTs and Spidering Feature
At the moment Spidering does not seem to work with php scripts, spidered pages display [*SCRIPT*] where there should have been script output. Otherwise scripts work in the non-spidered version.
Main Page: User Documentation MainPage
« Previous Page: How to use plugins | Top Page: How to work with phpCMS | Next Page: How to use PAX »

