line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MojoMojo::Controller::Gallery; |
2
|
|
|
|
|
|
|
|
3
|
35
|
|
|
35
|
|
16231
|
use strict; |
|
35
|
|
|
|
|
93
|
|
|
35
|
|
|
|
|
1050
|
|
4
|
35
|
|
|
35
|
|
184
|
use parent 'Catalyst::Controller'; |
|
35
|
|
|
|
|
78
|
|
|
35
|
|
|
|
|
225
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
MojoMojo::Controller::Gallery - Page gallery. |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 SYNOPSIS |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
See L<MojoMojo> |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 DESCRIPTION |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Controller for page photo galleries. |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 METHODS |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=cut |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head2 default |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
Private action to return a 404 not found page. |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=cut |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub default : Private { |
29
|
0
|
|
|
0
|
|
0
|
my ( $self, $c ) = @_; |
30
|
0
|
|
|
|
|
0
|
$c->stash->{template} = 'message.tt'; |
31
|
0
|
|
0
|
|
|
0
|
$c->stash->{message} ||= $c->loc('Photo not found'); |
32
|
0
|
|
|
|
|
0
|
return ( $c->res->status(404) ); |
33
|
35
|
|
|
35
|
|
4504
|
} |
|
35
|
|
|
|
|
82
|
|
|
35
|
|
|
|
|
207
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head2 gallery ( .gallery ) |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
Show a gallery page for the current node. |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=cut |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub gallery : Path { |
43
|
0
|
|
|
0
|
1
|
0
|
my ( $self, $c, $page ) = @_; |
44
|
0
|
|
|
|
|
0
|
$page--, $page++; # coerce to number; strings become 0 |
45
|
0
|
|
|
|
|
0
|
$c->stash->{template} = 'gallery.tt'; |
46
|
|
|
|
|
|
|
$c->stash->{pictures} = $c->model("DBIC::Photo")->search( |
47
|
|
|
|
|
|
|
{ 'attachment.page' => $c->stash->{page}->id }, |
48
|
|
|
|
|
|
|
{ |
49
|
0
|
|
0
|
|
|
0
|
page => $page || 1, |
50
|
|
|
|
|
|
|
join => [qw/attachment/], |
51
|
|
|
|
|
|
|
rows => 12, |
52
|
|
|
|
|
|
|
order_by => 'position' |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
); |
55
|
35
|
|
|
35
|
|
431503
|
} |
|
35
|
|
|
|
|
94
|
|
|
35
|
|
|
|
|
168
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head2 by_tag ( .gallery/by_tag ) |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Show a gallery by a given tag. Will also show photos in the |
60
|
|
|
|
|
|
|
descendants of the page with the given tag. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=cut |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub by_tag : Local { |
65
|
0
|
|
|
0
|
1
|
0
|
my ( $self, $c, $tag, $page ) = @_; |
66
|
0
|
|
|
|
|
0
|
$page--, $page++; # coerce to number; strings become 0 |
67
|
0
|
|
|
|
|
0
|
$tag = $c->model("DBIC::Tag")->search( tag => $tag )->next; |
68
|
0
|
0
|
|
|
|
0
|
if (not $tag) { |
69
|
0
|
|
|
|
|
0
|
$c->stash->{message} = $c->loc('Tag not found'); |
70
|
0
|
|
|
|
|
0
|
$c->detach('default'); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
0
|
$c->stash->{template} = 'gallery.tt'; |
74
|
0
|
|
|
|
|
0
|
$c->stash->{tag} = $tag->tag; |
75
|
0
|
|
|
|
|
0
|
my $conditions = { 'tags.tag' => $tag->tag }; |
76
|
|
|
|
|
|
|
$$conditions{'attachment.page'} = |
77
|
0
|
|
|
|
|
0
|
[ map { $_->id } ( $c->stash->{page}->descendants, $c->stash->{page} ) ] |
78
|
0
|
0
|
|
|
|
0
|
unless length( $c->stash->{page}->path ) == 1; # root |
79
|
0
|
|
0
|
|
|
0
|
$c->stash->{pictures} = $c->model("DBIC::Photo")->search( |
80
|
|
|
|
|
|
|
$conditions, |
81
|
|
|
|
|
|
|
{ |
82
|
|
|
|
|
|
|
join => [qw/attachment tags/], |
83
|
|
|
|
|
|
|
page => $page || 1, |
84
|
|
|
|
|
|
|
rows => 12, |
85
|
|
|
|
|
|
|
order_by => 'taken DESC' |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
); |
88
|
35
|
|
|
35
|
|
38053
|
} |
|
35
|
|
|
|
|
88
|
|
|
35
|
|
|
|
|
162
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head2 photo ( .photo/<id> ) |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Show a gallery photo page. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=cut |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub photo : Global { |
97
|
0
|
|
|
0
|
1
|
0
|
my ( $self, $c, $photo ) = @_; |
98
|
0
|
0
|
|
|
|
0
|
$photo = $c->model("DBIC::Photo")->find($photo) |
99
|
|
|
|
|
|
|
or $c->detach('default'); |
100
|
0
|
|
|
|
|
0
|
$c->stash->{photo} = $photo; |
101
|
0
|
|
|
|
|
0
|
$c->forward('inline_tags'); |
102
|
0
|
|
|
|
|
0
|
$c->stash->{template} = 'gallery/photo.tt'; |
103
|
0
|
|
|
|
|
0
|
$c->stash->{next} = $photo->next_sibling; |
104
|
0
|
|
|
|
|
0
|
$c->stash->{prev} = $photo->previous_sibling; |
105
|
35
|
|
|
35
|
|
33349
|
} |
|
35
|
|
|
|
|
85
|
|
|
35
|
|
|
|
|
174
|
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head2 ( /photo_by_tag/<id> ) |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Show a picture in tag gallery. |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=cut |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub photo_by_tag : Global { |
114
|
0
|
|
|
0
|
1
|
0
|
my ( $self, $c, $tag, $photo ) = @_; |
115
|
0
|
0
|
|
|
|
0
|
$photo = $c->model("DBIC::Photo")->find($photo) |
116
|
|
|
|
|
|
|
or $c->detach('default'); |
117
|
0
|
|
|
|
|
0
|
$c->stash->{photo} = $photo; |
118
|
0
|
|
|
|
|
0
|
$c->stash->{tag} = $tag; |
119
|
0
|
|
|
|
|
0
|
$c->forward('inline_tags'); |
120
|
0
|
|
|
|
|
0
|
$c->stash->{template} = 'gallery/photo.tt'; |
121
|
0
|
|
|
|
|
0
|
$c->stash->{next} = $photo->next_by_tag($tag); |
122
|
0
|
|
|
|
|
0
|
$c->stash->{prev} = $photo->prev_by_tag($tag); |
123
|
35
|
|
|
35
|
|
33948
|
} |
|
35
|
|
|
|
|
85
|
|
|
35
|
|
|
|
|
178
|
|
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head2 submittag ( /gallery/submittag ) |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Add a tag through form submit. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=cut |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub submittag : Local { |
132
|
0
|
|
|
0
|
1
|
0
|
my ( $self, $c, $photo ) = @_; |
133
|
0
|
|
|
|
|
0
|
$c->forward( 'tag', [ $photo, $c->req->params->{tag} ] ); |
134
|
35
|
|
|
35
|
|
31648
|
} |
|
35
|
|
|
|
|
84
|
|
|
35
|
|
|
|
|
157
|
|
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head2 tag ( /.jsrpc/tag ) |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Add a tag to a page. Forwards to |
139
|
|
|
|
|
|
|
L<< inline_tags|/inline_tags ( .gallery/tags ) >>. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=cut |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub tag : Local { |
144
|
0
|
|
|
0
|
1
|
0
|
my ( $self, $c, $photo, $tagname ) = @_; |
145
|
0
|
|
|
|
|
0
|
($tagname) = $tagname =~ m/([\w\s]+)/; |
146
|
0
|
|
|
|
|
0
|
foreach my $tag ( split m/\s/, $tagname ) { |
147
|
0
|
0
|
0
|
|
|
0
|
if ( |
148
|
|
|
|
|
|
|
$tag |
149
|
|
|
|
|
|
|
&& !$c->model("DBIC::Tag")->search( |
150
|
|
|
|
|
|
|
photo => $photo, |
151
|
|
|
|
|
|
|
person => $c->user->obj->id, |
152
|
|
|
|
|
|
|
tag => $tag |
153
|
|
|
|
|
|
|
)->next() |
154
|
|
|
|
|
|
|
) |
155
|
|
|
|
|
|
|
{ |
156
|
0
|
0
|
|
|
|
0
|
$c->model("DBIC::Tag")->create( |
157
|
|
|
|
|
|
|
{ |
158
|
|
|
|
|
|
|
photo => $photo, |
159
|
|
|
|
|
|
|
tag => $tag, |
160
|
|
|
|
|
|
|
person => $c->user->obj->id |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
) if $photo; |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
} |
165
|
0
|
|
|
|
|
0
|
$c->stash->{photo} = $photo; |
166
|
0
|
|
|
|
|
0
|
$c->forward( 'inline_tags', [$tagname] ); |
167
|
35
|
|
|
35
|
|
36313
|
} |
|
35
|
|
|
|
|
84
|
|
|
35
|
|
|
|
|
169
|
|
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head2 untag ( .gallery/untag ) |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
Remove a tag from a page. Forwards to |
172
|
|
|
|
|
|
|
L<< inline_tags|/inline_tags ( .gallery/tags ) >>. |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=cut |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
sub untag : Local { |
177
|
0
|
|
|
0
|
1
|
0
|
my ( $self, $c, $photo, $tagname ) = @_; |
178
|
0
|
|
|
|
|
0
|
my $tag = $c->model("DBIC::Tag")->search( |
179
|
|
|
|
|
|
|
photo => $photo, |
180
|
|
|
|
|
|
|
person => $c->user->obj->id, |
181
|
|
|
|
|
|
|
tag => $tagname |
182
|
|
|
|
|
|
|
)->next(); |
183
|
0
|
0
|
|
|
|
0
|
$tag->delete() if $tag; |
184
|
0
|
|
|
|
|
0
|
$c->stash->{photo} = $photo; |
185
|
0
|
|
|
|
|
0
|
$c->forward( 'inline_tags', [$tagname] ); |
186
|
35
|
|
|
35
|
|
32236
|
} |
|
35
|
|
|
|
|
95
|
|
|
35
|
|
|
|
|
157
|
|
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head2 inline_tags ( .gallery/tags ) |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
Make a list of the user's tags and popular tags, or just popular tags |
191
|
|
|
|
|
|
|
if no user is logged in. |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=cut |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
sub inline_tags : Local { |
196
|
0
|
|
|
0
|
1
|
0
|
my ( $self, $c, $highlight ) = @_; |
197
|
0
|
|
|
|
|
0
|
$c->stash->{template} = 'gallery/tags.tt'; |
198
|
0
|
|
|
|
|
0
|
$c->stash->{highlight} = $highlight; |
199
|
0
|
|
0
|
|
|
0
|
my $photo = $c->stash->{photo} || $c->req->params->{photo}; |
200
|
0
|
0
|
|
|
|
0
|
$photo = $c->model("DBIC::Photo")->find($photo) unless ref $photo; |
201
|
0
|
|
|
|
|
0
|
$c->stash->{photo} = $photo; |
202
|
0
|
0
|
|
|
|
0
|
if ( $c->user_exists ) { |
203
|
0
|
|
|
|
|
0
|
my @tags = $photo->others_tags( $c->user->obj->id ); |
204
|
0
|
|
|
|
|
0
|
$c->stash->{others_tags} = [@tags]; |
205
|
0
|
|
|
|
|
0
|
@tags = $photo->user_tags( $c->user->obj->id ); |
206
|
0
|
|
|
|
|
0
|
$c->stash->{taglist} = ' ' . join( ' ', map { $_->tag } @tags ) . ' '; |
|
0
|
|
|
|
|
0
|
|
207
|
0
|
|
|
|
|
0
|
$c->stash->{tags} = [@tags]; |
208
|
|
|
|
|
|
|
} |
209
|
|
|
|
|
|
|
else { |
210
|
0
|
|
|
|
|
0
|
$c->stash->{others_tags} = [ $photo->others_tags(undef) ]; |
211
|
|
|
|
|
|
|
} |
212
|
35
|
|
|
35
|
|
35921
|
} |
|
35
|
|
|
|
|
94
|
|
|
35
|
|
|
|
|
150
|
|
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=head2 description ( .gallery/description ) |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
AJAX method for updating picture descriptions inline. |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=cut |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
sub description : Local { |
221
|
0
|
|
|
0
|
1
|
0
|
my ( $self, $c, $photo ) = @_; |
222
|
0
|
0
|
|
|
|
0
|
my $img = $c->model("DBIC::Photo")->find($photo) |
223
|
|
|
|
|
|
|
or $c->detach('default'); |
224
|
0
|
0
|
|
|
|
0
|
if ( $c->req->param('update_value') ) { |
225
|
0
|
|
|
|
|
0
|
$img->description( $c->req->param('update_value') ); |
226
|
0
|
|
|
|
|
0
|
$img->update; |
227
|
|
|
|
|
|
|
} |
228
|
0
|
|
|
|
|
0
|
$c->res->body( $img->description ); |
229
|
35
|
|
|
35
|
|
32961
|
} |
|
35
|
|
|
|
|
90
|
|
|
35
|
|
|
|
|
173
|
|
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
=head2 title ( .gallery/title ) |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
AJAX method for updating picture titles inline. |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=cut |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
sub title : Local { |
238
|
0
|
|
|
0
|
1
|
0
|
my ( $self, $c, $photo ) = @_; |
239
|
0
|
0
|
|
|
|
0
|
my $img = $c->model("DBIC::Photo")->find($photo) |
240
|
|
|
|
|
|
|
or $c->detach('default'); |
241
|
0
|
0
|
|
|
|
0
|
if ( $c->req->param('update_value') ) { |
242
|
0
|
|
|
|
|
0
|
$img->title( $c->req->param('update_value') ); |
243
|
0
|
|
|
|
|
0
|
$img->update; |
244
|
|
|
|
|
|
|
} |
245
|
0
|
|
|
|
|
0
|
$c->res->body( $img->title ); |
246
|
35
|
|
|
35
|
|
32648
|
} |
|
35
|
|
|
|
|
89
|
|
|
35
|
|
|
|
|
163
|
|
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
sub tags : Local { |
249
|
0
|
|
|
0
|
1
|
|
my ( $self, $c, $tag ) = @_; |
250
|
0
|
|
|
|
|
|
$c->stash->{tags} = [ $c->model("DBIC::Tag")->by_photo ]; |
251
|
0
|
|
|
|
|
|
my $cloud = HTML::TagCloud->new(); |
252
|
0
|
|
|
|
|
|
foreach my $tag ( @{ $c->stash->{tags} } ) { |
|
0
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
$cloud->add( |
254
|
|
|
|
|
|
|
$tag->tag, |
255
|
|
|
|
|
|
|
$c->req->base |
256
|
|
|
|
|
|
|
. $c->stash->{path} |
257
|
0
|
|
|
|
|
|
. '.gallery/by_tag/' |
258
|
|
|
|
|
|
|
. $tag->tag . '/' |
259
|
|
|
|
|
|
|
. $tag->photo, |
260
|
|
|
|
|
|
|
$tag->refcount |
261
|
|
|
|
|
|
|
); |
262
|
|
|
|
|
|
|
} |
263
|
0
|
|
|
|
|
|
$c->stash->{cloud} = $cloud; |
264
|
0
|
|
|
|
|
|
$c->stash->{template} = 'gallery/cloud.tt'; |
265
|
35
|
|
|
35
|
|
34024
|
} |
|
35
|
|
|
|
|
90
|
|
|
35
|
|
|
|
|
170
|
|
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
=head1 AUTHOR |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
Marcus Ramberg <mramberg@cpan.org> |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
=head1 LICENSE |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
This library is free software. You can redistribute it and/or modify |
274
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
=cut |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
1; |