[geeklog-hg] geeklog: Removed preg_replace /e modifier

geeklog-cvs at lists.geeklog.net geeklog-cvs at lists.geeklog.net
Tue Jan 7 08:12:24 EST 2014


changeset 9393:82d33677cf71
url:  http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/82d33677cf71
user: Kenji ITO <mystralkk at gmail.com>
date: Tue Jan 07 22:11:56 2014 +0900
description:
Removed preg_replace /e modifier

diffstat:

 plugins/spamx/BlackList.Examine.class.php |  16 ++++++-
 public_html/lib-common.php                |  20 ++++++--
 system/classes/search.class.php           |  64 ++++++++++++++++--------------
 3 files changed, 62 insertions(+), 38 deletions(-)

diffs (267 lines):

diff -r 1bfa6d5d4181 -r 82d33677cf71 plugins/spamx/BlackList.Examine.class.php
--- a/plugins/spamx/BlackList.Examine.class.php	Tue Jan 07 03:14:29 2014 +0900
+++ b/plugins/spamx/BlackList.Examine.class.php	Tue Jan 07 22:11:56 2014 +0900
@@ -33,6 +33,18 @@
     /**
      * No Constructor Use BaseCommand constructor
      */
+
+    // Callback functions for preg_replace_callback()
+    protected function callbackDecimal($str)
+    {
+        return chr($str);
+    }
+
+    protected function callbackHex($str)
+    {
+        return chr('0x' . $str);
+    }
+
     /**
      * Here we do the work
      */
@@ -55,9 +67,9 @@
         // named entities
         $comment = html_entity_decode ($comment);
         // decimal notation
-        $comment = preg_replace ('/&#(\d+);/me', "chr(\\1)", $comment);
+        $comment = preg_replace_callback('/&#(\d+);/m', array($this, 'callbackDecimal'), $comment);
         // hex notation
-        $comment = preg_replace ('/&#x([a-f0-9]+);/mei', "chr(0x\\1)", $comment);
+        $comment = preg_replace_callback('/&#x([a-f0-9]+);/mi', array($this, 'callbackHex'), $comment);
         $ans = 0;
         for ($i = 1; $i <= $nrows; $i++) {
             list ($val) = DB_fetchArray ($result);
diff -r 1bfa6d5d4181 -r 82d33677cf71 public_html/lib-common.php
--- a/public_html/lib-common.php	Tue Jan 07 03:14:29 2014 +0900
+++ b/public_html/lib-common.php	Tue Jan 07 22:11:56 2014 +0900
@@ -6918,15 +6918,23 @@
     // they should NOT be used for validating links.
 
     // matches anything starting with http:// or https:// or ftp:// or ftps://
-    $regex[] = '/(?<=^|[\n\r\t\s\(\)\[\]<>";])((?:(?:ht|f)tps?:\/{2})(?:[^\n\r\t\s\(\)\[\]<>"&]+(?:&)?)+)(?=[\n\r\t\s\(\)\[\]<>"&]|$)/ei';
-    $replace[] = "COM_makeClickableLinksCallback('', '\\1')";
+    $regex = '/(?<=^|[\n\r\t\s\(\)\[\]<>";])((?:(?:ht|f)tps?:\/{2})(?:[^\n\r\t\s\(\)\[\]<>"&]+(?:&)?)+)(?=[\n\r\t\s\(\)\[\]<>"&]|$)/i';
+    $replace = create_function(
+        '$match',
+        'return COM_makeClickableLinksCallback(\'\', $match[1]);'
+    );
+
+    $text = preg_replace_callback($regex, $replace, $text);
 
     // matches anything containing a top level domain: xxx.com or xxx.yyy.net/stuff.php or xxx.yyy.zz
     // list taken from: http://en.wikipedia.org/wiki/List_of_Internet_TLDs
-    $regex[] = '/(?<=^|[\n\r\t\s\(\)\[\]<>";])((?:[a-z0-9]+\.)*[a-z0-9]+\.(?:aero|asia|biz|cat|com|coop|edu|gov|info|int|jobs|mil|mobi|museum|name|net|org|pro|tel|travel|[a-z]{2})(?:[\/?#](?:[^\n\r\t\s\(\)\[\]<>"&]+(?:&)?)*)?)(?=[\n\r\t\s\(\)\[\]<>"&]|$)/ei';
-    $replace[] = "COM_makeClickableLinksCallback('http://', '\\1')";
-
-    $text = preg_replace( $regex, $replace, $text );
+    $regex = '/(?<=^|[\n\r\t\s\(\)\[\]<>";])((?:[a-z0-9]+\.)*[a-z0-9]+\.(?:aero|asia|biz|cat|com|coop|edu|gov|info|int|jobs|mil|mobi|museum|name|net|org|post|pro|tel|travel|[a-z]{2})(?:[\/?#](?:[^\n\r\t\s\(\)\[\]<>"&]+(?:&)?)*)?)(?=[\n\r\t\s\(\)\[\]<>"&]|$)/i';
+    $replace = create_function(
+        '$match',
+        'return COM_makeClickableLinksCallback(\'http://\', $match[1]);'
+    );
+
+    $text = preg_replace_callback($regex, $replace, $text);
 
     return $text;
 }
