Newer
Older
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
<?php
// $Id$
/**
* @file
* GMap marker information routines.
*
* This file is pulled in whenever we need to refresh the marker information
* and marker name caches.
*/
/**
* Get marker icon data for constructing json object.
*/
function _gmap_get_icondata() {
$icons = array();
$imagetypes = array(
'shadow',
'printImage',
'mozPrintImage',
'printShadow',
'transparent',
);
$markerdir = variable_get('gmap_markerfiles', drupal_get_path('module', 'gmap') .'/markers');
// The following routines are designed to be easy to comprehend, not fast.
// This whole process gets cached.
// Get the ini files.
$inifiles = file_scan_directory($markerdir, '.*\.ini$');
// Parse the ini files and store by path
$inis = array();
foreach ($inifiles as $file) {
$path = substr($file->filename, strlen($markerdir), -strlen($file->basename));
if (!isset($inis[$path])) {
$inis[$path] = array();
}
$inis[$path][] = parse_ini_file($file->filename, TRUE);
}
unset($inifiles);
// Per directory..
foreach ($inis as $path => $path_inis) {
$icons[$path] = array(
'tempf' => array(),
'f' => array(),
'w' => array(),
'h' => array(),
'i' => array(), // Sets of sets
);
// Part 1: Collect image names
$filenames = array();
foreach ($path_inis as $ini) {
foreach ($ini as $k => $v) {
// Is this definition for an icon? (anything with a dot is a file)
if (strpos($k, '.') !== FALSE) {
// Add the icon name.
$filenames[$k] = TRUE;
}
else {
// Shadow / alternate search
foreach ($imagetypes as $check) {
if (isset($v[$check])) {
$filenames[$v[$check]] = TRUE;
}
}
// A sequence is a list of image names.
if (isset($v['sequence'])) {
foreach (explode(',', $v['sequence']) as $f) {
$filenames[trim($f)] = TRUE;
}
}
}
}
}
$icons[$path]['tempf'] = $filenames;
}
unset($filenames);
// Part 2: Assign ids, get width and height
foreach ($icons as $path => $v) {
$counter = 0;
foreach ($icons[$path]['tempf'] as $filename => $fv) {
// Skip empty filenames to avoid warnings.
if (empty($filename)) {
continue;
}
$size = getimagesize($markerdir . $path . $filename);
$icons[$path]['f'][$counter] = $filename;
$icons[$path]['w'][$counter] = $size[0];
$icons[$path]['h'][$counter] = $size[1];
// Store an index under tempf for the next part...
$icons[$path]['tempf'][$filename] = $counter;
$counter++;
}
_gmap_compress_array($icons[$path]['w']);
_gmap_compress_array($icons[$path]['h']);
}
// Part 3: Main ini parsing
// Per directory...
foreach ($inis as $path => $path_inis) {
// Per file...
foreach ($path_inis as $ini) {
// Compression.
foreach ($ini as $k => $v) {
// Compress sequence filenames.
if (isset($ini[$k]['sequence'])) {
$temp = array();
foreach (explode(',', $ini[$k]['sequence']) as $file) {
$temp[] = $icons[$path]['tempf'][$file];
}
$ini[$k]['sequence'] = $temp;
}
// Compress other image field filenames.
foreach ($imagetypes as $t) {
if (isset($ini[$k][$t])) {
$ini[$k][$t] = $icons[$path]['tempf'][$ini[$k][$t]];
}
}
// Setup key for compression
$ini[$k]['key'] = $k;
}
$mv = array();
$iv = array();
if (isset($ini['defaults'])) {
$mv[0] = $ini['defaults'];
unset($ini['defaults']);
}
else {
$mv[0] = array();
}
foreach ($ini as $k => $v) {
if (strpos($k, '.') === FALSE) {
$mv[] = $ini[$k];
}
else {
$iv[] = $ini[$k];
}
}
$icons[$path]['i'][] = array(
_gmap_compress_icon_def($mv),
_gmap_compress_icon_def($iv),
);
}
}
foreach ($icons as $path => $v) {
unset($icons[$path]['tempf']);
}
return $icons;
}
/**
* Make a compressed definition.
* A series of arrays with trailing holes allowed.
* Any missing values at the end of subarrays
* are equal to the last defined value.
*/
function _gmap_compress_icon_def($iconset) {
$order = array(
'key', 'name', 'sequence', 'anchorX', 'anchorY',
'infoX', 'infoY', 'shadow', 'printImage', 'mozPrintImage',
'printShadow', 'transparent',
);
$ints = array(3 => TRUE, 4 => TRUE, 5 => TRUE, 6 => TRUE);
$nulls = array('', '', array(), 0, 0, 0, 0, '', '', '', '', '', );
$a = array();
for ($c0 = 0; $c0<count($order); $c0++) {
$a[$c0] = array();
for ($c1=0; $c1<count($iconset); $c1++) {
$temp = isset($iconset[$c1][$order[$c0]]) ? $iconset[$c1][$order[$c0]] : $nulls[$c0];
// Ensure that numeric quantities are encoded as ints, not strings.
if ($ints[$c0]) {
$temp = (int)$temp;
}
$a[$c0][$c1] = $temp;
}
_gmap_compress_array($a[$c0]);
}
for ($c0--;$c0>=0;$c0--) {
if ($a[$c0] === array($nulls[$c0])) {
unset($a[$c0]);
}
else {
break;
}
}
return $a;
}
/**
* Remove trailing duplicates from an array.
*/
function _gmap_compress_array(&$arr) {
$c = count($arr) - 1;
// Walk backwards and unset duplicates...
for ($cval = $arr[$c]; $c>0; $c--) {
if ($arr[$c-1]==$cval) {
unset($arr[$c]);
}
else {
// .. until we hit a different number.
break;
}
}
}
function _gmap_get_marker_titles() {
$markerdir = variable_get('gmap_markerfiles', drupal_get_path('module', 'gmap') .'/markers');
// The following routines are designed to be easy to comprehend, not fast.
// This whole process gets cached.
// Get the ini files.
$inifiles = file_scan_directory($markerdir, '.*\.ini$');
// Parse the ini files and store by path
$inis = array();
foreach ($inifiles as $file) {
$data = parse_ini_file($file->filename, TRUE);
if (isset($data['defaults'])) {
// Ignore defaults
unset($data['defaults']);
}
foreach ($data as $k => $v) {
if (strpos($k, '.') !== FALSE) {
// Ignore files
unset($data[$k]);
}
}
$inis[] = $data;
}
unset($inifiles);
$titles = array();
foreach ($inis as $ini => $inidata) {
foreach ($inidata as $k => $v) {
$titles[$k] = $inis[$ini][$k]['name'];
}
}
return $titles;
}