| Current Path : /home/bechata/mp/wp-content/uploads/2022/ejn73c/ |
| Current File : /home/bechata/mp/wp-content/uploads/2022/ejn73c/inc.tar |
core/generator-views.php 0000666 00000025601 15175265024 0011345 0 ustar 00 <?php
/**
* Shortcode Generator
*/
class Su_Generator_Views {
/**
* Constructor
*/
function __construct() {}
public static function text( $id, $field ) {
$field = wp_parse_args( $field, array(
'default' => ''
) );
$return = '<input type="text" name="' . $id . '" value="' . esc_attr( $field['default'] ) . '" id="su-generator-attr-' . $id . '" class="su-generator-attr" />';
return $return;
}
public static function textarea( $id, $field ) {
$field = wp_parse_args( $field, array(
'rows' => 3,
'default' => ''
) );
$return = '<textarea name="' . $id . '" id="su-generator-attr-' . $id . '" rows="' . $field['rows'] . '" class="su-generator-attr">' . esc_textarea( $field['default'] ) . '</textarea>';
return $return;
}
public static function select( $id, $field ) {
// Multiple selects
$multiple = isset( $field['multiple'] ) && $field['multiple'] ? ' multiple' : '';
$return = '<select name="' . $id . '" id="su-generator-attr-' . $id . '" class="su-generator-attr"' . $multiple . '>';
// Create options
foreach ( $field['values'] as $option_value => $option_title ) {
// Is this option selected
$selected = ( $field['default'] === $option_value ) ? ' selected="selected"' : '';
// Create option
$return .= '<option value="' . $option_value . '"' . $selected . '>' . $option_title . '</option>';
}
$return .= '</select>';
return $return;
}
public static function post_type( $id, $field ) {
// Get post types
$types = get_post_types( array(), 'objects', 'or' );
// Prepare empty array for values
$field['values'] = array(
'any' => _x( 'Any post type', 'shortcodes-ultimate' ),
);
// Fill the array
foreach( $types as $type ) {
$field['values'][$type->name] = $type->label;
}
// Create select
return self::select( $id, $field );
}
public static function taxonomy( $id, $field ) {
// Get taxonomies
$taxonomies = get_taxonomies( array(), 'objects', 'or' );
// Prepare empty array for values
$field['values'] = array();
// Fill the array
foreach( $taxonomies as $taxonomy ) {
$field['values'][$taxonomy->name] = $taxonomy->label;
}
// Create select
return self::select( $id, $field );
}
public static function term( $id, $field ) {
// Get categories
$field['values'] = Su_Generator::get_terms( 'category' );
// Create select
return self::select( $id, $field );
}
public static function bool( $id, $field ) {
$return = '<span class="su-generator-switch su-generator-switch-' . $field['default'] . '"><span class="su-generator-yes">' . __( 'Yes', 'shortcodes-ultimate' ) . '</span><span class="su-generator-no">' . __( 'No', 'shortcodes-ultimate' ) . '</span></span><input type="hidden" name="' . $id . '" value="' . esc_attr( $field['default'] ) . '" id="su-generator-attr-' . $id . '" class="su-generator-attr su-generator-switch-value" />';
return $return;
}
public static function upload( $id, $field ) {
$return = '<input type="text" name="' . $id . '" value="' . esc_attr( $field['default'] ) . '" id="su-generator-attr-' . $id . '" class="su-generator-attr su-generator-upload-value" /><div class="su-generator-field-actions"><a href="javascript:;" class="button su-generator-upload-button"><img src="' . admin_url( '/images/media-button.png' ) . '" alt="' . __( 'Media manager', 'shortcodes-ultimate' ) . '" />' . __( 'Media manager', 'shortcodes-ultimate' ) . '</a></div>';
return $return;
}
public static function icon( $id, $field ) {
$return = '<input type="text" name="' . $id . '" value="' . esc_attr( $field['default'] ) . '" id="su-generator-attr-' . $id . '" class="su-generator-attr su-generator-icon-picker-value" /><div class="su-generator-field-actions"><a href="javascript:;" class="button su-generator-upload-button su-generator-field-action"><img src="' . admin_url( '/images/media-button.png' ) . '" alt="' . __( 'Media manager', 'shortcodes-ultimate' ) . '" />' . __( 'Media manager', 'shortcodes-ultimate' ) . '</a> <a href="javascript:;" class="button su-generator-icon-picker-button su-generator-field-action"><img src="' . admin_url( '/images/media-button-other.gif' ) . '" alt="' . __( 'Icon picker', 'shortcodes-ultimate' ) . '" />' . __( 'Icon picker', 'shortcodes-ultimate' ) . '</a></div><div class="su-generator-icon-picker su-generator-clearfix"><input type="text" class="widefat" placeholder="' . __( 'Filter icons', 'shortcodes-ultimate' ) . '" /></div>';
return $return;
}
public static function color( $id, $field ) {
$return = '<span class="su-generator-select-color"><span class="su-generator-select-color-wheel"></span><input type="text" name="' . $id . '" value="' . $field['default'] . '" id="su-generator-attr-' . $id . '" class="su-generator-attr su-generator-select-color-value" /></span>';
return $return;
}
public static function number( $id, $field ) {
$return = '<input type="number" name="' . $id . '" value="' . esc_attr( $field['default'] ) . '" id="su-generator-attr-' . $id . '" min="' . $field['min'] . '" max="' . $field['max'] . '" step="' . $field['step'] . '" class="su-generator-attr" />';
return $return;
}
public static function slider( $id, $field ) {
$return = '<div class="su-generator-range-picker su-generator-clearfix"><input type="number" name="' . $id . '" value="' . esc_attr( $field['default'] ) . '" id="su-generator-attr-' . $id . '" min="' . $field['min'] . '" max="' . $field['max'] . '" step="' . $field['step'] . '" class="su-generator-attr" /></div>';
return $return;
}
public static function shadow( $id, $field ) {
$defaults = ( $field['default'] === 'none' ) ? array ( '0', '0', '0', '#000000' ) : explode( ' ', str_replace( 'px', '', $field['default'] ) );
$return = '<div class="su-generator-shadow-picker"><span class="su-generator-shadow-picker-field"><input type="number" min="-1000" max="1000" step="1" value="' . $defaults[0] . '" class="su-generator-sp-hoff" /><small>' . __( 'Horizontal offset', 'shortcodes-ultimate' ) . ' (px)</small></span><span class="su-generator-shadow-picker-field"><input type="number" min="-1000" max="1000" step="1" value="' . $defaults[1] . '" class="su-generator-sp-voff" /><small>' . __( 'Vertical offset', 'shortcodes-ultimate' ) . ' (px)</small></span><span class="su-generator-shadow-picker-field"><input type="number" min="-1000" max="1000" step="1" value="' . $defaults[2] . '" class="su-generator-sp-blur" /><small>' . __( 'Blur', 'shortcodes-ultimate' ) . ' (px)</small></span><span class="su-generator-shadow-picker-field su-generator-shadow-picker-color"><span class="su-generator-shadow-picker-color-wheel"></span><input type="text" value="' . $defaults[3] . '" class="su-generator-shadow-picker-color-value" /><small>' . __( 'Color', 'shortcodes-ultimate' ) . '</small></span><input type="hidden" name="' . $id . '" value="' . esc_attr( $field['default'] ) . '" id="su-generator-attr-' . $id . '" class="su-generator-attr" /></div>';
return $return;
}
public static function border( $id, $field ) {
$defaults = ( $field['default'] === 'none' ) ? array ( '0', 'solid', '#000000' ) : explode( ' ', str_replace( 'px', '', $field['default'] ) );
$borders = su_html_dropdown( array(
'options' => su_get_config( 'borders' ),
'class' => 'su-generator-bp-style',
'selected' => $defaults[1]
) );
$return = '<div class="su-generator-border-picker"><span class="su-generator-border-picker-field"><input type="number" min="-1000" max="1000" step="1" value="' . $defaults[0] . '" class="su-generator-bp-width" /><small>' . __( 'Border width', 'shortcodes-ultimate' ) . ' (px)</small></span><span class="su-generator-border-picker-field">' . $borders . '<small>' . __( 'Border style', 'shortcodes-ultimate' ) . '</small></span><span class="su-generator-border-picker-field su-generator-border-picker-color"><span class="su-generator-border-picker-color-wheel"></span><input type="text" value="' . $defaults[2] . '" class="su-generator-border-picker-color-value" /><small>' . __( 'Border color', 'shortcodes-ultimate' ) . '</small></span><input type="hidden" name="' . $id . '" value="' . esc_attr( $field['default'] ) . '" id="su-generator-attr-' . $id . '" class="su-generator-attr" /></div>';
return $return;
}
public static function image_source( $id, $field ) {
$field = wp_parse_args( $field, array(
'default' => 'none'
) );
if ( ! isset( $field['media_sources'] ) ) {
$field['media_sources'] = array(
'media' => __( 'Media library', 'shortcodes-ultimate' ),
'posts: recent' => __( 'Recent posts', 'shortcodes-ultimate' ),
'taxonomy' => __( 'Taxonomy', 'shortcodes-ultimate' ),
);
}
$sources = su_html_dropdown( array(
'options' => $field['media_sources'],
'selected' => '0',
'none' => __( 'Select images source', 'shortcodes-ultimate' ) . '…',
'class' => 'su-generator-isp-sources'
) );
$categories = su_html_dropdown( array(
'options' => Su_Generator::get_terms( 'category' ),
'multiple' => true,
'size' => 10,
'class' => 'su-generator-isp-categories'
) );
$taxonomies = su_html_dropdown( array(
'options' => Su_Generator::get_taxonomies(),
'none' => __( 'Select taxonomy', 'shortcodes-ultimate' ) . '…',
'selected' => '0',
'class' => 'su-generator-isp-taxonomies'
) );
$terms = su_html_dropdown( array(
'class' => 'su-generator-isp-terms',
'multiple' => true,
'size' => 10,
'disabled' => true,
'style' => 'display:none'
) );
$return = '<div class="su-generator-isp">' . $sources . '<div class="su-generator-isp-source su-generator-isp-source-media"><div class="su-generator-clearfix"><a href="javascript:;" class="button button-primary su-generator-isp-add-media"><i class="sui sui-plus"></i> ' . __( 'Add images', 'shortcodes-ultimate' ) . '</a></div><div class="su-generator-isp-images su-generator-clearfix"><em class="description">' . __( 'Click the button above and select images.<br>You can select multimple images with Ctrl (Cmd) key', 'shortcodes-ultimate' ) . '</em></div></div><div class="su-generator-isp-source su-generator-isp-source-category"><em class="description">' . __( 'Select categories to retrieve posts from.<br>You can select multiple categories with Ctrl (Cmd) key', 'shortcodes-ultimate' ) . '</em>' . $categories . '</div><div class="su-generator-isp-source su-generator-isp-source-taxonomy"><em class="description">' . __( 'Select taxonomy and it\'s terms.<br>You can select multiple terms with Ctrl (Cmd) key', 'shortcodes-ultimate' ) . '</em>' . $taxonomies . $terms . '</div><input type="hidden" name="' . $id . '" value="' . $field['default'] . '" id="su-generator-attr-' . $id . '" class="su-generator-attr" /></div>';
return $return;
}
public static function extra_css_class( $id, $field ) {
$field = wp_parse_args( $field, array(
'default' => ''
) );
$return = '<input type="text" name="' . $id . '" value="' . esc_attr( $field['default'] ) . '" id="su-generator-attr-' . $id . '" class="su-generator-attr" />';
return $return;
}
}
core/generator.php 0000666 00000056344 15175265024 0010222 0 ustar 00 <?php
/**
* Shortcode Generator
*/
class Su_Generator {
public function __construct() {
add_action(
'media_buttons',
array( __CLASS__, 'button_classic_editor' ),
1000
);
add_action(
'enqueue_block_editor_assets',
array( __CLASS__, 'button_block_editor' )
);
add_action( 'wp_footer', array( __CLASS__, 'popup' ) );
add_action( 'admin_footer', array( __CLASS__, 'popup' ) );
add_action( 'wp_ajax_su_generator_settings', array( __CLASS__, 'settings' ) );
add_action( 'wp_ajax_su_generator_preview', array( __CLASS__, 'preview' ) );
add_action( 'su/generator/actions', array( __CLASS__, 'presets' ) );
add_action( 'wp_ajax_su_generator_get_icons', array( __CLASS__, 'ajax_get_icons' ) );
add_action( 'wp_ajax_su_generator_get_terms', array( __CLASS__, 'ajax_get_terms' ) );
add_action( 'wp_ajax_su_generator_get_taxonomies', array( __CLASS__, 'ajax_get_taxonomies' ) );
add_action( 'wp_ajax_su_generator_add_preset', array( __CLASS__, 'ajax_add_preset' ) );
add_action( 'wp_ajax_su_generator_remove_preset', array( __CLASS__, 'ajax_remove_preset' ) );
add_action( 'wp_ajax_su_generator_get_preset', array( __CLASS__, 'ajax_get_preset' ) );
}
/**
* @deprecated 5.1.0 Replaced with Su_Generator::classic_editor_button()
*/
public static function button( $args = array() ) {
return self::button_html_editor( $args );
}
public static function classic_editor_button( $args = array() ) {
return self::button_html_editor( $args );
}
public static function button_html_editor( $args = array() ) {
if ( ! self::access_check() ) {
return;
}
self::enqueue_generator();
$args = wp_parse_args(
$args,
array(
'target' => '',
'tag' => 'button',
'text' => __( 'Insert shortcode', 'shortcodes-ultimate' ),
'class' => 'button',
'icon' => true,
'echo' => true,
'shortcode' => '',
)
);
if ( $args['icon'] ) {
$args['icon'] = '<svg style="vertical-align:middle;position:relative;top:-1px;opacity:.8;width:18px;height:18px" viewBox="0 0 20 20" width="18" height="18" aria-hidden="true"><path fill="currentcolor" d="M8.48 2.75v2.5H5.25v9.5h3.23v2.5H2.75V2.75h5.73zm9.27 14.5h-5.73v-2.5h3.23v-9.5h-3.23v-2.5h5.73v14.5z"/></svg>';
}
$onclick = sprintf(
"SUG.App.insert('html',{editorID:'%s',shortcode:'%s'});return false;",
esc_attr( $args['target'] ),
esc_attr( $args['shortcode'] )
);
$button = sprintf(
'<%6$s
type="button"
href="javascript:;"
class="su-generator-button %1$s"
title="%2$s"
onclick="%3$s"
>%4$s %5$s</%6$s>',
esc_attr( $args['class'] ),
esc_attr( $args['text'] ),
$onclick,
$args['icon'],
esc_html( $args['text'] ),
sanitize_key( $args['tag'] )
);
if ( $args['echo'] ) {
echo $button;
}
return $button;
}
public static function button_classic_editor( $target ) {
if ( ! self::access_check() ) {
return;
}
self::enqueue_generator();
$onclick = sprintf(
"SUG.App.insert('classic',{editorID:'%s',shortcode:''});",
esc_attr( $target )
);
$icon = '<svg style="vertical-align:middle;position:relative;top:-1px;opacity:.8;width:18px;height:18px" viewBox="0 0 20 20" width="18" height="18" aria-hidden="true"><path fill="currentcolor" d="M8.48 2.75v2.5H5.25v9.5h3.23v2.5H2.75V2.75h5.73zm9.27 14.5h-5.73v-2.5h3.23v-9.5h-3.23v-2.5h5.73v14.5z"/></svg>';
$button = sprintf(
'<button
type="button"
class="su-generator-button button"
title="%1$s"
onclick="%2$s"
>
%3$s %1$s
</button>',
__( 'Insert shortcode', 'shortcodes-ultimate' ),
$onclick,
$icon
);
echo $button;
}
public static function button_block_editor() {
if ( ! self::access_check() ) {
return;
}
self::enqueue_generator();
wp_enqueue_script(
'shortcodes-ultimate-block-editor',
plugins_url( 'includes/js/block-editor/index.js', SU_PLUGIN_FILE ),
array( 'wp-element', 'wp-components', 'su-generator' ),
SU_PLUGIN_VERSION,
true
);
wp_localize_script(
'shortcodes-ultimate-block-editor',
'SUBlockEditorL10n',
array( 'insertShortcode' => __( 'Insert shortcode', 'shortcodes-ultimate' ) )
);
wp_localize_script(
'shortcodes-ultimate-block-editor',
'SUBlockEditorSettings',
array( 'supportedBlocks' => get_option( 'su_option_supported_blocks', array() ) )
);
}
public static function enqueue_generator() {
do_action( 'su/generator/enqueue' );
self::enqueue_assets();
}
public static function enqueue_assets() {
wp_enqueue_media();
su_query_asset(
'css',
array(
'simpleslider',
'farbtastic',
'magnific-popup',
'su-icons',
'su-generator',
)
);
su_query_asset(
'js',
array(
'jquery',
'jquery-ui-core',
'jquery-ui-widget',
'jquery-ui-mouse',
'simpleslider',
'farbtastic',
'magnific-popup',
'su-generator',
)
);
}
/**
* Generator popup form
*/
public static function popup() {
if ( ! did_action( 'su/generator/enqueue' ) ) {
return;
}
$tools = apply_filters( 'su/generator/tools', array(
'<a href="' . admin_url( 'admin.php?page=shortcodes-ultimate-settings' ) . '" target="_blank" title="' . __( 'Settings', 'shortcodes-ultimate' ) . '">' . __( 'Plugin settings', 'shortcodes-ultimate' ) . '</a>',
'<a href="https://getshortcodes.com/" target="_blank" title="' . __( 'Plugin homepage', 'shortcodes-ultimate' ) . '">' . __( 'Plugin homepage', 'shortcodes-ultimate' ) . '</a>',
) );
// Add add-ons links
if ( ! self::is_addons_active() ) {
$tools[] = '<a href="' . admin_url( 'admin.php?page=shortcodes-ultimate-addons&from-generator' ) . '" target="_blank" title="' . __( 'Add-ons', 'shortcodes-ultimate' ) . '" class="su-add-ons">★ ' . __( 'Premium Add-ons', 'shortcodes-ultimate' ) . '</a>';
}
?>
<div id="su-generator-wrap" style="display:none">
<div id="su-generator">
<div id="su-generator-header">
<div id="su-generator-tools"><?php echo implode( ' <span></span> ', $tools ); ?></div>
<input type="text" name="su_generator_search" id="su-generator-search" value="" placeholder="<?php _e( 'Search for shortcodes', 'shortcodes-ultimate' ); ?>" />
<p id="su-generator-search-pro-tip"><?php printf( '<strong>%s:</strong> %s', __( 'Pro Tip', 'shortcodes-ultimate' ), __( 'Hit enter to select highlighted shortcode, while searching' ) ) ?></p>
<div id="su-generator-filter">
<strong><?php _e( 'Filter by type', 'shortcodes-ultimate' ); ?></strong>
<?php foreach ( su_get_config( 'groups' ) as $group => $label ) echo '<a href="#" data-filter="' . $group . '">' . $label . '</a>'; ?>
</div>
<div id="su-generator-choices" class="su-generator-clearfix">
<?php
// Choices loop
foreach ( self::get_shortcodes() as $name => $shortcode ) {
if ( ! isset( $shortcode['icon'] ) ) {
$shortcode['icon'] = 'puzzle-piece';
}
if ( strpos( $shortcode['icon'], '/' ) === false ) {
$shortcode['icon'] = 'icon:' . $shortcode['icon'];
}
$shortcode['name'] = ( isset( $shortcode['name'] ) ) ? $shortcode['name'] : $name;
if ( ! isset( $shortcode['desc'] ) ) {
$shortcode['desc'] = '';
}
echo '<span data-name="' . $shortcode['name'] . '" data-shortcode="' . $name . '" title="' . esc_attr( $shortcode['desc'] ) . '" data-desc="' . esc_attr( $shortcode['desc'] ) . '" data-group="' . $shortcode['group'] . '">' . su_html_icon( $shortcode['icon'] ) . $shortcode['name'] . '</span>' . "\n";
}
?>
</div>
</div>
<div id="su-generator-settings"></div>
<input type="hidden" name="su-generator-selected" id="su-generator-selected" value="<?php echo plugins_url( '', SU_PLUGIN_FILE ); ?>" />
<input type="hidden" name="su-generator-url" id="su-generator-url" value="<?php echo plugins_url( '', SU_PLUGIN_FILE ); ?>" />
<input type="hidden" name="su-compatibility-mode-prefix" id="su-compatibility-mode-prefix" value="<?php echo su_get_shortcode_prefix(); ?>" />
<input type="hidden" name="su-generator-option-skip" id="su-generator-option-skip" value="<?php echo esc_attr( get_option( 'su_option_skip', '' ) ); ?>" />
<div id="su-generator-result" style="display:none"></div>
</div>
</div>
<?php
}
/**
* Process AJAX request
*/
public static function settings() {
self::access();
// Param check
if ( empty( $_REQUEST['shortcode'] ) ) wp_die( __( 'Shortcode not specified', 'shortcodes-ultimate' ) );
// Request queried shortcode
$shortcode = su_get_shortcode( sanitize_key( $_REQUEST['shortcode'] ) );
// Call custom callback
if (
isset( $shortcode['generator_callback'] ) &&
is_callable( $shortcode['generator_callback'] )
) {
call_user_func( $shortcode['generator_callback'], $shortcode );
exit;
}
// Prepare skip-if-default option
$skip = ( get_option( 'su_option_skip' ) === 'on' ) ? ' su-generator-skip' : '';
// Prepare actions
$actions = apply_filters( 'su/generator/actions', array(
'insert' => '<a href="javascript:void(0);" class="button button-primary button-large su-generator-insert"><i class="sui sui-check"></i> ' . __( 'Insert shortcode', 'shortcodes-ultimate' ) . '</a>',
'preview' => '<a href="javascript:void(0);" class="button button-large su-generator-toggle-preview"><i class="sui sui-eye"></i> ' . __( 'Live preview', 'shortcodes-ultimate' ) . '</a>'
) );
// Shortcode header
$return = '<div id="su-generator-breadcrumbs">';
$return .= apply_filters( 'su/generator/breadcrumbs', '<a href="javascript:void(0);" class="su-generator-home" title="' . __( 'Click to return to the shortcodes list', 'shortcodes-ultimate' ) . '">' . __( 'All shortcodes', 'shortcodes-ultimate' ) . '</a> → <span>' . $shortcode['name'] . '</span> <small class="alignright">' . $shortcode['desc'] . '</small><div class="su-generator-clear"></div>' );
$return .= '</div>';
// Shortcode note
if ( isset( $shortcode['note'] ) ) {
$return .= '<div class="su-generator-note"><i class="sui sui-info-circle"></i><div class="su-generator-note-content">' . wpautop( $shortcode['note'] ) . '</div></div>';
}
// Shortcode has atts
if ( isset( $shortcode['atts'] ) && count( $shortcode['atts'] ) ) {
// Loop through shortcode parameters
foreach ( $shortcode['atts'] as $attr_name => $attr_info ) {
// Prepare default value
$default = (string) ( isset( $attr_info['default'] ) ) ? $attr_info['default'] : '';
$attr_info['name'] = ( isset( $attr_info['name'] ) ) ? $attr_info['name'] : $attr_name;
$return .= '<div class="su-generator-attr-container' . $skip . '" data-default="' . esc_attr( $default ) . '">';
$return .= '<h5>' . $attr_info['name'] . '</h5>';
// Create field types
if ( !isset( $attr_info['type'] ) && isset( $attr_info['values'] ) && is_array( $attr_info['values'] ) && count( $attr_info['values'] ) ) $attr_info['type'] = 'select';
elseif ( !isset( $attr_info['type'] ) ) $attr_info['type'] = 'text';
if ( is_callable( array( 'Su_Generator_Views', $attr_info['type'] ) ) ) $return .= call_user_func( array( 'Su_Generator_Views', $attr_info['type'] ), $attr_name, $attr_info );
elseif ( isset( $attr_info['callback'] ) && is_callable( $attr_info['callback'] ) ) $return .= call_user_func( $attr_info['callback'], $attr_name, $attr_info );
if ( isset( $attr_info['desc'] ) ) $attr_info['desc'] = str_replace( '%su_skins_link%', self::skins_link(), $attr_info['desc'] );
if ( isset( $attr_info['desc'] ) ) $return .= '<div class="su-generator-attr-desc">' . str_replace( array( '<b%value>', '<b_>' ), '<b class="su-generator-set-value" title="' . __( 'Click to set this value', 'shortcodes-ultimate' ) . '">', $attr_info['desc'] ) . '</div>';
$return .= '</div>';
}
}
// Single shortcode (not closed)
if ( $shortcode['type'] == 'single' ) $return .= '<input type="hidden" name="su-generator-content" id="su-generator-content" value="false" />';
// Wrapping shortcode
else {
if ( !isset( $shortcode['content'] ) ) {
$shortcode['content'] = '';
}
if ( is_array( $shortcode['content'] ) ) {
$shortcode['content'] = self::get_shortcode_code( $shortcode['content'] );
}
// Prepare shortcode content
$return .= '<div class="su-generator-attr-container"><h5>' . __( 'Content', 'shortcodes-ultimate' ) . '</h5><textarea name="su-generator-content" id="su-generator-content" rows="5">' . esc_attr( str_replace( array( '%prefix_', '__' ), su_get_shortcode_prefix(), $shortcode['content'] ) ) . '</textarea></div>';
}
$return .= '<div id="su-generator-preview"></div>';
$return .= '<div class="su-generator-actions su-generator-clearfix">' . implode( ' ', array_values( $actions ) ) . '</div>';
set_transient( 'su/generator/settings/' . sanitize_text_field( $_REQUEST['shortcode'] ), $return, 2 * DAY_IN_SECONDS );
echo $return;
exit;
}
/**
* Process AJAX request and generate preview HTML
*/
public static function preview() {
// Check authentication
self::access();
// Output results
do_action( 'su/generator/preview/before' );
echo '<h5>' . __( 'Preview', 'shortcodes-ultimate' ) . '</h5>';
echo do_shortcode( wp_kses_post( wp_unslash( $_POST['shortcode'] ) ) );
echo '<div style="clear:both"></div>';
do_action( 'su/generator/preview/after' );
die();
}
public static function access() {
if ( !self::access_check() ) wp_die( __( 'Access denied', 'shortcodes-ultimate' ) );
}
public static function access_check() {
$required_capability = (string) get_option(
'su_option_generator_access',
'manage_options'
);
return current_user_can( $required_capability );
}
public static function ajax_get_icons() {
self::access();
$icons = array();
foreach ( su_get_config( 'icons' ) as $icon ) {
$icons[] = '<i class="sui sui-' . $icon . '" title="' . $icon . '"></i>';
}
die( implode( '', $icons ) );
}
public static function ajax_get_terms() {
self::access();
$args = array();
if ( isset( $_REQUEST['tax'] ) ) $args['options'] = (array) self::get_terms( sanitize_key( $_REQUEST['tax'] ) );
if ( isset( $_REQUEST['class'] ) ) $args['class'] = (string) sanitize_key( $_REQUEST['class'] );
if ( isset( $_REQUEST['multiple'] ) ) $args['multiple'] = (bool) sanitize_key( $_REQUEST['multiple'] );
if ( isset( $_REQUEST['size'] ) ) $args['size'] = (int) sanitize_key( $_REQUEST['size'] );
if ( isset( $_REQUEST['noselect'] ) ) $args['noselect'] = (bool) sanitize_key( $_REQUEST['noselect'] );
die( su_html_dropdown( $args ) );
}
public static function ajax_get_taxonomies() {
self::access();
$args = array();
$args['options'] = self::get_taxonomies();
die( su_html_dropdown( $args ) );
}
public static function presets( $actions ) {
ob_start();
?>
<div class="su-generator-presets alignright" data-shortcode="<?php echo sanitize_key( $_REQUEST['shortcode'] ); ?>">
<a href="javascript:void(0);" class="button button-large su-gp-button"><i class="sui sui-bars"></i> <?php _e( 'Presets', 'shortcodes-ultimate' ); ?></a>
<div class="su-gp-popup">
<div class="su-gp-head">
<a href="javascript:void(0);" class="button button-small button-primary su-gp-new"><?php _e( 'Save current settings as preset', 'shortcodes-ultimate' ); ?></a>
</div>
<div class="su-gp-list">
<?php self::presets_list(); ?>
</div>
</div>
</div>
<?php
$actions['presets'] = ob_get_contents();
ob_end_clean();
return $actions;
}
public static function presets_list( $shortcode = false ) {
// Shortcode isn't specified, try to get it from $_REQUEST
if ( !$shortcode ) $shortcode = $_REQUEST['shortcode'];
// Shortcode name is still doesn't exists, exit
if ( !$shortcode ) return;
// Shortcode has been specified, sanitize it
$shortcode = sanitize_key( $shortcode );
// Get presets
$presets = get_option( 'su_presets_' . $shortcode );
// Presets has been found
if ( is_array( $presets ) && count( $presets ) ) {
// Print the presets
foreach ( $presets as $preset ) {
echo '<span data-id="' . $preset['id'] . '"><em>' . stripslashes( $preset['name'] ) . '</em> <i class="sui sui-times"></i></span>';
}
// Hide default text
echo sprintf( '<b style="display:none">%s</b>', __( 'Presets not found', 'shortcodes-ultimate' ) );
}
// Presets doesn't found
else echo sprintf( '<b>%s</b>', __( 'Presets not found', 'shortcodes-ultimate' ) );
}
public static function ajax_add_preset() {
self::access();
// Check incoming data
if ( empty( $_POST['id'] ) ) return;
if ( empty( $_POST['name'] ) ) return;
if ( empty( $_POST['settings'] ) ) return;
if ( empty( $_POST['shortcode'] ) ) return;
// Clean-up incoming data
$id = sanitize_key( $_POST['id'] );
$name = sanitize_text_field( $_POST['name'] );
$settings = ( is_array( $_POST['settings'] ) ) ? stripslashes_deep( $_POST['settings'] ) : array();
$shortcode = sanitize_key( $_POST['shortcode'] );
// Prepare option name
$option = 'su_presets_' . $shortcode;
// Get the existing presets
$current = get_option( $option );
// Create array with new preset
$new = array(
'id' => $id,
'name' => $name,
'settings' => $settings
);
// Add new array to the option value
if ( !is_array( $current ) ) $current = array();
$current[$id] = $new;
// Save updated option
update_option( $option, $current );
// Clear cache
delete_transient( 'su/generator/settings/' . $shortcode );
}
public static function ajax_remove_preset() {
self::access();
// Check incoming data
if ( empty( $_POST['id'] ) ) return;
if ( empty( $_POST['shortcode'] ) ) return;
// Clean-up incoming data
$id = sanitize_key( $_POST['id'] );
$shortcode = sanitize_key( $_POST['shortcode'] );
// Prepare option name
$option = 'su_presets_' . $shortcode;
// Get the existing presets
$current = get_option( $option );
// Check that preset is exists
if ( !is_array( $current ) || empty( $current[$id] ) ) return;
// Remove preset
unset( $current[$id] );
// Save updated option
update_option( $option, $current );
// Clear cache
delete_transient( 'su/generator/settings/' . $shortcode );
}
public static function ajax_get_preset() {
self::access();
// Check incoming data
if ( empty( $_GET['id'] ) ) return;
if ( empty( $_GET['shortcode'] ) ) return;
// Clean-up incoming data
$id = sanitize_key( $_GET['id'] );
$shortcode = sanitize_key( $_GET['shortcode'] );
// Default data
$data = array();
// Get the existing presets
$presets = get_option( 'su_presets_' . $shortcode );
// Check that preset is exists
if ( is_array( $presets ) && isset( $presets[$id]['settings'] ) ) $data = $presets[$id]['settings'];
// Print results
die( json_encode( $data ) );
}
/**
* Helper function to create shortcode code with default settings.
*
* Example output: "[su_button color="#ff0000" ... ] Click me [/su_button]".
*
* @param mixed $args Array with settings
* @since 5.0.0
* @return string Shortcode code
*/
public static function get_shortcode_code( $args ) {
$defaults = array(
'id' => '',
'number' => 1,
'nested' => false,
);
// Accept shortcode ID as a string
if ( is_string( $args ) ) {
$args = array( 'id' => $args );
}
$args = wp_parse_args( $args, $defaults );
// Check shortcode ID
if ( empty( $args['id'] ) ) {
return '';
}
// Get shortcode data
$shortcode = su_get_shortcode( $args['id'] );
// Prepare shortcode prefix
$prefix = get_option( 'su_option_prefix' );
// Prepare attributes container
$attributes = '';
// Loop through attributes
foreach ( $shortcode['atts'] as $attr_id => $attribute ) {
// Skip hidden attributes
if ( isset( $attribute['hidden'] ) && $attribute['hidden'] ) {
continue;
}
// Add attribute
$attributes .= sprintf( ' %s="%s"', esc_html( $attr_id ), esc_attr( $attribute['default'] ) );
}
// Create opening tag with attributes
$output = "[{$prefix}{$args['id']}{$attributes}]";
// Indent nested shortcodes
if ( $args['nested'] ) {
$output = "\t" . $output;
}
// Insert shortcode content
if ( isset( $shortcode['content'] ) ) {
if ( is_string( $shortcode['content'] ) ) {
$output .= $shortcode['content'];
}
// Create complex content
else if ( is_array( $shortcode['content'] ) && $args['id'] !== $shortcode['content']['id'] ) {
$shortcode['content']['nested'] = true;
$output .= self::get_shortcode_code( $shortcode['content'] );
}
}
// Add closing tag
if ( isset( $shortcode['type'] ) && $shortcode['type'] === 'wrap' ) {
$output .= "[/{$prefix}{$args['id']}]";
}
// Repeat shortcode
if ( $args['number'] > 1 ) {
$output = implode( "\n", array_fill( 0, $args['number'], $output ) );
}
// Add line breaks around nested shortcodes
if ( $args['nested'] ) {
$output = "\n{$output}\n";
}
return $output;
}
/**
* Helper function to check if all available addons were activated.
*
* @since 5.0.5
* @return boolean True if all addons active, False otherwise.
*/
public static function is_addons_active() {
foreach ( su_get_config( 'addons' ) as $addon ) {
if ( isset( $addon['is_bundle'] ) && $addon['is_bundle'] ) {
continue;
}
$addon_id = sanitize_key( $addon['id'] );
if ( ! did_action( "su/{$addon_id}/ready" ) ) {
return false;
}
}
return true;
}
/**
* Display "Install additional skins" link if add-on isn't installed.
*
* @since 5.0.5
* @return string
*/
public static function skins_link() {
if ( did_action( 'su/skins/ready' ) ) {
return sprintf(
'<br><strong>%s</strong><br><strong>%s</strong>',
__( 'Additional skins successfully installed', 'shortcodes-ultimate' ),
__( 'Open dropdown to choose one of new styles', 'shortcodes-ultimate' )
);
}
else {
return sprintf(
'<br><a href="https://getshortcodes.com/add-ons/additional-skins/" target="_blank">%s →</a>',
__( 'Get more styles', 'shortcodes-ultimate' )
);
}
}
/**
* Get available shortcodes, skipping deprecated ones.
*
* @since 5.0.5
* @return array Available shortcodes data.
*/
public static function get_shortcodes() {
$shortcodes = su_get_all_shortcodes();
if ( get_option( 'su_option_hide_deprecated' ) ) {
$shortcodes = array_filter(
$shortcodes,
array( __CLASS__, 'filter_deprecated_shortcodes' )
);
}
return $shortcodes;
}
/**
* Filter shortcodes and skip deprecated ones.
*
* @since 5.0.5
* @param array $shortcode A single shortcode data.
* @return boolean False if shortcode deprecated, True otherwise.
*/
public static function filter_deprecated_shortcodes( $shortcode ) {
return ! isset( $shortcode['deprecated'] );
}
/**
* Get list of taxonomies as key-value pairs.
*
* @since 5.0.5
* @return array List of taxonomies.
*/
public static function get_taxonomies() {
$taxes = array();
foreach ( (array) get_taxonomies( '', 'objects' ) as $tax ) {
$taxes[$tax->name] = $tax->label;
}
return $taxes;
}
/**
* Get list of terms as key-value pairs.
*
* @since 5.0.5
* @return array List of terms.
*/
public static function get_terms( $tax = 'category', $key = 'id' ) {
$terms = array();
if ( $key === 'id' ) {
foreach ( (array) get_terms( $tax, array( 'hide_empty' => false ) ) as $term ) {
$terms[$term->term_id] = $term->name;
}
}
elseif ( $key === 'slug' ) {
foreach ( (array) get_terms( $tax, array( 'hide_empty' => false ) ) as $term ) {
$terms[$term->slug] = $term->name;
}
}
return $terms;
}
}
new Su_Generator;
class Shortcodes_Ultimate_Generator extends Su_Generator {
function __construct() {
parent::__construct();
}
}
core/tools.php 0000666 00000027634 15175265024 0007374 0 ustar 00 <?php
/**
* Resizes an image and returns an array containing the resized URL, width, height and file type. Uses native WordPress functionality.
*
* @author Matthew Ruddy (http://easinglider.com)
* @return array An array containing the resized image URL, width, height and file type.
*/
function su_image_resize( $url, $width = null, $height = null, $crop = true, $retina = false ) {
global $wp_version;
//######################################################################
// First implementation
//######################################################################
if ( isset( $wp_version ) && version_compare( $wp_version, '3.5' ) >= 0 ) {
global $wpdb;
if ( empty( $url ) ) {
return new WP_Error( 'no_image_url', 'No image URL has been entered.', $url );
}
// Get default size from database
$width = ( $width ) ? $width : get_option( 'thumbnail_size_w' );
$height = ( $height ) ? $height : get_option( 'thumbnail_size_h' );
// Allow for different retina sizes
$retina = $retina ? ( $retina === true ? 2 : $retina ) : 1;
// Get the image file path
$file_path = parse_url( $url );
$file_path = $_SERVER['DOCUMENT_ROOT'] . $file_path['path'];
// Check for Multisite
if ( is_multisite() ) {
global $blog_id;
$blog_details = get_blog_details( $blog_id );
$file_path = str_replace( $blog_details->path . 'files/', '/wp-content/blogs.dir/' . $blog_id . '/files/', $file_path );
}
// Destination width and height variables
$dest_width = intval( $width ) * intval( $retina );
$dest_height = intval( $height ) * intval( $retina );
// File name suffix (appended to original file name)
$suffix = "{$dest_width}x{$dest_height}";
// Some additional info about the image
$info = pathinfo( $file_path );
$dir = $info['dirname'];
$ext = $info['extension'];
$name = wp_basename( $file_path, ".$ext" );
// Suffix applied to filename
$suffix = "{$dest_width}x{$dest_height}";
// Get the destination file name
$dest_file_name = "{$dir}/{$name}-{$suffix}.{$ext}";
if ( ! file_exists( $dest_file_name ) ) {
$query = $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE guid='%s'", $url );
$get_attachment = $wpdb->get_results( $query );
if ( ! $get_attachment ) {
return array(
'url' => $url,
'width' => $width,
'height' => $height,
);
}
// Load WordPress Image Editor
$editor = wp_get_image_editor( $file_path );
if ( is_wp_error( $editor ) ) {
return array(
'url' => $url,
'width' => $width,
'height' => $height,
);
}
// Get the original image size
$size = $editor->get_size();
$orig_width = $size['width'];
$orig_height = $size['height'];
$src_x = $src_y = 0;
$src_w = $orig_width;
$src_h = $orig_height;
if ( $crop ) {
$cmp_x = $orig_width / $dest_width;
$cmp_y = $orig_height / $dest_height;
// Calculate x or y coordinate, and width or height of source
if ( $cmp_x > $cmp_y ) {
$src_w = round( $orig_width / $cmp_x * $cmp_y );
$src_x = round( ( $orig_width - ( $orig_width / $cmp_x * $cmp_y ) ) / 2 );
} elseif ( $cmp_y > $cmp_x ) {
$src_h = round( $orig_height / $cmp_y * $cmp_x );
$src_y = round( ( $orig_height - ( $orig_height / $cmp_y * $cmp_x ) ) / 2 );
}
}
// Time to crop the image!
$editor->crop( $src_x, $src_y, $src_w, $src_h, $dest_width, $dest_height );
// Now let's save the image
$saved = $editor->save( $dest_file_name );
// Get resized image information
$resized_url = str_replace( basename( $url ), basename( $saved['path'] ), $url );
$resized_width = $saved['width'];
$resized_height = $saved['height'];
$resized_type = $saved['mime-type'];
// Add the resized dimensions to original image metadata (so we can delete our resized images when the original image is delete from the Media Library)
$metadata = wp_get_attachment_metadata( $get_attachment[0]->ID );
if ( isset( $metadata['image_meta'] ) ) {
$metadata['image_meta']['resized_images'][] = $resized_width . 'x' . $resized_height;
wp_update_attachment_metadata( $get_attachment[0]->ID, $metadata );
}
// Create the image array
$image_array = array(
'url' => $resized_url,
'width' => $resized_width,
'height' => $resized_height,
'type' => $resized_type,
);
} else {
$image_array = array(
'url' => str_replace( basename( $url ), basename( $dest_file_name ), $url ),
'width' => $dest_width,
'height' => $dest_height,
'type' => $ext,
);
}
// Return image array
return $image_array;
}
//######################################################################
// Second implementation
//######################################################################
else {
global $wpdb;
if ( empty( $url ) ) {
return new WP_Error( 'no_image_url', 'No image URL has been entered.', $url );
}
// Bail if GD Library doesn't exist
if ( ! extension_loaded( 'gd' ) || ! function_exists( 'gd_info' ) ) {
return array(
'url' => $url,
'width' => $width,
'height' => $height,
);
}
// Get default size from database
$width = ( $width ) ? $width : get_option( 'thumbnail_size_w' );
$height = ( $height ) ? $height : get_option( 'thumbnail_size_h' );
// Allow for different retina sizes
$retina = $retina ? ( $retina === true ? 2 : $retina ) : 1;
// Destination width and height variables
$dest_width = $width * $retina;
$dest_height = $height * $retina;
// Get image file path
$file_path = parse_url( $url );
$file_path = $_SERVER['DOCUMENT_ROOT'] . $file_path['path'];
// Check for Multisite
if ( is_multisite() ) {
global $blog_id;
$blog_details = get_blog_details( $blog_id );
$file_path = str_replace( $blog_details->path . 'files/', '/wp-content/blogs.dir/' . $blog_id . '/files/', $file_path );
}
// Some additional info about the image
$info = pathinfo( $file_path );
$dir = $info['dirname'];
$ext = $info['extension'];
$name = wp_basename( $file_path, ".$ext" );
// Suffix applied to filename
$suffix = "{$dest_width}x{$dest_height}";
// Get the destination file name
$dest_file_name = "{$dir}/{$name}-{$suffix}.{$ext}";
// No need to resize & create a new image if it already exists!
if ( ! file_exists( $dest_file_name ) ) {
/*
* Bail if this image isn't in the Media Library either.
* We only want to resize Media Library images, so we can be sure they get deleted correctly when appropriate.
*/
$query = $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE guid='%s'", $url );
$get_attachment = $wpdb->get_results( $query );
if ( ! $get_attachment ) {
return array(
'url' => $url,
'width' => $width,
'height' => $height,
);
}
$image = wp_load_image( $file_path );
if ( ! is_resource( $image ) ) {
return new WP_Error( 'error_loading_image_as_resource', $image, $file_path );
}
// Get the current image dimensions and type
$size = @getimagesize( $file_path );
if ( ! $size ) {
return new WP_Error( 'file_path_getimagesize_failed', 'Failed to get $file_path information using getimagesize.' );
}
list( $orig_width, $orig_height, $orig_type ) = $size;
// Create new image
$new_image = wp_imagecreatetruecolor( $dest_width, $dest_height );
// Do some proportional cropping if enabled
if ( $crop ) {
$src_x = $src_y = 0;
$src_w = $orig_width;
$src_h = $orig_height;
$cmp_x = $orig_width / $dest_width;
$cmp_y = $orig_height / $dest_height;
// Calculate x or y coordinate, and width or height of source
if ( $cmp_x > $cmp_y ) {
$src_w = round( $orig_width / $cmp_x * $cmp_y );
$src_x = round( ( $orig_width - ( $orig_width / $cmp_x * $cmp_y ) ) / 2 );
} elseif ( $cmp_y > $cmp_x ) {
$src_h = round( $orig_height / $cmp_y * $cmp_x );
$src_y = round( ( $orig_height - ( $orig_height / $cmp_y * $cmp_x ) ) / 2 );
}
// Create the resampled image
imagecopyresampled( $new_image, $image, 0, 0, $src_x, $src_y, $dest_width, $dest_height, $src_w, $src_h );
} else {
imagecopyresampled( $new_image, $image, 0, 0, 0, 0, $dest_width, $dest_height, $orig_width, $orig_height );
}
// Convert from full colors to index colors, like original PNG.
if ( IMAGETYPE_PNG == $orig_type && function_exists( 'imageistruecolor' ) && ! imageistruecolor( $image ) ) {
imagetruecolortopalette( $new_image, false, imagecolorstotal( $image ) );
}
// Remove the original image from memory (no longer needed)
imagedestroy( $image );
// Check the image is the correct file type
if ( IMAGETYPE_GIF == $orig_type ) {
if ( ! imagegif( $new_image, $dest_file_name ) ) {
return new WP_Error( 'resize_path_invalid', 'Resize path invalid (GIF)' );
}
} elseif ( IMAGETYPE_PNG == $orig_type ) {
if ( ! imagepng( $new_image, $dest_file_name ) ) {
return new WP_Error( 'resize_path_invalid', 'Resize path invalid (PNG).' );
}
} else {
// All other formats are converted to jpg
if ( 'jpg' != $ext && 'jpeg' != $ext ) {
$dest_file_name = "{$dir}/{$name}-{$suffix}.jpg";
}
if ( ! imagejpeg( $new_image, $dest_file_name, apply_filters( 'resize_jpeg_quality', 90 ) ) ) {
return new WP_Error( 'resize_path_invalid', 'Resize path invalid (JPG).' );
}
}
// Remove new image from memory (no longer needed as well)
imagedestroy( $new_image );
// Set correct file permissions
$stat = stat( dirname( $dest_file_name ) );
$perms = $stat['mode'] & 0000666;
@chmod( $dest_file_name, $perms );
// Get some information about the resized image
$new_size = @getimagesize( $dest_file_name );
if ( ! $new_size ) {
return new WP_Error( 'resize_path_getimagesize_failed', 'Failed to get $dest_file_name (resized image) info via @getimagesize', $dest_file_name );
}
list( $resized_width, $resized_height, $resized_type ) = $new_size;
// Get the new image URL
$resized_url = str_replace( basename( $url ), basename( $dest_file_name ), $url );
// Add the resized dimensions to original image metadata (so we can delete our resized images when the original image is delete from the Media Library)
$metadata = wp_get_attachment_metadata( $get_attachment[0]->ID );
if ( isset( $metadata['image_meta'] ) ) {
$metadata['image_meta']['resized_images'][] = $resized_width . 'x' . $resized_height;
wp_update_attachment_metadata( $get_attachment[0]->ID, $metadata );
}
// Return array with resized image information
$image_array = array(
'url' => $resized_url,
'width' => $resized_width,
'height' => $resized_height,
'type' => $resized_type,
);
} else {
$image_array = array(
'url' => str_replace( basename( $url ), basename( $dest_file_name ), $url ),
'width' => $dest_width,
'height' => $dest_height,
'type' => $ext,
);
}
return $image_array;
}
}
/**
* Deletes the resized images when the original image is deleted from the WordPress Media Library.
*
* @author Matthew Ruddy
*/
function su_delete_resized_images( $post_id ) {
// Get attachment image metadata
$metadata = wp_get_attachment_metadata( $post_id );
if ( ! $metadata ) {
return;
}
// Do some bailing if we cannot continue
if ( ! isset( $metadata['file'] ) || ! isset( $metadata['image_meta']['resized_images'] ) ) {
return;
}
$pathinfo = pathinfo( $metadata['file'] );
$resized_images = $metadata['image_meta']['resized_images'];
// Get WordPress uploads directory (and bail if it doesn't exist)
$wp_upload_dir = wp_upload_dir();
$upload_dir = $wp_upload_dir['basedir'];
if ( ! is_dir( $upload_dir ) ) {
return;
}
// Delete the resized images
foreach ( $resized_images as $dims ) {
// Get the resized images filename
$file = $upload_dir . '/' . $pathinfo['dirname'] . '/' . $pathinfo['filename'] . '-' . $dims . '.' . $pathinfo['extension'];
// Delete the resized image
@unlink( $file );
}
}
add_action( 'delete_attachment', 'su_delete_resized_images' );
core/assets.php 0000666 00000024401 15175265024 0007523 0 ustar 00 <?php
/**
* Class for managing plugin assets
*/
class Su_Assets {
/**
* Set of queried assets
*
* @var array
*/
static $assets = array( 'css' => array(), 'js' => array() );
/**
* Constructor
*/
function __construct() {
// Register
add_action( 'wp_head', array( __CLASS__, 'register' ) );
add_action( 'admin_head', array( __CLASS__, 'register' ) );
add_action( 'su/generator/preview/before', array( __CLASS__, 'register' ) );
add_action( 'su/examples/preview/before', array( __CLASS__, 'register' ) );
// Enqueue
add_action( 'wp_footer', array( __CLASS__, 'enqueue' ) );
add_action( 'admin_footer', array( __CLASS__, 'enqueue' ) );
// Print
add_action( 'su/generator/preview/after', array( __CLASS__, 'prnt' ) );
add_action( 'su/examples/preview/after', array( __CLASS__, 'prnt' ) );
// Custom CSS
add_action( 'wp_footer', array( __CLASS__, 'custom_css' ), 99 );
add_action( 'su/generator/preview/after', array( __CLASS__, 'custom_css' ), 99 );
add_action( 'su/examples/preview/after', array( __CLASS__, 'custom_css' ), 99 );
// RTL support
add_action( 'su/assets/custom_css/after', array( __CLASS__, 'rtl_shortcodes' ) );
}
/**
* Register assets
*/
public static function register() {
// Chart.js
wp_register_script( 'chartjs', plugins_url( 'vendor/chartjs/chart.js', SU_PLUGIN_FILE ), false, '0.2', true );
// SimpleSlider
wp_register_script( 'simpleslider', plugins_url( 'vendor/simpleslider/simpleslider.js', SU_PLUGIN_FILE ), array( 'jquery' ), '1.0.0', true );
wp_register_style( 'simpleslider', plugins_url( 'vendor/simpleslider/simpleslider.css', SU_PLUGIN_FILE ), false, '1.0.0', 'all' );
// Owl Carousel
wp_register_script( 'owl-carousel', plugins_url( 'vendor/owl-carousel/owl-carousel.js', SU_PLUGIN_FILE ), array( 'jquery' ), '2.3.4', true );
wp_register_style( 'owl-carousel', plugins_url( 'vendor/owl-carousel/owl-carousel.css', SU_PLUGIN_FILE ), false, '2.3.4', 'all' );
// Animate.css
wp_register_style( 'animate', plugins_url( 'vendor/animatecss/animate.css', SU_PLUGIN_FILE ), false, '3.1.1', 'all' );
// InView
wp_register_script( 'jquery-inview', plugins_url( 'vendor/jquery-inview/jquery-inview.js', SU_PLUGIN_FILE ), array( 'jquery' ), '1.1.2', true );
// PopperJS
wp_register_script(
'popper',
plugins_url( 'vendor/popper/popper.min.js', SU_PLUGIN_FILE ),
array(),
'2.9.2',
true
);
// Magnific Popup
wp_register_style( 'magnific-popup', plugins_url( 'vendor/magnific-popup/magnific-popup.css', SU_PLUGIN_FILE ), false, '1.1.0', 'all' );
wp_register_script( 'magnific-popup', plugins_url( 'vendor/magnific-popup/magnific-popup.js', SU_PLUGIN_FILE ), array( 'jquery' ), '1.1.0', true );
// Swiper
wp_register_script( 'swiper', plugins_url( 'vendor/swiper/swiper.js', SU_PLUGIN_FILE ), array( 'jquery' ), '2.6.1', true );
// Flickity
wp_register_script(
'flickity',
plugins_url( 'vendor/flickity/flickity.js', SU_PLUGIN_FILE ),
array(),
'2.2.1',
true
);
wp_register_style(
'flickity',
plugins_url( 'vendor/flickity/flickity.css', SU_PLUGIN_FILE ),
array(),
'2.2.1',
'all'
);
// jPlayer
wp_register_script( 'jplayer', plugins_url( 'vendor/jplayer/jplayer.js', SU_PLUGIN_FILE ), array( 'jquery' ), '2.4.0', true );
// Generator
wp_register_style( 'su-generator', plugins_url( 'admin/css/generator.css', SU_PLUGIN_FILE ), array( 'farbtastic', 'magnific-popup', 'simpleslider' ), SU_PLUGIN_VERSION, 'all' );
wp_register_script( 'su-generator', plugins_url( 'includes/js/generator/index.js', SU_PLUGIN_FILE ), array( 'farbtastic', 'magnific-popup', 'simpleslider' ), SU_PLUGIN_VERSION, true );
wp_localize_script( 'su-generator', 'SUGL10n', array(
'upload_title' => __( 'Choose file', 'shortcodes-ultimate' ),
'upload_insert' => __( 'Insert', 'shortcodes-ultimate' ),
'isp_media_title' => __( 'Select images', 'shortcodes-ultimate' ),
'isp_media_insert' => __( 'Add selected images', 'shortcodes-ultimate' ),
'presets_prompt_msg' => __( 'Please enter a name for new preset', 'shortcodes-ultimate' ),
'presets_prompt_value' => __( 'New preset', 'shortcodes-ultimate' ),
'last_used' => __( 'Last used settings', 'shortcodes-ultimate' ),
) );
// Shortcodes stylesheets
wp_register_style( 'su-shortcodes', plugins_url( 'includes/css/shortcodes.css', SU_PLUGIN_FILE ), false, SU_PLUGIN_VERSION, 'all' );
// Plugin Icons (Fork Awesome)
wp_register_style( 'su-icons', plugins_url( 'includes/css/icons.css', SU_PLUGIN_FILE ), false, '1.1.5', 'all' );
// DEPRECATED - Shortcodes stylesheets
// wp_register_style( 'su-content-shortcodes', '', false, SU_PLUGIN_VERSION, 'all' );
// wp_register_style( 'su-box-shortcodes', '', false, SU_PLUGIN_VERSION, 'all' );
// wp_register_style( 'su-media-shortcodes', '', false, SU_PLUGIN_VERSION, 'all' );
// wp_register_style( 'su-other-shortcodes', '', false, SU_PLUGIN_VERSION, 'all' );
// wp_register_style( 'su-galleries-shortcodes', '', false, SU_PLUGIN_VERSION, 'all' );
// wp_register_style( 'su-players-shortcodes', '', false, SU_PLUGIN_VERSION, 'all' );
// RTL stylesheets
wp_register_style( 'su-rtl-shortcodes', plugins_url( 'includes/css/rtl-shortcodes.css', SU_PLUGIN_FILE ), false, SU_PLUGIN_VERSION, 'all' );
wp_register_style( 'su-rtl-admin', plugins_url( 'admin/css/rtl-admin.css', SU_PLUGIN_FILE ), false, SU_PLUGIN_VERSION, 'all' );
// Shortcodes scripts
wp_register_script(
'su-shortcodes',
plugins_url( 'includes/js/shortcodes/index.js', SU_PLUGIN_FILE ),
array( 'jquery' ),
SU_PLUGIN_VERSION,
true
);
wp_localize_script(
'su-shortcodes',
'SUShortcodesL10n',
array(
'noPreview' => __( 'This shortcode doesn\'t work in live preview. Please insert it into editor and preview on the site.', 'shortcodes-ultimate' ),
'magnificPopup' => array(
'close' => __( 'Close (Esc)', 'shortcodes-ultimate' ),
'loading' => __( 'Loading...', 'shortcodes-ultimate' ),
'prev' => __( 'Previous (Left arrow key)', 'shortcodes-ultimate' ),
'next' => __( 'Next (Right arrow key)', 'shortcodes-ultimate' ),
// translators: %1$s of %2$s represents image counter in lightbox, will be replaced with "1 of 5"
'counter' => sprintf( __( '%1$s of %2$s', 'shortcodes-ultimate' ), '%curr%', '%total%' ),
'error' => sprintf(
// translators: %1$s and %2$s will be replace <a> and </a> tags
__( 'Failed to load content. %1$sOpen link%2$s' ),
'<a href="%url%" target="_blank"><u>',
'</u></a>'
),
),
)
);
// Hook to deregister assets or add custom
do_action( 'su/assets/register' );
}
/**
* Enqueue assets
*/
public static function enqueue() {
// Get assets query and plugin object
$assets = self::assets();
// Enqueue stylesheets
foreach ( $assets['css'] as $style ) wp_enqueue_style( $style );
// Enqueue scripts
foreach ( $assets['js'] as $script ) wp_enqueue_script( $script );
// Hook to dequeue assets or add custom
do_action( 'su/assets/enqueue', $assets );
}
/**
* Print assets without enqueuing
*/
public static function prnt() {
// Prepare assets set
$assets = self::assets();
// Enqueue stylesheets
wp_print_styles( $assets['css'] );
// Enqueue scripts
wp_print_scripts( $assets['js'] );
// Hook
do_action( 'su/assets/print', $assets );
}
/**
* Print custom CSS
*/
public static function custom_css() {
// Get custom CSS and apply filters to it
$custom_css = (string) apply_filters( 'su/assets/custom_css', get_option( 'su_option_custom-css' ) );
$template = '%1$s<!-- %2$s - %3$s -->%1$s<style type="text/css">%1$s%5$s%1$s</style>%1$s<!-- %2$s - %4$s -->%1$s';
$template = apply_filters( 'su/assets/custom_css/template', $template );
if ( ! empty( $custom_css ) ) {
$custom_css = str_replace(
array( '%theme_url%', '%home_url%', '%plugin_url%' ),
array(
trailingslashit( get_stylesheet_directory_uri() ),
trailingslashit( get_option( 'home' ) ),
trailingslashit( plugins_url( '', SU_PLUGIN_FILE ) ),
),
$custom_css
);
printf(
$template,
PHP_EOL,
'Shortcodes Ultimate custom CSS',
'start',
'end',
strip_tags( $custom_css )
);
}
// Hook
do_action( 'su/assets/custom_css/after' );
}
/**
* RTL support for shortcodes
*/
public static function rtl_shortcodes( $assets ) {
// Check RTL
if ( !is_rtl() ) return;
// Add RTL stylesheets
wp_print_styles( array( 'su-rtl-shortcodes' ) );
}
/**
* RTL support for admin
*/
public static function rtl_admin( $assets ) {
// Check RTL
if ( !is_rtl() ) return;
// Add RTL stylesheets
self::add( 'css', 'su-rtl-admin' );
}
/**
* Add asset to the query
*/
public static function add( $type, $handle ) {
// Array with handles
if ( is_array( $handle ) ) { foreach ( $handle as $h ) self::$assets[$type][$h] = $h; }
// Single handle
else self::$assets[$type][$handle] = $handle;
}
/**
* Get queried assets
*/
public static function assets() {
// Get assets query
$assets = self::$assets;
// Apply filters to assets set
$assets['css'] = array_unique( ( array ) apply_filters( 'su/assets/css', ( array ) array_unique( $assets['css'] ) ) );
$assets['js'] = array_unique( ( array ) apply_filters( 'su/assets/js', ( array ) array_unique( $assets['js'] ) ) );
// Return set
return $assets;
}
/**
* Helper to get full URL of a skin file
*/
public static function skin_url( $file = '' ) {
$skin = get_option( 'su_option_skin' );
$uploads = wp_upload_dir(); $uploads = $uploads['baseurl'];
// Prepare url to skin directory
$url = ( !$skin || $skin === 'default' ) ? plugins_url( 'assets/css/', SU_PLUGIN_FILE ) : $uploads . '/shortcodes-ultimate-skins/' . $skin;
return trailingslashit( apply_filters( 'su/assets/skin', $url ) ) . $file;
}
}
new Su_Assets;
/**
* Helper function to add asset to the query
*
* @param string $type Asset type (css|js)
* @param mixed $handle Asset handle or array with handles
*/
function su_query_asset( $type, $handle ) {
Su_Assets::add( $type, $handle );
}
/**
* Helper function to get current skin url
*
* @param string $file Asset file name. Example value: box-shortcodes.css
*/
function su_skin_url( $file ) {
return Su_Assets::skin_url( $file );
}