diff -r 1bfa6d5d4181 -r 82d33677cf71 system/classes/search.class.php
--- a/system/classes/search.class.php	Tue Jan 07 03:14:29 2014 +0900
+++ b/system/classes/search.class.php	Tue Jan 07 22:11:56 2014 +0900
@@ -46,8 +46,8 @@
 * @package net.geeklog.search
 *
 */
-class Search {
-
+class Search
+{
     // PRIVATE VARIABLES
     private $_query = '';
     private $_topic = '';
@@ -70,10 +70,9 @@
     * Sets up private search variables
     *
     * @author Tony Bibbs, tony AT geeklog DOT net
-    * @access public
     *
     */
-    function Search()
+    public function __construct()
     {
         global $_CONF, $_TABLES;
 
@@ -128,11 +127,10 @@
     * This performs those checks
     *
     * @author Tony Bibbs, tony AT geeklog DOT net
-    * @access private
     * @return boolean True if search is allowed, otherwise false
     *
     */
-    function _isSearchAllowed()
+    private function _isSearchAllowed()
     {
         global $_CONF;
 
@@ -160,11 +158,10 @@
     * This performs those checks
     *
     * @author Dirk Haun, dirk AT haun-online DOT de
-    * @access private
     * @return boolean True if form usage is allowed, otherwise false
     *
     */
-    function _isFormAllowed ()
+    private function _isFormAllowed()
     {
         global $_CONF;
 
@@ -181,11 +178,10 @@
     * Shows advanced search page
     *
     * @author Tony Bibbs, tony AT geeklog DOT net
-    * @access public
     * @return string HTML output for form
     *
     */
-    function showForm ()
+    public function showForm()
     {
         global $_CONF, $_TABLES, $LANG09;
 
@@ -324,11 +320,10 @@
     /**
     * Performs search on all stories
     *
-    * @access private
     * @return object plugin object
     *
     */
-    function _searchStories()
+    private function _searchStories()
     {
         global $_TABLES, $_DB_dbms, $LANG09;
         
@@ -423,11 +418,10 @@
     * in this function to allow legacy support to plugins using
     * the old API calls defined versions prior to Geeklog 1.5.1
     *
-    * @access public
     * @return string HTML output for search results
     *
     */
-    function doSearch()
+    public function doSearch()
     {
         global $_CONF, $LANG01, $LANG09, $LANG31;
 
@@ -687,12 +681,11 @@
     * each row accordingly for example pulling usernames from the
     * users table and displaying a link to their profile.
     *
-    * @access public
     * @param array $row An array of plain data to format
     * @return array A reformatted version of the input array
     *
     */
-    function searchFormatCallback( $preSort, $row )
+    public function searchFormatCallback($preSort, $row)
     {
         global $_CONF, $LANG09;
 
@@ -768,14 +761,13 @@
     * version depending where the text was cut. Works on a
     * word basis, so long words wont get cut.
     *
-    * @access private
     * @param string $keyword The word to centre around
     * @param string $text The complete text string
     * @param int $num_words The number of words to display, best to use an odd number
     * @return string A short version of the text
     *
     */
-    function _shortenText($keyword, $text, $num_words = 7)
+    private function _shortenText($keyword, $text, $num_words = 7)
     {
         $text = COM_getTextContent($text);
         $words = explode(' ', $text);
@@ -853,10 +845,9 @@
     * @param   string  $needle    keyword(s), separated by spaces
     * @param   array   $haystack  array of words to search through
     * @return  mixed              index in $haystack or false when not found
-    * @access  private
     *
     */
-    function _arraySearch($needle, $haystack)
+    private function _arraySearch($needle, $haystack)
     {
         $keywords = explode(' ', $needle);
         $num_keywords = count($keywords);
@@ -890,13 +881,12 @@
     * number of similar heading names. Used for backwards
     * compatibility in the doSearch() function.
     *
-    * @access private
     * @param array $headings All the headings
     * @param array $find An array of alternative headings to find
     * @return int The index of the alternative heading
     *
     */
-    function _findColumn( $headings, $find )
+    private function _findColumn($headings, $find)
     {
         // We can't use normal for loops here as some of the
         // heading indexes start from 1, so foreach works better
@@ -914,29 +904,43 @@
         return -1;
     }
 
+    private function _convertsqlCallback($replace, $match)
+    {
+        return preg_replace('/,?(\'[^\']+\'|[^,]+),/i', $replace, $match);
+    }
+
     /**
     * Converts the MySQL CONCAT function to the MS SQL / Postgres equivalents
     *
-    * @access private
     * @param  string $sql The SQL to convert
     * @return string      MS SQL or PostgreSQL friendly SQL
     *
     */
-    function _convertsql($sql)
+    private function _convertsql($sql)
     {
         global $_DB_dbms;
 
-        if ($_DB_dbms == 'mssql') {
+        if ($_DB_dbms === 'mssql') {
+            $callback = create_function(
+                '$match',
+                'return $this->_convertsqlCallback(\'\\\\1 + \', $match[1]);'
+            );
+
             if (is_string($sql)) {
-                $sql = preg_replace("/CONCAT\(([^\)]+)\)/ie", "preg_replace('/,?(\'[^\']+\'|[^,]+),/i', '\\\\1 + ', '\\1')", $sql);
+                $sql = preg_replace_callback("/CONCAT\(([^\)]+)\)/i", $callback, $sql);
             } elseif (is_array($sql)) {
-                $sql['mssql'] = preg_replace("/CONCAT\(([^\)]+)\)/ie", "preg_replace('/,?(\'[^\']+\'|[^,]+),/i', '\\\\1 + ', '\\1')", $sql['mssql']);
+                $sql['mssql'] = preg_replace_callback("/CONCAT\(([^\)]+)\)/i", $callback, $sql['mssql']);
             }
-        } elseif ($_DB_dbms == 'pgsql') {
+        } elseif ($_DB_dbms === 'pgsql') {
+            $callback = create_function(
+                '$match',
+                'return $this->_convertsqlCallback(\'\\\\1 || \', $match[1]);'
+            );
+
             if (is_string($sql)) {
-                $sql = preg_replace("/CONCAT\(([^\)]+)\)/ie", "preg_replace('/,?(\'[^\']+\'|[^,]+),/i', '\\\\1 || ', '\\1')", $sql);
+                $sql = preg_replace_callback("/CONCAT\(([^\)]+)\)/i", $callback, $sql);
             } elseif (is_array($sql)) {
-                $sql['pgsql'] = preg_replace("/CONCAT\(([^\)]+)\)/ie", "preg_replace('/,?(\'[^\']+\'|[^,]+),/i', '\\\\1 || ', '\\1')", $sql['pgsql']);
+                $sql['pgsql'] = preg_replace_callback("/CONCAT\(([^\)]+)\)/i", $callback, $sql['pgsql']);
             }
         }
 



More information about the geeklog-cvs mailing list