first commit

This commit is contained in:
2026-03-05 13:07:40 +01:00
commit 64ba0721ee
25709 changed files with 4691006 additions and 0 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,362 @@
<?php
/**
* Form_Fields. Render form fields out of an array.
*
* @class Form_Fields
* @package SilkyPressFrm
*/
namespace SilkyPressFrm;
defined( 'ABSPATH' ) || exit;
if ( ! class_exists( '\SilkyPressFrm\Form_Fields' ) ) {
/**
* Form_Fields class.
*/
class Form_Fields {
/**
* Fields description.
*
* @var array
*/
private $fields = array();
/**
* Current field values.
*
* @var array
*/
private $current_values = array();
/**
* Additional attributes.
*
* @var array
*/
private $atts = array();
/**
* Validation error/info messages.
*
* @var array
*/
private $messages = array();
/**
* Constructor.
*
* @param array $fields The field description array.
*/
public function __construct( $fields = array() ) {
$this->fields = $fields;
// Default attributes.
$this->atts = array(
'tooltip_img' => '',
'section' => '',
'label-class' => '',
'disable_pro' => true,
);
}
/**
* Add settings.
*
* @param string $var Variable.
* @param string $value Value.
*/
public function add_setting( $var = '', $value = '' ) {
$this->atts[ $var ] = $value;
}
/**
* Set the $this->current_values array.
*
* @param array $values Current values.
*/
public function set_current_values( $values = array() ) {
$this->current_values = $values;
}
/**
* Render all the fields.
*
* @param array $fields The fields to be rendered.
*
* @return string The rendered fields.
*/
public function render( $fields = null ) {
$content = '';
$fields = ( null === $fields ) ? $this->fields : array();
if ( count( $fields ) === 0 ) {
return '';
}
foreach ( $fields as $_key => $_field ) {
if ( isset( $this->atts['section'] ) && $_field['section'] !== $this->atts['section'] ) {
continue;
}
$content .= $this->render_field( $_key, $_field );
}
return $content;
}
/**
* Render one field
*
* @param string $_key The field's id.
* @param array $_field The fields' description.
*
* @return string The rendered field.
*/
public function render_field( $_key, $_field ) {
$atts = '';
$description = '';
$label = '';
$input_values = '';
$add_label = true;
$group_wrap = true;
if ( 'header' === $_field['input_form'] || isset( $_field['no_wrap'] ) ) {
$add_label = true;
$group_wrap = false;
}
$_field['value'] = isset( $this->current_values[ $_key ] ) ? $this->current_values[ $_key ] : $_field['value'];
$_field['disabled'] = ( $this->atts['disable_pro'] && isset( $_field['pro'] ) && $_field['pro'] ) ? true : false;
$atts .= ( isset( $_field['disabled'] ) && $_field['disabled'] ) ? ' disabled' : '';
$atts .= ( 'checkbox' === $_field['input_form'] && true === (bool) $_field['value'] && ! $_field['disabled'] ) ? ' checked="checked"' : '';
// Radio templates.
if ( 'radio' === $_field['input_form'] ) {
foreach ( $_field['values'] as $__id => $__value ) {
$_style = isset( $_field['style'] ) && 'inline' === $_field['style'] ? '-inline' : '';
$input_atts = ( $__id === $_field['value'] ) ? $atts . ' checked=""' : $atts;
$input_values .= vsprintf(
'<div class="radio%s"%s><label><input type="radio" name="%s" id="%s" value="%s" %s />%s</label></div>',
array( $_style, $atts, $_key, $__id, $__id, $input_atts, $__value )
);
}
}
// Button templates.
if ( 'buttons' === $_field['input_form'] ) {
foreach ( $_field['values'] as $__id => $__value ) {
$toggle = ( ! empty( $__value[1] ) ) ? ' data-toggle="tooltip" data-placement="top" title="' . $__value[1] . '" data-original-title="' . $__value[1] . '"' : '';
$__atts = ( $__id == $_field['value'] ) ? ' active' : ''; // Keep the loosely == equal operator instead of the strict === identical operator
$__atts .= ( $_field['disabled'] ) ? ' disabled' : '';
$input_values .= vsprintf(
'<label class="btn btn-default %s"><input type="radio" name="%s" id="%s" value="%s" %s /><div class="icon-in-label ndd-spot-icon icon-style-1"%s><div class="ndd-icon-main-element">%s</div></div></label>',
array( $__atts, $_key, $__id, $__id, $__id === $_field['value'] ? 'checked' : '', $toggle, $__value[0] )
);
}
}
// Input templates.
$templates = array(
'text' => array( '%s', array( $_field['value'] ) ),
'radio' => array( '%s', array( $input_values ) ),
'buttons' => array( '<div class="btn-group%s" data-toggle="buttons" id="btn-group-style-circle">%s</div>', array( $atts, $input_values ) ),
'input_color' => array(
'<input type="color" class="form-control" id="%s" name="%s" value="%s"%s /><span class="input-group-addon" id="color-text-color-hex">%s</span>',
array( $_key, $_key, $_field['value'], $atts, $_field['value'] ),
),
'input_text' => array(
'<input type="text" class="form-control" id="%s" name="%s" value="%s"%s />',
array( $_key, $_key, stripslashes( $_field['value'] ), $atts ),
),
'checkbox' => array(
'<input type="checkbox" id="%s" name="%s" value="1"%s />',
array( $_key, $_key, $atts ),
),
'header' => array(
'<h4 class="col-sm-5">%s</h4><div style="clear: both;"></div>',
array( $_field['label'] ),
),
);
// The input.
$input = vsprintf(
$templates[ $_field['input_form'] ][0],
$templates[ $_field['input_form'] ][1]
);
// The input addon.
if ( isset( $_field['post_input'] ) && ! empty( $_field['post_input'] ) ) {
$input .= sprintf( '<span class="input-group-addon">%s</span>', $_field['post_input'] );
}
// The description.
if ( isset( $_field['description'] ) && ! empty( $_field['description'] ) ) {
$description = vsprintf(
' <img src="%s" data-toggle="tooltip" data-placement="top" title="%s" data-original-title="%s" />',
array( $this->atts['tooltip_img'], $_field['description'], $_field['description'] )
);
}
// The label.
$label_class = isset( $this->atts['label_class'] ) ? $this->atts['label_class'] : 'col-sm-6';
$label_class = isset( $_field['label_class'] ) ? $_field['label_class'] : $label_class;
if ( isset( $_field['label'] ) && $add_label ) {
$label = vsprintf(
'<label for="%s" class="%s">%s</label>',
array( $_key, 'control-label ' . $label_class, $_field['label'] . $description )
);
}
// The Bootstrap 4 form-group wrapper.
if ( $group_wrap ) {
$_field['disabled'] = ( $this->atts['disable_pro'] && isset( $_field['pro'] ) && $_field['pro'] ) ? true : false;
$class = ( isset( $_field['disabled'] ) && $_field['disabled'] ) ? ' disabled' : '';
$input = vsprintf(
'<div class="%s"%s>%s<div class="%s">%s</div></div>',
array( 'form-group' . $class, '', $label, 'input-group input-group-' . $_field['input_form'], $input )
);
}
return $input;
}
/**
* Validate the $_POST values.
*
* @param array $post The $_POST values.
*/
public function validate( $post ) {
// Filter the $post array for allowed fields.
$post = array_intersect_key( $post, array_fill_keys( array_keys( $this->fields ), '' ) );
foreach ( $this->fields as $_key => $settings ) {
$reset = array();
// Validate only fields from the current section.
if ( isset( $this->atts['section'] ) && $settings['section'] !== $this->atts['section'] ) {
if ( 'header' !== $settings['input_form'] && 'text' !== $settings['input_form'] && isset( $settings['value'] ) ) {
$post[ $_key ] = isset( $this->current_values[ $_key ] ) ? $this->current_values[ $_key ] : $settings['value'];
}
continue;
}
// Add the unchecked checkboxes.
if ( 'checkbox' === $settings['input_form'] ) {
$post[ $_key ] = isset( $post[ $_key ] ) ? true : false;
}
// Validate colors.
if ( 'input_color' === $settings['input_form'] && isset( $post[ $_key ] ) && ! preg_match( '/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/', $post[ $_key ] ) ) {
$reset = array(
/* translators: 1: field label 2: value */
__( 'Unrecognized %1$s. The value was reset to %2$s' ),
array( '<b>' . $settings['label'] . '</b>', '<b>' . $settings['value'] . '</b>' ),
);
}
// Sanitize text inputs.
if ( 'input_text' === $settings['input_form'] ) {
$post[ $_key ] = isset( $post[ $_key ] ) ? sanitize_text_field( wp_unslash( $post[ $_key ] ) ) : (string) $settings['value'];
}
// Validate button and radio inputs.
if ( in_array( $settings['input_form'], array( 'button', 'radio' ), true ) && isset( $post[ $_key ] ) && ! array_key_exists( $post[ $_key ], $settings['values'] ) ) {
$reset = array(
/* translators: 1: field label 2: value */
__( 'Unrecognized %1$s. The value was reset to %2$s' ),
array( '<b>' . $settings['label'] . '</b>', '<b>' . $settings['value'] . '</b>' ),
);
}
// Validate according to a rule.
if ( isset( $settings['validate'] ) && isset( $post[ $_key ] ) ) {
if ( 'int' === $settings['validate']['type'] ) {
if ( (string) (int) $post[ $_key ] !== $post[ $_key ] ) {
$this->add_message(
'info',
vsprintf(
/* translators: 1: field label 2: value */
__( 'The %1$s field accepts only an integer value. It was set to %2$s' ),
array( '<b>' . $settings['label'] . '</b>', (int) $post[ $_key ] )
)
);
}
$post[ $_key ] = (int) $post[ $_key ];
}
if ( 'float' === $settings['validate']['type'] ) {
if ( (string) (float) $post[ $_key ] !== $post[ $_key ] ) {
$this->add_message(
'info',
vsprintf(
/* translators: 1: field label 2: value */
__( 'The %1$s field accepts only a number. It was set to %2$s' ),
array( '<b>' . $settings['label'] . '</b>', (float) $post[ $_key ] )
)
);
}
$post[ $_key ] = (float) $post[ $_key ];
}
if ( in_array( $settings['validate']['type'], array( 'int', 'float' ), true ) &&
( $post[ $_key ] < $settings['validate']['range'][0] ||
$post[ $_key ] > $settings['validate']['range'][1] ) ) {
$reset = array(
/* translators: 1: field label 2: minimum value 3: maximum value 4: value */
__( '%1$s accepts values between %2$s and %3$s. Your value was reset to %4$s' ),
array( '<b>' . $settings['label'] . '</b>', $settings['validate']['range'][0], $settings['validate']['range'][1], '<b>' . $settings['value'] . '</b>' ),
);
}
}
// Reset the value and add the info message.
if ( count( $reset ) > 0 ) {
$post[ $_key ] = $settings['value'];
$this->add_message( 'info', vsprintf( $reset[0], $reset[1] ) );
}
}
return $post;
}
/**
* Add messages.
*
* @param string $type The message type.
* @param string $message The message.
*/
public function add_message( $type = '', $message = '' ) {
$this->messages[] = array( $type, $message );
}
/**
* Render the messages.
*
* @return string Messages.
*/
public function render_messages() {
if ( 0 === count( $this->messages ) ) {
return;
}
$output = '';
foreach ( $this->messages as $_message ) {
$output .= vsprintf(
'<div class="alert alert-%s"><button type="button" class="close" data-dismiss="alert">&times;</button>%s</div>',
array( $_message[0], $_message[1] )
);
}
$output = sprintf( '<div class="col-lg-12">%s</div>', $output );
return $output;
}
}
}

