/** * Search content (articles). * The SQL must return the following fields that are used in a common display * routine: href, title, section, created, text, browsernav. * * @param string $text Target search string. * @param string $phrase Matching option (possible values: exact|any|all). Default is "any". * @param string $ordering Ordering option (possible values: newest|oldest|popular|alpha|category). Default is "newest". * @param mixed $areas An array if the search it to be restricted to areas or null to search all areas. * * @return array Search results. * * @since 1.6 */ public function onContentSearch($text, $phrase = '', $ordering = '', $areas = null) { $shortCodeRegex = JSNPagebuilderHelpersShortcode::getShortcodeRegex(); $results = @parent::onContentSearch($text, $phrase, $ordering, $areas); foreach ($results as $_result) { $_result->text = self::removeShortCode($_result->text, $shortCodeRegex); } return $results; }
/** * Search content for shortcodes and filter shortcodes through their hooks. * * If there are no shortcode tags defined, then the content will be returned * without any filtering. This might cause issues when plugins are disabled but * the shortcode will still show up in the post or content. * * @since 2.5.0 * * @uses $shortcode_tags * @uses get_shortcode_regex() Gets the search pattern for searching shortcodes. * * @param string $content Content to search for shortcodes * @return string Content with shortcodes filtered out. */ public static function doShortcode($content) { // if ( false === strpos( $content, '[' ) ) { // return $content; // } $pattern = JSNPagebuilderHelpersShortcode::getShortcodeRegex(); return preg_replace_callback("/{$pattern}/s", 'doShortcodeTag', $content); }
/** * DEFINE shortcode content * * @param array $attributes * @param mixed $content * * @return string */ function element_shortcode($attributes = null, $content = null) { $document = JFactory::getDocument(); $document->addStyleSheet(JSNPB_ELEMENT_URL . '/articlelist/assets/css/articlelist.css', 'text/css'); $arr_params = JSNPagebuilderHelpersShortcode::shortcodeAtts($this->config['params'], $attributes); extract($arr_params); $html_element = ''; $articles = JSNPbArticleListHelper::getArticles($attributes); if (count($articles) == 0) { $html_element = "<div class='alert alert-warning' style='width: 100%;'>" . JText::_('JSN_PAGEBUILDER_ELEMENT_ARTICLELIST_FILTER_HAS_NO_RESULT') . "</div>"; return $this->element_wrapper($html_element, $arr_params); } $app = JFactory::getApplication(); $isAdmin = $app->isAdmin() ? true : false; $adminPreviewClass = $isAdmin ? "in-admin" : ""; $url_pattern = '/^(http|https)/'; $html_element .= "<div class='pb-articlelist-wrapper " . str_replace('_', '-', $arr_params['articlelist_layout']) . " " . $adminPreviewClass . "'>"; if ($arr_params['articlelist_show_title'] == JSNPagebuilderHelpersType::PB_HELPER_ANSWER_YES) { $html_element .= "<div class='pb-articlelist-title'><h3 class='pb-articlelist-head'>{$arr_params['articlelist_title']}</h3></div>"; } $html_element .= "<div class='row'>"; if ($arr_params['articlelist_layout'] != JSNPbArticleListHelper::PB_ARTICLE_LIST_LAYOUT) { if ($arr_params['articlelist_layout'] == JSNPbArticleListHelper::PB_ARTICLE_HORIZONTAL_LAYOUT) { $html_element .= "<div class='col-md-6 col-sm-6 col-xs-6 pb-articlelist-first'>"; } else { if ($arr_params['articlelist_layout'] == JSNPbArticleListHelper::PB_ARTICLE_VERTICAL_LAYOUT) { $html_element .= "<div class='col-md-12 col-sm-12 col-xs-12 pb-articlelist-first'>"; } else { $html_element .= "<div class='pb-articlelist-first'>"; } } // Display with first item $articleFirst = array_shift($articles); // Default thumbnail dimension $thumbnailFirstWidth = $arr_params['articlelist_first_thumbnail_type'] == 'custom' ? 'width: ' . (int) $arr_params['articlelist_first_thumbnail_dimension_width'] . 'px;' : 'width: 100%; max-width: 100%;'; $thumbnailFirstHeight = $arr_params['articlelist_first_thumbnail_type'] == 'custom' ? 'height: ' . (int) $arr_params['articlelist_first_thumbnail_dimension_height'] . 'px;' : 'height: 100%; max-height: 100%;'; $firstMetaData = explode("__#__", $arr_params['articlelist_show_first_meta_data']); $firstUrl = $isAdmin ? "#" : $articleFirst['direct_url']; if ($arr_params['articlelist_show_first_thumbnail'] == JSNPagebuilderHelpersType::PB_HELPER_ANSWER_YES) { $imageFirstUrl = ''; $imageFirstAlt = "No image"; if (isset($articleFirst['images'])) { $articleFirstImages = json_decode($articleFirst['images'], true); if (isset($articleFirstImages['image_intro']) && $articleFirstImages['image_intro'] != "") { $imageFirstUrl = $articleFirstImages['image_intro']; $imageFirstAlt = $articleFirstImages['image_intro_alt']; } else { if (isset($articleFirstImages['image_fulltext']) && $articleFirstImages['image_fulltext'] != "") { $imageFirstUrl = $articleFirstImages['image_fulltext']; $imageFirstAlt = $articleFirstImages['image_fulltext_alt']; } } } if ($imageFirstUrl != '') { $imageFirstUrl = preg_match($url_pattern, $imageFirstUrl) !== 0 ? $imageFirstUrl : JUri::root() . $imageFirstUrl; $html_element .= "<div class='first-thumbnail'>"; $html_element .= "<a href='{$firstUrl}'><img src='{$imageFirstUrl}' alt='{$imageFirstAlt}' style='{$thumbnailFirstHeight} {$thumbnailFirstWidth}' /></a>"; $html_element .= "</div>"; } } $html_element .= "<div class='title'><a class='title' href='{$firstUrl}'>{$articleFirst['title']}</a></div>"; if (count($firstMetaData) > 1) { $html_element .= "<div class='meta-data-wrapper muted'>"; if (in_array(JSNPbArticleListHelper::PB_ARTICLE_META_DATA_AUTHOR, $firstMetaData)) { $html_element .= "<div class='created-by'>" . JText::_('JSN_PAGEBUILDER_ELEMENT_ARTICLELIST_WRITTEN_BY') . ": <span>{$articleFirst['author']}</span></div>"; } if (in_array(JSNPbArticleListHelper::PB_ARTICLE_META_DATA_DATE_PUBLISHED, $firstMetaData)) { $_publishData = new DateTime($articleFirst['publish_up']); $html_element .= "<div class='published'>" . JText::_('JSN_PAGEBUILDER_ELEMENT_ARTICLELIST_PUBLISHED') . ": " . $_publishData->format('d M Y') . "</div>"; } if (in_array(JSNPbArticleListHelper::PB_ARTICLE_META_DATA_CATEGORY, $firstMetaData)) { $urlCat = $isAdmin ? "#" : $articleFirst['category_direct_url']; $html_element .= "<div class='category'>" . JText::_('JSN_PAGEBUILDER_ELEMENT_ARTICLELIST_CATEGORY') . ": <a href='{$urlCat}'>{$articleFirst['category_title']}</a></div>"; } if (in_array(JSNPbArticleListHelper::PB_ARTICLE_META_DATA_HITS, $firstMetaData)) { $html_element .= "<div class='hits'>" . JText::_('JSN_PAGEBUILDER_ELEMENT_ARTICLELIST_HITS') . ": {$articleFirst['hits']}</div>"; } $html_element .= "</div>"; } if ($attributes['articlelist_show_first_description'] == JSNPagebuilderHelpersType::PB_HELPER_ANSWER_YES) { preg_match_all(JSNPbArticleListHelper::PB_SHORTCODE_SYNTAX, $articleFirst['introtext'], $out); if (!count($out[0])) { $_firstIntroText = $articleFirst['introtext']; } else { $shortCodeRegex = JSNPagebuilderHelpersShortcode::getShortcodeRegex(); $_firstIntroText = JSNPbArticleListHelper::removeShortCode($articleFirst['introtext'], $shortCodeRegex); } $html_element .= "<div class='articlelist-first-thumbnail'><p>" . JSNPbArticleListHelper::wordLimiter($_firstIntroText, (int) $attributes['articlelist_first_description_limit']) . "</p></div>"; } if ($arr_params['articlelist_show_read_more_first'] == JSNPagebuilderHelpersType::PB_HELPER_ANSWER_YES) { $html_element .= "<div class='articlelist-item-read-more'><a class='link-button button-light' href='{$firstUrl}'>" . JText::_('JSN_PAGEBUILDER_ELEMENT_ARTICLELIST_READMORE') . "</a></div>"; } $html_element .= "</div>"; } if ($arr_params['articlelist_layout'] == JSNPbArticleListHelper::PB_ARTICLE_HORIZONTAL_LAYOUT) { $html_element .= "<div class='col-md-6 col-sm-6 col-xs-6 pb-articlelist-list'>"; } else { $html_element .= "<div class='col-md-12 col-sm-12 col-xs-12 pb-articlelist-list'>"; } // Display list if ($isOrderList = in_array($arr_params['articlelist_list_style'], JSNPbArticleListHelper::getArticleOlListStyle())) { $html_element .= "<ol type='{$arr_params['articlelist_list_style']}'>"; } else { switch ($arr_params['articlelist_list_style']) { case JSNPbArticleListHelper::PB_ARTICLE_LIST_STYLE_IMAGE: if (getimagesize(JUri::root() . $attributes['articlelist_list_image']) !== false) { $styleUl = "list-style-image: url(\"" . JUri::root() . $attributes['articlelist_list_image'] . "\")"; } else { $styleUl = "list-style-image: url(\"" . JUri::root() . "plugins/jsnpagebuilder/defaultelements/articlelist/assets/img/10x10.png" . "\")"; } break; case JSNPbArticleListHelper::PB_ARTICLE_LIST_STYLE_THUMBNAIL: $styleUl = "list-style-type: none"; break; default: $styleUl = "list-style-type:{$arr_params['articlelist_list_style']}"; break; } $html_element .= "<ul class='list-style-type-{$arr_params['articlelist_list_style']}' style='{$styleUl}'>"; } // Default thumbnail dimension $thumbnailWidth = $arr_params['articlelist_thumbnail_type'] == 'custom' ? 'width: ' . (int) $arr_params['articlelist_thumbnail_dimension_width'] . 'px;' : 'width: 100%; max-width: 100%;'; $thumbnailHeight = $arr_params['articlelist_thumbnail_type'] == 'custom' ? 'height: ' . (int) $arr_params['articlelist_thumbnail_dimension_height'] . 'px;' : 'height: 100%; max-height: 100%;'; $metaData = explode("__#__", $arr_params['articlelist_show_meta_data']); foreach ($articles as $_article) { $url = $isAdmin ? "#" : $_article['direct_url']; $html_element .= "<li class='articlelist-item'>"; if ($arr_params['articlelist_list_style'] == JSNPbArticleListHelper::PB_ARTICLE_LIST_STYLE_THUMBNAIL) { $bgImageItemUrl = ""; if (isset($_article['images'])) { $articleImages = json_decode($_article['images'], true); if (isset($articleImages['image_intro']) && $articleImages['image_intro'] != "") { $bgImageItemUrl = $articleImages['image_intro']; } else { if (isset($articleImages['image_fulltext']) && $articleImages['image_fulltext'] != "") { $bgImageItemUrl = $articleImages['image_fulltext']; } } } if ($bgImageItemUrl != '') { $bgImageItemUrl = preg_match($url_pattern, $bgImageItemUrl) !== 0 ? $bgImageItemUrl : JUri::root() . $bgImageItemUrl; $html_element .= "<div class='articlelist-item-thumbnail'><a href='{$url}'><img src='{$bgImageItemUrl}' style='{$thumbnailHeight} {$thumbnailWidth}'></a></div>"; } } $html_element .= "<div class='articlelist-item-content'>"; $html_element .= "<div class='title'><a class='title' href='{$url}'>{$_article['title']}</a></div>"; if (count($metaData) > 1) { $html_element .= "<div class='meta-data-wrapper muted'>"; if (in_array(JSNPbArticleListHelper::PB_ARTICLE_META_DATA_AUTHOR, $metaData)) { $html_element .= "<div class='created-by'>" . JText::_('JSN_PAGEBUILDER_ELEMENT_ARTICLELIST_WRITTEN_BY') . ": <span>{$_article['author']}</span></div>"; } if (in_array(JSNPbArticleListHelper::PB_ARTICLE_META_DATA_DATE_PUBLISHED, $metaData)) { $_publishData = new DateTime($_article['publish_up']); $html_element .= "<div class='published'>" . JText::_('JSN_PAGEBUILDER_ELEMENT_ARTICLELIST_PUBLISHED') . ": " . $_publishData->format('d M Y') . "</div>"; } if (in_array(JSNPbArticleListHelper::PB_ARTICLE_META_DATA_CATEGORY, $metaData)) { $urlCat = $isAdmin ? "#" : $_article['category_direct_url']; $html_element .= "<div class='category'>" . JText::_('JSN_PAGEBUILDER_ELEMENT_ARTICLELIST_CATEGORY') . ": <a href='{$urlCat}'>{$_article['category_title']}</a></div>"; } if (in_array(JSNPbArticleListHelper::PB_ARTICLE_META_DATA_HITS, $metaData)) { $html_element .= "<div class='hits'>" . JText::_('JSN_PAGEBUILDER_ELEMENT_ARTICLELIST_HITS') . ": {$_article['hits']}</div>"; } $html_element .= "</div>"; } if ($attributes['articlelist_show_description'] == JSNPagebuilderHelpersType::PB_HELPER_ANSWER_YES) { preg_match_all(JSNPbArticleListHelper::PB_SHORTCODE_SYNTAX, $_article['introtext'], $out); if (!count($out[0])) { $_introText = $_article['introtext']; } else { $shortCodeRegex = JSNPagebuilderHelpersShortcode::getShortcodeRegex(); $_introText = JSNPbArticleListHelper::removeShortCode($_article['introtext'], $shortCodeRegex); } $html_element .= "<div class='articlelist-item-description'><p>" . JSNPbArticleListHelper::wordLimiter($_introText, (int) $attributes['articlelist_description_limit']) . "</p></div>"; } if ($arr_params['articlelist_show_read_more'] == JSNPagebuilderHelpersType::PB_HELPER_ANSWER_YES) { $html_element .= "<div class='articlelist-item-read-more'><a class='link-button button-light' href='{$url}'>" . JText::_('JSN_PAGEBUILDER_ELEMENT_ARTICLELIST_READMORE') . "</a></div>"; } $html_element .= "</div></li>"; } $html_element .= $isOrderList ? "</ol>" : "</ul>"; $html_element .= "</div></div>"; $html_element .= "</div>"; return $this->element_wrapper($html_element, $arr_params); }
/** * This method is to load neccessary access * for PageBuilder need * * @return void */ public function onBeforeRender() { // Check if JoomlaShine extension framework is enabled? $framework = JTable::getInstance('Extension'); $framework->load(array('element' => 'jsnframework', 'type' => 'plugin', 'folder' => 'system')); // Do nothing if JSN Extension framework not found. if (!$framework->extension_id) { return; } $app = JFactory::getApplication(); $tpl = $app->input->getInt('tp', 0); if ($app->isAdmin() || $tpl) { return; } // Get requested component, view and task $option = $app->input->getCmd('option', ''); $view = $app->input->getCmd('view', ''); $layout = $app->input->getCmd('layout', ''); $user = JFactory::getUser(); if ($app->isSite() && $option == 'com_content' && $view == 'form' && $layout == 'edit' && $user->get('id') > 0) { return; } $doc = JFactory::getDocument(); if (get_class($doc) != "JDocumentHTML") { return; } if ($app->isSite() && $option == 'com_k2' && $view == 'item' && $app->input->getInt('id', 0)) { if (file_exists(JPATH_ROOT . '/administrator/components/com_pagebuilder/helpers/shortcode.php')) { if (class_exists('K2HelperUtilities')) { include_once JPATH_ROOT . '/administrator/components/com_pagebuilder/helpers/shortcode.php'; $shortCodeRegex = JSNPagebuilderHelpersShortcode::getShortcodeRegex(); JModelLegacy::addIncludePath(JPATH_ROOT . '/components/com_k2/models'); $K2ModelItem = JModelLegacy::getInstance('k2modelitem'); $k2Item = $K2ModelItem->getData(); if (count($k2Item)) { $metaDescItem = preg_replace("#{(.*?)}(.*?){/(.*?)}#s", '', $k2Item->introtext . ' ' . $k2Item->fulltext); $metaDescItem = strip_tags($metaDescItem); $k2params = K2HelperUtilities::getParams('com_k2'); $metaDescItem = self::removeShortCode($metaDescItem, $shortCodeRegex); $metaDescItem = K2HelperUtilities::characterLimit($metaDescItem, $k2params->get('metaDescLimit', 150)); if ($doc->getMetaData('og:description') != null) { $doc->setMetaData('og:description', $metaDescItem); } if ($doc->getDescription() != '') { $doc->setDescription($metaDescItem); } } } } } // Get PageBuilder configuration. $params = JSNConfigHelper::get('com_pagebuilder'); // Check if it's enabled or not. $isEnabled = $params->get('enable_pagebuilder', 1); // Do nothing if PageBuilder not enabled; if (!$isEnabled) { } // Register autoloaded classes JSN_Loader::register(JSNPB_ADMIN_ROOT . '/helpers', 'JSNPagebuilderHelpers'); JSN_Loader::register(JSNPB_ADMIN_ROOT . '/helpers/shortcode', 'JSNPBShortcode'); //JSN_Loader::register(JPATH_ROOT . '/plugins/pagebuilder/' , 'JSNPBShortcode'); //JSN_Loader::register(JPATH_ROOT . '/administrator/components/com_pagebuilder/elements/' , 'JSNPBShortcode'); JSN_Loader::register(JPATH_ROOT . '/plugins/jsnpagebuilder/defaultelements/', 'JSNPBShortcode'); //load ElementAssets self::loadElementAssets(); /* * Move all css files of PageBuilder * to the end of css list * */ $data = $doc->getHeadData(); $styleSheetList = $data['styleSheets']; $_tmpList = array(); if (count($styleSheetList)) { foreach ($styleSheetList as $cssUrl => $css) { // Check if the file belongs to PageBuilder if (strpos($cssUrl, 'plugins/pagebuilder/') !== false || strpos($cssUrl, 'com_pagebuilder') !== false) { $_tmpList[$cssUrl] = $css; unset($styleSheetList[$cssUrl]); } } } $styleSheetList = array_merge($styleSheetList, $_tmpList); $data['styleSheets'] = $styleSheetList; $doc->setHeadData($data); }