sfCommonFilter.class.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /*
  3. * This file is part of the symfony package.
  4. * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
  5. *
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. /**
  10. * sfCommonFilter automatically adds javascripts and stylesheets information in the sfResponse content.
  11. *
  12. * @package symfony
  13. * @subpackage filter
  14. * @author Fabien Potencier <fabien.potencier@symfony-project.com>
  15. * @version SVN: $Id: sfCommonFilter.class.php 9087 2008-05-20 02:00:40Z Carl.Vondrick $
  16. */
  17. class sfCommonFilter extends sfFilter
  18. {
  19. /**
  20. * Executes this filter.
  21. *
  22. * @param sfFilterChain $filterChain A sfFilterChain instance
  23. */
  24. public function execute($filterChain)
  25. {
  26. // execute next filter
  27. $filterChain->execute();
  28. // execute this filter only once
  29. $response = $this->context->getResponse();
  30. // include javascripts and stylesheets
  31. $content = $response->getContent();
  32. if (false !== ($pos = strpos($content, '</head>')))
  33. {
  34. sfLoader::loadHelpers(array('Tag', 'Asset'));
  35. $html = '';
  36. if (!sfConfig::get('symfony.asset.javascripts_included', false))
  37. {
  38. $html .= get_javascripts($response);
  39. }
  40. if (!sfConfig::get('symfony.asset.stylesheets_included', false))
  41. {
  42. $html .= get_stylesheets($response);
  43. }
  44. if ($html)
  45. {
  46. $response->setContent(substr($content, 0, $pos).$html.substr($content, $pos));
  47. }
  48. }
  49. sfConfig::set('symfony.asset.javascripts_included', false);
  50. sfConfig::set('symfony.asset.stylesheets_included', false);
  51. }
  52. }