File: init.pm

package info (click to toggle)
haci 0.97c-2
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 1,816 kB
  • sloc: perl: 19,106; sh: 190; makefile: 8
file content (76 lines) | stat: -rw-r--r-- 2,273 bytes parent folder | download | duplicates (2)
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
package HaCi::GUI::init;

use warnings;
use strict;
use Template;

use HaCi::Conf qw/getConfigValue/;
use HaCi::GUI::gettext qw/_gettext initLocale/;

local our $t			= undef;
our $conf; *conf	= \$HaCi::Conf::conf;

sub init {
	my $s					= $HaCi::HaCi::session;

	if (&getConfigValue('gui', 'enableLocaleSupport')) {
		my $locale		= (defined $s) ? ($s->param('locale') || undef) : undef;
		my $langsT		= (exists $ENV{HTTP_ACCEPT_LANGUAGE}) ? $ENV{HTTP_ACCEPT_LANGUAGE} : '';
		my $langs			= (split(/;/, $langsT))[0] || '';
		my @httpLangs	= split(/,/, $langs);
	
		unless (defined $locale) {
			foreach (reverse @httpLangs) {
				my $currLoc	= (split(/[^a-z]/, lc($_)))[0];
				foreach (@{$conf->{static}->{gui}->{locales}}) {
					my $newLoc	= (split(/[^a-z]/, lc($_->{id})))[0];
					$locale	= $_->{id} if $currLoc eq $newLoc;
				}
			}
		}
		$locale	= 'C' unless defined $locale && $locale;
	
		&initLocale($locale);
		$s->param('locale', $locale);
	}

	$t->{T}	= Template->new(
		INCLUDE_PATH	=> $conf->{static}->{path}->{templateincludepath},
		PRE_CHOMP			=> 3,
		POST_CHOMP		=> 3,
		TRIM					=> 1,
		COMPILE_DIR		=> $conf->{static}->{path}->{templatecompilepath},
		COMPILE_EXT		=> '.ttc',
	);

}

sub setUserVars {
	my $s	= $HaCi::HaCi::session;

	$t->{V}->{showTreeStructure}	= (defined $s->param('settings') && exists $s->param('settings')->{bShowTreeStruct}) ? ${$s->param('settings')->{bShowTreeStruct}}[0] : $conf->{user}->{gui}->{showtreestructure};
	$t->{V}->{directaccess}				= $conf->{user}->{gui}->{directaccess};
	my $style											= (defined $s->param('settings') && exists $s->param('settings')->{layout}) ? ${$s->param('settings')->{layout}}[0] : $conf->{user}->{gui}->{style} || $conf->{static}->{gui}->{style};

	foreach (@{$conf->{static}->{gui}->{layouts}}) {
		my $layout	= $_;
		if ($layout->{name} eq $style) {
			$t->{V}->{style}			= $layout->{file};
			$t->{V}->{styleDescr}	= $layout->{descr};
		}
	}
}

sub setVars {
	$t->{V}												= $conf->{static}->{gui};
	$t->{V}->{thisScript}					= $conf->{var}->{thisscript};
	$t->{V}->{techContact}				= $conf->{user}->{gui}->{techcontact};
	$t->{V}->{gettext_contact}		= _gettext("Contact");
	$t->{V}->{gettext_support}		= _gettext("Supports");

	&setUserVars();
}

1;

# vim:ts=2:sw=2:sws=2