[geeklog-cvs] geeklog: Avoid using preg_replace where str_replace is sufficien...

geeklog-cvs at lists.geeklog.net geeklog-cvs at lists.geeklog.net
Mon Jan 12 04:22:41 EST 2009


details:   http://project.geeklog.net/cgi-bin/hgweb.cgi/rev/ea5e93e5bb47
changeset: 6669:ea5e93e5bb47
user:      Dirk Haun <dirk at haun-online.de>
date:      Sat Jan 10 10:29:04 2009 +0100
description:
Avoid using preg_replace where str_replace is sufficient (cf. bug #0000794)

diffstat:

4 files changed, 19 insertions(+), 24 deletions(-)
public_html/lib-common.php            |   11 +++++------
sql/updates/mysql_1.3.9_to_1.3.10.php |    2 +-
system/lib-syndication.php            |   22 ++++++++++------------
system/lib-trackback.php              |    8 +++-----

diffs (156 lines):

diff -r bcb391cc856b -r ea5e93e5bb47 public_html/lib-common.php
--- a/public_html/lib-common.php	Sat Jan 10 10:15:58 2009 +0100
+++ b/public_html/lib-common.php	Sat Jan 10 10:29:04 2009 +0100
@@ -3283,9 +3283,8 @@
             {
                 if( $day != 'noday' )
                 {
-                    $daylist = COM_makeList( $oldnews, 'list-older-stories' );
-                    $daylist = preg_replace( "/(\015\012)|(\015)|(\012)/",
-                                             '', $daylist );
+                    $daylist = COM_makeList($oldnews, 'list-older-stories');
+                    $daylist = str_replace(array("\015", "\012"), '', $daylist);
                     $string .= $daylist . '<br' . XHTML . '>';
                 }
 
@@ -3304,8 +3303,8 @@
 
         if( !empty( $oldnews ))
         {
-            $daylist = COM_makeList( $oldnews, 'list-older-stories' );
-            $daylist = preg_replace( "/(\015\012)|(\015)|(\012)/", '', $daylist );
+            $daylist = COM_makeList($oldnews, 'list-older-stories');
+            $daylist = str_replace(array("\015", "\012"), '', $daylist);
             $string .= $daylist;
             $string = addslashes( $string );
 
@@ -3759,7 +3758,7 @@
 
         // build a list
         $content = COM_makeList($articles, 'list-feed');
-        $content = preg_replace("/(\015\012)|(\015)|(\012)/", '', $content);
+        $content = str_replace(array("\015", "\012"), '', $content);
 
         if (strlen($content) > 65000) {
             $content = $LANG21[68];
diff -r bcb391cc856b -r ea5e93e5bb47 sql/updates/mysql_1.3.9_to_1.3.10.php
--- a/sql/updates/mysql_1.3.9_to_1.3.10.php	Sat Jan 10 10:15:58 2009 +0100
+++ b/sql/updates/mysql_1.3.9_to_1.3.10.php	Sat Jan 10 10:29:04 2009 +0100
@@ -111,7 +111,7 @@
         }
 
         $rel[] = '<a href="' . $matches[1][$i] . '">'
-               . str_replace ("/(\015\012)|(\015)|(\012)/", '', $matches[2][$i])
+               . str_replace(array("\015", "\012"), '', $matches[2][$i])
                . '</a>';
     }
 
diff -r bcb391cc856b -r ea5e93e5bb47 system/lib-syndication.php
--- a/system/lib-syndication.php	Sat Jan 10 10:15:58 2009 +0100
+++ b/system/lib-syndication.php	Sat Jan 10 10:29:04 2009 +0100
@@ -2,13 +2,13 @@
 
 /* Reminder: always indent with 4 spaces (no tabs). */
 // +---------------------------------------------------------------------------+
-// | Geeklog 1.5                                                               |
+// | Geeklog 1.6                                                               |
 // +---------------------------------------------------------------------------+
 // | lib-syndication.php                                                       |
 // |                                                                           |
 // | Geeklog syndication library.                                              |
 // +---------------------------------------------------------------------------+
-// | Copyright (C) 2003-2008 by the following authors:                         |
+// | Copyright (C) 2003-2009 by the following authors:                         |
 // |                                                                           |
 // | Authors: Dirk Haun        - dirk AT haun-online DOT de                    |
 // |          Michael Jervis   - mike AT fuckingbrit DOT com                   |
@@ -29,11 +29,6 @@
 // | Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.           |
 // |                                                                           |
 // +---------------------------------------------------------------------------+
-//
-// $Id: lib-syndication.php,v 1.45 2008/09/21 08:37:12 dhaun Exp $
-
-// set to true to enable debug output in error.log
-$_SYND_DEBUG = false;
 
 if (strpos(strtolower($_SERVER['PHP_SELF']), 'lib-syndication.php') !== false) {
     die('This file can not be used on its own!');
@@ -42,6 +37,9 @@
 if ($_CONF['trackback_enabled']) {
     require_once $_CONF['path_system'] . 'lib-trackback.php';
 }
+
+// set to true to enable debug output in error.log
+$_SYND_DEBUG = false;
 
 /**
 * Check if a feed for all stories needs to be updated.
@@ -270,8 +268,8 @@
             $storytext = SYND_truncateSummary( $fulltext, $contentLength );
 
             $fulltext = trim( $fulltext );
-            $fulltext = preg_replace( "/(\015)/", "", $fulltext );
-            
+            $fulltext = str_replace("\015", '', $fulltext);
+
             if( $row['postmode'] == 'plaintext' ) 
             {
                 if( !empty($storytext) )
@@ -393,8 +391,8 @@
         $fulltext = PLG_replaceTags( $fulltext );
         $storytext = SYND_truncateSummary( $fulltext, $contentLength );
         $fulltext = trim( $fulltext );
-        $fulltext = preg_replace( "/(\015)/", "", $fulltext );
-        
+        $fulltext = str_replace("\015", '', $fulltext);
+
         if( $row['postmode'] == 'plaintext' ) 
         {
             if( !empty($storytext) )
@@ -622,7 +620,7 @@
     {
         $text = stripslashes( $text );
         $text = trim( $text );
-        $text = preg_replace( "/(\015)/", "", $text );
+        $text = str_replace("\015", '', $text);
         if(( $length > 3 ) && ( MBYTE_strlen( $text ) > $length ))
         {
             $text = substr( $text, 0, $length - 3 ) . '...';
diff -r bcb391cc856b -r ea5e93e5bb47 system/lib-trackback.php
--- a/system/lib-trackback.php	Sat Jan 10 10:15:58 2009 +0100
+++ b/system/lib-trackback.php	Sat Jan 10 10:29:04 2009 +0100
@@ -2,13 +2,13 @@
 
 /* Reminder: always indent with 4 spaces (no tabs). */
 // +---------------------------------------------------------------------------+
-// | Geeklog 1.5                                                               |
+// | Geeklog 1.6                                                               |
 // +---------------------------------------------------------------------------+
 // | lib-trackback.php                                                         |
 // |                                                                           |
 // | Functions needed to handle trackback comments.                            |
 // +---------------------------------------------------------------------------+
-// | Copyright (C) 2005-2008 by the following authors:                         |
+// | Copyright (C) 2005-2009 by the following authors:                         |
 // |                                                                           |
 // | Author: Dirk Haun - dirk AT haun-online DOT de                            |
 // +---------------------------------------------------------------------------+
@@ -28,8 +28,6 @@
 // | Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.           |
 // |                                                                           |
 // +---------------------------------------------------------------------------+
-//
-// $Id: lib-trackback.php,v 1.52 2008/09/21 08:37:12 dhaun Exp $
 
 if (strpos(strtolower($_SERVER['PHP_SELF']), 'lib-trackback.php') !== false) {
     die('This file can not be used on its own!');
@@ -861,7 +859,7 @@
     // no luck with the RDF? try searching for a rel="trackback" link
     if ($retval === false) {
         // remove all linefeeds first to help the regexp below
-        $page = preg_replace( "/(\015\012)|(\015)|(\012)/", '', $page);
+        $page = str_replace(array("\015", "\012"), '', $page);
 
         preg_match_all( "/<a[^>]*href=[\"']([^\"']*)[\"'][^>]*>(.*?)<\/a>/i", $page, $matches );
         for ($i = 0; $i < count ($matches[0]); $i++) {



More information about the geeklog-cvs mailing list