commit 47de4853ff19541966b9b56a35494e7d0786433a
parent 07d15071016954cb54bc19f417df9068c305ce44
Author: dankert <devnull@localhost>
Date: Thu, 17 Feb 2005 22:20:47 +0100
Textformatierungen in eigene Klasse verlagert
Diffstat:
1 file changed, 11 insertions(+), 384 deletions(-)
diff --git a/objectClasses/Value.class.php b/objectClasses/Value.class.php
@@ -129,377 +129,7 @@ class Value
$this->languageid = $language->languageid;
}
-
- /**
- * Umwandeln von BB-Code in Wiki-Textauszeichnungen
- *
- * @param text zu bearbeitender Text
- *
- * @return String Ausgabe
- */
- function convert_bbcode( $inhalt )
- {
- $inhalt = eregi_replace('\[b\]([^\[]*)\[\/b\]' , '*\\1*' ,$inhalt);
- $inhalt = eregi_replace('\[i\]([^\[]*)\[\/i\]' , '_\\1_' ,$inhalt);
- $inhalt = eregi_replace('\[code\]([^\[]*)\[\/code\]' , '=\\1=' ,$inhalt);
-
- $inhalt = eregi_replace('\[url\]([^\[]*)[\/url\]' ,'"\\1"->"\\1"' ,$inhalt);
- $inhalt = eregi_replace('\[url=([^\[]*)\]([^\[]*)\[\/url\]','"\\2"->"\\1"' ,$inhalt);
- return $inhalt;
- }
-
-
- /**
- * Umwandeln von einfachen HTML-Befehlen in Wiki-Textauszeichnungen
- *
- * @param text zu bearbeitender Text
- *
- * @return String Ausgabe
- */
- function convert_html( $inhalt )
- {
- $inhalt = eregi_replace('<b(.*)>(.*)</b>','*\\2*' ,$inhalt);
- $inhalt = eregi_replace('<i(.*)>(.*)</i>','_\\2_' ,$inhalt);
- $inhalt = eregi_replace('<a(.*)href="(.*)">(.*)</a>','"\\3"->"\\2"' ,$inhalt);
- return $inhalt;
- }
-
-
- /**
- * Umwandeln von Wiki-Textauszeichnungen in HTML-Auszeichnungen
- *
- * @param text zu bearbeitender Text
- * @param html Boolean, ob HTML-Tags erlaubt sind
- *
- * @return String Ausgabe
- */
- function decode_wiki( $text,$html=false )
- {
- global $conf_languagedir,
- $conf_php;
- global $conf;
-
- $neu = array();
-
- $toc = array();
- $tocid = 0;
-
- $pre = false;
- $quote = false;
- $br = false;
- $ul = false;
- $ol = false;
- $li = true;
- $level = 0;
- $lis = array();
- $table = false;
- $p = false;
-
- // Links
- if ( $this->element->html )
- $pf = '>';
- else $pf = '&gt;';
-
- if ( $this->element->html )
- $pf = '>';
- else $pf = '&gt;';
-
- // Zeichenkette in die einzelnen Zeilen zerlegen
- $zeilen = explode("\n",$text);
-
- foreach( $zeilen as $zeile )
- {
- # Leer- und Sonderzeichen am Zeilenende entfernen
- $zeile = chop( $zeile );
-
- // Backtick am Zeilenbeginn schaltet Wikiauszeichnungen aus
- if ( substr($zeile,0,1) == '`' && !$pre )
- {
- $zeile = substr($zeile,1);
- $nowiki = true;
- }
- else
- {
- $nowiki = false;
- }
-
- // Zitat Anfang
- if ( $zeile == $pf && !$quote && !$pre )
- {
- if ( $p )
- {
- $neu[] = '</p>';
- $p = false;
- }
-
- $zeile = '<blockquote>';
- $quote = true;
- }
-
- // Zitat Ende
- if ( $zeile == $pf && $quote && !$pre )
- {
- if ( $p )
- {
- $neu[] = '</p>';
- $p = false;
- }
- $zeile = '</blockquote>';
- $quote = false;
- }
-
- // Pr?formatierter Text Anfang
- if ( $zeile == '=' && !$pre )
- {
- if ( $p )
- {
- $neu[] = '</p>';
- $p = false;
- }
-
- $zeile = '<pre>';
- $pre = true;
- }
-
- // Pr?formatierter Text Ende
- if ( $zeile == '=' && $pre )
- {
- $zeile = '</pre>';
- $pre = false;
- }
-
-
- // ?berschriften
- if ( preg_match('/^([+]{1,}) ?(.*)/',$zeile,$match) && !$nowiki && !$pre && !$quote )
- {
- if ( $p )
- {
- $neu[] = '</p>';
- $p = false;
- }
-
- $tocid++;
- $hlev = strlen($match[1]);
- $toc[] = array('level'=>$hlev,'id'=>$tocid,'text'=>$match[2]);
- $zeile = '<h'.$hlev.'><a name="toc'.$tocid.'"></a>'.$match[2].'</h'.$hlev.'>';
- }
-
- // Bei pr?formatierem Text keine weiteren Formatierungen durchf?hren
- if ( !$pre )
- {
- // Tabellen
- $beg = substr($zeile,0,1);
-
- if ( $beg == '|' )
- {
- if ( !$table )
- {
- if ( $p )
- {
- $neu[] = '</p>';
- $p = false;
- }
-
- $neu[] = '<table>';
- $table = true;
- }
-
- $zeile = ereg_replace( '^\|','<tr><td>',$zeile );
- $zeile = ereg_replace( '\|?$','</td></tr>',$zeile );
- $zeile = str_replace( '|','</td><td>',$zeile );
-
- // Spalten?bergreifende Zellen
- $zeile = str_replace('<td></td><td>','<td colspan\="2">',$zeile);
- for( $i=2; $i<=10; $i++)
- $zeile = str_replace('</td><td colspan\="'.$i.'"></td><td>','</td><td colspan\="'.($i+1).'">',$zeile);
-
- // Spalten-?berschriften <th>
- $zeile = eregi_replace( '<td([^<]*)>!([^<]+)</td>','<th\\1>\\2</th>',$zeile );
-
- // CSS-Klassen
- $zeile = eregi_replace( '<t([dh][^<]*)>\(([a-zA-Z0-9]+)\)([^<]+)</td>','<t\\1 class\="\\2">\\3</td>',$zeile );
- }
- else
- {
- if( $table )
- {
- $table = false;
- $neu[] = '</table>';
- }
- }
-
-
- // Aufz?hlungen
- if ( preg_match('/^( *)([\*#-]) (.*)/',$zeile,$match) && !$nowiki )
- {
- if ( $p )
- {
- $neu[] = '</p>';
- $p = false;
- }
-
- $lev = strlen($match[1])+1;
- $type = $match[2];
- $text = $match[3];
-
- if ( $level == $lev ) $neu[] = '</li>';
-
- while( $level < $lev )
- {
- $level++;
-
- if ( $match[2]=='#')
- $neu[] = '<ol class="level'.$level.'">';
- else $neu[] = '<ul class="level'.$level.'">';
-
- $lis[$level] = $match[2];
- }
-
- while( $level > $lev )
- {
- $neu[] = '</li>';
- if ( $lis[$level]=='#')
- $neu[] = '</ol>';
- else $neu[] = '</ul>';
-
- $level--;
- }
-
- $zeile = '<li>'.$text;
- }
- else
- {
- while( $level > 0 )
- {
- if ( $lis[$level]=='#')
- $neu[] = '</ol>';
- else $neu[] = '</ul>';
- $level--;
- }
- }
- }
-
-
- // Abs?tze einrichten
- if (!$pre && !$ol && !$ul && !$table && substr($zeile,0,1)!='<' )
- {
- if ( $zeile != '' && $p )
- {
- $neu[] = '<br/>';
- }
-
- if ( $zeile == '' && $p )
- {
- $neu[] = '</p>';
- $p = false;
- }
-
- if ( $zeile != '' && !$p )
- {
- $neu[] = '<p>';
- $p = true;
- }
- }
-
-
-
- // Textauszeichnungen fett,kursiv,fest
- if ( !$pre && !$nowiki ) // nicht bei praeformatiertem Text
- {
- $html = $conf['html'];
- // *Fett*
- $zeile = ereg_replace( '\*([^\*]+[^\\])\*' , $html['tag_strong_open'].'\\1'.$html['tag_strong_close'] , $zeile );
-
- // _kursiv_
- $zeile = ereg_replace( '_([^_]+[^\\])_' , $html['tag_emphatic_open'].'\\1'.$html['tag_emphatic_close'] , $zeile );
-
- // "Wortliche Rede"
- if ( !$html )
- $zeile = ereg_replace( '([^\-].{1,4})"([^"\-]+[^\\])"([^\-])', '\\1'.$html['tag_speech_open'].'\\2'.$html['tag_speech_close'].'\\3' , $zeile );
-
- // =feste Breite=
- $zeile = ereg_replace( '=([^=]+[^\\])=' , $html['tag_teletype_open'].'\\1'.$html['tag_teletype_close'] , $zeile );
-
-
- // Text->... umsetzen nach "Text"->... (Anfuehrungszeichen ergaenzen)
- $zeile = ereg_replace( '([A-Za-z0-9._????????-]+)-'.$pf, '"\\1"-'.$pf, $zeile );
-
- // ...->Link umsetzen nach ...->"Link" (Anfuehrungszeichen ergaenzen)
- $zeile = ereg_replace( '-'.$pf.'([A-Za-z0-9.:_\/\,\?\=\&-]+)', '-'.$pf.'"\\1"',$zeile );
-
- # Links ...->"nnn" ersetzen mit ...->"object:nnn"
- $zeile = ereg_replace( '-'.$pf.'\"([0-9]+)\"', '-'.$pf.'"object:\\1"', $zeile );
-
- // Links ->... url-kodieren
-// preg_match_all( '|-'.$pf.'\"([^\"]+)\"|',$zeile,$urls,PREG_SET_ORDER );
-// foreach( $urls as $url )
-// {
-// echo $url[1];
-// $urlneu = urlencode( $url[1] );
-// echo "wird zu $urlneu<br>";
-// $zeile = str_replace( $url[0],'-'.$pf.'"'.$urlneu.'"',$zeile );
-// }
-
- # Links "mit->..."
- $zeile = ereg_replace( '\"([^\"]+)\"-'.$pf.'\"([^\"]+)\"', '<a href="\\2">\\1</a>', $zeile );
-
- // alleinstehende externe Links
- $zeile = ereg_replace( '([^"])((https?|ftps?|news|gopher):\/\/([A-Za-z0-9._\/\,-]*))', '\\1<a href="\\2">\\4</a>', $zeile );
- $zeile = ereg_replace( '^((https?|ftps?|news|gopher):\/\/([A-Za-z0-9._\/\,-]*))', '<a href="\\1">\\3</a>', $zeile );
-
- // Einbinden von Bildern
- $zeile = ereg_replace( '(ima?ge?):\/?\/?(([0-9]+))(\{.*\})?', '<img src="object:\\2" class="text" alt="" />', $zeile );
- $zeile = ereg_replace( '{([0-9]+)}' , '<img src="object:\\1" class="text" alt="" />', $zeile );
-
- # mailto:...-Links
- $zeile = ereg_replace( '([A-Za-z0-9._-]+@[A-Za-z0-9._-]+)', '<a href="mailto:\\1">\\1</a>', $zeile );
-
- // Links object:nnn ersetzen
- preg_match_all( '|object:([0-9]+)|',$zeile,$objects,PREG_SET_ORDER );
- foreach( $objects as $object )
- {
- $var = $this->page->path_to_object( $object[1] );
- $zeile = str_replace( $object[0],$var,$zeile );
- }
-
- $zeile = ereg_replace( '([^\\\\])\\\\','\\1', $zeile );
- }
- $neu[] = $zeile;
- }
-
- if ( $ol ) $neu[] = '</ol>';
- if ( $ul ) $neu[] = '</ul>';
- if ( $table ) $neu[] = '</table>';
- if ( $pre ) $neu[] = '</pre>';
- if ( $p ) $neu[] = '</p>';
-
-
- $text = implode("\n",$neu);
-
- // Inhaltsverzeichnis
-
- $toctext = array();
- foreach( $toc as $t )
- {
- if ($t['level'] == 1 && count($toctext)>0) $toctext[] = '';
- $toctext[] = str_repeat(' ',$t['level']*2).'<a href="#toc'.$t['id'].'">'.$t['text'].'</a>';
- }
- $text = str_replace( '##TOC##',implode("<br/>\n",$toctext),$text ); // Inhaltsverzeichnis einf?gen
-
-// foreach( $ini_chars as $key=>$val)
-// {
-// $text = str_replace( chr($key),$val,$text );
-// }
- foreach( $conf['replace'] as $replace )
- {
- $repl = explode(',',$replace);
- if ( count($repl) == 2 )
- $text = str_replace( $repl[0],$repl[1],$text );
- }
-
- return $text;
- }
function path_to_page( $pageid )
@@ -895,26 +525,23 @@ class Value
$inhalt = $this->text;
+ // Wenn Inhalt leer, dann Vorbelegung verwenden
if ( $inhalt == '' )
$inhalt = $this->element->defaultText;
- // Wenn HTML nicht erlaubt ist, dann die HTML-Tags ersetzen
- if ( !$this->element->html )
- {
- //$inhalt = htmlentities($inhalt);
-
- $inhalt = str_replace('<','<' ,$inhalt);
- $inhalt = str_replace('>','>' ,$inhalt);
- $inhalt = str_replace('&','&',$inhalt);
- }
-
+ // Wenn HTML nicht erlaubt und Wiki-Formatierung aktiv, dann einfache HTML-Tags in Wiki umwandeln
if ( !$this->element->html && $this->element->wiki && $conf['wiki']['convert_html'] )
- $inhalt = $this->convert_html( $inhalt );
+ $inhalt = Text::html2Wiki( $inhalt );
+ // Wenn Wiki-Formatierung aktiv, dann BB-Code umwandeln
if ( $this->element->wiki && $conf['wiki']['convert_bbcode'] )
- $inhalt = $this->convert_bbcode( $inhalt );
-
- // Schnellformatierung ('Wiki') durchf?hren
+ $inhalt = Text::bbCode2Wiki( $inhalt );
+
+ // Wenn HTML nicht erlaubt ist, dann die HTML-Tags ersetzen
+ if ( !$this->element->html && !$this->element->wiki )
+ $inhalt = Text::encodeHtml( $inhalt );
+
+ // Schnellformatierung ('Wiki') durchfuehren
if ( $this->element->wiki )
{
$transformer = new Transformer();