/** * GET <script type='text/html'... template for shortcode element * @global type $Wr_Pb_Widgets * @return string */ function get_shortcode_tpl() { global $wr_megamenu_element; if (!isset($_POST[WR_MEGAMENU_NONCE]) || !wp_verify_nonce($_POST[WR_MEGAMENU_NONCE], WR_MEGAMENU_NONCE)) { return; } if (!$_POST['shortcode']) { return; } $shortcode = $_POST['shortcode']; $type = $_POST['type']; $elements = $wr_megamenu_element->get_elements(); if ($type == 'element') { if (isset($elements['element'][strtolower($shortcode)]) && is_object($elements['element'][strtolower($shortcode)])) { $element = $elements['element'][strtolower($shortcode)]; } else { $class = WR_Megamenu_Helpers_Shortcode::get_shortcode_class($shortcode); $element = new $class(); } $element->shortcode_data(); $element_type = $element->element_in_megamenu(); foreach ($element_type as $element_structure) { echo balanceTags("<script type='text/html' id='tmpl-{$shortcode}'>\n{$element_structure}\n</script>\n"); } } else { $shortcode = mysql_real_escape_string($shortcode); $element = new WR_Megamenu_Widget(); global $wr_megamenu_widgets; $modal_title = $wr_megamenu_widgets[$shortcode]['identity_name']; $element->config['shortcode'] = $shortcode; $content = $element->config['exception']['data-modal-title'] = $modal_title; $element->config['shortcode_structure'] = WR_Megamenu_Helpers_Placeholder::add_placeholder("[wr_megamenu_widget widget_id=\"{$shortcode}\"]%s[/wr_megamenu_widget]", 'widget_title'); $element->config['el_type'] = $type; $element_type = $element->element_in_megamenu($content); foreach ($element_type as $element_structure) { echo balanceTags("<script type='text/html' id='tmpl-{$shortcode}'>\n{$element_structure}\n</script>\n"); } } exit; }
/** * DEFINE html structure of shortcode in MegaMenu 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 MegaMenu * Ex: param-tag=h6¶m-text=Your+heading¶m-font=custom¶m-font-family=arial * @return string */ public function element_in_megamenu($content = '', $shortcode_data = '', $el_title = '', $index = '') { $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_megamenu_widgets; if (isset($wr_megamenu_widgets[$shortcode]) && is_array($wr_megamenu_widgets[$shortcode]) && isset($wr_megamenu_widgets[$shortcode]['identity_name'])) { $modal_title = $wr_megamenu_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_Megamenu_Helpers_Placeholder::add_placeholder($exception['item_text'] . ' %s', 'index'); } } else { $content = WR_Megamenu_Helpers_Placeholder::add_placeholder(__(ucfirst($parent_shortcode), WR_MEGAMENU_TEXTDOMAIN) . ' ' . __('Item', WR_MEGAMENU_TEXTDOMAIN) . ' %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_MEGAMENU_TEXTDOMAIN) . ' ' . __('Item', WR_MEGAMENU_TEXTDOMAIN); } } 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-mm-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}'"; $data = array('element_wrapper' => $element_wrapper, 'modal_title' => $modal_title, 'element_type' => $element_type, 'name' => $name, 'shortcode' => $shortcode, 'shortcode_data' => $shortcode_data, 'content_class' => $content_class, 'content' => $content, 'action_btn' => empty($exception['action_btn']) ? '' : $exception['action_btn']); $extra = array(); if (isset($this->config['exception']['disable_preview_container'])) { $extra = array('has_preview' => FALSE); } $data = array_merge($data, $extra); $html_preview = WR_Megamenu_Helpers_Functions::get_element_item_html($data); return array($html_preview); }