Source for file outputfilter.pagevars.php
Documentation is available at outputfilter.pagevars.php
* Zikula Application Framework
* @copyright (c) 2004, Zikula Development Team
* @link http://www.zikula.org
* @version $Id: outputfilter.pagevars.php 24342 2008-06-06 12:03:14Z markwest $
* @license GNU/GPL - http://www.gnu.org/copyleft/gpl.html
* @package Zikula_Template_Plugins
* Smarty outputfilter to add page variables and additional header global into page header
* By default this output filter places page variable output immediately prior to the closing
* head tag (</head>). The output can, optionally, be placed anywhere in the template by adding
* the HTML comment <!-- pagevars --> to the page template. Note that this must always be in
* the header for the output to function correctly.
// We need to make sure that the content of the oldstyle additional_header array does
// lead to duplicate headers if the same output is also defined in the PageVars.
// This is complicated as the format differs:
// PageVar for javascript: path/to/javascript.js
// additional_header: <script type="text/javascript" src="path/to/javascript"></script> or different
// We go the easy way and check if the value of a pagevar is part of the additional_header value (which
// it is in the example above)
// This will be done for stylesheet and javascript pagevars only right now. We can extend this if necessary.
global $additional_header;
// get any stylesheet page vars
if (is_array($stylesheets) && !empty($stylesheets)) {
foreach ($stylesheets as $stylesheet) {
if (empty($stylesheet)) continue;
// check if the stylesheets is in the additional_header array
if ($themeinfo['xhtml']) {
// get any javascript page vars
if (is_array($javascripts) && !empty($javascripts)) {
// Ugly but necessary inline javascript for now: Some javascripts, eg. the lightbox, need to know the path to the system and
// the entrypoint as well (which can be configured in the settings) otherwise they may fail in case of short urls being
// enabled. We will now add some inline javascript to extend the DOM:
// document.location.entrypoint: will be set to what is configured to be the entrypoint
// document.location.pnbaseURL: will point to the result of pnGetBaseURL();
// todo: make his more unobtrusive, but how? Dynamic javascript creation might be a performance problem. Any idea here
// is highly appreciated! [landseer]
$return .= '<script type="text/javascript">/* <![CDATA[ */ document.location.entrypoint="' . pnConfigGetVar('entrypoint', 'index.php') . '"; document.location.pnbaseURL="' . pnGetBaseURL() . '"; /* ]]> */</script>'. "\n";
foreach ($javascripts as $javascript) {
if (empty($javascript)) continue;
// check if the javascript is in the additional_header array
if (is_array($rawtext) && !empty($rawtext)) {
$return .= implode("\n", $rawtext) . "\n";
// add generic stylesheet
if ($themeinfo['xhtml']) {
$return .= '<link rel="stylesheet" href="javascript/style.css" type="text/css" />'. "\n";
$return .= '<link rel="stylesheet" href="javascript/style.css" type="text/css">'. "\n";
// implode the remaining additional header global to a string
if (isset ($additional_header) && count($additional_header)> 0) {
$return .= @implode("\n", $additional_header) . "\n";
// if we've got some page vars to add the header wrap the output in
// suitable identifiying comments when in development mode
$return = "<!-- pnpagevars -->\n" . $return . "\n<!-- /pnpagevars-->";
// get any body page vars
$bodyattribs = '<body ' . @implode(' ', $bodyvars) . '>';
$source = str_replace('<body>', $bodyattribs, $source);
// get any footer page vars
if (!empty($footervars)) {
$footersource = @implode("\n", $footervars). "\n</body>";
$source = str_replace('</body>', $footersource, $source);
// replace the string in the template source
if (stristr($source, '<!-- pagevars -->')) {
$source = str_replace('<!-- pagevars -->', $return, $source);
$source = str_replace('</head>', $return. "\n</head>", $source);
// return the modified source
$ahcount = count($additional_header);
for($i= 0; $i < $ahcount; $i++ ) {
if (!empty($additional_header[$i])) {
if(stristr($additional_header[$i], $pagevar) <> false) {
// gotcha -found pagevar in additional_header string
// not found, keep the additional_header for later checks or output
$new_header[] = $additional_header[$i];
$additional_header = $new_header;
|