NAVIGATION
Requirement: <$phpwcms['allow_ext_render'] = 1; → /config/phpwcms/conf.inc.php
Description:
Into the folder template/inc_script/frontend_render/ you can install own php scripts, which are processed while parsing (simplified: Internal processing) the site, before the page is delivered to the browser.
All files ending with *.php are loaded and implemented by the system. The file names are freely selectable (recommended sample: rt_mein_dateiname.php).
The sequence of processing is not assignable without special programming.
The principal item is usually the variable $content [“all”], which is holding the content of the page (between <body> and </body>).
Naturally also different system external functions can be implemented.
Folder: template/inc_script/frontend_render/
Condition: → /config/phpwcms/conf.inc.php
In all files in these folders should be for security reasons at the beginning of each file, the following sequence:
<?php // ---------------------------------------------------------------- // obligate check for phpwcms constants if (!defined('PHPWCMS_ROOT')) { die("You Cannot Access This Script Directly, Have a Nice Day."); } // ---------------------------------------------------------------- ... ...
The file content of a very simple procedure, which simply will write only the text ” That is an unreasonable text” to the end of page at each page:
<?php // ---------------------------------------------------------------- // obligate check for phpwcms constants if (!defined('PHPWCMS_ROOT')) { die("You Cannot Access This Script Directly, Have a Nice Day."); } // ---------------------------------------------------------------- $content["all"] .= '<p>That is an unreasonable text</p>'; ?>
The file content of a very simple example:
<?php // ---------------------------------------------------------------- // obligate check for phpwcms constants if (!defined('PHPWCMS_ROOT')) { die("You Cannot Access This Script Directly, Have a Nice Day."); } // ---------------------------------------------------------------- $content["all"] = str_replace('{My_TicTac}', 'My clock ist working very well.', $content["all"]); ?>
The used tag: {My_TicTac}.
Inserted into a cp
{My_TicTac} {DATE_LONG}
the result
My clock ist working very well. Freitag, 23. Januar 2009
at frontend.
The tag is replaced by the result of the /frontend_render/ file. (The system tag {DATE_LONG} is in use also).
<?php /* ================================================================ dd.mm.yyyy Short descrition Autor: My Name TAG: {My_Tag} Filename: my_tag_replacer.php Folder: /template/inc_script/frontend_render/ Switch: $phpwcms['allow_ext_render'] = 1; (/config/phpwcms/conf.inc.php) Forum: http://forum.phpwcms.org/viewtopic.php?p=xxxxx ================================================================ */ // ---------------------------------------------------------------- // obligate check for phpwcms constants if (!defined('PHPWCMS_ROOT')) { die("You Cannot Access This Script Directly, Have a Nice Day."); } // ---------------------------------------------------------------- if( ! (strpos($content["all"],'{My_Tag:')===false)) { function func_my_specials ($spec1,$spec2) { $my_spec_result = ' ['. $spec2 . ' + '. $spec1 . ']'; return $my_spec_result; } function func_my_tag_replacer ($var1, $var2, $var3 = "no parameter catched") { // My_php_code/source; // e.g. $my_result = ' var1= '. $var1 . func_my_specials ($var3,$var2) . '<br /> var2= '. $var2 . '<br /> var3= '. $var3 . '<br />'. LF; return $my_result; } // {My_Tag:,,} or {My_Tag:} // ----------------------------------------------------- $content["all"] = str_replace('{My_Tag:}', func_my_tag_replacer("Werner","Ulla"), $content["all"]); $content["all"] = preg_replace('/{My_Tag:(.*?),(.*?),(.*?)}/e', 'func_my_tag_replacer("$1","$2","$3")', $content["all"]); // ----------------------------------------------------- } // -----------[ CLOSE ]---------------- ?>
Call in a CP:
{My_Tag:} {My_Tag: first mad text, second mad text, third mad text}
Frontend output:
var1= Werner [Ulla + no parameter catched] var2= Ulla var3= no parameter catched var1= first mad text [ second mad text + third mad text] var2= second mad text var3= third mad text
This way it is possible to solve very special problems.
— Knut Heermann (flip-flop) 2009/01/23 15:19
If you have more than one file within frontend_render and the results of the routines are depending on each other, a fundamental problem of the processing sequence is arising.
We can´t determinethe processing sequence of the files in this folder directly.
Explained by the example NAV_HORIZ_DD and the FE language switch.
–> Forum
If the frontend_render language switch is processed before the NAV_HORIZ_DD script, all language tags in this navigation file are not processed.
[de]Das Haus[/de][en]The Hotel[/en][de]Urlaub & Familie[/de][en]Holidays & Family[/en]
The simplest solution:
Shift the concerning files into another folder and define the correct processing order of the these files with the help of a third file.
<?php // ---------------------------------------------------------------- // obligate check for phpwcms constants if (!defined('PHPWCMS_ROOT')) { die("You Cannot Access This Script Directly, Have a Nice Day."); } // ---------------------------------------------------------------- // Specifies the sequence of processing files include ('special/rt_nav_horiz_drop_down.php'); // processing first include ('special/lang_replace.php'); // processing second ?>
To optimize the script's runtime on your server you can put the content of all /frontend_render/* files in the right order into one file e.g. called /frontend_render/master.php. Disable all other files of this folder by extending the suffix like e.g. *.php_
Thats it, we have determined the processing order.
(You can do this with all other php snippets in /frontend_render/ if you have similar problems).