View File

@@ -0,0 +1,111 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( !class_exists('SilkyPress_PremiumTooltips') ) {
/**
* SilkyPress_PremiumTooltips
*/
class SilkyPress_PremiumTooltips {
/**
* Constructor
*/
public function __construct($message) {
$this->html($message);
$this->css();
$this->javascript();
}
function html($message) {
?>
<div id="skp-premium-tooltip">
<div class="skp-premium-tooltip--arrow">
<div style=""></div>
</div>
<div class="skp-premium-tooltip--msg">
<label><?php echo $message; ?></label>
</div>
</div>
<?php
}
function css() {
?>
<style type="text/css">
#skp-premium-tooltip {
display:none;
width: 230px;
height: 60px;
position: absolute;
margin-left: 354px;
margin-top: 112px;
color: white;
}
#skp-premium-tooltip .skp-premium-tooltip--arrow {
float:left;
width:13px;
}
#skp-premium-tooltip .skp-premium-tooltip--arrow div {
width: 0px;
height: 0px;
border-top: 6px solid transparent;
border-right: 6px solid #333333;
border-bottom: 6px solid transparent;
float: right;
margin-right: 0px;
margin-top: 16px;
}
#skp-premium-tooltip .skp-premium-tooltip--msg {
font-family:sans-serif;
font-size:13px;
text-align: center;
border-radius: 5px;
float: left;
background-color: rgb(51, 51, 51);
color: white;
width: 210px;
padding: 10px 0px;
}
</style>
<?php
}
function javascript() {
?>
<script type="text/javascript">
jQuery(document).ready(function($){
$(".form-group.disabled-short, .form-group.disabled").on('click',function(e){
if(typeof window.tooltip != "undefined"){
clearTimeout(window.tooltip);
}
var inputCon = $(e.currentTarget).find(".input-group");
var left = 30;
$(e.currentTarget).children().each(function(i, child){
left += $(child).width();
});
var offsetTop = $(e.currentTarget).offset().top - 38;
offsetTop -= $('h2').offset().top - 52;
$("#skp-premium-tooltip").css({"margin-left" : left + "px", "margin-top" : offsetTop + "px"});
$("#skp-premium-tooltip").fadeIn( "slow", function() {
window.tooltip = setTimeout(function(){ $("#skp-premium-tooltip").hide(); }, 1000);
});
return;
});
});
</script>
<?php
}
}
}

