示例#1
0
/**
 * Returns <link> tags for all stylesheets configured in view.yml or added to the response object.
 *
 * You can use this helper to decide the location of stylesheets in pages.
 * By default, if you don't call this helper, symfony will automatically include stylesheets before </head>.
 * Calling this helper disables this behavior.
 *
 * @return string <link> tags
 */
function get_less_stylesheets()
{
    $response = sfContext::getInstance()->getResponse();
    $dispatcher = sfContext::getInstance()->getEventDispatcher();
    $dispatcher->notify(new sfEvent($response, 'less_js.compile'));
    return get_stylesheets();
}
/**
 * Returns <link> tags with the url toward all stylesheets configured in view.yml or added to the response object.
 *
 * You can use this helper to decide the location of stylesheets in pages.
 * By default, if you don't call this helper, symfony will automatically include stylesheets before </head>.
 * Calling this helper disables this behavior.
 *
 * @return string <link> tags
 */
function get_combined_stylesheets()
{
    if (!sfConfig::get('app_sfCombinePlugin_enabled', false)) {
        return get_stylesheets();
    }
    $response = sfContext::getInstance()->getResponse();
    sfConfig::set('symfony.asset.stylesheets_included', true);
    $configSfCombinePlugin['css'] = sfConfig::get('app_sfCombinePlugin_css', array());
    $html = '';
    $cssFiles = $include_tags = array();
    foreach (array('first', '', 'last') as $position) {
        foreach ($response->getStylesheets($position) as $files => $options) {
            if (!in_array($files, $configSfCombinePlugin['css']['online']) && !in_array($files, $configSfCombinePlugin['css']['offline'])) {
                if (!is_array($files)) {
                    $files = array($files);
                }
                $cssFiles = array_merge($cssFiles, $files);
            } else {
                $include_tags[] = stylesheet_tag(url_for($files));
            }
        }
    }
    $key = _get_key($cssFiles);
    $include_tags[] = str_replace('.css', '', stylesheet_tag(url_for('sfCombine/css?key=' . $key)));
    return implode("", $include_tags);
}
  /**
   * Executes this filter.
   *
   * @param sfFilterChain $filterChain A sfFilterChain instance
   */
  public function execute($filterChain)
  {
    // execute next filter
    $filterChain->execute();

    // execute this filter only once
    $response = $this->context->getResponse();

    // include javascripts and stylesheets
    $content = $response->getContent();
    if (false !== ($pos = strpos($content, '</head>')))
    {
      $this->context->getConfiguration()->loadHelpers(array('Tag', 'Asset'));
      $html = '';
      if (!sfConfig::get('symfony.asset.javascripts_included', false))
      {
        $html .= get_javascripts($response);
      }
      if (!sfConfig::get('symfony.asset.stylesheets_included', false))
      {
        $html .= get_stylesheets($response);
      }

      if ($html)
      {
        $response->setContent(substr($content, 0, $pos).$html.substr($content, $pos));
      }
    }

    sfConfig::set('symfony.asset.javascripts_included', false);
    sfConfig::set('symfony.asset.stylesheets_included', false);
  }
/**
 * Retrieves the stylesheets tags from the response or the tmp css tag 
 * @return string
 */
function stylesheet_assets()
{
    sfContext::getInstance()->getConfiguration()->loadHelpers('Asset');
    // Update response after it gets totally loaded
    if (sfConfig::get('app_sf_assets_manager_plugin_alter_response', false)) {
        return sfConfig::get('app_sf_assets_manager_plugin_alter_response_tempcsstag');
    } else {
        return get_stylesheets();
    }
}
/**
 * Returns <link> tags with the url toward all stylesheets configured in view.yml or added to the response object.
 *
 * You can use this helper to decide the location of stylesheets in pages.
 * By default, if you don't call this helper, symfony will automatically include stylesheets before </head>.
 * Calling this helper disables this behavior.
 *
 * @return string <link> tags
 */
