sfCommonFilter.class.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 11783 2008-09-25 16:21:27Z fabien $
  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. $this->context->getConfiguration()->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. }