function advagg_get_css_aggregate_contents

cis7 advagg.missing.inc advagg_get_css_aggregate_contents($files, $aggregate_settings)
cle7 advagg.missing.inc advagg_get_css_aggregate_contents($files, $aggregate_settings)
elmsmedia7 advagg.missing.inc advagg_get_css_aggregate_contents($files, $aggregate_settings)
icor7 advagg.missing.inc advagg_get_css_aggregate_contents($files, $aggregate_settings)
meedjum_blog7 advagg.missing.inc advagg_get_css_aggregate_contents($files, $aggregate_settings)
mooc7 advagg.missing.inc advagg_get_css_aggregate_contents($files, $aggregate_settings)

Given a list of files, grab their contents and glue it into one big string.

Parameters

array $files: array of filenames.

array $aggregate_settings: array of settings.

Return value

string string containing all the files.

1 call to advagg_get_css_aggregate_contents()
advagg_save_aggregate in sites/all/modules/ulmus/advagg/advagg.missing.inc
Save an aggregate given a filename, the files included in it, and the type.

File

sites/all/modules/ulmus/advagg/advagg.missing.inc, line 459
Advanced CSS/JS aggregation module.

Code

function advagg_get_css_aggregate_contents($files, $aggregate_settings) {
  // Check if CSS compression is enabled.
  $optimize = TRUE;
  if (!empty($aggregate_settings['settings']['no_alters'])) {
    $optimize = FALSE;
  }

  $data = '';
  if (!empty($files)) {
    $media_changes = FALSE;
    $last_media = NULL;
    foreach ($files as $file => $settings) {
      if (!isset($settings['media'])) {
        continue;
      }
      if (is_null($last_media)) {
        $last_media = $settings['media'];
        continue;
      }
      if ($settings['media'] != $last_media) {
        $media_changes = TRUE;
        break;
      }
    }
    $last_media = NULL;
    $import_statements = array();
    module_load_include('inc', 'advagg', 'advagg');
    foreach ($files as $file => $settings) {
      $contents = advagg_load_css_stylesheet($file, $optimize, $aggregate_settings);

      // Allow other modules to modify this files contents.
      // Call hook_advagg_get_css_file_contents_alter().
      if (empty($aggregate_settings['settings']['no_alters'])) {
        drupal_alter('advagg_get_css_file_contents', $contents, $file, $aggregate_settings);
      }

      if ($media_changes) {
        $media_blocks = advagg_parse_media_blocks($contents);
        $contents = '';

        foreach ($media_blocks as $css_rules) {
          if (strpos($css_rules, '@media') !== FALSE) {
            // Get start and end of the rules for this media query block.
            $start = strpos($css_rules, '{');
            if ($start === FALSE) {
              continue;
            }
            $end = strrpos($css_rules, '}');
            if ($end === FALSE) {
              continue;
            }

            // Get current media queries for this media block.
            $media_rules = substr($css_rules, 6, $start - 6);
            // Get everything else besides top level media query.
            $css_selectors_rules = substr($css_rules, $start + 1, $end - ($start + 1));

            // Add in main media rule if needed.
            if (strpos($media_rules, $settings['media']) === FALSE) {
              $media_rules = $settings['media'] . ' ' . $media_rules;
            }
          }
          else {
            $media_rules = $settings['media'];
            $css_selectors_rules = $css_rules;
          }
          // Remove the all rule.
          $media_rules = str_replace('all', '', $media_rules);
          $media_rules = trim($media_rules);
          $css_selectors_rules = trim($css_selectors_rules);

          // Start of stylesheet.
          if (is_null($last_media)) {
            if (!empty($media_rules)) {
              $output = '@media ' . $media_rules . ' {' . $css_selectors_rules;
            }
            else {
              $output = $css_selectors_rules;
            }
          }
          elseif ($media_rules != $last_media) {
            if (!empty($media_rules)) {
              if (!empty($last_media)) {
                $output = "} \n@media " . $media_rules . ' {' . $css_selectors_rules;
              }
              else {
                $output = "\n@media " . $media_rules . ' {' . $css_selectors_rules;
              }
            }
            else {
              $output = "} \n " . $css_selectors_rules;
            }
          }
          else {
            $output = ' ' . $css_selectors_rules;
          }

          $last_media = $media_rules;
          $contents .= $output;
        }

      }
      // Per the W3C specification at
      // http://www.w3.org/TR/REC-CSS2/cascade.html#at-import, @import rules
      // must proceed any other style, so we move those to the top.
      $regexp = '/@import[^;]+;/i';
      preg_match_all($regexp, $contents, $matches);
      $contents = preg_replace($regexp, '', $contents);
      $import_statements[] = array($last_media, $matches[0]);

      // Close any open comment blocks.
      $contents .= '/**/';

      $data .= $contents;
    }

    // Close the final media bracket.
    if ($media_changes && !empty($last_media)) {
      $data .= '}';
    }

    // Add import statements to the top of the stylesheet.
    $import_string = '';
    foreach ($import_statements as $values) {
      if ($media_changes) {
        foreach ($values[1] as $statement) {
          $import_string .= str_replace(';', $values[0] . ';', $statement);
        }
      }
      else {
        $import_string .= implode('', $values[1]);
      }
    }
    $data = $import_string . $data;
  }

  // Allow other modules to modify this aggregates contents.
  // Call hook_advagg_get_css_aggregate_contents_alter().
  if (empty($aggregate_settings['settings']['no_alters'])) {
    drupal_alter('advagg_get_css_aggregate_contents', $data, $files, $aggregate_settings);
  }
  return $data;
}
Error | ELMSLN API

Error

×

Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/elmsln_community/api.elmsln.org/includes/common.inc:2791) in drupal_send_headers() (line 1499 of /var/www/html/elmsln_community/api.elmsln.org/includes/bootstrap.inc).
  • Error: Call to undefined function apc_delete() in DrupalAPCCache->clear() (line 289 of /var/www/html/elmsln_community/api.elmsln.org/sites/all/modules/apc/drupal_apc_cache.inc).
The website encountered an unexpected error. Please try again later.