forked from bentglasstube/blosxom-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions-v0i1
79 lines (56 loc) · 1.73 KB
/
functions-v0i1
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
#!/usr/bin/perl -w
# Blosxom Plugin: functions
# Author: Brian Akins ([email protected])
# Version: 0+1i
# Blosxom Home/Docs/Licensing: http://www.raelity.org/blosxom
package functions;
use strict;
use vars qw(%functions $functions_dir);
#ugh! blosxom need an external config..
#this is where functions live.
$functions_dir = "/www/u/bakins/blosxom/functions";
#slurp in the functions
sub start {
# Drop ending any / from dir settings
$functions_dir =~ s!/$!!;
# Functions: Start, lifted from blosxom core code
if ( $functions_dir and opendir FUNCTIONS, $functions_dir ) {
foreach my $function ( grep { /^\w+$/ && -f "$functions_dir/$_" } sort readdir(FUNCTIONS) ) {
my($function_name) = $function =~ /^\d*(\w+)$/;
require "$functions_dir/$function";
my $package = "functions::$function_name";
$package->start();
}
closedir FUNCTIONS;
}
return 1;
}
sub story {
my($pkg, $path, $filename, $story_ref, $title_ref, $body_ref) = @_;
my @lines = split(/(\n|\r\n){1}/, $$body_ref);
$$body_ref = '';
foreach my $line(@lines) {
#lines that start with space are not processed
unless($line =~ /^\s/) {
$line =~ s/\@(.*?:.*?)\@/do_func($1)/eg;
}
$$body_ref .= $line;
}
return 1;
}
sub do_func
{
my ($orig, $opts) = @_;
$opts ||= {};
my ($func, $args) = split(/\s*:\s*/, $orig, 2);
$func =~ s/^\s*|\s*$//g;
$args =~ s/^\s*|\s*$//g;
# if the function exists, do it, otherwise return original string.
if(exists($functions{$func})) {
#function must parse args
return $functions{$func}($args, $opts);
} else {
return $orig;
}
}
1;