1 |
joko |
1.1 |
#!/usr/bin/perl |
2 |
|
|
|
3 |
|
|
## ---------------------------------------------------------------------- |
4 |
|
|
## $Id: feed.pl,v 1.4 2003/01/23 14:44:35 janosch Exp $ |
5 |
|
|
## ---------------------------------------------------------------------- |
6 |
|
|
## $Log: feed.pl,v $ |
7 |
|
|
## ---------------------------------------------------------------------- |
8 |
|
|
|
9 |
|
|
|
10 |
|
|
use strict; |
11 |
|
|
use warnings; |
12 |
|
|
|
13 |
|
|
BEGIN { |
14 |
|
|
use FindBin qw($Bin); |
15 |
|
|
eval("use lib qw( ../libs $Bin/../../libs );"); |
16 |
|
|
die($@) if $@; |
17 |
|
|
} |
18 |
|
|
|
19 |
|
|
use shortcuts::files qw( f2s s2f ); |
20 |
|
|
|
21 |
|
|
|
22 |
|
|
# ----------------------------------- subs ----------------------- |
23 |
|
|
my $payload; |
24 |
|
|
|
25 |
|
|
sub read_from { |
26 |
|
|
my $path = shift; |
27 |
|
|
$payload = f2s($path); |
28 |
|
|
} |
29 |
|
|
|
30 |
|
|
sub twingle_to { |
31 |
|
|
my $type = shift; |
32 |
|
|
|
33 |
|
|
|
34 |
|
|
# PreFlights |
35 |
|
|
# insert block seperator |
36 |
|
|
$payload =~ s/\n\n/\n<!-- block -->\n/g; |
37 |
|
|
|
38 |
|
|
# AutoColouring |
39 |
|
|
# items: o=red, x=green |
40 |
|
|
$payload =~ s/^(\s*)(o|\-)\s(.*)/$1<font color="red"><b>$2 <\/b><\/font>$3/gm; |
41 |
|
|
$payload =~ s/^(\s*)(x|\+)\s(.*)/$1<font color="green"><b>$2 <\/b><\/font>$3/gm; |
42 |
|
|
$payload =~ s/^(\s*)(c)\s(.*)/$1<font color="green"><b>$2 <\/b><\/font><s>$3<\/s>/gm; |
43 |
|
|
|
44 |
|
|
# LinkExpansion |
45 |
|
|
|
46 |
|
|
my $no_quote = '([^\"])'; |
47 |
|
|
|
48 |
|
|
my $p_wordchars = '[\w|\/|\.|\*|\s]'; |
49 |
|
|
#my $p_wordchars = '[\w]'; |
50 |
|
|
$payload =~ s/{$no_quote}search::($p_wordchars+)::($p_wordchars+)/<a href="http:\/\/search.netfrag.org\/$2\/$1" target="_blank">$2<\/a>/gm; |
51 |
|
|
#$payload =~ s/(?:\[??search::\[??(\w+[\s|,|\:])[\n|\|\s|\]]*?)/<a href="http:\/\/search.netfrag.org\/$1" target="_blank">$1<\/a>/gm; |
52 |
|
|
|
53 |
|
|
#my $s_word = '([\w| ]+)'; |
54 |
|
|
#my $s_word = '[\w| |\-|\.|\'|\"]+'; |
55 |
|
|
my $s_word = '[\w|\-|\.|\'|"| |,]+'; |
56 |
|
|
|
57 |
|
|
#my $s_word_encap = "(?:\[$s_word\]|$s_word)"; |
58 |
|
|
my $s_word_encap = "(\[$s_word\]|$s_word)+"; |
59 |
|
|
#my $s_word_encap = "(?:\[($s_word)\]??|($s_word)+?)"; |
60 |
|
|
|
61 |
|
|
#$payload =~ s/(?:\[??search::$s_word_encap[ |\s|\n|\| |\]]??)/<a href="http:\/\/search.netfrag.org\/$1" target="_blank">$1<\/a>/gm; |
62 |
|
|
$payload =~ s/(?:\[??search::($s_word))/<a href="http:\/\/search.netfrag.org\/$1" target="_blank">$1<\/a>/gm; |
63 |
|
|
|
64 |
|
|
#$payload =~ s/search::\[(.+?)\]/<a href="http:\/\/search.netfrag.org\/$1" target="_blank">$1<\/a>/gm; |
65 |
|
|
#$payload =~ s/search::\[(.+?)\]/my $url = quotemeta($1); my $result = '<a href="http://search.netfrag.org/' . $url. '" target="_blank">' . $1 . '</a>'; /gme; |
66 |
|
|
#$payload =~ s/search::\[(.+?)\]/ my $url = ($1); print "url: $url\n"; return "abc"; /gme; |
67 |
|
|
|
68 |
|
|
my $search_nfo_base = "http://search.netfrag.org/"; |
69 |
|
|
$payload =~ s/search::\[(.+?)\]/<a href="$search_nfo_base$1" target="_blank">$1<\/a>/gm; |
70 |
|
|
#my $searchurl = '<a href="http:\/\/search.netfrag.org\/$1" target="_blank">$1<\/a>'; |
71 |
|
|
#$payload =~ s/search::\[(.+?)\]/$searchurl/gm; |
72 |
|
|
|
73 |
|
|
my $google_base = 'http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q='; |
74 |
|
|
#print "base: $google_base", "\n"; |
75 |
|
|
#$payload =~ s/google::[\[]*($p_wordchars+)[\[]*[^\n]/<a href="$google_base$1" target="_blank">$1<\/a>/gm; |
76 |
|
|
#$payload =~ s/google::[\[]*($p_wordchars+)/<a href="$google_base$1" target="_blank">$1<\/a>/gm; |
77 |
|
|
$payload =~ s/google::[\[]*([\w|\s]+)/<a href="$google_base$1" target="_blank">$1<\/a>/gm; |
78 |
|
|
|
79 |
|
|
# FIXME: allow "\s" inside urls! (guess it's unallowed by html-standard, but just do it!) |
80 |
|
|
my $p_urlchars = '[\w|\.|\/|\-|~|%|\?|&|=|:]'; |
81 |
|
|
#my $p_url_querychars = '[]'; |
82 |
|
|
my $p_url = "$no_quote(http[s]??:\/\/$p_urlchars+)::??(.+?)??"; |
83 |
|
|
$payload =~ s/$p_url/$1<a href="$2#$3" target="_blank">$2<\/a>/g; |
84 |
|
|
|
85 |
|
|
#$payload =~ s/(\w+::\w+)+/<font color="orange"><b>$1<\/b><\/font>/g; |
86 |
|
|
#$payload =~ s/(\w+::\w+)+/<font color="orange"><b><a href="$search_nfo_base$1" target="_blank">$1<\/a><\/b><\/font>/g; |
87 |
|
|
|
88 |
|
|
#$payload =~ s/(\w+::\w+(?:::\w)??)+/<font color="orange"><b><a href="$search_nfo_base$1" target="_blank">$1<\/a><\/b><\/font>/g; |
89 |
|
|
$payload =~ s/(\w+(?:::\w+)+)+/<font color="orange"><b><a href="$search_nfo_base$1" target="_blank">$1<\/a><\/b><\/font>/g; |
90 |
|
|
|
91 |
|
|
# PostFixes |
92 |
|
|
# spaces |
93 |
|
|
$payload =~ s/^(\s*)/' ' x (length($1) * 2)/gme; |
94 |
|
|
# newlines |
95 |
|
|
#$payload =~ s/\n\n/<br\/><\/br>/g; |
96 |
|
|
$payload =~ s/\n/<br\/>\n/g; |
97 |
|
|
|
98 |
|
|
# trace |
99 |
|
|
#print "payload: $payload", "\n"; |
100 |
|
|
|
101 |
|
|
} |
102 |
|
|
|
103 |
|
|
sub write_to { |
104 |
|
|
my $path = shift; |
105 |
|
|
|
106 |
|
|
my $header = <<HEADER; |
107 |
|
|
<html> |
108 |
|
|
<head> |
109 |
|
|
<title></title> |
110 |
|
|
<link href="/horde/css.php?app=chora" rel="stylesheet" type="text/css" /> |
111 |
|
|
</head> |
112 |
|
|
<body> |
113 |
|
|
HEADER |
114 |
|
|
|
115 |
|
|
my $footer = <<FOOTER; |
116 |
|
|
</body> |
117 |
|
|
</html> |
118 |
|
|
FOOTER |
119 |
|
|
|
120 |
|
|
$payload = "$header$payload$footer"; |
121 |
|
|
|
122 |
|
|
s2f($path, $payload); |
123 |
|
|
} |
124 |
|
|
|
125 |
|
|
|
126 |
|
|
# ----------------------------------- main ----------------------- |
127 |
|
|
|
128 |
|
|
my $from = shift; |
129 |
|
|
my $to = shift; |
130 |
|
|
my $to_type = shift; |
131 |
|
|
$from ||= ''; |
132 |
|
|
$to_type ||= 'html'; |
133 |
|
|
|
134 |
|
|
|
135 |
|
|
# auto-options |
136 |
|
|
if (!$to) { |
137 |
|
|
my @parts = split(/\./, $from); |
138 |
|
|
pop @parts; |
139 |
|
|
$to = join('.', @parts, $to_type); |
140 |
|
|
} |
141 |
|
|
|
142 |
|
|
print "Task: Reading from '$from', twingling to '$to_type', writing to '$to'.", "\n"; |
143 |
|
|
|
144 |
|
|
read_from($from); |
145 |
|
|
twingle_to($to_type); |
146 |
|
|
write_to($to); |
147 |
|
|
|
148 |
|
|
print "ready.", "\n"; |
149 |
|
|
|
150 |
|
|
1; |