6ab9c313 |
1 | <?php |
2 | /******************************************************************************** |
3 | * install.d/format.inc.php : HTML output subroutines |
4 | * -------------------------- |
5 | * |
6 | * This file is part of the banana distribution |
7 | * Copyright: See COPYING files that comes with this distribution |
8 | ********************************************************************************/ |
9 | |
10 | /** produces HTML output for overview |
11 | * @param $_header STRING name of the header |
12 | * @param $_text STRING value of the header |
13 | * @param $_id INTEGER MSGNUM of message |
14 | * @param $_group TEXT name of newsgroup |
15 | * @param $_isref BOOLEAN emphasizes message in overview tree ? |
16 | * @param $_isread BOOLEAN displays message as read ? |
17 | * @return STRING HTML output |
18 | * @see disp_desc |
19 | */ |
20 | |
21 | function formatSpoolHeader($_header,$_text,$_id,$_group,$_isref,$_isread=true) { |
22 | global $locale; |
23 | switch ($_header) { |
24 | case "date": |
25 | return date($locale['format']['datefmt'],$_text); |
26 | case "from": |
27 | # From: mark@cbosgd.ATT.COM |
28 | # From: mark@cbosgd.ATT.COM (Mark Horton) |
29 | # From: Mark Horton <mark@cbosgd.ATT.COM> |
30 | $result = htmlentities($_text); |
31 | if (preg_match("/^([^ ]+)@([^ ]+)$/",$_text,$regs)) |
32 | $result="<a href=\"mailto:". |
33 | "{$regs[1]}@{$regs[2]}\">".htmlentities($regs[1]. |
34 | "@".$regs[2])."</a>"; |
35 | if (preg_match("/^([^ ]+)@([^ ]+) \((.*)\)$/",$_text,$regs)) |
36 | $result="<a href=\"mailto:". |
37 | "{$regs[1]}@{$regs[2]}\">".htmlentities($regs[3])."</a>"; |
38 | if (preg_match("/^\"?([^<>\"]+)\"? +<(.+)@(.+)>$/",$_text,$regs)) |
39 | $result="<a href=\"mailto:". |
40 | "{$regs[2]}@{$regs[3]}\">".htmlentities($regs[1])."</a>"; |
41 | return preg_replace("/\\\(\(|\))/","\\1",$result); |
42 | case "subject": |
43 | if ($_isref) { |
44 | return '<span class="isref">'.htmlentities($_text).'</span>'; |
45 | } else { |
46 | if ($_isread) { |
cf0b2c70 |
47 | return "<a href=\"article.php?group=$_group&id=$_id\">" |
6ab9c313 |
48 | .htmlentities($_text)."</a>"; |
49 | }else { |
cf0b2c70 |
50 | return "<a href=\"article.php?group=$_group&id=$_id\"><b>" |
6ab9c313 |
51 | .htmlentities($_text)."</b></a>"; |
52 | } |
53 | } |
54 | default: |
55 | return htmlentities($_text); |
56 | } |
57 | } |
58 | |
59 | /** produces HTML ouput for header section in post.php |
60 | * @param $_header STRING name of the header |
61 | * @param $_text STRING value of the header |
62 | * @param $_spool OBJECT spool object for building references |
63 | * @return STRING HTML output |
64 | */ |
65 | |
66 | function formatDisplayHeader($_header,$_text,$_spool) { |
67 | global $locale; |
68 | switch ($_header) { |
69 | case "date": |
70 | return locale_date($_text); |
71 | case "followup": |
72 | case "newsgroups": |
73 | $res = ""; |
74 | $groups = preg_split("/(\t| )*,(\t| )*/",$_text); |
4491aea0 |
75 | foreach ($groups as $g) { |
6ab9c313 |
76 | $res.='<a href="thread.php?group='.$g.'">'.$g.'</a>, '; |
77 | } |
78 | return substr($res,0, -2); |
79 | case "from": |
80 | # From: mark@cbosgd.ATT.COM |
81 | # From: mark@cbosgd.ATT.COM (Mark Horton) |
82 | # From: Mark Horton <mark@cbosgd.ATT.COM> |
83 | # From: Anonymous <anonymous> |
84 | $result = htmlentities($_text); |
85 | if (preg_match("/^([^ ]+)@([^ ]+)$/",$_text,$regs)) |
86 | $result="<a href=\"mailto:" |
87 | ."{$regs[1]}@{$regs[2]}\">".htmlentities($regs[1]) |
88 | ."@{$regs[2]}</a>"; |
89 | if (preg_match("/^([^ ]+)@([^ ]+) \((.*)\)$/",$_text,$regs)) |
90 | $result="<a href=\"mailto:" |
91 | ."{$regs[1]}@{$regs[2]}\">".htmlentities($regs[3]) |
92 | ."</a>"; |
93 | if (preg_match("/^\"?([^<>\"]+)\"? +<(.+)@(.+)>$/",$_text,$regs)) |
94 | $result="<a href=\"mailto:" |
95 | ."{$regs[2]}@{$regs[3]}\">".htmlentities($regs[1]) |
96 | ."</a>"; |
97 | return preg_replace("/\\\(\(|\))/","\\1",$result); |
98 | case "references": |
99 | $rsl = ""; |
100 | $ndx = 1; |
101 | $text=str_replace("><","> <",$_text); |
4491aea0 |
102 | $text=preg_split("/( |\t)/",strtr($text,$_spool->ids)); |
103 | $parents=preg_grep("/^\d+$/",$text); |
6ab9c313 |
104 | $p=array_pop($parents); |
105 | while ($p) { |
106 | $rsl .= "<a href=\"article.php?group={$_spool->group}" |
cf0b2c70 |
107 | ."&id=$p\">$ndx</a> "; |
6ab9c313 |
108 | $_spool->overview[$p]->desc++; |
109 | $p = $_spool->overview[$p]->parent; |
110 | $ndx++; |
111 | } |
112 | return $rsl; |
113 | case "xface": |
114 | return '<img src="xface.php?face='.base64_encode($_text) |
115 | .'" alt="x-face" />'; |
116 | default: |
117 | return htmlentities($_text); |
118 | } |
119 | } |
120 | |
121 | /** produces HTML output for message body |
122 | * @param $_text STRING message body |
123 | * @return STRING HTML output |
124 | */ |
125 | function formatbody($_text) { |
126 | global $news; |
127 | $res ="\n\n"; |
128 | $res .= htmlentities(wrap($_text,"",$news['wrap']))."\n"; |
129 | $res = preg_replace("/(<|>|")/"," \\1 ",$res); |
130 | $res = preg_replace('/(["\[])?((https?|ftp|news):\/\/[a-z@0-9.~%$£µ&i#\-+=_\/\?]*)(["\]])?/i', |
131 | "\\1<a href=\"\\2\">\\2</a>\\4", $res); |
132 | $res = preg_replace("/ (<|>|") /","\\1",$res); |
133 | return $res."\n"; |
134 | } |
135 | |
136 | /** contextual links |
137 | * @return STRING HTML output |
138 | */ |
139 | function displayshortcuts() { |
140 | global $news,$locale,$first,$spool,$group,$post,$id; |
141 | $sname = $_SERVER['SCRIPT_NAME']; |
142 | $array = explode('/',$sname); |
143 | $sname = array_pop($array); |
144 | |
145 | echo '<div class="shortcuts">'; |
146 | echo '[<a href="disconnect.php">'.$locale['format']['disconnection'] |
147 | .'</a>] '; |
148 | |
149 | switch ($sname) { |
150 | case 'thread.php' : |
151 | echo '[<a href="index.php">'.$locale['format']['grouplist'] |
152 | .'</a>] '; |
153 | echo "[<a href=\"post.php?group=$group\">" |
154 | .$locale['format']['newpost']."</a>] "; |
155 | if (sizeof($spool->overview)>$news['max']) { |
156 | for ($ndx=1; $ndx<=sizeof($spool->overview); $ndx += $news['max']) { |
157 | if ($first==$ndx) { |
158 | echo "[$ndx-".min($ndx+$news['max']-1,sizeof($spool->overview))."] "; |
159 | } else { |
cf0b2c70 |
160 | echo "[<a href=\"".$_SERVER['PHP_SELF']."?group=$group&first=" |
6ab9c313 |
161 | ."$ndx\">$ndx-".min($ndx+$news['max']-1,sizeof($spool->overview)) |
162 | ."</a>] "; |
163 | } |
164 | } |
165 | } |
166 | break; |
167 | case 'article.php' : |
168 | echo '[<a href="index.php">'.$locale['format']['grouplist'] |
169 | .'</a>] '; |
170 | echo "[<a href=\"thread.php?group=$group\">" |
171 | .$locale['format']['group_b'].$group |
172 | .$locale['format']['group_a']."</a>] "; |
cf0b2c70 |
173 | echo "[<a href=\"post.php?group=$group&id=$id&type=followup\">" |
6ab9c313 |
174 | .$locale['format']['followup']."</a>] "; |
175 | if (checkcancel($post->headers)) { |
cf0b2c70 |
176 | echo "[<a href=\"article.php?group=$group&id=$id&type=cancel\">" |
6ab9c313 |
177 | .$locale['format']['cancel']."</a>] "; |
178 | } |
179 | break; |
180 | case 'post.php' : |
181 | echo '[<a href="index.php">'.$locale['format']['grouplist'] |
182 | .'</a>] '; |
183 | echo "[<a href=\"thread.php?group=$group\">" |
184 | .$locale['format']['group_b'].$group |
185 | .$locale['format']['group_a']."</a>] "; |
186 | break; |
187 | } |
188 | echo '</div>'; |
189 | } |
190 | |
191 | ?> |
192 | |