Initial commit

This commit is contained in:
Felix Förtsch
2020-10-20 14:39:50 +02:00
commit 648ded8896
1225 changed files with 216511 additions and 0 deletions

View File

@@ -0,0 +1,69 @@
<?php
/**
*
*
*/
namespace WCFE\SysPlugins;
/**
*
*/
class Plugins
{
/**
* put your comment there...
*
* @var mixed
*/
protected static $instance;
/**
* put your comment there...
*
* @var mixed
*/
protected $plugins;
/**
* put your comment there...
*
*/
private function __construct()
{
# Load Plugins
$this->plugins[ ] = new SysFilters\Plugin();
}
/**
* put your comment there...
*
*/
public static function & load()
{
if ( ! self::$instance )
{
self::$instance = new Plugins();
}
return self::$instance;
}
/**
* put your comment there...
*
*/
public function runPlugins()
{
foreach ( $this->plugins as $plugin )
{
$plugin->run();
}
return $this;
}
}

View File

@@ -0,0 +1,218 @@
<?php
/**
*
*
*/
namespace WCFE\SysPlugins\SysFilters;
/**
*
*/
class Module
{
/**
* put your comment there...
*
* @var mixed
*/
private $data;
/**
* put your comment there...
*
* @var mixed
*/
protected $filters = array();
/**
* put your comment there...
*
* @var mixed
*/
protected $handlers = array();
/**
* put your comment there...
*
* @param mixed $filters
* @return Module
*/
public function __construct( $filters = null )
{
if ( $filters )
{
$this->filters = $filters;
}
}
/**
* put your comment there...
*
* @param mixed $method
* @param mixed $params
*/
public function __call( $method, $params )
{
# Get callback name
$components = explode( '_', substr( $method, 1 ) );
$handlerName = "_{$components[ 0 ]}";
# Call with method name passed
$components[ 0 ] = $method;
$params = array_merge( $components, $params );
return call_user_func_array( array( & $this, $handlerName ), $params ) ;
}
/**
* put your comment there...
*
* @param mixed $callbackName
*/
public function _return( $callbackName, $varName )
{
return $this->getVar( $varName );
}
/**
* put your comment there...
*
* @param mixed $callbackName
* @param mixed $array
*/
public function _setArrayElement( $callbackName, $varName, $array )
{
$params = $this->handlers[ $callbackName ][ 'params' ];
// call custom handler if specified
$params[ 'flags' ] = isset( $params[ 'flags' ] ) ? explode( '|', $params[ 'flags' ] ) : array();
$value = $this->getVar( $varName );
if ( in_array( 'customHandler', $params[ 'flags' ] ) )
{
$customHandler = "get_{$varName}Value";
$value = $this->$customHandler( $value );
}
$array[ $params[ 'element' ] ] = $value;
return $array;
}
/**
* put your comment there...
*
* @param mixed $callbackName
* @param mixed $varName
*/
public function _setGlobalVar( $callbackName, $varName )
{
$params = $this->handlers[ $callbackName ][ 'params' ];
$GLOBALS[ $params[ 'varName' ] ] = $this->getVar( $varName );
}
/**
* put your comment there...
*
* @param mixed $filters
*/
public function & buildFiltersList( $filters )
{
foreach ( $filters as $handlerName => $handlers )
{
foreach ( $handlers as $varName => $filter )
{
$handlerCallbackName = "_{$handlerName}_{$varName}";
# Map handlers to retrive associated data later when filter triggered
$this->handlers[ $handlerCallbackName ][ 'params' ] = isset( $filter[ 'params' ] ) ? $filter[ 'params' ] : null;
# Map filters to be binded
$this->filters[ $varName ] = array
(
'filter' => $filter[ 'filter' ],
'callback' => $handlerCallbackName,
'args' => isset( $filter[ 'args' ] ) ? $filter[ 'args' ] : 1
);
}
}
return $this;
}
/**
* put your comment there...
*
*/
public function getFilters()
{
return $this->filters;
}
/**
* put your comment there...
*
* @param mixed $method
*/
public function getHandlerVarName( $method )
{
return substr( $method, 1 );
}
/**
* put your comment there...
*
* @param mixed $name
*/
public final function getVar( $varName, $sectionName = 'value' )
{
return isset( $this->data[ $varName ][ 'value' ] ) ? $this->data[ $varName ][ $sectionName ] : null;
}
/**
* put your comment there...
*
* @param mixed $varName
* @param mixed $optName
*/
public final function getVarOption( $varName, $optName )
{
return isset( $this->data[ $varName ][ 'options' ][ $optName ] ) ? $this->data[ $varName ][ 'options' ][ $optName ] : null;
}
/**
* put your comment there...
*
* @param mixed $data
* @return Module
*/
public final function & run( $data )
{
$this->data =& $data;
foreach ( $this->getFilters() as $varName => $handler )
{
# Don't involved if disabled
if ( ! $this->getVarOption( $varName, 'disabled' ) )
{
add_filter( $handler[ 'filter' ], array( & $this, $handler[ 'callback' ] ), $this->getVarOption( $varName, 'priority' ), $handler[ 'args' ] );
}
}
return $this;
}
}

