123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503 |
- use strict;
- use v5.10;
- use utf8;
- AddModuleDescription('hibernal.pl', 'Hibernal Extension');
- our ($q, $bol, %Action, %Page, $OpenPageName, %IndexHash, $Now, $Today, %RuleOrder, @MyRules, @MyInitVariables, $CommentsPrefix, $DeletedPage, $CalAsTable);
- our ($HibernalTitleOrSubtitleSuffix,
- $HibernalArchiveTitleOrSubtitleSuffix,
- $HibernalNewPostLinkText,
- $HibernalNewerPostsLinkText,
- $HibernalOlderPostsLinkText,
- $HibernalArchiveLinkText,
- $HibernalArchiveYearLinkText,
- $HibernalPostCommentLinkText,
- $HibernalPostCommentsLinkText,
- $HibernalPostCommentsCreateLinkText,
- $HibernalPostCommentsDemarcatorMarkup,
- $HibernalPostCommentsAuthorshipMarkup,
- $HibernalDefaultPostNameRegexp,
- $HibernalDefaultPostsPerPage, $HibernalMaximumPostsPerPage,
- $HibernalDefaultTitle, $HibernalDefaultSubtitle,
- $HibernalDefaultArchiveTitle, $HibernalDefaultArchiveSubtitle,
- $HibernalIsCurrentlyPrinting,
- $HibernalDefaultDateRegexp);
- $HibernalTitleOrSubtitleSuffix = ' ~ Posts %s — %s';
- $HibernalArchiveTitleOrSubtitleSuffix = ' ~ Posts for %s';
- $HibernalNewPostLinkText = 'New post';
- $HibernalOlderPostsLinkText = 'Older posts...';
- $HibernalNewerPostsLinkText = 'Newer posts...';
- $HibernalArchiveLinkText = 'Posts archive!';
- $HibernalArchiveYearLinkText = '%s...';
- $HibernalPostCommentLinkText = 'Add a comment...';
- $HibernalPostCommentsLinkText = 'Comments';
- $HibernalPostCommentsCreateLinkText = 'Comment on this post';
- $HibernalPostCommentsDemarcatorMarkup = qq`----\n`;
- $HibernalPostCommentsAuthorshipMarkup = undef;
- $HibernalDefaultPostNameRegexp = '^\d\d\d\d-\d\d-\d\d';
- $HibernalDefaultPostsPerPage = 8;
- $HibernalMaximumPostsPerPage = 16;
- $HibernalDefaultTitle = 'Blog';
- $HibernalDefaultSubtitle = '';
- $HibernalDefaultArchiveTitle = 'Blog Archive';
- $HibernalDefaultArchiveSubtitle = '';
- my ($second_now, $minute_now, $hour_now, $day_now, $month_now, $year_now,
- $is_calendar_installed,
- $is_creoleaddition_installed,
- $is_smarttitles_installed);
- push(@MyInitVariables, \&HibernalInit);
- sub HibernalInit {
-
- ($second_now, $minute_now, $hour_now, $day_now, $month_now, $year_now) =
- localtime($Now);
- $month_now += 1;
- $year_now += 1900;
-
-
- $is_calendar_installed = defined &draw_month;
- $is_smarttitles_installed = defined &GetSmartTitles;
-
- $Action{hibernal} = \&DoHibernal;
- $Action{hibernal_archive} = \&DoHibernalArchive if $is_calendar_installed;
-
-
-
-
-
-
-
- *GetHibernalHeaderOld = \&GetHeader;
- *GetHeader = \&GetHibernalHeader;
-
-
- if (not defined $HibernalPostCommentsAuthorshipMarkup) {
- if (defined &CreoleAdditionRule) {
- $HibernalPostCommentsAuthorshipMarkup = qq`\n\n"""\n**%s.** %s.\n"""`;
- }
- elsif (defined &CreoleRule) {
- $HibernalPostCommentsAuthorshipMarkup = qq`\n\n|**%s.** %s.|`;
- }
- elsif (defined &UsemodRule) {
- $HibernalPostCommentsAuthorshipMarkup = qq`\n\n||''%s.'' %s.||`;
- }
- elsif (defined &MarkupRule) {
- $HibernalPostCommentsAuthorshipMarkup = qq`\n\n⇒ //**%s.** %s.//`;
- }
- else {
- $HibernalPostCommentsAuthorshipMarkup = qq`\n\n⇒ %s. %s.`;
- }
- }
- }
- push(@MyRules, \&HibernalRule);
- $RuleOrder{\&HibernalRule} = -32;
- sub HibernalRule {
-
- if ($bol &&
- m~\G(\<hibernal
- (\s+(?:post_names\s*=\s*)?"(.+?)")?
- (\s+(?:post_bodies\s*=\s*)?"(.+?)")?
- (\s+(?:posts_start_at\s*=\s*)?"?(\d+)"?)?
- (\s+(?:posts_per_page\s*=\s*)?"?(\d+)"?)?
- (\s+(?:posts_ordering\s*=\s*)?"?(reverse|past|future)"?)?
- \>[ \t]*\n?)~cgix) {
- Clean(CloseHtmlEnvironments());
- Dirty($1);
- my ($oldpos, $old_) = (pos, $_);
- PrintHibernal($3, $5, $7, $9, $11);
- Clean(AddHtmlEnvironment('p'));
- ($_, pos) = ($old_, $oldpos);
- return '';
- }
- return;
- }
- *AddComment = \&AddHibernalComment;
- sub AddHibernalComment {
- my ($comments, $comment) = @_;
- $comment =~ s~\r~~g;
- $comment =~ s~\s+$~~gs;
- if ($comment) {
- my $author = GetParam('username', T('Anonymous'));
- my $homepage = GetParam('homepage', '');
- if ($homepage) {
- $homepage = "http://$homepage" if not substr($homepage, 0, 7) eq 'http://';
- $author = "[[$homepage|$author]]";
- }
- else {
- my $author_page_name = FreeToNormal($author);
- if ($IndexHash{$author_page_name}) {
- $author = $author_page_name eq $author
- ? "[[$author_page_name]]"
- : "[[$author_page_name|$author]]";
- }
- }
-
-
- if ($comments and $comments =~ m~\S~) {
- $comments .= $HibernalPostCommentsDemarcatorMarkup;
- }
-
- $comments .= $comment.
- Tss($HibernalPostCommentsAuthorshipMarkup, $author, TimeToText($Now));
- }
- return $comments;
- }
- my ($page_title, $page_subtitle);
- sub GetHibernalHeader {
- my $html_header = GetHibernalHeaderOld(@_);
- (undef, $page_title) = $html_header =~ m~\Q<h1>\E(<a.*>)?(.+?)(</a>)?\Q</h1>\E~;
- ($page_subtitle) = $html_header =~ m~\Q<p class="subtitle">\E(.+?)\Q</p>\E~;
- return $html_header;
- }
- =head2 PrintHibernalHeader
- Prints the title and subtitle for other hibernal and hibernal archive pages.
- (This does not print the title or subtitle for the hibernal front page, as
- that's embedded in the physical markup for that page.)
- =cut
- sub PrintHibernalHeader {
- my ($page_title_default, $page_subtitle_default, $suffix) = @_;
- $page_title = GetParam('title', $page_title_default);
- $page_subtitle = GetParam('subtitle', $page_subtitle_default);
- # Avoid tainting the $page_title and $page_subtitle globals with the suffix.
- my ($page_title_suffixed, $page_subtitle_suffixed) =
- ($page_title, $page_subtitle);
- if ($is_smarttitles_installed and $page_subtitle) {
- $page_subtitle_suffixed .= $suffix;
- }
- else {
- $page_title_suffixed .= $suffix;
- }
- # Note: we musn't call "GetHibernalHeader", as that could, conceivably, record
- # the suffix for this page's title or subtitle within the string for
- # that title or subtitle - which, in recursive turn, would badly cause
- # that suffix to be appended to the "next" page's title or subtitle,
- # again. (Good grief, eh? There's little relief, here, for insanity...)
- print GetHibernalHeaderOld(undef, $page_title_suffixed, undef, undef, undef,
- undef, $page_subtitle_suffixed);
- }
- # ....................{ HIBERNAL }....................
- =head2 DoHibernal
- Prints all blog posts matched by the passed regular expression and limit bounds.
- =cut
- sub DoHibernal {
- my $post_name_regexp = GetParam('post_name_regexp', $HibernalDefaultPostNameRegexp);
- my $post_body_regexp = GetParam('post_body_regexp', '');
- my $posts_start_at = GetParam('posts_start_at', 0);
- my $posts_per_page = GetParam('posts_per_page', $HibernalDefaultPostsPerPage);
- my $posts_ordering = GetParam('posts_ordering', '');
- PrintHibernalHeader(T($HibernalDefaultTitle),
- T($HibernalDefaultSubtitle),
- Tss($HibernalTitleOrSubtitleSuffix,
- $posts_start_at,
- $posts_start_at + $posts_per_page - 1));
- print $q->start_div({-class=> 'content'});
- PrintHibernal($post_name_regexp, $post_body_regexp,
- $posts_start_at, $posts_per_page, $posts_ordering);
- print $q->end_div();
- PrintFooter();
- }
- =head2 PrintHibernal
- Prints all blog posts for the current set of blog posts, followed by a
- set of links for navigating, managing, and otherwise munging those entries.
- =cut
- sub PrintHibernal {
- return if $HibernalIsCurrentlyPrinting; # avoid infinite loops
- local $HibernalIsCurrentlyPrinting = 1;
- my ($post_name_regexp, $post_body_regexp,
- $posts_start_at, $posts_per_page, $posts_ordering) = @_;
- # As this function may, also, be called by HibernalRule(), we must establish
- # some decent defaults.
- $post_name_regexp = $HibernalDefaultPostNameRegexp unless $post_name_regexp;
- $posts_start_at = 0 unless $posts_start_at;
- $posts_per_page = $HibernalDefaultPostsPerPage unless $posts_per_page > 0;
- $posts_per_page = $HibernalMaximumPostsPerPage unless $posts_per_page <=
- $HibernalMaximumPostsPerPage;
- # Implicitly ensure the regular expression also includes comments on all
- # pages matched by this regular expression.
- if ($post_name_regexp !~ m~^\Q^($CommentsPrefix)?\E~ and not
- $post_name_regexp =~ s~^\^~^($CommentsPrefix)?~) {
- $post_name_regexp = "^($CommentsPrefix)?.*$post_name_regexp";
- }
- my @post_names =
- sort SortHibernalPostNames ( # passes, not calls, SortHibernalPostNames()
- grep(/$post_name_regexp/, $post_body_regexp
- ? SearchTitleAndBody($post_body_regexp)
- : AllPagesList()));
- $posts_ordering and OrderHibernalPostNames(\@post_names, $posts_ordering);
- if (defined $post_names[$posts_start_at]) {
- my $posts_end_at;
-
-
- if ($CommentsPrefix) {
- ($posts_start_at, $posts_end_at) = AssayHibernalPostBounds(\@post_names,
- $posts_start_at, $posts_end_at, $posts_per_page);
- }
-
-
- else {
- $posts_end_at = Max($posts_start_at + $posts_per_page - 1, $#post_names);
- }
-
- my $is_older_posts = $#post_names > $posts_end_at;
- @post_names = @post_names[$posts_start_at..$posts_end_at];
-
-
-
- @post_names and PrintHibernalContent(\@post_names,
- $post_name_regexp, $post_body_regexp,
- $posts_start_at, $posts_end_at, $posts_per_page,
- $posts_ordering, $is_older_posts);
- }
- }
- sub SortHibernalPostNames {
- my ($A, $B) = ($a, $b);
- $A .= 'z' unless $A =~ s/^$CommentsPrefix//;
- $B .= 'z' unless $B =~ s/^$CommentsPrefix//;
- $B cmp $A;
- }
- sub OrderHibernalPostNames {
- my ($post_names, $posts_ordering) = @_;
- if ($posts_ordering eq 'future' or $posts_ordering eq 'reverse') {
- @$post_names = reverse @$post_names;
- }
-
- if ($posts_ordering eq 'future' or $posts_ordering eq 'past') {
- $b = defined($Today) ? $Today : CalcDay($Now);
- if ($posts_ordering eq 'future') {
- for (my $i = 0; $i < @$post_names; $i++) {
- $a = $$post_names[$i];
- if (SortHibernalPostNames() == -1) {
- @$post_names = @$post_names[$i..$#$post_names];
- last;
- }
- }
- }
- else {
- for (my $i = 0; $i < @$post_names; $i++) {
- $a = $$post_names[$i];
- if (SortHibernalPostNames() == 1) {
- @$post_names = @$post_names[$i..$#$post_names];
- last;
- }
- }
- }
- }
- }
- sub AssayHibernalPostBounds {
- my ($post_names, $posts_start_at, $posts_end_at, $posts_per_page) = @_;
- my $posts_sans_comments;
- my $posts_end_at_max =
- Max($posts_start_at + $posts_per_page*2 - 1, $#$post_names);
-
-
- for ($posts_sans_comments = 0,
- $posts_end_at = $posts_start_at - 1,
- my $post_index = $posts_start_at;
- $post_index <= $posts_end_at_max;
- $post_index++, $posts_end_at++) {
- if ($$post_names[$post_index] =~ m~^$CommentsPrefix~) {
-
-
-
-
-
-
-
- $posts_start_at++ if $post_index == $posts_start_at;
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- elsif ($posts_sans_comments++ == $posts_per_page) { last; }
- }
- return ($posts_start_at, $posts_end_at);
- }
- sub AssayHibernalPostBoundsForNewerPosts {
- my ($post_names, $posts_start_at, $posts_end_at, $posts_per_page) = @_;
- my $posts_start_at_newer = Max(0,
- GetParam('posts_start_at_newer', $posts_start_at - $posts_per_page));
- return ($posts_start_at_newer, $posts_start_at - 1);
- }
- sub PrintHibernalContent {
- my ($post_names, $post_name_regexp, $post_body_regexp,
- $posts_start_at, $posts_end_at, $posts_per_page,
- $posts_ordering, $is_older_posts) = @_;
-
- local %Page;
- local $OpenPageName = '';
- print $q->start_div({-class=> 'hibernal'});
- PrintHibernalPosts($post_names);
- PrintHibernalNav (@_);
- print $q->end_div();
- }
- sub PrintHibernalPosts {
- my $post_names = shift;
- my $lang = GetParam('lang', 0);
- my ($post_title, $post_subtitle);
- my ($prior_post_name, $is_prior_post_commented_on) = ('', 1);
- print $q->start_div({-class=> 'posts'});
- for my $post_name (@$post_names) {
- OpenPage($post_name);
- my @languages = split(/,/, $Page{languages});
-
-
- next if
- ($lang and @languages and not grep(/$lang/, @languages)) or
- ($Page{text} =~ m~^$DeletedPage~);
-
- if ($post_name =~ m~^$CommentsPrefix~) {
- $is_prior_post_commented_on = 1;
- print
- $q->start_div({-class=> 'post_comments'})
- .$q->div ({-class=> 'post_comments_header'},
- GetPageLink($post_name,
- Ts($HibernalPostCommentsLinkText)))
- .$q->start_div({-class=> 'post_comments_body hibernal_include'});
- PrintPageHtml();
- print $q->end_div().$q->end_div();
- }
-
- else {
- ($post_title, $post_subtitle) = $is_smarttitles_installed
- ? GetSmartTitles()
- : (NormalToFree($post_name), '');
- PrintHibernalPostCommentsCreateLink($prior_post_name, $is_prior_post_commented_on);
- $is_prior_post_commented_on = '';
- print
- $q->start_div({-class=> 'post'})
- .$q->div({-class=> 'post_header'},
- $q->h1(GetPageLink($post_name, $post_title))
- .($post_subtitle
- ? $q->p({-class=> 'subtitle'}, $post_subtitle) : ''))
- .$q->start_div({-class=> 'post_body hibernal_include'});
- PrintPageHtml();
- print $q->end_div().$q->end_div();
- }
-
- $prior_post_name = $post_name;
- }
-
-
- $prior_post_name and
- PrintHibernalPostCommentsCreateLink($prior_post_name, $is_prior_post_commented_on);
- print $q->end_div();
- }
- sub PrintHibernalPostCommentsCreateLink {
- my ($prior_post_name, $is_prior_post_commented_on) = @_;
- print $q->div({-class=> 'post_comments'},
- $q->div({-class=> 'post_comments_header'},
- GetPageLink($CommentsPrefix.$prior_post_name,
- Ts($HibernalPostCommentsCreateLinkText))))
- if $CommentsPrefix and $prior_post_name and not $is_prior_post_commented_on;
- }
- sub PrintHibernalNav {
- my ($post_names, $post_name_regexp, $post_body_regexp,
- $posts_start_at, $posts_end_at, $posts_per_page,
- $posts_ordering, $is_older_posts) = @_;
- my $post_name_regexp_sans_comments =
- GetHibernalCommentlessPostNameRegexp($post_name_regexp);
- my $hibernal_action = "action=hibernal"
- .";post_name_regexp=$post_name_regexp"
- .";post_body_regexp=$post_body_regexp"
- .";posts_ordering=$posts_ordering";
- my $hibernal_archive_action = "action=hibernal_archive"
- .";post_name_regexp=$post_name_regexp_sans_comments";
- my $action_suffix = '';
-
- if ($page_title ) { $action_suffix .= ';title='. $page_title; }
- if ($page_subtitle) { $action_suffix .= ';subtitle='.$page_subtitle; }
- $hibernal_action .= $action_suffix;
- $hibernal_archive_action .= $action_suffix;
- my ($older_posts_link_text, $newer_posts_link_text);
- if ($posts_ordering eq 'future' or $posts_ordering eq 'reverse') {
- $newer_posts_link_text = $HibernalOlderPostsLinkText;
- $older_posts_link_text = $HibernalNewerPostsLinkText;
- }
- else {
- $newer_posts_link_text = $HibernalNewerPostsLinkText;
- $older_posts_link_text = $HibernalOlderPostsLinkText;
- }
- print $q->start_div({-class=> 'nav'});
-
-
- my $new_post_name =
- GetHibernalDaySpecificPostName($post_name_regexp_sans_comments);
- if (UserCanEdit($new_post_name, 0)) {
- print GetEditLink($new_post_name, T($HibernalNewPostLinkText), undef, T('e'));
- }
-
- if ( $posts_start_at > 0) {
- my ($posts_start_at_newer, $posts_end_at_newer) =
- AssayHibernalPostBoundsForNewerPosts($post_names,
- $posts_start_at, $posts_end_at, $posts_per_page);
- print ScriptLink($hibernal_action
- .";posts_start_at=$posts_start_at_newer"
- .";posts_per_page=$posts_per_page",
- T($newer_posts_link_text));
- }
-
-
-
-
-
-
- if ($is_older_posts) {
- print ScriptLink($hibernal_action
- .";posts_start_at_newer=$posts_start_at"
- .";posts_start_at=".($posts_end_at + 1)
- .";posts_per_page=$posts_per_page",
- T($older_posts_link_text));
- }
-
- if ($is_calendar_installed) {
- print ScriptLink($hibernal_archive_action, T($HibernalArchiveLinkText));
- }
- print $q->end_div();
- }
- sub DoHibernalArchive {
- my $post_name_regexp = GetParam('post_name_regexp', $HibernalDefaultDateRegexp);
- my $year = GetParam('year', $year_now);
- PrintHibernalHeader(T($HibernalDefaultArchiveTitle),
- T($HibernalDefaultArchiveSubtitle),
- Ts($HibernalArchiveTitleOrSubtitleSuffix, $year));
- print $q->start_div({-class=> 'content'});
- PrintHibernalArchive($post_name_regexp, $year);
- print $q->end_div();
- PrintFooter();
- }
- sub PrintHibernalArchive {
- my ($post_name_regexp, $year) = @_;
-
-
-
- $post_name_regexp = GetHibernalCommentlessPostNameRegexp($post_name_regexp);
- print $q->start_div({-class=> 'hibernal_archive cal'});
- PrintHibernalArchiveNav ($post_name_regexp, $year);
- PrintHibernalArchiveYear($post_name_regexp, $year);
- print $q->end_div();
- }
- sub PrintHibernalArchiveNav {
- my ($post_name_regexp, $year) = @_;
- my @post_names = AllPagesList();
- my %matching_years;
- my $match_year_regexp = $post_name_regexp;
- $match_year_regexp =~ s~(\Q\d\d\d\d\E)~($1)~;
- foreach my $post_name (@post_names) {
- if ($post_name =~ m~$match_year_regexp~) { $matching_years{$1} = 1; }
- }
- print $q->start_div({-class=> 'nav'});
- my $hibernal_archive_action =
- "action=hibernal_archive;post_name_regexp=$post_name_regexp";
-
- if ($page_title ) { $hibernal_archive_action .= ';title='. $page_title; }
- if ($page_subtitle) { $hibernal_archive_action .= ';subtitle='.$page_subtitle; }
- foreach my $matching_year (sort keys %matching_years) {
- print ScriptLink($hibernal_archive_action.";year=$matching_year",
- Ts($HibernalArchiveYearLinkText, $matching_year));
- }
- print $q->end_div();
- }
- sub PrintHibernalArchiveYear {
- my ($post_name_regexp, $year) = @_;
- print $q->start_div({-class=> 'year'});
- if ($CalAsTable) {
- print '<table><tr>';
- for my $month (1..12) {
- print '<td>' . GetHibernalArchiveMonth($post_name_regexp, $year, $month) . '</td>';
-
- print '</tr><tr>' if $month == 3 or $month == 6 or $month == 9;
- }
- print '</tr></table>';
- }
- else {
- for my $month (1..12) {
- print GetHibernalArchiveMonth($post_name_regexp, $year, $month);
- }
- }
-
-
-
-
-
- print $q->div({-class=> 'year_end', -style=> 'clear: left'})
- .$q->end_div();
- }
- sub GetHibernalArchiveMonth {
- my ($post_name_regexp, $year, $month) = @_;
-
- if ($year < 1) { return $q->p(T('Illegal year value: Use 0001-9999')); }
- my $html_month = draw_month($month, $year).'</div>';
-
- $html_month =~ s~\s*(\S+) \d\d\d\d\n(.+?\n)~
- GetHibernalArchiveMonthHeader($year, $month, $1, $2)
- ~e;
- $html_month =~ s~( {1,2})(\d{1,2})\b~
- $1.GetHibernalArchiveMonthDay($post_name_regexp, $year, $month, $2)
- ~eg;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- return $q->div({-class=> 'month', -style=> 'float: left'}, $html_month);
- }
- sub GetHibernalArchiveMonthHeader {
- my ($year, $month, $month_text, $day_labels) = @_;
- my $date = sprintf('%d-%02d', $year, $month);
- return
- $q->div({-class=> 'month_header'},
- ScriptLink("action=collect;match=%5e$date",
- "$month_text $year",
- 'local collection month'))
- .$q->start_div({-class=> 'month_body'})
- .$q->span({-class=> 'day_labels'}, $day_labels);
- }
- sub GetHibernalArchiveMonthDay {
- my ($post_name_regexp, $year, $month, $day) = @_;
- my $class = $day == $day_now && $month == $month_now && $year == $year_now
- ? ' today'
- : ''
- ;
- $post_name_regexp = GetHibernalDaySpecificPostNameRegexp(@_);
- my @post_name_matches = grep(/$post_name_regexp/, AllPagesList());
- if (@post_name_matches == 0) {
- return ScriptLink('action=edit;id='.UrlEncode(GetHibernalDaySpecificPostName(@_)),
- $day, 'edit'.$class);
- }
- elsif (@post_name_matches == 1) {
- return ScriptLink($post_name_matches[0],
- $day, 'local exact'.$class);
- }
- else {
- return ScriptLink('action=collect;match='.UrlEncode($post_name_regexp),
- $day, 'local collection'.$class);
- }
- }
- sub Tss {
- my $format_string = shift;
- my @format_variables = @_;
- $format_string = Ts($format_string, $_) foreach (@format_variables);
- return $format_string;
- }
- sub Max {
- my ($x, $y) = @_;
- return $x >= $y ? $x : $y;
- }
- sub GetHibernalDaySpecificPostName {
- my $post_name = GetHibernalDaySpecificPostNameRegexp(@_);
- $post_name =~ s~^\^~~;
- $post_name =~ s~\$$~~;
- return $post_name;
- }
- sub GetHibernalDaySpecificPostNameRegexp {
- my ($post_name_regexp, $year, $month, $day) = @_;
- $year = $year_now unless $year;
- $month = $month_now unless $month;
- $day = $day_now unless $day;
- my ($date_regexp) = $post_name_regexp =~ m~(\\d\\d(?:\\d|-)+)~;
- if ($date_regexp) {
- if ($date_regexp eq '\d\d\d\d-\d\d-\d\d') {
- $post_name_regexp =~
- s~\Q$date_regexp\E~sprintf('%d-%02d-%02d', $year, $month, $day)~e;
- }
- elsif ($date_regexp eq '\d\d-\d\d-\d\d\d\d') {
- $post_name_regexp =~
- s~\Q$date_regexp\E~sprintf('%02d-%02d-%d', $day, $month, $year)~e;
- }
- else { undef $date_regexp; }
- }
-
-
- if (not $date_regexp) {
- $post_name_regexp =~ s/\Q\d\d\d\d\E/$year/;
- $post_name_regexp =~ s/\Q\d\d\E/sprintf('%02d', $month)/e;
- $post_name_regexp =~ s/\Q\d\d\E/sprintf('%02d', $day)/e;
- }
- return $post_name_regexp;
- }
- sub GetHibernalCommentlessPostNameRegexp {
- my $post_name_regexp = shift;
- $post_name_regexp =~ s~^\Q^($CommentsPrefix)?\E~^~ if $CommentsPrefix;
- return $post_name_regexp;
- }
|