diff options
| author | bitweaver.org <bitweaver@users.sourceforge.net> | 2005-06-19 04:55:51 +0000 |
|---|---|---|
| committer | bitweaver.org <bitweaver@users.sourceforge.net> | 2005-06-19 04:55:51 +0000 |
| commit | 9263d2df0226a118f4add4664d746a266ce5aa78 (patch) | |
| tree | 7bc560ee5a4111a80f7b4ecd23afe53278cfd352 /plugins/format.tikihtml.php | |
| download | liberty-9263d2df0226a118f4add4664d746a266ce5aa78.tar.gz liberty-9263d2df0226a118f4add4664d746a266ce5aa78.tar.bz2 liberty-9263d2df0226a118f4add4664d746a266ce5aa78.zip | |
IMPORT TikiPro CLYDE FINAL
Diffstat (limited to 'plugins/format.tikihtml.php')
| -rw-r--r-- | plugins/format.tikihtml.php | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/plugins/format.tikihtml.php b/plugins/format.tikihtml.php new file mode 100644 index 0000000..e25a079 --- /dev/null +++ b/plugins/format.tikihtml.php @@ -0,0 +1,82 @@ +<?php +global $gLibertySystem; + +define( 'PLUGIN_GUID_BITHTML', 'bithtml' ); + +$pluginParams = array ( 'store_function' => 'bithtml_save_data', + 'load_function' => 'bithtml_parse_data', + 'verify_function' => 'bithtml_verify_data', + 'description' => 'HTML Syntax Format Parser', + 'edit_label' => 'HTML', + 'edit_field' => '<input type="radio" name="format_guid" value="'.PLUGIN_GUID_BITHTML.'"', + 'plugin_type' => FORMAT_PLUGIN + ); + +$gLibertySystem->registerPlugin( PLUGIN_GUID_BITHTML, $pluginParams ); + +function bithtml_verify_data( &$pParamHash ) { + $errorMsg = NULL; + $pParamHash['content_store']['data'] = purge_html( $pParamHash['edit'] ); + return $errorMsg; +} + +// This function is a menagerie of the techniques of the comments listed at +// http://www.php.net/manual/en/function.strip-tags.php - spiderr +function purge_html( $pText ) { + global $gBitSystem, $gBitUser; + + // convert all HTML entites to catch people trying to sneak stuff by with things like { etc.. + if( function_exists( 'html_entity_decode' ) ) { + $text = html_entity_decode( $pText ); + } else { + $trans_tbl = get_html_translation_table(HTML_ENTITIES); + $trans_tbl = array_flip($trans_tbl); + $text = strtr($pText, $trans_tbl); + } + + // strip_tags() appears to become nauseated at the site of a <!DOCTYPE> declaration + $text = str_replace( '<!DOCTYPE', '<DOCTYPE', $text ); + + // Yank style - both tag and inline attributes + // strip_tags has doesn't recognize that css within the style tags are not document text. To fix this do something similar to the following: + if( !$gBitUser->hasPermission( 'bit_p_edit_html_style' ) ) { + $text = preg_replace( "/<style[^>]*>.*<\/style>/siU", '', $text ); + } + $text = stripslashes($text); + if( !$gBitUser->hasPermission( 'bit_p_edit_html_style' ) ) { + $text = preg_replace( "/ (style|class)=[\"]?([^\"]*)[\"]?/i", '', $text); + } + + // Strip all evil tags that remain + // this comes out of gBitSystem->getPreference() set in Liberty Admin + $acceptableTags = $gBitSystem->getPreference( 'approved_html_tags', DEFAULT_ACCEPTABLE_TAGS ); + + // Destroy all script code "manually" - strip_tags will leave code inline as plain text + if( !preg_match( '/\<script\>/', $acceptableTags ) ) { + $text = preg_replace( "/(\<script)(.*?)(script\>)/si", '', $text ); + } + + $text = strip_tags( $text, $acceptableTags ); + $text = str_replace("<!--", "<!--", $text); + $text = preg_replace("/(\<)(.*?)(--\>)/mi", "".nl2br("\\2")."", $text); + + return( $text ); +} + +function bithtml_save_data( &$pParamHash ) { + static $parser; + if( empty( $parser ) ) { + $parser = new TikiWikiParser(); + } + if( $pParamHash['edit'] ) { + $parser->storeLinks( $pParamHash ); + } +} + +function bithtml_parse_data( &$pData, &$pCommonObject ) { + parse_data_plugins( $pData, $foo, $bar, $empty ); + // eventually we should strip tags, maybe tikilink, or other things. + return $pData; +} + +?> |
