/** * Return html structure of shortcode in Page Builder area * * @param string $shortcode_name * @param string $content * @param string $shortcode_data * @param array $shortcode_params * * @return string */ public static function transformShortcodeToPagebuilder($shortcode_name, $content = '', $shortcode_data = '', $shortcode_params = '', $client = 'backend') { $class = JSNPagebuilderHelpersShortcode::getShortcodeClass($shortcode_name); if (class_exists($class)) { global $JSNPbElements; $JSNPbElements->setGeneratedStatus(true); $elements = $JSNPbElements->getElements(); $instance = isset($elements[strtolower($class)]) ? $elements[strtolower($class)] : null; if (!is_object($instance)) { $instance = new $class(); } $el_title = ""; // 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] = JSNPagebuilderHelpersFunctions::removeQuotes($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 = JSNPagebuilderHelpersShortcode::shortcodeParseAtts($shortcode_params); $el_title = !empty($params[$title["id"]]) ? $params[$title["id"]] : ""; } } if ($client === 'backend') { $shortcode_view = $instance->element_in_pgbldr($content, $shortcode_data, $el_title); } else { // Render the shortcode frontend HTML $params = JSNPagebuilderHelpersShortcode::shortcodeParseAtts($shortcode_params); $shortcode_view = $instance->element_shortcode($params, $content); } return $shortcode_view; } }
/** * Method to print element settings */ public function settings() { $js = ' var JSNPbParams = {pbstrings : {}}; JSNPbParams.rootUrl = \'' . JUri::root() . '\'; JSNPbParams.pbstrings.NO_ITEM_FOUND = \'' . JText::_('No %s found') . '\'; JSNPbParams.pbstrings.SINGLE_ENTRY = \'' . JText::_('Single %s') . '\'; JSNPbParams.pbstrings.SETTINGS = \'' . JText::_('Settings') . '\'; JSNPbParams.pbstrings.INVALID_LINK = \'' . JText::_('The link is invalid') . '\'; JSNPbParams.pbstrings.COPY = \'' . JText::_('copy') . '\'; JSNPbParams.pbstrings.EMPTY = \'' . JText::_('(Untitled)') . '\'; JSNPbParams.pbstrings.SELECT_DES_MARKER = \'' . JText::_('Select Destination Marker') . '\'; JSNPbParams.pbstrings.ALERT_DELETE_ROW = \'' . JText::_('Are you sure you want to delete the whole row including all elements it contains?') . '\'; JSNPbParams.pbstrings.ALERT_DELETE_COLUMN = \'' . JText::_('Are you sure you want to delete the whole column including all elements it contains?') . '\'; JSNPbParams.pbstrings.ALERT_DELETE_ELEMENT = \'' . JText::_('Are you sure you want to delete the element?') . '\'; '; JSNPagebuilderHelpersFunctions::print_asset_tag($js, 'js', null, true); $shortcode = JRequest::getString('shortcode'); $params = isset($_POST['params']) ? $_POST['params'] : ''; // TODO: move under assets inside shortcode // Add common js library for elements. JSNPagebuilderHelpersFunctions::print_asset_tag(JSNPB_FRAMEWORK_ASSETS . '/3rd-party/jquery-tipsy/jquery.tipsy.js', 'js'); JSNPagebuilderHelpersFunctions::print_asset_tag(JSNPB_FRAMEWORK_ASSETS . '/3rd-party/jquery-tipsy/tipsy.css', 'css'); JSNPagebuilderHelpersFunctions::print_asset_tag(JSNPB_FRAMEWORK_ASSETS . '/joomlashine/css/jsn-general.css', 'css'); // for accordion_item, buttonbar_item, JSNPagebuilderHelpersFunctions::print_asset_tag(JSNPB_FRAMEWORK_ASSETS . '/joomlashine/css/jsn-fonticomoon.css', 'css'); // for accordion_item, buttonbar_item, $extract_params = ''; $shortcodeHelper = new JSNPagebuilderHelpersShortcode(); $data = array(); if (!empty($shortcode)) { // elements $class = $shortcodeHelper->getShortcodeClass($shortcode); if (class_exists($class)) { // Get all regitered element shortcodes global $JSNPbElements; $elements = $JSNPbElements->getElements(); $instance = isset($elements[strtolower($class)]) ? $elements[strtolower($class)] : null; // Init and register new instance if it not if (!is_object($instance)) { $instance = new $class(); } if (!empty($params)) { $params = stripslashes($params); $params = urldecode($params); } else { $params = $instance->config['shortcode_structure']; } // Add neccessary assets for the shortcode $instance->backend_element_assets(); if (!empty($params)) { $extract_params = JSNPagebuilderHelpersShortcode::extractParams($params, $shortcode); // if have sub-shortcode, get content if (!empty($instance->config['has_subshortcode'])) { $sub_sc_data = JSNPagebuilderHelpersShortcode::extractSubShortcode($params, true); $extract_params['sub_sc_content'] = $sub_sc_data; } // MODIFY $instance->items $shortcodeHelper->generateShortcodeParams($instance->items, NULL, $extract_params, TRUE); // recall this to re-extract params $instance->shortcode_data(); } // get Modal setting box $settings = $instance->items; $shortcodeAterfix = substr($shortcode, -5); $showPreview = true; if ($shortcodeAterfix == '_item') { $showPreview = false; } if ($shortcode == 'pb_row') { $showPreview = false; } $modalContent = $shortcodeHelper->getShortcodeModalSettings($settings, $shortcode, $extract_params); } } $html[] = ''; if ($showPreview) { $html[] = '<div id="jsn_column1" class="pull-left">'; } $html[] = '<div class="jsn-bootstrap" id="settings-form-container"> <div id="modalOptions" class="form-horizontal"> ' . $modalContent . ' <div id="modalAction"></div> </div> <textarea class="hidden" id="shortcode_content" name="shortcode_content">' . $params . '</textarea> <textarea class="hidden" id="pb_share_data" ></textarea> <textarea class="hidden" id="pb_merge_data" ></textarea> <textarea class="hidden" id="pb_extract_data" ></textarea> <input type="hidden" id="pb_previewing" value="0" /> <input id="shortcode_name" name="shortcode_name" type="hidden" value="' . $shortcode . '" /> </div>'; if ($showPreview) { $html[] = '</div>'; } if ($showPreview) { $html[] = '<div id="jsn_column2" class="pull-left"> <div class="preview_title">' . JText::_("Preview") . '</div> <div id="framePreview" class="preview_border"> <div id="iframeLoading" class="iframe_loading_border"><div class="iframe_loading_image"><img src="components/com_pagebuilder/assets/images/icons-32/ajax-loader.gif"></div></div> <div class="control-group"> <div id="preview_container"> <iframe id="shortcode_preview_iframe" scrolling="auto" name="shortcode_preview_iframe" class="shortcode_preview_iframe" width="100%"></iframe> <div id="preview"></div> </div> </div> </div> </div>'; } $html[] = '<div class="clearfix"></div>'; echo implode('', $html); exit; }
/** * Register elements * * @return void */ public function registerElements() { //$current_shortcode = IG_Pb_Functions::current_shortcode(); $shortcodes = JSNPagebuilderHelpersShortcode::getShortcodeTags(); //echo "<pre>"; //print_r($shortcodes); die(); // Use Row and Column as shortcodes $shortcodes['pb_row'] = 'row'; $shortcodes['pb_column'] = 'column'; foreach ($shortcodes as $name => $type) { $class = JSNPagebuilderHelpersShortcode::getShortcodeClass($name); if (class_exists($class)) { $element = new $class(); $this->setElement($class, $element); } } }
public function display($tpl = null) { JSNHtmlAsset::addScript(JSNPB_ADMIN_URL . '/assets/js/shortcodesetting/settings-handler.js'); $js = ' var JSNPbParams = {pbstrings : {}}; JSNPbParams.rootUrl = \'' . JUri::root() . '\'; JSNPbParams.pbstrings.NO_ITEM_FOUND = \'' . JText::_('JSN_PAGEBUILDER_CONTROLLERS_SHORTCODE_NO_ITEM_FOUND') . '\'; JSNPbParams.pbstrings.SINGLE_ENTRY = \'' . JText::_('JSN_PAGEBUILDER_CONTROLLERS_SHORTCODE_SINGLE_ENTRY') . '\'; JSNPbParams.pbstrings.SETTINGS = \'' . JText::_('JSN_PAGEBUILDER_CONTROLLERS_SHORTCODE_SETTINGS') . '\'; JSNPbParams.pbstrings.INVALID_LINK = \'' . JText::_('JSN_PAGEBUILDER_CONTROLLERS_SHORTCODE_THE_LINK_IS_INVALID') . '\'; JSNPbParams.pbstrings.COPY = \'' . JText::_('JSN_PAGEBUILDER_CONTROLLERS_SHORTCODE_COPY') . '\'; JSNPbParams.pbstrings.EMPTY = \'' . JText::_('JSN_PAGEBUILDER_CONTROLLERS_SHORTCODE_EMPTY') . '\'; JSNPbParams.pbstrings.SELECT_DES_MARKER = \'' . JText::_('JSN_PAGEBUILDER_CONTROLLERS_SHORTCODE_SELECT_DES_MARKER') . '\'; '; JSNHtmlAsset::addInlineScript($js); $shortcode = JRequest::getString('shortcode'); $params = ''; // Get params from session then clear the session if (isset($_SESSION[JSNPB_SHORTCODE_SESSION_NAME][$shortcode]['params'])) { $params = $_SESSION[JSNPB_SHORTCODE_SESSION_NAME][$shortcode]['params']; $params = json_decode($params); $_SESSION[JSNPB_SHORTCODE_SESSION_NAME][$shortcode]['params'] = ''; } // TODO: move under assets inside shortcode // Add common js library for elements. JSNHtmlAsset::addScript(JSNPB_FRAMEWORK_ASSETS . '/3rd-party/jquery-tipsy/jquery.tipsy.js'); JSNHtmlAsset::addStyle(JSNPB_FRAMEWORK_ASSETS . '/3rd-party/jquery-tipsy/tipsy.css'); JSNHtmlAsset::addStyle(JSNPB_FRAMEWORK_ASSETS . '/joomlashine/css/jsn-general.css'); // for accordion_item, buttonbar_item, JSNHtmlAsset::addStyle(JSNPB_FRAMEWORK_ASSETS . '/joomlashine/css/jsn-fonticomoon.css'); // for accordion_item, buttonbar_item, $extract_params = ''; $shortcodeHelper = new JSNPagebuilderHelpersShortcode(); $data = array(); if (!empty($shortcode)) { // elements $class = $shortcodeHelper->getShortcodeClass($shortcode); if (class_exists($class)) { // Get all regitered element shortcodes global $JSNPbElements; $elements = $JSNPbElements->getElements(); $instance = isset($elements[strtolower($class)]) ? $elements[strtolower($class)] : null; // Init and register new instance if it not if (!is_object($instance)) { $instance = new $class(); } if (!empty($params)) { $params = stripslashes($params); $params = urldecode($params); } else { $params = $instance->config['shortcode_structure']; } // Add neccessary assets for the shortcode $instance->backend_element_assets(); // process require_js at backend setting if (isset($instance->config['exception']['require_js'])) { $requires = $instance->config['exception']['require_js']; foreach ($requires as $i => $require) { if (file_exists(JSNPB_ASSETS_PATH . $require)) { JSNHtmlAsset::addScript(JSNPB_ASSETS_PATH . $require); } } } if (!empty($params)) { $extract_params = JSNPagebuilderHelpersShortcode::extractParams($params, $shortcode); // if have sub-shortcode, get content if (!empty($instance->config['has_subshortcode'])) { $sub_sc_data = JSNPagebuilderHelpersShortcode::extractSubShortcode($params, true); $extract_params['sub_sc_content'] = $sub_sc_data; } // MODIFY $instance->items $shortcodeHelper->generateShortcodeParams($instance->items, NULL, $extract_params, TRUE); // recall this to re-extract params $instance->shortcode_data(); } // get Modal setting box $settings = $instance->items; $shortcodeAterfix = substr($shortcode, -5); $showPreview = true; if ($shortcodeAterfix == '_item') { $showPreview = false; } if ($shortcode == 'pb_row') { $showPreview = false; } $modalContent = $shortcodeHelper->getShortcodeModalSettings($settings, $shortcode, $extract_params); $this->assign('content', $modalContent); $this->assign('params', $params); $this->assign('shortcodeName', $shortcode); $this->assign('showPreview', $showPreview); } } return parent::display(); }
public function getShortCodeClassBeforeRender($content) { $helper = new JSNPagebuilderHelpersShortcode(); $content = trim($content); $shortcodeTags = $helper::getShortcodeTags(); $shortcodeClass = array(); foreach ($shortcodeTags as $pattern => $shortcodeTag) { preg_match("/{$pattern}/", $content, $match); if (count($match)) { if ($match[0]) { $class = JSNPagebuilderHelpersShortcode::getShortcodeClass($match[0]); $shortcodeClass[] = $class; } } } return $shortcodeClass; }