-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.pl
executable file
·232 lines (209 loc) · 9.58 KB
/
index.pl
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#!/usr/bin/perl
# This is the index for Movies.
use strict;
use warnings FATAL => qw( all );
use CGI::Simple;
use CGI::Carp qw(fatalsToBrowser);
use FindBin qw($Bin);
use Encode;
use Lingua::EN::Inflect qw(PL_N);
use lib "$Bin/../files/lib";
use Page::Base qw(page);
use Page::File qw(file_directory file_menu);
use Page::HTML qw(section nav div paragraph list form fieldset selection details input anchor);
use Page::Sort qw(article_sort);
use Page::Story qw(story);
use Page::Columns qw(number_of_columns);
use Page::Convert qw(idify);
use Page::CGI::Param qw(get_cgi_param);
use Page::List::Alpha qw(first_alpha alpha_hash alpha_array alpha_menu);
use Page::Movie qw(movie genre movie_option display_option textify_movie start_year end_year
display_movie display_simple_movie print_series print_movie
get_genre get_media movies_beginning);
use Fancy::Join::Grammatical qw(grammatical_join);
my ($sec,$min,$hour,$mday,$mon,$ltyear,$wday,$yday,$isdst) = localtime();
my $current_year = ($ltyear + 1900);
my $cgi = CGI::Simple->new;
my $title = get_cgi_param($cgi, 'title');
my $year = get_cgi_param($cgi, 'year');
my $media = get_cgi_param($cgi, 'media');
my $genre = get_cgi_param($cgi, 'genre');
my $source = get_cgi_param($cgi, 'source');
my $alpha = get_cgi_param($cgi, 'alpha');
my $series = get_cgi_param($cgi, 'series');
my $opinions = get_cgi_param($cgi, 'opinions');
my $genre_list = get_cgi_param($cgi, 'genre list');
my $select = get_cgi_param($cgi, 'page');
my @selects = qw(genre media source);
my %select_options = map { $_ => movie_option($_) } @selects;
my $movies_data = movie('data');
my $search;
my @movies;
if ( $title || $year || $genre || $media || $source || $alpha ) {
my @selections;
push @selections, $title if $title;
push @selections, $year if $year;
push @selections, get_genre($genre) if $genre;
push @selections, get_media($media) if $media;
push @selections, PL_N($source) if $source;
my $selection = @selections ? grammatical_join(' ', map("<b>$_</b>", @selections)) : '';
my $selection_text = $selection;
for my $movie (values %$movies_data) {
my $item = $movie->{'title'};
if ($year) {
my $start_year = start_year($movie);
my $end_year = end_year($movie);
if ($start_year !~ /\d/ || $end_year !~ /\d/) {
if ($start_year ne $year || $end_year ne $year) {
next;
}
}
else {
if ($year < $start_year || $year > $end_year) {
next;
};
}
}
next if $media && $movie->{'media'} ne $media;
next if $genre && !grep($genre =~ /$_/i , @{$movie->{'genre'}});
next if $source && (!$movie->{'source'} || $movie->{'source'} !~ /\b$source(?!ing)/i);
next if $title && lc($movie->{'title'}) !~ /\Q$title\E/i;
next if $alpha && first_alpha($movie->{'title'}) ne $alpha;
push @movies, $movie->{'title'};
}
$search = @movies > 0 ? "You searched for $selection_text in my collection." : "No matches found for $selection_text.";
}
else {
@movies = keys %$movies_data;
}
my $alpha_movies = alpha_array(\@movies);
for my $movies (keys %$alpha_movies) {
my @movies = map(display_movie($movies_data->{$_}, { 'series' => 1, 'links' => 1, 'crossover' => 1 }), sort { article_sort(lc $a, lc $b) } @{$alpha_movies->{$movies}});
@{$alpha_movies->{$movies}} = @movies;
}
my $alpha_menu = scalar(@movies) > 10 ?
alpha_menu($alpha_movies, { 'addition' => anchor('Search the list', { href => '#Search' }), 'join' => ' | ' }) :
undef;
my $browse_alpha = alpha_hash($movies_data);
my $browse_alpha_menu = alpha_menu($browse_alpha, { 'param' => 'alpha', 'join' => ' | ', 'addition' => anchor(" Series list ", { href => '?series=list' }) });
my $open_directory = file_directory('Movies', 'data');
my $text_directory = file_directory('Movies', 'text');
my $series_select = movie_option('series');
my @series_selects = keys %$series_select;
my $series_alpha_movies = alpha_array(\@series_selects);
my $series_alpha_menu = alpha_menu($series_alpha_movies, { 'join' => ' | ' });
my $genre_select = genre('data');
my $genre_link_list = [
map { anchor(ucfirst $_, { 'href' => "index.pl?genre+list=$_" }); } (sort keys %$genre_select)
];
my $magic;
$magic->{'search form'} = sub {
my $tab = 4;
section($tab, sub {
$tab++;
form($tab, sub {
$tab++;
fieldset($tab, sub {
$tab++;
input($tab, { 'type' => 'text', 'name' => 'title', 'placeholder' => 'Title', 'style' => 'width: 19em' });
input($tab, { 'type' => 'number', 'name' => 'year', 'placeholder' => 'Year', 'style' => 'width: 5em', 'min' => "1911", 'max' => $current_year + 1 });
for my $select (@selects) {
my @options = ([ucfirst($select), { 'value' => '' }], map(display_option($select, $_), @{$select_options{$select}}));
selection($tab, \@options, { 'name' => $select, 'style' => 'width: 10em' });
}
input($tab, { 'type' => 'submit', 'value' => 'List movies' });
input($tab, { 'type' => 'button', 'value' => 'Start over', 'onclick' => "location='index.pl'" });
nav(6, "Browse movies: $browse_alpha_menu", { 'class' => 'alpha_menu' });
}, { 'legend' => 'Search my collection' });
}, { 'action' => 'index.pl', 'method' => 'get', 'id' => 'movie_search_form' });
}, { 'id' => 'movie_search' });
};
$magic->{'genre link list'} = sub {
details(6, sub {
list(5, 'u', $genre_link_list, { 'class' => 'four' });
}, { 'summary' => 'List of genres' });
};
my $heading = length $series && $series_select->{$series} ? textify_movie($series) :
length $series && !$series_select->{$series} ? 'Movie series' :
length $genre_list && $genre_select->{$genre_list} ? ucfirst "$genre_list movies" :
length $genre_list && !$genre_select->{$genre_list} ? 'Movie genres' :
length $alpha ? movies_beginning(decode('UTF-8',$alpha)) :
length $opinions ? 'Movie opinions' :
length $select && $select eq 'Movie opinions' ? 'Movie opinions' :
q(Lady Aleena's movie lists);
page( 'heading' => $heading, 'selected' => $select, 'code' => sub {
if ( $search || $alpha ) {
section(3, sub {
paragraph(4, 'This is a list of films and television series I have collected that either interest my fiancé or me or helps populate other pages. You can browse the list or search it.');
&{$magic->{'search form'}};
if ( $title || $year || $media || $genre || $source ) {
paragraph(4, $search) if $search;
}
});
for my $alpha_movie (sort keys %$alpha_movies) {
my $heading = keys %$alpha_movies > 1 ? [2, $alpha_movie, { id => "section_$alpha_movie" }] : undef;
section(3, sub {
list(5, 'u', $alpha_movies->{$alpha_movie}, { 'class' => 'movie_list' });
nav(5, $alpha_menu, { 'class' => 'alpha_menu' }) if $alpha_menu;
}, { 'heading' => $heading });
}
}
elsif ( length $series ) {
if ($series && $series_select->{$series}) {
if ($series_select->{$series} eq 'series') {
print_series(4, 1, $series);
}
else {
print_movie(3, 1, $series);
}
}
else {
for my $series_alpha (sort keys %$series_alpha_movies) {
my $class = number_of_columns(3, scalar @{$series_alpha_movies->{$series_alpha}}, 1);
section(3, sub {
list(5, 'u', file_menu('series', [sort { article_sort($a, $b) } @{$series_alpha_movies->{$series_alpha}}]), { 'class' => $class, 'style' => 'font-size:smaller' });
nav(5, "$series_alpha_menu", { 'class' => 'alpha_menu' });
}, { 'heading' => [2, $series_alpha, { 'id' => "section_$series_alpha" }] });
}
}
}
elsif ( length $genre_list ) {
if ($genre_select->{$genre_list}) {
section(3, sub {
my @subgenres = (sort grep(!/main/, keys %{$genre_select->{$genre_list}}));
unshift @subgenres, 'main' if $genre_select->{$genre_list}{'main'};
for my $subgenre (@subgenres) {
my @movies = map { display_simple_movie(movie($_)) } sort { article_sort(lc $a, lc $b) } @{$genre_select->{$genre_list}{$subgenre}};
my $class = scalar(@movies) > 72 ? 'three' : scalar(@movies) > 36 ? 'two' : 'one';
my $style = $class eq 'three' ? 'font-size:smaller' : undef;
section(4, sub {
my $genre = $subgenre ne 'main' ? $subgenre : $genre_list;
paragraph(6, "This is a list of $genre movies I have gathered.");
list(6, 'u', \@movies, { 'class' => $class, 'style' => $style });
}, { 'heading' => $subgenre ne 'main' ? [3, ucfirst $subgenre] : undef });
}
});
section(3, sub {
my $list = [
map { anchor(ucfirst $_, { 'href' => "?genre+list=$_" }) }
sort
grep { !/$genre_list/ } keys %$genre_select
];
list(5, 'u', $list, { 'class' => 'four' });
}, { 'heading' => [2, 'Other genres'] });
}
else {
my $genre_map = anchor('genre map', { href => '../Miscellany/index.pl?select=Genre+map' });
section(3, sub {
paragraph(6, "Click a genre to see a list of movies. There is a $genre_map to see how the genres are connected.");
list(5, 'u', $genre_link_list, { 'class' => 'four' });
});
}
}
elsif ( ( length $opinions && $opinions =~ /^[ryt1]/i ) || ( length $select && $select eq 'Movie opinions' ) ) {
story('file' => "$text_directory/Movie_opinions.txt", 'magic' => { 'doc magic' => $magic, 'line magic' => $magic });
}
else {
story('file' => "$text_directory/index.txt", 'magic' => { 'doc magic' => $magic, 'line magic' => $magic });
}
});