1 |
dpavlin |
167 |
package Strix; |
2 |
|
|
|
3 |
|
|
use strict; |
4 |
|
|
use warnings; |
5 |
|
|
|
6 |
dpavlin |
168 |
use base qw(Jifty::Object Class::Accessor::Fast); |
7 |
|
|
__PACKAGE__->mk_accessors( qw(site) ); |
8 |
dpavlin |
167 |
|
9 |
|
|
use DBI; |
10 |
|
|
use Data::Dump qw/dump/; |
11 |
dpavlin |
168 |
use Carp qw/confess/; |
12 |
dpavlin |
167 |
|
13 |
dpavlin |
168 |
our $debug = 0; |
14 |
|
|
|
15 |
dpavlin |
167 |
=head1 NAME |
16 |
|
|
|
17 |
|
|
Strix |
18 |
|
|
|
19 |
|
|
=head1 METHODS |
20 |
|
|
|
21 |
dpavlin |
168 |
=head2 new |
22 |
|
|
|
23 |
|
|
my $strix = Strix->new({ site => 'os-test0604-zg' }); |
24 |
|
|
|
25 |
dpavlin |
167 |
=head2 dbh |
26 |
|
|
|
27 |
dpavlin |
168 |
my $dbh = Strix->dbh( $site_name ); |
28 |
dpavlin |
167 |
|
29 |
dpavlin |
168 |
my $dbh = $strix->dbh; |
30 |
|
|
|
31 |
dpavlin |
167 |
=cut |
32 |
|
|
|
33 |
|
|
sub dbh { |
34 |
|
|
my $self = shift; |
35 |
|
|
|
36 |
dpavlin |
168 |
my $site = shift || $self->site || confess "no site"; |
37 |
dpavlin |
167 |
|
38 |
|
|
my $config = Jifty->config->app('strix') or die "need strix config"; |
39 |
|
|
my $database = $config->{database} or die "no strix.database in config"; |
40 |
|
|
|
41 |
|
|
Jifty->log->debug("using config ", dump( $database )); |
42 |
|
|
|
43 |
|
|
my $dsn = |
44 |
|
|
'DBI:Pg:dbname=' . $site . |
45 |
|
|
';host=' . $database->{host} . |
46 |
|
|
';port=' . $database->{port}; |
47 |
|
|
|
48 |
|
|
Jifty->log->info("Connect to site $site with dsn $dsn"); |
49 |
|
|
|
50 |
|
|
my $dbh = DBI->connect( $dsn, $database->{user}, $database->{passwd} ) or die $DBI::errstr; |
51 |
|
|
|
52 |
|
|
return $dbh; |
53 |
|
|
} |
54 |
|
|
|
55 |
dpavlin |
168 |
=head2 category |
56 |
|
|
|
57 |
|
|
my $category = Strix->category( $url ); |
58 |
|
|
|
59 |
|
|
=cut |
60 |
|
|
|
61 |
|
|
sub category { |
62 |
|
|
my $self = shift; |
63 |
|
|
|
64 |
|
|
my $url = shift || confess "no url"; |
65 |
|
|
|
66 |
|
|
# sysinc/profiles.php |
67 |
|
|
my $sth = $self->dbh->prepare(qq{ |
68 |
|
|
SELECT kategorija.*, lang.langid, lang.locale, template.tfilename, template.tflags, site.naziv as sitename, site.admin_mail, site.address, site.root as site_root, getPathFromNav(kategorija.id) as path, site.ordstr as site_ordstr FROM kategorija, template, site, lang WHERE kategorija.url = ? AND kategorija.template_id = template.id AND kategorija.site_id = site.id AND lang.id = kategorija.lang |
69 |
|
|
}); |
70 |
|
|
$sth->execute($url); |
71 |
|
|
|
72 |
|
|
my $category = $sth->fetchrow_hashref() or die "can't fetch category $url"; |
73 |
|
|
return $category; |
74 |
|
|
} |
75 |
|
|
|
76 |
|
|
=head2 layout |
77 |
|
|
|
78 |
|
|
my $layout = $strix->layout( $url ); |
79 |
|
|
|
80 |
|
|
=cut |
81 |
|
|
|
82 |
|
|
sub layout { |
83 |
|
|
my $self = shift; |
84 |
|
|
|
85 |
|
|
my $url = shift || confess "no url"; |
86 |
|
|
|
87 |
|
|
my $dbh = $self->dbh; |
88 |
|
|
my $category = $self->category( $url ); |
89 |
|
|
|
90 |
|
|
my $sth = $dbh->prepare(qq{ |
91 |
|
|
SELECT template.tfilename, template.tflags FROM template WHERE id = ? |
92 |
|
|
}); |
93 |
|
|
$sth->execute( $category->{template_id} ); |
94 |
|
|
|
95 |
|
|
my $template = $sth->fetchrow_hashref() or die "can't fetch template"; |
96 |
|
|
|
97 |
|
|
warn "template = ",dump( $template ) if $debug; |
98 |
|
|
|
99 |
|
|
my $page; |
100 |
|
|
warn "### free layout...\n" if $debug; |
101 |
|
|
|
102 |
|
|
# index.php |
103 |
|
|
$sth = $dbh->prepare(qq{ |
104 |
|
|
SELECT layout_id, module_id, pozicija, module_args, name, fname, notitle, class_name |
105 |
|
|
FROM pre_layout, modules |
106 |
|
|
WHERE id=module_id AND ? = template_id AND redoslijed >= 0 |
107 |
|
|
ORDER BY redoslijed DESC |
108 |
|
|
}); |
109 |
|
|
$sth->execute( $category->{template_id} ); |
110 |
|
|
|
111 |
|
|
while (my $row = $sth->fetchrow_hashref() ) { |
112 |
|
|
warn dump( $row ) if $debug; |
113 |
|
|
push @{ $page->{free} }, { $row->{name} => $row->{module_args} }; |
114 |
|
|
} |
115 |
|
|
|
116 |
|
|
warn "### pre layout...\n" if $debug; |
117 |
|
|
|
118 |
|
|
$sth = $dbh->prepare(qq{ |
119 |
|
|
SELECT |
120 |
|
|
l.id as layout_id, l.user_id, l.kategorija_id, l.module_id, l.pozicija, l.redoslijed, l.module_args, l.state, l.notitle, |
121 |
|
|
m.name, m.fname, m.hidden, m.nocache, m.pos, m.class_name, |
122 |
|
|
acl_module.acl_register_id |
123 |
|
|
FROM layout as l, modules as m LEFT JOIN acl_module ON (acl_module.modules_id = m.id) |
124 |
|
|
WHERE l.user_id=? |
125 |
|
|
AND l.kategorija_id=? |
126 |
|
|
AND m.id=l.module_id |
127 |
|
|
ORDER BY pozicija,redoslijed DESC |
128 |
|
|
}); |
129 |
|
|
$sth->execute( 1, $category->{id} ); |
130 |
|
|
|
131 |
|
|
while (my $row = $sth->fetchrow_hashref() ) { |
132 |
|
|
warn dump( $row ) if $debug; |
133 |
|
|
push @{ $page->{pre}->{ $row->{pos} } }, { $row->{name} => $row->{module_args} }; |
134 |
|
|
} |
135 |
|
|
|
136 |
|
|
warn "### post layout...\n" if $debug; |
137 |
|
|
|
138 |
|
|
$sth = $dbh->prepare(qq{ |
139 |
|
|
SELECT layout_id, module_id, pozicija, module_args, name, notitle |
140 |
|
|
FROM pre_layout, modules |
141 |
|
|
WHERE id=module_id AND ? = template_id AND redoslijed < 0 |
142 |
|
|
ORDER BY redoslijed DESC |
143 |
|
|
}); |
144 |
|
|
$sth->execute( $category->{template_id} ); |
145 |
|
|
|
146 |
|
|
while (my $row = $sth->fetchrow_hashref() ) { |
147 |
|
|
warn dump( $row ) if $debug; |
148 |
|
|
push @{ $page->{post}->{ $row->{pozicija} } }, { $row->{name} => $row->{module_args} }; |
149 |
|
|
} |
150 |
|
|
|
151 |
|
|
return $page; |
152 |
|
|
|
153 |
|
|
} |
154 |
|
|
|
155 |
dpavlin |
167 |
1; |