* @license GPL-2.0+
* @link http://www.contentviewspro.com/
* @copyright 2014 PT Guy
*/
if ( !class_exists( 'PT_CV_Html' ) ) {
/**
* @name PT_CV_Html
* @todo related HTML functions: Define HTML layout, Set class name...
*/
class PT_CV_Html {
// Store directory of selected view_types
static $view_type_dir = array();
// Store all selected styles
static $style = array();
/**
* return class for Panel (Group of) group of params
*
* @return string
*/
static function html_panel_group_class() {
return 'panel-group';
}
/**
* Return ID for Panel (Group of) group of params
*
* @param string $id Unique id of element
*
* @return string
*/
static function html_panel_group_id( $id ) {
return 'panel-group-' . $id;
}
/**
* Return class for group of params
*
* @return string
*/
static function html_group_class() {
return PT_CV_PREFIX . 'group';
}
/**
* Return ID for group of params
*
* @param string $id Unique id of element
*
* @return string
*/
static function html_group_id( $id ) {
return self::html_group_class() . '-' . $id;
}
/**
* Collapse HTML
*
* @param string $parent_id Id of parent element
* @param string $id Unique id of element
* @param string $heading Heading text
* @param string $content Content
* @param bool $show Show/hide the content
*/
static function html_collapse_one( $parent_id, $id, $heading, $content = '', $show = true ) {
$class = $show ? 'in' : '';
ob_start();
?>
', esc_attr( $dimension ), esc_attr( $class ), __( 'Loading...', 'content-views-query-and-display-post-page' ), self::loading_img_src(), PT_CV_PREFIX . 'clear-pagination' );
return apply_filters( PT_CV_PREFIX_ . 'loading_image', $img );
}
static function loading_img_src() {
return apply_filters( PT_CV_PREFIX_ . 'loading_image_url', 'data:image/gif;base64,R0lGODlhDwAPALMPAMrKygwMDJOTkz09PZWVla+vr3p6euTk5M7OzuXl5TMzMwAAAJmZmWZmZszMzP///yH/C05FVFNDQVBFMi4wAwEAAAAh+QQFCgAPACwAAAAADwAPAAAEQvDJaZaZOIcV8iQK8VRX4iTYoAwZ4iCYoAjZ4RxejhVNoT+mRGP4cyF4Pp0N98sBGIBMEMOotl6YZ3S61Bmbkm4mAgAh+QQFCgAPACwAAAAADQANAAAENPDJSRSZeA418itN8QiK8BiLITVsFiyBBIoYqnoewAD4xPw9iY4XLGYSjkQR4UAUD45DLwIAIfkEBQoADwAsAAAAAA8ACQAABC/wyVlamTi3nSdgwFNdhEJgTJoNyoB9ISYoQmdjiZPcj7EYCAeCF1gEDo4Dz2eIAAAh+QQFCgAPACwCAAAADQANAAAEM/DJBxiYeLKdX3IJZT1FU0iIg2RNKx3OkZVnZ98ToRD4MyiDnkAh6BkNC0MvsAj0kMpHBAAh+QQFCgAPACwGAAAACQAPAAAEMDC59KpFDll73HkAA2wVY5KgiK5b0RRoI6MuzG6EQqCDMlSGheEhUAgqgUUAFRySIgAh+QQFCgAPACwCAAIADQANAAAEM/DJKZNLND/kkKaHc3xk+QAMYDKsiaqmZCxGVjSFFCxB1vwy2oOgIDxuucxAMTAJFAJNBAAh+QQFCgAPACwAAAYADwAJAAAEMNAs86q1yaWwwv2Ig0jUZx3OYa4XoRAfwADXoAwfo1+CIjyFRuEho60aSNYlOPxEAAAh+QQFCgAPACwAAAIADQANAAAENPA9s4y8+IUVcqaWJ4qEQozSoAzoIyhCK2NFU2SJk0hNnyEOhKR2AzAAj4Pj4GE4W0bkJQIAOw==' );
}
/**
* Html output for button
*
* @param string $style Bootstrap type of button
* @param string $text Text of button
* @param string $class Class of button
* @param string $size Size of button
*
* @return string
*/
static function html_button( $style, $text = 'Button', $class = '', $size = '' ) {
return sprintf( '', $style, $class, $size, $text );
}
/**
* Html output for a link, but style as button
*
* @deprecated since version 2.0
* @param string $link Value for href attribute of link
* @param string $style Bootstrap type of button
* @param string $text Text of button
* @param string $class Class of button
* @param string $size Size of button
*
* @return string
*/
static function link_button( $link, $style, $text = 'Button', $class = '', $size = '' ) {
return sprintf( '%s', $link, $style, $class, $size, $text );
}
/**
* Get Output HTML of a View type
*
* @param string $view_type The view type (grid, collapse...)
* @param object $post The post object
* @param string $style The style of view type (main, style2...)
*/
static function view_type_output( $view_type, $post, $post_idx = 0, $style = 'main' ) {
$dargs = PT_CV_Functions::get_global_variable( 'dargs' );
$content = NULL;
if ( empty( $view_type ) ) {
return $content;
}
// Get view type directory
$view_type_dir = apply_filters( PT_CV_PREFIX_ . 'view_type_dir', PT_CV_VIEW_TYPE_OUTPUT, $view_type ) . $view_type;
// Compatible code for other Pro versions
$view_type_dir = apply_filters( PT_CV_PREFIX_ . 'view_type_dir_special', $view_type_dir, $view_type );
if ( strpos( $view_type_dir, $view_type . $view_type ) !== false ) {
$view_type_dir = str_replace( $view_type . $view_type, $view_type, $view_type_dir );
}
// Get asset directory
$view_type_assets_dir = apply_filters( PT_CV_PREFIX_ . 'view_type_asset', $view_type_dir, $view_type );
if ( is_dir( $view_type_dir ) ) {
// Store view type & asset information
self::$view_type_dir[] = $view_type_assets_dir;
self::$style[] = $style;
// Generate HTML output of all content fields
$fields_html = array();
$other_dargs = apply_filters( PT_CV_PREFIX_ . 'dargs_others', $dargs, $post_idx );
foreach ( (array) $other_dargs[ 'fields' ] as $field_name ) {
// Get settings of fields
$fargs = isset( $other_dargs[ 'field-settings' ] ) ? $other_dargs[ 'field-settings' ] : array();
$fargs[ 'layout-format' ] = $other_dargs[ 'layout-format' ];
// Get HTML output of field
$item_html = self::field_item_html( $field_name, $post, $fargs );
if ( $item_html ) {
$fields_html[ $field_name ] = $item_html;
}
}
$fields_html = apply_filters( PT_CV_PREFIX_ . 'fields_html', $fields_html, $post );
$content = apply_filters( PT_CV_PREFIX_ . 'view_type_custom_output', $content, $fields_html, $post );
if ( !$content ) {
// Get HTML content of view type, with specific style
$file_path = apply_filters( PT_CV_PREFIX_ . 'view_type_file', $view_type_dir . '/' . 'html' . '/' . $style . '.' . 'php' );
if ( file_exists( $file_path ) ) {
ob_start();
// Include, not include_once
include $file_path;
$content = ob_get_clean();
}
}
}
return $content;
}
/**
* Wrap content of a item
*
* @param array $html_item The HTML output of a item
* @param string $class The extra wrapper class of a item, such as col span
* @param array $post_id The post ID
*
* @return string Full HTML output of a item
*/
static function content_item_wrap( $html_item, $class = '', $post_id = 0 ) {
if ( empty( $html_item ) ) {
return '';
}
$classes = array( $class );
$classes[] = PT_CV_PREFIX . 'content-item';
$classes[] = PT_CV_PREFIX . PT_CV_Functions::setting_value( PT_CV_PREFIX . 'layout-format' );
$item_class = apply_filters( PT_CV_PREFIX_ . 'content_item_class', $classes, $post_id );
$item_filter = apply_filters( PT_CV_PREFIX_ . 'content_item_filter_value', '', $post_id );
ob_start();
do_action( PT_CV_PREFIX_ . 'item_extra_html', $post_id );
$html_item .= ob_get_clean();
$result = sprintf( '