Skip to content

Commit

Permalink
Merge pull request #289 from WBCE/filter_from_2_0_and_opf
Browse files Browse the repository at this point in the history
Filter from 2 0 and opf

Quite a lot of changes to output filters

CSS to head was fixed.  
CSS to head runns in backend now. 
Stefeks bakend droplets should be functional now.
Droples may bring their own CSS definitions , by simply echo them. 
they are moved to head then by the filter.   
ALL filters can be turned on and off . 
The horrible chaos of using binary flags for mail filter is replaced by simple constants. 
mdcr.js is loaded by the filter now , no more need to add this whith frontend modfiles. 
Prepared everything for a new JS to head filter.
  • Loading branch information
NorHei authored Aug 24, 2017
2 parents aad2b48 + b4074a9 commit b4a885e
Show file tree
Hide file tree
Showing 33 changed files with 1,201 additions and 783 deletions.
60 changes: 47 additions & 13 deletions wbce/framework/class.admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,17 @@
* @license GNU GPL2 (or any later version)
*/

// Must include code to stop this file being accessed directly
if (!defined('WB_PATH')) {
require_once dirname(__FILE__) . '/globalExceptionHandler.php';
throw new IllegalFileException();
}
/* -------------------------------------------------------- */
require_once WB_PATH . '/framework/class.wb.php';
//no direct file access
if(count(get_included_files())==1) die(header("Location: ../index.php",TRUE,301));


// Get WB version
require_once ADMIN_PATH . '/interface/version.php';

