first commit

This commit is contained in:
2024-07-15 11:28:08 +02:00
commit f52d538ea5
21891 changed files with 6161164 additions and 0 deletions

View File

@@ -0,0 +1,72 @@
<?php
/**
* Sets up the admin functionality for the plugin.
*
* @package Cherry_Framework
* @subpackage Modules
* @author Cherry Team <cherryframework@gmail.com>
* @copyright Copyright (c) 2012 - 2017, Cherry Team
* @link http://www.cherryframework.com/
* @license http://www.gnu.org/licenses/gpl-3.0.html
*/
// If class `Cherry5_Insertion_Button` doesn't exists yet.
if ( ! class_exists( 'Cherry5_Insertion_Button' ) ) {
/**
* Cherry5_Insertion_Button class.
*/
class Cherry5_Insertion_Button {
/**
* Module arguments
*
* @var array
*/
public $args = array();
/**
* Core instance
*
* @var object
*/
public $core = null;
/**
* Class constructor.
*
* @since 1.0.0
* @access public
* @return void
*/
public function __construct( $core = null, $args = array(), $parent_self = null ) {
$this->core = $core;
$this->args = $args;
$this->parent_self = $parent_self;
add_action( 'media_buttons', array( $this, 'add_button' ) );
add_action( 'cherry5-insert-shortcode', array( $this, 'add_button' ) );
}
/**
* Function add button into tinymce editor.
*
* @since 1.0.0
* @access public
* @return void
*/
public function add_button( $editor_id ) {
if ( 'content' !== $editor_id ) {
return;
}
echo '<button class="button cherry5-is__open-button" type="button"><span class="cherry5-is__icon dashicons dashicons-plus"></span>' . esc_html__( 'Cherry Shortcodes', 'cherry-framework' ) . '</button>';
if ( ! defined( 'DOING_AJAX' ) ) {
add_action( 'admin_print_footer_scripts', array( $this->parent_self->shortcodes_popup, 'render_popup' ), 99 );
}
}
}
}

View File