function get_combined_stylesheets()
{
    if (!sfConfig::get('app_sfCombinePlugin_enabled', false)) {
        return get_stylesheets();
    }
    sfConfig::set('symfony.asset.stylesheets_included', true);
    $html = '';
    $cssFiles = array();
    $response = sfContext::getInstance()->getResponse();
    foreach ($response->getStylesheets() as $files => $options) {
        if (!is_array($files)) {
            $files = array($files);
        }
        $cssFiles = array_merge($cssFiles, $files);
    }
    if (!empty($cssFiles)) {
        $html .= str_replace(array('.css', '.pcss'), '', stylesheet_tag(url_for('sfCombine/css?key=' . _get_key($cssFiles))));
    }
    return $html;
}
 /**
  * Executes this filter.
  *
  * @param sfFilterChain A sfFilterChain instance
  */
 public function execute($filterChain)
 {
     // execute next filter
     $filterChain->execute();
     // execute this filter only once
     $response = $this->getContext()->getResponse();
     // include javascripts and stylesheets
     $content = $response->getContent();
     if (false !== ($pos = strpos($content, '</head>'))) {
         sfLoader::loadHelpers(array('Tag', 'Asset'));
         $html = '';
         if (!$response->getParameter('javascripts_included', false, 'symfony/view/asset')) {
             $html .= get_javascripts($response);
         }
         if (!$response->getParameter('stylesheets_included', false, 'symfony/view/asset')) {
             $html .= get_stylesheets($response);
         }
         if ($html) {
             $response->setContent(substr($content, 0, $pos) . $html . substr($content, $pos));
         }
     }
     $response->setParameter('javascripts_included', false, 'symfony/view/asset');
     $response->setParameter('stylesheets_included', false, 'symfony/view/asset');
 }
示例#7
0
/**
 * Prints <link> tags for all stylesheets configured in view.yml or added to the response object.
 *
 * @see get_stylesheets()
 */
function include_stylesheets()
{
    echo get_stylesheets();
}
示例#8
0
$t->is(dynamic_javascript_include_tag('module/action', true, array('class' => 'foo')), '<script type="text/javascript" src="/module/action?sf_format=js" class="foo"></script>'."\n", 'dynamic_javascript_include_tag() takes an array of HTML attributes as its third argument');

$context->response = new myResponse($context->getEventDispatcher());

// use_dynamic_javascript()
$t->diag('use_dynamic_javascript()');
use_dynamic_javascript('module/action');
$t->is(get_javascripts(),
  '<script type="text/javascript" src="module/action?sf_format=js"></script>'."\n",
  'use_dynamic_javascript() register a dynamic javascript in the response'
);

// use_dynamic_stylesheet()
$t->diag('use_dynamic_stylesheet()');
use_dynamic_stylesheet('module/action');
$t->is(get_stylesheets(),
  '<link rel="stylesheet" type="text/css" media="screen" href="module/action?sf_format=css" />'."\n",
  'use_dynamic_stylesheet() register a dynamic stylesheet in the response'
);

class MyForm extends sfForm
{
  public function getStylesheets()
  {
    return array('/path/to/a/foo.css' => 'all', '/path/to/a/bar.css' => 'print');
  }

