2015-07-28 22:44:53 +02:00
|
|
|
|
# Copyright (C) 2005–2014 Alex Schroeder <alex@gnu.org>
|
2005-09-04 23:39:07 +00:00
|
|
|
|
#
|
2011-12-31 00:27:33 +00:00
|
|
|
|
# This program is free software; you can redistribute it and/or modify it under
|
|
|
|
|
|
# the terms of the GNU General Public License as published by the Free Software
|
|
|
|
|
|
# Foundation; either version 3 of the License, or (at your option) any later
|
|
|
|
|
|
# version.
|
2005-09-04 23:39:07 +00:00
|
|
|
|
#
|
2011-12-31 00:27:33 +00:00
|
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
|
|
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
2005-09-04 23:39:07 +00:00
|
|
|
|
#
|
2011-12-31 00:27:33 +00:00
|
|
|
|
# You should have received a copy of the GNU General Public License along with
|
|
|
|
|
|
# this program. If not, see <http://www.gnu.org/licenses/>.
|
2005-09-04 23:39:07 +00:00
|
|
|
|
|
2015-03-29 23:46:26 +02:00
|
|
|
|
use strict;
|
2015-08-18 10:48:03 +02:00
|
|
|
|
use v5.10;
|
2015-03-27 03:01:01 +02:00
|
|
|
|
|
2014-08-21 22:23:23 +02:00
|
|
|
|
AddModuleDescription('weblog-3.pl', 'Create a Blog Front Page');
|
2005-09-04 23:39:07 +00:00
|
|
|
|
|
|
|
|
|
|
# Categories
|
|
|
|
|
|
|
2015-07-03 11:57:29 +02:00
|
|
|
|
our ($q, %Action, %Page, $OpenPageName, $HomePage, $ScriptName, @MyInitVariables, $FreeLinkPattern, $UserGotoBar, @UserGotoBarPages, $UsePathInfo);
|
2015-04-10 13:31:28 +03:00
|
|
|
|
our ($CategoriesPage);
|
2011-12-31 01:40:26 +00:00
|
|
|
|
|
2005-09-04 23:39:07 +00:00
|
|
|
|
$CategoriesPage = 'Categories';
|
|
|
|
|
|
|
2015-04-11 23:41:33 +03:00
|
|
|
|
*CategoriesOldOpenPage = \&OpenPage;
|
|
|
|
|
|
*OpenPage = \&CategoriesNewOpenPage;
|
2005-09-04 23:39:07 +00:00
|
|
|
|
|
2011-12-31 01:40:26 +00:00
|
|
|
|
my %Category = (); # fast checking
|
|
|
|
|
|
my @Categories = (); # correct order
|
2015-03-30 00:47:12 +02:00
|
|
|
|
my $CategoryInit = 0;
|
2011-12-31 01:40:26 +00:00
|
|
|
|
|
2015-07-03 11:57:29 +02:00
|
|
|
|
*OldCategoriesNewText = \&NewText;
|
|
|
|
|
|
*NewText = \&NewCategoriesNewText;
|
2011-12-31 01:40:26 +00:00
|
|
|
|
|
2015-07-03 11:57:29 +02:00
|
|
|
|
sub NewCategoriesNewText {
|
|
|
|
|
|
my $id = shift;
|
|
|
|
|
|
if ($id eq $HomePage) {
|
|
|
|
|
|
return '<journal>';
|
|
|
|
|
|
} elsif (GetParam('tag','')
|
|
|
|
|
|
or $Category{$id}) {
|
|
|
|
|
|
# if the page is either on the categories page, or the tag=1
|
|
|
|
|
|
# parameter was added, show a journal
|
|
|
|
|
|
$Page{text} = T('Matching pages:')
|
|
|
|
|
|
. "\n\n"
|
|
|
|
|
|
. '<journal "^\d\d\d\d-\d\d-\d\d.*'
|
|
|
|
|
|
. $OpenPageName
|
|
|
|
|
|
. '">';
|
|
|
|
|
|
} else {
|
|
|
|
|
|
return OldCategoriesNewText($id, @_);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2005-09-04 23:39:07 +00:00
|
|
|
|
|
|
|
|
|
|
sub CategoriesNewOpenPage {
|
|
|
|
|
|
CategoryInit() unless $CategoryInit;
|
|
|
|
|
|
CategoriesOldOpenPage(@_);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2011-12-31 01:40:26 +00:00
|
|
|
|
# Category page
|
|
|
|
|
|
|
2011-12-31 00:27:33 +00:00
|
|
|
|
sub CategoryParse {
|
|
|
|
|
|
my @paragraphs = split(/\n\n+/, shift);
|
|
|
|
|
|
my @result;
|
2005-09-04 23:39:07 +00:00
|
|
|
|
foreach (@paragraphs) {
|
|
|
|
|
|
next unless /^\*/;
|
2011-12-31 00:27:33 +00:00
|
|
|
|
while (/\*+\s*\[\[$FreeLinkPattern\]\]/g) {
|
2005-09-07 19:47:30 +00:00
|
|
|
|
my $id = FreeToNormal($1);
|
2011-12-31 00:27:33 +00:00
|
|
|
|
push(@result, $id);
|
2005-09-04 23:39:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
last;
|
|
|
|
|
|
}
|
2011-12-31 00:27:33 +00:00
|
|
|
|
return @result;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub CategoryInit {
|
|
|
|
|
|
$CategoryInit = 1;
|
|
|
|
|
|
@Categories = CategoryParse(GetPageContent($CategoriesPage));
|
|
|
|
|
|
map { $Category{$_} = 1 } @Categories;
|
2005-09-04 23:39:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# New Action
|
|
|
|
|
|
|
|
|
|
|
|
$Action{new} = \&DoCategories;
|
|
|
|
|
|
|
|
|
|
|
|
sub DoCategories {
|
2005-09-07 19:47:30 +00:00
|
|
|
|
print GetHeader('', T('New')), $q->start_div({-class=>'content categories'}),
|
|
|
|
|
|
GetFormStart(undef, 'get', 'cat');
|
2005-09-04 23:39:07 +00:00
|
|
|
|
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) = gmtime();
|
|
|
|
|
|
my $today = sprintf("%d-%02d-%02d", $year + 1900, $mon + 1, $mday);
|
|
|
|
|
|
CategoryInit() unless $CategoryInit;
|
2005-09-04 23:59:52 +00:00
|
|
|
|
print $q->p({-class=>'table'}, map {GetEditLink("$today $_", $_)} @Categories);
|
2005-10-01 22:54:09 +00:00
|
|
|
|
print $q->p($q->textfield('id', $today), GetHiddenValue('action', 'edit'));
|
2005-09-04 23:39:07 +00:00
|
|
|
|
print $q->p(Ts('Edit %s.', GetPageLink($CategoriesPage)));
|
|
|
|
|
|
print $q->submit("Go!");
|
|
|
|
|
|
print $q->end_form, $q->end_div();
|
|
|
|
|
|
PrintFooter();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2011-12-31 01:40:26 +00:00
|
|
|
|
# Goto Bar
|
|
|
|
|
|
|
2005-09-04 23:39:07 +00:00
|
|
|
|
my $GotoBarInit = 0;
|
|
|
|
|
|
|
|
|
|
|
|
sub GotoBarInit {
|
|
|
|
|
|
$GotoBarInit = 1;
|
2011-12-31 00:27:33 +00:00
|
|
|
|
@UserGotoBarPages = (@UserGotoBarPages,
|
|
|
|
|
|
CategoryParse(GetPageContent($HomePage)));
|
2005-09-04 23:39:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2011-12-31 01:40:26 +00:00
|
|
|
|
*GetGotoBar = * NewGetGotoBar;
|
|
|
|
|
|
|
2005-09-04 23:39:07 +00:00
|
|
|
|
sub NewGetGotoBar {
|
|
|
|
|
|
my $id = shift;
|
|
|
|
|
|
GotoBarInit() unless $GotoBarInit;
|
|
|
|
|
|
my @links;
|
|
|
|
|
|
foreach my $name (@UserGotoBarPages) {
|
2005-09-05 20:03:55 +00:00
|
|
|
|
push (@links, GetPageLink($name, $name));
|
2005-09-04 23:39:07 +00:00
|
|
|
|
}
|
2005-09-04 23:59:52 +00:00
|
|
|
|
my @parts = split(/_/, GetId());
|
2005-09-07 19:47:30 +00:00
|
|
|
|
CategoryInit() unless $CategoryInit;
|
2005-09-04 23:59:52 +00:00
|
|
|
|
if ($parts[0] =~ /\d\d\d\d-\d\d-\d\d/) {
|
|
|
|
|
|
shift(@parts);
|
2005-09-07 19:47:30 +00:00
|
|
|
|
push(@links, map {
|
|
|
|
|
|
if ($Category{$_}) {
|
|
|
|
|
|
$q->a({-href=>$ScriptName . ($UsePathInfo ? '/' : '?') . UrlEncode($_),
|
|
|
|
|
|
-class=>'local tag',
|
|
|
|
|
|
-rel=>'tag'}, $_);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
# provide tag=1 parameter to tell OpenPage to add journal tag
|
|
|
|
|
|
$q->a({-href=>$ScriptName . '?tag=1;action=browse;id=' . UrlEncode($_),
|
|
|
|
|
|
-class=>'local tag',
|
|
|
|
|
|
-rel=>'tag'}, $_);
|
|
|
|
|
|
}
|
|
|
|
|
|
} @parts);
|
2005-09-04 23:59:52 +00:00
|
|
|
|
}
|
2005-09-05 00:06:16 +00:00
|
|
|
|
push (@links, ScriptLink('action=new', T('New')));
|
2005-09-09 16:00:50 +00:00
|
|
|
|
return $q->span({-class=>'gotobar bar'}, @links, $UserGotoBar);
|
2005-09-04 23:39:07 +00:00
|
|
|
|
}
|