Zikula_Template_Plugins
[ class tree: Zikula_Template_Plugins ] [ index: Zikula_Template_Plugins ] [ all elements ]

Source for file outputfilter.pagevars.php

Documentation is available at outputfilter.pagevars.php

  1. <?php
  2. /**
  3.  * Zikula Application Framework
  4.  *
  5.  * @copyright (c) 2004, Zikula Development Team
  6.  * @link http://www.zikula.org
  7.  * @version $Id: outputfilter.pagevars.php 24342 2008-06-06 12:03:14Z markwest $
  8.  * @license GNU/GPL - http://www.gnu.org/copyleft/gpl.html
  9.  * @package Zikula_Template_Plugins
  10.  * @subpackage Filters
  11.  */
  12.  
  13. /**
  14.  * Smarty outputfilter to add page variables and additional header global into page header
  15.  *
  16.  * By default this output filter places page variable output immediately prior to the closing
  17.  * head tag (</head>). The output can, optionally, be placed anywhere in the template by adding
  18.  * the HTML comment <!-- pagevars --> to the page template. Note that this must always be in
  19.  * the header for the output to function correctly.
  20.  *
  21.  * @author    Mark West
  22.  * @param     string 
  23.  * @param     Smarty 
  24.  */
  25. function smarty_outputfilter_pagevars($source&$smarty)
  26. {
  27.     $return '';
  28.     
  29.     // We need to make sure that the content of the oldstyle additional_header array does
  30.     // lead to duplicate headers if the same output is also defined in the PageVars. 
  31.     // This is complicated as the format differs:
  32.     // PageVar for javascript: path/to/javascript.js
  33.     // additional_header: <script type="text/javascript" src="path/to/javascript"></script> or different
  34.     // We go the easy way and check if the value of a pagevar is part of the additional_header value (which
  35.     // it is in the example above)
  36.     // This will be done for stylesheet and javascript pagevars only right now. We can extend this if necessary. 
  37.     global $additional_header;
  38.  
  39.  
  40.     // get any stylesheet page vars
  41.     $stylesheets PageUtil::getVar('stylesheet');
  42.     if (is_array($stylesheets&& !empty($stylesheets)) {
  43.         foreach ($stylesheets as $stylesheet{
  44.             if (empty($stylesheet)) continue;
  45.             // check if the stylesheets is in the additional_header array
  46.             _clean_additional_header($additional_header$stylesheet);
  47.             if ($themeinfo['xhtml']{
  48.                 $return .= '<link rel="stylesheet" href="'.DataUtil::formatForDisplay($stylesheet).'" type="text/css" />'."\n";
  49.             else {
  50.                 $return .= '<link rel="stylesheet" href="'.DataUtil::formatForDisplay($stylesheet).'" type="text/css">'."\n";
  51.             }
  52.         }
  53.     }
  54.  
  55.     // get any javascript page vars
  56.     $javascripts PageUtil::getVar('javascript');
  57.     if (is_array($javascripts&& !empty($javascripts)) {
  58.         // Ugly but necessary inline javascript for now: Some javascripts, eg. the lightbox, need to know the path to the system and
  59.         // the entrypoint as well (which can be configured in the settings) otherwise they may fail in case of short urls being
  60.         // enabled. We will now add some inline javascript to extend the DOM:
  61.         //
  62.         // document.location.entrypoint: will be set to what is configured to be the entrypoint
  63.         // document.location.pnbaseURL: will point to the result of pnGetBaseURL();
  64.         //
  65.         // todo: make his more unobtrusive, but how? Dynamic javascript creation might be a performance problem. Any idea here 
  66.         // is highly appreciated! [landseer]
  67.         //
  68.         $return .= '<script type="text/javascript">/* <![CDATA[ */ document.location.entrypoint="' pnConfigGetVar('entrypoint''index.php''"; document.location.pnbaseURL="' pnGetBaseURL('"; /* ]]> */</script>'."\n";
  69.         foreach ($javascripts as $javascript{
  70.             if (empty($javascript)) continue;
  71.             // check if the javascript is in the additional_header array
  72.             _clean_additional_header($additional_header$javascript);
  73.             $return .= '<script type="text/javascript" src="'.DataUtil::formatForDisplay($javascript).'"></script>'."\n";
  74.         }
  75.     }
  76.  
  77.     $rawtext PageUtil::getVar('rawtext');
  78.     if (is_array($rawtext&& !empty($rawtext)) {
  79.         $return .= implode("\n"$rawtext"\n";
  80.     }
  81.  
  82.     // add generic stylesheet
  83.     if ($themeinfo['xhtml']{
  84.         $return .= '<link rel="stylesheet" href="javascript/style.css" type="text/css" />'."\n";
  85.     else {
  86.         $return .= '<link rel="stylesheet" href="javascript/style.css" type="text/css">'."\n";
  87.     }
  88.  
  89.     // implode the remaining additional header global to a string
  90.     if (isset($additional_header&& count($additional_header)>0{
  91.         $return .= @implode("\n"$additional_header"\n";
  92.     }
  93.  
  94.     // if we've got some page vars to add the header wrap the output in
  95.     // suitable identifiying comments when in development mode
  96.     $return trim($return);
  97.     if (!empty($return&& pnConfigGetVar('development'!= 0{
  98.         $return "<!-- pnpagevars -->\n" $return "\n<!-- /pnpagevars-->";
  99.     }
  100.  
  101.     // get any body page vars
  102.     $bodyvars PageUtil::getVar('body');
  103.     if (!empty($bodyvars)) {
  104.         $bodyattribs '<body ' @implode(' '$bodyvars'>';
  105.         $source str_replace('<body>'$bodyattribs$source);
  106.     }
  107.  
  108.     // get any footer page vars
  109.     $footervars PageUtil::getVar('footer');
  110.     if (!empty($footervars)) {
  111.         $footersource @implode("\n"$footervars)."\n</body>";
  112.         $source str_replace('</body>'$footersource$source);
  113.     }
  114.  
  115.     // replace the string in the template source
  116.     if (stristr($source'<!-- pagevars -->')) {
  117.         $source str_replace('<!-- pagevars -->'$return$source);
  118.     else {
  119.         $source str_replace('</head>'$return."\n</head>"$source);
  120.     }
  121.     // return the modified source
  122.     return $source;
  123. }
  124.  
  125.  
  126. function _clean_additional_header(&$additional_header$pagevar)
  127. {
  128.     $ahcount count($additional_header);
  129.     if($ahcount==0{
  130.         return;
  131.     }
  132.     
  133.     $new_header array();
  134.     for($i=0$i $ahcount$i++{
  135.         if (!empty($additional_header[$i])) {
  136.             if(stristr($additional_header[$i]$pagevar<> false{
  137.                 // gotcha -found pagevar in additional_header string
  138.                 // skip this
  139.             else {
  140.                 // not found, keep the additional_header for later checks or output
  141.                 $new_header[$additional_header[$i];
  142.             }
  143.         }
  144.     }
  145.     $additional_header $new_header;
  146.     return;
  147. }

Documentation generated on Fri, 18 Jul 2008 21:48:03 +0200 by phpDocumentor 1.4.1