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
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00062 class Text
00063 {
00069 function maxLaenge( $laenge,$text )
00070 {
00071 return Text::maxLength($text,$laenge);
00072 }
00073
00074
00085 function maxLength( $text,$laenge=20,$append='...',$where=STR_PAD_RIGHT )
00086 {
00087 if ( strlen($text) > $laenge )
00088 {
00089 if ( $where == STR_PAD_RIGHT )
00090 $text = substr($text,0,$laenge).$append;
00091 elseif ( $where == STR_PAD_BOTH )
00092 $text = substr($text,0,$laenge/2).$append.substr($text,strlen($text)-($laenge/2));
00093 }
00094
00095 return $text;
00096 }
00097
00098
00106 function bbCode2Wiki( $inhalt )
00107 {
00108 $inhalt = eregi_replace('\[b\]([^\[]*)\[\/b\]' , '*\\1*' ,$inhalt);
00109 $inhalt = eregi_replace('\[i\]([^\[]*)\[\/i\]' , '_\\1_' ,$inhalt);
00110 $inhalt = eregi_replace('\[code\]([^\[]*)\[\/code\]' , '=\\1=' ,$inhalt);
00111
00112 $inhalt = eregi_replace('\[url\]([^\[]*)[\/url\]' ,'"\\1"->"\\1"' ,$inhalt);
00113 $inhalt = eregi_replace('\[url=([^\[]*)\]([^\[]*)\[\/url\]','"\\2"->"\\1"' ,$inhalt);
00114
00115 return $inhalt;
00116 }
00117
00118
00126 function Html2Wiki( $inhalt )
00127 {
00128 $inhalt = eregi_replace('<b(.*)>(.*)</b>','*\\2*' ,$inhalt);
00129 $inhalt = eregi_replace('<i(.*)>(.*)</i>','_\\2_' ,$inhalt);
00130 $inhalt = eregi_replace('<a(.*)href="(.*)">(.*)</a>','"\\3"->"\\2"' ,$inhalt);
00131
00132 return $inhalt;
00133 }
00134
00135
00142 function encodeHtml( $inhalt )
00143 {
00144 $inhalt = str_replace('&','&',$inhalt);
00145 $inhalt = str_replace('<','<' ,$inhalt);
00146 $inhalt = str_replace('>','>' ,$inhalt);
00147
00148 return $inhalt;
00149 }
00150
00151
00152
00157 function replaceHtmlChars( $text )
00158 {
00159 global $conf;
00160
00161 foreach( explode(' ',$conf['editor']['html']['replace']) as $repl )
00162 {
00163 list( $ersetze, $mit ) = explode(':',$repl.':');
00164 $text = str_replace($ersetze, $mit, $text);
00165 }
00166
00167 return $text;
00168 }
00169
00170
00171
00178 function encodeHtmlSpecialChars( $inhalt )
00179 {
00180 return Text::replaceHtmlChars( $inhalt );
00181 }
00182
00183
00184
00189 function diff( $from_text,$to_text )
00190 {
00191
00192 $pos_from = -1;
00193 $pos_to = -1;
00194
00195
00196 $from_out = array();
00197 $to_out = array();
00198
00199 while( true )
00200 {
00201 $pos_from++;
00202 $pos_to ++;
00203
00204 if ( !isset($from_text[$pos_from]) &&
00205 !isset($to_text [$pos_to ]) )
00206 {
00207
00208 break;
00209 }
00210 elseif
00211 ( isset($from_text[$pos_from]) &&
00212 !isset($to_text [$pos_to]) )
00213 {
00214
00215 while( isset($from_text[$pos_from]) )
00216 {
00217 $from_out[] = array('text'=>$from_text[$pos_from],'line'=>$pos_from+1,'type'=>'old');
00218 $to_out [] = array();
00219 $pos_from++;
00220 }
00221 break;
00222 }
00223 elseif
00224 ( !isset($from_text[$pos_from]) &&
00225 isset($to_text [$pos_to]) )
00226 {
00227
00228 while( isset($to_text[$pos_to]) )
00229 {
00230 $from_out[] = array();
00231 $to_out [] = array('text'=>$to_text[$pos_to],'line'=>$pos_to+1,'type'=>'new');
00232 $pos_to++;
00233 }
00234 break;
00235 }
00236 elseif
00237 ( rtrim($from_text[$pos_from]) != rtrim($to_text[$pos_to]) )
00238 {
00239
00240
00241 $max_entf = min(count($from_text)-$pos_from-1,count($to_text)-$pos_to-1);
00242
00243 #echo "suche start, max_entf=$max_entf, pos_from=$pos_from, pos_to=$pos_to<br/>";
00244
00245 for ( $a=0; $a<=$max_entf; $a++ )
00246 {
00247 #echo "a ist $a<br/>";
00248 for ( $b=0; $b<=$max_entf; $b++ )
00249 {
00250 #echo "b ist $b<br/>";
00251 if ( trim($from_text[$pos_from+$b]) != '' &&
00252 $from_text[$pos_from+$b] == $to_text[$pos_to+$a] )
00253 {
00254 $pos_gef_from = $pos_from+$b;
00255 $pos_gef_to = $pos_to +$a;
00256 break;
00257 }
00258
00259 if ( trim($from_text[$pos_from+$a]) != '' &&
00260 $from_text[$pos_from+$a] == $to_text[$pos_to+$b] )
00261 {
00262 $pos_gef_from = $pos_from+$a;
00263 $pos_gef_to = $pos_to +$b;
00264 break;
00265 }
00266 }
00267
00268 if ( $b <=$max_entf)
00269 {
00270 break;
00271 }
00272 }
00273
00274 if ( $a<=$max_entf )
00275 {
00276
00277 #echo "gefunden, pos_gef_from=$pos_gef_from, pos_gef_to=$pos_gef_to<br/>";
00278
00279 if ( $pos_gef_from - $pos_from == 0 )
00280 $type = 'new';
00281 elseif
00282 ( $pos_gef_to - $pos_to == 0 )
00283 $type = 'old';
00284 else
00285 $type = 'notequal';
00286
00287 while( $pos_gef_from - $pos_from > 0 &&
00288 $pos_gef_to - $pos_to > 0 )
00289 {
00290 $from_out[] = array('text'=>$from_text[$pos_from],'line'=>$pos_from+1,'type'=>$type);
00291 $to_out [] = array('text'=>$to_text [$pos_to ],'line'=>$pos_to+1 ,'type'=>$type);
00292
00293 $pos_from++;
00294 $pos_to++;
00295 }
00296
00297 while( $pos_gef_from - $pos_from > 0 )
00298 {
00299 $from_out[] = array('text'=>$from_text[$pos_from],'line'=>$pos_from+1,'type'=>$type);
00300 $to_out [] = array();
00301 $pos_from++;
00302 }
00303
00304 while( $pos_gef_to - $pos_to > 0 )
00305 {
00306 $from_out[] = array();
00307 $to_out [] = array('text'=>$to_text [$pos_to ],'line'=>$pos_to+1 ,'type'=>$type);
00308 $pos_to++;
00309 }
00310 $pos_from--;
00311 $pos_to--;
00312 }
00313 else
00314 {
00315
00316 #echo "nicht gefunden, i=$i, j=$j, pos_from war $pos_from, pos_to war $pos_to<br/>";
00317
00318 while( true )
00319 {
00320 if ( !isset($from_text[$pos_from]) &&
00321 !isset($to_text [$pos_to ]) )
00322 {
00323 break;
00324 }
00325 elseif
00326 ( isset($from_text[$pos_from]) &&
00327 !isset($to_text [$pos_to ]) )
00328 {
00329 $from_out[] = array('text'=>$from_text[$pos_from],'line'=>$pos_from+1,'type'=>'notequal');
00330 $to_out [] = array();
00331 }
00332 elseif
00333 ( !isset($from_text[$pos_from]) &&
00334 isset($to_text [$pos_to ]) )
00335 {
00336 $from_out[] = array();
00337 $to_out [] = array('text'=>$to_text [$pos_to ],'line'=>$pos_to+1 ,'type'=>'notequal');
00338 }
00339 else
00340 {
00341 $from_out[] = array('text'=>$from_text[$pos_from],'line'=>$pos_from+1,'type'=>'notequal');
00342 $to_out [] = array('text'=>$to_text [$pos_to ],'line'=>$pos_to+1 ,'type'=>'notequal');
00343 }
00344 $pos_from++;
00345 $pos_to++;
00346 }
00347 }
00348 }
00349 else
00350 {
00351
00352 $from_out[] = array('text'=>$from_text[$pos_from],'line'=>$pos_from+1,'type'=>'equal');
00353 $to_out [] = array('text'=>$to_text [$pos_to ],'line'=>$pos_to+1 ,'type'=>'equal');
00354 }
00355 }
00356
00357 return( array($from_out,$to_out) );
00358 }
00359
00360
00361 function entferneVonBis($text,$von,$bis)
00362 {
00363 $beg = strpos($text,$von);
00364 $end = strpos($text,$bis);
00365 if ( $beg!==false && $end !==false )
00366 $text = substr($src,0,$beg).substr($src,$end);
00367 return $text;
00368 }
00369 }
00370
00371
00372 ?>