/** * Add shortcode * * @param array $atts Array of setting parameters for shortcode * @param string $content Content of shortcode */ static function view_output($atts) { $atts = shortcode_atts(apply_filters(PT_CV_PREFIX_ . 'shortcode_params', array('id' => 0)), $atts); // View meta id $id = esc_sql($atts['id']); if (!$id) { return 'No view ID'; } // View shortcode parameters global $pt_cv_glb, $pt_cv_sub_id, $pt_cv_id; /** * Prevent recursive queries by disabling View shortcode in child pages if parent View is not finished * @since 1.6.8.4, 2.4 */ if (apply_filters(PT_CV_PREFIX_ . 'disable_child_view', true) && $pt_cv_id != 0 && !isset($pt_cv_glb[$pt_cv_id]['finished'])) { return PT_CV_Functions::debug_output('parent_view_not_finished', ''); } $pt_cv_glb[$id] = array(); $pt_cv_glb[$id]['shortcode_params'] = $atts; $pt_cv_sub_id = $id; // Get View settings $settings = PT_CV_Functions::view_get_settings($id); // Show View output $view_html = PT_CV_Functions::view_process_settings($id, $settings); return PT_CV_Functions::view_final_output($view_html); }
/** * Wrap content of all items * * @param array $content_items The array of Raw HTML output (is not wrapped) of each item * @param int $current_page The current page * @param int $post_per_page The number of posts per page * @param int $id ID of View * * @return string Full HTML output for Content View */ static function content_items_wrap($content_items, $current_page, $post_per_page, $id) { $dargs = PT_CV_Functions::get_global_variable('dargs'); if (empty($content_items)) { return PT_CV_Functions::debug_output('empty content_items', 'No posts found!'); } // Assign as global variable PT_CV_Functions::set_global_variable('content_items', $content_items); $nonpaging_or_firstpage = PT_CV_Functions::nonpaging_or_firstpage($dargs, $current_page); // 1. Before output $before_output = $nonpaging_or_firstpage ? apply_filters(PT_CV_PREFIX_ . 'before_output_html', '') : ''; // 2. Output content $content = array(); $view_type = $dargs['view-type']; // Separate items by row, column switch ($view_type) { // Grid case 'grid': PT_CV_Html_ViewType::grid_wrapper($content_items, $content); break; // Collapsible List // Collapsible List case 'collapsible': PT_CV_Html_ViewType::collapsible_wrapper($content_items, $content); break; // Scrollable List // Scrollable List case 'scrollable': PT_CV_Html_ViewType::scrollable_wrapper($content_items, $content); break; default: foreach ($content_items as $post_id => $content_item) { // Wrap content of item $content[] = PT_CV_Html::content_item_wrap($content_item, '', $post_id); } $content = apply_filters(PT_CV_PREFIX_ . 'content_items_wrap', $content, $content_items, $current_page, $post_per_page); break; } // Join content $content_list = implode("\n", $content); // Custom attribute of a page $col_count = sprintf('data-cvc="%s"', (int) $dargs['number-columns']); $page_attr_ = apply_filters(PT_CV_PREFIX_ . 'page_attr', $col_count, $view_type, $content_items, $dargs); $page_attr = strip_tags($page_attr_); if (apply_filters(PT_CV_PREFIX_ . 'wrap_in_page', true)) { // Wrap items in 'page' wrapper $html = sprintf('<div id="%s" class="%s" %s>%s</div>', esc_attr(PT_CV_PREFIX . 'page' . '-' . $current_page), esc_attr(PT_CV_PREFIX . 'page'), $page_attr, $content_list); // Remove page attribute value $page_attr = ''; } else { $html = $content_list; } if ($nonpaging_or_firstpage) { // Get wrapper class of View $view_class = apply_filters(PT_CV_PREFIX_ . 'view_class', array(PT_CV_PREFIX . 'view', PT_CV_PREFIX . $view_type)); // ID for the wrapper $view_id = PT_CV_PREFIX . 'view-' . $id; $output = sprintf('<div class="%s" id="%s" %s>%s</div>', esc_attr(implode(' ', array_filter($view_class))), esc_attr($view_id), $page_attr, $html); do_action(PT_CV_PREFIX_ . 'store_view_data', $view_id); } else { $output = $html; } return $before_output . $output; }
/** * Wrap content of all items * * @param array $content_items The array of Raw HTML output (is not wrapped) of each item * @param int $current_page The current page * @param int $post_per_page The number of posts per page * @param int $id ID of View * * @return string Full HTML output for Content View */ static function content_items_wrap($content_items, $current_page, $post_per_page, $id) { $dargs = PT_CV_Functions::get_global_variable('dargs'); if (empty($content_items)) { return PT_CV_Functions::debug_output('empty content_items', self::no_post_found()); } // Assign as global variable PT_CV_Functions::set_global_variable('content_items', $content_items); $full_output = !defined('PT_CV_DOING_PAGINATION'); // 1. Before output $before_output = $full_output ? apply_filters(PT_CV_PREFIX_ . 'before_output_html', '') : ''; // 2. Output content $content = array(); $view_type = $dargs['view-type']; // Separate items by row, column switch ($view_type) { // Grid case 'grid': PT_CV_Html_ViewType::grid_wrapper($content_items, $content); break; // Collapsible List // Collapsible List case 'collapsible': PT_CV_Html_ViewType::collapsible_wrapper($content_items, $content); break; // Scrollable List // Scrollable List case 'scrollable': PT_CV_Html_ViewType::scrollable_wrapper($content_items, $content); break; default: foreach ($content_items as $post_id => $content_item) { $content[] = PT_CV_Html::content_item_wrap($content_item, '', $post_id); } $content = apply_filters(PT_CV_PREFIX_ . 'content_items_wrap', $content, $content_items, $current_page, $post_per_page); break; } // Join content $content_list = implode("\n", $content); // Wrap in Page if (apply_filters(PT_CV_PREFIX_ . 'wrap_in_page', true)) { $cols = sprintf('data-cvc="%s"', (int) $dargs['number-columns']); $page_attr = apply_filters(PT_CV_PREFIX_ . 'page_attr', $cols, $view_type, $content_items); $html = sprintf('<div id="%s" class="%s" %s>%s</div>', PT_CV_PREFIX . 'page' . '-' . $current_page, PT_CV_PREFIX . 'page', $page_attr, $content_list); } else { $html = $content_list; } // Wrap in View if ($full_output) { $use_grid = PT_CV_Functions::get_global_variable('use_grid', true); $view_class = apply_filters(PT_CV_PREFIX_ . 'view_class', array(PT_CV_PREFIX . 'view', PT_CV_PREFIX . $view_type, $use_grid ? PT_CV_PREFIX . 'colsys' : '')); $view_id = PT_CV_PREFIX . 'view-' . $id; $output = sprintf('<div class="%s" id="%s">%s</div>', esc_attr(implode(' ', array_filter($view_class))), $view_id, $html); // Keep this action for CVP < 3.5 do_action(PT_CV_PREFIX_ . 'store_view_data', $view_id); } else { $output = $html; } return $before_output . $output; }