View File

@@ -0,0 +1,110 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( !class_exists('SilkyPress_Warnings') ) {
/**
* SilkyPress_Warnings
*/
class SilkyPress_Warnings {
var $allowed_actions = array();
var $notices = array();
/**
* Constructor
*/
public function __construct($allowed_actions) {
$this->allowed_actions = $allowed_actions;
add_action( 'wp_ajax_sk_dismiss_warning', array( $this, 'notice_dismiss' ) );
}
/**
* Check if we are on the right page
*/
function is_url( $url_part = '' ) {
if ( !isset( $_SERVER ) || !isset( $_SERVER['REQUEST_URI'] ) ) {
return false;
}
if ( strpos( $_SERVER['REQUEST_URI'], $url_part ) !== false ) {
return true;
}
return false;
}
/**
* Add this message to the $this->notices array
*/
function add_notice($id, $message, $class = '') {
if ( get_option($id) != false ) return false;
$notice = array(
'id' => $id,
'message' => $message,
);
if ( !empty($class) ) $notice['class'] = $class;
$this->notices[] = $notice;
}
function show_warnings() {
add_action( 'admin_notices', array($this, 'show_admin_notice') );
}
/**
* Show the admin notices
* */
function show_admin_notice() {
if ( !is_array($this->notices) || count($this->notices) == 0 ) return;
foreach( $this->notices as $_n ) {
$nonce = wp_create_nonce( $_n['id'] );
if ( !isset($_n['class'])) $_n['class'] = 'notice notice-warning is-dismissible';
$_n['class'] .= ' sk-notice-dismiss';
printf( '<div class="%1$s" id="%2$s" data-nonce="%3$s"><p>%4$s</p></div>', $_n['class'], $_n['id'], $nonce, $_n['message'] );
}
?>
<script type='text/javascript'>
jQuery(function($){
$(document).on( 'click', '.sk-notice-dismiss', function() {
var id = $(this).attr('id');
var data = {
action: 'sk_dismiss_warning',
option: id,
nonce: $(this).data('nonce'),
};
$.post(ajaxurl, data, function(response ) {
$('#'+id).fadeOut('slow');
});
});
});
</script>
<?php
}
/**
* Ajax response for `notice_dismiss` action
*/
function notice_dismiss() {
$option = $_POST['option'];
if ( ! in_array($option, $this->allowed_actions ) ) return;
check_ajax_referer( $option, 'nonce' );
update_option( $option, 1 );
wp_die();
}
}
}