View File

@@ -0,0 +1,68 @@
<?php
/**
*
*/
namespace WCFE\SysPlugins\SysFilters\Modules;
use WCFE\SysPlugins\SysFilters\Module;
/**
*
*/
class EditorModule extends Module
{
/**
* put your comment there...
*
*/
public function getFilters()
{
$filtersToBuild = array
(
'setArrayElement' => array
(
'autoParagraph' => array( 'filter' => 'wp_editor_settings', 'params' => array( 'element' => 'wpautop' ) ),
'editorHeight' => array( 'filter' => 'wp_editor_settings', 'params' => array( 'element' => 'editor_height' ) ),
'mediaButtons' => array( 'filter' => 'wp_editor_settings', 'params' => array( 'element' => 'media_buttons' ) ),
'dragDropUpload' => array( 'filter' => 'wp_editor_settings', 'params' => array( 'element' => 'drag_drop_upload' ) ),
'textAreaRows' => array( 'filter' => 'wp_editor_settings', 'params' => array( 'element' => 'textarea_rows' ) ),
'tabIndex' => array( 'filter' => 'wp_editor_settings', 'params' => array( 'element' => 'tabindex' ) ),
'editorCSS' => array( 'filter' => 'wp_editor_settings', 'params' => array( 'element' => 'editor_css' ) ),
'editorClass' => array( 'filter' => 'wp_editor_settings', 'params' => array( 'element' => 'editor_class' ) ),
'teeny' => array( 'filter' => 'wp_editor_settings', 'params' => array( 'element' => 'teeny' ) ),
'tinyMCE' => array( 'filter' => 'wp_editor_settings', 'params' => array( 'element' => 'tinymce' ) ),
'quickTags' => array( 'filter' => 'wp_editor_settings', 'params' => array( 'element' => 'quicktags', 'flags' => 'customHandler' ) ),
),
'return' => array
(
'plugins' => array( 'filter' => 'tiny_mce_plugins' ),
'buttons2' => array( 'filter' => 'mce_buttons_2' ),
)
);
$this->buildFiltersList( $filtersToBuild );
return parent::getFilters();
}
/**
* put your comment there...
*
*/
protected function get_quickTagsValue( $value )
{
# If buttons is supplied then Return array with buttons as item
$buttons = $this->getVar( 'quickTags', 'buttons' );
if ( $value && $buttons )
{
$value = array( 'buttons' => $buttons );
}
return $value;
}
}

View File

@@ -0,0 +1,55 @@
<?php
/**
*
*/
namespace WCFE\SysPlugins\SysFilters\Modules;
use WCFE\SysPlugins\SysFilters\Module;
/**
*
*/
class HTTPModule extends Module
{
/**
* put your comment there...
*
*/
public function getFilters()
{
$filtersToBuild = array
(
'setArrayElement' => array
(
'timeOut' => array( 'filter' => 'http_request_args', 'params' => array( 'element' => 'timeout' ) ),
'redirectCount' => array( 'filter' => 'http_request_args', 'params' => array( 'element' => 'redirection' ) ),
'version' => array( 'filter' => 'http_request_args', 'params' => array( 'element' => 'httpversion' ) ),
'userAgent' => array( 'filter' => 'http_request_args', 'params' => array( 'element' => 'user-agent' ) ),
'rejectUnsafeUrls' => array( 'filter' => 'http_request_args', 'params' => array( 'element' => 'reject_unsafe_urls' ) ),
'stream' => array( 'filter' => 'http_request_args', 'params' => array( 'element' => 'stream' ) ),
'blocking' => array( 'filter' => 'http_request_args', 'params' => array( 'element' => 'blocking' ) ),
'compress' => array( 'filter' => 'http_request_args', 'params' => array( 'element' => 'compress' ) ),
'decompress' => array( 'filter' => 'http_request_args', 'params' => array( 'element' => 'decompress' ) ),
'responseSizeLimit' => array( 'filter' => 'http_request_args', 'params' => array( 'element' => 'limit_response_size' ) ),
),
'return' => array
(
'proxyBlockLocalRequests' => array( 'filter' => 'block_local_requests' ),
'localSSLVerify' => array( 'filter' => 'https_local_ssl_verify' ),
'sslVerify' => array( 'filter' => 'https_ssl_verify' ),
'useSteamTransport' => array( 'filter' => 'use_streams_transport' ),
'useCurlTransport' => array( 'filter' => 'use_curl_transport' ),
'allowLocalHost' => array( 'filter' => 'http_request_host_is_external' ),
)
);
$this->buildFiltersList( $filtersToBuild );
return parent::getFilters();
}
}

