Re: cvs: phpweb /include layout.inc

From: Date: Thu, 21 Aug 2003 13:50:06 +0000
Subject: Re: cvs: phpweb /include layout.inc
References: 1  Groups: php.mirrors 
Request: Send a blank email to php-mirrors+get-20528@lists.php.net to get a copy of this message
Hi Goba, Maybe you should add a little note in manual/add-note.php asking users to surround their code with <?php and ?> for the highlighting. didou Gabor Hojtsy wrote:
goba Thu Aug 21 09:16:34 2003 EDT
  Modified files:                  /phpweb/include	layout.inc   Log:
Apply patch sent by Cece: - use highlight_php() to highlight notes, so PHP code will
     be color coded in user note text
- better URL recognition, and open stuff in new window - drop code converting strings back and forth, and fixing old
     formatting stuff
  Index: phpweb/include/layout.inc
diff -u phpweb/include/layout.inc:1.187 phpweb/include/layout.inc:1.188 --- phpweb/include/layout.inc:1.187 Sat Aug 16 09:38:56 2003 +++ phpweb/include/layout.inc Thu Aug 21 09:16:34 2003 @@ -1,5 +1,5 @@ <?php -/* $Id: layout.inc,v 1.187 2003/08/16 13:38:56 goba Exp $ */ +/* $Id: layout.inc,v 1.188 2003/08/21 13:16:34 goba Exp $ */ // Set the static content root differently on php.net $_SERVER['STATIC_ROOT'] = ($MYSITE == 'http://www.php.net/') ? @@ -560,40 +560,19 @@ return htmlspecialchars(get_magic_quotes_gpc() ? stripslashes($var) : $var); } -function clean_note($text) {
-    $text = htmlspecialchars(trim($text));
-
-    /* turn urls into links */
-    $text = preg_replace("/((mailto|http|ftp|nntp|news):.+?)(&gt;|\\s|\\)|\"|\\.\\s|$)/","<a href=\"\\1\">\\1</a>\\3",$text);
+// Clean out the content of one user note for printing to HTML +function clean_note($text) +{
+    // Highlight PHP source
+    $text = highlight_php(trim($text), TRUE);
 -    /* this 'fixing' code will go away eventually. */
-    $fixes = array('<br>', '<p>', '</p>');
-    reset($fixes);
-    while (list(,$f)=each($fixes)) {
-        $text=str_replace(htmlspecialchars($f), $f, $text);
-        $text=str_replace(htmlspecialchars(strtoupper($f)), $f, $text);
-    }
-    -    /* <p> tags make things look awfully weird (breaks things out of the <code>
-       tag). Just convert them to <br>'s
-    */
-    $text = str_replace (array ('<P>', '<p>'), '<br>', $text);
-    -    /* Remove </p> tags to prevent it from showing up in the note */
-    $text = str_replace (array ('</P>', '</p>'), '', $text);
-
-    /* preserve linebreaks */
-    $text = str_replace("\n", "<br>", $text);
-
-    /* this will only break long lines */
-    if (function_exists("wordwrap")) {
-        $text = wordwrap($text);
-    }
+    // Turn urls into links
+    $text = preg_replace(
+        '!((mailto:|(http|ftp|nntp|news):\/\/).*?)(\s|<|\)|"|\\|\'|$)!',
+        '<a href="\1" target="_blank">\1</a>\4',
+        $text
+    );
     -    // Preserve spacing of user notes
-    $text = str_replace("  ", " &nbsp;", $text);
-
-    $text = "<code class=\"note\">".$text."</code>";
     return $text;
}


« previous php.mirrors (#20528) next »