Commit:    80aff627ec41af469963848e0f30c2eef14cc2ac
Author:    Sobak <[email protected]>         Thu, 13 Mar 2014 06:31:37 
+0100
Parents:   7c6ab80ff11ed269f4aad0c4f6aebfe1d11360ac
Branches:  master

Link:       
http://git.php.net/?p=web/news.git;a=commitdiff;h=80aff627ec41af469963848e0f30c2eef14cc2ac

Log:
Merged common.inc and nntp.inc into common.php

Changed paths:
  M  article.php
  D  common.inc
  A  common.php
  M  getpart.php
  M  group.php
  M  index.php
  D  nntp.inc
  M  search.php

diff --git a/article.php b/article.php
index c295c02..6378895 100644
--- a/article.php
+++ b/article.php
@@ -1,7 +1,6 @@
 <?php
 
-require 'common.inc';
-require 'nntp.inc';
+require 'common.php';
 
 if (isset($_GET['article'])) {
        $article = (int)$_GET['article'];
diff --git a/common.inc b/common.inc
deleted file mode 100644
index dc6b6ec..0000000
--- a/common.inc
+++ /dev/null
@@ -1,165 +0,0 @@
-<?php
-
-define('NNTP_HOST', 'localhost');
-
-function error($str) {
-       head("PHP news : error");
-       echo "<blockquote><strong>Error:</strong> $str</blockquote>\n";
-       foot();
-       die();
-}
-
-function head($title="PHP news") {
-       header("Content-type: text/html; charset=utf-8");
-       echo '<?xml version="1.0"?>' . "\n";
-
-?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
-    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>
-<html xmlns="http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en">
- <head>
-  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-  <title><?php echo $title?></title>
-  <link rel="stylesheet" href="/style.css" type="text/css" />
- </head>
- <body>
-  <table width="100%" border="0" cellspacing="0" cellpadding="0">
-   <tr class="header">
-    <td>
-     <a href="/index.php"><img src="/i/l.gif" width="120" height="67" 
alt="PHP" /></a>
-    </td>
-    <td align="right" valign="bottom">
-     PHP.net <a href="news://<?php echo $_SERVER['HTTP_HOST']; ?>/" 
class="top">news server</a> web interface
-    </td>
-   </tr>
-   <tr class="subheader">
-    <td colspan="2">
-     <img src="/i/g.gif" width="1" height="1" alt="" />
-    </td>
-   </tr>
-  </table>
-<?php
-}
-
-function foot() {?>
-  <hr />
-  <div class="small">
-   Written by Jim Winstead. no rights reserved. (<a 
href="https://git.php.net/?p=web/news.git";>source code</a>)
-  </div>
- </body>
-</html>
-<?php
-}
-
-function to_utf8($str, $charset)
-{
-       $n = iconv($charset ? $charset : 'iso-8859-1', 'utf-8', $str);
-       if ($n === false) {
-               return $str;
-       }
-       return $n;
-}
-
-/*
-if (function_exists("mb_convert_encoding")) {
-function to_utf8($str, $charset)
-{
-return mb_convert_encoding($str, "utf-8", strlen($charset) ? $charset : 
"iso-8859-1");
-}
-} else if (function_exists("recode_string")) {
-function to_utf8($str, $charset)
-{
-if (strlen($charset) == 0)
-$charset = "iso-8859-1";
-return recode_string("$charset..utf-8", $str);
-}
-} else if (function_exists("iconv")) {
-function to_utf8($str, $charset)
-{
-return iconv(strlen($charset) ? $charset : "iso-8859-1", "utf-8", $str);
-}
-} else {
-function to_utf8($str, $charset)
-{
-return $str;
-}
-}
-*/
-
-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("/=\\?(.+?)\\?([qb])\\?(.+?)(\\?=|$)/ie", 
"decode_header('\\1','\\2','\\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) {
-       $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(" ", "&nbsp;", 
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(" ", "&nbsp;", 
htmlspecialchars($ar[1], ENT_QUOTES, "UTF-8"))."</a>";
-       }
-       if (ereg("@",$a)) {
-               $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(" ", "&nbsp;", htmlspecialchars($a, ENT_QUOTES, 
"UTF-8"));
-}
-
-function format_subject($s, $charset) {
-       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 nl2br(htmlspecialchars($s, ENT_QUOTES, "UTF-8"));
-}
-
-
-function format_title($s, $charset) {
-       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 = strftime("%c", $d);
-       return str_replace(" ", "&nbsp;", $d);
-}
diff --git a/common.php b/common.php
new file mode 100644
index 0000000..3dd96b8
--- /dev/null
+++ b/common.php
@@ -0,0 +1,187 @@
+<?php
+
+define('NNTP_HOST', 'localhost');
+
+function nntp_connect($server, $port = 119) {
+       $s = @fsockopen($server, $port, $errno, $errstr, 30);
+       if (!$s) {
+               return false;
+       }
+       $hello = fgets($s, 1024);
+       if (substr($hello,0,4) != "200 ") {
+               return false;
+       }
+       return $s;
+}
+
+function nntp_cmd($conn, $command, $expected) {
+       if (strlen($command) > 510) {
+               die("command too long: $command");
+       }
+       fputs($conn, "$command\r\n");
+       $res = fgets($conn, 1024);
+       list($code, $extra) = explode(" ", $res, 2);
+       return ($code == $expected) ? $extra : false;
+}
+
+function error($str) {
+       head("PHP news : error");
+       echo "<blockquote><strong>Error:</strong> $str</blockquote>\n";
+       foot();
+       die();
+}
+
+function head($title="PHP news") {
+       header("Content-type: text/html; charset=utf-8");
+       echo '<?xml version="1.0"?>' . "\n";
+
+?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>
+<html xmlns="http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en">
+ <head>
+  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+  <title><?php echo $title?></title>
+  <link rel="stylesheet" href="/style.css" type="text/css" />
+ </head>
+ <body>
+  <table width="100%" border="0" cellspacing="0" cellpadding="0">
+   <tr class="header">
+    <td>
+     <a href="/index.php"><img src="/i/l.gif" width="120" height="67" 
alt="PHP" /></a>
+    </td>
+    <td align="right" valign="bottom">
+     PHP.net <a href="news://<?php echo $_SERVER['HTTP_HOST']; ?>/" 
class="top">news server</a> web interface
+    </td>
+   </tr>
+   <tr class="subheader">
+    <td colspan="2">
+     <img src="/i/g.gif" width="1" height="1" alt="" />
+    </td>
+   </tr>
+  </table>
+<?php
+}
+
+function foot() {?>
+  <hr />
+  <div class="small">
+   Written by Jim Winstead. no rights reserved. (<a 
href="https://git.php.net/?p=web/news.git";>source code</a>)
+  </div>
+ </body>
+</html>
+<?php
+}
+
+function to_utf8($str, $charset)
+{
+       $n = iconv($charset ? $charset : 'iso-8859-1', 'utf-8', $str);
+       if ($n === false) {
+               return $str;
+       }
+       return $n;
+}
+
+/*
+if (function_exists("mb_convert_encoding")) {
+function to_utf8($str, $charset)
+{
+return mb_convert_encoding($str, "utf-8", strlen($charset) ? $charset : 
"iso-8859-1");
+}
+} else if (function_exists("recode_string")) {
+function to_utf8($str, $charset)
+{
+if (strlen($charset) == 0)
+$charset = "iso-8859-1";
+return recode_string("$charset..utf-8", $str);
+}
+} else if (function_exists("iconv")) {
+function to_utf8($str, $charset)
+{
+return iconv(strlen($charset) ? $charset : "iso-8859-1", "utf-8", $str);
+}
+} else {
+function to_utf8($str, $charset)
+{
+return $str;
+}
+}
+*/
+
+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("/=\\?(.+?)\\?([qb])\\?(.+?)(\\?=|$)/ie", 
"decode_header('\\1','\\2','\\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) {
+       $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(" ", "&nbsp;", 
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(" ", "&nbsp;", 
htmlspecialchars($ar[1], ENT_QUOTES, "UTF-8"))."</a>";
+       }
+       if (ereg("@",$a)) {
+               $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(" ", "&nbsp;", htmlspecialchars($a, ENT_QUOTES, 
"UTF-8"));
+}
+
+function format_subject($s, $charset) {
+       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 nl2br(htmlspecialchars($s, ENT_QUOTES, "UTF-8"));
+}
+
+
+function format_title($s, $charset) {
+       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 = strftime("%c", $d);
+       return str_replace(" ", "&nbsp;", $d);
+}
diff --git a/getpart.php b/getpart.php
index d7dfdfa..bc18b7f 100644
--- a/getpart.php
+++ b/getpart.php
@@ -1,7 +1,6 @@
 <?php
 
-require 'common.inc';
-require 'nntp.inc';
+require 'common.php';
 
 if (isset($_GET['group'])) {
        $group = preg_replace('@[^A-Za-z0-9.-]@', '', $_GET['group']);
diff --git a/group.php b/group.php
index 230ceea..de5feec 100644
--- a/group.php
+++ b/group.php
@@ -1,7 +1,6 @@
 <?php
 
-require 'common.inc';
-require 'nntp.inc';
+require 'common.php';
 
 if (isset($_GET['group'])) {
        $group = preg_replace('@[^A-Za-z0-9.-]@', '', $_GET['group']);
diff --git a/index.php b/index.php
index fc0ea5b..0795eb5 100644
--- a/index.php
+++ b/index.php
@@ -1,7 +1,6 @@
 <?php
 
-require 'common.inc';
-require 'nntp.inc';
+require 'common.php';
 
 $s = nntp_connect(NNTP_HOST);
 if (!$s) {
diff --git a/nntp.inc b/nntp.inc
deleted file mode 100644
index f6a59aa..0000000
--- a/nntp.inc
+++ /dev/null
@@ -1,23 +0,0 @@
-<?php
-
-function nntp_connect($server, $port = 119) {
-       $s = @fsockopen($server, $port, $errno, $errstr, 30);
-       if (!$s) {
-               return false;
-       }
-       $hello = fgets($s, 1024);
-       if (substr($hello,0,4) != "200 ") {
-               return false;
-       }
-       return $s;
-}
-
-function nntp_cmd($conn, $command, $expected) {
-       if (strlen($command) > 510) {
-               die("command too long: $command");
-       }
-       fputs($conn, "$command\r\n");
-       $res = fgets($conn, 1024);
-       list($code, $extra) = explode(" ", $res, 2);
-       return ($code == $expected) ? $extra : false;
-}
diff --git a/search.php b/search.php
index fd7eb8b..44cc39c 100644
--- a/search.php
+++ b/search.php
@@ -1,5 +1,5 @@
 <?php
-require 'common.inc';
+require 'common.php';
 
 $q = isset($_GET['q']) ? $_GET['q'] : false;
-- 
PHP Webmaster List Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to