/** * DEFINE html structure of shortcode in Page Builder area * * @param string $content * @param string $shortcode_data: string stores params (which is modified default value) of shortcode * @param string $el_title: Element Title used to identifying elements in WR PageBuilder * @param int $index * @param bool $inlude_sc_structure * @param array $extra_params * Ex: param-tag=h6¶m-text=Your+heading¶m-font=custom¶m-font-family=arial * @return string */ public function element_in_pgbldr($content = '', $shortcode_data = '', $el_title = '', $index = '', $inlude_sc_structure = true, $extra_params = array()) { // Init neccessary data to render element in backend. $this->init_element(); $shortcode = $this->config['shortcode']; $is_sub_element = isset($this->config['sub_element']) ? true : false; $parent_shortcode = $is_sub_element ? str_replace('wr_item_', '', $shortcode) : $shortcode; $type = !empty($this->config['el_type']) ? $this->config['el_type'] : 'widget'; // Empty content if this is not sub element if (!$is_sub_element) { $content = ''; } $exception = isset($this->config['exception']) ? $this->config['exception'] : array(); $content = isset($exception['default_content']) ? $exception['default_content'] : $content; $modal_title = ''; // if is widget if ($type == 'widget') { global $Wr_Pb_Widgets; if (isset($Wr_Pb_Widgets[$shortcode]) && is_array($Wr_Pb_Widgets[$shortcode]) && isset($Wr_Pb_Widgets[$shortcode]['identity_name'])) { $modal_title = $Wr_Pb_Widgets[$shortcode]['identity_name']; $content = $this->config['exception']['data-modal-title'] = $modal_title; } } // if content is still empty, Generate it if (empty($content)) { if (!$is_sub_element) { $content = ucfirst(str_replace('wr_', '', $shortcode)); } else { if (isset($exception['item_text'])) { if (!empty($exception['item_text'])) { $content = WR_Pb_Utils_Placeholder::add_placeholder($exception['item_text'] . ' %s', 'index'); } } else { $content = WR_Pb_Utils_Placeholder::add_placeholder(__(ucfirst($parent_shortcode), WR_PBL) . ' ' . __('Item', WR_PBL) . ' %s', 'index'); } } } $content = !empty($el_title) ? $content . ': ' . "<span>{$el_title}</span>" : $content; // element name if ($type == 'element') { if (!$is_sub_element) { $name = ucfirst(str_replace('wr_', '', $shortcode)); } else { $name = __(ucfirst($parent_shortcode), WR_PBL) . ' ' . __('Item', WR_PBL); } } else { $name = $content; } if (empty($shortcode_data)) { $shortcode_data = $this->config['shortcode_structure']; } // Process index for subitem element if (!empty($index)) { $shortcode_data = str_replace('_WR_INDEX_', $index, $shortcode_data); } $shortcode_data = stripslashes($shortcode_data); $element_wrapper = !empty($exception['item_wrapper']) ? $exception['item_wrapper'] : ($is_sub_element ? 'li' : 'div'); $content_class = $is_sub_element ? 'jsn-item-content' : 'wr-pb-element'; $modal_title = empty($modal_title) ? !empty($exception['data-modal-title']) ? "data-modal-title='{$exception['data-modal-title']}'" : '' : $modal_title; $element_type = "data-el-type='{$type}'"; $edit_using_ajax = isset($this->config['edit_using_ajax']) && $this->config['edit_using_ajax'] ? sprintf("data-using-ajax='%s'", esc_attr($this->config['edit_using_ajax'])) : ''; $data = array('element_wrapper' => $element_wrapper, 'modal_title' => $modal_title, 'element_type' => $element_type, 'edit_using_ajax' => $edit_using_ajax, 'edit_inline' => isset($this->config['edit_inline']) ? 1 : 0, 'name' => $name, 'shortcode' => $shortcode, 'shortcode_data' => $shortcode_data, 'content_class' => $content_class, 'content' => $content, 'action_btn' => empty($exception['action_btn']) ? '' : $exception['action_btn'], 'is_sub_element' => $is_sub_element); // Merge extra params if it exists. if (!empty($extra_params)) { $data = array_merge($data, $extra_params); } $extra = array(); if (isset($this->config['exception']['disable_preview_container'])) { $extra = array('has_preview' => FALSE); } $data = array_merge($data, $extra); $html_preview = WR_Pb_Helper_Functions::get_element_item_html($data, $inlude_sc_structure); return array($html_preview); }
/** * Localize for js files */ public static function wr_localize() { WR_Pb_Init_Assets::localize('wr-pb-handleelement', 'Wr_Translate', WR_Pb_Helper_Functions::js_translation()); WR_Pb_Init_Assets::localize('wr-pb-handleelement', 'Wr_Js_Html', WR_Pb_Helper_Shortcode::$item_html_template); WR_Pb_Init_Assets::localize('wr-pb-handleelement', 'Wr_Ajax', WR_Pb_Helper_Functions::localize_js()); // Localize scripts for premade layout modal. WR_Pb_Init_Assets::localize('wr-pb-premade-pages', 'Wr_Translate', WR_Pb_Helper_Functions::js_translation()); WR_Pb_Init_Assets::localize('wr-pb-premade-pages', 'Wr_Ajax', WR_Pb_Helper_Functions::localize_js()); WR_Pb_Init_Assets::localize('wr-pb-layout', 'Wr_Translate', WR_Pb_Helper_Functions::js_translation()); WR_Pb_Init_Assets::localize('wr-pb-widget', 'Wr_Preview_Html', WR_Pb_Helper_Functions::get_element_item_html(array('element_wrapper' => 'div', 'modal_title' => '', 'element_type' => 'data-el-type="element"', 'name' => 'Widget Element Setting', 'shortcode' => 'WR_SHORTCODE_CONTENT', 'shortcode_data' => 'WR_SHORTCODE_DATA', 'content_class' => 'wr-pb-element', 'content' => 'Widget Element Setting'))); }