-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwireframe_me.inc
82 lines (74 loc) · 2.67 KB
/
wireframe_me.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
<?php
// Wireframe_me.inc Parser - based upon Profiler2 module.
/**
* Load the Wireframe Me "./wireframes/wireframes.inc" file.
* Returns an array ($config) if True, otherwise returns False.
*/
function wireframe_me_load_wireframes() {
// Grab wireframe config file. @TODO - support multiple files for mixing and matching.
$file = drupal_get_path('module', 'wireframe_me') . '/wireframes/wireframe_me.wireframes.inc';
$data = is_file($file) ? file_get_contents($file) : '';
if ($config = wireframe_me_parse_wireframes($data)) {
return $config;
} else {
return FALSE;
}
}
/**
* Copy of drupal_parse_info_file() but must be passed a string rather than a
* file path to read from.
*/
function wireframe_me_parse_wireframes($data) {
if (!$data) {
return FALSE;
}
$constants = get_defined_constants();
if (preg_match_all('
@^\s* # Start at the beginning of a line, ignoring leading whitespace
((?:
[^=;\[\]]| # Key names cannot contain equal signs, semi-colons or square brackets,
\[[^\[\]]*\] # unless they are balanced and not nested
)+?)
\s*=\s* # Key/value pairs are separated by equal signs (ignoring white-space)
(?:
("(?:[^"]|(?<=\\\\)")*")| # Double-quoted string, which may contain slash-escaped quotes/slashes
(\'(?:[^\']|(?<=\\\\)\')*\')| # Single-quoted string, which may contain slash-escaped quotes/slashes
([^\r\n]*?) # Non-quoted string
)\s*$ # Stop at the next end of a line, ignoring trailing whitespace
@msx', $data, $matches, PREG_SET_ORDER)) {
$info = array();
foreach ($matches as $match) {
// Fetch the key and value string
$i = 0;
foreach (array('key', 'value1', 'value2', 'value3') as $var) {
$$var = isset($match[++$i]) ? $match[$i] : '';
}
$value = stripslashes(substr($value1, 1, -1)) . stripslashes(substr($value2, 1, -1)) . $value3;
// Parse array syntax
$keys = preg_split('/\]?\[/', rtrim($key, ']'));
$last = array_pop($keys);
$parent = &$info;
// Create nested arrays
foreach ($keys as $key) {
if ($key == '') {
$key = count($parent);
}
if (!isset($parent[$key]) || !is_array($parent[$key])) {
$parent[$key] = array();
}
$parent = &$parent[$key];
}
// Handle PHP constants
if (defined($value)) {
$value = constant($value);
}
// Insert actual value
if ($last == '') {
$last = count($parent);
}
$parent[$last] = $value;
}
return $info;
}
return FALSE;
}