@@ -0,0 +1,306 @@
<?php
/**
* Sets up the admin functionality for the plugin.
*
* @package Cherry_Framework
* @subpackage Modules
* @author Cherry Team <cherryframework@gmail.com>
* @copyright Copyright (c) 2012 - 2017, Cherry Team
* @link http://www.cherryframework.com/
* @license http://www.gnu.org/licenses/gpl-3.0.html
*/
// If class `Cherry5_Insertion_Popup` doesn't exists yet.
if ( ! class_exists( 'Cherry5_Insertion_Popup' ) ) {
/**
* Cherry5_Insertion_Popup class.
*/
class Cherry5_Insertion_Popup {
/**
* A reference to an instance of parent class.
*
* @since 1.0.0
* @var object
* @access private
*/
private static $instance = null;
/**
* Module arguments
*
* @since 1.0.0
* @var array
* @access private
*/
private $args = array();
/**
* Core instance
*
* @since 1.0.0
* @var object
* @access private
*/
private $core = null;
/**
* Shortcode list.
*
* @since 1.0.0
* @var array
* @access private
*/
private $shortcode_list = array(
array(
'title' => '',
'description' => '',
'icon' => '',
'slug' => '',
'shortcodes' => array(
array(
'title' => '',
'description' => '',
'icon' => '',
'slug' => '',
'enclosing ' => false,
'options' => array(),
),
),
),
);
/**
* Class constructor.
*
* @since 1.0.0
* @access public
* @return void
*/
public function __construct( $core = null, $args = array(), $parent_self = null ) {
$this->core = $core;
$this->args = $args;
$this->parent_self = $parent_self;
$this->core->init_module(
'cherry-handler',
array(
'id' => 'cherry5_insert_shortcode',
'action' => 'cherry5_insert_shortcode',
'type' => 'GET',
'capability' => 'manage_options',
'callback' => array( $this , 'get_shortcode_options' ),
'sys_messages' => array(
'invalid_base_data' => '',
'no_right' => '',
'invalid_nonce' => '',
'access_is_allowed' => '',
),
)
);
}
/**
* Add popup into page.
*
* @since 1.0.0
* @access public
* @return void
*/
public function render_popup( $hook ) {
$screen = get_current_screen();
if ( in_array( $screen->base, $this->args['in_screen'] ) ) {
$this->shortcode_list = apply_filters( 'cherry5-is__shortcode_list', array() );
$popup_title = esc_html( 'Insert Cherry Shortcode', 'cherry' );
$sidebar_list = $this->get_sidebar_list( $this->shortcode_list );
$args = apply_filters( 'cherry5-is__insert-button', array(
'id' => '',
'name' => '',
'style' => 'primary',
'content' => esc_html__( 'insert shortcode', 'cherry-framework' ),
'class' => 'cherry5-is__insert-button',
) );
$insert_button = $this->parent_self->ui_elements->get_ui_element_instance( 'button', $args )->render();
require_once( apply_filters( 'cherry5-is__popup-template', $this->args['module_path'] . 'inc/views/insert-shortcode-pop-up.php' ) );
}
}
/**
* The function returns a HTML structure of registered shortcodes.
*
* @since 1.0.0
* @access private
* @return string
*/
private function get_sidebar_list( $plugins = array() ) {
$structure['shortcode-list'] = array(
'type' => 'component-accordion',
'title' => esc_html__( 'Shortcode List', 'cherry-framework' ),
);
$defaults = array(
'icon' => '',
'title' => '',
'description' => '',
);
$list_items_template = apply_filters( 'cherry5-is__list-items-template', '<li><button id="button-%1$s-%2$s" class="cherry5-is__get-shotcode" data-plugin-slug="%1$s" data-shortcode-slug="%2$s" title="%3$s">%4$s%5$s</button></li>' );
foreach ( $plugins as $plugin_slug => $plugin_value ) {
$plugin_value = wp_parse_args( $plugin_value, $defaults );
$structure[ $plugin_slug ] = array(
'id' => $plugin_slug,
'type' => 'settings',
'parent' => 'shortcode-list',
'title' => $plugin_value['icon'] . $plugin_value['title'],
'description' => $plugin_value['description'],
);
$output_html = '<ul class="cherry5-is__shortcode-list">';
foreach ( $plugin_value['shortcodes'] as $shortcode_slug => $shortcode_value ) {
$shortcode_value = wp_parse_args( $shortcode_value, $defaults );
$output_html .= sprintf( $list_items_template, $plugin_slug, $shortcode_slug, $shortcode_value['description'], $shortcode_value['icon'], $shortcode_value['title'] );
}
$output_html .= '</ul>';
$structure[ $plugin_slug . '-shortcodes' ] = array(
'id' => $plugin_slug . '-shortcodes',
'type' => 'html',
'parent' => $plugin_slug,
'html' => $output_html,
);
}
return $this->parent_self->cherry_interface_builder->render( false, $structure );
}
/**
* The function returns option was shortcode.
*
* @since 1.0.0
* @access public
* @return array
*/
public function get_shortcode_options() {
$shortcode_list = apply_filters( 'cherry5-is__shortcode_list', array() );
$plugin_slug = ( ! empty( $_GET['data']['plugin_slug'] ) )? $_GET['data']['plugin_slug'] : '' ;
$shortcode_slug = ( ! empty( $_GET['data']['shortcode_slug'] ) )? $_GET['data']['shortcode_slug'] : '' ;
$shortcode_attr = isset( $shortcode_list[ $plugin_slug ]['shortcodes'][ $shortcode_slug ] ) ? $shortcode_list[ $plugin_slug ]['shortcodes'][ $shortcode_slug ] : false;
if ( ! $shortcode_attr ) {
return array(
'error' => true,
'message' => esc_html__( 'Shortcode not found.', 'cherry-framework' ),
);
} else {
$defaults = array(
'content_area' => '',
'enclosing' => false,
'title' => '',
'description' => '',
'defaultContent' => '',
'options' => false,
);
$shortcode_attr = wp_parse_args( $shortcode_attr, $defaults );
if ( $shortcode_attr['enclosing'] ) {
$shortcode_attr['content_area'] = $this->get_shortcode_content_editor( $default_content, $plugin_slug, $shortcode_slug );
}
if ( ! empty( $shortcode_attr['options'] ) ) {
foreach ( $shortcode_attr['options'] as $key => $settings ) {
if ( ! array_key_exists( 'id', $settings ) ) {
$shortcode_attr['options'][ $key ]['id'] = $shortcode_slug . '_' . $key;
}
if ( isset( $settings['options'] ) ) {
$shortcode_attr['options'][ $key ]['options'] = $this->apply_options_cb( $settings );
}
}
$shortcode_options_html = $this->parent_self->cherry_interface_builder->render( false, $shortcode_attr['options'] );
} else {
$shortcode_options_html = $this->get_empty_layer();
}
$shortcode_option_template = apply_filters( 'cherry5-is__options-template', Cherry_Toolkit::get_file( $this->args['module_path'] . 'inc/views/shortcode-options.php' ) );
$output_html = sprintf( $shortcode_option_template, $plugin_slug, $shortcode_slug, $shortcode_attr['title'], $shortcode_attr['description'], $shortcode_attr['content_area'], $shortcode_options_html );
return array(
'error' => false,
'pluginSlug' => $plugin_slug,
'shortcodeSlug' => $shortcode_slug,
'enclosing' => $shortcode_attr['enclosing'],
'defaultContent' => $shortcode_attr['defaultContent'],
'html' => $output_html,
);
}
}
/**
* Apply shortcode options callback if required.
*
* @since 1.0.2
* @param array $atts Shortcode field parameters.
* @return array
*/
private function apply_options_cb( $atts ) {
if ( ! empty( $atts['options'] ) ) {
return $atts['options'];
}
if ( empty( $atts['options_cb'] ) || ! is_callable( $atts['options_cb'] ) ) {
return array();
}
return call_user_func( $atts['options_cb'] );
}
/**
* The function returns content area HTML.
*
* @since 1.0.0
* @access private
* @return string
*/
private function get_shortcode_content_editor( $content = '', $plugin_slug = '', $shortcode_slug = '' ) {
$template = apply_filters( 'cherry5-is__content-area-template', Cherry_Toolkit::get_file( $this->args['module_path'] . 'inc/views/shortcode-content-area.php' ) );
$title = apply_filters( 'cherry5-is__content-title', esc_html__( 'Shortcode content.', 'cherry-framework' ) );
$placeholder = apply_filters( 'cherry5-is__content-placeholder', esc_html__( 'Input shortcode content.', 'cherry-framework' ) );
$output = sprintf( $template, $plugin_slug, $shortcode_slug, $title, $placeholder, $content );
return $output;
}
/**
* The function returns empty layer HTML.
*
* @since 1.0.0
* @access private
* @return string
*/
private function get_empty_layer() {
$text = apply_filters( 'cherry5-is__empty_layer-text', esc_html__( 'Shortcode not a have options.', 'cherry-framework' ) );
$template = apply_filters( 'cherry5-is__empty_layer-template', Cherry_Toolkit::get_file( $this->args['module_path'] . 'inc/views/shortcode-has-not-option.php' ) );
$output = sprintf( $template, $text );
return $output;
}
}
}

