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