eZ Publish  [4.0]
eztexttool.php
Go to the documentation of this file.
00001 <?php
00002 //
00003 // Definition of eZTextTool class
00004 //
00005 // Created on: <04-Jun-2002 09:12:36 bf>
00006 //
00007 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00008 // SOFTWARE NAME: eZ Publish
00009 // SOFTWARE RELEASE: 4.0.x
00010 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS
00011 // SOFTWARE LICENSE: GNU General Public License v2.0
00012 // NOTICE: >
00013 //   This program is free software; you can redistribute it and/or
00014 //   modify it under the terms of version 2.0  of the GNU General
00015 //   Public License as published by the Free Software Foundation.
00016 //
00017 //   This program is distributed in the hope that it will be useful,
00018 //   but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 //   GNU General Public License for more details.
00021 //
00022 //   You should have received a copy of version 2.0 of the GNU General
00023 //   Public License along with this program; if not, write to the Free
00024 //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00025 //   MA 02110-1301, USA.
00026 //
00027 //
00028 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00029 //
00030 
00031 /*!
00032   \class eZTextTool eztexttool.php
00033   \ingroup eZUtils
00034   \brief eZTextTool is a class with different useful text functions
00035 
00036 */
00037 
00038 class eZTextTool
00039 {
00040     /*!
00041      \static
00042      Returns an HTML highlighted and displayable formatted HTML from the
00043      input text. < and > are converted to &lt; and &gt;
00044     */
00045     function highlightHTML( $input )
00046     {
00047         $input = str_replace( "<", "&lt;", $input );
00048         $input = str_replace( ">", "&gt;", $input );
00049 
00050         $input = preg_replace( "#&lt;(.*?)&gt;#m", "<font color='red'>&lt;$1&gt;</font>", $input );
00051 
00052         return $input;
00053     }
00054 
00055     function highlightPHP()
00056     {
00057 
00058     }
00059 
00060     function concatDelimited()
00061     {
00062         $numargs = func_num_args();
00063         $argList = func_get_args();
00064         $text = null;
00065         if ( $numargs > 1 )
00066         {
00067             $delimit = $argList[0];
00068             $text = implode( $delimit, eZTextTool::arrayFlatten( array_splice( $argList, 1 ) ) );
00069         }
00070         return $text;
00071     }
00072 
00073     function concat()
00074     {
00075         $numargs = func_num_args();
00076         $argList = func_get_args();
00077         $text = null;
00078         if ( $numargs > 0 )
00079         {
00080             $text = implode( '', eZTextTool::arrayFlatten( $argList ) );
00081         }
00082         return $text;
00083     }
00084 
00085     function arrayFlatten( $array )
00086     {
00087         $flatArray = array();
00088         $expandItems = $array;
00089         $done = false;
00090         while ( !$done )
00091         {
00092             $checkList = $expandItems;
00093             $leftOvers = array();
00094             $foundArray = false;
00095             foreach ( array_keys( $checkList ) as $key )
00096             {
00097                 $item = $checkList[$key];
00098                 if ( is_array ( $item ) )
00099                 {
00100                     $leftOvers = array_merge( $leftOvers, $item );
00101                     $foundArray = true;
00102                 }
00103                 else
00104                 {
00105                     if ( $foundArray )
00106                         $leftOvers[] = $item;
00107                     else
00108                         $flatArray[] = $item;
00109                 }
00110             }
00111             $expandItems = $leftOvers;
00112             if ( count( $expandItems ) == 0 )
00113             {
00114                 $done = true;
00115             }
00116         }
00117         return $flatArray;
00118     }
00119 }
00120 ?>