View File

@@ -0,0 +1,49 @@
<?php
/**
* Popup view.
*
* @package cherry5_insert_shortcode
* @subpackage Views
* @author Cherry Team <cherryframework@gmail.com>
* @copyright Copyright (c) 2012 - 2017, Cherry Team
* @link http://www.cherryframework.com/
* @license http://www.gnu.org/licenses/gpl-3.0.html
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
?>
<div class="cherry5-is cherry5-is__modal-window cherry-ui-kit">
<div class="cherry5-is__popup">
<div class="cherry5-is__popup-header">
<div class="cherry5-is__popup-header-inner">
<h3 class="cherry5-is__popup-title"><?php echo $popup_title ?></h3>
<div class="cherry5-is__close-button">
<span class="dashicons dashicons-no"></span>
</div>
</div>
</div>
<div class="cherry5-is__popup-body">
<div class="cherry5-is__popup-sidebar">
<div class="cherry5-is__sidebar-list cherry-scroll">
<?php echo $sidebar_list ?>
</div>
<div class="cherry5-is__sidebar-button">
<span class="dashicons dashicons-arrow-left-alt2 close"></span>
<span class="dashicons dashicons-arrow-right-alt2 open"></span>
</div>
</div>
<div class="cherry5-is__popup-section">
<div class="cherry5-is__shortcodes-options cherry-scroll">
<span class="cherry-loader-wrapper"><span class="cherry-loader"></span></span>
</div>
<div class="cherry5-is__popup-footer">
<?php echo $insert_button ?>
</div>
</div>
</div>
</div>
<div class="cherry5-is__background"></div>
</div>

View File

@@ -0,0 +1,23 @@
<?php
/**
* Shortcode options view.
*
* @package cherry5_insert_shortcode
* @subpackage Views
* @author Cherry Team <cherryframework@gmail.com>
* @copyright Copyright (c) 2012 - 2017, Cherry Team
* @link http://www.cherryframework.com/
* @license http://www.gnu.org/licenses/gpl-3.0.html
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
?>
<div class="cherry5-is__content-area">
<header class="cherry5-is__content-area-header">
<h3 class="cherry5-is__content-area-title" role="banner">%3$s</h3>
</header>
<textarea id="%1$s-%2$s-content" name="cherry5-is__shortcode-content" class="cherry5-is__shortcode-content cherry-ui-textarea" rows="10" cols="20" placeholder="%4$s">%5$s</textarea>
</div>

View File

@@ -0,0 +1,22 @@
<?php
/**
* Shortcode has not option view.
*
* @package cherry5_insert_shortcode
* @subpackage Views
* @author Cherry Team <cherryframework@gmail.com>
* @copyright Copyright (c) 2012 - 2017, Cherry Team
* @link http://www.cherryframework.com/
* @license http://www.gnu.org/licenses/gpl-3.0.html
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
?>
<div class="cherry5-is__has-not-option">
<span class="cherry5-is__has-not-option-text">
%1$s
<span>
</div>

View File

@@ -0,0 +1,25 @@
<?php
/**
* Shortcode options view.
*
* @package cherry5_insert_shortcode
* @subpackage Views
* @author Cherry Team <cherryframework@gmail.com>
* @copyright Copyright (c) 2012 - 2017, Cherry Team
* @link http://www.cherryframework.com/
* @license http://www.gnu.org/licenses/gpl-3.0.html
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
?>
<form id="%1$s-%2$s" name="%1$s-%2$s" class="cherry5-is__shortcode-form show" >
<header class="cherry5-is__shortcode-form-header">
<h2 class="cherry5-is__shortcode-title" role="banner">%3$s</h2>
<div class="cherry5-is__shortcode-description" role="note">%4$s</div>
</header>
%5$s
%6$s
<form>