00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 define( "EZ_INPUT_CHUNK_TEXT", 1 );
00037 define( "EZ_INPUT_CHUNK_TAG", 2 );
00038
00039 class eZTextInputParser
00040 {
00041
00042
00043
00044 function eZTextInputParser()
00045 {
00046
00047 }
00048
00049
00050
00051
00052
00053 function &parseText( &$text )
00054 {
00055 $returnArray = array();
00056 $pos = 0;
00057
00058 while ( $pos < strlen( $text ) )
00059 {
00060
00061 $tagStart = strpos( $text, "<", $pos );
00062
00063 if ( $tagStart !== false )
00064 {
00065 if ( ( $tagStart - $pos ) >= 1 )
00066 {
00067 $textChunk = substr( $text, $pos, $tagStart - $pos );
00068 $pos += $tagStart - $pos;
00069
00070
00071 if ( strlen( trim( $textChunk ) ) != 0 )
00072 {
00073 $returnArray[] = array( "Type" => EZ_INPUT_CHUNK_TEXT,
00074 "Text" => $textChunk,
00075 "TagName" => "#text" );
00076
00077 eZDebug::writeNotice( $textChunk, "New text chunk in input" );
00078 }
00079 }
00080
00081 $tagEnd = strpos( $text, ">", $pos );
00082 $tagChunk = substr( $text, $pos, $tagEnd - $pos + 1 );
00083 $tagName = preg_replace( "#^<(.+)?(\s.*|>)#m", "\\1", $tagChunk );
00084
00085
00086 if ( $tagName[0] == "/" )
00087 {
00088 print( "endtag" );
00089 }
00090
00091 $returnArray[] = array( "Type" => EZ_INPUT_CHUNK_TAG,
00092 "TagName" => $tagName,
00093 "Text" => $tagChunk,
00094 );
00095
00096 $pos += $tagEnd - $pos;
00097 eZDebug::writeNotice( $tagChunk, "New tag chunk in input" );
00098 }
00099 else
00100 {
00101
00102
00103 $textChunk = substr( $text, $pos, strlen( $text ) );
00104 eZDebug::writeNotice( $textChunk, "New text chunk in input" );
00105
00106 if ( strlen( trim( $textChunk ) ) != 0 )
00107 {
00108 $returnArray[] = array( "Type" => EZ_INPUT_CHUNK_TEXT,
00109 "Text" => $textChunk,
00110 "TagName" => "#text" );
00111 }
00112
00113 $pos = strlen( $text );
00114 }
00115
00116
00117
00118
00119 $pos++;
00120 }
00121 return $returnArray;
00122 }
00123
00124
00125 var $TagStack = array();
00126
00127
00128 var $InlineTags = array( "emphasize", "strong" );
00129
00130
00131 var $BreakTags = array();
00132 }
00133
00134 ?>