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