/** * DEFINE shortcode content * * @param type $atts * @param type $content * * @return string */ public function element_shortcode($atts = null, $content = null) { $document = JFactory::getDocument(); $app = JFactory::getApplication(); if ($app->isAdmin()) { $this->load_assets_frontend(); } $arr_params = JSNPagebuilderHelpersShortcode::shortcodeAtts($this->config['params'], $atts); extract($arr_params); $random_id = JSNPagebuilderHelpersShortcode::generateRandomString(); $testimonial_id = "testimonial_{$random_id}"; $styles = "style='width:100%'"; $image_container_style = $author_image_style != 'no-styling' ? "{$author_image_style}" : ''; $content_elements = array_filter(explode('__#__', $content_elements)); $testimonial_indicators = array(); $testimonial_indicators[] = '<ol class="carousel-indicators">'; $sub_shortcode = empty($content) ? JSNPagebuilderHelpersShortcode::removeAutop($content) : JSNPagebuilderHelpersBuilder::generateShortCode($content, false, 'frontend', true); $testimonial_content = array(); $items = explode('<!--seperate-->', $sub_shortcode); $items = array_filter($items); $count_items = count($items); foreach ($items as $idx => $item) { $pathRoot = JURI::root(); $item = unserialize($item); $url_pattern = '/^(http|https)/'; $image_file = @$item['image_file']; preg_match($url_pattern, $image_file, $m); if (count($m)) { $pathRoot = ''; } if ($idx % $items_per_slide == 0) { $active = $idx == 0 ? 'active' : ''; $testimonial_content[] = "<div class='item row {$active}'>"; $active_li = $idx == 0 ? "class='active'" : ''; $testimonial_indicators[] = "<li {$active_li}></li>"; } $divide = $count_items > $items_per_slide ? $items_per_slide : $count_items; $colmd = 'col-md-' . 12 / $divide; $colsm = 'col-sm-' . 12 / $divide; $item_html = "<div class='pb-testimonial-item {$colmd} {$colsm}'>"; $testimonial_info = array(); if (in_array('content', $content_elements)) { $item_content = JSNPagebuilderHelpersShortcode::removeAutop($item['testimonial_content']); $item_content = JSNPagebuilderHelpersShortcode::pbTrimContent($item_content, $content_count, $content_type); $testimonial_info['content'] = "<div class='pb-testimonial-box top'><div class='arrow'></div><div class='pb-testimonial-content'><p>" . $item_content . '</p></div></div>'; } $img = !empty($item['image_file']) ? "<div class='pb-testimonial-avatar'><img class='{$image_container_style}' src='{$pathRoot}{$item['image_file']}' /></div>" : ''; $testimonial_info['image'] = in_array('image', $content_elements) ? $img : ''; // Process company field if (isset($item['company']) && $item['company'] != '') { $company_link = "<a href='{$item['web_url']}' target='_blank'>{$item['company']}</a>"; } else { $company_link = "<a href='{$item['web_url']}' target='_blank'>{$item['web_url']}</a>"; } if (!isset($item['web_url']) || empty($item['web_url'])) { $company_link = $item['company']; } // Process testimonial metadata $arr_style = array(); if (isset($item['name_height'])) { $arr_style[] = 'font-size: ' . $item['name_height'] . 'px'; } if (isset($item['name_color'])) { $arr_style[] = 'color: ' . $item['name_color']; } $style = $arr_style ? "style='" . implode(';', $arr_style) . "'" : ''; $name = in_array('name', $content_elements) ? "<strong {$style} class='pb-testimonial-name'>" . @$item['name'] . "</strong>" : ''; $job_title = in_array('job_title', $content_elements) ? "<span class='pb-testimonial-jobtitle'>" . @$item['job_title'] . "</span>" : ''; $country = in_array('country', $content_elements) ? "<span class='pb-testimonial-country'>" . @$item['country'] . "</span>" : ''; if ($company_link) { $company = in_array('company', $content_elements) ? "<span class='pb-testimonial-company'>{$company_link}</span>" : ''; } $html_metadata = ''; if ($name != '' || $job_title != '' || $country != '' || $company != '') { $html_metadata .= '<div class="pb-testimonial-meta">'; $html_metadata .= $name . $job_title . $country . $company; $html_metadata .= '</div>'; } foreach ($content_elements as $element) { $item_html .= isset($testimonial_info[$element]) ? $testimonial_info[$element] : ''; } $item_html .= $html_metadata; $item_html .= '</div>'; $testimonial_content[] = $item_html; if (($idx + 1) % $items_per_slide == 0 || $idx + 1 == count($items)) { $testimonial_content[] = '</div>'; } } $testimonial_content = "<div class='carousel-inner'>" . implode('', $testimonial_content) . '</div>'; $testimonial_indicators[] = "</ol>"; $testimonial_indicators = implode('', $testimonial_indicators); $slider_time = $slider_time . '000'; if ($auto_play == 'yes') { $script = "<script type='text/javascript'>\n\t\t\t\t\t\t(function(\$){\n\t\t\t\t\t\t\t\$(document).ready(function(){\n\t\t\t\t\t\t\t\tif(\$('#{$testimonial_id}').length){\n\t\t\t\t\t\t\t\t\t\$('#{$testimonial_id}').carousel({\n\t\t\t\t\t\t\t\t interval: " . (int) $slider_time . "\n\t\t\t\t\t\t\t\t });\n\t\t\t\t\t\t\t\t\t\$('#{$testimonial_id} .carousel-indicators li').each(function(i){\n\t\t\t\t\t\t\t\t\t\t\$(this).on('click', function(){\n\t\t\t\t\t\t\t\t\t\t\t\$('#{$testimonial_id}').carousel(i);\n\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t})(jQuery)\n\t\t\t\t</script>"; } else { $script = "<script type='text/javascript'>\n\t\t\t\t\t\t(function(\$){\n\t\t\t\t\t\t\t\$(document).ready(function(){\n\t\t\t\t\t\t\t\tif(\$('#{$testimonial_id}').length){\n\t\t\t\t\t\t\t\t\t\$('#{$testimonial_id}').carousel({\n\t\t\t\t\t\t\t\t interval: false\n\t\t\t\t\t\t\t\t });\n\t\t\t\t\t\t\t\t\t\$('#{$testimonial_id} .carousel-indicators li').each(function(i){\n\t\t\t\t\t\t\t\t\t\t\$(this).on('click', function(){\n\t\t\t\t\t\t\t\t\t\t\t\$('#{$testimonial_id}').carousel(i);\n\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t})(jQuery)\n\t\t\t\t</script>"; } $slider_elements = explode('__#__', $slider_elements); if ($count_items <= (int) $items_per_slide || !in_array('indicator', $slider_elements)) { $testimonial_indicators = ''; } $testimonial_navigator = $count_items > $items_per_slide && in_array('arrows', $slider_elements) ? "<a class='carousel-control left icon-arrow-left pb-arrow-left'></a><a class='carousel-control right icon-arrow-right pb-arrow-right'></a>" : ''; $html = "<div class='carousel slide pb-testimonial' {$styles} id='{$testimonial_id}'> {$testimonial_content} {$testimonial_indicators} {$testimonial_navigator}</div>"; return $this->element_wrapper($script . $html, $arr_params); }