示例#1
0
 /**
  * Return html structure of shortcode in Page Builder area
  *
  * @param type $shortcode_name
  * @param type $attr
  * @param type $content
  */
 public static function shortcode_to_pagebuilder($shortcode_name, $content = '', $shortcode_data = '', $shortcode_params = '')
 {
     $class = WR_Pb_Helper_Shortcode::get_shortcode_class($shortcode_name);
     if (class_exists($class)) {
         global $Wr_Pb;
         $elements = $Wr_Pb->get_elements();
         $instance = isset($elements['element'][strtolower($class)]) ? $elements['element'][strtolower($class)] : null;
         if (!is_object($instance)) {
             $instance = new $class();
         }
         $instance->init_element();
         $el_title = '';
         if ($class != 'WR_Widget') {
             // extract param of shortcode ( now for column )
             if (isset($instance->config['extract_param'])) {
                 parse_str(trim($shortcode_params), $output);
                 foreach ($instance->config['extract_param'] as $param) {
                     if (isset($output[$param])) {
                         $instance->params[$param] = WR_Pb_Utils_Common::remove_quotes($output[$param]);
                     }
                 }
             }
             // get content in pagebuilder of shortcode: Element Title must always first option of Content tab
             if (isset($instance->items['content']) && isset($instance->items['content'][0])) {
                 $title = $instance->items['content'][0];
                 if ($title['role'] == 'title') {
                     $params = shortcode_parse_atts($shortcode_params);
                     $el_title = !empty($params[$title['id']]) ? $params[$title['id']] : __('(Untitled)', WR_PBL);
                 }
             }
         } else {
             $widget_info = WR_Pb_Helper_Shortcode::extract_widget_params($shortcode_data);
             $el_title = !empty($widget_info['title']) ? $widget_info['title'] : '';
             $params = WR_Pb_Helper_Shortcode::extract_params($shortcode_data);
             $instance->config['shortcode'] = $params['widget_id'];
             $instance->config['el_type'] = 'widget';
         }
         $shortcode_view = $instance->element_in_pgbldr($content, $shortcode_data, $el_title);
         return $shortcode_view[0];
     }
 }
示例#2
0
 /**
  * Generate Setting HTML for each shortcode
  *
  * @global object $Wr_Pb
  * @param string $shortcode The current shortcode
  * @param array $params The shortcode content
  * @param string $el_title Title of shortcode
  * @param bool $no_tab
  *
  * @return string
  */
 public static function shortcode_modal_settings($shortcode, $params, $el_title = '', $no_tab = false)
 {
     $html = '';
     // get shortcode class
     $class = WR_Pb_Helper_Shortcode::get_shortcode_class($shortcode);
     if (class_exists($class)) {
         global $Wr_Pb;
         $settings_html = '';
         $elements = $Wr_Pb->get_elements();
         $instance = isset($elements['element'][strtolower($class)]) ? $elements['element'][strtolower($class)] : null;
         if (!is_object($instance)) {
             $instance = new $class();
         }
         $instance->init_element();
         $has_preview = false;
         // Generate default params if they were not posted.
         if (empty($params)) {
             $params = $instance->config['shortcode_structure'];
         }
         if (!empty($params)) {
             $params = str_replace('#_EDITTED', '', $params);
             $extract_params = WR_Pb_Helper_Shortcode::extract_params($params, $shortcode);
             // if have sub-shortcode, extract sub shortcodes content
             if (!empty($instance->config['has_subshortcode'])) {
                 $sub_sc_data = WR_Pb_Helper_Shortcode::extract_sub_shortcode($params, true);
                 $sub_sc_data = apply_filters('wr_pb_sub_items_filter', $sub_sc_data, $shortcode, isset($_COOKIE['wr_pb_data_for_modal']) ? $_COOKIE['wr_pb_data_for_modal'] : '');
                 $extract_params['sub_items_content'] = $sub_sc_data;
             }
             // Set auto title for the subitem if have
             $extract_title = isset($el_title) && $el_title != __('(Untitled)', WR_PBL) ? $el_title : '';
             // MODIFY $instance->items
             WR_Pb_Helper_Shortcode::generate_shortcode_params($instance->items, NULL, $extract_params, TRUE, FALSE, $extract_title, $has_preview);
             // if have sub-shortcode, re-generate shortcode structure
             if (!empty($instance->config['has_subshortcode'])) {
                 $instance->shortcode_data();
             }
         }
         // get Modal setting box
         $settings = $instance->items;
         $settings_html .= WR_Pb_Objects_Modal::get_shortcode_modal_settings($settings, $shortcode, $extract_params, $params, $has_preview, $no_tab);
         // Add preview
         if ($has_preview) {
             $settings_html .= WR_Pb_Helper_Shortcode::render_parameter('preview');
         }
         $html = balanceTags($settings_html);
     }
     return $html;
 }
示例#3
0
 /**
  * Get shortcode structure with default attributes
  * eg: [wr_text title="The text"]Lorem ipsum[/wr_text]
  * Enter description here ...
  */
 function get_default_shortcode_structure()
 {
     if (!isset($_POST[WR_NONCE]) || !wp_verify_nonce($_POST[WR_NONCE], WR_NONCE)) {
         return;
     }
     if (!$_POST['shortcode']) {
         return;
     }
     $shortcode = $_POST['shortcode'];
     $class = WR_Pb_Helper_Shortcode::get_shortcode_class($shortcode);
     if (class_exists($class)) {
         $element = new $class();
         if (method_exists($element, 'init_element')) {
             $element->init_element();
         }
         $shortcode_structure = isset($element->config['shortcode_structure']) ? $element->config['shortcode_structure'] : '';
         if (strpos($shortcode, 'wr_item') === false) {
             // Replace _WR_INDEX_ with index string when call generate shortcode first.
             $this->index_shortcode_item = 1;
             $shortcode_structure = preg_replace_callback('/_WR_INDEX_/', array(&$this, 'replace_index_count'), $shortcode_structure);
         }
         echo $shortcode_structure;
     }
     exit;
 }