Almost-minimal filesystem based blog.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

867 lines
22 KiB

17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
17 years ago
  1. #!/usr/bin/perl
  2. =pod
  3. =head1 NAME
  4. Display - module to display fragments of text on the web and elsewhere
  5. =head1 SYNOPSIS
  6. #!/usr/bin/perl
  7. use Display qw(%WalaConf %DISPLAY_CONF &handle);
  8. do 'conf.pl' if -e 'conf.pl'; # grab config
  9. $WalaConf{'ShowSearchlinks'} = 0;
  10. print handle(@ARGV);
  11. =head1 DESCRIPTION
  12. Display started life as a simple script to concatenate fragments of handwritten
  13. HTML by date. It has since haphazardly accumulated several of the usual weblog
  14. features (comments, lightweight markup, feed generation, embedded Perl, poetry
  15. tools, ill-advised dependencies), but the basic idea hasn't changed much.
  16. The module will work with FastCGI, via CGI::Fast, if called from the
  17. appropriate wrapper script.
  18. Entries are stored in a simple directory tree under
  19. C<$DISPLAY_CONF{ROOT_DIR}>.
  20. Like:
  21. archives/2001/1/1
  22. archives/2001/1/1/sub_entry
  23. An entry may be either a plain text file, or a directory containing several
  24. such files + whatever else you'd like to store. If it's a directory, the file
  25. called "index" will be treated as the text of the entry, and all other lower
  26. case filenames without extensions will be treated as sub-entries or documents
  27. within that entry, and displayed accordingly.
  28. Directories may be nested to an arbitrary depth, though I don't promise that
  29. this won't break on you.
  30. A PNG or JPEG file with a name like
  31. 2001/1/1.icon.png
  32. 2001/1/1/index.icon.png
  33. 2001/1/1/whatever.icon.png
  34. will be treated as an icon for the appropriate entry file.
  35. =head2 MARKUP
  36. Entries may consist of hand-written HTML (to be passed along without further
  37. interpretation), a supported form of lightweight markup, or some combination
  38. thereof. Actually, an entry may consist of any darn thing you please, as long
  39. as Perl will agree that it is text, but presumably you're going to be feeding
  40. this to a browser.
  41. Special markup is indicated by a variety of XML-style container tags.
  42. B<Embedded Perl> - evaluated and replaced by whatever value you return
  43. (evaluated in a scalar context):
  44. <perl>my $dog = "Ralph."; return $dog;</perl>
  45. This code is evaluated before any other processing is done, so you can return
  46. any other markup understood by the script and have it handled appropriately.
  47. B<Interpolated variables> - actually keys to %TEMPLATE, for the moment:
  48. <perl>$TEMPLATE{dog} = "Ralph"; return '';</perl>
  49. <p>My dog is named ${dog}.</p>
  50. Embedded code and variables are mostly intended for use in F<header> and
  51. F<footer> files, where it's handy to drop in titles or conditionalize aspects
  52. of a layout. You want to be careful with this sort of thing - it's useful in
  53. small doses, but it's also a maintainability nightmare waiting to happen.
  54. (WordPress, I am looking at you.)
  55. B<Several forms of lightweight markup>:
  56. <wala>Wala::Markup, via Wala.pm - very basic wiki syntax</wala>
  57. <textile>Dean Allen's Textile, via Brad Choate's
  58. Text::Textile.</textile>
  59. <freeverse>An easy way to
  60. get properly broken lines
  61. -- en and em dashes ---
  62. for poetry and such.</freeverse>
  63. B<And a couple of shortcuts>:
  64. <image>filename.ext
  65. alt text, if any</image>
  66. <list>
  67. one list item
  68. another list item
  69. </list>
  70. As it stands, freeverse, image, and list are not particularly robust.
  71. =cut
  72. package Display;
  73. use strict;
  74. use warnings;
  75. no warnings 'uninitialized';
  76. BEGIN {
  77. use base qw(Exporter);
  78. our @EXPORT_OK = qw(%WalaConf %DISPLAY_CONF &handle);
  79. use XML::Atom::SimpleFeed;
  80. use Wala qw(%WalaConf %DISPLAY_CONF);
  81. use Display::HTML qw(:highlevel);
  82. use Display::Markup qw(line_parse);
  83. use Display::Image qw(image_size);
  84. }
  85. our @EXPORT_OK;
  86. ######################
  87. # DEFAULT OPTIONS #
  88. ######################
  89. %DISPLAY_CONF = (
  90. ROOT_DIR => 'archives', # root dir for archived files
  91. URL_ROOT => 'http://p1k3.com/', # root URL for building links
  92. IMAGE_URL_ROOT => 'http://p1k3.com/', # same for images
  93. HEADER => 'header',
  94. FOOTER => 'footer',
  95. );
  96. $WalaConf{'ShowSearchlinks'} = 0;
  97. =head1 SUBROUTINES
  98. For no bigger than this thing is, it gets a little convoluted.
  99. =over
  100. =item handle
  101. Handle a given request, either in the form of a CGI query object
  102. or a date/entry string.
  103. =cut
  104. sub handle {
  105. my (@options) = @_;
  106. my $output;
  107. # Get parameters from any CGI objects we've been given:
  108. @options = map { expand_query($_) } @options;
  109. # By default, we display the most recent month.
  110. $options[0] = 'new' unless $options[0];
  111. # Title for head/foot template:
  112. $DISPLAY_CONF{title} = join ' ', @options;
  113. # Maps 'all' and 'new' to appropriate entries:
  114. @options = map { expand_option($_) } @options;
  115. for my $o (@options) {
  116. return feed_print() if $o eq 'feed';
  117. $output .= output($o);
  118. }
  119. # Wrap entries in header/footer:
  120. $output = fragment_slurp($DISPLAY_CONF{HEADER})
  121. . $output
  122. . fragment_slurp($DISPLAY_CONF{FOOTER});
  123. return $output;
  124. }
  125. =item output
  126. Returns appropriate output for a given option.
  127. =cut
  128. sub output {
  129. my ($option) = @_;
  130. if ( $option =~ m'^[0-9/]{5,11}[a-z_/]+$' ) {
  131. # nnnn/[nn/nn/]doc_name
  132. # It's a document within a date.
  133. return entry_markup(entry_print($option) . datestamp($option));
  134. }
  135. elsif ( $option =~ m'^[0-9]{4}/[0-9]{1,2}/[0-9]{1,2}$' ) {
  136. # nnnn/nn/nn - A specific date. Print it in full.
  137. return entry_markup(entry_print($option, 'all') . datestamp($option));
  138. }
  139. elsif ( $option =~ m'^[0-9]{4}/[0-9]{1,2}$' ) {
  140. # nnnn/nn - It's a month. Print it.
  141. return month_print($option);
  142. }
  143. elsif ( $option =~ m'^[0-9]{4}$' ) {
  144. # nnnn - It's a year. Display a list of entries.
  145. return year_print($option);
  146. }
  147. elsif ($option eq 'portfolio') {
  148. return entry_print($option, 'all');
  149. }
  150. elsif ($option =~ m'^[a-z_]') {
  151. # Assume it's a document in the root directory.
  152. return entry_markup(entry_print($option, 'all'));
  153. }
  154. }
  155. =item expand_query
  156. Expands a CGI query (for example, one passed in from CGI::Fast) to an
  157. appropriate list of parameters.
  158. =cut
  159. sub expand_query {
  160. my ($option) = shift;
  161. if ( (ref($option) eq 'CGI::Fast') or (ref($option) eq 'CGI')) {
  162. return $option->param('keywords');
  163. } else {
  164. return $option;
  165. }
  166. }
  167. =item expand_option
  168. Expands/converts 'all' and 'new' to appropriate values.
  169. =cut
  170. sub expand_option {
  171. my ($option) = shift;
  172. # take care of trailing slashes
  173. chop ($option) if (substr($option, -1, 1) eq '/');
  174. if ($option eq 'all') {
  175. return dir_list($DISPLAY_CONF{ROOT_DIR}, 'high_to_low',
  176. qr/^[0-9]{1,4}$/);
  177. } elsif ($option eq 'new') {
  178. return recent_month();
  179. } else {
  180. return $option;
  181. }
  182. }
  183. =item recent_month
  184. Tries to find the most recent month in the archive.
  185. If a year file is text, returns that instead.
  186. =cut
  187. sub recent_month {
  188. my ($dir) = $DISPLAY_CONF{ROOT_DIR};
  189. # Below replaces:
  190. # my ($sec, $min, $hour, $mday, $mon,
  191. # $year, $wday, $yday, $isdst) = localtime(time);
  192. my ($mon, $year) = (localtime time)[4,5];
  193. $mon++;
  194. $year += 1900;
  195. if (-e "$dir/$year/$mon") {
  196. return "$year/$mon";
  197. }
  198. else {
  199. my @year_files = dir_list($dir, 'high_to_low', qr/^[0-9]{1,4}$/);
  200. if (-T "$dir/$year_files[0]") {
  201. return $year_files[0];
  202. }
  203. my @month_files = dir_list("$dir/$year_files[0]", 'high_to_low',
  204. qr/^[0-9]{1,2}$/);
  205. return "$year_files[0]/$month_files[0]";
  206. }
  207. }
  208. =item month_before
  209. Return the month before the given month in the archive.
  210. Very naive; there has got to be a smarter way.
  211. =cut
  212. { my %cache; # cheap memoization
  213. sub month_before {
  214. my ($this_month) = @_;
  215. if (exists $cache{$this_month}) {
  216. return $cache{$this_month};
  217. }
  218. my ($year, $month) = ( $this_month =~ m/^ # start of string
  219. ([0-9]{4}) # 4 digit year
  220. \/ #
  221. ([0-9]{1,2}) # 2 digit month
  222. /x );
  223. if ($month == 1) {
  224. $month = 12;
  225. $year = $year - 1;
  226. } else {
  227. $month--;
  228. }
  229. until (-e "$DISPLAY_CONF{ROOT_DIR}/$year/$month") {
  230. if (! -d "$DISPLAY_CONF{ROOT_DIR}/$year") {
  231. # give up easily
  232. return 0;
  233. }
  234. # handle January:
  235. if ($month == 1) {
  236. $month = 12;
  237. $year--;
  238. next;
  239. }
  240. $month--;
  241. }
  242. return $cache{$this_month} = "$year/$month";
  243. }
  244. }
  245. =item dir_list
  246. Return a $sort_order sorted list of files matching regex $pattern in a
  247. directory.
  248. Calls $sort_order, which can be one of:
  249. alpha - alphabetical
  250. reverse_alpha - alphabetical, reversed
  251. high_to_low - numeric, high to low
  252. low_to_high - numeric, low to high
  253. =cut
  254. sub dir_list {
  255. my ($dir, $sort_order, $file_pattern) = @_;
  256. $file_pattern = qr/^[0-9]{1,2}$/ unless ($file_pattern);
  257. $sort_order = 'high_to_low' unless ($sort_order);
  258. opendir LIST_DIR, $dir
  259. or die "Couldn't open $dir: $!";
  260. my @files = sort $sort_order
  261. grep { m/$file_pattern/ }
  262. readdir LIST_DIR;
  263. closedir LIST_DIR;
  264. return @files;
  265. }
  266. # various named sorts for dir_list
  267. sub alpha { $a cmp $b; } # alphabetical
  268. sub high_to_low { $b <=> $a; } # numeric, high to low
  269. sub low_to_high { $a <=> $b; } # numberic, low to high
  270. sub reverse_alpha { $b cmp $a; } # alphabetical, reversed
  271. =item year_print
  272. List out the updates for a year.
  273. =cut
  274. sub year_print {
  275. my ($year) = @_;
  276. my ($year_file) = "$DISPLAY_CONF{ROOT_DIR}/$year";
  277. my ($year_url) = "$DISPLAY_CONF{URL_ROOT}$year";
  278. my $result;
  279. if (-d $year_file) {
  280. # Handle year directories with index files.
  281. $result .= entry_print($year) if -T "$year_file/index";
  282. # this is stupid:
  283. my $header_text = icon_markup($year, $year);
  284. $header_text = '' unless $header_text;
  285. $result .= heading("$header_text $year", 3);
  286. my @months = dir_list($year_file, 'high_to_low', qr/^[0-9]{1,2}$/);
  287. my $year_text;
  288. my $count = 0; # explicitly defined for later printing.
  289. foreach my $month (@months) {
  290. my @entries = dir_list("$year_file/$month", 'low_to_high',
  291. qr/^[0-9]{1,2}$/);
  292. # Add the count of files to $update_count:
  293. $count += @entries;
  294. my $month_text;
  295. foreach my $entry (@entries) {
  296. $month_text .= a("href: $year_url/$month/$entry", $entry) . "\n";
  297. }
  298. $month_text = small('(' . $month_text . ')');
  299. my $link = a("href: $year_url/$month", month_name($month));
  300. $year_text .= table_row(
  301. table_cell('class: datelink', $link),
  302. table_cell('class: datelink', $month_text)
  303. ) . "\n\n";
  304. }
  305. $result .= "\n\n" . table($year_text) . "\n";
  306. if ($count > 1) {
  307. my ($average) = int($count / @months);
  308. $count = "$count entries, roughly $average an active month.";
  309. }
  310. elsif ($count == 0) { $count = $count . ' entries'; }
  311. elsif ($count == 1) { $count = $count . ' entry'; }
  312. $result .= p($count);
  313. } elsif (-T $year_file) {
  314. $result .= entry_print($year);
  315. } else {
  316. $result .= p('No such year.');
  317. }
  318. return entry_markup($result);
  319. }
  320. =item month_print
  321. Prints the entries in a given month (nnnn/nn).
  322. =cut
  323. sub month_print {
  324. my ($month) = @_;
  325. my $month_file = "$DISPLAY_CONF{ROOT_DIR}/$month";
  326. my $result;
  327. # If a directory exists for $month, use dir_list to grab
  328. # the entry files it contains into @entry_files, sorted
  329. # numerically. Then send each entry to entry_print.
  330. if (-d $month_file) {
  331. if (-T "$month_file/index") {
  332. $result .= entry_print($month);
  333. }
  334. my @entry_files = dir_list ($month_file, 'high_to_low',
  335. qr/^[0-9]{1,2}$/);
  336. foreach my $entry_file (@entry_files) {
  337. $result .= entry_markup( entry_print("$month/$entry_file")
  338. . datestamp("$month/$entry_file") );
  339. }
  340. } elsif (-T $month_file) {
  341. $result .= entry_print($month);
  342. }
  343. $result .= p( 'class: centerpiece',
  344. a("href: $DISPLAY_CONF{URL_ROOT}" . month_before($month), 'previous') ) . "\n\n";
  345. return $result;
  346. }
  347. =item entry_print
  348. Prints the contents of a given entry. Calls datestamp,
  349. dir_list, and icon_markup. Recursively calls itself.
  350. =cut
  351. sub entry_print {
  352. my ($entry, $level) = @_;
  353. $level = 'index' unless $level;
  354. # location of entry on local filesystem, and its URL:
  355. my $entry_loc = "$DISPLAY_CONF{ROOT_DIR}/$entry";
  356. my $entry_url = $DISPLAY_CONF{URL_ROOT} . $entry;
  357. my $result;
  358. # display an icon, if we have one:
  359. if ( my $ico_markup = icon_markup($entry) ) {
  360. $result .= heading($ico_markup, 2) . "\n\n";
  361. }
  362. if (-T $entry_loc) {
  363. # is text, slurp it and return
  364. return $result . fragment_slurp($entry_loc);
  365. } elsif (-d $entry_loc) {
  366. # print index as head
  367. $result .= fragment_slurp("$entry_loc/index");
  368. # followed by any sub-entries:
  369. my @sub_entries = get_sub_entries($entry_loc);
  370. if ( $level eq 'index' and @sub_entries >= 1 ) {
  371. # spit out icons or text links for extra files
  372. $result .= list_contents($entry, @sub_entries);
  373. } elsif ( $level eq 'all' and @sub_entries >= 1 ) {
  374. # or if we're supposed to print everything in the directory
  375. # and if there's more there than just the index file,
  376. foreach my $se (@sub_entries) {
  377. next if ($se =~ m/[.](tgz|zip|tar[.]gz|gz|txt)$/);
  378. # print each of the other files, separated by little headers
  379. #my $url = "$DISPLAY_CONF{URL_ROOT}$entry/$se";
  380. #$result .= "\n\n" . p('{' . a("href: $url", $se) . '}') . "\n\n";
  381. $result .= p('class: centerpiece', '+');
  382. $result .= entry_print("$entry/$se");
  383. }
  384. }
  385. }
  386. return $result;
  387. }
  388. sub get_sub_entries {
  389. my $entry_loc = shift;
  390. my $match = qr/^[a-z_]+(\.(tgz|zip|tar[.]gz|gz|txt))?$/;
  391. my %ignore = ('index' => 1);
  392. return grep { ! $ignore{$_} } dir_list ($entry_loc, 'alpha', $match);
  393. }
  394. sub list_contents {
  395. my ($entry) = shift;
  396. my (@entries) = @_;
  397. my $contents;
  398. foreach my $se (@entries) {
  399. my $linktext = icon_markup("$entry/$se", $se);
  400. $linktext = $se unless $linktext;
  401. $contents .= ' ' . a("href: $DISPLAY_CONF{URL_ROOT}$entry/$se",
  402. $linktext,
  403. "title: $se");
  404. }
  405. return p( em('more') . ": $contents" ) . "\n";
  406. }
  407. =item icon_markup
  408. Check if an icon exists for a given entry if so, return markup to include it.
  409. Icons are PNG or JPEG image files following a specific naming convention:
  410. index.icon.[png|jp(e)g] for directories
  411. [filename].icon.[png|jp(e)g] for flat text files
  412. Calls image_size, uses filename to determine type.
  413. =cut
  414. sub icon_markup {
  415. my ($entry, $alt) = @_;
  416. my ($entry_loc) = "$DISPLAY_CONF{ROOT_DIR}/$entry";
  417. my ($entry_url) = "$DISPLAY_CONF{IMAGE_URL_ROOT}${entry}";
  418. my ($icon_loc, $icon_url);
  419. if (-T $entry_loc) {
  420. $icon_loc = "$entry_loc.icon";
  421. $icon_url = "$entry_url.icon";
  422. }
  423. elsif (-d $entry_loc) {
  424. $icon_loc = "$entry_loc/index.icon";
  425. $icon_url = "$entry_url/index.icon";
  426. }
  427. # put a list of icon image types to check for here
  428. # (first one found will be used)
  429. my (@suffixes) = qw(png gif jpg jpeg);
  430. my $suffix = "";
  431. for (@suffixes) {
  432. if (-e "$icon_loc.$_") {
  433. $suffix = $_;
  434. last;
  435. }
  436. }
  437. # fail unless there's a file with one of the above suffixes
  438. return 0 unless $suffix;
  439. # call image_size to slurp width & height from the image file
  440. my ($width, $height) = image_size("$icon_loc.$suffix");
  441. return qq{<img src="$icon_url.$suffix"\n width="$width" }
  442. . qq{height="$height"\n alt="$alt" />};
  443. }
  444. =item datestamp
  445. Returns a nice html datestamp for a given entry, including a wikilink for
  446. discussion and suchlike.
  447. =cut
  448. sub datestamp {
  449. my ($entry) = @_;
  450. my ($stamp);
  451. if ( $entry =~ m{(^[0-9]{4}/[0-9]{1,2}/[0-9]{1,2})} ) {
  452. my ($entry_year, $entry_month, $entry_day) = split (/\//, $1);
  453. # this stuff conditionalizes the wikilink
  454. # so that if nothing exists, you wind up with an edit form
  455. my ($wiki_date_name) = month_name($entry_month) .
  456. "_${entry_day}_${entry_year}";
  457. my $wikistamp = ':: ';
  458. if (-e "$WalaConf{PagesDir}/${wiki_date_name}") {
  459. $wikistamp .= a("href: $WalaConf{ScriptName}?$wiki_date_name",
  460. 'read the margins',
  461. 'title: a page you can edit');
  462. } else {
  463. $wikistamp .= a("href: $WalaConf{ScriptName}?$wiki_date_name",
  464. 'write in the margins',
  465. 'title: a page you can edit');
  466. }
  467. # return a fancy datestamp.
  468. my $month_name = month_name($entry_month);
  469. my $year_url = "href: $DISPLAY_CONF{URL_ROOT}$entry_year";
  470. $stamp = "\n "
  471. . a($year_url, $entry_year, "title: $entry_year") . "\n "
  472. . a("$year_url/$entry_month", $month_name, "title: $entry_year/$entry_month") . "\n "
  473. . a("$year_url/$entry_month/$entry_day", $entry_day, "title: $entry_year/$entry_month/$entry_day") . "\n "
  474. . $wikistamp . "\n";
  475. } else {
  476. $stamp = "(failed to construct datestamp for $entry)";
  477. }
  478. return p('class: datelink', $stamp);
  479. }
  480. =item fragment_slurp
  481. Read a text fragment, call line_parse to take care of funky markup and
  482. interpreting embedded code, and then return it as a string. Takes one
  483. parameter, the name of the file, and returns '' if it's not an extant text
  484. file.
  485. This might be the place to implement an in-memory cache for FastCGI or mod_perl
  486. environments. The trick is that the line_parse() results for certain files
  487. shouldn't be cached because they contain embedded code.
  488. =cut
  489. sub fragment_slurp {
  490. my ($file) = @_;
  491. # if $file is text
  492. if (-T $file) {
  493. my $everything;
  494. open my $fh, '<', $file
  495. or die "Couldn't open $file: $!\n";
  496. {
  497. # line sep
  498. local $/ = undef;
  499. $everything = <$fh>;
  500. }
  501. close $fh or die "Couldn't close: $!";
  502. # eval embedded Perl and ${variables}:
  503. eval_perl($everything);
  504. # Take care of any special markup.
  505. # We pass along $file so it has some context to work with
  506. return line_parse ($everything, $file);
  507. } else {
  508. return q{};
  509. }
  510. }
  511. =item eval_perl
  512. Evaluate embedded Perl in a string, replacing blocks enclosed with <perl> tags
  513. with whatever they return (well, evaluated in a scalar context). Modifies
  514. a string in-place, so be careful.
  515. Also handles simple ${variables}, replacing them (for now) from %DISPLAY_CONF
  516. values.
  517. =cut
  518. sub eval_perl {
  519. while ($_[0] =~ m/<perl>(.*?)<\/perl>/s) {
  520. my $block = $1;
  521. my $output = eval $block;
  522. if ($@) {
  523. # got an error
  524. $_[0] =~ s/<perl>\Q$block\E<\/perl>/$@/s;
  525. } else {
  526. # include anything returned from $block
  527. $_[0] =~ s/<perl>\Q$block\E<\/perl>/$output/s;
  528. }
  529. }
  530. # interpolate variables
  531. $_[0] =~ s/\${([a-zA-Z_]+)}/$DISPLAY_CONF{$1}/ge;
  532. return;
  533. }
  534. =item month_name
  535. Turn numeric dates into English.
  536. =cut
  537. sub month_name {
  538. my ($number) = @_;
  539. # "Null" is here so that $month_name[1] corresponds to January, etc.
  540. my @months = qw(Null January February March April May June
  541. July August September October November December);
  542. return $months[$number];
  543. }
  544. =item feed_print
  545. Return an Atom feed of entries for a month. Defaults to the most
  546. recent month in the archive.
  547. Called from handle(), requires XML::Atom::SimpleFeed.
  548. =cut
  549. sub feed_print {
  550. my $month = shift;
  551. $month = recent_month() unless defined $month;
  552. # create a feed object
  553. my $feed = XML::Atom::SimpleFeed->new(
  554. title => $DISPLAY_CONF{title},
  555. link => $DISPLAY_CONF{URL_ROOT},
  556. link => { rel => 'self', href => $DISPLAY_CONF{feed_url}, },
  557. icon => $DISPLAY_CONF{favicon_url},
  558. author => $DISPLAY_CONF{author},
  559. id => $DISPLAY_CONF{URL_ROOT},
  560. generator => "Display.pm / XML::Atom::SimpleFeed",
  561. );
  562. # If a directory exists for $month, use dir_list to grab
  563. # the entry files it contains into @entry_files, sorted
  564. # numerically. Then send each entry to entry_print.
  565. my @entry_files;
  566. if (-d "$DISPLAY_CONF{ROOT_DIR}/$month") {
  567. (@entry_files) = dir_list ("$DISPLAY_CONF{ROOT_DIR}/$month",
  568. 'high_to_low',
  569. qr/^[0-9]{1,2}$/);
  570. } else {
  571. return 0;
  572. }
  573. foreach my $entry_file (@entry_files) {
  574. # Going to feed this to SimpleFeed.
  575. my $content = entry_print("$month/$entry_file");
  576. $feed->add_entry(
  577. title => "$month/$entry_file",
  578. link => $DISPLAY_CONF{URL_ROOT} . "$month/$entry_file",
  579. id => $DISPLAY_CONF{URL_ROOT} . "$month/$entry_file",
  580. content => $content,
  581. );
  582. }
  583. return "Content-type: application/atom+xml\n\n"
  584. . $feed->as_string;
  585. }
  586. =back
  587. =head1 SEE ALSO
  588. walawiki.org, Blosxom, rassmalog, Text::Textile, XML::Atom::SimpleFeed,
  589. Image::Size, CGI::Fast.
  590. =head1 AUTHOR
  591. Copyright 2001-2007 Brennen Bearnes
  592. Image sizing code (in image_size) derived from wwwis, by Alex Knowles and
  593. Andrew Tong.
  594. display.pl is free software; you can redistribute it and/or modify
  595. it under the terms of the GNU General Public License as published by
  596. the Free Software Foundation; either version 2 of the License, or
  597. (at your option) any later version.
  598. This program is distributed in the hope that it will be useful,
  599. but WITHOUT ANY WARRANTY; without even the implied warranty of
  600. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  601. GNU General Public License for more details.
  602. =cut
  603. 1;