1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
<?php
namespace Bitweaver\Liberty;
/**
* @version $Header$
* @package liberty
* @subpackage plugins_filter
*/
/**
* definitions ( guid character limit is 16 chars )
*/
define( 'PLUGIN_GUID_FILTERSTYLEPURIFIER', 'filterstylepure' );
global $gLibertySystem;
$pluginParams = [
// plugin title
'title' => 'Style Purification',
// help page on bitweaver org that explains this plugin
'help_page' => 'Style Purifier',
// brief description of the plugin
'description' => 'Strips out both inline and attribute style for users who don\'t have p_liberty_edit_html_style.',
// should this plugin be active or not when loaded for the first time
'auto_activate' => true,
// type of plugin
'plugin_type' => FILTER_PLUGIN,
// filter hooks
'prestore_function' => 'stylepure_filter',
];
$gLibertySystem->registerPlugin( PLUGIN_GUID_FILTERSTYLEPURIFIER, $pluginParams );
/*
* Removes all style both inline and attributes unless the user
* has permission to edit styles.
*/
function stylepure_filter( &$pData, &$pFilterHash ) {
global $gBitUser;
// 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( 'p_liberty_edit_html_style' )) {
$pattern = [
"!<style[^>]*>.*</style>!siU", // <style>...</style>
'![\s\n]*(style|class)\s*=\s*"[^">]*"?!i', // style="..." | class="..."
"![\s\n]*(style|class)\s*=\s*'[^'>]*'?!i", // style='...' | class='...'
"![\s\n]*(style|class)\s*=\s*[^\s>]*!i", // style=... | class=...
];
$pData = preg_replace( $pattern, '', $pData );
}
}
|