-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathextjs.utils.inc
220 lines (203 loc) · 6.87 KB
/
extjs.utils.inc
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
<?php
/**
* @file
*
* A collection of helper/utility functions for this module.
*/
/**
* Returns the path to the ExtJS library.
*
* @return string
* The path to the ExtJS library if found, FALSE otherwise.
*/
function extjs_get_path() {
static $path;
if (isset($path)) {
return $path;
}
$path = FALSE;
if (function_exists('libraries_get_path')) { // Libraries API integration.
$path = libraries_get_path('extjs');
if ($path !== FALSE && !file_exists($path)) { // Libraries API 1.x returns a default path; 2.x returns FALSE.
$path = FALSE;
}
}
else if (file_exists('./sites/all/libraries/extjs')) { // Manually check sites/all/libraries in case Libraries API is not available.
$path = 'sites/all/libraries/extjs';
}
return $path;
}
/**
* Returns the path to the ExtJS library's resource folder where all the css/image/theme data is kept.
*
* @return string
* The path to the ExtJS library's resouce folder if found, FALSE otherwise.
*/
function extjs_get_resources_path() {
return extjs_get_path() . '/resources';
}
/**
* Returns the path to the ExtJS library's core css folder.
*
* @return string
* The path to the ExtJS library's css folder if found, FALSE otherwise.
*/
function extjs_get_css_path() {
return extjs_get_resources_path() . '/css';
}
/**
* Returns the path to the ExtJS library's core js folder.
*
* @return string
* The path to the ExtJS library's js folder if found, FALSE otherwise.
*/
function extjs_get_js_path() {
return extjs_get_path();
}
/**
* Gets the installed version of ExtJS
*
* @return string
* The currently installed version, if found FALSE otherwise.
*/
function extjs_get_version() {
static $version;
if(isset($version)) {
return $version;
}
$version = FALSE;
$filename = extjs_get_path() . '/ext.js';
if(file_exists($filename)) {
$text = file_get_contents($filename);
$matches = array();
preg_match('/setVersion\(\"extjs\",\"([^.]*\.[^.]*\.[^.]*)\"\)/', $text, $matches);
if(isset($matches[1])) { // The first sub expression.
$version = $matches[1];
}
}
return $version;
}
/**
* Generates a version requirement for the extjs library for use in the hook_requirements() function.
* This should be used by modules that require the extjs library to have a specific version higher than 4.0
*
* @param string $module
* The name of the module with the requirement.
* @param string $version
* The version the module requries.
*
* @return array
* A requirement definition for use in the hook_requirements() function. It should be added to the $requirements array with a unique key.
*/
function extjs_get_version_requirement($module_name, $required_version) {
$t = get_t();
$requirement = array('title' => $t('Ext JS Library'));
$requirement['value'] = $version = extjs_get_version();
if (version_compare($version, $required_version) >= 0) {
$requirement['severity'] = REQUIREMENT_OK;
}
else {
$requirement['severity'] = REQUIREMENT_ERROR;
$requirement['description'] = extjs_get_version_requirement_status_message($module_name, $required_version);
}
return $requirement;
}
/**
* Returns the 'de facto' description message that can be used by modules that require
* a specific version of extjs.
*
* @param string $module
* The name of the module with the requirement.
* @param string $version
* The version the module requries.
*
* @return string
* A translated description message that can be used in the status page to describe
* which version of extjs is required and where it can be downloaded.
*/
function extjs_get_version_requirement_status_message($module, $version) {
$t = get_t();
return $t('The module "@module" requires !extjs version @version or higher. !download and extract it into the !directory directory. Rename the extracted folder to !name.',
array(
'@module' => $module,
'@version' => $version,
'!extjs' => '<a href="http://www.sencha.com/">Ext JS</a>',
'!download' => '<a href="http://www.sencha.com/products/extjs/download?page=a">' . t('Download') . '</a>',
'!directory' => '<code>sites/all/libraries</code>',
'!name' => '<code>extjs</code>'
)
);
}
/**
* Gets the suffix for the file depending on the compression settings.
*
* @return string
* The suffix of the file, denoting its compression type.
*/
function extjs_get_js_file_suffix() {
$suffix = array(
EXTJS_MIN_COMPRESSION => '.js',
EXTJS_DEV_COMPRESSION => '-dev.js',
EXTJS_DEBUG_COMPRESSION => '-debug.js',
EXTJS_DEBUG_COMMENTS_COMPRESSION => '-debug-w-comments.js'
);
$compression_type = variable_get('extjs_compression_type', EXTJS_MIN_COMPRESSION);
return $suffix[$compression_type];
}
/**
* Gets the suffix for the file depending on the compression settings.
*
* @return string
* The suffix of the file, denoting its compression type.
*/
function extjs_get_css_file_suffix() {
$suffix = array(
EXTJS_MIN_COMPRESSION => '.css',
EXTJS_DEV_COMPRESSION => '-debug.css',
EXTJS_DEBUG_COMPRESSION => '-debug.css',
EXTJS_DEBUG_COMMENTS_COMPRESSION => '-debug.css'
);
$compression_type = variable_get('extjs_compression_type', EXTJS_MIN_COMPRESSION);
return $suffix[$compression_type];
}
/**
* Includes the given extjs css file.
*/
function extjs_add_css_file($file) {
$path = extjs_get_css_path();
drupal_add_css($path . '/' . $file . extjs_get_css_file_suffix(), 'theme', 'all');
}
/**
* Includes the given extjs js file.
*/
function extjs_add_js_file($file) {
$path = extjs_get_js_path();
drupal_add_js($path . '/' . $file . extjs_get_js_file_suffix(), 'module', 'header', TRUE);
}
/**
* not safe yet, the theme layer must be spec'd out.
*/
function extjs_add_default_settings($settings = NULL) {
drupal_add_js(array(
'extjs' => array(
'buildSettings' => array(
'scopeResetCSS' => TRUE))), 'setting');
}
/**
* not safe yet, the theme layer must be spec'd out.
*/
function extjs_add_settings_js_file() {
drupal_add_js(drupal_get_path('module', 'extjs') . '/js/extjs-settings.js', 'module', 'header', TRUE);
}
/**
* Includes several css files that are used to remove css styles applied to tag without any class qualifiers.
* Currently this only corrects for the Drupal system module and the Garland theme, custom themes are expected to scope their styles.
*/
function extjs_add_drupal_reset_css_files() {
$css_path = drupal_get_path('module', 'extjs') . '/css';
drupal_add_css("$css_path/reset-system.css", 'theme', 'all'); // Fix the Drupal system.css problems. @TODO build theme system for extjs.
drupal_add_css("$css_path/reset-defaults.css", 'theme', 'all'); // Fix the Drupal system.css problems. @TODO build theme system for extjs.
if(variable_get('theme_default', NULL) == 'garland') {
drupal_add_css("$css_path/reset-garland-style.css", 'theme', 'all'); // Fix the Garland theme style.css problems. @TODO build theme system for extjs.
}
}