  public function getJavaScripts()
  {
    return array('/path/to/a/foo.js', '/path/to/a/bar.js');
  }
示例#9
0
$t->is(_dynamic_path('module/action?key=value', 'js'), 'module/action?key=value&sf_format=js', '_dynamic_path() converts an internal URI to a URL');
$t->is(_dynamic_path('module/action', 'js', true), '/module/action?sf_format=js', '_dynamic_path() converts an internal URI to a URL');
// dynamic_javascript_include_tag()
$t->diag('dynamic_javascript_include_tag()');
$t->is(dynamic_javascript_include_tag('module/action'), '<script type="text/javascript" src="module/action?sf_format=js"></script>' . "\n", 'dynamic_javascript_include_tag() returns a tag relative to the given action');
$t->is(dynamic_javascript_include_tag('module/action', true), '<script type="text/javascript" src="/module/action?sf_format=js"></script>' . "\n", 'dynamic_javascript_include_tag() takes an absolute boolean as its second argument');
$t->is(dynamic_javascript_include_tag('module/action', true, array('class' => 'foo')), '<script type="text/javascript" src="/module/action?sf_format=js" class="foo"></script>' . "\n", 'dynamic_javascript_include_tag() takes an array of HTML attributes as its third argument');
$context->response = new myResponse($context->getEventDispatcher());
// use_dynamic_javascript()
$t->diag('use_dynamic_javascript()');
use_dynamic_javascript('module/action');
$t->is(get_javascripts(), '<script type="text/javascript" src="module/action?sf_format=js"></script>' . "\n", 'use_dynamic_javascript() register a dynamic javascript in the response');
// use_dynamic_stylesheet()
$t->diag('use_dynamic_stylesheet()');
use_dynamic_stylesheet('module/action');
$t->is(get_stylesheets(), '<link rel="stylesheet" type="text/css" media="screen" href="module/action?sf_format=css" />' . "\n", 'use_dynamic_stylesheet() register a dynamic stylesheet in the response');
class MyForm extends sfForm
{
    public function getStylesheets()
    {
        return array('/path/to/a/foo.css' => 'all', '/path/to/a/bar.css' => 'print');
    }
    public function getJavaScripts()
    {
        return array('/path/to/a/foo.js', '/path/to/a/bar.js');
    }
}
// get_javascripts_for_form() get_stylesheets_for_form()
$t->diag('get_javascripts_for_form() get_stylesheets_for_form()');
$form = new MyForm();
$output = <<<EOF
示例#10
0
文件: layout.php 项目: EQ4/smint
    <?php 
use_stylesheet('../smintplayer/css/custom.css');
?>
	<?php 
use_javascript('../smintplayer/js/smintplayer.js');
?>
	<?php 
use_javascript('../smintplayer/js/slider.js');
?>
	<?php 
use_javascript('../smintplayer/js/jquery.ui.touch-punch.min.js');
?>

<!-- css should be before js for performance reasons -->
    <?php 
echo get_stylesheets();
?>

<!-- other js : should be at the end of all use_javascript calls -->
    <?php 
echo get_javascripts();
?>
    
    
   
    <link rel="icon" type="image/png" href="<?php 
echo image_path("favicon.png");
?>
" />

/**
 * @see get_combined_javascripts
 */
function get_combined_stylesheets($groups = null, $groupType = sfCombinePlusManager::GROUP_INCLUDE, $onlyUnusedGroups = true, $markGroupsUsed = true)
{
    if (!sfConfig::get('app_sfCombinePlusPlugin_enabled', false)) {
        return get_stylesheets();
    }
    $manager = sfCombinePlusManager::getCssManager();
    sfConfig::set('symfony.asset.stylesheets_included', true);
    $response = sfContext::getInstance()->getResponse();
    $config = sfConfig::get('app_sfCombinePlusPlugin_css', array());
    $doNotCombine = isset($config['combine_skip']) ? $config['combine_skip'] : array();
    $manager->setSkips(array_merge($manager->getSkips(), $doNotCombine));
    $groupedFiles = $manager->getAssetsByGroup($response->getStylesheets(), $config['combine'], $groups, $groupType, $onlyUnusedGroups, $markGroupsUsed);
    $html = '';
    foreach ($groupedFiles as $fileDetails) {
        if (!$fileDetails['combinable']) {
            $html .= stylesheet_tag(stylesheet_path($fileDetails['files']), $fileDetails['options']);
        } else {
            $route = isset($config['route']) ? $config['route'] : 'sfCombinePlus';
            $html .= stylesheet_tag(url_for('@' . $route . '?module=sfCombinePlus&action=js&' . sfCombinePlusUrl::getUrlString($fileDetails['files'])), $fileDetails['options']);
        }
    }
    return $html;
}