function advagg_mod_js_contains_jquery_drupal in Advanced CSS/JS Aggregation 7.2
See if JavaScript file contains drupal and/or jquery.
Parameters
string $filename: Inline css, full URL, or filename.
string $type: (Optional) inline, external, or file.
Return value
array Returns an array stating if this JS file contains drupal or jquery.
2 calls to advagg_mod_js_contains_jquery_drupal()
- advagg_mod_advagg_get_info_on_files_alter in advagg_mod/
advagg_mod.advagg.inc - Implements hook_advagg_get_info_on_files_alter().
- advagg_mod_remove_js_if_not_used in advagg_mod/
advagg_mod.module - Remove JS if not in use on current page.
File
- advagg_mod/
advagg_mod.module, line 3417 - Advanced aggregation modifier module.
Code
function advagg_mod_js_contains_jquery_drupal($filename, $type = '') {
if (is_string($filename)) {
if ($type === 'inline') {
$contents = $filename;
}
elseif ($type === 'external' || strpos($filename, 'http://') === 0 || strpos($filename, 'https://') === 0 || strpos($filename, '//') === 0) {
$result = drupal_http_request($filename);
if (($result->code == 200 || isset($result->redirect_code) && $result->redirect_code == 200) && !empty($result->data)) {
$contents = $result->data;
}
}
elseif (file_exists($filename)) {
$contents = (string) @advagg_file_get_contents($filename);
}
}
$results = array();
if (!empty($contents) && stripos($contents, 'drupal.') !== FALSE) {
$results['contents']['drupal'] = TRUE;
if (stripos($contents, 'drupal.settings.') !== FALSE) {
$results['contents']['drupal.settings'] = TRUE;
}
else {
$results['contents']['drupal.settings'] = FALSE;
}
if (stripos($contents, 'drupal.behaviors.') !== FALSE) {
$results['contents']['drupal.behaviors'] = TRUE;
}
else {
$results['contents']['drupal.behaviors'] = FALSE;
}
}
else {
$results['contents']['drupal'] = FALSE;
$results['contents']['drupal.settings'] = FALSE;
$results['contents']['drupal.behaviors'] = FALSE;
}
if (!empty($contents) && stripos($contents, 'jquery') !== FALSE) {
$results['contents']['jquery'] = TRUE;
}
else {
$results['contents']['jquery'] = FALSE;
}
return $results;
}