/** * Render the View. * * @param $out * * @return mixed|string|void */ function wpmtst_render_view($out) { // Did we find this view? if (isset($out['view_not_found']) && $out['view_not_found']) { return '<p style="color:red">' . __(sprintf('Strong Testimonials error: View %s not found', $out['view'])) . '</p>'; } // Container class is shared by display and form in templates. $out['container_class'] = 'strong-view-id-' . $out['view']; if ($out['class']) { $out['container_class'] .= ' ' . str_replace(',', ' ', $out['class']); } if (is_rtl()) { $out['container_class'] .= ' rtl'; } WPMST()->set_atts($out); /** * MODE: FORM */ if ($out['form']) { return wpmtst_form_view($out); } /** * MODE: DISPLAY (default) */ global $view; $view = new Strong_View($out); $view->build(); return $view->output(); }
/** * Preprocess a view to gather styles, scripts and script vars. * * @param $view * @param bool $handle * @since 1.25.0 * @since 2.5.0 Move some processing to Strong_View class. * * @todo Move add_script and add_style to Strong_View class. * * @return string */ private static function preprocess($view, $handle = false) { global $strong_templates; $options = get_option('wpmtst_options'); // subset of all shortcode atts $atts = shortcode_atts(self::get_view_defaults(), $view['atts']); $new_view = new Strong_View($atts); $new_view->process(); /** * Slideshow */ if ($atts['slideshow']) { // TODO Is this still beneficial? self::add_script('wpmtst-slider', 'later'); } else { /** * Pagination */ if ($atts['per_page'] && $new_view->query->post_count > $atts['per_page'] && apply_filters('wpmtst_use_default_pagination', true, $atts)) { // Populate variable for QuickPager script. $nav = $atts['nav']; if (false !== strpos($atts['nav'], 'before') && false !== strpos($atts['nav'], 'after')) { $nav = 'both'; } $pager = array('id' => '.strong-paginated', 'pageSize' => $atts['per_page'], 'currentPage' => 1, 'pagerLocation' => $nav, 'scrollTop' => $options['scrolltop'], 'offset' => apply_filters('wpmtst_pagination_scroll_offset', $options['scrolltop_offset'])); self::add_script('wpmtst-pager-script'); self::add_script_var('wpmtst-pager-script', 'pagerVar', $pager); } /** * Layouts */ if ('masonry' == $atts['layout']) { self::add_script('wpmtst-masonry-script'); self::add_style('wpmtst-masonry-style'); } elseif ('columns' == $atts['layout']) { self::add_style('wpmtst-columns-style'); } elseif ('grid' == $atts['layout']) { self::add_script('wpmtst-grid-script'); self::add_style('wpmtst-grid-style'); } } /** * Load template's script and/or dependencies. * * @since 1.25.0 */ $deps = $strong_templates->get_template_attr($atts, 'deps', false); $deps_array = array(); if ($deps) { $deps_array = explode(',', str_replace(' ', '', $deps)); } $script = $strong_templates->get_template_attr($atts, 'script', false); if ($script) { $handle = 'testimonials-' . str_replace(':', '-', $atts['template']); wp_register_script($handle, $script, $deps_array); self::add_script($handle); } else { foreach ($deps_array as $handle) { self::add_script($handle); } } self::custom_background($view, $atts['background'], $handle); }