forked from arnolem/web-news
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.php
172 lines (151 loc) · 6.29 KB
/
common.php
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<?php
require_once 'lib/Web/News/Nntp.php';
require_once 'lib/fMailbox.php';
$NNTP_HOST = 'localhost';
if (getenv('NNTP_HOST')) {
$NNTP_HOST = getenv('NNTP_HOST');
}
define('NNTP_HOST', $NNTP_HOST);
function error($str) {
head("PHP news : error");
echo "<section class=\"content\"><blockquote><strong>Error:</strong> ".to_utf8($str)."</blockquote></section>\n";
foot();
die();
}
function head($title="PHP Mailing Lists (PHP News)") {
header("Content-type: text/html; charset=utf-8");
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php echo htmlspecialchars($title); ?></title>
<link rel="stylesheet" href="/fonts/Fira/fira.css" type="text/css" />
<link rel="stylesheet" href="/style.css" type="text/css" />
<link rel="shortcut icon" href="/favicon.ico">
</head>
<body>
<header class="header">
<nav class="header-inner">
<a href="/" class="header-brand"><img src="http://php.net/images/logos/php-logo.svg" class="header-brand-img" alt="PHP" height="24" width="48"><span class="header-brand-text">lists</span></a><ul class="header-menu">
<li class="header-menu-item"><a class="header-menu-item-link" href="http://php.net/downloads.php">Downloads</a></li>
<li class="header-menu-item"><a class="header-menu-item-link" href="http://php.net/docs.php">Documentation</a></li>
<li class="header-menu-item"><a class="header-menu-item-link" href="http://php.net/get-involved.php">Get Involved</a></li>
<li class="header-menu-item mod-active"><a class="header-menu-item-link" href="http://php.net/support.php">Help</a></li>
</ul>
<form class="search-form" action="http://php.net/search.php">
<input class="search-input" value="" name="pattern" placeholder="Search">
</form>
<div class="menu-icon" onclick="document.querySelector('.menu-mobile').classList.toggle('hide')">☰ MENU</div>
<ul class="menu-mobile hide">
<li class="menu-mobile-item"><a class="menu-mobile-item-link" href="http://php.net/downloads.php">Downloads</a></li>
<li class="menu-mobile-item"><a class="menu-mobile-item-link" href="http://php.net/docs.php">Documentation</a></li>
<li class="menu-mobile-item"><a class="menu-mobile-item-link" href="http://php.net/get-involved.php">Get Involved</a></li>
<li class="menu-mobile-item mod-active"><a class="menu-mobile-item-link" href="http://php.net/support.php">Help</a></li>
</ul>
</nav>
</header>
<?php
}
function foot() {?>
<footer class="footer">
<ul class="footer-nav">
<li class="footer-nav-item"><a class="footer-nav-item-link" href="http://php.net/copyright.php">Copyright © 2001-<?php echo date('Y'); ?> The PHP Group</a></li>
<li class="footer-nav-item"><a class="footer-nav-item-link" href="http://php.net/my.php">My PHP.net</a></li>
<li class="footer-nav-item"><a class="footer-nav-item-link" href="http://php.net/contact.php">Contact</a></li>
<li class="footer-nav-item"><a class="footer-nav-item-link" href="http://php.net/sites.php">Other PHP.net sites</a></li>
<li class="footer-nav-item"><a class="footer-nav-item-link" href="http://php.net/mirrors.php">Mirror sites</a></li>
<li class="footer-nav-item"><a class="footer-nav-item-link" href="http://php.net/privacy.php">Privacy policy</a></li>
</ul>
</footer>
</body>
</html>
<?php
}
function to_utf8($str, $charset = 'iso-8859-1')
{
$n = iconv($charset , 'utf-8', $str);
if ($n === false) {
return $str;
}
return $n;
}
function decode_header($charset,$encoding,$text) {
if (strtolower($encoding) == "b") {
$text = base64_decode($text);
} else {
$text = quoted_printable_decode($text);
}
return to_utf8($text, $charset);
}
function recode_header($header, $basecharset) {
if (strpos($header, "=?") === false) {
return to_utf8($header, $basecharset);
}
return preg_replace_callback(
"/=\\?(.+?)\\?([qb])\\?(.+?)(\\?=|$)/i",
function ($m) {
return decode_header($m[1], $m[2], $m[3]);
},
$header
);
}
/* Email spam protection (taken from php-bugs-web) */
function spam_protect($txt) {
$translate = array('@' => ' at ', '.' => ' dot ');
/* php.net addresses are not protected! */
if (preg_match('/^(.+)@php\.net/i', $txt)) {
return $txt;
} else {
return strtr($txt, $translate);
}
}
# this turns some common forms of email addresses into mailto: links
function format_author($a, $charset = 'iso-8859-1') {
$a = recode_header($a, $charset);
if (preg_match("/^\s*(.+)\s+\\(\"?(.+?)\"?\\)\s*$/",$a,$ar)) {
return "<a href=\"mailto:".htmlspecialchars(urlencode(spam_protect($ar[1])), ENT_QUOTES, "UTF-8")."\" class=\"email fn n\">".str_replace(" ", " ", htmlspecialchars($ar[2], ENT_QUOTES, "UTF-8"))."</a>";
}
if (preg_match("/^\s*\"?(.+?)\"?\s*<(.+)>\s*$/",$a,$ar)) {
return "<a href=\"mailto:".htmlspecialchars(urlencode(spam_protect($ar[2])), ENT_QUOTES, "UTF-8")."\" class=\"email fn n\">".str_replace(" ", " ", htmlspecialchars($ar[1], ENT_QUOTES, "UTF-8"))."</a>";
}
if (strpos("@",$a) !== false) {
$a = spam_protect($a);
return "<a href=\"mailto:".htmlspecialchars(urlencode($a), ENT_QUOTES, "UTF-8")."\" class=\"email fn n\">".htmlspecialchars($a, ENT_QUOTES, "UTF-8")."</a>";
}
return str_replace(" ", " ", htmlspecialchars($a, ENT_QUOTES, "UTF-8"));
}
function format_subject($s, $charset = 'iso-8859-1') {
global $article;
$s = recode_header($s, $charset);
if ((($pos = strpos($s, '[PHP')) !== false || ($pos = strpos($s, '[PEAR')) !== false)) {
if (($end_pos = strpos($s, ']', $pos)) !== false) {
$s = ltrim(substr_replace($s, '', $pos, $end_pos - $pos + 1));
}
}
// make this look better on the preview page..
if (strlen($s) > 150 && !isset($article)) {
$s = substr($s, 0, 150) . "...";
} else {
$s = wordwrap($s, 150);
}
return nl2br(htmlspecialchars($s, ENT_QUOTES, "UTF-8"));
}
function format_title($s, $charset = 'iso-8859-1') {
global $article;
$s = recode_header($s, $charset);
$s = preg_replace("/^(Re: *)?\[(PHP|PEAR)(-.*)?\] /i", "\\1", $s);
// make this look better on the preview page..
if (strlen($s) > 150 && !isset($article)) {
$s = substr($s, 0, 150) . "...";
} else {
$s = wordwrap($s, 150);
}
return htmlspecialchars($s, ENT_QUOTES, "UTF-8");
}
function format_date($d) {
$d = strtotime($d);
$d = gmdate('r', $d);
return str_replace(" ", " ", $d);
}