class admin extends wb
{
// Authenticate user then auto print the header
public function __construct($section_name = '##skip##', $section_permission = 'start', $auto_header = true, $auto_auth = true)
public function __construct($section_name = '##skip##', $section_permission = 'start', $auto_header = true, $auto_auth = true, $operateBuffer=true)
{
parent::__construct(SecureForm::BACKEND);
if ($section_name != '##skip##') {
Expand Down Expand Up @@ -67,14 +63,23 @@ public function __construct($section_name = '##skip##', $section_permission = 's

// Auto header code
if ($auto_header == true) {
$this->print_header();
$this->print_header($body_tags = '',$operateBuffer);
}
}

// i know this sucks but some old stuff really need this
global $wb;
$wb = $this;
}

// Print the admin header
public function print_header($body_tags = '')
public function print_header($body_tags = '', $operateBuffer=true)
{
// this buffer is needed so we can later apply output filters to BE Output
if ($operateBuffer){
ob_start();
}

// Get vars from the language file
global $MENU, $MESSAGE, $TEXT, $database;
// Connect to database and get website title
Expand Down Expand Up @@ -192,7 +197,7 @@ public function print_header($body_tags = '')
}

// Print the admin footer
public function print_footer($activateJsAdmin = false)
public function print_footer($activateJsAdmin = false, $operateBuffer=true)
{
// include the required file for Javascript admin
if ($activateJsAdmin != false) {
Expand Down Expand Up @@ -222,6 +227,35 @@ public function print_footer($activateJsAdmin = false)
));
$footer_template->parse('header', 'footer_block', false);
$footer_template->pparse('output', 'page');
// If we operate on buffer in BE load all necessary filter
if ($operateBuffer){
// fetch all output
$allOutput = ob_get_clean ();

// OPF dashboard
// is it installed ?
if(function_exists('opf_controller')) {
// then apply backend filter
$allOutput = opf_controller('backend', $allOutput);
}

// Conventional output filter
// if not deactivated
if (!defined("WB_SUPPRESS_OLD_OPF") or !WB_SUPPRESS_OLD_OPF){
// Module is installed, filter file in place?
$file=WB_PATH . '/modules/output_filter/filter_routines.php';
if (file_exists($file)) {
include_once ($file);
// Correct module ? Check it .
if (function_exists('executeBackendOutputFilter')) {
// call the backend filter
$allOutput = executeBackendOutputFilter($allOutput);
}
}
}
// finally output everything as if nothing happened
echo $allOutput;
}
}

// Return a system permission
Expand Down Expand Up @@ -370,7 +404,7 @@ public function register_backend_modfiles_body($file_id = "js")
if (isset($_GET['tool'])) {
// check if displayed page contains a installed admin tool
$sql = 'SELECT * FROM `' . TABLE_PREFIX . 'addons` ';
$sql .= 'WHERE `type`=\'module\' AND `function`=\'tool\' AND `directory`=\'' . $database->escapeString($_GET['tool']) . '\'';
$sql .= 'WHERE `type`=\'module\' AND `function` LIKE \'%tool%\' AND `directory`=\'' . $database->escapeString($_GET['tool']) . '\'';
$result = $database->query($sql);
if ($result->numRows()) {
// check if admin tool directory contains a backend_body.js file to include
Expand Down Expand Up @@ -431,7 +465,7 @@ public function register_backend_modfiles($file_id = "css")
if (isset($_GET['tool'])) {
// check if displayed page contains a installed admin tool
$sql = 'SELECT * FROM `' . TABLE_PREFIX . 'addons` ';
$sql .= 'WHERE `type`=\'module\' AND `function`=\'tool\' AND `directory`=\'' . $database->escapeString($_GET['tool']) . '\'';
$sql .= 'WHERE `type`=\'module\' AND `function` LIKE \'%tool%\' AND `directory`=\'' . $database->escapeString($_GET['tool']) . '\'';
$result = $database->query($sql);
if ($result->numRows()) {
// check if admin tool directory contains a backend.js or backend.css file to include
Expand Down
7 changes: 1 addition & 6 deletions wbce/framework/frontend.functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -647,12 +647,7 @@ function register_frontend_modfiles($file_id = "css")
;
}
}
// include the Javascript email protection function
if ($file_id != 'css' && file_exists(WB_PATH . '/modules/droplets/js/mdcr.js')) {
$head_links .= '<script src="' . WB_URL . '/modules/droplets/js/mdcr.js" type="text/javascript"></script>' . "\n";
} elseif ($file_id != 'css' && file_exists(WB_PATH . '/modules/output_filter/js/mdcr.js')) {
$head_links .= '<script src="' . WB_URL . '/modules/output_filter/js/mdcr.js" type="text/javascript"></script>' . "\n";
}

}
print $head_links;
}
Expand Down
31 changes: 26 additions & 5 deletions wbce/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,45 @@
//Get pagecontent in buffer for Droplets and/or Filter operations
ob_start();
require WB_PATH . '/templates/' . TEMPLATE . '/index.php';


// fetch the Page content for applying filters
$output = ob_get_clean();

// OPF hook, apply outputfilter
if(function_exists('opf_apply_filters')) {
$output = opf_controller('page', $output);

// Load OPF Dashboard OutputFilter functions
// As thish should replace the old filters on the long run , its a bad idea to
// have this in an output filter.
// Besides you cannnot deactivate the old filters if its IN the old filters
$sOpfFile = WB_PATH.'modules/outputfilter_dashboard/functions.php';
if (is_readable($sOpfFile)) {
require_once($sOpfFile);
// apply outputfilter
if (function_exists('opf_apply_filters')) {
// use 'cache' instead of 'nocache' to enable page-cache.
// Do not use 'cache' in case you use dynamic contents (e.g. snippets)!
opf_controller('init', 'nocache');
$output = opf_controller('page', $output);
}
}


// execute old frontend output filters or not
// Sooner or later this is going to be removed as we dont need to OPF systems
// So if the module is removed , this goes inactive.
if (!defined("WB_SUPPRESS_OLD_OPF") or WB_SUPPRESS_OLD_OPF===false){
$sOldOpfPath=WB_PATH . '/modules/output_filter/filter_routines.php';
// Module is installed?
if (file_exists(WB_PATH . '/modules/output_filter/index.php')) {
include_once WB_PATH . '/modules/output_filter/index.php';
if (file_exists($sOldOpfPath)) {
require_once $sOldOpfPath;
// module correctly loaded
if (function_exists('executeFrontendOutputFilter')) {
$output = executeFrontendOutputFilter($output);
}
}
}


// now send complete page to the browser
echo $output;

Expand Down
4 changes: 3 additions & 1 deletion wbce/languages/EN.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@
$TEXT['FORGOTTEN_DETAILS'] = 'Forgotten your details?';
$TEXT['FORGOT_DETAILS'] = 'Forgot Details?';
$TEXT['FROM'] = 'From';
$TEXT['FRONTEND'] = 'Front-end';
$TEXT['FRONTEND'] = 'Frontend';
$TEXT['BACKEND'] = 'Backend';
$TEXT['FULL_NAME'] = 'Full Name';
$TEXT['FUNCTION'] = 'Function';
$TEXT['GROUP'] = 'Group';
Expand Down Expand Up @@ -682,3 +683,4 @@
$OVERVIEW['USERS'] = 'Manage users who can log-in to WBCE CMS...';
$OVERVIEW['VIEW'] = 'Quickly view and browse your website in a new window...';


110 changes: 63 additions & 47 deletions wbce/modules/droplets/droplets.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,84 +33,100 @@ function do_eval($_x_codedata, $_x_varlist, &$wb_page_data)
return false;
}

function processDroplets( &$wb_page_data ) {
// collect all droplets from document


/**
@brief process all droplets
@param string $wb_page_data
@param string $position ('frontend'|'backend')
*/
function processDroplets( &$wb_page_data, $position = 'frontend' ) {

// collect all droplets from document
$droplet_tags = array();
$droplet_replacements = array();
if( preg_match_all( '/\[\[(.*?)\]\]/', $wb_page_data, $found_droplets ) )
{
foreach( $found_droplets[1] as $droplet )
{
if(array_key_exists( '[['.$droplet.']]', $droplet_tags) == false)
{
// go in if same droplet with same arguments is not processed already
// Special matches for FE and BE
$match = ($position == 'backend') ? '/\[\[\[(.*?)\]\]\]/' : '/\[\[(.*?)\]\]/';
$openTag = ($position == 'backend') ? '[[[' : '[[';
$closeTag = ($position == 'backend') ? ']]]' : ']]';
// now get the actual matches
if( preg_match_all( $match, $wb_page_data, $found_droplets ) ) {
// loop over all matches
foreach( $found_droplets[1] as $droplet ){
if(array_key_exists( $openTag.$droplet.$closeTag, $droplet_tags) == false) {
// go in if same droplet with same arguments is not processed already
$varlist = array();
// split each droplet command into droplet_name and request_string

// split each droplet command into droplet_name and request_string
$tmp = preg_split('/\?/', $droplet, 2);
$droplet_name = $tmp[0];
$request_string = (isset($tmp[1]) ? $tmp[1] : '');
if( $request_string != '' )
{
// make sure we can parse the arguments correctly
if( $request_string != '' ){

// make sure we can parse the arguments correctly
$request_string = html_entity_decode($request_string, ENT_COMPAT,DEFAULT_CHARSET);
// create array of arguments from query_string

// create array of arguments from query_string
$argv = preg_split( '/&(?!amp;)/', $request_string );
foreach ($argv as $argument)
{
// split argument in pair of varname, value
foreach ($argv as $argument){
// split argument in pair of varname, value
list( $variable, $value ) = explode('=', $argument,2);
if( !empty($value) )
{
// re-encode the value and push the var into varlist
if( !empty($value) ){
// re-encode the value and push the var into varlist
$varlist[$variable] = htmlentities($value, ENT_COMPAT,DEFAULT_CHARSET);
}
}
}
else
{
// no arguments given, so
} else {
// no arguments given, so
$droplet_name = $droplet;
}
// request the droplet code from database

// request the droplet code from database
$sql = 'SELECT `code` FROM `'.TABLE_PREFIX.'mod_droplets` WHERE `name` LIKE "'.$droplet_name.'" AND `active` = 1';
$codedata = $GLOBALS['database']->get_one($sql);
if (!is_null($codedata))
{
$newvalue = do_eval($codedata, $varlist, $wb_page_data);
// check returnvalue (must be a string of 1 char at least or (bool)true
if ($newvalue == '' && $newvalue !== true)
{
if(DEBUG === true)
{
if ($newvalue == '' && $newvalue !== true) {
// do debug output on debug mode
if(defined ('WB_DEBUG') and WB_DEBUG === true){
$newvalue = '<span class="mod_droplets_err">Error in: '.$droplet.', no valid returnvalue.</span>';
}
else
{
} else {
$newvalue = true;
}
}
if ($newvalue === true) { $newvalue = ""; }
// remove any defined CSS section from code. For valid XHTML a CSS-section is allowed inside <head>...</head> only!
// deactivated this filter as we have an output filter that moves all CSS up to head . so no need for struggle
// $newvalue = preg_replace('/<style.*>.*<\/style>/siU', '', $newvalue);
// push droplet-tag and it's replacement into Search/Replace array after executing only
$droplet_tags[] = '[['.$droplet.']]';

// remove any defined CSS section from code. For valid XHTML a CSS-section is allowed inside <head>...</head> only!
// deactivated this filter as we have an output filter that moves all CSS up to head . so no need for struggle
//$newvalue = preg_replace('/<style.*>.*<\/style>/siU', '', $newvalue);

// push droplet-tag and it's replacement into Search/Replace array after executing only
$droplet_tags[] = $openTag.$droplet.$closeTag;
$droplet_replacements[] = $newvalue;
}
}
} // End foreach( $found_droplets[1] as $droplet )
// replace each Droplet-Tag with coresponding $newvalue
// replace each Droplet-Tag with coresponding $newvalue
$wb_page_data = str_replace($droplet_tags, $droplet_replacements, $wb_page_data);
}
// returns TRUE if droplets found in content, FALSE if not
// returns TRUE if droplets found in content, FALSE if not
return( count($droplet_tags)!=0 );
}

function evalDroplets( &$wb_page_data, $max_loops = 3 ) {
$max_loops = ((int)$max_loops = 0 ? 3 : (int)$max_loops);
while( (processDroplets($wb_page_data) == true) && ($max_loops > 0))
{
$max_loops--;
}
return $wb_page_data;
}
/**
@brief eval droplets
@param string $wb_page_data
@param string $position ('frontend'|'backend')
@param int $max_loops
Multiple runns so you get droplets created by droplets up to 3 levels
*/
function evalDroplets( &$wb_page_data, $position = 'frontend', $max_loops = 3 ) {
$max_loops = ((int)$max_loops = 0 ? 3 : (int)$max_loops);
while( (processDroplets($wb_page_data, $position) == true) && ($max_loops > 0)){
$max_loops--;
}
return $wb_page_data;
}
7 changes: 5 additions & 2 deletions wbce/modules/droplets/info.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
$module_directory = 'droplets';
$module_name = 'Droplets';
$module_function = 'tool';
$module_version = '2.1.4';
$module_version = '2.2.4';
$module_platform = '2.8.x';
$lepton_platform = '1.x';
$module_author = 'Ruud, pcwacht, WebBird, cwsoft, Norhei, Colinax';
Expand All @@ -24,6 +24,9 @@

/**
* Version history
2.2.4 norhei - added support for backend droplets
*
* v2.1.4 - colinax
* - Revert "Fix for no droplet bug" - The fix does not work correctly
Expand Down Expand Up @@ -77,4 +80,4 @@
* tablesorter jQuery plugin included directly;
* please note that you will have to ensure that jquery is loaded!
*
**/
**/
1 change: 0 additions & 1 deletion wbce/modules/output_filter/FTAN_SUPPORTED

This file was deleted.

Loading

0 comments on commit b4a885e

Please sign in to comment.