Пример #1
0
 /**
  * Public method to get the singleton instance
  *
  * @return Youxi_Shortcode_Manager
  */
 public static function get()
 {
     if (!self::$instance) {
         self::$instance = new Youxi_Shortcode_Manager();
     }
     return self::$instance;
 }
Пример #2
0
/**
 * Lead Text Shortcode Handler
 */
function youxi_shortcode_lead_text_cb($atts, $content, $tag)
{
    /* Remove all <p> tags first */
    $content = preg_replace('#</?p[^>]*>#', '', $content);
    /* Fix shortcodes */
    $content = Youxi_Shortcode_Manager::get()->shortcode_unautop($content);
    /* do_shortcode */
    $content = do_shortcode($content);
    /* apply wpautop */
    return wpautop('<p class="lead">' . $content . '</p>');
}
Пример #3
0
 /**
  * Convert shortcodes string to an array recursively
  * 
  * @param string The shortcodes string
  *
  * @return array The shortcodes converted into an array
  */
 public static function to_array($content, $parse_defaults = false)
 {
     $result = array();
     preg_match_all('/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER);
     foreach ($matches as $m) {
         // If we matched an escaped shortcode
         if ($m[1] == '[' && $m[6] == ']') {
             continue;
         }
         /* Parse attributes */
         $atts = shortcode_parse_atts($m[3]);
         $content = isset($m[5]) ? $m[5] : null;
         $tag = $m[2];
         /* Parse default attributes */
         if ($parse_defaults) {
             $object = Youxi_Shortcode_Manager::get()->get_shortcode($tag);
             if (is_a($object, 'Youxi_Shortcode')) {
                 $atts = shortcode_atts($object->get_default_atts(), $atts, $tag);
             }
         }
         /* Parse content */
         if (!is_null($content)) {
             $shortcode = Youxi_Shortcode_Manager::get()->get_shortcode($tag);
             if (is_a($shortcode, 'Youxi_Shortcode') && $shortcode->get_args('escape', true)) {
                 $content = trim($content);
             } else {
                 $content = self::to_array($content, $parse_defaults);
             }
         }
         /* Save the shortcode objects */
         $result[] = compact('atts', 'content', 'tag');
     }
     return empty($result) ? trim($content) : $result;
 }
Пример #4
0
 /**
  * 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'));
 }
Пример #5
0
/**
 * Text Widget Shortcode Handler
 */
function youxi_shortcode_text_widget_cb($atts, $content, $tag)
{
    return do_shortcode(Youxi_Shortcode_Manager::get()->shortcode_unautop(wpautop($content)));
}
Пример #6
0
function youxi_shortcode_plugins_loaded()
{
    if (!defined('YOUXI_CORE_VERSION')) {
        if (!class_exists('Youxi_Admin_Notice')) {
            require plugin_dir_path(__FILE__) . 'class-admin-notice.php';
        }
        Youxi_Admin_Notice::instance()->add_error(__FILE__, __('This plugin requires you to install and activate the Youxi Core plugin.', 'youxi'));
        return;
    }
    define('YOUXI_SHORTCODE_VERSION', '3.2');
    define('YOUXI_SHORTCODE_DIR', plugin_dir_path(__FILE__));
    define('YOUXI_SHORTCODE_URL', plugin_dir_url(__FILE__));
    define('YOUXI_SHORTCODE_LANG_DIR', dirname(plugin_basename(__FILE__)) . '/languages/');
    /* Load Language File */
    load_plugin_textdomain('youxi', false, YOUXI_SHORTCODE_LANG_DIR);
    /* Include the default shortcodes */
    require_once YOUXI_SHORTCODE_DIR . 'definitions/layout.php';
    require_once YOUXI_SHORTCODE_DIR . 'definitions/content.php';
    require_once YOUXI_SHORTCODE_DIR . 'definitions/statistic.php';
    require_once YOUXI_SHORTCODE_DIR . 'definitions/media.php';
    require_once YOUXI_SHORTCODE_DIR . 'definitions/uncategorized.php';
    /* Instantiate the manager */
    if (!class_exists('Youxi_Shortcode_Manager')) {
        require YOUXI_SHORTCODE_DIR . 'classes/class-manager.php';
    }
    Youxi_Shortcode_Manager::get();
}