From 4e17e6c9dbac8991ee8b302cb2581241247dc8bc Mon Sep 17 00:00:00 2001 From: thomascube Date: Sun, 25 Sep 2005 14:18:03 +0000 Subject: Initial revision --- program/lib/enriched.inc | 114 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 program/lib/enriched.inc (limited to 'program/lib/enriched.inc') diff --git a/program/lib/enriched.inc b/program/lib/enriched.inc new file mode 100644 index 000000000..2435a8233 --- /dev/null +++ b/program/lib/enriched.inc @@ -0,0 +1,114 @@ +'=>'',''=>'',''=>'', + ''=>'',''=>'',''=>'', + ''=>'',''=>'', + ''=>'',''=>'', + ''=>'', + ''=>'', + ''=>'', + ''=>'', + ''=>'', + ''=>'', + ''=>'', + ''=>'', + ''=>'', + ''=>'', + ''=>'', + ''=>''); + + while(list($find,$replace)=each($a)){ + $body = eregi_replace($find,$replace,$body); + } + return $body; +} + +function enriched_font($body){ + $pattern = '/(.*)\\(.*)\<\/param\>(.*)\<\/fontfamily\>(.*)/ims'; + while(preg_match($pattern,$body,$a)){ + //print_r($a); + if (count($a)!=5) continue; + $body=$a[1].''.$a[3].''.$a[4]; + } + + return $body; +} + + +function enriched_color($body){ + $pattern = '/(.*)\\(.*)\<\/param\>(.*)\<\/color\>(.*)/ims'; + while(preg_match($pattern,$body,$a)){ + //print_r($a); + if (count($a)!=5) continue; + + //extract color (either by name, or ####,####,####) + if (strpos($a[2],',')){ + $rgb = explode(',',$a[2]); + $color ='#'; + for($i=0;$i<3;$i++) $color.=substr($rgb[$i],0,2); //just take first 2 bytes + }else{ + $color = $a[2]; + } + + //put it all together + $body = $a[1].''.$a[3].''.$a[4]; + } + + return $body; +} + +function enriched_excerpt($body){ + + $pattern = '/(.*)\(.*)\<\/excerpt\>(.*)/i'; + while(preg_match($pattern,$body,$a)){ + //print_r($a); + if (count($a)!=4) continue; + $quoted = ''; + $lines = explode('
',$a[2]); + foreach($lines as $n=>$line) $quoted.='>'.$line.'
'; + $body=$a[1].''.$quoted.''.$a[3]; + } + + return $body; +} + +function enriched_to_html($body){ + $body = str_replace('<<','<',$body); + $body = enriched_convert_newlines($body); + $body = str_replace("\n", '
', $body); + $body = enriched_convert_formatting($body); + $body = enriched_color($body); + $body = enriched_font($body); + $body = enriched_excerpt($body); + //$body = nl2br($body); + return $body; +} + +?> \ No newline at end of file -- cgit v1.2.3