/** * Return the builder settings array that will be used by the builder client script * * @return array The settings */ public function get_builder_settings() { $prefix = Youxi_Shortcode::prefix(); /* Get container shortcodes */ $container_shortcodes = Youxi_Shortcode::get_container_shortcodes(); /* Get row shortcodes */ $row_shortcode = Youxi_Shortcode::get_row_shortcode(); /* Get separator shortcodes */ $separator_shortcodes = Youxi_Shortcode::get_separator_shortcodes(); /* Determine if we're using simple columns */ $simple_columns = Youxi_Shortcode::use_simple_columns(); /* Determine if container is enabled */ $container_enabled = apply_filters('youxi_builder_enable_container', true); /* If any of the container shortcode doesn't exists, disable the container mode */ foreach ($container_shortcodes as $shortcode) { if (!Youxi_Shortcode_Manager::get()->shortcode_exists($shortcode)) { $container_enabled = false; } } /* Define column shortcodes */ $column_sizes = Youxi_Shortcode::get_column_sizes(); // Create size and tags array if ($simple_columns) { $column_props = Youxi_Shortcode::get_simple_columns(); $column_shortcodes = array_intersect_key($column_props, array_combine($column_sizes, $column_sizes)); $column_shortcodes = array_values($column_shortcodes); } else { $tag = Youxi_Shortcode::get_column_shortcode(); $column_shortcodes = array(); foreach ($column_sizes as $size) { $column_shortcodes[] = compact('size', 'tag'); } } $column_tags = array_unique(wp_list_pluck($column_shortcodes, 'tag')); /* Helper variables */ $non_column_or_widget_shortcodes = array_merge($container_shortcodes, (array) $row_shortcode); $non_widget_shortcodes = array_merge($non_column_or_widget_shortcodes, $column_tags); $rows_and_separators = array_merge((array) $row_shortcode, $separator_shortcodes); /* Define the builder rules */ $rules = array(); $rules[$row_shortcode] = array('accept' => $column_tags, 'reject' => $non_column_or_widget_shortcodes); foreach ($column_tags as $tag) { $rules[$tag] = array('accept' => '*', 'reject' => $non_widget_shortcodes); } /* Adjust rules based on enable_container state */ if ($container_enabled) { $rules = array_merge(array('root' => array('accept' => $container_shortcodes), 'container' => array('accept' => $rows_and_separators, 'reject' => $container_shortcodes), 'fullwidth' => array('accept' => '*', 'reject' => $non_widget_shortcodes)), $rules); } else { $rules = array_merge(array('root' => array('accept' => $rows_and_separators, 'reject' => $container_shortcodes)), $rules); } /* Compact all in one setting array */ $settings = array('parseMethod' => apply_filters('youxi_builder_parse_method', 'js'), 'simpleColumns' => $simple_columns, 'enableContainer' => $container_enabled, 'containerShortcodes' => $container_shortcodes, 'columnContainerShortcode' => Youxi_Shortcode::get_column_container_shortcode(), 'rowShortcode' => $row_shortcode, 'rowSize' => Youxi_Shortcode::get_column_count(), 'columnShortcodes' => $column_shortcodes, 'rules' => $rules, 'uiIcons' => apply_filters('youxi_builder_ui_icons', array('resizeLeft' => array('icon' => 'dashicons dashicons-arrow-left', 'title' => __('Decrease Size', 'youxi')), 'resizeRight' => array('icon' => 'dashicons dashicons-arrow-right', 'title' => __('Increase Size', 'youxi')), 'remove' => array('icon' => 'dashicons dashicons-trash', 'title' => __('Remove', 'youxi')), 'edit' => array('icon' => 'dashicons dashicons-edit', 'title' => __('Edit', 'youxi')), 'copy' => array('icon' => 'dashicons dashicons-admin-page', 'title' => __('Copy', 'youxi'))))); /* The builder languages strings */ $l10n = array('invalidColumnSize' => __('The specified column size is invalid.', 'youxi'), 'invalidRowSlotsSize' => __('The specified row slots size is invalid.', 'youxi'), 'notEnoughColumnSlots' => __('The containing row does not have enough slots.', 'youxi'), 'confirmRemoveContainer' => __('Are you sure you want to remove this container?', 'youxi'), 'confirmRemoveRow' => __('Are you sure you want to remove this row?', 'youxi'), 'confirmRemoveColumn' => __('Are you sure you want to remove this column?', 'youxi'), 'confirmRemoveWidget' => __('Are you sure you want to remove this widget?', 'youxi'), 'columnTitlePrefix' => __('Column ', 'youxi')); return array_merge($l10n, compact('settings')); }
/** * Register but do not enqueue the default needed scripts for shortcodes. * Other plugins/themes can pass configuration variables through the youxi_shortcode_js_vars filter */ public function admin_enqueue_scripts($hook) { $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; /* Register serialize JSON script as it's needed by the shortcode helper */ wp_register_script('serialize-json', YOUXI_SHORTCODE_URL . "admin/assets/plugins/serializejson/jquery.serializejson{$suffix}.js", array('jquery'), '1.2.3', true); wp_register_script('youxi-shortcode-editor', YOUXI_SHORTCODE_URL . "admin/assets/js/youxi.shortcode.editor{$suffix}.js", array('media-views', 'serialize-json'), YOUXI_SHORTCODE_VERSION, true); /* Register shortcode admin helper */ wp_register_script('youxi-shortcode', YOUXI_SHORTCODE_URL . "admin/assets/js/youxi.shortcode{$suffix}.js", array('youxi-shortcode-editor', 'youxi-form-manager', 'underscore'), YOUXI_SHORTCODE_VERSION, true); /* Register shortcode admin styles */ wp_register_style('youxi-shortcode', YOUXI_SHORTCODE_URL . "admin/assets/css/youxi.shortcode{$suffix}.css", array('youxi-form', 'media-views'), YOUXI_SHORTCODE_VERSION, 'screen'); /* Attach setting variables to the script */ wp_localize_script('youxi-shortcode', 'youxiShortcodeSettings', apply_filters('youxi_shortcode_js_vars', array('args' => $this->get_shortcode_args(), 'prefix' => Youxi_Shortcode::prefix()))); /* Enqueue all admin assets and print media templates if allowed */ if (apply_filters('youxi_shortcode_admin_enqueue_scripts', false)) { foreach ($this->shortcodes as $shortcode) { $shortcode->admin_enqueue_scripts($hook); } add_action('print_media_templates', array($this, 'print_media_templates')); do_action('youxi_shortcode_admin_enqueue', $hook); } }
/** * Tabs Shortcode Handler */ function youxi_shortcode_tabs_cb($atts, $content, $tag) { $o = ''; $tabs = Youxi_Shortcode::to_array($content, true); if (is_array($tabs) && !empty($tabs)) { /* Reset the tab_content index */ Youxi_Shortcode::reset_counter('tab'); $o .= '<ul class="nav nav-' . esc_attr($atts['type']) . '">'; foreach ($tabs as $index => $tab) { if (isset($tab['tag'], $tab['atts']) && Youxi_Shortcode::prefix('tab') == $tab['tag']) { extract($tab['atts']); $tab_id = sanitize_key($title . Youxi_Shortcode::read_counter($tag) . $index); $o .= '<li' . ($index == 0 ? ' class="active"' : '') . '>'; $o .= '<a href="#' . esc_attr($tab_id) . '" data-toggle="tab">'; $o .= $title; $o .= '</a>'; $o .= '</li>'; } } $o .= '</ul>'; $o .= '<div class="tab-content">'; $o .= do_shortcode($content); $o .= '</div>'; } return $o; }