1 | package Greenstone::Site;
|
---|
2 |
|
---|
3 | use strict;
|
---|
4 | use warnings;
|
---|
5 | use utf8;
|
---|
6 | use base 'Exporter';
|
---|
7 |
|
---|
8 | use Greenstone::Config;
|
---|
9 | use XML::Tidy;
|
---|
10 |
|
---|
11 | our $VERSION = 1.00;
|
---|
12 | our @EXPORT = ( );
|
---|
13 | my $configTemplate;
|
---|
14 |
|
---|
15 | sub new {
|
---|
16 | my ($class, $name, %args) = @_;
|
---|
17 | ref $class and die "Constructor used as object method\n";
|
---|
18 | defined $name or die "A site must have a name\n";
|
---|
19 | my $self = bless (
|
---|
20 | {
|
---|
21 | name => $name,
|
---|
22 | },
|
---|
23 | $class
|
---|
24 | );
|
---|
25 | for my $param (keys %args) {
|
---|
26 | $self->{$param} = $args{$param};
|
---|
27 | }
|
---|
28 | return $self;
|
---|
29 | }
|
---|
30 |
|
---|
31 | sub list {
|
---|
32 | ref shift and die "Static method called on object\n";
|
---|
33 | my $sites = {};
|
---|
34 | my $dir = "$Greenstone::Config::GSDL3HOME/sites";
|
---|
35 | opendir DH, $dir or die "Could not open sites directory '$dir'\n";
|
---|
36 | while (my $site = readdir DH) {
|
---|
37 | # skip hidden files and current/parent directory
|
---|
38 | $site =~ /^\./ and next;
|
---|
39 | # skip non-directories
|
---|
40 | -d "$dir/$site" or next;
|
---|
41 | # We don't really need to store anything more than the fact that the site exists
|
---|
42 | # So we just store nothing, which is enough to put the key in the hash
|
---|
43 | # (i.e. it acts as a hashset)
|
---|
44 | $sites->{$site} = ();
|
---|
45 | }
|
---|
46 | closedir DH;
|
---|
47 | return $sites;
|
---|
48 | }
|
---|
49 |
|
---|
50 | sub exists {
|
---|
51 | my $self = shift;
|
---|
52 | my $sites = list;
|
---|
53 | return exists $sites->{$self->{name}};
|
---|
54 | }
|
---|
55 |
|
---|
56 | sub create {
|
---|
57 | my $self = shift;
|
---|
58 | $self->exists and return 0;
|
---|
59 | my $dir = "$Greenstone::Config::GSDL3HOME/sites/$self->{name}";
|
---|
60 | mkdir $dir or die "Failed to create site directory: $!\n";
|
---|
61 | mkdir "$dir/collect" or die "Failed to create collections directory: $!\n";
|
---|
62 | open FH, '>', "$dir/siteConfig.xml" or die "Failed to create site config: $!\n";
|
---|
63 | write_xml $configTemplate, *FH;
|
---|
64 | close FH;
|
---|
65 | return 1;
|
---|
66 | }
|
---|
67 |
|
---|
68 | $configTemplate = {
|
---|
69 | 'siteConfig' => {
|
---|
70 | 'siteList' => {},
|
---|
71 | 'serviceRackList' => {
|
---|
72 | 'serviceRack' => [
|
---|
73 | {
|
---|
74 | '.attr' => {
|
---|
75 | 'name' => 'Authentication'
|
---|
76 | },
|
---|
77 | 'recaptcha' => [
|
---|
78 | {
|
---|
79 | '.attr' => {
|
---|
80 | 'name' => 'public_key',
|
---|
81 | 'value' => '6LckI88SAAAAACUYjj97WMcnz5HPjVp3lI-x-ue8'
|
---|
82 | }
|
---|
83 | },
|
---|
84 | {
|
---|
85 | '.attr' => {
|
---|
86 | 'value' => '6LckI88SAAAAAGnGy1PwuXYZzIMXZYoPxN51bWWG',
|
---|
87 | 'name' => 'private_key'
|
---|
88 | }
|
---|
89 | }
|
---|
90 | ]
|
---|
91 | },
|
---|
92 | {
|
---|
93 | '.attr' => {
|
---|
94 | 'name' => 'ArchiveIO'
|
---|
95 | }
|
---|
96 | },
|
---|
97 | {
|
---|
98 | '.attr' => {
|
---|
99 | 'name' => 'DocumentMaker'
|
---|
100 | }
|
---|
101 | },
|
---|
102 | {
|
---|
103 | '.attr' => {
|
---|
104 | 'name' => 'DocXMLUtil'
|
---|
105 | }
|
---|
106 | },
|
---|
107 | {
|
---|
108 | '.attr' => {
|
---|
109 | 'name' => 'DocumentBasket'
|
---|
110 | }
|
---|
111 | },
|
---|
112 | {
|
---|
113 | '.attr' => {
|
---|
114 | 'name' => 'BerryBasket'
|
---|
115 | }
|
---|
116 | },
|
---|
117 | {
|
---|
118 | '.attr' => {
|
---|
119 | 'name' => 'GS2Construct'
|
---|
120 | }
|
---|
121 | },
|
---|
122 | {
|
---|
123 | '.attr' => {
|
---|
124 | 'name' => 'DebugService'
|
---|
125 | }
|
---|
126 | },
|
---|
127 | {
|
---|
128 | '.attr' => {
|
---|
129 | 'name' => 'UserTracker'
|
---|
130 | }
|
---|
131 | },
|
---|
132 | {
|
---|
133 | 'format' => {
|
---|
134 | 'gsf:template' => {
|
---|
135 | '.attr' => {
|
---|
136 | 'match' => 'documentNode'
|
---|
137 | },
|
---|
138 | 'td' => [
|
---|
139 | {
|
---|
140 | 'a' => {
|
---|
141 | 'xsl:attribute' => {
|
---|
142 | 'xsl:value-of' => [
|
---|
143 | {
|
---|
144 | '.attr' => {
|
---|
145 | 'select' => '$library_name'
|
---|
146 | }
|
---|
147 | },
|
---|
148 | {
|
---|
149 | '.attr' => {
|
---|
150 | 'select' => '@collection'
|
---|
151 | }
|
---|
152 | },
|
---|
153 | {
|
---|
154 | '.attr' => {
|
---|
155 | 'select' => '@nodeID'
|
---|
156 | }
|
---|
157 | }
|
---|
158 | ],
|
---|
159 | '.value' => '/collection//document/',
|
---|
160 | '.attr' => {
|
---|
161 | 'name' => 'href'
|
---|
162 | }
|
---|
163 | },
|
---|
164 | 'gsf:icon' => {}
|
---|
165 | }
|
---|
166 | },
|
---|
167 | {
|
---|
168 | 'gsf:metadata' => {
|
---|
169 | '.attr' => {
|
---|
170 | 'name' => 'Title'
|
---|
171 | }
|
---|
172 | }
|
---|
173 | },
|
---|
174 | {
|
---|
175 | 'a' => {
|
---|
176 | 'xsl:value-of' => {
|
---|
177 | '.attr' => {
|
---|
178 | 'select' => '/page/pageResponse/service/paramList/param[@name=\'collection\']/option[@name=$collname]/displayItem[@name=\'name\']'
|
---|
179 | }
|
---|
180 | },
|
---|
181 | '.attr' => {
|
---|
182 | 'href' => '{$library_name}/collection/{$collname}/page/about'
|
---|
183 | }
|
---|
184 | }
|
---|
185 | }
|
---|
186 | ],
|
---|
187 | 'xsl:variable' => {
|
---|
188 | '.attr' => {
|
---|
189 | 'name' => 'collname',
|
---|
190 | 'select' => '@collection'
|
---|
191 | }
|
---|
192 | }
|
---|
193 | }
|
---|
194 | },
|
---|
195 | '.attr' => {
|
---|
196 | 'name' => 'CrossCollectionSearch'
|
---|
197 | }
|
---|
198 | }
|
---|
199 | ]
|
---|
200 | },
|
---|
201 | '.attr' => {
|
---|
202 | 'xmlns:gsf' => 'http://www.greenstone.org/greenstone3/schema/ConfigFormat',
|
---|
203 | 'xmlns:xsl' => 'http://www.w3.org/1999/XSL/Transform'
|
---|
204 | },
|
---|
205 | 'serviceClusterList' => {},
|
---|
206 | 'metadataList' => {
|
---|
207 | 'metadata' => [
|
---|
208 | {
|
---|
209 | '.attr' => {
|
---|
210 | 'lang' => 'en',
|
---|
211 | 'name' => 'siteName'
|
---|
212 | },
|
---|
213 | '.value' => 'My Greenstone Library'
|
---|
214 | },
|
---|
215 | {
|
---|
216 | '.attr' => {
|
---|
217 | 'lang' => 'fr',
|
---|
218 | 'name' => 'siteName'
|
---|
219 | },
|
---|
220 | '.value' => "Mon site de d\x{e9}velopment"
|
---|
221 | },
|
---|
222 | {
|
---|
223 | '.attr' => {
|
---|
224 | 'name' => 'siteDescription',
|
---|
225 | 'lang' => 'en'
|
---|
226 | },
|
---|
227 | '.value' => 'This is just a random site for testing stuff...'
|
---|
228 | },
|
---|
229 | {
|
---|
230 | '.attr' => {
|
---|
231 | 'lang' => 'fr',
|
---|
232 | 'name' => 'siteDescription'
|
---|
233 | },
|
---|
234 | '.value' => 'C\'est juste un site pour tester des trucs...'
|
---|
235 | },
|
---|
236 | {
|
---|
237 | '.value' => '[email protected]',
|
---|
238 | '.attr' => {
|
---|
239 | 'name' => 'siteAdmin'
|
---|
240 | }
|
---|
241 | }
|
---|
242 | ],
|
---|
243 | '.attr' => {
|
---|
244 | 'xmlns:xsl' => 'http://www.w3.org/1999/XSL/Transform',
|
---|
245 | 'xmlns:gsf' => 'http://www.greenstone.org/greenstone3/schema/MetadataFormat'
|
---|
246 | }
|
---|
247 | },
|
---|
248 | 'replaceList' => [
|
---|
249 | {
|
---|
250 | 'replace' => [
|
---|
251 | {
|
---|
252 | '.attr' => {
|
---|
253 | 'scope' => 'metadata',
|
---|
254 | 'text' => '<img src=\'interfaces/default/images/ipdf.gif\' border=\'0\'/>',
|
---|
255 | 'macro' => '_iconpdf_',
|
---|
256 | 'resolve' => 'false'
|
---|
257 | }
|
---|
258 | },
|
---|
259 | {
|
---|
260 | '.attr' => {
|
---|
261 | 'macro' => '_icondoc_',
|
---|
262 | 'resolve' => 'false',
|
---|
263 | 'text' => '<img src=\'interfaces/default/images/imsword.gif\' border=\'0\'/>',
|
---|
264 | 'scope' => 'metadata'
|
---|
265 | }
|
---|
266 | },
|
---|
267 | {
|
---|
268 | '.attr' => {
|
---|
269 | 'scope' => 'metadata',
|
---|
270 | 'resolve' => 'false',
|
---|
271 | 'macro' => '_iconps_',
|
---|
272 | 'text' => '<img src=\'interfaces/default/images/ips.gif\' border=\'0\'/>'
|
---|
273 | }
|
---|
274 | },
|
---|
275 | {
|
---|
276 | '.attr' => {
|
---|
277 | 'text' => '<img src=\'interfaces/default/images/irtf.gif\' border=\'0\'/>',
|
---|
278 | 'macro' => '_iconrtf_',
|
---|
279 | 'resolve' => 'false',
|
---|
280 | 'scope' => 'metadata'
|
---|
281 | }
|
---|
282 | },
|
---|
283 | {
|
---|
284 | '.attr' => {
|
---|
285 | 'scope' => 'metadata',
|
---|
286 | 'text' => '<img src=\'interfaces/default/images/iexcel.gif\' border=\'0\'/>',
|
---|
287 | 'resolve' => 'false',
|
---|
288 | 'macro' => '_iconxls_'
|
---|
289 | }
|
---|
290 | },
|
---|
291 | {
|
---|
292 | '.attr' => {
|
---|
293 | 'macro' => '_iconppt_',
|
---|
294 | 'resolve' => 'false',
|
---|
295 | 'text' => '<img src=\'interfaces/default/images/ippt.gif\' border=\'0\'/>',
|
---|
296 | 'scope' => 'metadata'
|
---|
297 | }
|
---|
298 | },
|
---|
299 | {
|
---|
300 | '.attr' => {
|
---|
301 | 'text' => '<img src=\'interfaces/default/images/itext.gif\' border=\'0\'/>',
|
---|
302 | 'resolve' => 'false',
|
---|
303 | 'macro' => '_icontext_',
|
---|
304 | 'scope' => 'metadata'
|
---|
305 | }
|
---|
306 | },
|
---|
307 | {
|
---|
308 | '.attr' => {
|
---|
309 | 'scope' => 'metadata',
|
---|
310 | 'text' => '<img src=\'interfaces/default/images/ibtext.gif\' border=\'0\'/>',
|
---|
311 | 'macro' => '_iconblanktext_',
|
---|
312 | 'resolve' => 'false'
|
---|
313 | }
|
---|
314 | },
|
---|
315 | {
|
---|
316 | '.attr' => {
|
---|
317 | 'scope' => 'metadata',
|
---|
318 | 'text' => '<img src=\'interfaces/default/images/imp3.gif\' border=\'0\'/>',
|
---|
319 | 'macro' => '_iconmp3_',
|
---|
320 | 'resolve' => 'false'
|
---|
321 | }
|
---|
322 | },
|
---|
323 | {
|
---|
324 | '.attr' => {
|
---|
325 | 'scope' => 'metadata',
|
---|
326 | 'text' => '<img src=\'interfaces/default/images/imidi.gif\' border=\'0\'/>',
|
---|
327 | 'macro' => '_iconmidi_',
|
---|
328 | 'resolve' => 'false'
|
---|
329 | }
|
---|
330 | },
|
---|
331 | {
|
---|
332 | '.attr' => {
|
---|
333 | 'text' => '<img src=\'interfaces/default/images/iworld.gif\' border=\'0\'/>',
|
---|
334 | 'macro' => '_iconworld_',
|
---|
335 | 'resolve' => 'false',
|
---|
336 | 'scope' => 'metadata'
|
---|
337 | }
|
---|
338 | },
|
---|
339 | {
|
---|
340 | '.attr' => {
|
---|
341 | 'text' => '<img src=\'interfaces/default/images/iunknown.gif\' border=\'0\'/>',
|
---|
342 | 'resolve' => 'false',
|
---|
343 | 'macro' => '_iconunknown_',
|
---|
344 | 'scope' => 'metadata'
|
---|
345 | }
|
---|
346 | },
|
---|
347 | {
|
---|
348 | '.attr' => {
|
---|
349 | 'resolve' => 'false',
|
---|
350 | 'macro' => '[archivedir]',
|
---|
351 | 'scope' => 'all',
|
---|
352 | 'metadata' => 'assocfilepath'
|
---|
353 | }
|
---|
354 | },
|
---|
355 | {
|
---|
356 | '.attr' => {
|
---|
357 | 'metadata' => 'assocfilepath',
|
---|
358 | 'scope' => 'all',
|
---|
359 | 'macro' => '[assocfilepath]',
|
---|
360 | 'resolve' => 'false'
|
---|
361 | }
|
---|
362 | },
|
---|
363 | {
|
---|
364 | '.attr' => {
|
---|
365 | 'resolve' => 'false',
|
---|
366 | 'macro' => '[srcurl]',
|
---|
367 | 'metadata' => 'srcurl',
|
---|
368 | 'scope' => 'metadata'
|
---|
369 | }
|
---|
370 | },
|
---|
371 | {
|
---|
372 | '.attr' => {
|
---|
373 | 'resolve' => 'false',
|
---|
374 | 'macro' => '[SourceFile]',
|
---|
375 | 'metadata' => 'SourceFile',
|
---|
376 | 'scope' => 'metadata'
|
---|
377 | }
|
---|
378 | },
|
---|
379 | {
|
---|
380 | '.attr' => {
|
---|
381 | 'scope' => 'metadata',
|
---|
382 | 'text' => '_httpsite_/collect/_clustername_',
|
---|
383 | 'macro' => '_httpcollection_',
|
---|
384 | 'resolve' => 'true'
|
---|
385 | }
|
---|
386 | },
|
---|
387 | {
|
---|
388 | '.attr' => {
|
---|
389 | 'scope' => 'metadata',
|
---|
390 | 'text' => '_httpsite_',
|
---|
391 | 'macro' => '_httpprefix_',
|
---|
392 | 'resolve' => 'true'
|
---|
393 | }
|
---|
394 | },
|
---|
395 | {
|
---|
396 | '.attr' => {
|
---|
397 | 'text' => '_httpsite_/collect/_clustername_/index/assoc/[assocfilepath]/',
|
---|
398 | 'resolve' => 'true',
|
---|
399 | 'macro' => '_httpdocimg_',
|
---|
400 | 'scope' => 'text'
|
---|
401 | }
|
---|
402 | },
|
---|
403 | {
|
---|
404 | '.attr' => {
|
---|
405 | 'scope' => 'text',
|
---|
406 | 'text' => '_libraryname_/collection/_clustername_/document/[DocOID]',
|
---|
407 | 'resolve' => 'true',
|
---|
408 | 'macro' => '_httpsamepagelink_'
|
---|
409 | }
|
---|
410 | },
|
---|
411 | {
|
---|
412 | '.attr' => {
|
---|
413 | 'text' => '_clustername_',
|
---|
414 | 'resolve' => 'true',
|
---|
415 | 'macro' => '[collection]',
|
---|
416 | 'scope' => 'all'
|
---|
417 | }
|
---|
418 | },
|
---|
419 | {
|
---|
420 | '.attr' => {
|
---|
421 | 'scope' => 'all',
|
---|
422 | 'macro' => '_httpextlink_',
|
---|
423 | 'resolve' => 'true',
|
---|
424 | 'text' => '_libraryname_?el=&a=d&c=_clustername_&d='
|
---|
425 | }
|
---|
426 | }
|
---|
427 | ],
|
---|
428 | '.attr' => {
|
---|
429 | 'id' => 'gs2-standard'
|
---|
430 | }
|
---|
431 | },
|
---|
432 | {
|
---|
433 | 'replace' => [
|
---|
434 | {
|
---|
435 | '.attr' => {
|
---|
436 | 'macro' => '[Image]',
|
---|
437 | 'resolve' => 'false',
|
---|
438 | 'metadata' => 'Image',
|
---|
439 | 'scope' => 'metadata'
|
---|
440 | }
|
---|
441 | },
|
---|
442 | {
|
---|
443 | '.attr' => {
|
---|
444 | 'metadata' => 'Thumb',
|
---|
445 | 'scope' => 'metadata',
|
---|
446 | 'resolve' => 'false',
|
---|
447 | 'macro' => '[Thumb]'
|
---|
448 | }
|
---|
449 | },
|
---|
450 | {
|
---|
451 | '.attr' => {
|
---|
452 | 'scope' => 'metadata',
|
---|
453 | 'metadata' => 'ThumbWidth',
|
---|
454 | 'macro' => '[ThumbWidth]',
|
---|
455 | 'resolve' => 'false'
|
---|
456 | }
|
---|
457 | },
|
---|
458 | {
|
---|
459 | '.attr' => {
|
---|
460 | 'metadata' => 'ThumbHeight',
|
---|
461 | 'scope' => 'metadata',
|
---|
462 | 'resolve' => 'false',
|
---|
463 | 'macro' => '[ThumbHeight]'
|
---|
464 | }
|
---|
465 | },
|
---|
466 | {
|
---|
467 | '.attr' => {
|
---|
468 | 'macro' => '[Screen]',
|
---|
469 | 'resolve' => 'false',
|
---|
470 | 'metadata' => 'Screen',
|
---|
471 | 'scope' => 'metadata'
|
---|
472 | }
|
---|
473 | },
|
---|
474 | {
|
---|
475 | '.attr' => {
|
---|
476 | 'metadata' => 'ScreenWidth',
|
---|
477 | 'scope' => 'metadata',
|
---|
478 | 'macro' => '[ScreenWidth]',
|
---|
479 | 'resolve' => 'false'
|
---|
480 | }
|
---|
481 | },
|
---|
482 | {
|
---|
483 | '.attr' => {
|
---|
484 | 'resolve' => 'false',
|
---|
485 | 'macro' => '[ScreenHeight]',
|
---|
486 | 'metadata' => 'ScreenHeight',
|
---|
487 | 'scope' => 'metadata'
|
---|
488 | }
|
---|
489 | }
|
---|
490 | ],
|
---|
491 | '.attr' => {
|
---|
492 | 'id' => 'gs2-image'
|
---|
493 | }
|
---|
494 | }
|
---|
495 | ]
|
---|
496 | }
|
---|
497 | };
|
---|
498 |
|
---|