-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmscdn.module
124 lines (108 loc) · 3.65 KB
/
cmscdn.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
/**
* @file
* Finds a predetermined set of JavaScript references and points them to a shared CDN domain
* When JavaScript Aggregation is enabled this module will still function by not allowing
* those files to be aggregated, and listing them out separately.
*/
// Disables the modules functionality temporarily if not active
define('CMSCDN_STATUS', variable_get('cmscdn_status', 'active'));
// CMS CDN Domain
define('CMSCDN_DEFAULT_DOMAIN', 'http://static.cmscdn.net/drupal/');
define('CMSCDN_DOMAIN', variable_get('cmscdn_domain', CMSCDN_DEFAULT_DOMAIN));
// If aggregation is turned on files need to be flagged to not aggregate
define('CMSCDN_JS_AGGREGATION', variable_get('cmscdn_aggregate_js', FALSE));
define('CMSCDN_CSS_AGGREGATION', variable_get('cmscdn_aggregate_css', FALSE));
/**
* Implements hook_menu().
*/
function cmscdn_menu() {
$items = array();
$path = drupal_get_path('module', 'cmscdn');
$items['admin/config/system/cmscdn'] = array(
'title' => 'CMS CDN Settings',
'description' => 'Configure settings for CMS CDN module.',
'page callback' => 'drupal_get_form',
'page arguments' => array('cmscdn_settings'),
'type' => MENU_NORMAL_ITEM,
'file' => 'cmscdn.admin.inc',
'access arguments' => array('administer site configuration'),
'file path' => $path,
);
return $items;
}
/**
* Implements hook_js_alter().
*/
function cmscdn_js_alter(&$js) {
if (CMSCDN_STATUS !== 'active') {
return;
}
if (CMSCDN_JS_AGGREGATION) {
// Adds external aggregated JavaScript file
$js = drupal_add_js(CMSCDN_DOMAIN . VERSION . '/core.min.js', 'external');
}
else {
// Adds external JavaScript files
$js = drupal_add_js(CMSCDN_DOMAIN . VERSION . '/misc/drupal.js', array('type' => 'external', 'weight' => -19));
$js = drupal_add_js(CMSCDN_DOMAIN . VERSION . '/misc/jquery.once.js', array('type' => 'external', 'weight' => -20));
}
unset($js['misc/drupal.js']);
unset($js['misc/jquery.once.js']);
}
/**
* Implements hook_css_alter().
*/
function cmscdn_css_alter(&$css) {
if (CMSCDN_STATUS !== 'active') {
return;
}
global $language;
$core_css = array();
if ($language->dir == 'rtl') {
// All known Right to Left core CSS files
$core_css = array(
'modules/system/system.base-rtl.css',
'modules/system/system.menus-rtl.css',
'modules/system/system.admin-rtl.css',
'modules/system/system.messages-rtl.css',
'modules/system/system.theme-rtl.css',
'modules/field/theme/field-rtl.css',
'modules/node/node.css',
'modules/user/user-rtl.css',
);
}
else {
// All known core CSS files
$core_css = array(
'modules/system/system.base.css',
'modules/system/system.menus.css',
'modules/system/system.admin.css',
'modules/system/system.messages.css',
'modules/system/system.theme.css',
'modules/field/theme/field.css',
'modules/node/node.css',
'modules/user/user.css',
);
}
if (CMSCDN_CSS_AGGREGATION) {
// Adds external aggregated CSS file
// Use rtl files for any right to left language sites
if ($language->dir == 'rtl') {
$css = drupal_add_css(CMSCDN_DOMAIN . VERSION . '/core-rtl.min.css', array('type' => 'external', 'weight' => -1));
}
else {
$css = drupal_add_css(CMSCDN_DOMAIN . VERSION . '/core.min.css', array('type' => 'external', 'weight' => -1));
}
}
else {
// Adds external CSS files
foreach ($core_css as $file) {
$css = drupal_add_css(CMSCDN_DOMAIN . VERSION . '/' . $file, array('type' => 'external', 'weight' => 0));
}
}
// Removes all known core CSS files
foreach ($core_css as $key) {
unset($css[$key]);
}
}