/** * Group items * * @param type $element * * @return string */ static function render($element) { $_element = $element; $label_item = isset($element['label_item']) ? $element['label_item'] : ''; $sub_items = $_element['sub_items']; $overwrite_shortcode_data = isset($element['overwrite_shortcode_data']) ? $element['overwrite_shortcode_data'] : true; $sub_item_type = $element['sub_item_type']; $items_html = array(); $shortcode_name = str_replace('WR_', '', $element['shortcode']); // get id of parameter to extract $extract_title = isset($element['extract_title']) ? $element['extract_title'] : ''; $extra_params = array('drag_handle' => false); if ($sub_items) { foreach ($sub_items as $idx => $item) { $el = new $sub_item_type(); $el->init_element(); // check if $item['std'] is empty or not $shortcode_data = ''; if (!$label_item) { $content = __($shortcode_name, WR_PBL) . ' ' . __('Item', WR_PBL) . ' ' . ($idx + 1); } else { $content = $label_item . ($idx + 1); } if (isset($_element['no_title'])) { $content = $_element['no_title']; } if (!empty($item['std'])) { // keep shortcode data as it is $shortcode_data = $item['std']; // reassign params for shortcode base on std string $extract_params = WR_Pb_Helper_Shortcode::extract_params($item['std']); $params = WR_Pb_Helper_Shortcode::generate_shortcode_params($el->items, NULL, $extract_params, TRUE, FALSE, $content); $el->shortcode_data(); $params['extract_title'] = empty($params['extract_title']) ? __('(Untitled)', WR_PBL) : $params['extract_title']; $content = $params['extract_title']; if ($overwrite_shortcode_data) { $shortcode_data = $el->config['shortcode_structure']; } } $element_type = (array) $el->element_in_pgbldr($content, $shortcode_data, '', '', true, $extra_params); foreach ($element_type as $element_structure) { $items_html[$shortcode_data] = $element_structure; } } } $style = isset($_element['style']) ? 'style="' . $_element['style'] . '"' : ''; // Wrap item html to table $html = ''; foreach ($items_html as $shortcode_data => $item_html) { if (!empty($extract_title)) { $attrs = shortcode_parse_atts($shortcode_data); $title = isset($attrs[$extract_title]) ? $attrs[$extract_title] : ''; $html .= sprintf('<tr><td><b>%s</b></td><td>%s</td></tr>', $title, $item_html); } } $html = sprintf('<table class="%s" %s>%s</table>', 'table table-bordered', $style, balanceTags($html)); $element_name = isset($_element['name']) ? $_element['name'] : __(ucwords(!$label_item ? $shortcode_name : $label_item), WR_PBL) . ' ' . __('Items', WR_PBL); $html_element = "<div id='{$_element['id']}' class='form-group control-group clearfix'><label class='control-label'>{$element_name}</label>\n\t\t\t\t<div class='item-container submodal_frame_2 controls group-table {$_element['class']}'>\n <div class='item-container-content jsn-items-list'>\n {$html}\n </div>\n </div>\n </div>"; return $html_element; }
/** * Group items * * @param type $element * * @return string */ static function render($element) { $_element = $element; $add_item = isset($element['add_item_text']) ? $element['add_item_text'] : __('Add Item', WR_PBL); $sub_items = $_element['sub_items']; $overwrite_shortcode_data = isset($element['overwrite_shortcode_data']) ? $element['overwrite_shortcode_data'] : true; $sub_item_type = $element['sub_item_type']; $items_html = array(); $shortcode_name = str_replace('WR_', '', $element['shortcode']); if ($sub_items) { foreach ($sub_items as $idx => $item) { $element = new $sub_item_type(); $element->init_element(); $label_item = isset($element->config['exception']['item_text']) ? $element->config['exception']['item_text'] : ''; // check if $item['std'] is empty or not $shortcode_data = ''; if (!$label_item) { $content = __($shortcode_name, WR_PBL) . ' ' . __('Item', WR_PBL) . ' ' . ($idx + 1); } else { $content = rtrim($label_item) . ' ' . ($idx + 1); } if (isset($_element['no_title'])) { $content = $_element['no_title']; } if (!empty($item['std'])) { // keep shortcode data as it is $shortcode_data = $item['std']; // reassign params for shortcode base on std string $extract_params = WR_Pb_Helper_Shortcode::extract_params($item['std']); $params = WR_Pb_Helper_Shortcode::generate_shortcode_params($element->items, NULL, $extract_params, TRUE, FALSE, $content); $element->shortcode_data(); $params['extract_title'] = empty($params['extract_title']) ? __('(Untitled)', WR_PBL) : $params['extract_title']; $content = $params['extract_title']; if ($overwrite_shortcode_data) { $shortcode_data = $element->config['shortcode_structure']; } } $element_type = (array) $element->element_in_pgbldr($content, $shortcode_data, '', $idx + 1); foreach ($element_type as $element_structure) { $items_html[] = $element_structure; } } } $style = isset($_element['style']) ? 'style="' . $_element['style'] . '"' : ''; $items_html = implode('', $items_html); $element_name = isset($_element['name']) ? $_element['name'] : __(ucwords(!$label_item ? $shortcode_name : $label_item), WR_PBL); $element_name = str_replace('Item', '', $element_name) . ' ' . __('Items', WR_PBL); $group_heading = WR_Pb_Helper_Html_Fieldset::render(array('name' => $element_name, 'id' => '', 'type' => 'fieldset')); $html_element = "<div id='{$_element['id']}' class='form-group control-group clearfix'>{$group_heading}\n\t\t\t\t<div class='item-container has_submodal controls'>\n\t\t\t\t\t<ul {$style} class='ui-sortable jsn-items-list item-container-content jsn-rounded-medium' id='group_elements'>\n\t\t\t\t\t{$items_html}\n\t\t\t\t\t</ul>\n\t\t\t\t\t<a href='javascript:void(0);' class='jsn-add-more wr-more-element in-modal' item_common_title='" . __($shortcode_name, WR_PBL) . ' ' . __('Item', WR_PBL) . "' data-shortcode-item='" . strtolower($sub_item_type) . "'><i class='icon-plus'></i>" . __($add_item, WR_PBL) . '</a> </div></div>'; return $html_element; }
/** * get params & structure of shortcode * OVERWRIGE parent function */ public function shortcode_data() { $params = WR_Pb_Helper_Shortcode::generate_shortcode_params($this->items); $this->config['params'] = array_merge(array('div_margin_top' => '', 'div_margin_bottom' => '', 'disabled_el' => 'no', 'css_suffix' => ''), $params); // get content of sub-shortcode $sub_items_content = array(); $sub_items = isset($this->config['params']['sub_items_content']) ? $this->config['params']['sub_items_content'] : array(); foreach ($sub_items as $sub_item_type => &$sub_shortcodes) { foreach ($sub_shortcodes as $sub_shortcode) { $sub_sc = new $sub_item_type(); $sub_sc->init_element(); // empty std if (empty($sub_shortcode['std'])) { // only empty 'std' if (count($sub_shortcode) == 1) { // get default shortcode structure of sub-shortcode $sub_sc->config['params'] = WR_Pb_Helper_Shortcode::generate_shortcode_params($sub_sc->items, null, null, false, true); // re-generate shortcode structure $sub_shortcode['std'] = WR_Pb_Helper_Shortcode::generate_shortcode_structure($sub_sc->config['shortcode'], $sub_sc->config['params']); } else { // MODIFY $instance->items WR_Pb_Helper_Shortcode::generate_shortcode_params($sub_sc->items, NULL, $sub_shortcode, TRUE); // re-generate shortcode structure $sub_sc->shortcode_data(); // get updated std of sub-shortcode $sub_shortcode['std'] = $sub_sc->config['shortcode_structure']; } } else { // if std of sub-shortcode is predefined ( such as GoogleMap ) $params = stripslashes($sub_shortcode['std']); $extract_params = WR_Pb_Helper_Shortcode::extract_params(urldecode($params)); // MODIFY $instance->items WR_Pb_Helper_Shortcode::generate_shortcode_params($sub_sc->items, NULL, $extract_params, TRUE); // re-generate shortcode structure $sub_sc->shortcode_data(); } $sub_items_content[] = $sub_shortcode['std']; } } $sub_items_content = implode('', $sub_items_content); // END get content of sub-shortcode $this->config['shortcode_structure'] = WR_Pb_Helper_Shortcode::generate_shortcode_structure($this->config['shortcode'], $this->config['params'], $sub_items_content); }
/** * 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; }
/** * generate HTML in WR PageBuilder for Table type * @param sub_item_type $element * @return type */ static function render($element) { $label = parent::get_label($element); $sub_items = $element['sub_items']; $sub_item_type = $element['sub_item_type']; $items_html = array(); $sample_table_item = ''; // Get HTML of Each Cell $shortcode_data_arr = array(); // Add extra params to disable drag handle $extra_params = array('drag_handle' => false); foreach ($sub_items as $idx => $item) { $element_ = new $sub_item_type(); $element_->init_element(); $shortcode_data = ''; $content = ' '; // don't leave it empty if (!empty($item['std'])) { // keep shortcode data as it is $shortcode_data = $item['std']; // reassign params for shortcode base on std string $extract_params = WR_Pb_Helper_Shortcode::extract_params($item['std']); $params = WR_Pb_Helper_Shortcode::generate_shortcode_params($element_->items, NULL, $extract_params, TRUE, FALSE, $content); $element_->shortcode_data(); if (!empty($params['extract_title'])) { $content = $params['extract_title']; $shortcode_data = $element_->config['shortcode_structure']; } $shortcode_data_arr[$idx] = $shortcode_data; } $element_type = $element_->element_in_pgbldr($content, $shortcode_data, '', '', true, $extra_params); // Create sample table item data if (!$sample_table_item) { $sample_table_item = $element_->element_in_pgbldr(null, null, '', '', true, $extra_params); } foreach ($element_type as $element_structure) { $items_html[] = $element_structure; } } // Wrap cell to a Table to display in WR PageBuilder $row = 0; $updated_html = array(); $columns_count = array(); foreach ($items_html as $idx => $cell) { if (!isset($columns_count[$row])) { $columns_count[$row] = 0; } else { $columns_count[$row]++; } $cell_html = ''; $cell_wrap = $row == 0 ? 'th' : 'td'; if (strpos($cell, "[wr_item_table tagname='tr_start' ][/wr_item_table]") !== false) { $cell_html .= '<tr>'; } else { if (strpos($cell, "[wr_item_table tagname='tr_end' ][/wr_item_table]") !== false) { // Delete button on right side of table $action_html = $row == 0 ? '' : "<a href='#' title='" . __('Delete', WR_PBL) . "' onclick='return false;' data-target='row_table' class='element-delete'><i class='icon-trash'></i></a>"; $cell_html .= "<{$cell_wrap} valign='middle' class='wr-delete-column-td'><div class='jsn-iconbar'>{$action_html}</div></{$cell_wrap}>"; $cell_html .= '</tr>'; $row++; } else { extract(shortcode_parse_atts($shortcode_data_arr[$idx])); $width = !empty($width_value) ? "width='{$width_value}{$width_type}'" : ''; $cell_html .= "<{$cell_wrap} rowspan='{$rowspan}' colspan='{$colspan}' {$width}>{$cell}</{$cell_wrap}>"; } } $updated_html[] = $cell_html; } // Delete button below the table $bottom_row = "<tr class='wr-row-of-delete'>"; for ($i = 0; $i < max($columns_count) - 1; $i++) { $bottom_row .= "<td><div class='jsn-iconbar'><a href='#' title='" . __('Delete', WR_PBL) . "' onclick='return false;' data-target='column_table' class='element-delete'><i class='icon-trash'></i></a></div></td>"; } $bottom_row .= '</tr>'; $updated_html[] = $bottom_row; $items_html = "<table class='table table-bordered igpb-table-exceprt' id='table_content'>" . implode('', $updated_html) . '</table>'; // end Wrap $buttons = '<button class="btn btn-default table_action" data-target="table_row">' . __('Add Row', WR_PBL) . '</button> <button class="btn btn-default table_action" data-target="table_column">' . __('Add Column', WR_PBL) . '</button>'; $output = "<div class='item-container has_submodal table_element'>\n\t\t\t\t\t\t<div class='jsn-fieldset-filter'><div class='btn-toolbar clearafter'>{$buttons}</div></div>\n\t\t\t\t\t\t<div class='ui-sortable item-container-content'>\n\t\t\t\t\t\t{$items_html}\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>"; $sample_tmpl_id = strtolower($sub_item_type); $output .= isset($sample_table_item[0]) ? "<script id='tmpl-" . $sample_tmpl_id . "-sample' type='text/html'>" . $sample_table_item[0] . "</script>" : ''; return parent::final_element($element, $output, $label); }
/** * Replace widget shortcode by Widget output * * @param type $widget_shortcode * * @return type */ public static function widget_content($widget_shortcode) { $widget_contents = urldecode($widget_shortcode[0]); // get widget class $element = WR_Pb_Helper_Shortcode::extract_params($widget_contents); if (empty($element['widget_id'])) { return ''; } $widget = $element['widget_id']; // get widget settings parameters $instance = WR_Pb_Helper_Shortcode::extract_widget_params($widget_contents); $args = array('widget_id' => strtolower($widget)); // fix problem of woocommerce global $woocommerce; if (isset($woocommerce) && empty($woocommerce->query)) { $woocommerce->query = new WC_Query(); } // init the widget $w = new $widget(); $sidebars_widgets = wp_get_sidebars_widgets(); // Set a dummy sidebar $sidebars_widgets['dummy_wrpb_sidebar'][] = $w->id_base; wp_set_sidebars_widgets($sidebars_widgets); // ouput ob_start(); the_widget($widget, $instance, $args); $widget_content = ob_get_clean(); return $widget_content; }
/** * Merge new style params to existed shortcode content * * @return type */ function merge_style_params() { if (!isset($_POST[WR_NONCE]) || !wp_verify_nonce($_POST[WR_NONCE], WR_NONCE)) { return; } $shortcode_name = $_POST['shortcode_name']; $structure = str_replace("\\", "", $_POST['content']); $alter_structure = str_replace("\\", "", $_POST['new_style_content']); // Extract params of current element $params = WR_Pb_Helper_Shortcode::extract_params($structure, $shortcode_name); // Extract styling params of copied element $alter_params = WR_Pb_Helper_Shortcode::get_styling_atts($shortcode_name, $alter_structure); // Alter params of current element by copied element's params if (count($alter_params)) { foreach ($alter_params as $k => $v) { $params[$k] = $v; } } $_shortcode_content = ''; // Exclude shortcode_content from param list if (isset($params['_shortcode_content'])) { $_shortcode_content = $params['_shortcode_content']; unset($params['_shortcode_content']); } $new_shortcode_structure = WR_Pb_Helper_Shortcode::join_params($params, $shortcode_name, $_shortcode_content); // Print out new shortcode structure. echo $new_shortcode_structure; exit; }
/** * Generate HTML code from shortcode content. * * @param array $atts Shortcode attributes. * @param string $content Current content. * * @return string */ public function element_shortcode_full($atts = null, $content = null) { $html_element = ''; $arr_sub_shortcodes = self::sync_sub_content($content); $arr_params = shortcode_atts($this->config['params'], $atts); extract($arr_params); $arr_elements = explode('__#__', $prtbl_elements); // Build html for cols label. $pr_tbl_label_html = '<div class="wr-prtbl-cols first">'; // Append blank header $header_ = '<div class="wr-prtbl-title">'; if (in_array('image', $arr_elements)) { $header_ .= '<div class="wr-prtbl-image"></div>'; } $header_ .= '<h3> </h3></div>'; if (in_array('price', $arr_elements) || in_array('description', $arr_elements)) { $header_ .= '<div class="wr-prtbl-meta">'; // append blank price if (in_array('price', $arr_elements)) { $header_ .= '<div class="wr-prtbl-price"> </div>'; } // append blank price if (in_array('description', $arr_elements)) { $header_ .= '<p class="wr-prtbl-desc"> </p>'; } $header_ .= '</div>'; } // Process deactive pricing table item attribute set_transient('pricingtable_attrs', ''); $pattern = '\\[(\\[?)(wr_item_pricing_table_attr)(?![\\w-])([^\\]\\/]*(?:\\/(?!\\])[^\\]\\/]*)*?)(?:(\\/)\\]|\\](?:([^\\[]*+(?:\\[(?!\\/\\2\\])[^\\[]*+)*+)\\[\\/\\2\\])?)(\\]?)'; preg_match_all("/{$pattern}/s", $arr_sub_shortcodes['wr_item_pricing_table_attr'], $matches); $arr_prtbl_atts = $matches[0]; $arr_disable_el = array(); foreach ($arr_prtbl_atts as $i => $att) { if (!empty($att)) { $att_extract_params = WR_Pb_Helper_Shortcode::extract_params($att); if (isset($att_extract_params['disabled_el']) && $att_extract_params['disabled_el'] == 'yes' && isset($att_extract_params['prtbl_item_attr_id'])) { $arr_disable_el[] = $att_extract_params['prtbl_item_attr_id']; } } } set_transient('pricingtable_attrs', json_encode($arr_disable_el)); $pr_tbl_label_html .= sprintf('<div class="wr-prtbl-header">%s</div>', balanceTags($header_)); if (isset($arr_sub_shortcodes['wr_item_pricing_table_attr']) && !empty($arr_sub_shortcodes['wr_item_pricing_table_attr'])) { $pr_tbl_label_html .= '<ul class="wr-prtbl-features">'; $pr_tbl_label_html .= do_shortcode($arr_sub_shortcodes['wr_item_pricing_table_attr']); $pr_tbl_label_html .= '</ul>'; } $pr_tbl_label_html .= '<div class="wr-prtbl-footer"></div>'; $pr_tbl_label_html .= '</div>'; // Build html for cols value. $pr_tbl_col_value_html = ''; if (isset($arr_sub_shortcodes['wr_item_pricing_table']) && !empty($arr_sub_shortcodes['wr_item_pricing_table'])) { $pr_tbl_col_value_html = do_shortcode(implode('', $arr_sub_shortcodes['wr_item_pricing_table'])); $pr_tbl_col_value_html = $this->check_field_allow('title', 'prtbl_item_title', $arr_elements, $pr_tbl_col_value_html); $pr_tbl_col_value_html = $this->check_field_allow('description', 'prtbl_item_desc', $arr_elements, $pr_tbl_col_value_html); $pr_tbl_col_value_html = $this->check_field_allow('image', 'prtbl_item_image', $arr_elements, $pr_tbl_col_value_html); $pr_tbl_col_value_html = $this->check_field_allow('button', 'prtbl_item_button', $arr_elements, $pr_tbl_col_value_html); $pr_tbl_col_value_html = $this->check_field_allow('price', 'prtbl_item_price', $arr_elements, $pr_tbl_col_value_html); if (!in_array('price', $arr_elements) && !in_array('description', $arr_elements)) { $pattern = '\\[(\\[?)(prtbl_item_meta)(?![\\w-])([^\\]\\/]*(?:\\/(?!\\])[^\\]\\/]*)*?)(?:(\\/)\\]|\\](?:([^\\[]*+(?:\\[(?!\\/\\2\\])[^\\[]*+)*+)\\[\\/\\2\\])?)(\\]?)'; $pr_tbl_col_value_html = preg_replace("/{$pattern}/s", '', $pr_tbl_col_value_html); } else { $pr_tbl_col_value_html = str_replace("[prtbl_item_meta]", '', $pr_tbl_col_value_html); $pr_tbl_col_value_html = str_replace("[/prtbl_item_meta]", '', $pr_tbl_col_value_html); } } $count_columns = isset($arr_sub_shortcodes['wr_item_pricing_table']) ? count($arr_sub_shortcodes['wr_item_pricing_table']) + 1 : 1; $html_element = $pr_tbl_label_html . $pr_tbl_col_value_html; return $this->element_wrapper($html_element, $arr_params, "table-{$count_columns}-col"); }