Import legacy nurinda.co.id website

This commit is contained in:
dirga committed 2026-10-01 14:27:19 +07:00
1 parent 3f59bb9038
commit 6e21646ac4
13389 files changed
+3246690

No files matched your search

@@ -0,0 +1,300 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
/**
* WPBakery WPBakery Page Builder admin editor
*
* @package WPBakeryPageBuilder
*
*/
/**
* VC backend editor.
*
* This editor is available on default Wp post/page admin edit page. ON admin_init callback adds meta box to
* edit page.
*
* @since 4.2
*/
class Vc_Backend_Editor implements Vc_Editor_Interface {
/**
* @var
*/
protected $layout;
/**
* @var
*/
public $post_custom_css;
/**
* @var bool|string $post - stores data about post.
*/
public $post = false;
/**
* This method is called by Vc_Manager to register required action hooks for VC backend editor.
*
* @since 4.2
* @access public
*/
public function addHooksSettings() {
// @todo - fix_roles do this only if be editor is enabled.
// load backend editor
if ( function_exists( 'add_theme_support' ) ) {
add_theme_support( 'post-thumbnails' ); // @todo check is it needed?
}
add_action( 'add_meta_boxes', array(
$this,
'render',
), 5 );
add_action( 'admin_print_scripts-post.php', array(
$this,
'registerScripts',
) );
add_action( 'admin_print_scripts-post-new.php', array(
$this,
'registerScripts',
) );
add_action( 'admin_print_scripts-post.php', array(
$this,
'printScriptsMessages',
) );
add_action( 'admin_print_scripts-post-new.php', array(
$this,
'printScriptsMessages',
) );
}
public function registerScripts() {
$this->registerBackendJavascript();
$this->registerBackendCss();
// B.C:
visual_composer()->registerAdminCss();
visual_composer()->registerAdminJavascript();
}
/**
* Calls add_meta_box to create Editor block. Block is rendered by WPBakeryVisualComposerLayout.
*
* @see WPBakeryVisualComposerLayout
* @since 4.2
* @access public
*
* @param $post_type
*/
public function render( $post_type ) {
if ( $this->isValidPostType( $post_type ) ) {
// meta box to render
add_meta_box( 'wpb_visual_composer', __( 'WPBakery Page Builder', 'js_composer' ), array(
$this,
'renderEditor',
), $post_type, 'normal', 'high' );
}
}
/**
* Output html for backend editor meta box.
*
* @param null|Wp_Post $post
*
* @return bool
*/
public function renderEditor( $post = null ) {
/**
* TODO: setter/getter for $post
*/
if ( ! is_object( $post ) || 'WP_Post' !== get_class( $post ) || ! isset( $post->ID ) ) {
return false;
}
$this->post = $post;
$post_custom_css = strip_tags( get_post_meta( $post->ID, '_wpb_post_custom_css', true ) );
$this->post_custom_css = $post_custom_css;
vc_include_template( 'editors/backend_editor.tpl.php', array(
'editor' => $this,
'post' => $this->post,
) );
add_action( 'admin_footer', array(
$this,
'renderEditorFooter',
) );
do_action( 'vc_backend_editor_render' );
return true;
}
/**
* Output required html and js content for VC editor.
*
* Here comes panels, modals and js objects with data for mapped shortcodes.
*/
public function renderEditorFooter() {
vc_include_template( 'editors/partials/backend_editor_footer.tpl.php', array(
'editor' => $this,
'post' => $this->post,
) );
do_action( 'vc_backend_editor_footer_render' );
}
/**
* Check is post type is valid for rendering VC backend editor.
*
* @param string $type
*
* @return bool
*/
public function isValidPostType( $type = '' ) {
$type = ! empty( $type ) ? $type : get_post_type();
if ( 'vc_grid_item' === $type ) {
return false;
}
return apply_filters( 'vc_is_valid_post_type_be', vc_check_post_type( $type ), $type );
}
/**
* Enqueue required javascript libraries and css files.
*
* This method also setups reminder about license activation.
*
* @since 4.2
* @access public
*/
public function printScriptsMessages() {
if ( ! vc_is_frontend_editor() && $this->isValidPostType( get_post_type() ) ) {
$this->enqueueEditorScripts();
}
}
/**
* Enqueue required javascript libraries and css files.
*
* @since 4.8
* @access public
*/
public function enqueueEditorScripts() {
if ( $this->editorEnabled() ) {
$this->enqueueJs();
$this->enqueueCss();
WPBakeryShortCodeFishBones::enqueueCss();
WPBakeryShortCodeFishBones::enqueueJs();
} else {
wp_enqueue_script( 'vc-backend-actions-js' );
$this->enqueueCss(); //needed for navbar @todo split
}
do_action( 'vc_backend_editor_enqueue_js_css' );
}
public function registerBackendJavascript() {
// editor can be disabled but fe can be enabled. so we currently need this file. @todo maybe make backend-disabled.min.js
wp_register_script( 'vc-backend-actions-js', vc_asset_url( 'js/dist/backend-actions.min.js' ), array(
'jquery',
'backbone',
'underscore',
), WPB_VC_VERSION, true );
wp_register_script( 'vc-backend-min-js', vc_asset_url( 'js/dist/backend.min.js' ), array( 'vc-backend-actions-js' ), WPB_VC_VERSION, true );
// used in tta shortcodes, and panels.
wp_register_script( 'vc_accordion_script', vc_asset_url( 'lib/vc_accordion/vc-accordion.min.js' ), array( 'jquery' ), WPB_VC_VERSION, true );
wp_register_script( 'wpb_php_js', vc_asset_url( 'lib/php.default/php.default.min.js' ), array( 'jquery' ), WPB_VC_VERSION, true );
// used as polyfill for JSON.stringify and etc
wp_register_script( 'wpb_json-js', vc_asset_url( 'lib/bower/json-js/json2.min.js' ), array(), WPB_VC_VERSION, true );
// used in post settings editor
wp_register_script( 'ace-editor', vc_asset_url( 'lib/bower/ace-builds/src-min-noconflict/ace.js' ), array( 'jquery' ), WPB_VC_VERSION, true );
wp_register_script( 'webfont', 'https://ajax.googleapis.com/ajax/libs/webfont/1.6.26/webfont.js' ); // Google Web Font CDN
wp_localize_script( 'vc-backend-actions-js', 'i18nLocale', visual_composer()->getEditorsLocale() );
}
public function registerBackendCss() {
wp_register_style( 'js_composer', vc_asset_url( 'css/js_composer_backend_editor.min.css' ), array(), WPB_VC_VERSION, false );
if ( $this->editorEnabled() ) {
/**
* @deprecated, used for accordions/tabs/tours
*/
wp_register_style( 'ui-custom-theme', vc_asset_url( 'css/ui-custom-theme/jquery-ui-less.custom.min.css' ), array(), WPB_VC_VERSION );
/**
* @todo check vc_add-element-deprecated-warning for fa icon usage ( set to our font )
* also used in vc_icon shortcode
*/
wp_register_style( 'font-awesome', vc_asset_url( 'lib/bower/font-awesome/css/font-awesome.min.css' ), array(), WPB_VC_VERSION );
/**
* @todo check for usages
* definetelly used in edit form param: css_animation, but curreny vc_add_shortcode_param doesn't accept css [ @todo refactor that ]
*/
wp_register_style( 'animate-css', vc_asset_url( 'lib/bower/animate-css/animate.min.css' ), array(), WPB_VC_VERSION );
}
}
public function enqueueJs() {
$wp_dependencies = array(
'jquery',
'underscore',
'backbone',
'media-views',
'media-editor',
'wp-pointer',
'mce-view',
'wp-color-picker',
'jquery-ui-sortable',
'jquery-ui-droppable',
'jquery-ui-draggable',
'jquery-ui-autocomplete',
'jquery-ui-resizable',
// used in @deprecated tabs
'jquery-ui-tabs',
'jquery-ui-accordion',
);
$dependencies = array(
'vc_accordion_script',
'wpb_php_js',
// used in our files [e.g. edit form saving sprintf]
'wpb_json-js',
'ace-editor',
'webfont',
'vc-backend-min-js',
);
// This workaround will allow to disable any of dependency on-the-fly
foreach ( $wp_dependencies as $dependency ) {
wp_enqueue_script( $dependency );
}
foreach ( $dependencies as $dependency ) {
wp_enqueue_script( $dependency );
}
}
public function enqueueCss() {
$wp_dependencies = array(
'wp-color-picker',
'farbtastic',
// deprecated for tabs/accordion
'ui-custom-theme',
// used in deprecated message and also in vc-icon shortcode
'font-awesome',
// used in css_animation edit form param
'animate-css',
);
$dependencies = array(
'js_composer',
);
// This workaround will allow to disable any of dependency on-the-fly
foreach ( $wp_dependencies as $dependency ) {
wp_enqueue_style( $dependency );
}
foreach ( $dependencies as $dependency ) {
wp_enqueue_style( $dependency );
}
}
/**
* @return bool
*/
public function editorEnabled() {
return vc_user_access()->part( 'backend_editor' )->can()->get();
}
}
@@ -0,0 +1,309 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
/**
* WPBakery WPBakery Page Builder shortcode attributes fields
*
* @package WPBakeryPageBuilder
*
*/
/**
* Edit form fields builder for shortcode attributes.
*
* @since 4.4
*/
class Vc_Edit_Form_Fields implements Vc_Render {
/**
* @since 4.4
* @var bool
*/
protected $tag = false;
/**
* @since 4.4
* @var array
*/
protected $atts = array();
/**
* @since 4.4
* @var array
*/
protected $settings = array();
/**
* @since 4.4
* @var bool
*/
protected $post_id = false;
/**
* Construct Form fields.
*
* @since 4.4
*
* @param $tag - shortcode tag
* @param $atts - list of attribute assign to the shortcode.
*/
public function __construct( $tag, $atts ) {
$this->tag = $tag;
$this->atts = apply_filters( 'vc_edit_form_fields_attributes_' . $this->tag, $atts );
$this->setSettings( WPBMap::getShortCode( $this->tag ) );
}
/**
* Get settings
* @since 4.4
*
* @param $key
*
* @return null
*/
public function setting( $key ) {
return isset( $this->settings[ $key ] ) ? $this->settings[ $key ] : null;
}
/**
* Set settings data
* @since 4.4
*
* @param array $settings
*/
public function setSettings( array $settings ) {
$this->settings = $settings;
}
/**
* Shortcode Post ID getter.
* If post id isn't set try to get from get_the_ID function.
* @since 4.4
* @return int|bool;
*/
public function postId() {
if ( false === $this->post_id ) {
$this->post_id = get_the_ID();
}
return $this->post_id;
}
/**
* Shortcode Post ID setter.
* @since 4.4
*
* @param $post_id - integer value in post_id
*/
public function setPostId( $post_id ) {
$this->post_id = (int) $post_id;
}
/**
* Get shortcode attribute value.
*
* This function checks if value isn't set then it uses std or value fields in param settings.
* @since 4.4
*
* @param $param_settings
* @param $value
*
* @return null
*/
protected function parseShortcodeAttributeValue( $param_settings, $value ) {
if ( is_null( $value ) ) { // If value doesn't exists
if ( isset( $param_settings['std'] ) ) {
$value = $param_settings['std'];
} elseif ( isset( $param_settings['value'] ) && is_array( $param_settings['value'] ) && ! empty( $param_settings['type'] ) && 'checkbox' !== $param_settings['type'] ) {
$first_key = key( $param_settings['value'] );
$value = $first_key ? $param_settings['value'][ $first_key ] : '';
} elseif ( isset( $param_settings['value'] ) && ! is_array( $param_settings['value'] ) ) {
$value = $param_settings['value'];
}
}
return $value;
}
/**
* Enqueue js scripts for attributes types.
* @since 4.4
* @return string
*/
public function enqueueScripts() {
$output = '';
if ( ! WpbakeryShortcodeParams::isEnqueue() ) {
$scripts = apply_filters( 'vc_edit_form_enqueue_script', WpbakeryShortcodeParams::getScripts() );
foreach ( $scripts as $script ) {
$output .= "\n\n" . '<script type="text/javascript" src="' . $script . '"></script>';
}
}
return $output;
}
/**
* Render grouped fields.
* @since 4.4
*
* @param $groups
* @param $groups_content
*
* @return string
*/
protected function renderGroupedFields( $groups, $groups_content ) {
$output = '';
if ( sizeof( $groups ) > 1 || ( sizeof( $groups ) >= 1 && empty( $groups_content['_general'] ) ) ) {
$output .= '<div class="vc_panel-tabs" id="vc_edit-form-tabs">';
$output .= '<ul class="vc_general vc_ui-tabs-line" data-vc-ui-element="panel-tabs-controls">';
$key = 0;
foreach ( $groups as $g ) {
$output .= '<li class="vc_edit-form-tab-control" data-tab-index="' . $key . '"><button data-vc-ui-element-target="#vc_edit-form-tab-' . $key ++ . '" class="vc_ui-tabs-line-trigger" data-vc-ui-element="panel-tab-control">' . ( '_general' === $g ? __( 'General', 'js_composer' ) : $g ) . '</button></li>';
}
$output .= '<li class="vc_ui-tabs-line-dropdown-toggle" data-vc-action="dropdown"
data-vc-content=".vc_ui-tabs-line-dropdown" data-vc-ui-element="panel-tabs-line-toggle">
<span class="vc_ui-tabs-line-trigger" data-vc-accordion
data-vc-container=".vc_ui-tabs-line-dropdown-toggle"
data-vc-target=".vc_ui-tabs-line-dropdown"> </span>
<ul class="vc_ui-tabs-line-dropdown" data-vc-ui-element="panel-tabs-line-dropdown">
</ul>
</ul>';
$key = 0;
foreach ( $groups as $g ) {
$output .= '<div id="vc_edit-form-tab-' . $key ++ . '" class="vc_edit-form-tab vc_row vc_ui-flex-row" data-vc-ui-element="panel-edit-element-tab">';
$output .= $groups_content[ $g ];
$output .= '</div>';
}
$output .= '</div>';
} elseif ( ! empty( $groups_content['_general'] ) ) {
$output .= '<div class="vc_edit-form-tab vc_row vc_ui-flex-row vc_active" data-vc-ui-element="panel-edit-element-tab">' . $groups_content['_general'] . '</div>';
}
return $output;
}
/**
* Render fields html and output it.
* @since 4.4
* vc_filter: vc_edit_form_class - filter to override editor_css_classes array
*/
public function render() {
$this->loadDefaultParams();
$output = $el_position = '';
$groups_content = $groups = array();
$params = $this->setting( 'params' );
$editor_css_classes = apply_filters( 'vc_edit_form_class', array(
'wpb_edit_form_elements',
'vc_edit_form_elements',
), $this->atts, $params );
$deprecated = $this->setting( 'deprecated' );
require_once vc_path_dir( 'AUTOLOAD_DIR', 'class-vc-settings-presets.php' );
$list_vendor_presets = Vc_Settings_Preset::listVendorSettingsPresets( $this->tag );
$list_presets = Vc_Settings_Preset::listSettingsPresets( $this->tag );
$show_settings = false;
$saveAsTemplateElements = apply_filters( 'vc_popup_save_as_template_elements', array(
'vc_row',
'vc_section',
) );
$show_presets = ! in_array( $this->tag, $saveAsTemplateElements ) && vc_user_access()->part( 'presets' )->checkStateAny( true, null )->get();
if ( in_array( $this->tag, $saveAsTemplateElements ) && vc_user_access()->part( 'templates' )->checkStateAny( true, null )->get() ) {
$show_settings = true;
}
$output .= sprintf( '<script type="text/javascript">window.vc_presets_show=%s;</script>', $show_presets ? 'true' : 'false' );
$output .= sprintf( '<script type="text/javascript">window.vc_settings_show=%s;</script>', $show_presets || $show_settings ? 'true' : 'false' );
if ( ! empty( $deprecated ) ) {
$output .= '<div class="vc_row vc_ui-flex-row vc_shortcode-edit-form-deprecated-message"><div class="vc_col-sm-12 wpb_element_wrapper">' . vc_message_warning( sprintf( __( 'You are using outdated element, it is deprecated since version %s.', 'js_composer' ), $this->setting( 'deprecated' ) ) ) . '</div></div>';
}
$output .= '<div class="' . implode( ' ', $editor_css_classes ) . '" data-title="' . htmlspecialchars( __( 'Edit', 'js_composer' ) . ' ' . __( $this->setting( 'name' ), 'js_composer' ) ) . '">';
if ( is_array( $params ) ) {
foreach ( $params as $param ) {
$name = isset( $param['param_name'] ) ? $param['param_name'] : null;
if ( ! is_null( $name ) ) {
$value = isset( $this->atts[ $name ] ) ? $this->atts[ $name ] : null;
$value = $this->parseShortcodeAttributeValue( $param, $value );
$group = isset( $param['group'] ) && '' !== $param['group'] ? $param['group'] : '_general';
if ( ! isset( $groups_content[ $group ] ) ) {
$groups[] = $group;
$groups_content[ $group ] = '';
}
$groups_content[ $group ] .= $this->renderField( $param, $value );
}
}
}
$output .= $this->renderGroupedFields( $groups, $groups_content );
$output .= '</div>';
$output .= $this->enqueueScripts();
echo $output;
do_action( 'vc_edit_form_fields_after_render' );
}
/**
* Generate html for shortcode attribute.
*
* Method
* @since 4.4
*
* @param $param
* @param $value
*
* vc_filter: vc_single_param_edit - hook to edit any shortode param
* vc_filter: vc_form_fields_render_field_{shortcode_name}_{param_name}_param_value - hook to edit shortcode param
* value vc_filter: vc_form_fields_render_field_{shortcode_name}_{param_name}_param - hook to edit shortcode
* param attributes vc_filter: vc_single_param_edit_holder_output - hook to edit output of this method
*
* @return mixed|void
*/
protected function renderField( $param, $value ) {
$param['vc_single_param_edit_holder_class'] = array(
'wpb_el_type_' . $param['type'],
'vc_wrapper-param-type-' . $param['type'],
'vc_shortcode-param',
'vc_column',
);
if ( ! empty( $param['param_holder_class'] ) ) {
$param['vc_single_param_edit_holder_class'][] = $param['param_holder_class'];
}
$param = apply_filters( 'vc_single_param_edit', $param, $value );
$output = '<div class="' . implode( ' ', $param['vc_single_param_edit_holder_class'] ) . '" data-vc-ui-element="panel-shortcode-param" data-vc-shortcode-param-name="' . esc_attr( $param['param_name'] ) . '" data-param_type="' . esc_attr( $param['type'] ) . '" data-param_settings="' . esc_attr( json_encode( $param ) ) . '">';
$output .= ( isset( $param['heading'] ) ) ? '<div class="wpb_element_label">' . $param['heading'] . '</div>' : '';
$output .= '<div class="edit_form_line">';
$value = apply_filters( 'vc_form_fields_render_field_' . $this->setting( 'base' ) . '_' . $param['param_name'] . '_param_value', $value, $param, $this->settings, $this->atts );
$param = apply_filters( 'vc_form_fields_render_field_' . $this->setting( 'base' ) . '_' . $param['param_name'] . '_param', $param, $value, $this->settings, $this->atts );
$output = apply_filters( 'vc_edit_form_fields_render_field_' . $param['type'] . '_before', $output );
$output .= vc_do_shortcode_param_settings_field( $param['type'], $param, $value, $this->setting( 'base' ) );
$output_after = '';
if ( isset( $param['description'] ) ) {
$output_after .= '<span class="vc_description vc_clearfix">' . $param['description'] . '</span>';
}
$output_after .= '</div></div>';
$output .= apply_filters( 'vc_edit_form_fields_render_field_' . $param['type'] . '_after', $output_after );
return apply_filters( 'vc_single_param_edit_holder_output', $output, $param, $value, $this->settings, $this->atts );
}
/**
* Create default shortcode params
*
* List of params stored in global variable $vc_params_list.
* Please check include/params/load.php for default params list.
* @since 4.4
* @return bool
*/
public function loadDefaultParams() {
global $vc_params_list;
if ( empty( $vc_params_list ) ) {
return false;
}
$script_url = vc_asset_url( 'js/dist/edit-form.min.js' );
foreach ( $vc_params_list as $param ) {
vc_add_shortcode_param( $param, 'vc_' . $param . '_form_field', $script_url );
}
do_action( 'vc_load_default_params' );
return true;
}
}
@@ -0,0 +1,953 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
/**
* WPBakery WPBakery Page Builder front end editor
*
* @package WPBakeryPageBuilder
*
*/
/**
* Vc front end editor.
*
* Introduce principles ‘What You See Is What You Get’ into your page building process with our amazing frontend editor.
* See how your content will look on the frontend instantly with no additional clicks or switches.
*
* @since 4.0
*/
class Vc_Frontend_Editor implements Vc_Editor_Interface {
/**
* @var
*/
protected $dir;
/**
* @var int
*/
protected $tag_index = 1;
/**
* @var array
*/
public $post_shortcodes = array();
/**
* @var string
*/
protected $template_content = '';
/**
* @var bool
*/
protected static $enabled_inline = true;
/**
* @var
*/
public $current_user;
/**
* @var
*/
public $post;
/**
* @var
*/
public $post_id;
/**
* @var
*/
public $post_url;
/**
* @var
*/
public $url;
/**
* @var
*/
public $post_type;
/**
* @var array
*/#vc_ui-panel-edit-element
protected $settings = array(
'assets_dir' => 'assets',
'templates_dir' => 'templates',
'template_extension' => 'tpl.php',
'plugin_path' => 'js_composer/inline',
);
/**
* @var string
*/
protected static $content_editor_id = 'content';
/**
* @var array
*/
protected static $content_editor_settings = array(
'dfw' => true,
'tabfocus_elements' => 'insert-media-button',
'editor_height' => 360,
);
/**
* @var string
*/
protected static $brand_url = 'http://wpbakery.com/?utm_campaign=VCplugin&utm_source=vc_user&utm_medium=frontend_editor';
/**
*
*/
public function init() {
$this->addHooks();
/**
* If current mode of VC is frontend editor load it.
*/
if ( vc_is_frontend_editor() ) {
$this->hookLoadEdit();
} elseif ( vc_is_page_editable() ) {
/**
* if page loaded inside frontend editor iframe it has page_editable mode.
* It required to some some js/css elements and add few helpers for editor to be used.
*/
$this->buildEditablePage();
} else {
// Is it is simple page just enable buttons and controls
$this->buildPage();
}
}
/**
*
*/
public function addHooks() {
add_action( 'template_redirect', array(
$this,
'loadShortcodes',
) );
add_filter( 'page_row_actions', array(
$this,
'renderRowAction',
) );
add_filter( 'post_row_actions', array(
$this,
'renderRowAction',
) );
add_shortcode( 'vc_container_anchor', 'vc_container_anchor' );
}
/**
*
*/
public function hookLoadEdit() {
add_action( 'current_screen', array(
$this,
'adminInit',
) );
do_action( 'vc_frontend_editor_hook_load_edit' );
}
/**
*
*/
public function adminInit() {
$this->setPost();
$this->renderEditor();
}
/**
*
*/
public function buildEditablePage() {
if ( isset( $_REQUEST['action'] ) && 'vc_load_shortcode' === $_REQUEST['action'] ) {
return;
}
! defined( 'CONCATENATE_SCRIPTS' ) && define( 'CONCATENATE_SCRIPTS', false );
visual_composer()->shared_templates->init();
add_filter( 'the_title', array(
$this,
'setEmptyTitlePlaceholder',
) );
add_action( 'the_post', array(
$this,
'parseEditableContent',
), 9999 ); // after all the_post actions ended
do_action( 'vc_inline_editor_page_view' );
add_filter( 'wp_enqueue_scripts', array(
$this,
'loadIFrameJsCss',
) );
add_action( 'wp_footer', array(
$this,
'printPostShortcodes',
) );
}
/**
*
*/
public function buildPage() {
add_action( 'admin_bar_menu', array(
$this,
'adminBarEditLink',
), 1000 );
add_filter( 'edit_post_link', array(
$this,
'renderEditButton',
) );
}
/**
* @return bool
*/
public static function inlineEnabled() {
return true === self::$enabled_inline;
}
public static function frontendEditorEnabled() {
return self::inlineEnabled() && vc_user_access()->part( 'frontend_editor' )->can()->get();
}
/**
* @param bool $disable
*/
public static function disableInline( $disable = true ) {
self::$enabled_inline = ! $disable;
}
/**
* Main purpose of this function is to
* 1) Parse post content to get ALL shortcodes in to array
* 2) Wrap all shortcodes into editable-wrapper
* 3) Return "iframe" editable content in extra-script wrapper
*
* @param Wp_Post $post
*/
public function parseEditableContent( $post ) {
if ( ! vc_is_page_editable() || vc_action() || vc_post_param( 'action' ) ) {
return;
}
$post_id = (int) vc_get_param( 'vc_post_id' );
if ( $post_id > 0 && $post->ID === $post_id && ! defined( 'VC_LOADING_EDITABLE_CONTENT' ) ) {
define( 'VC_LOADING_EDITABLE_CONTENT', true );
remove_filter( 'the_content', 'wpautop' );
do_action( 'vc_load_shortcode' );
ob_start();
$this->getPageShortcodesByContent( $post->post_content );
vc_include_template( 'editors/partials/vc_welcome_block.tpl.php' );
$post_content = ob_get_clean();
ob_start();
vc_include_template( 'editors/partials/post_shortcodes.tpl.php', array( 'editor' => $this ) );
$post_shortcodes = ob_get_clean();
$GLOBALS['vc_post_content'] = '<script type="template/html" id="vc_template-post-content" style="display:none">' . rawurlencode( apply_filters( 'the_content', $post_content ) ) . '</script>' . $post_shortcodes;
// We already used the_content filter, we need to remove it to avoid double-using
remove_all_filters( 'the_content' );
// Used for just returning $post->post_content
add_filter( 'the_content', array(
$this,
'editableContent',
) );
}
}
/**
* @since 4.4
* Used to print rendered post content, wrapped with frontend editors "div" and etc.
*/
public function printPostShortcodes() {
echo isset( $GLOBALS['vc_post_content'] ) ? $GLOBALS['vc_post_content'] : '';
}
/**
* @param $content
*
* @return string
*/
public function editableContent( $content ) {
// same addContentAnchor
do_shortcode( $content ); // this will not be outputted, but this is needed to enqueue needed js/styles.
return '<span id="vc_inline-anchor" style="display:none !important;"></span>';
}
/**
* @param string $url
* @param string $id
*
* vc_filter: vc_get_inline_url - filter to edit frontend editor url (can be used for example in vendors like
* qtranslate do)
*
* @return mixed|void
*/
public static function getInlineUrl( $url = '', $id = '' ) {
$the_ID = ( strlen( $id ) > 0 ? $id : get_the_ID() );
return apply_filters( 'vc_get_inline_url', admin_url() . 'post.php?vc_action=vc_inline&post_id=' . $the_ID . '&post_type=' . get_post_type( $the_ID ) . ( strlen( $url ) > 0 ? '&url=' . rawurlencode( $url ) : '' ) );
}
/**
* @return string
*/
function wrapperStart() {
return '';
}
/**
* @return string
*/
function wrapperEnd() {
return '';
}
/**
* @param $url
*/
public static function setBrandUrl( $url ) {
self::$brand_url = $url;
}
/**
* @return string
*/
public static function getBrandUrl() {
return self::$brand_url;
}
/**
* @return string
*/
public static function shortcodesRegexp() {
$tagnames = array_keys( WPBMap::getShortCodes() );
$tagregexp = implode( '|', array_map( 'preg_quote', $tagnames ) );
// WARNING from shortcodes.php! Do not change this regex without changing do_shortcode_tag() and strip_shortcode_tag()
// Also, see shortcode_unautop() and shortcode.js.
return '\\[' // Opening bracket
. '(\\[?)' // 1: Optional second opening bracket for escaping shortcodes: [[tag]]
. "($tagregexp)" // 2: Shortcode name
. '(?![\\w-])' // Not followed by word character or hyphen
. '(' // 3: Unroll the loop: Inside the opening shortcode tag
. '[^\\]\\/]*' // Not a closing bracket or forward slash
. '(?:' . '\\/(?!\\])' // A forward slash not followed by a closing bracket
. '[^\\]\\/]*' // Not a closing bracket or forward slash
. ')*?' . ')' . '(?:' . '(\\/)' // 4: Self closing tag ...
. '\\]' // ... and closing bracket
. '|' . '\\]' // Closing bracket
. '(?:' . '(' // 5: Unroll the loop: Optionally, anything between the opening and closing shortcode tags
. '[^\\[]*+' // Not an opening bracket
. '(?:' . '\\[(?!\\/\\2\\])' // An opening bracket not followed by the closing shortcode tag
. '[^\\[]*+' // Not an opening bracket
. ')*+' . ')' . '\\[\\/\\2\\]' // Closing shortcode tag
. ')?' . ')' . '(\\]?)'; // 6: Optional second closing brocket for escaping shortcodes: [[tag]]
}
/**
*
*/
function setPost() {
global $post;
$this->post = get_post(); // fixes #1342 if no get/post params set
$this->post_id = vc_get_param( 'post_id' );
if ( vc_post_param( 'post_id' ) ) {
$this->post_id = vc_post_param( 'post_id' );
}
if ( $this->post_id ) {
$this->post = get_post( $this->post_id );
}
do_action_ref_array( 'the_post', array( $this->post ) );
$post = $this->post;
$this->post_id = $this->post->ID;
}
/**
* @return mixed
*/
function post() {
! isset( $this->post ) && $this->setPost();
return $this->post;
}
/**
* Used for wp filter 'wp_insert_post_empty_content' to allow empty post insertion.
*
* @param $allow_empty
*
* @return bool
*/
public function allowInsertEmptyPost( $allow_empty ) {
return false;
}
/**
* vc_filter: vc_frontend_editor_iframe_url - hook to edit iframe url, can be used in vendors like qtranslate do.
*/
function renderEditor() {
global $current_user;
wp_get_current_user();
$this->current_user = $current_user;
$this->post_url = set_url_scheme( get_permalink( $this->post_id ) );
if ( ! self::inlineEnabled() || ! vc_user_access()->wpAny( array(
'edit_post',
$this->post_id,
) )->get() ) {
header( 'Location: ' . $this->post_url );
}
$this->registerJs();
$this->registerCss();
visual_composer()->registerAdminCss(); //bc
visual_composer()->registerAdminJavascript(); //bc
if ( $this->post && 'auto-draft' === $this->post->post_status ) {
$post_data = array(
'ID' => $this->post_id,
'post_status' => 'draft',
'post_title' => '',
);
add_filter( 'wp_insert_post_empty_content', array(
$this,
'allowInsertEmptyPost',
) );
wp_update_post( $post_data, true );
$this->post->post_status = 'draft';
$this->post->post_title = '';
}
add_filter( 'admin_body_class', array(
$this,
'filterAdminBodyClass',
) );
$this->post_type = get_post_type_object( $this->post->post_type );
$this->url = $this->post_url . ( preg_match( '/\?/', $this->post_url ) ? '&' : '?' ) . 'vc_editable=true&vc_post_id=' . $this->post->ID . '&_vcnonce=' . vc_generate_nonce( 'vc-admin-nonce' );
$this->url = apply_filters( 'vc_frontend_editor_iframe_url', $this->url );
$this->enqueueAdmin();
$this->enqueueMappedShortcode();
wp_enqueue_media( array( 'post' => $this->post_id ) );
remove_all_actions( 'admin_notices', 3 );
remove_all_actions( 'network_admin_notices', 3 );
$post_custom_css = strip_tags( get_post_meta( $this->post_id, '_wpb_post_custom_css', true ) );
$this->post_custom_css = $post_custom_css;
if ( ! defined( 'IFRAME_REQUEST' ) ) {
define( 'IFRAME_REQUEST', true );
}
/**
* @deprecated vc_admin_inline_editor action hook
*/
do_action( 'vc_admin_inline_editor' );
/**
* new one
*/
do_action( 'vc_frontend_editor_render' );
add_filter( 'admin_title', array(
$this,
'setEditorTitle',
) );
$this->render( 'editor' );
die();
}
/**
* @return string
*/
function setEditorTitle() {
return sprintf( __( 'Edit %s with WPBakery Page Builder', 'js_composer' ), $this->post_type->labels->singular_name );
}
/**
* @param $title
*
* @return string|void
*/
function setEmptyTitlePlaceholder( $title ) {
return ! is_string( $title ) || strlen( $title ) === 0 ? __( '(no title)', 'js_composer' ) : $title;
}
/**
* @param $template
*/
function render( $template ) {
vc_include_template( 'editors/frontend_' . $template . '.tpl.php', array( 'editor' => $this ) );
}
/**
* @param $link
*
* @return string
*/
function renderEditButton( $link ) {
if ( $this->showButton( get_the_ID() ) ) {
return $link . ' <a href="' . self::getInlineUrl() . '" id="vc_load-inline-editor" class="vc_inline-link">' . __( 'Edit with WPBakery Page Builder', 'js_composer' ) . '</a>';
}
return $link;
}
/**
* @param $actions
*
* @return mixed
*/
function renderRowAction( $actions ) {
$post = get_post();
if ( $this->showButton( $post->ID ) ) {
$actions['edit_vc'] = '<a
href="' . $this->getInlineUrl( '', $post->ID ) . '">' . __( 'Edit with WPBakery Page Builder', 'js_composer' ) . '</a>';
}
return $actions;
}
/**
* @param null $post_id
*
* @return bool
*/
function showButton( $post_id = null ) {
$type = get_post_type();
$result = self::inlineEnabled() && ! in_array( get_post_status(), array(
'private',
'trash',
) ) && ! in_array( $type, array(
'templatera',
'vc_grid_item',
) ) && vc_user_access()->wpAny( array(
'edit_post',
$post_id,
) )->get() && vc_check_post_type( $type );
return apply_filters( 'vc_show_button_fe', $result, $post_id, $type );
}
/**
* @param WP_Admin_Bar $wp_admin_bar
*/
function adminBarEditLink( $wp_admin_bar ) {
if ( ! is_object( $wp_admin_bar ) ) {
global $wp_admin_bar;
}
if ( is_singular() ) {
if ( $this->showButton( get_the_ID() ) ) {
$wp_admin_bar->add_menu( array(
'id' => 'vc_inline-admin-bar-link',
'title' => __( 'Edit with WPBakery Page Builder', 'js_composer' ),
'href' => self::getInlineUrl(),
'meta' => array( 'class' => 'vc_inline-link' ),
) );
}
}
}
/**
* @param $content
*/
function setTemplateContent( $content ) {
$this->template_content = $content;
}
/**
* vc_filter: vc_inline_template_content - filter to override template content
* @return mixed|void
*/
function getTemplateContent() {
return apply_filters( 'vc_inline_template_content', $this->template_content );
}
/**
*
*/
function renderTemplates() {
$this->render( 'templates' );
die();
}
/**
*
*/
function loadTinyMceSettings() {
if ( ! class_exists( '_WP_Editors' ) ) {
require( ABSPATH . WPINC . '/class-wp-editor.php' );
}
$set = _WP_Editors::parse_settings( self::$content_editor_id, self::$content_editor_settings );
_WP_Editors::editor_settings( self::$content_editor_id, $set );
}
/**
*
*/
function loadIFrameJsCss() {
wp_enqueue_script( 'jquery-ui-tabs' );
wp_enqueue_script( 'jquery-ui-sortable' );
wp_enqueue_script( 'jquery-ui-droppable' );
wp_enqueue_script( 'jquery-ui-draggable' );
wp_enqueue_script( 'jquery-ui-accordion' );
wp_enqueue_script( 'jquery-ui-autocomplete' );
wp_enqueue_script( 'wpb_composer_front_js' );
wp_enqueue_style( 'js_composer_front' );
wp_enqueue_style( 'vc_inline_css', vc_asset_url( 'css/js_composer_frontend_editor_iframe.min.css' ), array(), WPB_VC_VERSION );
wp_enqueue_script( 'waypoints' );
wp_enqueue_script( 'wpb_scrollTo_js', vc_asset_url( 'lib/bower/scrollTo/jquery.scrollTo.min.js' ), array( 'jquery' ), WPB_VC_VERSION, true );
wp_enqueue_style( 'js_composer_custom_css' );
wp_enqueue_script( 'wpb_php_js', vc_asset_url( 'lib/php.default/php.default.min.js' ), array( 'jquery' ), WPB_VC_VERSION, true );
wp_enqueue_script( 'vc_inline_iframe_js', vc_asset_url( 'js/dist/page_editable.min.js' ), array(
'jquery',
'underscore',
), WPB_VC_VERSION, true );
do_action( 'vc_load_iframe_jscss' );
}
/**
*
*/
function loadShortcodes() {
if ( vc_is_page_editable() && vc_enabled_frontend() ) {
$action = vc_post_param( 'action' );
if ( 'vc_load_shortcode' === $action ) {
! defined( 'CONCATENATE_SCRIPTS' ) && define( 'CONCATENATE_SCRIPTS', false );
ob_start();
$this->setPost();
$shortcodes = (array) vc_post_param( 'shortcodes' );
do_action( 'vc_load_shortcode', $shortcodes );
$this->renderShortcodes( $shortcodes );
echo '<div data-type="files">';
_print_styles();
print_head_scripts();
wp_footer();
echo '</div>';
$output = ob_get_clean();
die( apply_filters( 'vc_frontend_editor_load_shortcode_ajax_output', $output ) );
} elseif ( 'vc_frontend_load_template' === $action ) {
$this->setPost();
visual_composer()->templatesPanelEditor()->renderFrontendTemplate();
} else if ( '' !== $action ) {
do_action( 'vc_front_load_page_' . esc_attr( vc_post_param( 'action' ) ) );
}
}
}
/**
* @param $s
*
* @return string
*/
function fullUrl( $s ) {
$ssl = ( ! empty( $s['HTTPS'] ) && 'on' === $s['HTTPS'] ) ? true : false;
$sp = strtolower( $s['SERVER_PROTOCOL'] );
$protocol = substr( $sp, 0, strpos( $sp, '/' ) ) . ( ( $ssl ) ? 's' : '' );
$port = $s['SERVER_PORT'];
$port = ( ( ! $ssl && '80' === $port ) || ( $ssl && '443' === $port ) ) ? '' : ':' . $port;
$host = isset( $s['HTTP_X_FORWARDED_HOST'] ) ? $s['HTTP_X_FORWARDED_HOST'] : isset( $s['HTTP_HOST'] ) ? $s['HTTP_HOST'] : $s['SERVER_NAME'];
return $protocol . '://' . $host . $port . $s['REQUEST_URI'];
}
/**
* @return string
*/
static function cleanStyle() {
return '';
}
/**
*
*/
function enqueueRequired() {
do_action( 'wp_enqueue_scripts' );
visual_composer()->frontCss();
visual_composer()->frontJsRegister();
}
/**
* @param array $shortcodes
*
* vc_filter: vc_front_render_shortcodes - hook to override shortcode rendered output
*/
function renderShortcodes( array $shortcodes ) {
$this->enqueueRequired();
$output = '';
foreach ( $shortcodes as $shortcode ) {
if ( isset( $shortcode['id'] ) && isset( $shortcode['string'] ) ) {
if ( isset( $shortcode['tag'] ) ) {
$shortcode_obj = visual_composer()->getShortCode( $shortcode['tag'] );
if ( is_object( $shortcode_obj ) ) {
$output .= '<div data-type="element" data-model-id="' . $shortcode['id'] . '">';
$is_container = $shortcode_obj->settings( 'is_container' ) || ( null !== $shortcode_obj->settings( 'as_parent' ) && false !== $shortcode_obj->settings( 'as_parent' ) );
if ( $is_container ) {
$shortcode['string'] = preg_replace( '/\]/', '][vc_container_anchor]', $shortcode['string'], 1 );
}
$output .= '<div class="vc_element"' . self::cleanStyle() . ' data-shortcode-controls="' . esc_attr( json_encode( $shortcode_obj->shortcodeClass()
->getControlsList() ) ) . '" data-container="' . $is_container . '" data-model-id="' . $shortcode['id'] . '">' . $this->wrapperStart() . do_shortcode( stripslashes( $shortcode['string'] ) ) . $this->wrapperEnd() . '</div>';
$output .= '</div>';
}
}
}
}
echo apply_filters( 'vc_front_render_shortcodes', $output );
}
/**
* @param $string
*
* @return string
*/
function filterAdminBodyClass( $string ) {
// @todo check vc_inline-shortcode-edit-form class looks like incorrect place
$string .= ( strlen( $string ) > 0 ? ' ' : '' ) . 'vc_editor vc_inline-shortcode-edit-form';
if ( '1' === vc_settings()->get( 'not_responsive_css' ) ) {
$string .= ' vc_responsive_disabled';
}
return $string;
}
/**
* @param $path
*
* @return string
*/
function adminFile( $path ) {
return ABSPATH . 'wp-admin/' . $path;
}
public function registerJs() {
wp_register_script( 'vc_bootstrap_js', vc_asset_url( 'lib/bower/bootstrap3/dist/js/bootstrap.min.js' ), array( 'jquery' ), WPB_VC_VERSION, true );
wp_register_script( 'vc_accordion_script', vc_asset_url( 'lib/vc_accordion/vc-accordion.min.js' ), array( 'jquery' ), WPB_VC_VERSION, true );
wp_register_script( 'wpb_php_js', vc_asset_url( 'lib/php.default/php.default.min.js' ), array( 'jquery' ), WPB_VC_VERSION, true );
// used as polyfill for JSON.stringify and etc
wp_register_script( 'wpb_json-js', vc_asset_url( 'lib/bower/json-js/json2.min.js' ), array(), WPB_VC_VERSION, true );
// used in post settings editor
wp_register_script( 'ace-editor', vc_asset_url( 'lib/bower/ace-builds/src-min-noconflict/ace.js' ), array( 'jquery' ), WPB_VC_VERSION, true );
wp_register_script( 'webfont', 'https://ajax.googleapis.com/ajax/libs/webfont/1.6.26/webfont.js' ); // Google Web Font CDN
wp_register_script( 'wpb_scrollTo_js', vc_asset_url( 'lib/bower/scrollTo/jquery.scrollTo.min.js' ), array( 'jquery' ), WPB_VC_VERSION, true );
wp_register_script( 'vc_accordion_script', vc_asset_url( 'lib/vc_accordion/vc-accordion.min.js' ), array( 'jquery' ), WPB_VC_VERSION, true );
wp_register_script( 'vc-frontend-editor-min-js', vc_asset_url( 'js/dist/frontend-editor.min.js' ), array(), WPB_VC_VERSION, true );
wp_localize_script( 'vc-frontend-editor-min-js', 'i18nLocale', visual_composer()->getEditorsLocale() );
}
/**
*
*/
public function enqueueJs() {
$wp_dependencies = array(
'jquery',
'underscore',
'backbone',
'media-views',
'media-editor',
'wp-pointer',
'mce-view',
'wp-color-picker',
'jquery-ui-sortable',
'jquery-ui-droppable',
'jquery-ui-draggable',
'jquery-ui-resizable',
'jquery-ui-accordion',
'jquery-ui-autocomplete',
// used in @deprecated tabs
'jquery-ui-tabs',
'wp-color-picker',
'farbtastic',
);
$dependencies = array(
'vc_bootstrap_js',
'vc_accordion_script',
'wpb_php_js',
'wpb_json-js',
'ace-editor',
'webfont',
'vc_accordion_script',
'vc-frontend-editor-min-js',
);
// This workaround will allow to disable any of dependency on-the-fly
foreach ( $wp_dependencies as $dependency ) {
wp_enqueue_script( $dependency );
}
foreach ( $dependencies as $dependency ) {
wp_enqueue_script( $dependency );
}
}
public function registerCss() {
wp_register_style( 'ui-custom-theme', vc_asset_url( 'css/ui-custom-theme/jquery-ui-less.custom.min.css' ), false, WPB_VC_VERSION );
wp_register_style( 'animate-css', vc_asset_url( 'lib/bower/animate-css/animate.min.css' ), false, WPB_VC_VERSION, 'screen' );
wp_register_style( 'font-awesome', vc_asset_url( 'lib/bower/font-awesome/css/font-awesome.min.css' ), false, WPB_VC_VERSION, 'screen' );
wp_register_style( 'vc_inline_css', vc_asset_url( 'css/js_composer_frontend_editor.min.css' ), array(), WPB_VC_VERSION );
}
public function enqueueCss() {
$wp_dependencies = array(
'wp-color-picker',
'farbtastic',
);
$dependencies = array(
'ui-custom-theme',
'animate-css',
'font-awesome',
//'wpb_jscomposer_autosuggest',
'vc_inline_css',
);
// This workaround will allow to disable any of dependency on-the-fly
foreach ( $wp_dependencies as $dependency ) {
wp_enqueue_style( $dependency );
}
foreach ( $dependencies as $dependency ) {
wp_enqueue_style( $dependency );
}
}
/**
*
*/
function enqueueAdmin() {
$this->enqueueJs();
$this->enqueueCss();
do_action( 'vc_frontend_editor_enqueue_js_css' );
}
/**
* Enqueue js/css files from mapped shortcodes.
*
* To add js/css files to this enqueue please add front_enqueue_js/front_enqueue_css setting in vc_map array.
* @since 4.3
*
*/
function enqueueMappedShortcode() {
foreach ( WPBMap::getUserShortCodes() as $shortcode ) {
$param = isset( $shortcode['front_enqueue_js'] ) ? $shortcode['front_enqueue_js'] : null;
if ( is_array( $param ) && ! empty( $param ) ) {
foreach ( $param as $value ) {
$this->enqueueMappedShortcodeJs( $value );
}
} elseif ( is_string( $param ) && ! empty( $param ) ) {
$this->enqueueMappedShortcodeJs( $param );
}
$param = isset( $shortcode['front_enqueue_css'] ) ? $shortcode['front_enqueue_css'] : null;
if ( is_array( $param ) && ! empty( $param ) ) {
foreach ( $param as $value ) {
$this->enqueueMappedShortcodeCss( $value );
}
} elseif ( is_string( $param ) && ! empty( $param ) ) {
$this->enqueueMappedShortcodeCss( $param );
}
}
}
public function enqueueMappedShortcodeJs( $value ) {
wp_enqueue_script( 'front_enqueue_js_' . md5( $value ), $value, array( 'vc-frontend-editor-min-js' ), WPB_VC_VERSION, true );
}
public function enqueueMappedShortcodeCss( $value ) {
wp_enqueue_style( 'front_enqueue_css_' . md5( $value ), $value, array( 'vc_inline_css' ), WPB_VC_VERSION );
}
/**
* @param $content
*
* @since 4.4
*/
function getPageShortcodesByContent( $content ) {
if ( ! empty( $this->post_shortcodes ) ) {
return;
}
$content = shortcode_unautop( trim( $content ) ); // @todo this seems not working fine.
$not_shortcodes = preg_split( '/' . self::shortcodesRegexp() . '/', $content );
foreach ( $not_shortcodes as $string ) {
$temp = str_replace( array(
'<p>',
'</p>',
), '', $string ); // just to avoid autop @todo maybe do it better like vc_wpnop in js.
if ( strlen( trim( $temp ) ) > 0 ) {
$content = preg_replace( '/(' . preg_quote( $string, '/' ) . '(?!\[\/))/', '[vc_row][vc_column width="1/1"][vc_column_text]$1[/vc_column_text][/vc_column][/vc_row]', $content );
}
}
echo $this->parseShortcodesString( $content );
}
/**
* @param $content
* @param bool $is_container
* @param bool $parent_id
*
* @since 4.2
* @return string
*/
function parseShortcodesString( $content, $is_container = false, $parent_id = false ) {
$string = '';
preg_match_all( '/' . self::shortcodesRegexp() . '/', trim( $content ), $found );
WPBMap::addAllMappedShortcodes();
add_shortcode( 'vc_container_anchor', 'vc_container_anchor' );
if ( count( $found[2] ) === 0 ) {
return $is_container && strlen( $content ) > 0 ? $this->parseShortcodesString( '[vc_column_text]' . $content . '[/vc_column_text]', false, $parent_id ) : $content;
}
foreach ( $found[2] as $index => $s ) {
$id = md5( time() . '-' . $this->tag_index ++ );
$content = $found[5][ $index ];
$attrs = shortcode_parse_atts( $found[3][ $index ] );
if ( empty( $attrs ) ) {
$attrs = array();
} elseif ( ! is_array( $attrs ) ) {
$attrs = (array) $attrs;
}
$shortcode = array(
'tag' => $s,
'attrs_query' => $found[3][ $index ],
'attrs' => $attrs,
'id' => $id,
'parent_id' => $parent_id,
);
if ( false !== WPBMap::getParam( $s, 'content' ) ) {
$shortcode['attrs']['content'] = $content;
}
$this->post_shortcodes[] = rawurlencode( json_encode( $shortcode ) );
$string .= $this->toString( $shortcode, $content );
}
return $string;
}
/**
* @param $shortcode
* @param $content
*
* @since 4.2
* @return string
*/
function toString( $shortcode, $content ) {
$shortcode_obj = visual_composer()->getShortCode( $shortcode['tag'] );
$is_container = $shortcode_obj->settings( 'is_container' ) || ( null !== $shortcode_obj->settings( 'as_parent' ) && false !== $shortcode_obj->settings( 'as_parent' ) );
$shortcode = apply_filters( 'vc_frontend_editor_to_string', $shortcode, $shortcode_obj );
$output = ( '<div class="vc_element" data-tag="' . $shortcode['tag'] . '" data-shortcode-controls="' . esc_attr( json_encode( $shortcode_obj->shortcodeClass()
->getControlsList() ) ) . '" data-model-id="' . $shortcode['id'] . '"' . self::cleanStyle() . '>' . $this->wrapperStart() . '[' . $shortcode['tag'] . ' ' . $shortcode['attrs_query'] . ']' . ( $is_container ? '[vc_container_anchor]' . $this->parseShortcodesString( $content, $is_container, $shortcode['id'] ) : do_shortcode( $content ) ) . '[/' . $shortcode['tag'] . ']' . $this->wrapperEnd() . '</div>' );
return $output;
}
}
if ( ! function_exists( 'vc_container_anchor' ) ) {
/**
* @since 4.2
* @return string
*/
function vc_container_anchor() {
return '<span class="vc_container-anchor" style="display: none;"></span>';
}
}
@@ -0,0 +1,167 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
require_once vc_path_dir( 'EDITORS_DIR', 'navbar/class-vc-navbar.php' );
/**
*
*/
class Vc_Navbar_Frontend extends Vc_Navbar {
/**
* @var array
*/
protected $controls = array(
'add_element',
'templates',
'view_post',
'save_update',
'screen_size',
//'guides_switch', // disabled in 4.9
'custom_css',
);
/**
* @var string
*/
protected $controls_filter_name = 'vc_nav_front_controls';
/**
* @var string
*/
protected $brand_url = 'https://wpbakery.com/?utm_campaign=VCplugin&utm_source=vc_user&utm_medium=frontend_editor';
/**
* @var string
*/
protected $css_class = 'vc_navbar vc_navgar-frontend';
/**
* @return string
*/
public function getControlGuidesSwitch() {
return '<li class="vc_pull-right">'
. '<button id="vc_guides-toggle-button" class="vc_btn vc_btn-primary vc_btn-sm vc_navbar-btn"'
. ' title="' . __( "Toggle editor's guides", 'js_composer' ) . '">'
. __( 'Guides ON', 'js_composer' )
. '</button>'
. '</li>';
}
/**
* @return string
*/
public function getControlScreenSize() {
$disable_responsive = vc_settings()->get( 'not_responsive_css' );
if ( '1' !== $disable_responsive ) {
$screen_sizes = array(
array(
'title' => __( 'Desktop', 'js_composer' ),
'size' => '100%',
'key' => 'default',
'active' => true,
),
array(
'title' => __( 'Tablet landscape mode', 'js_composer' ),
'size' => '1024px',
'key' => 'landscape-tablets',
),
array(
'title' => __( 'Tablet portrait mode', 'js_composer' ),
'size' => '768px',
'key' => 'portrait-tablets',
),
array(
'title' => __( 'Smartphone landscape mode', 'js_composer' ),
'size' => '480px',
'key' => 'landscape-smartphones',
),
array(
'title' => __( 'Smartphone portrait mode', 'js_composer' ),
'size' => '320px',
'key' => 'portrait-smartphones',
),
);
$output = '<li class="vc_pull-right">'
. '<div class="vc_dropdown" id="vc_screen-size-control">'
. '<a href="#" class="vc_dropdown-toggle"'
. ' title="' . __( 'Responsive preview', 'js_composer' ) . '"><i class="vc-composer-icon vc_current-layout-icon vc-c-icon-layout_default"'
. ' id="vc_screen-size-current"></i><i class="vc-composer-icon vc-c-icon-arrow_drop_down"></i></a>'
. '<ul class="vc_dropdown-list">';
while ( $screen = current( $screen_sizes ) ) {
$output .= '<li><a href="#" title="' . esc_attr( $screen['title'] ) . '"'
. ' class="vc_screen-width vc-composer-icon vc-c-icon-layout_' . $screen['key']
. ( isset( $screen['active'] ) && $screen['active'] ? ' active' : '' )
. '" data-size="' . $screen['size'] . '"></a></li>';
next( $screen_sizes );
}
$output .= '</ul></div></li>';
return $output;
}
return '';
}
/**
* @return string
*/
public function getControlSaveUpdate() {
$post = $this->post();
$post_type = get_post_type_object( $this->post->post_type );
$can_publish = current_user_can( $post_type->cap->publish_posts );
ob_start();
?>
<li class="vc_show-mobile vc_pull-right">
<button data-url="<?php esc_attr_e( get_edit_post_link( $post->ID ) . '&wpb_vc_js_status=true&classic-editor' ) ?>"
class="vc_btn vc_btn-default vc_btn-sm vc_navbar-btn vc_btn-backend-editor" id="vc_button-cancel"
title="<?php _e( 'Cancel all changes and return to WP dashboard', 'js_composer' ) ?>"><?php echo vc_user_access()
->part( 'backend_editor' )
->can()
->get() ? __( 'Backend Editor', 'js_composer' ) : __( 'Edit', 'js_composer' ); ?></button>
<?php if ( ! in_array( $post->post_status, array(
'publish',
'future',
'private',
) )
) : ?>
<?php if ( 'draft' === $post->post_status ) : ?>
<button type="button" class="vc_btn vc_btn-default vc_btn-sm vc_navbar-btn vc_btn-save-draft"
id="vc_button-save-draft"
title="<?php esc_attr_e( 'Save Draft', 'js_composer' ) ?>"><?php _e( 'Save Draft', 'js_composer' ) ?></button>
<?php elseif ( 'pending' === $post->post_status && $can_publish ) : ?>
<button type="button" class="vc_btn vc_btn-primary vc_btn-sm vc_navbar-btn vc_btn-save"
id="vc_button-save-as-pending"
title="<?php esc_attr_e( 'Save as Pending', 'js_composer' ) ?>"><?php _e( 'Save as Pending', 'js_composer' ) ?></button>
<?php endif ?>
<?php if ( $can_publish ) : ?>
<button type="button" class="vc_btn vc_btn-primary vc_btn-sm vc_navbar-btn vc_btn-save"
id="vc_button-update" title="<?php esc_attr_e( 'Publish', 'js_composer' ) ?>"
data-change-status="publish"><?php _e( 'Publish', 'js_composer' ) ?></button>
<?php else : ?>
<button type="button" class="vc_btn vc_btn-primary vc_btn-sm vc_navbar-btn vc_btn-save"
id="vc_button-update" title="<?php esc_attr_e( 'Submit for Review', 'js_composer' ) ?>"
data-change-status="pending"><?php _e( 'Submit for Review', 'js_composer' ) ?></button>
<?php endif ?>
<?php else : ?>
<button type="button" class="vc_btn vc_btn-primary vc_btn-sm vc_navbar-btn vc_btn-save"
id="vc_button-update"
title="<?php esc_attr_e( 'Update', 'js_composer' ) ?>"><?php _e( 'Update', 'js_composer' ) ?></button>
<?php endif ?>
</li>
<?php
$output = ob_get_contents();
ob_end_clean();
return $output;
}
/**
* @return string
*/
public function getControlViewPost() {
return '<li class="vc_pull-right">'
. '<a href="' . esc_attr( get_permalink( $this->post() ) ) . '" class="vc_icon-btn vc_back-button"'
. ' title="' . esc_attr__( 'Exit WPBakery Page Builder edit mode', 'js_composer' ) . '"><i class="vc-composer-icon vc-c-icon-close"></i></a>'
. '</li>';
}
}
@@ -0,0 +1,33 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
class Vc_Navbar_Undoredo {
public function __construct() {
// Backend
add_filter( 'vc_nav_controls', array(
$this,
'addControls',
) );
// Frontend
add_filter( 'vc_nav_front_controls', array(
$this,
'addControls',
) );
}
public function addControls( $controls ) {
$controls[] = array(
'redo',
'<li class="vc_pull-right"><a id="vc_navbar-redo" href="javascript:;" class="vc_icon-btn" disabled title="' . __( 'Redo', 'js_composer' ) . '"><i class="vc_navbar-icon fa fa-repeat"></i></a></li>',
);
$controls[] = array(
'undo',
'<li class="vc_pull-right"><a id="vc_navbar-undo" href="javascript:;" class="vc_icon-btn" disabled title="' . __( 'Undo', 'js_composer' ) . '"><i class="vc_navbar-icon fa fa-undo"></i></a></li>',
);
return $controls;
}
}
@@ -0,0 +1,195 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
/**
* Renders navigation bar for Editors.
*/
class Vc_Navbar implements Vc_Render {
/**
* @var array
*/
protected $controls = array(
'add_element',
'templates',
'save_backend',
'preview',
'frontend',
'custom_css',
'fullscreen',
'windowed',
);
/**
* @var string
*/
protected $brand_url = 'https://wpbakery.com/?utm_campaign=VCplugin&utm_source=vc_user&utm_medium=backend_editor';
/**
* @var string
*/
protected $css_class = 'vc_navbar';
/**
* @var string
*/
protected $controls_filter_name = 'vc_nav_controls';
/**
* @var bool|WP_Post
*/
protected $post = false;
/**
* @param WP_Post $post
*/
public function __construct( WP_Post $post ) {
$this->post = $post;
}
/**
* Generate array of controls by iterating property $controls list.
* vc_filter: vc_nav_controls - hook to override list of controls
* @return array - list of arrays witch contains key name and html output for button.
*/
public function getControls() {
$list = array();
foreach ( $this->controls as $control ) {
$method = vc_camel_case( 'get_control_' . $control );
if ( method_exists( $this, $method ) ) {
$list[] = array( $control, $this->$method() . "\n" );
}
}
return apply_filters( $this->controls_filter_name, $list );
}
/**
* Get current post.
* @return null|WP_Post
*/
public function post() {
if ( $this->post ) {
return $this->post;
}
return get_post();
}
/**
* Render template.
*/
public function render() {
vc_include_template( 'editors/navbar/navbar.tpl.php', array(
'css_class' => $this->css_class,
'controls' => $this->getControls(),
'nav_bar' => $this,
'post' => $this->post(),
) );
}
/**
* vc_filter: vc_nav_front_logo - hook to override WPBakery Page Builder logo
* @return mixed|void
*/
public function getLogo() {
$output = '<a id="vc_logo" class="vc_navbar-brand" title="' . __( 'WPBakery Page Builder', 'js_composer' )
. '" href="' . esc_attr( $this->brand_url ) . '" target="_blank">'
. __( 'WPBakery Page Builder', 'js_composer' ) . '</a>';
return apply_filters( 'vc_nav_front_logo', $output );
}
/**
* @return string
*/
public function getControlCustomCss() {
if ( ! vc_user_access()->part( 'post_settings' )->can()->get() ) {
return '';
}
return '<li class="vc_pull-right"><a id="vc_post-settings-button" href="javascript:;" class="vc_icon-btn vc_post-settings" title="'
. __( 'Page settings', 'js_composer' ) . '">'
. '<span id="vc_post-css-badge" class="vc_badge vc_badge-custom-css" style="display: none;">' . __( 'CSS', 'js_composer' )
. '</span><i class="vc-composer-icon vc-c-icon-cog"></i></a>'
. '</li>';
}
/**
* @return string
*/
public function getControlFullscreen() {
return '<li class="vc_show-mobile vc_pull-right">'
. '<a id="vc_fullscreen-button" class="vc_icon-btn vc_fullscreen-button" title="'. __( 'Full screen', 'js_composer' ) . '"><i class="vc-composer-icon vc-c-icon-fullscreen"></i></a>'
. '</li>';
}
/**
* @return string
*/
public function getControlWindowed() {
return '<li class="vc_show-mobile vc_pull-right">'
. '<a id="vc_windowed-button" class="vc_icon-btn vc_windowed-button" title="'. __( 'Exit full screen', 'js_composer' ) . '"><i class="vc-composer-icon vc-c-icon-fullscreen_exit"></i></a>'
. '</li>';
}
/**
* @return string
*/
public function getControlAddElement() {
if ( vc_user_access()
->part( 'shortcodes' )
->checkStateAny( true, 'custom', null )
->get() &&
vc_user_access_check_shortcode_all( 'vc_row' ) && vc_user_access_check_shortcode_all( 'vc_column' )
) {
return '<li class="vc_show-mobile">'
. ' <a href="javascript:;" class="vc_icon-btn vc_element-button" data-model-id="vc_element" id="vc_add-new-element" title="'
. '' . __( 'Add new element', 'js_composer' ) . '">'
. ' <i class="vc-composer-icon vc-c-icon-add_element"></i>'
. ' </a>'
. '</li>';
}
return '';
}
/**
* @return string
*/
public function getControlTemplates() {
if ( ! vc_user_access()->part( 'templates' )->can()->get() ) {
return '';
}
return '<li><a href="javascript:;" class="vc_icon-btn vc_templates-button" id="vc_templates-editor-button" title="'
. __( 'Templates', 'js_composer' ) . '"><i class="vc-composer-icon vc-c-icon-add_template"></i></a></li>';
}
/**
* @return string
*/
public function getControlFrontend() {
if ( ! vc_enabled_frontend() ) {
return '';
}
return '<li class="vc_pull-right" style="display: none;">'
. '<a href="' . vc_frontend_editor()->getInlineUrl() . '" class="vc_btn vc_btn-primary vc_btn-sm vc_navbar-btn" id="wpb-edit-inline">' . __( 'Frontend', 'js_composer' ) . '</a>'
. '</li>';
}
/**
* @return string
*/
public function getControlPreview() {
return '';
}
/**
* @return string
*/
public function getControlSaveBackend() {
return '<li class="vc_pull-right vc_save-backend">'
. '<a href="javascript:;" class="vc_btn vc_btn-grey vc_btn-sm vc_navbar-btn vc_control-preview">' . __( 'Preview', 'js_composer' ) . '</a>'
. '<a class="vc_btn vc_btn-sm vc_navbar-btn vc_btn-primary vc_control-save" id="wpb-save-post">' . __( 'Update', 'js_composer' ) . '</a>'
. '</li>';
}
}
@@ -0,0 +1,158 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
/**
* WPBakery WPBakery Page Builder front end editor
*
* @package WPBakeryPageBuilder
*
*/
/**
* Add element for VC editors with a list of mapped shortcodes.
*
* @since 4.3
*/
class Vc_Add_Element_Box implements Vc_Render {
/**
* Enable show empty message
*
* @since 4.8
* @var bool
*/
protected $show_empty_message = false;
/**
* @param $params
*
* @return string
*/
protected function getIcon( $params ) {
$data = '';
if ( isset( $params['is_container'] ) && true === $params['is_container'] ) {
$data = ' data-is-container="true"';
}
return '<i class="vc_general vc_element-icon' . ( ! empty( $params['icon'] ) ? ' ' . sanitize_text_field( $params['icon'] ) : '' ) . '"' . $data . '></i> ';
}
/**
* Single button html template
*
* @param $params
*
* @return string
*/
public function renderButton( $params ) {
if ( ! is_array( $params ) || empty( $params ) ) {
return '';
}
$output = $class = $class_out = $data = $category_css_classes = '';
if ( ! empty( $params['class'] ) ) {
$class_ar = $class_at_out = explode( ' ', $params['class'] );
for ( $n = 0; $n < count( $class_ar ); $n ++ ) {
$class_ar[ $n ] .= '_nav';
$class_at_out[ $n ] .= '_o';
}
$class = ' ' . implode( ' ', $class_ar );
$class_out = ' ' . implode( ' ', $class_at_out );
}
if ( isset( $params['_category_ids'] ) ) {
foreach ( $params['_category_ids'] as $id ) {
$category_css_classes .= ' js-category-' . $id;
}
}
if ( isset( $params['is_container'] ) && true === $params['is_container'] ) {
$data .= ' data-is-container="true"';
}
$data .= ' data-vc-ui-element="add-element-button"';
$description = ! empty( $params['description'] ) ? '<span class="vc_element-description">' . htmlspecialchars( $params['description'] ) . '</span>' : '';
$name = '<span data-vc-shortcode-name>' . htmlspecialchars( stripslashes( $params['name'] ) ) . '</span>';
$output .= '<li data-element="' . $params['base'] . '"'. ( isset( $params['presetId'] ) ? ' data-preset="' . $params['presetId'] . '"' : '' ) .' class="wpb-layout-element-button vc_col-xs-12 vc_col-sm-4 vc_col-md-3 vc_col-lg-2' . ( isset( $params['deprecated'] ) ? ' vc_element-deprecated' : '' ) . $category_css_classes . $class_out . '"' . $data . '><div class="vc_el-container"><a id="' . $params['base'] . '" data-tag="' . $params['base'] . '" class="dropable_el vc_shortcode-link' . $class . '" href="#" data-vc-clickable>' . $this->getIcon( $params ) . $name . $description . '</a></div></li>';
return $output;
}
/**
* Get mapped shortcodes list.
*
* @since 4.4
* @return array
*/
public function shortcodes() {
return apply_filters( 'vc_add_new_elements_to_box', WPBMap::getSortedUserShortCodes() );
}
/**
* Render list of buttons for each mapped and allowed VC shortcodes.
* vc_filter: vc_add_element_box_buttons - hook to override output of getControls method
* @see WPBMap::getSortedUserShortCodes
* @return mixed|void
*/
public function getControls() {
$output = '<ul class="wpb-content-layouts">';
/** @var array $element */
$buttons_count = 0;
$shortcodes = $this->shortcodes();
foreach ( $shortcodes as $element ) {
if ( isset( $element['content_element'] ) && false === $element['content_element'] ) {
continue;
}
$button = $this->renderButton( $element );
if ( ! empty( $button ) ) {
$buttons_count ++;
}
$output .= $button;
}
$output .= '</ul>';
if ( 0 === $buttons_count ) {
$this->show_empty_message = true;
}
return apply_filters( 'vc_add_element_box_buttons', $output );
}
/**
* Get categories list from mapping data.
* @since 4.5
*
* @return array
*/
public function getCategories() {
return apply_filters( 'vc_add_new_category_filter', WPBMap::getUserCategories() );
}
public function render() {
vc_include_template( 'editors/popups/vc_ui-panel-add-element.tpl.php', array(
'box' => $this,
'template_variables' => array(
'categories' => $this->getCategories(),
),
) );
}
/**
* Render icon for shortcode
*
* @param $params
*
* @since 4.8
* @return string
*/
public function renderIcon( $params ) {
return $this->getIcon( $params );
}
/**
* @return boolean
*/
public function isShowEmptyMessage() {
return $this->show_empty_message;
}
public function getPartState() {
return vc_user_access()->part( 'shortcodes' )->getState();
}
}
@@ -0,0 +1,18 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
/**
* Edit row layout
*
* @since 4.3
*/
class Vc_Edit_Layout {
public function renderUITemplate() {
global $vc_row_layouts;
vc_include_template( 'editors/popups/vc_ui-panel-row-layout.tpl.php', array(
'vc_row_layouts' => $vc_row_layouts,
) );
}
}
@@ -0,0 +1,39 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
/**
* Post settings like custom css for page are displayed here.
*
* @since 4.3
*/
class Vc_Post_Settings {
/**
* @var Vc_Editor_Interface
*/
protected $editor;
/**
* @param Vc_Editor_Interface $editor
*/
public function __construct( Vc_Editor_Interface $editor ) {
$this->editor = $editor;
}
/**
* @return Vc_Editor_Interface
*/
public function editor() {
return $this->editor;
}
/**
*
*/
public function renderUITemplate() {
vc_include_template( 'editors/popups/vc_ui-panel-post-settings.tpl.php', array(
'box' => $this,
) );
}
}
@@ -0,0 +1,118 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
/**
* Class Vc_Preset_Panel_Editor
* @since 5.2
*/
class Vc_Preset_Panel_Editor {
/**
* @since 5.2
* @var bool
*/
protected $initialized = false;
/**
* @since 5.2
* Add ajax hooks, filters.
*/
public function init() {
if ( $this->initialized ) {
return;
}
$this->initialized = true;
}
/**
* @since 5.2
*/
public function renderUIPreset() {
vc_include_template( 'editors/popups/vc_ui-panel-preset.tpl.php', array(
'box' => $this,
) );
return '';
}
/**
* Get list of all presets for specific shortcode
*
* @since 5.2
*
*
* @return array E.g. array(id1 => title1, id2 => title2, ...)
*/
public function listPresets() {
$list = array();
$args = array(
'post_type' => 'vc_settings_preset',
'orderby' => array( 'post_date' => 'DESC' ),
'posts_per_page' => - 1,
);
$posts = get_posts( $args );
foreach ( $posts as $post ) {
$presetParentName = self::constructPresetParent( $post->post_mime_type );
$list[ $post->ID ] = array(
'title' => $post->post_title,
'parent' => $presetParentName,
);
}
return $list;
}
/**
* Single preset html
*
* @since 5.2
*
*
* @return string
*/
public function getPresets() {
$listPresets = $this->listPresets();
$output = '';
foreach ( $listPresets as $presetId => $preset ) {
$output .= '<div class="vc_ui-template">';
$output .= '<div class="vc_ui-list-bar-item">';
$output .= '<button type="button" class="vc_ui-list-bar-item-trigger" title="' . esc_attr( $preset['title'] ) . '"
data-vc-ui-element="template-title">' . esc_html( $preset['title'] ) . '</button>';
$output .= '<div class="vc_ui-list-bar-item-actions">';
$output .= '<button id="' . esc_attr( $preset['parent'] ) . '" type="button" class="vc_general vc_ui-control-button" title="' . esc_attr( 'Add element', 'js_composer' ) . '" data-template-handler="" data-preset="' . esc_attr( $presetId ) . '" data-tag="' . esc_attr( $preset['parent'] ) . '" data-vc-ui-add-preset>';
$output .= '<i class="vc-composer-icon vc-c-icon-add"></i>';
$output .= '</button>';
$output .= '<button type="button" class="vc_general vc_ui-control-button" data-vc-ui-delete="preset-title" data-preset="' . esc_attr( $presetId ) . '" data-preset-parent="' . esc_attr( $preset['parent'] ) . '" title="' . esc_attr( 'Delete element', 'js_composer' ) . '">';
$output .= '<i class="vc-composer-icon vc-c-icon-delete_empty"></i>';
$output .= '</button>';
$output .= '</div>';
$output .= '</div>';
$output .= '</div>';
}
return $output;
}
/**
* Get preset parent shortcode name from post mime type
*
* @since 5.2
*
* @param $presetMimeType
*
* @return string
*/
public static function constructPresetParent( $presetMimeType ) {
return str_replace( '-', '_', str_replace( 'vc-settings-preset/', '', $presetMimeType ) );
}
}
@@ -0,0 +1,104 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
/**
* WPBakery WPBakery Page Builder main class.
*
* @package WPBakeryPageBuilder
* @since 4.2
*/
/**
* Edit form for shortcodes with ability to manage shortcode attributes in more convenient way.
*
* @since 4.2
*/
class Vc_Shortcode_Edit_Form implements Vc_Render {
protected $initialized;
/**
*
*/
public function init() {
if ( $this->initialized ) {
return;
}
$this->initialized = true;
add_action( 'wp_ajax_vc_edit_form', array(
$this,
'renderFields',
) );
add_filter( 'vc_single_param_edit', array(
$this,
'changeEditFormFieldParams',
) );
add_filter( 'vc_edit_form_class', array(
$this,
'changeEditFormParams',
) );
}
/**
*
*/
public function render() {
vc_include_template( 'editors/popups/vc_ui-panel-edit-element.tpl.php', array(
'box' => $this,
) );
}
/**
* Build edit form fields.
*
* @since 4.4
*/
public function renderFields() {
$tag = vc_post_param( 'tag' );
vc_user_access()->checkAdminNonce()->validateDie( __( 'Access denied', 'js_composer' ) )->wpAny( array(
'edit_post',
(int) vc_request_param( 'post_id' ),
) )->validateDie( __( 'Access denied', 'js_composer' ) )->check( 'vc_user_access_check_shortcode_edit', $tag )->validateDie( __( 'Access denied', 'js_composer' ) );
$params = (array) stripslashes_deep( vc_post_param( 'params' ) );
$params = array_map( 'vc_htmlspecialchars_decode_deep', $params );
require_once vc_path_dir( 'EDITORS_DIR', 'class-vc-edit-form-fields.php' );
$fields = new Vc_Edit_Form_Fields( $tag, $params );
$fields->render();
die();
}
/**
* @param $param
*
* @return mixed
*/
public function changeEditFormFieldParams( $param ) {
$css = $param['vc_single_param_edit_holder_class'];
if ( isset( $param['edit_field_class'] ) ) {
$new_css = $param['edit_field_class'];
} else {
$new_css = 'vc_col-xs-12';
}
array_unshift( $css, $new_css );
$param['vc_single_param_edit_holder_class'] = $css;
return $param;
}
/**
* @param $css_classes
*
* @return mixed
*/
public function changeEditFormParams( $css_classes ) {
$css = '';
array_unshift( $css_classes, $css );
return $css_classes;
}
}
@@ -0,0 +1,874 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
/**
* Class Vc_Templates_Panel_Editor
* @since 4.4
*/
class Vc_Templates_Panel_Editor {
/**
* @since 4.4
* @var string
*/
protected $option_name = 'wpb_js_templates';
/**
* @since 4.4
* @var bool
*/
protected $default_templates = false;
/**
* @since 4.4
* @var bool
*/
protected $initialized = false;
/**
* @since 4.4
* Add ajax hooks, filters.
*/
public function init() {
if ( $this->initialized ) {
return;
}
$this->initialized = true;
add_filter( 'vc_load_default_templates_welcome_block', array(
$this,
'loadDefaultTemplatesLimit',
) );
add_filter( 'vc_templates_render_category', array(
$this,
'renderTemplateBlock',
), 10 );
add_filter( 'vc_templates_render_template', array(
$this,
'renderTemplateWindow',
), 10, 2 );
/**
* Ajax methods
* 'vc_save_template' -> saving content as template
* 'vc_backend_load_template' -> loading template content for backend
* 'vc_frontend_load_template' -> loading template content for frontend
* 'vc_delete_template' -> deleting template by index
*/
add_action( 'wp_ajax_vc_save_template', array(
$this,
'save',
) );
add_action( 'wp_ajax_vc_backend_load_template', array(
$this,
'renderBackendTemplate',
) );
add_action( 'wp_ajax_vc_frontend_load_template', array(
$this,
'renderFrontendTemplate',
) );
add_action( 'wp_ajax_vc_load_template_preview', array(
$this,
'renderTemplatePreview',
) );
add_action( 'wp_ajax_vc_delete_template', array(
$this,
'delete',
) );
/* add_action( 'vc-render-templates-preview-template', array(
$this,
'addScriptsToTemplatePreview',
) );*/
}
public function addBodyClassTemplatePreview() {
return 'vc_general-template-preview';
}
public function renderTemplateBlock( $category ) {
if ( 'my_templates' === $category['category'] ) {
$category['output'] = '';
if ( vc_user_access()->part( 'templates' )->checkStateAny( true, null )->get() ) {
$category['output'] .= '
<div class="vc_column vc_col-sm-12" data-vc-hide-on-search="true">
<div class="vc_element_label">' . esc_html( __( 'Save current layout as a template', 'js_composer' ) ) . '</div>
<div class="vc_input-group">
<input name="padding" data-js-element="vc-templates-input" class="vc_form-control wpb-textinput vc_panel-templates-name" type="text" value="" placeholder="' . esc_attr__( 'Template name', 'js_composer' ) . '" data-vc-disable-empty="#vc_ui-save-template-btn">
<span class="vc_input-group-btn">
<button class="vc_general vc_ui-button vc_ui-button-size-sm vc_ui-button-action vc_ui-button-shape-rounded vc_template-save-btn" id="vc_ui-save-template-btn" disabled data-vc-ui-element="button-save">' . esc_html( __( 'Save Template', 'js_composer' ) ) . '</button>
</span>
</div>
<span class="vc_description">' . esc_html( __( 'Save layout and reuse it on different sections of this site.', 'js_composer' ) ) . '</span>
</div>';
}
$category['output'] .= '<div class="vc_column vc_col-sm-12">';
if ( isset( $category['category_name'] ) ) {
$category['output'] .= '<h3>' . esc_html( $category['category_name'] ) . '</h3>';
}
if ( isset( $category['category_description'] ) ) {
$category['output'] .= '<p class="vc_description">' . esc_html( $category['category_description'] ) . '</p>';
}
$category['output'] .= '</div>';
$category['output'] .= '
<div class="vc_column vc_col-sm-12">
<div class="vc_ui-template-list vc_templates-list-my_templates vc_ui-list-bar" data-vc-action="collapseAll">';
if ( ! empty( $category['templates'] ) ) {
foreach ( $category['templates'] as $template ) {
$category['output'] .= $this->renderTemplateListItem( $template );
}
}
$category['output'] .= '
</div>
</div>';
} else {
if ( 'default_templates' === $category['category'] ) {
$category['output'] = '<div class="vc_col-md-12">';
if ( isset( $category['category_name'] ) ) {
$category['output'] .= '<h3>' . esc_html( $category['category_name'] ) . '</h3>';
}
if ( isset( $category['category_description'] ) ) {
$category['output'] .= '<p class="vc_description">' . esc_html( $category['category_description'] ) . '</p>';
}
$category['output'] .= '</div>';
$category['output'] .= '
<div class="vc_column vc_col-sm-12">
<div class="vc_ui-template-list vc_templates-list-default_templates vc_ui-list-bar" data-vc-action="collapseAll">';
if ( ! empty( $category['templates'] ) ) {
foreach ( $category['templates'] as $template ) {
$category['output'] .= $this->renderTemplateListItem( $template );
}
}
$category['output'] .= '
</div>
</div>';
}
}
return $category;
}
/** Output rendered template in new panel dialog
* @since 4.4
*
* @param $template_name
* @param $template_data
*
* @return string
*/
function renderTemplateWindow( $template_name, $template_data ) {
if ( 'my_templates' === $template_data['type'] ) {
return $this->renderTemplateWindowMyTemplates( $template_name, $template_data );
} else {
if ( 'default_templates' === $template_data['type'] ) {
return $this->renderTemplateWindowDefaultTemplates( $template_name, $template_data );
}
}
return $template_name;
}
/**
* @since 4.4
*
* @param $template_name
* @param $template_data
*
* @return string
*/
public function renderTemplateWindowMyTemplates( $template_name, $template_data ) {
ob_start();
$template_id = esc_attr( $template_data['unique_id'] );
$template_id_hash = md5( $template_id ); // needed for jquery target for TTA
$template_name = esc_html( $template_name );
$preview_template_title = esc_attr__( 'Preview template', 'js_composer' );
$add_template_title = esc_attr__( 'Add template', 'js_composer' );
$deleteControlRender = '';
if ( vc_user_access()->part( 'templates' )->checkStateAny( true, null )->get() ) {
$delete_template_title = esc_attr__( 'Delete template', 'js_composer' );
$deleteControlRender = <<<DATA
<button type="button" class="vc_general vc_ui-control-button" data-vc-ui-delete="template-title" title="$delete_template_title">
<i class="vc-composer-icon vc-c-icon-delete_empty"></i>
</button>
DATA;
}
echo <<<HTML
<button type="button" class="vc_ui-list-bar-item-trigger" title="$add_template_title"
data-template-handler=""
data-vc-ui-element="template-title">$template_name</button>
<div class="vc_ui-list-bar-item-actions">
<button type="button" class="vc_general vc_ui-control-button" title="$add_template_title"
data-template-handler="">
<i class="vc-composer-icon vc-c-icon-add"></i>
</button>
$deleteControlRender
<button type="button" class="vc_general vc_ui-control-button" title="$preview_template_title"
data-vc-container=".vc_ui-list-bar" data-vc-preview-handler data-vc-target="[data-template_id_hash=$template_id_hash]">
<i class="vc-composer-icon vc-c-icon-arrow_drop_down"></i>
</button>
</div>
HTML;
return ob_get_clean();
}
/**
* @since 4.4
*
* @param $template_name
* @param $template_data
*
* @return string
*/
public function renderTemplateWindowDefaultTemplates( $template_name, $template_data ) {
ob_start();
$template_id = esc_attr( $template_data['unique_id'] );
$template_id_hash = md5( $template_id ); // needed for jquery target for TTA
$template_name = esc_html( $template_name );
$preview_template_title = esc_attr__( 'Preview template', 'js_composer' );
$add_template_title = esc_attr__( 'Add template', 'js_composer' );
echo <<<HTML
<button type="button" class="vc_ui-list-bar-item-trigger" title="$add_template_title"
data-template-handler=""
data-vc-ui-element="template-title">$template_name</button>
<div class="vc_ui-list-bar-item-actions">
<button type="button" class="vc_general vc_ui-control-button" title="$add_template_title"
data-template-handler="">
<i class="vc-composer-icon vc-c-icon-add"></i>
</button>
<button type="button" class="vc_general vc_ui-control-button" title="$preview_template_title"
data-vc-container=".vc_ui-list-bar" data-vc-preview-handler data-vc-target="[data-template_id_hash=$template_id_hash]">
<i class="vc-composer-icon vc-c-icon-arrow_drop_down"></i>
</button>
</div>
HTML;
return ob_get_clean();
}
/**
* @since 4.4
* vc_filter: vc_templates_render_frontend_template - called when unknown template received to render in frontend.
*/
function renderFrontendTemplate() {
vc_user_access()->checkAdminNonce()->validateDie()->wpAny( 'edit_posts', 'edit_pages' )->validateDie()->part( 'templates' )->can()->validateDie();
add_filter( 'vc_frontend_template_the_content', array(
$this,
'frontendDoTemplatesShortcodes',
) );
$template_id = vc_post_param( 'template_unique_id' );
$template_type = vc_post_param( 'template_type' );
add_action( 'wp_print_scripts', array(
$this,
'addFrontendTemplatesShortcodesCustomCss',
) );
if ( '' === $template_id ) {
die( 'Error: Vc_Templates_Panel_Editor::renderFrontendTemplate:1' );
}
WPBMap::addAllMappedShortcodes();
if ( 'my_templates' === $template_type ) {
$saved_templates = get_option( $this->option_name );
vc_frontend_editor()->setTemplateContent( $saved_templates[ $template_id ]['template'] );
vc_frontend_editor()->enqueueRequired();
vc_include_template( 'editors/frontend_template.tpl.php', array(
'editor' => vc_frontend_editor(),
) );
die();
} else {
if ( 'default_templates' === $template_type ) {
$this->renderFrontendDefaultTemplate();
} else {
echo apply_filters( 'vc_templates_render_frontend_template', $template_id, $template_type );
}
}
die(); // no needs to do anything more. optimization.
}
/**
* Load frontend default template content by index
* @since 4.4
*/
public function renderFrontendDefaultTemplate() {
$template_index = (int) vc_post_param( 'template_unique_id' );
$data = $this->getDefaultTemplate( $template_index );
if ( ! $data ) {
die( 'Error: Vc_Templates_Panel_Editor::renderFrontendDefaultTemplate:1' );
}
vc_frontend_editor()->setTemplateContent( trim( $data['content'] ) );
vc_frontend_editor()->enqueueRequired();
vc_include_template( 'editors/frontend_template.tpl.php', array(
'editor' => vc_frontend_editor(),
) );
die();
}
/**
* @since 4.7
*/
public function renderUITemplate() {
vc_include_template( 'editors/popups/vc_ui-panel-templates.tpl.php', array(
'box' => $this,
) );
return '';
}
/**
* @since 4.4
*/
public function save() {
vc_user_access()->checkAdminNonce()->validateDie()->wpAny( 'edit_posts', 'edit_pages' )->validateDie()->part( 'templates' )->checkStateAny( true, null )->validateDie();
$template_name = vc_post_param( 'template_name' );
$template = vc_post_param( 'template' );
if ( ! isset( $template_name ) || '' === trim( $template_name ) || ! isset( $template ) || '' === trim( $template ) ) {
header( ':', true, 500 );
throw new Exception( 'Error: Vc_Templates_Panel_Editor::save:1' ); // @todo set default function for reply
}
$template_arr = array(
'name' => stripslashes( $template_name ),
'template' => stripslashes( $template ),
);
$saved_templates = get_option( $this->option_name );
$template_id = sanitize_title( $template_name ) . '_' . rand();
if ( false === $saved_templates ) {
$deprecated = '';
$autoload = 'no';
$new_template = array();
$new_template[ $template_id ] = $template_arr;
add_option( $this->option_name, $new_template, $deprecated, $autoload );
} else {
$saved_templates[ $template_id ] = $template_arr;
update_option( $this->option_name, $saved_templates );
}
$template = array(
'name' => $template_arr['name'],
'type' => 'my_templates',
'unique_id' => $template_id,
);
echo $this->renderTemplateListItem( $template );
die();
}
/**
* Loading Any templates Shortcodes for backend by string $template_id from AJAX
* @since 4.4
* vc_filter: vc_templates_render_backend_template - called when unknown template requested to render in backend
*/
public function renderBackendTemplate() {
vc_user_access()->checkAdminNonce()->validateDie()->wpAny( 'edit_posts', 'edit_pages' )->validateDie()->part( 'templates' )->can()->validateDie();
$template_id = vc_post_param( 'template_unique_id' );
$template_type = vc_post_param( 'template_type' );
if ( ! isset( $template_id, $template_type ) || '' === $template_id || '' === $template_type ) {
die( 'Error: Vc_Templates_Panel_Editor::renderBackendTemplate:1' );
}
WPBMap::addAllMappedShortcodes();
if ( 'my_templates' === $template_type ) {
$saved_templates = get_option( $this->option_name );
$content = trim( $saved_templates[ $template_id ]['template'] );
$content = str_replace( '\"', '"', $content );
$pattern = get_shortcode_regex();
$content = preg_replace_callback( "/{$pattern}/s", 'vc_convert_shortcode', $content );
echo $content;
die();
} else {
if ( 'default_templates' === $template_type ) {
$this->getBackendDefaultTemplate();
die();
} else {
echo apply_filters( 'vc_templates_render_backend_template', $template_id, $template_type );
die();
}
}
}
/**
* Render new template view as backened editor content.
*
* @since 4.8
*/
public function renderTemplatePreview() {
vc_user_access()->checkAdminNonce()->validateDie()->wpAny( array(
'edit_post',
(int) vc_request_param( 'post_id' ),
) )->validateDie()->part( 'templates' )->can()->validateDie();
$template_id = vc_request_param( 'template_unique_id' );
$template_type = vc_request_param( 'template_type' );
global $current_user;
wp_get_current_user();
if ( ! isset( $template_id, $template_type ) || '' === $template_id || '' === $template_type ) {
die( __( 'Error: wrong template id.', 'js_composer' ) );
}
WPBMap::addAllMappedShortcodes();
if ( 'my_templates' === $template_type ) {
$saved_templates = get_option( $this->option_name );
$content = trim( $saved_templates[ $template_id ]['template'] );
$content = str_replace( '\"', '"', $content );
$pattern = get_shortcode_regex();
$content = preg_replace_callback( "/{$pattern}/s", 'vc_convert_shortcode', $content );
} else {
if ( 'default_templates' === $template_type ) {
$content = $this->getBackendDefaultTemplate( true );
} else {
$content = apply_filters( 'vc_templates_render_backend_template_preview', $template_id, $template_type );
}
}
vc_include_template( apply_filters( 'vc_render_template_preview_include_template', 'editors/vc_ui-template-preview.tpl.php' ), array(
'content' => $content,
'editorPost' => get_post( vc_request_param( 'post_id' ) ),
'current_user' => $current_user,
) );
die();
}
public function registerPreviewScripts() {
visual_composer()->registerAdminJavascript();
visual_composer()->registerAdminCss();
vc_backend_editor()->registerBackendJavascript();
vc_backend_editor()->registerBackendCss();
wp_register_script( 'vc_editors-templates-preview-js', vc_asset_url( 'js/editors/templates-preview.js' ), array(
'vc-backend-min-js',
), WPB_VC_VERSION, true );
}
/**
* Enqueue required scripts for template preview
* @since 4.8
*/
public function enqueuePreviewScripts() {
vc_backend_editor()->enqueueCss();
vc_backend_editor()->enqueueJs();
wp_enqueue_script( 'vc_editors-templates-preview-js' );
}
/**
* @since 4.4
*/
public function delete() {
vc_user_access()->checkAdminNonce()->validateDie()->wpAny( 'edit_posts', 'edit_pages' )->validateDie()->part( 'templates' )->checkStateAny( true, null )->validateDie();
$template_id = vc_post_param( 'template_id' );
$template_type = vc_post_param( 'template_type' );
if ( ! isset( $template_id ) || '' === $template_id ) {
die( 'Error: Vc_Templates_Panel_Editor::delete:1' );
}
if ( 'my_templates' === $template_type ) {
$saved_templates = get_option( $this->option_name );
unset( $saved_templates[ $template_id ] );
if ( count( $saved_templates ) > 0 ) {
update_option( $this->option_name, $saved_templates );
} else {
delete_option( $this->option_name );
}
wp_send_json_success();
} else {
do_action( 'vc_templates_delete_templates', $template_id, $template_type );
}
wp_send_json_error();
}
/**
* @since 4.4
*
* @param $templates
*
* vc_filter: vc_load_default_templates_limit_total - total items to show
*
* @return array
*/
public function loadDefaultTemplatesLimit( $templates ) {
$start_index = 0;
$total_templates_to_show = apply_filters( 'vc_load_default_templates_limit_total', 6 );
return array_slice( $templates, $start_index, $total_templates_to_show );
}
/**
* Get user templates
*
* @since 4.12
* @return mixed
*/
public function getUserTemplates() {
return apply_filters( 'vc_get_user_templates', get_option( $this->option_name ) );
}
/**
* Function to get all templates for display
* - with image (optional preview image)
* - with unique_id (required for do something for rendering.. )
* - with name (required for display? )
* - with type (required for requesting data in server)
* - with category key (optional/required for filtering), if no category provided it will be displayed only in
* "All" category type vc_filter: vc_get_user_templates - hook to override "user My Templates" vc_filter:
* vc_get_all_templates - hook for override return array(all templates), hook to add/modify/remove more templates,
* - this depends only to displaying in panel window (more layouts)
* @since 4.4
* @return array - all templates with name/unique_id/category_key(optional)/image
*/
public function getAllTemplates() {
$data = array();
// Here we go..
if ( apply_filters( 'vc_show_user_templates', true ) ) {
// We need to get all "My Templates"
$user_templates = $this->getUserTemplates();
// this has only 'name' and 'template' key and index 'key' is template id.
$arr_category = array(
'category' => 'my_templates',
'category_name' => __( 'My Templates', 'js_composer' ),
'category_description' => __( 'Append previously saved template to the current layout.', 'js_composer' ),
'category_weight' => 10,
);
$category_templates = array();
if ( ! empty( $user_templates ) ) {
foreach ( $user_templates as $template_id => $template_data ) {
$category_templates[] = array(
'unique_id' => $template_id,
'name' => $template_data['name'],
'type' => 'my_templates',
// for rendering in backend/frontend with ajax
);
}
}
$arr_category['templates'] = $category_templates;
$data[] = $arr_category;
}
// To get all "Default Templates"
$default_templates = $this->getDefaultTemplates();
// this has 'name', 'image_path', 'custom_class', and 'content' as template data
if ( ! empty( $default_templates ) ) {
$arr_category = array(
'category' => 'default_templates',
'category_name' => __( 'Default Templates', 'js_composer' ),
'category_description' => __( 'Append default template to the current layout.', 'js_composer' ),
'category_weight' => 11,
);
$category_templates = array();
foreach ( $default_templates as $template_id => $template_data ) {
if ( isset( $template_data['disabled'] ) && $template_data['disabled'] ) {
continue;
}
$category_templates[] = array(
'unique_id' => $template_id,
'name' => $template_data['name'],
'type' => 'default_templates',
// for rendering in backend/frontend with ajax
'image' => isset( $template_data['image_path'] ) ? $template_data['image_path'] : false,
// preview image
'custom_class' => isset( $template_data['custom_class'] ) ? $template_data['custom_class'] : false,
);
}
if ( ! empty( $category_templates ) ) {
$arr_category['templates'] = $category_templates;
$data[] = $arr_category;
}
}
// To get any other 3rd "Custom template" - do this by hook filter 'vc_get_all_templates'
return apply_filters( 'vc_get_all_templates', $data );
}
/**
* Load default templates list and initialize variable
* To modify you should use add_filter('vc_load_default_templates','your_custom_function');
* Argument is array of templates data like:
* array(
* array(
* 'name'=>__('My custom template','my_plugin'),
* 'image_path'=> preg_replace( '/\s/', '%20', plugins_url( 'images/my_image.png', __FILE__ ) ), //
* always use preg replace to be sure that "space" will not break logic
* 'custom_class'=>'my_custom_class', // if needed
* 'content'=>'[my_shortcode]yeah[/my_shortcode]', // Use HEREDoc better to escape all single-quotes
* and double quotes
* ),
* ...
* );
* Also see filters 'vc_load_default_templates_panels' and 'vc_load_default_templates_welcome_block' to modify
* templates in panels tab and/or in welcome block. vc_filter: vc_load_default_templates - filter to override
* default templates array
* @since 4.4
* @return array
*/
public function loadDefaultTemplates() {
if ( ! $this->initialized ) {
$this->init(); // add hooks if not added already (fix for in frontend)
}
if ( ! is_array( $this->default_templates ) ) {
require_once vc_path_dir( 'CONFIG_DIR', 'templates.php' );
$templates = apply_filters( 'vc_load_default_templates', $this->default_templates );
$this->default_templates = $templates;
do_action( 'vc_load_default_templates_action' );
}
return $this->default_templates;
}
/**
* Alias for loadDefaultTemplates
* @since 4.4
* @return array - list of default templates
*/
public function getDefaultTemplates() {
return $this->loadDefaultTemplates();
}
/**
* Get default template data by template index in array.
* @since 4.4
*
* @param number $template_index
*
* @return array|bool
*/
public function getDefaultTemplate( $template_index ) {
$this->loadDefaultTemplates();
if ( ! is_numeric( $template_index ) || ! is_array( $this->default_templates ) || ! isset( $this->default_templates[ $template_index ] ) ) {
return false;
}
return $this->default_templates[ $template_index ];
}
/**
* Add custom template to default templates list ( at end of list )
* $data = array( 'name'=>'', 'image'=>'', 'content'=>'' )
* @since 4.4
*
* @param $data
*
* @return bool true if added, false if failed
*/
public function addDefaultTemplates( $data ) {
if ( is_array( $data ) && ! empty( $data ) && isset( $data['name'], $data['content'] ) ) {
if ( ! is_array( $this->default_templates ) ) {
$this->default_templates = array();
}
$this->default_templates[] = $data;
return true;
}
return false;
}
/**
* Load default template content by index from ajax
* @since 4.4
*
* @param bool $return | should function return data or not
*
* @return string
*/
public function getBackendDefaultTemplate( $return = false ) {
$template_index = (int) vc_request_param( 'template_unique_id' );
$data = $this->getDefaultTemplate( $template_index );
if ( ! $data ) {
die( 'Error: Vc_Templates_Panel_Editor::getBackendDefaultTemplate:1' );
}
if ( $return ) {
return trim( $data['content'] );
} else {
echo trim( $data['content'] );
die();
}
}
/**
* @since 4.4
*
* @param array $data
*
* @return array
*/
public function sortTemplatesByCategories( array $data ) {
$buffer = $data;
uasort( $buffer, array(
$this,
'cmpCategory',
) );
return $buffer;
}
/**
* @since 4.4
*
* @param array $data
*
* @return array
*/
public function sortTemplatesByNameWeight( array $data ) {
$buffer = $data;
uasort( $buffer, array(
$this,
'cmpNameWeight',
) );
return $buffer;
}
/**
* Function should return array of templates categories
* @since 4.4
*
* @param array $categories
*
* @return array - associative array of category key => and visible Name
*/
public function getAllCategoriesNames( array $categories ) {
$categories_names = array();
foreach ( $categories as $category ) {
if ( isset( $category['category'] ) ) {
$categories_names[ $category['category'] ] = isset( $category['category_name'] ) ? $category['category_name'] : $category['category'];
}
}
return $categories_names;
}
/**
* @since 4.4
* @return array
*/
public function getAllTemplatesSorted() {
$data = $this->getAllTemplates();
// firstly we need to sort by categories
$data = $this->sortTemplatesByCategories( $data );
// secondly we need to sort templates by their weight or name
foreach ( $data as $key => $category ) {
$data[ $key ]['templates'] = $this->sortTemplatesByNameWeight( $category['templates'] );
}
return $data;
}
/**
* Used to compare two templates by category, category_weight
* If category weight is less template will appear in first positions
* @since 4.4
*
* @param array $a - template one
* @param array $b - second template to compare
*
* @return int
*/
protected function cmpCategory( $a, $b ) {
$a_k = isset( $a['category'] ) ? $a['category'] : '*';
$b_k = isset( $b['category'] ) ? $b['category'] : '*';
$a_category_weight = isset( $a['category_weight'] ) ? $a['category_weight'] : 0;
$b_category_weight = isset( $b['category_weight'] ) ? $b['category_weight'] : 0;
return $a_category_weight == $b_category_weight ? strcmp( $a_k, $b_k ) : $a_category_weight - $b_category_weight;
}
/**
* @since 4.4
*
* @param $a
* @param $b
*
* @return int
*/
protected function cmpNameWeight( $a, $b ) {
$a_k = isset( $a['name'] ) ? $a['name'] : '*';
$b_k = isset( $b['name'] ) ? $b['name'] : '*';
$a_weight = isset( $a['weight'] ) ? $a['weight'] : 0;
$b_weight = isset( $b['weight'] ) ? $b['weight'] : 0;
return $a_weight == $b_weight ? strcmp( $a_k, $b_k ) : $a_weight - $b_weight;
}
/**
* Calls do_shortcode for templates.
*
* @param $content
*
* @return string
*/
public function frontendDoTemplatesShortcodes( $content ) {
return do_shortcode( $content );
}
/**
* Add custom css from shortcodes from template for template editor.
*
* Used by action 'wp_print_scripts'.
*
* @todo move to autoload or else some where.
* @since 4.4.3
*
*/
public function addFrontendTemplatesShortcodesCustomCss() {
$output = $shortcodes_custom_css = '';
$shortcodes_custom_css = visual_composer()->parseShortcodesCustomCss( vc_frontend_editor()->getTemplateContent() );
if ( ! empty( $shortcodes_custom_css ) ) {
$shortcodes_custom_css = strip_tags( $shortcodes_custom_css );
$output .= '<style type="text/css" data-type="vc_shortcodes-custom-css">';
$output .= $shortcodes_custom_css;
$output .= '</style>';
}
echo $output;
}
public function addScriptsToTemplatePreview() {
// wp_enqueue_script( 'vc-template-preview-script', vc_asset_url( 'js/editors/vc_ui-panel-templates-preview-be.js' ), array( 'vc-backend-min-js' ), WPB_VC_VERSION, true );
}
public function renderTemplateListItem( $template ) {
$name = isset( $template['name'] ) ? esc_html( $template['name'] ) : esc_html( __( 'No title', 'js_composer' ) );
$template_id = esc_attr( $template['unique_id'] );
$template_id_hash = md5( $template_id ); // needed for jquery target for TTA
$template_name = esc_html( $name );
$template_name_lower = esc_attr( vc_slugify( $template_name ) );
$template_type = esc_attr( isset( $template['type'] ) ? $template['type'] : 'custom' );
$custom_class = esc_attr( isset( $template['custom_class'] ) ? $template['custom_class'] : '' );
$output = <<<HTML
<div class="vc_ui-template vc_templates-template-type-$template_type $custom_class"
data-template_id="$template_id"
data-template_id_hash="$template_id_hash"
data-category="$template_type"
data-template_unique_id="$template_id"
data-template_name="$template_name_lower"
data-template_type="$template_type"
data-vc-content=".vc_ui-template-content">
<div class="vc_ui-list-bar-item">
HTML;
$output .= apply_filters( 'vc_templates_render_template', $name, $template );
$output .= <<<HTML
</div>
<div class="vc_ui-template-content" data-js-content>
</div>
</div>
HTML;
return $output;
}
public function getOptionName() {
return $this->option_name;
}
}