View File

@@ -0,0 +1,66 @@
<?php
/**
*
*/
namespace WCFE\SysPlugins\SysFilters\Modules;
use WCFE\SysPlugins\SysFilters\Module;
/**
*
*/
class KsesModule extends Module
{
/**
* put your comment there...
*
* @param mixed $callbackName
* @param mixed $varName
*/
public function _tags( $callbackName, $varName, $tags, $context )
{
# Applying Tags filter single time will call all associated
# handlers even those not requested by the variable name
# So lets make sure we're returing the correct result with the requested context/varname
if ( ( ( $context == 'post' ) && ( $varName == 'postTags' ) ) ||
( ( $context == 'pre_comment_content' ) && ( $varName == 'commentTags' ) ) )
{
$tags = $this->getVar( $varName );
}
return $tags;
}
/**
* put your comment there...
*
*/
public function getFilters()
{
$filtersToBuild = array
(
'return' => array
(
'protocols' => array( 'filter' => 'kses_allowed_protocols' ),
),
'tags' => array(
'postTags' => array( 'filter' => 'wp_kses_allowed_html', 'args' => 2 ),
'commentTags' => array( 'filter' => 'wp_kses_allowed_html', 'args' => 2 ),
),
'setGlobalVar' => array(
'entities' => array( 'filter' => 'init', 'params' => array( 'varName' => 'allowedentitynames' ) ),
)
);
$this->buildFiltersList( $filtersToBuild );
return parent::getFilters();
}
}

View File

@@ -0,0 +1,40 @@
<?php
/**
*
*/
namespace WCFE\SysPlugins\SysFilters\Modules;
use WCFE\SysPlugins\SysFilters\Module;
/**
*
*/
class MiscModule extends Module
{
/**
* put your comment there...
*
*/
public function getFilters()
{
$filtersToBuild = array
(
'return' => array
(
'queryVars' => array( 'filter' => 'query_vars' ),
'quality' => array( 'filter' => 'wp_editor_set_quality' ),
'memoryLimit' => array( 'filter' => 'image_memory_limit' ),
'themesPersistCache' => array( 'filter' => 'wp_cache_themes_persistently' ),
'uploadAllowedMimes' => array( 'filter' => 'upload_mimes' ),
),
);
$this->buildFiltersList( $filtersToBuild );
return parent::getFilters();
}
}

View File

@@ -0,0 +1,82 @@
<?php
/**
*
*/
namespace WCFE\SysPlugins\SysFilters;
/**
*
*/
class Plugin
{
/**
* put your comment there...
*
* @var mixed
*/
protected $data;
/**
* put your comment there...
*
* @var mixed
*/
protected $modules;
/**
* put your comment there...
*
*/
public function __construct()
{
# Load site data if not in multi site or load primary
# site data for multi site (configuration will be applied or all sites)
$optionName = 'wcfe-model-state_sysfiltersdashboardmodel';
$this->data = is_multisite() ? get_blog_option( get_main_network_id(), $optionName ) : get_option( $optionName );
}
/**
* put your comment there...
*
*/
public function run()
{
// System Parameters page never saved/configured!
// Get out until admin configue it from Dashboard page
if ( ! $this->data )
{
return;
}
// No reason for this, however no chance for errors
// in Sys Plugins that is always RUNS!!!
if ( ! isset( $this->data[ 'sysFiltersData' ] ) || ! is_array( $this->data[ 'sysFiltersData' ] ) )
{
return;
}
$this->data = $this->data[ 'sysFiltersData' ];
# Load modules
$this->modules[ 'misc' ] = new Modules\MiscModule();
$this->modules[ 'http' ] = new Modules\HTTPModule();
$this->modules[ 'editor' ] = new Modules\EditorModule();
$this->modules[ 'kses' ] = new Modules\KsesModule();
foreach ( $this->modules as $name => $module )
{
$module->run( isset( $this->data[ $name ] ) ? $this->data[ $name ] : null );
}
return;
}
}