weblog-4.pl 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # Copyright (C) 2006–2014 Alex Schroeder <alex@gnu.org>
  2. #
  3. # This program is free software: you can redistribute it and/or modify it under
  4. # the terms of the GNU General Public License as published by the Free Software
  5. # Foundation, either version 3 of the License, or (at your option) any later
  6. # version.
  7. #
  8. # This program is distributed in the hope that it will be useful, but WITHOUT
  9. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  10. # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  11. #
  12. # You should have received a copy of the GNU General Public License along with
  13. # this program. If not, see <http://www.gnu.org/licenses/>.
  14. use strict;
  15. use v5.10;
  16. AddModuleDescription('weblog-4.pl', 'Blogging With Tags');
  17. our ($q, %Action, %Page, $OpenPageName, $HomePage, $ScriptName, @MyInitVariables, @MyAdminCode, $SearchFreeTextTagUrl);
  18. push(@MyInitVariables, sub {
  19. $SearchFreeTextTagUrl = $ScriptName . '?action=browse;tag=1;id=';
  20. });
  21. push(@MyAdminCode, \&BlogMenu);
  22. sub BlogMenu {
  23. my ($id, $menuref, $restref) = @_;
  24. push(@$menuref, ScriptLink('action=new', T('New'), 'new'));
  25. }
  26. # Default page content copied from weblog-3.pl.
  27. *BlogOldOpenPage = \&OpenPage;
  28. *OpenPage = \&BlogNewOpenPage;
  29. sub BlogNewOpenPage {
  30. BlogOldOpenPage(@_);
  31. if ($Page{revision} == 0) {
  32. if ($OpenPageName eq $HomePage) {
  33. $Page{text} = '<journal>';
  34. } elsif (GetParam('tag','')) {
  35. # if the page is either on the categories page, or the tag=1
  36. # parameter was added, show a journal
  37. $Page{text} = T('Matching pages:')
  38. . "\n\n<journal search tag:$OpenPageName>";
  39. }
  40. }
  41. }
  42. # New Action
  43. $Action{new} = \&DoNewPage;
  44. sub DoNewPage {
  45. if (GetParam('tags', '') and GetParam('id', '')) {
  46. DoEdit(GetParam('id', ''), "\n\n\nTags: "
  47. . join (' ', map { "[[tag:$_]]" } split(' ', GetParam('tags', ''))),
  48. 1);
  49. } else {
  50. print GetHeader('', T('New')), $q->start_div({-class=>'content new'}),
  51. GetFormStart(undef, 'get', 'cat');
  52. my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) = gmtime();
  53. my $today = sprintf("%d-%02d-%02d", $year + 1900, $mon + 1, $mday);
  54. my $go = T('Go!');
  55. print $q->p(T('Title:') . ' '
  56. . qq{<input type="text" name="id" value="$today" tabindex="1" />},
  57. GetHiddenValue('action', 'new'));
  58. print $q->p(T('Tags:') . ' '
  59. . qq{<input type="text" name="tags" tabindex="2" />});
  60. print $q->p(qq{<input type="submit" value="$go" tabindex="3" />});
  61. print $q->end_form, $q->end_div();
  62. PrintFooter();
  63. }
  64. }