]*class=["\']edd-add-to-cart)/' , '$1 edd-has-js', $html );
}
}
break;
// Show Custom Fields
case 'custom-fields':
$html = cvp_ctf_html( $post );
break;
// New WooCommerce options for blocks
case 'wooprice':
if ( $post_type === 'product' && function_exists( 'wc_get_product' ) ) {
$product = wc_get_product( $post->ID );
$price = $product->get_price_html();
$html = '' . $price . '
';
}
break;
case 'wooatc':
if ( $post_type === 'product' ) {
$atc = do_shortcode( sprintf( '[add_to_cart id="%s" style="" show_price="false"]', $post->ID ) );
$html = '' . $atc . '
';
}
break;
}
return $html;
}
/**
* Enable/Disable Read more button
*
* @param string $args The readmore text
* @param array $fargs The settings of Content
*/
public static function filter_field_content_readmore_enable( $args, $fargs ) {
// not empty => true => show
$args = !empty( $fargs[ 'readmore' ] );
return $args;
}
/**
* Filter Read more class
*
* @param string $args Current class
* @param array $fargs The settings of Content
*/
public static function filter_field_content_readmore_class( $args, $fargs ) {
if ( !empty( $fargs[ 'content' ][ 'readmore-textlink' ] ) ) {
$args = PT_CV_PREFIX . 'textlink';
} else {
if ( PT_CV_Functions::setting_value( PT_CV_PREFIX . 'font-text-align-readmore' ) === 'center' ) {
$args .= ' cvprmct ';
}
}
return $args;
}
/**
* Filter Read more seperate tag
*
* @param string $args Current class
* @param array $fargs The settings of Content
*/
public static function filter_field_content_readmore_seperated( $args, $fargs ) {
if ( !empty( $fargs[ 'content' ][ 'readmore-textlink' ] ) ) {
$args = ' ';
}
return $args;
}
/**
* Filter post title
*
* @param string $args The excerpt output
* @param array $fargs The field display settings
* @param int $post
*
* @return string
*/
public static function filter_field_title_result( $args, $fargs, $post ) {
// Custom title from custom field: native, ACF
if ( !empty( $post->cvp_custom_title ) ) {
$args = force_balance_tags( $post->cvp_custom_title );
}
// Strip Title
if ( isset( $fargs[ 'title' ] ) ) {
if ( !empty( $fargs[ 'title' ][ 'length' ] ) ) {
$desired_length = intval( $fargs[ 'title' ][ 'length' ] );
// fix untrackable 500 error in hosting which doesn't enable/install relative module
$this_length = function_exists( 'mb_strlen' ) ? mb_strlen( $args, CVP_ENCODING ) : strlen( $args );
if ( $desired_length < $this_length ) {
$args = html_entity_decode( $args, ENT_QUOTES, CVP_ENCODING );
$args = strip_tags( $args );
$sub_title = function_exists( 'mb_substr' ) ? mb_substr( $args, 0, $desired_length, CVP_ENCODING ) : substr( $args, 0, $desired_length );
$args = $sub_title . '...';
}
}
}
return $args;
}
public static function filter_tag_to_remove( $args ) {
$var = PT_CV_Functions::setting_value( PT_CV_PREFIX . 'field-excerpt-remove-tag' );
if ( $var ) {
$var = PT_CV_Functions::setting_value( PT_CV_PREFIX . 'field-excerpt-tag-to-remove' );
$tags = explode( ',', sanitize_text_field( $var ) );
$args = array_merge( $args, array_filter( $tags ) );
}
return $args;
}
/**
* Allow all HTML tags in excerpt
* @since 4.6.0
* @param type $args
* @return type
*/
public static function filter_strip_tags( $args ) {
if ( PT_CV_Functions::setting_value( PT_CV_PREFIX . 'field-excerpt-allow_html' ) === 'all-tags' ) {
$args = false;
}
return $args;
}
/* Allow more HTML tags in excerpt
* @since 6.2
*/
public static function filter_allowable_tags( $args ) {
if ( PT_CV_Functions::setting_value( PT_CV_PREFIX . 'field-excerpt-allow_html' ) === 'more-tags' ) {
array_push( $args, '', '' , '' );
}
return $args;
}
/**
* Filter post excerpt
*
* @param string $args The excerpt output
* @param type $fargs The field display settings
* @param type $post The post object
*
* @return string
*/
public static function filter_field_content_excerpt( $args, $fargs, $post ) {
// Prevent recursive call
if ( empty( $fargs ) ) {
return $args;
}
// Get manual excerpt
if ( !empty( $fargs[ 'content' ][ 'manual' ] ) && !empty( $post->post_excerpt ) ) {
$args = $post->post_excerpt;
if ( $fargs[ 'content' ][ 'manual' ] === 'origin' ) {
$GLOBALS[ 'cv_excerpt_type' ] = 'manual';
}
}
// Apply filters, do shortcodes
if ( !empty( $fargs[ 'content' ][ 'enable_filter' ] ) ) {
$args = apply_filters( 'the_content', $args );
}
// Final filter
$args = apply_filters( PT_CV_PREFIX_ . 'field_manual_excerpt', $args, $fargs, $post );
return $args;
}
/**
* Append ... to Excerpt or not
*
* @param array $args
*/
public static function filter_field_excerpt_dots( $args, $fargs ) {
$args = empty( $fargs[ 'content' ][ 'hide_dots' ] );
return $args;
}
/**
* Modify assets folder of View type
*
* @param string $args The path to assets folder of view type
* @param string $view_type The view type
*/
public static function filter_view_type_asset( $args, $view_type ) {
$path = PT_CV_VIEW_TYPE_OUTPUT_PRO . $view_type;
if ( is_dir( $path ) ) {
$args = $path;
}
return $args;
}
/**
* Modify the list of fields to get
*
* @param string $args Array of fields
* @param string $post_idx Index of current post
*/
public static function filter_dargs_others( $args, $post_idx ) {
$view_type = PT_CV_Functions::get_global_variable( 'view_type' );
// Simplify fields for other posts of "One and others" layout
if ( $view_type === 'one_others' && $post_idx > 0 ) {
$args[ 'layout-format' ] = '2-col';
$show_fields = $fields_to_show = isset( $args[ 'view-type-settings' ][ 'show-fields' ] ) ? $args[ 'view-type-settings' ][ 'show-fields' ] : array( 'thumbnail', 'title', 'meta-fields' );
foreach ( $show_fields as $idx => $value ) {
foreach ( array( 'content', 'meta-fields' ) as $field ) {
if ( strpos( $value, $field ) !== false ) {
$show_fields[ $idx ] = $field;
}
}
}
$args[ 'fields' ] = apply_filters( PT_CV_PREFIX_ . 'one_others_fields', array_unique( $show_fields ) );
if ( in_array( 'thumbnail', $fields_to_show ) ) {
$thumbnail_width = !empty( $args[ 'view-type-settings' ][ 'thumbnail-width-others' ] ) ? (int) $args[ 'view-type-settings' ][ 'thumbnail-width-others' ] : 150;
$thumbnail_height = !empty( $args[ 'view-type-settings' ][ 'thumbnail-height-others' ] ) ? (int) $args[ 'view-type-settings' ][ 'thumbnail-height-others' ] : null;
$args[ 'field-settings' ][ 'thumbnail' ][ 'size' ] = apply_filters( PT_CV_PREFIX_ . 'one_others_thumbnail_size', PT_CV_PREFIX . 'custom' );
$args[ 'field-settings' ][ 'thumbnail' ][ 'size-custom-width' ] = apply_filters( PT_CV_PREFIX_ . 'one_others_thumbnail_size_width', $thumbnail_width );
$args[ 'field-settings' ][ 'thumbnail' ][ 'size-custom-height' ] = apply_filters( PT_CV_PREFIX_ . 'one_others_thumbnail_size_height', $thumbnail_height );
// Store this custom size
PT_CV_Functions::set_global_variable( 'image_sizes_others', array( $thumbnail_width, $thumbnail_height ) );
$args[ 'field-settings' ][ 'thumbnail' ][ 'position' ] = 'left';
}
// Excerpt
if ( in_array( 'content', $fields_to_show ) ) {
$args[ 'field-settings' ][ 'content' ][ 'show' ] = 'excerpt';
$args[ 'field-settings' ][ 'content' ][ 'length' ] = apply_filters( PT_CV_PREFIX_ . 'one_others_excerpt_length', PT_CV_Functions::setting_value( PT_CV_PREFIX . 'field-excerpt-length' ) );
unset( $args[ 'field-settings' ][ 'content' ][ 'readmore' ] );
}
if ( in_array( 'full-content', $fields_to_show ) ) {
$args[ 'field-settings' ][ 'content' ][ 'show' ] = 'full';
unset( $args[ 'field-settings' ][ 'content' ][ 'readmore' ] );
}
if ( in_array( 'readmore', $fields_to_show ) ) {
$args[ 'field-settings' ][ 'content' ][ 'readmore' ] = 'yes';
if ( !in_array( 'content', $fields_to_show ) ) {
$args[ 'fields' ][] = 'content';
$args[ 'field-settings' ][ 'content' ][ 'show' ] = 'excerpt';
$args[ 'field-settings' ][ 'content' ][ 'length' ] = '0';
}
}
if ( in_array( 'meta-fields', $fields_to_show ) ) {
$args[ 'field-settings' ][ 'meta-fields' ][ 'date' ] = 'yes';
}
if ( in_array( 'meta-fields-taxonomy', $fields_to_show ) ) {
$args[ 'field-settings' ][ 'meta-fields' ][ 'taxonomy' ] = 'yes';
}
#ch986
PT_CV_Functions::set_global_variable( 'soft_resize', true );
}
// Show special field
if ( PT_CV_Functions::setting_value( PT_CV_PREFIX . 'meta-fields-taxonomy-special-place' ) && PT_CV_Functions::setting_value( PT_CV_PREFIX . 'show-field-thumbnail' ) ) {
$args[ 'fields' ][] = 'special-field';
PT_CV_Functions::set_global_variable( 'special-field', 'taxonomy' );
}
return $args;
}
/**
* Filter directory of Pro View type
*
* @param string $args The path to main folder of view type
* @param string $view_type The view type
*
* @return string
*/
public static function filter_view_type_dir( $args, $view_type ) {
$view_types_pro = array_keys( PT_CV_Values_Pro::view_type_pro() );
if ( in_array( $view_type, $view_types_pro ) ) {
$args = PT_CV_VIEW_TYPE_OUTPUT_PRO;
}
return $args;
}
/**
* Filter directory of Pro View type
*
* @param string $args The path to main folder of view type
* @param string $view_type The view type
*
* @return string
*/
public static function filter_view_type_dir_special( $args, $view_type ) {
if ( ($view_type == 'masonry' ) ) {
$args = PT_CV_VIEW_TYPE_OUTPUT_PRO . 'pinterest';
}
return $args;
}
/**
* Add toggle icon to Scrollable item
*
* @param string $args HTML of toggle icon
*
* @return string
*/
public static function filter_scrollable_toggle_icon( $args ) {
$args = '';
return $args;
}
/**
* Filter interval for Scrollable List
*
* @param string $args The interval value
*/
public static function filter_scrollable_interval( $args ) {
$dargs = PT_CV_Functions::get_global_variable( 'dargs' );
$carousel_settings = !empty( $dargs[ 'view-type-settings' ] ) ? $dargs[ 'view-type-settings' ] : array();
$interval = isset( $carousel_settings[ 'interval' ] ) ? (int) $carousel_settings[ 'interval' ] : 5;
$args = !isset( $carousel_settings[ 'auto-cycle' ] ) ? 'false' : $interval * 1000;
return $args;
}
/**
* Filter default value of setting options for Scrollable List
*
* @param string $args The default value
*/
public static function filter_scrollable_fields_enable( $args ) {
$args = 0;
return $args;
}
// Remove the class w-img or wo-img and its CSS
public static function filter_scrollable_caption_class( $args ) {
if ( PT_CV_Functions::setting_value( PT_CV_PREFIX . 'scrollable-textbelow' ) ) {
unset( $args[ 1 ] );
}
return $args;
}
/**
* Filter custom data attributes for a page
*
* @param string $view_type The view type
* @param array $content_items The items array
*/
public static function filter_page_attr( $args, $view_type, $content_items ) {
# Shuffle filter: Show all posts of term on pagination
if ( PT_CV_Functions::get_global_variable( 'enable_shuffle_filter' ) ) {
if ( PT_CV_Functions::setting_value( PT_CV_PREFIX . 'enable-pagination' ) ) {
$args .= sprintf( ' data-sfpp="%s"', (int) PT_CV_Functions::setting_value( PT_CV_PREFIX . 'pagination-items-per-page' ) );
if ( PT_CV_Functions::setting_value( PT_CV_PREFIX . 'taxonomy-filter-show-all' ) ) {
$args .= ' data-sfshowall="1"';
}
if ( PT_CV_Functions::setting_value( PT_CV_PREFIX . 'taxonomy-filter-trigger-pagination' ) ) {
$args .= ' data-sftp="1"';
}
}
if ( $tax_relation = PT_CV_Functions::setting_value( PT_CV_PREFIX . 'taxonomy-relation' ) ) {
$args .= sprintf( ' data-sfop="%s"', esc_attr( strtolower( $tax_relation ) ) );
}
}
if ( PT_CV_Functions::get_global_variable( 'view_type' ) === 'grid' && PT_CV_Functions::setting_value( PT_CV_PREFIX . 'grid-same-height' ) ) {
$args .= ' data-cvct="' . (int) PT_CV_Functions::setting_value( PT_CV_PREFIX . 'resp-tablet-number-columns' ) . '"';
$args .= ' data-cvcm="' . (int) PT_CV_Functions::setting_value( PT_CV_PREFIX . 'resp-number-columns' ) . '"';
}
if ( PT_CV_Functions::get_global_variable( 'collapsible_shuffle' ) ) {
$args .= ' ' . sprintf( 'id="%s"', PT_CV_Html_Pro::collapsible_parent_id() );
}
// Fix the layout & width of other posts, on desktop only
if ( PT_CV_Functions::get_global_variable( 'view_type' ) === 'one_others' ) {
$args .= ' data-cvco="' . (int) PT_CV_Functions::setting_value( PT_CV_PREFIX . 'one_others-number-columns-others' ) . '"';
}
return $args;
}
public static function filter_page_class( $args ) {
if ( PT_CV_Functions::get_global_variable( 'collapsible_shuffle' ) ) {
$args .= ' ' . 'panel-group';
}
return $args;
}
/**
* Filter elements of Collapsible
* @since 4.3
*
* @param type $args
* @param type $params
* @return type
*/
public static function filter_collapsible_filters( $args, $params ) {
if ( PT_CV_Functions::get_global_variable( 'collapsible_shuffle' ) ) {
if ( !empty( $params[ 0 ] ) ) {
switch ( $params[ 0 ] ) {
case 'random_id':
$args = PT_CV_Html_Pro::collapsible_parent_id();
break;
case 'output':
$args = implode( "\n", $params[ 1 ] );
break;
}
}
}
return $args;
}
/**
* Whether or not to wrap items in a page
*
* @param bool $args Wrap or not
*/
public static function filter_wrap_in_page( $args ) {
$dargs = PT_CV_Functions::get_global_variable( 'dargs' );
if ( PT_CV_Functions::setting_value( PT_CV_PREFIX . 'enable-pagination' ) ) {
if ( $dargs[ 'pagination-settings' ][ 'type' ] === 'ajax' ) {
if ( isset( $dargs[ 'pagination-settings' ][ 'style' ] ) && in_array( $dargs[ 'pagination-settings' ][ 'style' ], array( 'loadmore', 'infinite' ) ) ) {
// Not wrap only if called by Ajax request. If access URL directly with ?_page=N, must wrap.
if ( defined( 'DOING_AJAX' ) && DOING_AJAX && !empty( $_POST[ 'action' ] ) && $_POST[ 'action' ] == 'pagination_request' ) {
$args = false;
}
}
}
}
if ( $dargs[ 'view-type' ] === 'timeline' ) {
$args = false;
}
return $args;
}
/**
* Filter wrapper HTML of list of items by view type
*
* @param array $content The output array
* @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
*/
public static function filter_content_items_wrap( $content, $content_items, $current_page, $post_per_page ) {
$view_type = PT_CV_Functions::get_global_variable( 'view_type' );
if ( $view_type === 'pinterest' ) {
$content = PT_CV_Html_ViewType_Pro::pinterest_wrapper( $content_items );
} elseif ( $view_type === 'masonry' ) {
$content = PT_CV_Html_ViewType_Pro::masonry_wrapper( $content_items );
} elseif ( $view_type === 'timeline' ) {
$content = PT_CV_Html_ViewType_Pro::timeline_wrapper( $content_items, $current_page, $post_per_page );
} elseif ( $view_type === 'glossary' ) {
$content = PT_CV_Html_ViewType_Pro::glossary_wrapper( $content_items, $current_page, $post_per_page );
} elseif ( $view_type === 'one_others' ) {
$content = PT_CV_Html_ViewType_Pro::one_others_wrapper( $content_items, $current_page, $post_per_page );
}
return $content;
}
/**
* Filter display settings value
*
* @param array $args The settings array of Fields
*/
public static function filter_all_display_settings( $args ) {
$view_settings = PT_CV_Functions::get_global_variable( 'view_settings' );
$args[ 'view-style' ] = array();
$args[ 'view-style' ][ 'font' ] = PT_CV_Functions::settings_values_by_prefix( PT_CV_PREFIX . 'font-' );
$args[ 'view-style' ][ 'margin' ] = PT_CV_Functions::settings_values_by_prefix( PT_CV_PREFIX . 'margin-value-' );
$args[ 'view-style' ][ 'item-margin' ] = PT_CV_Functions::settings_values_by_prefix( PT_CV_PREFIX . 'item-margin-value-' );
$args[ 'view-style' ][ 'item-padding' ] = PT_CV_Functions::settings_values_by_prefix( PT_CV_PREFIX . 'item-padding-value-' );
$args[ 'view-style' ][ 'others' ] = PT_CV_Functions::settings_values_by_prefix( PT_CV_PREFIX . 'style-' );
if ( PT_CV_Functions::setting_value( PT_CV_PREFIX . 'field-thumbnail-style', $view_settings ) === 'img-rounded' ) {
$args[ 'view-style' ][ 'border-radius' ] = PT_CV_Functions::setting_value( PT_CV_PREFIX . 'thumbnail-border-radius', $view_settings );
}
$args[ 'taxonomy-filter' ] = PT_CV_Functions::setting_value( PT_CV_PREFIX . 'taxonomy', $view_settings );
$ffcache = PT_CV_Functions::setting_value( PT_CV_PREFIX . 'scrollable-ffcache', $view_settings );
if ( PT_CV_Functions::get_global_variable( 'view_type' ) === 'scrollable' && empty( $ffcache ) ) {
// Only do this if has navigation or indicator, otherwise users can't see other posts
if ( array_key_exists( 'navigation', $args[ 'view-type-settings' ] ) || array_key_exists( 'indicator', $args[ 'view-type-settings' ] ) || array_key_exists( 'auto-cycle', $args[ 'view-type-settings' ] ) ) {
if ( PT_CV_Functions_Pro::check_device( 'mobile' ) ) {
$mol_col = PT_CV_Functions::setting_value( PT_CV_PREFIX . 'resp-number-columns', $view_settings );
if ( !empty( $mol_col ) ) {
$args[ 'number-columns' ] = $mol_col;
}
} elseif ( PT_CV_Functions_Pro::check_device( 'tablet' ) ) {
$tab_col = PT_CV_Functions::setting_value( PT_CV_PREFIX . 'resp-tablet-number-columns', $view_settings );
if ( !empty( $tab_col ) ) {
$args[ 'number-columns' ] = $tab_col;
}
}
}
}
return $args;
}
public static function filter_selected_terms( $terms, $taxonomy ) {
// Get all IF no terms selected
$view_settings = PT_CV_Functions::get_global_variable( 'view_settings' );
if ( empty( $terms ) && PT_CV_Functions_Pro::taxonomy_custom_setting_enable( $view_settings, 'taxonomy-term-info', 'as_output' ) ) {
$all_terms = array();
PT_CV_Values::term_of_taxonomy( $taxonomy, $all_terms, array(), 'object' );
$terms = array_keys( $all_terms[ $taxonomy ] );
}
return $terms;
}
/**
* Order settings args
*
* @param array $args
*/
public static function filter_order_setting( $args ) {
/**
* Order by "View count"
* Backward compatibility with CV < 1.8.9, CVP < 3.9.5
*/
if ( $args[ 'orderby' ] == 'view_count' ) {
$args[ 'orderby' ] = '';
$args[ 'order' ] = '';
}
// Order by "Custom field"
$metadata_order = PT_CV_Functions::settings_values_by_prefix( PT_CV_PREFIX . 'order-custom-field-' );
if ( $metadata_order ) {
if ( !empty( $metadata_order[ 'key' ] ) && is_array( $metadata_order[ 'key' ] ) ) {
// Get format of custom date field for sorting, before it is eliminated by following filter
self::sort_ctf_date_format( $metadata_order );
$metadata_order = apply_filters( PT_CV_PREFIX_ . 'custom_field_order_settings', $metadata_order );
$cvp_meta_query_order = $orderby = array();
foreach ( $metadata_order[ 'key' ] as $idx => $field ) {
if ( $field ) {
$key = CVP_CTF_ORDER_PREFIX . $field;
$type = $metadata_order[ 'type' ][ $idx ];
$cvp_meta_query_order[ $key ] = array(
'key' => $field,
'compare' => 'EXISTS',
'type' => $type === 'DECIMAL' ? 'DECIMAL(15,5)' : $type,
);
$orderby[ $key ] = $metadata_order[ 'order' ][ $idx ];
}
}
PT_CV_Functions::set_global_variable( 'meta_query_order', $cvp_meta_query_order );
if ( $orderby ) {
// If ordered by common field
if ( array_filter( $args ) ) {
$orderby[ $args[ 'orderby' ] ] = $args[ 'order' ];
}
/* @since 5.3.4 Append id desc to make the consistent results when there are many posts have same values of custom fields */
$orderby[ 'ID' ] = 'DESC';
$args = array(
'orderby' => $orderby
);
}
}
}
if ( $args[ 'orderby' ] === 'dragdrop' ) {
$args[ 'orderby' ] = '';
$args[ 'order' ] = '';
}
// Prevent duplicated posts in pagination when they have same values
if ( in_array( $args[ 'orderby' ], array( 'post_type', 'comment_count', 'post_author' ) ) ) {
$args[ 'orderby' ] .= ' ID';
}
return $args;
}
/**
* Get format of custom date field for sorting
* @param array $metadata_order
*/
public static function sort_ctf_date_format( $metadata_order ) {
$cvp_orderby_dateformat = $cvp_thousand_commas_fields = array();
foreach ( $metadata_order[ 'key' ] as $idx => $field ) {
if ( $field ) {
$type = $metadata_order[ 'type' ][ $idx ];
// Get date format to modify the MySQL orderby statement
if ( in_array( $type, array( 'DATE', 'DATETIME' ) ) ) {
$dfm = trim( $metadata_order[ 'date-format' ][ $idx ] );
if ( !empty( $dfm ) ) {
$cvp_orderby_dateformat[ $idx ] = $dfm;
}
}
if ( $type === 'NUMERIC' ) {
$tcm = isset( $metadata_order[ 'thousand-commas' ][ $idx ] ) ? trim( $metadata_order[ 'thousand-commas' ][ $idx ] ) : null;
if ( !empty( $tcm ) ) {
$cvp_thousand_commas_fields[ $idx ] = $tcm;
}
}
}
}
PT_CV_Functions::set_global_variable( 'orderby_dateformat', $cvp_orderby_dateformat );
PT_CV_Functions::set_global_variable( 'thousand_commas_fields', $cvp_thousand_commas_fields );
}
/**
* Validate settings filter
*
* @param string $errors The error message
* @param array $args The Query parameters array
*/
public static function filter_validate_settings( $errors, $args ) {
$dargs = PT_CV_Functions::get_global_variable( 'dargs' );
// Prefix string for error message
$messages = array(
'field' => array(
'select' => __( 'Please select an option in', 'content-views-query-and-display-post-page' ) . ' : ',
'text' => __( 'Please set value in', 'content-views-query-and-display-post-page' ) . ' : ',
),
'tab' => array(
'filter' => __( 'Filter Settings', 'content-views-query-and-display-post-page' ),
'display' => __( 'Display Settings', 'content-views-query-and-display-post-page' ),
),
);
// View type
if ( !empty( $dargs[ 'view-type' ] ) ) {
switch ( $dargs[ 'view-type' ] ) {
case 'scrollable':
if ( empty( $dargs[ 'number-columns' ] ) ) {
$errors[] = $messages[ 'field' ][ 'text' ] . $messages[ 'tab' ][ 'display' ] . ' > ' . __( 'Layout', 'content-views-query-and-display-post-page' ) . ' > ' . __( 'Items per row', 'content-views-query-and-display-post-page' );
}
if ( empty( $dargs[ 'number-rows' ] ) ) {
$errors[] = $messages[ 'field' ][ 'text' ] . $messages[ 'tab' ][ 'display' ] . ' > ' . __( 'Layout', 'content-views-query-and-display-post-page' ) . ' > ' . __( 'Rows per slide', 'content-views-pro' );
}
break;
case 'pinterest':
if ( empty( $dargs[ 'number-columns' ] ) ) {
$errors[] = $messages[ 'field' ][ 'text' ] . $messages[ 'tab' ][ 'display' ] . ' > ' . __( 'Layout', 'content-views-query-and-display-post-page' ) . ' > ' . __( 'Items per row', 'content-views-query-and-display-post-page' );
}
break;
}
}
return array_filter( $errors );
}
/**
* Filter array of parameters for Wp_Query
*
* @param type $args The Query parameters array
*
* @return array $args
*/
public static function filter_query_parameters( $args ) {
$view_settings = PT_CV_Functions::get_global_variable( 'view_settings' );
$advanced_settings = (array) PT_CV_Functions::setting_value( PT_CV_PREFIX . 'advanced-settings' );
$content_type = PT_CV_Functions::setting_value( PT_CV_PREFIX . 'content-type', $view_settings );
// Quick filter WooCommerce Product (featured/best seller/... products)
if ( $content_type == 'product' ) {
$products_list = PT_CV_Functions::setting_value( PT_CV_PREFIX . 'products-list', $view_settings );
$args = array_merge( $args, PT_CV_WooCommerce::query_parameters( $products_list ) );
}
$args = CVP_Replace_Layout::modify_query_params( $args );
PT_CV_Functions_Pro::filter_by_date( $args );
$args = self::filter_by_custom_field( $args );
$args = self::reuse_view( $args );
$args = CVP_ADVERT::modify_params( $args );
/**
* @deprecated since version 3.9.3
*/
if ( !empty( $view_settings[ PT_CV_PREFIX . 'include-current' ] ) ) {
global $post;
if ( !empty( $post->ID ) ) {
if ( !isset( $args[ 'post__in' ] ) ) {
$args[ 'post__in' ] = array();
}
$args[ 'post__in' ][] = $post->ID;
}
}
if ( !empty( $view_settings[ PT_CV_PREFIX . 'exclude-current' ] ) ) {
$current_post = (int) cvp_get_current_post_across_pagination();
if ( $current_post ) {
if ( !isset( $args[ 'post__not_in' ] ) ) {
$args[ 'post__not_in' ] = array();
}
$args[ 'post__not_in' ][] = $current_post;
}
}
if ( !empty( $view_settings[ PT_CV_PREFIX . 'exclude-pw-protected' ] ) ) {
$args[ 'has_password' ] = false;
}
if ( !empty( $view_settings[ PT_CV_PREFIX . 'exclude-children-posts' ] ) ) {
$args[ 'post_parent' ] = 0;
}
if ( empty( $args[ 'orderby' ] ) && !empty( $args[ 'post__in' ] ) ) {
$args[ 'orderby' ] = 'post__in';
}
if ( in_array( 'order', $advanced_settings ) && !empty( $args[ 'orderby' ] ) ) {
if ( $args[ 'orderby' ] == 'rand' ) {
// Random posts from "Include only"
if ( !empty( $args[ 'post__in' ] ) ) {
$limit = $args[ 'limit' ];
$count = count( $args[ 'post__in' ] );
if ( $count > $limit ) {
$args[ 'post__in' ] = (array) array_rand( array_flip( $args[ 'post__in' ] ), min( $limit, $count ) );
} else {
shuffle( $args[ 'post__in' ] );
}
}
// Disable suppress_filters when order randomly & enable pagination
$pagination_enable = PT_CV_Functions::setting_value( PT_CV_PREFIX . 'enable-pagination', $view_settings );
if ( !empty( $pagination_enable ) ) {
$args[ 'suppress_filters' ] = false;
// Bug: duplicated posts when order randonly & pagination
$args[ PT_CV_PREFIX . 'orp' ] = 1;
}
} elseif ( $args[ 'orderby' ] == 'title_human' ) {
$args[ 'orderby' ] = 'post_title';
$args[ 'suppress_filters' ] = false;
$args[ PT_CV_PREFIX . 'human_sort' ] = 1;
}
}
$cvp_orderby_dateformat = PT_CV_Functions::get_global_variable( 'orderby_dateformat' );
if ( !empty( $cvp_orderby_dateformat ) ) {
$args[ 'suppress_filters' ] = false;
$args[ PT_CV_PREFIX . 'ctf_sort_dfm' ] = $cvp_orderby_dateformat;
}
$fdf = PT_CV_Functions::get_global_variable( 'ctf_filter_dateformat' );
if ( !empty( $fdf ) ) {
$args[ 'suppress_filters' ] = false;
$args[ PT_CV_PREFIX . 'ctf_filter_dfm' ] = $fdf;
}
$cvp_tcm = PT_CV_Functions::get_global_variable( 'thousand_commas_fields' );
if ( !empty( $cvp_tcm ) ) {
$args[ 'suppress_filters' ] = false;
$args[ PT_CV_PREFIX . 'ctftcm' ] = $cvp_tcm;
}
// Post of current user
if ( in_array( 'author', $advanced_settings ) && PT_CV_Functions::wp_version_compare( '3.7' ) ) {
$author_current_user = !empty( $view_settings[ PT_CV_PREFIX . 'author-current-user' ] ) ? $view_settings[ PT_CV_PREFIX . 'author-current-user' ] : null;
$cur_uid = get_current_user_id();
if ( $cur_uid ) {
if ( $author_current_user === 'include' || isset( $view_settings[ PT_CV_PREFIX . 'author-include-current' ] ) ) {
$args[ 'author__in' ] = isset( $args[ 'author__in' ] ) ? $args[ 'author__in' ] : array();
$args[ 'author__in' ][] = $cur_uid;
} else if ( $author_current_user === 'exclude' || isset( $view_settings[ PT_CV_PREFIX . 'author-not-include-current' ] ) ) {
$args[ 'author__not_in' ] = isset( $args[ 'author__not_in' ] ) ? $args[ 'author__not_in' ] : array();
$args[ 'author__not_in' ][] = $cur_uid;
}
}
}
if ( PT_CV_Functions_Pro::has_translation_plugin() ) {
$args[ 'suppress_filters' ] = false;
}
/* show more posts that limit (then check in filter_check_post_visibility) to ensure showing enough & correct posts on each page */
$membership_plugin = PT_CV_Functions_Pro::has_access_restriction_plugin();
if ( $membership_plugin && in_array( 'check_access_restriction', $advanced_settings ) ) {
$args[ 'suppress_filters' ] = false;
$args[ 'posts_per_page_backup' ] = $args[ 'posts_per_page' ];
$args[ 'offset_backup' ] = $args[ 'offset' ];
// to reduce performance, don't get all posts, just get around the current page range
$current_page = (int) PT_CV_Functions::get_global_variable( 'current_page' );
$extend_val = (int) PT_CV_Functions::setting_value( PT_CV_PREFIX . 'extend-scope', null, 2 );
$args[ 'posts_per_page' ] = PT_CV_Functions_Pro::get_limit_value() * $current_page * $extend_val;
/* when ppp = -1, offset is ignored. now ppp is limited, so must reset */
$args[ 'offset' ] = 0;
}
// For Sticky posts
// @since 5.7.0
$sticky_option = PT_CV_Functions::setting_value( PT_CV_PREFIX . 'sticky-posts' );
if ( apply_filters( PT_CV_PREFIX_ . 'sticky_posts_dependence', true ) && $content_type !== 'post' ) {
$sticky_option = null;
}
if ( $sticky_option === 'prepend' ) {
$args[ 'suppress_filters' ] = false;
add_filter( 'posts_orderby', array( __CLASS__, 'prepend_matched_sticky_posts' ), 999, 2 );
}
if ( $sticky_option == 'prepend-all' ) {
$args[ 'suppress_filters' ] = false;
add_filter( 'the_posts', array( __CLASS__, 'prepend_all_sticky_posts' ), 999, 2 );
}
if ( $sticky_option == 'sticky-only' ) {
$sticky_post_ids = get_option( 'sticky_posts' );
$args[ 'post__in' ] = !empty( $sticky_post_ids ) ? $sticky_post_ids : array( 0 );
}
// Shuffle filter pagination
$sf_custom_data = !empty( $_POST[ 'custom_data' ] ) ? $_POST[ 'custom_data' ] : '';
if ( defined( 'PT_CV_DOING_PAGINATION' ) && isset( $sf_custom_data[ 'sf_taxo' ], $sf_custom_data[ 'sf_pids' ] ) ) {
// Use escape function later to prevent added double quotations
$sf_pid = $sf_custom_data[ 'sf_pids' ];
$taxo_terms = json_decode( wp_unslash( $sf_custom_data[ 'sf_taxo' ] ), true );
$taxo_operators = json_decode( wp_unslash( $sf_custom_data[ 'sf_opera' ] ), true );
$view_id = cv_sanitize_vid( $_POST[ 'sid' ] );
$modified = 0;
$view_tt = isset( $taxo_terms[ $view_id ] ) ? $taxo_terms[ $view_id ] : '';
$view_operators = isset( $taxo_operators[ $view_id ] ) ? $taxo_operators[ $view_id ] : '';
if ( is_array( $view_tt ) ) {
$subtax = array();
foreach ( $view_tt as $taxo => $terms ) {
if ( $terms !== 'all' && $terms !== '' ) {
$operator = 'IN';
if ( count( $terms ) > 1 ) {
if ( !empty( $view_operators[ $taxo ] ) && $view_operators[ $taxo ] === 'and' ) {
$operator = 'AND';
}
}
$subtax[ $taxo ] = array(
'taxonomy' => $taxo,
'field' => 'id',
'terms' => array_map( 'cv_esc_sql', str_replace( $taxo . '-', '', $terms ) ), //reverse shuffle_filter_key()
'include_children' => false,
'operator' => $operator,
);
}
}
if ( $subtax ) {
$relation = PT_CV_Functions::setting_value( PT_CV_PREFIX . 'taxonomy-relation' );
if ( $relation === 'AND' && !empty( $args[ 'tax_query' ] ) ) {
foreach ( $args[ 'tax_query' ] as $taxq ) {
if ( !empty( $taxq[ 'taxonomy' ] ) && !isset( $subtax[ $taxq[ 'taxonomy' ] ] ) ) {
$subtax[ $taxq[ 'taxonomy' ] ] = $taxq;
}
}
}
$args[ 'tax_query' ] = $subtax;
if ( count( $subtax ) > 1 ) {
$args[ 'tax_query' ][ 'relation' ] = $relation;
}
$show_all = PT_CV_Functions::setting_value( PT_CV_PREFIX . 'taxonomy-filter-show-all' );
$args[ 'posts_per_page' ] = !empty( $show_all ) ? 1000 : (int) PT_CV_Functions::setting_value( PT_CV_PREFIX . 'pagination-items-per-page' ); // -1 will ignore offset value
$modified++;
}
}
// Exclude shown posts of this View
$pids = isset( $sf_pid[ $view_id ] ) ? (array) json_decode( wp_unslash( $sf_pid[ $view_id ] ), true ) : array();
$to_exclude = array_filter( $pids );
if ( !empty( $to_exclude ) ) {
$args[ 'post__not_in' ] = array_merge( (array) $args[ 'post__not_in' ], array_map( 'intval', $to_exclude ) );
$modified++;
}
if ( $modified ) {
$args[ 'offset' ] = 0;
define( 'PT_CV_SHUFFLE_PAGINATION', true );
}
$args = apply_filters( PT_CV_PREFIX_ . 'query_args_sf_pagination', $args );
}
return $args;
}
/** Must run this after live filters handle (modify_query) or any similar things
* so the "filtered" custom fields are handled correctly, before merge with "sorted" custom fields
*/
public static function filter_query_params( $args ) {
/**
* Order by multi custom fields: need to combine & link meta_query to orderby array
* http://wordpress.stackexchange.com/a/246358/3687
*/
$cvp_meta_query_order = PT_CV_Functions::get_global_variable( 'meta_query_order' );
if ( $cvp_meta_query_order ) {
if ( !isset( $args[ 'meta_query' ] ) ) {
$args[ 'meta_query' ] = $cvp_meta_query_order;
} else {
// Remove key which existed in meta_query
foreach ( array_keys( $cvp_meta_query_order ) as $key_with_prefix ) {
$key = substr( $key_with_prefix, strlen( CVP_CTF_ORDER_PREFIX ) );
foreach ( $args[ 'meta_query' ] as $idx => $m_settings ) {
if ( isset( $m_settings[ 'key' ] ) && $m_settings[ 'key' ] === $key && $m_settings[ 'compare' ] === 'EXISTS' ) {
unset( $args[ 'meta_query' ][ $idx ] );
}
}
}
if ( count( $cvp_meta_query_order ) > 1 ) {
$cvp_meta_query_order[ 'relation' ] = 'AND';
}
$args[ 'meta_query' ] = array(
'relation' => 'AND',
$args[ 'meta_query' ],
$cvp_meta_query_order
);
}
}
return $args;
}
/**
* Whether or not to include posts of children taxonomies
*
* @param boolean $args
* @return boolean
*/
public static function filter_include_children( $args ) {
// Only process if $args = true (default value)
if ( $args === true ) {
$view_settings = PT_CV_Functions::get_global_variable( 'view_settings' );
$exclude = PT_CV_Functions::setting_value( PT_CV_PREFIX . 'taxonomy-' . 'exclude-children', $view_settings );
$args = !empty( $exclude ) ? false : true;
/**
* @since 3.3
* If it is still true, make it false if shuffle-filter is enable
* to prevent posts of child terms from being retrieved
*/
if ( $args === true ) {
$shuffle_filter = PT_CV_Functions::setting_value( PT_CV_PREFIX . 'enable-taxonomy-filter', $view_settings );
if ( $shuffle_filter === 'yes' ) {
$args = false;
}
}
}
return $args;
}
/**
* Filter kind of content of View
*
* @param string $args
* @return string
*/
public static function filter_display_what( $args ) {
$view_settings = PT_CV_Functions::get_global_variable( 'view_settings' );
// Show terms as output
if ( PT_CV_Functions_Pro::taxonomy_custom_setting_enable( $view_settings, 'taxonomy-term-info', 'as_output' ) ) {
$args = 'term_as_output';
}
// Get one post of each term
else if ( PT_CV_Functions_Pro::taxonomy_custom_setting_enable( $view_settings, 'taxonomy-one-per-term' ) ) {
$args = 'post_per_term';
}
return $args;
}
/**
* Filter content of View
*
* @param string $args
* @return string
*/
public static function filter_view_content( $args ) {
$display_what = PT_CV_Functions::get_global_variable( 'display_what' );
$query_args = PT_CV_Functions::get_global_variable( 'args' );
$view_type = PT_CV_Functions::get_global_variable( 'view_type' );
$for_replacing = isset( $query_args[ 'cvp_replace_layout_page' ] ) && PT_CV_Functions::setting_value( PT_CV_PREFIX . 'taxonomy-child-terms-auto' );
if ( empty( $query_args[ 'tax_query' ] ) && !$for_replacing ) {
cvp_preview_notice( 'Please select terms!' );
return $args;
}
// Display terms as output
if ( $display_what === 'term_as_output' ) {
cvp_preview_notice( __( 'Some settings (including pagination, advertisement) will NOT work when enables "Show terms as output"', 'content-views-pro' ) );
if ( !$for_replacing ) {
$taxonomies = $include = array();
foreach ( $query_args[ 'tax_query' ] as $tax_query ) {
if ( !isset( $tax_query[ 'taxonomy' ], $tax_query[ 'terms' ] ) ) {
continue;
}
$taxonomies[] = $tax_query[ 'taxonomy' ];
$include = array_merge( $include, $tax_query[ 'terms' ] );
}
// Get terms
$args = array();
// @since 5.9.0 get terms of current post
$sc_params = PT_CV_Functions::get_global_variable( 'shortcode_params' );
if ( $sc_params[ 'terms' ] === 'GET_CURRENT' ) {
global $post;
if ( isset( $post->ID ) ) {
$term_list = wp_get_post_terms( $post->ID, $taxonomies, array( 'fields' => 'ids' ) );
}
$term_args = array(
'taxonomy' => $taxonomies,
'include' => $term_list,
'orderby' => 'include',
'hide_empty' => apply_filters( PT_CV_PREFIX_ . 'hide_empty_tax', false ),
);
unset( $include );
} else {
// @since after 6.4
if ( PT_CV_Functions::setting_value( PT_CV_PREFIX . 'taxonomy-child-terms-ofselected' ) ) {
if ( isset( $include[ 0 ], $taxonomies[ 0 ] ) ) {
$termobj = get_term_by( 'slug', $include[ 0 ], $taxonomies[ 0 ] );
if ( !empty( $termobj->term_id ) ) {
$term_args = array(
'taxonomy' => $taxonomies,
'parent' => $termobj->term_id,
'hide_empty' => apply_filters( PT_CV_PREFIX_ . 'hide_empty_tax', false ),
);
}
}
} else {
$field = PT_CV_Functions::get_global_variable( 'slug_to_id' ) ? 'include' : 'slug';
$term_args = array(
'taxonomy' => $taxonomies,
$field => $include,
'hide_empty' => apply_filters( PT_CV_PREFIX_ . 'hide_empty_tax', false ),
);
}
}
} else {
$term_obj = get_queried_object();
$term_args = array(
'taxonomy' => $term_obj->taxonomy,
'parent' => $term_obj->term_id,
'hide_empty' => 0,
);
}
// Live filter search
$lfsk = CVP_LIVE_FILTER_SEARCH::get_searched_value();
if ( PT_CV_Functions::get_global_variable( 'lf_enabled' ) && !empty( $lfsk ) ) {
$term_args[ 'name__like' ] = esc_sql( $lfsk );
}
$terms = get_terms( $term_args );
if ( $terms ) {
PT_CV_Functions::set_global_variable( 'force_disable_theme_pagination', $for_replacing );
foreach ( $terms as $term ) {
$term_link = get_term_link( $term, $term->taxonomy );
$dargs = PT_CV_Functions::get_global_variable( 'dargs' );
$term_data = array();
foreach ( $dargs[ 'fields' ] as $field ) {
$field_html = '';
switch ( $field ) {
case 'thumbnail':
$thumb_size = $dargs[ 'field-settings' ][ 'thumbnail' ][ 'size' ];
$term_img = CVP_Term_Thumbnail::get_thumbnail_of_term( $term, $thumb_size );
$term_img = apply_filters( PT_CV_PREFIX_ . 'term_thumbnail', $term_img, $term );
if ( $term_img ) {
$css = array();
if ( $thumb_size === PT_CV_PREFIX . 'custom' ) {
foreach ( array( 'width', 'height' ) as $f ) {
if ( !empty( $dargs[ 'field-settings' ][ 'thumbnail' ][ "size-custom-$f" ] ) ) {
$val = absint( $dargs[ 'field-settings' ][ 'thumbnail' ][ "size-custom-$f" ] );
$css[ $f ] = "$f:{$val}px!important;";
}
}
}
if ( PT_CV_Functions_Pro::animate_activated_content_hover() ) {
$css[ 'width' ] = "width:100%!important;";
}
if ( $css ) {
$term_img = preg_replace( '/
name, $term );
$count = PT_CV_Functions::setting_value( PT_CV_PREFIX . 'taxonomy-show-posts-count' ) ? sprintf( ' (%s)', $term->count ) : '';
$field_html = PT_CV_Html_Pro::term_output_link( $term_link, esc_html( $name ) . $count, PT_CV_PREFIX . 'tao' );
break;
case 'content':
$content_setting = $dargs[ 'field-settings' ][ 'content' ];
$full_content = $content_setting[ 'show' ] === 'full';
$content = $full_content ? $term->description : wp_trim_words( $term->description, (int) $content_setting[ 'length' ], !empty( $content_setting[ 'hide_dots' ] ) ? '' : ' …' );
$content = apply_filters( PT_CV_PREFIX_ . 'term_content', $content, $term );
$fargs = isset( $dargs[ 'field-settings' ] ) ? $dargs[ 'field-settings' ] : array();
if ( $full_content || !empty( $fargs[ 'content' ][ 'enable_filter' ] ) ) {
$content = do_shortcode( $content );
}
if ( !$full_content && PT_CV_Functions::setting_value( PT_CV_PREFIX . 'field-excerpt-readmore' ) ) {
$content .= apply_filters( PT_CV_PREFIX_ . 'field_content_readmore_seperated', '
', $fargs );
$content .= PT_CV_Html_Pro::custom_readmore( $term_link );
}
$content = sprintf( '%s
', PT_CV_PREFIX . 'content', $content );
$field_html = $content;
break;
case 'custom-fields':
$field_html = cvp_ctf_html( $term, false );
break;
}
if ( $field_html ) {
$term_data[ $field ] = $field_html;
}
}
if ( array_key_exists( 'thumbnail', $term_data ) ) {
$term_data = apply_filters( PT_CV_PREFIX_ . 'fields_html', $term_data, null );
}
$args[ PT_CV_Functions::term_slug_sanitize( $term->slug ) ] = sprintf( '%s
', PT_CV_PREFIX . 'taso', implode( '', $term_data ) );
}
// Reorder by order of selected terms
if ( isset( $include ) ) {
$args = PT_CV_Functions_Pro::_array_replace( array_flip( $include ), $args );
}
}
if ( empty( $args ) ) {
cvp_preview_notice( 'No terms found to show as output!' );
}
}
// Get N posts of each term
else if ( $display_what === 'post_per_term' ) {
// Get terms
$new_tax_query = array();
foreach ( (array) $query_args[ 'tax_query' ] as $tax_query ) {
if ( !isset( $tax_query[ 'taxonomy' ], $tax_query[ 'terms' ] ) ) {
continue;
}
foreach ( (array) $tax_query[ 'terms' ] as $term ) {
$new_tax_query[] = array(
'taxonomy' => $tax_query[ 'taxonomy' ],
'field' => PT_CV_Functions::get_global_variable( 'slug_to_id' ) ? 'term_id' : $tax_query[ 'field' ],
'terms' => $term,
'include_children' => PT_CV_Functions::setting_value( PT_CV_PREFIX . 'taxonomy-exclude-children' ) ? false : true,
);
}
}
// Query X posts of each term
$posts_limit = PT_CV_Functions::setting_value( PT_CV_PREFIX . 'taxonomy-number-per-term' );
$content_items = array();
foreach ( $new_tax_query as $tax_query ) {
$_args = $query_args;
$_args[ 'tax_query' ] = array( $tax_query );
$_args[ 'posts_per_page' ] = $posts_limit ? (int) $posts_limit : 1;
$_args[ 'offset' ] = 0;
do_action( PT_CV_PREFIX_ . 'post_of_term', $tax_query );
if ( !isset( $_args[ 'post__not_in' ] ) ) {
$_args[ 'post__not_in' ] = array();
}
$_args[ 'post__not_in' ] = array_merge( $_args[ 'post__not_in' ], array_keys( $content_items ) );
$pt_query = new WP_Query( $_args );
if ( $pt_query->have_posts() ) {
do_action( PT_CV_PREFIX_ . 'before_process_item' );
while ( $pt_query->have_posts() ) {
$pt_query->the_post();
global $post;
// Output HTML for this item
$content_items[ $post->ID ] = PT_CV_Html::view_type_output( $view_type, $post );
}
do_action( PT_CV_PREFIX_ . 'after_process_item' );
}
PT_CV_Functions::reset_query();
}
$args = apply_filters( PT_CV_PREFIX_ . 'content_items', $content_items, $view_type );
if ( empty( $args ) ) {
cvp_preview_notice( 'No posts found for selected terms!' );
}
}
return $args;
}
/**
* Add parameters to filter by Custom Field
*
* @param array $args
*
* @return array
*/
public static function filter_by_custom_field( $args ) {
$advanced_settings = (array) PT_CV_Functions::setting_value( PT_CV_PREFIX . 'advanced-settings' );
if ( !in_array( 'custom_field', $advanced_settings ) ) {
return $args;
}
$ctf_query = array();
$ctf_dateformat = array();
$saved_ctf = PT_CV_Functions::settings_values_by_prefix( PT_CV_PREFIX . 'ctf-filter-', true );
$fields_count = isset( $saved_ctf[ 'key' ] ) ? count( $saved_ctf[ 'key' ] ) : 0;
$operators = array(
'allow_empty' => array( 'EXISTS', 'NOT EXISTS', 'TODAY', 'NOW_PAST', 'NOW_FUTURE', 'IN_PAST' ),
'no_value' => array( 'EXISTS', 'NOT EXISTS' ),
'require_2values' => array( 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ),
);
$saved_ctf = apply_filters( PT_CV_PREFIX_ . 'filtered_ctf', $saved_ctf, $fields_count );
for ( $idx = 0; $idx < $fields_count; $idx ++ ) {
if ( !isset( $saved_ctf[ 'value' ][ $idx ] ) ) {
continue;
}
$value = $saved_ctf[ 'value' ][ $idx ];
$key = $saved_ctf[ 'key' ][ $idx ];
$compare = isset( $saved_ctf[ 'operator' ][ $idx ] ) ? $saved_ctf[ 'operator' ][ $idx ] : null; // do not use sanitize_text_field(), it will convert 'compare' < > to HTML entities
$type = sanitize_text_field( $saved_ctf[ 'type' ][ $idx ] );
$arr_val = in_array( $compare, $operators[ 'require_2values' ] ) ? explode( ',', $value ) : array( $value );
$arr_val = array_map( 'cvp_stripallslashes', $arr_val );
// Value is not empty Or ...
$allow_empty_value = in_array( $compare, $operators[ 'allow_empty' ] );
if ( !empty( $key ) && ( $value !== '' || $allow_empty_value ) ) {
// Check if require array of value
$require_array = 0;
// Validate input which requires 2 values
if ( in_array( $compare, $operators[ 'require_2values' ] ) ) {
$require_array = 1;
if ( count( $arr_val ) <= 1 ) {
cvp_preview_notice( sprintf( __( '[Filter by Custom field] This custom field "%s" requires 2 different values (separate by comma)', 'content-views-pro' ), $key ) );
}
}
// Validate date value
if ( $type == 'DATE' || $type == 'DATETIME' ) {
$suffix = ($type == 'DATETIME') ? ' H:i:s' : '';
if ( !in_array( $compare, array( 'TODAY', 'NOW_PAST', 'NOW_FUTURE', 'IN_PAST' ) ) ) {
// If all dates are valid, convert to Ymd format
$arr_dates = array();
foreach ( $arr_val as $date ) {
/**
* English textual datetime
* @since 4.8.1
*/
if ( preg_match( '/[a-zA-Z]+/', $date ) ) {
$converted_date = date( 'Y-m-d' . $suffix, strtotime( trim( $date ), current_time( 'timestamp' ) ) );
if ( $converted_date ) {
$arr_dates[] = $converted_date;
} else {
cvp_preview_notice( sprintf( __( '[Filter by Custom field] Value of this date field "%s" is invalid', 'content-views-pro' ), $key ) );
}
} else {
$date = DateTime::createFromFormat( 'Y/m/d' . $suffix, $date );
// Support old version where datepicker's dateformat is m/d/Y
if ( !$date ) {
$date = DateTime::createFromFormat( 'm/d/Y', $date );
}
if ( $date ) {
$arr_dates[] = $date->format( 'Y-m-d' . $suffix );
} else if ( !$allow_empty_value ) {
cvp_preview_notice( sprintf( __( '[Filter by Custom field] Value of this date field "%s" is invalid', 'content-views-pro' ), $key ) );
}
}
}
$arr_val = $arr_dates;
} else {
if ( $compare == 'NOW_FUTURE' ) {
$compare = '>=';
} else if ( $compare == 'IN_PAST' ) {
$compare = '<';
} else if ( $compare == 'TODAY' ) {
$compare = '=';
} else if ( $compare == 'NOW_PAST' ) {
$compare = '<=';
}
$arr_val = array( current_time( 'Y-m-d' . $suffix ) );
}
}
// Create query array for this custom field
$tmp_arr = array(
'key' => $key,
'type' => $type === 'DECIMAL' ? 'DECIMAL(15,5)' : $type,
'compare' => $compare,
);
# If value is not empty
if ( !in_array( $compare, $operators[ 'no_value' ] ) && isset( $arr_val, $arr_val[ 0 ] ) ) {
$tmp_arr[ 'value' ] = apply_filters( PT_CV_PREFIX_ . 'query_ctf_value', $require_array ? $arr_val : $arr_val[ 0 ], $key );
}
if ( $tmp_arr ) {
$ctf_query[] = $tmp_arr;
}
}
}
// Get custom date format if set, for backend filter or Live filter
for ( $idx = 0; $idx < $fields_count; $idx ++ ) {
$type = sanitize_text_field( $saved_ctf[ 'type' ][ $idx ] );
if ( $type == 'DATE' || $type == 'DATETIME' ) {
$dfm = isset( $saved_ctf[ 'date-format' ][ $idx ] ) ? trim( $saved_ctf[ 'date-format' ][ $idx ] ) : null;
if ( !empty( $dfm ) ) {
$ctf_dateformat[ $idx ] = $dfm;
}
}
}
PT_CV_Functions::set_global_variable( 'ctf_filter_dateformat', $ctf_dateformat );
PT_CV_Functions::set_global_variable( 'meta_query_origin', $ctf_query );
if ( count( $ctf_query ) > 1 ) {
$ctf_query[ 'relation' ] = sanitize_text_field( $saved_ctf[ 'relation' ] );
}
$args = array_merge( $args, array( 'meta_query' => $ctf_query ) );
return $args;
}
/**
* Filter when get list of taxonomies
*
* @param array $args The settings array to get taxonomies
*/
public static function filter_taxonomies_to_show( $args ) {
$dargs = PT_CV_Functions::get_global_variable( 'dargs' );
if ( !empty( $dargs[ 'field-settings' ][ 'meta-fields' ][ 'taxonomy-display-what' ] ) ) {
if ( !empty( $dargs[ 'field-settings' ][ 'meta-fields' ][ 'taxonomy-display-custom' ] ) ) {
$args = (array) $dargs[ 'field-settings' ][ 'meta-fields' ][ 'taxonomy-display-custom' ];
PT_CV_Functions::set_global_variable( 'tax-to-show', $args );
}
}
return $args;
}
public static function filter_post_term( $args, $term ) {
$args = array(
'key' => PT_CV_Functions_Pro::shuffle_filter_key( $term ),
'value' => $term,
);
return $args;
}
/**
* Show terms in selected order of taxonomies
*/
public static function filter_post_terms_output( $args, $links, $taxonomy_terms ) {
$taxes = PT_CV_Functions::get_global_variable( 'tax-to-show' );
if ( $taxes && count( $taxes ) > 1 ) {
$new_args = array();
$taxonomy_terms = PT_CV_Functions_Pro::_array_replace( array_flip( $taxes ), $taxonomy_terms );
foreach ( $taxonomy_terms as $taxonomy => $terms_html ) {
$terms_html = array_filter( $terms_html );
$new_args[ $taxonomy ] = $terms_html ? implode( ', ', $terms_html ) : false;
}
$args = implode( ', ', array_filter( $new_args ) );
}
return $args;
}
/**
* Filter taxonomy: Get all registered taxonomies
*
* @param array $args Array to filter
*
* @return boolean
*/
public static function filter_taxonomy_query_args( $args ) {
if ( isset( $args[ 'show_ui' ] ) ) {
unset( $args[ 'show_ui' ] );
}
if ( isset( $args[ '_builtin' ] ) ) {
unset( $args[ '_builtin' ] );
}
return $args;
}
/** Add Woocommerce hidden taxonomies to the list
* @since 5.6.0
*
* @param type $args
* @return type
*/
public static function filter_tax_list( $args ) {
if ( taxonomy_exists( 'product_visibility' ) ) {
$args[ 'product_visibility' ] = __( 'Visibility', 'content-views-pro' );
}
// Get Woocommerce attributes taxonomies
if ( function_exists( 'wc_get_attribute_taxonomies' ) ) {
$attributes = wc_get_attribute_taxonomies();
if ( !empty( $attributes ) ) {
// Don't include all if too many attributes, that cause slow/unable saving
if ( count( $attributes ) > 30 ) {
$attributes = array_slice( $attributes, 0, 30, true );
}
foreach ( $attributes as $tax ) {
$tslug = wc_attribute_taxonomy_name( $tax->attribute_name );
if ( !array_key_exists( $tslug, $args ) ) {
$args[ $tslug ] = $tax->attribute_name;
}
}
}
}
return $args;
}
/**
* Add parameters for View shortcode, used to reuse View
*
* @param array $args
*/
public static function filter_shortcode_params( $args ) {
$args[ 'limit' ] = 0;
$args[ 'offset' ] = 0;
$args[ 'field' ] = 'slug';
$args[ 'operator' ] = $args[ 'operator2' ] = $args[ 'operator3' ] = $args[ 'operator4' ] = 'IN'; // IN, NOT IN, AND
$args[ 'relation' ] = 'AND'; // AND, OR
$text_keys = array( 'reuse_tax_query', 'keyword', 'post_type', 'post_parent', 'post_id', 'author', 'cat', 'tag', 'taxonomy', 'taxonomy2', 'terms', 'terms2', 'custom_field_value' );
$args += array_fill_keys( $text_keys, '' );
return $args;
}
/**
* Add wrapper class of View
*
* @param array $args
*
* @return int
*/
public static function filter_view_class( $args ) {
$view_settings = PT_CV_Functions::get_global_variable( 'view_settings' );
$view_type = PT_CV_Functions::get_global_variable( 'view_type' );
$dargs = PT_CV_Functions::get_global_variable( 'dargs' );
if ( PT_CV_Functions::setting_value( PT_CV_PREFIX . 'text-direction' ) === 'rtl' ) {
$args[] = PT_CV_PREFIX . 'rtl';
}
if ( $view_type == 'masonry' ) {
$args[] = PT_CV_PREFIX . 'pinterest';
}
if ( $view_type == 'pinterest' || $view_type == 'masonry' ) {
$style = PT_CV_Functions::setting_value( PT_CV_PREFIX . $view_type . '-box-style', $view_settings, 'shadow' );
$args[] = esc_attr( PT_CV_PREFIX . $style );
$no_bb = PT_CV_Functions::setting_value( PT_CV_PREFIX . $view_type . '-no-bb', $view_settings, 'bb' );
if ( $no_bb ) {
$args[] = esc_attr( PT_CV_PREFIX . $no_bb );
}
if ( PT_CV_Functions::setting_value( PT_CV_PREFIX . 'item-margin-value-bottom' ) === '0' ) {
$args[] = PT_CV_PREFIX . 'mb0';
}
// New way, @since 7.2
if ( PT_CV_Functions::setting_value( PT_CV_PREFIX . 'item-margin-value-bottom' ) === '-5' ) {
$args[] = PT_CV_PREFIX . 'sb0';
}
}
if ( $view_type == 'timeline' ) {
if ( PT_CV_Functions::setting_value( PT_CV_PREFIX . 'timeline-long-distance' ) ) {
$args[] = PT_CV_PREFIX . 'lmode';
}
if ( PT_CV_Functions::setting_value( PT_CV_PREFIX . 'timeline-simulate-fb' ) ) {
$args[] = PT_CV_PREFIX . 'sifb';
}
if ( PT_CV_Functions::get_global_variable( 'no_post_found' ) ) {
$args[] = 'cv-npf';
}
}
if ( $view_type == 'grid' ) {
$fields = array( 'grid-same-height', 'post-border' );
foreach ( $fields as $field ) {
if ( PT_CV_Functions::setting_value( PT_CV_PREFIX . $field ) && !PT_CV_Functions::get_global_variable( 'enable_shuffle_filter' ) ) {
$args[] = PT_CV_PREFIX . str_replace( 'grid-', '', $field );
}
}
}
if ( $overlay = PT_CV_Functions_Pro::animate_activated_content_hover() ) {
$animation = PT_CV_Functions::get_global_variable( 'animation' );
$args[] = PT_CV_PREFIX . 'content-hover';
if ( !empty( $animation[ 'box-clickable' ] ) ) {
$args[] = PT_CV_PREFIX . 'clickable';
}
if ( !empty( $animation[ 'disable-onmobile' ] ) ) {
$args[] = PT_CV_PREFIX . 'nohover';
}
if ( $overlay === 'onhover' ) {
$args[] = !empty( $animation[ 'content-animation' ] ) ? esc_attr( $animation[ 'content-animation' ] ) : 'effect-fi';
}
if ( $overlay === 'always' ) {
$args[] = PT_CV_PREFIX . 'force-mask';
}
$position = !empty( $animation[ 'overlay-position' ] ) ? $animation[ 'overlay-position' ] : 'middle';
$args[] = PT_CV_PREFIX . 'overlay-' . $position;
}
if ( PT_CV_Functions::setting_value( PT_CV_PREFIX . 'enable-pagination' ) ) {
if ( isset( $dargs[ 'pagination-settings' ][ 'style' ] ) && $dargs[ 'pagination-settings' ][ 'type' ] === 'ajax' ) {
$class = 'pg' . $dargs[ 'pagination-settings' ][ 'style' ];
$args[] = esc_attr( PT_CV_PREFIX . $class );
}
}
if ( !empty( $dargs[ 'view-style' ][ 'others' ][ 'text-align' ] ) ) {
$args[] = esc_attr( PT_CV_PREFIX . $dargs[ 'view-style' ][ 'others' ][ 'text-align' ] );
}
if ( PT_CV_Functions::get_global_variable( 'display_what' ) === 'term_as_output' ) {
$args[] = PT_CV_PREFIX . 'show-taxonomy';
}
if ( PT_CV_Functions_Pro::check_device( 'mobile' ) ) {
$args[] = PT_CV_PREFIX . 'mobile';
}
if ( PT_CV_Functions_Pro::check_device( 'mobile_tablet' ) ) {
$args[] = PT_CV_PREFIX . 'mobile-tablet';
}
if ( PT_CV_Functions::setting_value( PT_CV_PREFIX . 'other-social-show', $view_settings ) && PT_CV_Functions::setting_value( PT_CV_PREFIX . 'other-social-count', $view_settings ) ) {
$args[] = PT_CV_PREFIX . 'socialsc';
}
if ( $view_type == 'scrollable' && PT_CV_Functions::setting_value( PT_CV_PREFIX . 'scrollable-textbelow' ) ) {
$args[] = PT_CV_PREFIX . 'textbelow';
}
if ( PT_CV_Functions::setting_value( PT_CV_PREFIX . 'field-excerpt-readmore-round' ) ) {
$args[] = PT_CV_PREFIX . 'round-btn';
}
if ( PT_CV_Functions::setting_value( PT_CV_PREFIX . 'other-social-circle' ) ) {
$args[] = PT_CV_PREFIX . 'round-share';
}
if ( PT_CV_Functions::get_global_variable( 'reused_view' ) ) {
$args[] = PT_CV_PREFIX . 'reused';
}
if ( PT_CV_Functions::get_global_variable( 'enable_shuffle_filter' ) ) {
$args[] = PT_CV_PREFIX . 'sf';
}
// @since 5.8.6
if ( PT_CV_Functions::get_global_variable( 'lf_enabled' ) ) {
$args[] = 'cvp-lfres';
}
if ( PT_CV_Functions::setting_value( PT_CV_PREFIX . 'layout-format' ) === '2-col' && PT_CV_Functions::setting_value( PT_CV_PREFIX . 'lf-alternate' ) ) {
if ( PT_CV_Functions::setting_value( PT_CV_PREFIX . 'field-thumbnail-position' ) === 'left' ) {
$args[] = PT_CV_PREFIX . 'alternate-right';
} else {
$args[] = PT_CV_PREFIX . 'alternate-left';
}
}
$view_classes = PT_CV_Functions::setting_value( PT_CV_PREFIX . 'view-css-class' );
if ( $view_classes ) {
$args[] = implode( ' ', array_map( 'sanitize_html_class', array_filter( explode( ' ', $view_classes ) ) ) );
}
return $args;
}
/**
* Filter asset files to include in Preview/Front-end
*
* @param array $args
*/
public static function filter_assets_files( $args ) {
if ( PT_CV_Functions::setting_value( PT_CV_PREFIX . 'text-direction' ) === 'rtl' ) {
$args[ 'css' ][] = plugins_url( 'public/assets/css/rtl.css', PT_CV_FILE_PRO );
}
return $args;
}
/**
* Add custom HTML before list of items
*
* @param string $args
*/
public static function filter_before_output_html( $args ) {
global $pt_cv_glb, $pt_cv_id;
$view_settings = PT_CV_Functions::get_global_variable( 'view_settings' );
$view_type = PT_CV_Functions::get_global_variable( 'view_type' );
// Showing live filter filters/results separately
$sc_params = PT_CV_Functions::get_global_variable( 'shortcode_params' );
$output_separate_filter = !empty( $sc_params[ 'show' ] );
if ( $output_separate_filter ) {
$current_output = $args;
}
if ( !empty( $pt_cv_glb[ 'parent_page' ] ) ) {
$show_what = PT_CV_Functions::setting_value( PT_CV_PREFIX . 'post_parent-auto-info', $view_settings );
if ( $show_what ) {
$parent = get_post( $pt_cv_glb[ 'parent_page' ] );
$parent_title = esc_html( $parent->post_title );
$parent_title = apply_filters( PT_CV_PREFIX_ . 'field_title_result', $parent_title, array(), $parent );
if ( $show_what === 'title' ) {
$args = sprintf( '%s
', PT_CV_PREFIX . 'parent-title', $parent_title );
} else {
$args = sprintf( '', PT_CV_PREFIX . 'parent-title', get_permalink( $parent->ID ), $parent_title );
}
}
}
// Show terms as heading
if ( PT_CV_Functions_Pro::taxonomy_custom_setting_enable( $view_settings, 'taxonomy-term-info', 'as_heading' ) ) {
$dargs = PT_CV_Functions::get_global_variable( 'dargs' );
// Get selected taxonomy
$taxonomies_to_get = isset( $dargs[ 'taxonomy-filter' ] ) ? $dargs[ 'taxonomy-filter' ] : NULL;
// Get selected terms or all terms of selected taxonomies
$selected_terms_of_taxonomies = (array) PT_CV_Functions_Pro::get_selected_terms( $taxonomies_to_get );
if ( $selected_terms_of_taxonomies ) {
$first_taxonomy = current( array_keys( $selected_terms_of_taxonomies ) );
$terms_of_first_taxonomy = array_shift( $selected_terms_of_taxonomies );
// Skip if enable live filter of this taxonomy, but selecting the All option
$skip = false;
global $cvp_lf_params;
$lfe = PT_CV_Functions::get_global_variable( 'lf_enabled' );
if ( !empty( $lfe[ 'tx' ][ 'settings' ][ $first_taxonomy ][ 'live-filter-enable' ] ) && empty( $cvp_lf_params[ 'tax_query' ][ $first_taxonomy ] ) ) {
$skip = true;
}
if ( !$skip && $first_taxonomy && $terms_of_first_taxonomy ) {
$first_term = array_slice( $terms_of_first_taxonomy, 0, 1, true );
if ( $first_term ) {
$term = current( $first_term );
$term_link = get_term_link( $term, $first_taxonomy );
if ( !is_wp_error( $term_link ) ) {
// Get term heading tag
$tag = tag_escape( apply_filters( PT_CV_PREFIX_ . 'field_term_heading_tag', 'h3' ) );
$tag_class = esc_attr( apply_filters( PT_CV_PREFIX_ . 'field_term_heading_class', PT_CV_PREFIX . 'term-heading' ) );
$text = apply_filters( PT_CV_PREFIX_ . 'field_term_heading_text', esc_html( $term->name ), $term );
$args = "<$tag class='$tag_class' id='$tag_class-$pt_cv_id'>$text$tag>";
}
}
}
}
}
// Enable filter
if ( PT_CV_Functions::get_global_variable( 'enable_shuffle_filter' ) ) {
self::before_output_html_shuffle_filter( $args );
}
// For Glossary list
if ( $view_type == 'glossary' ) {
self::before_output_html_glossary_header( $args );
}
if ( $output_separate_filter ) {
PT_CV_Functions::set_global_variable( 'before_output_not_filter', $args );
$args = $current_output;
}
/**
* Add edit button if:
* in front-end
* & is administrator or allowed role
* & want to display this button (have option in Settings page)
*/
$hide_edit_view = apply_filters( PT_CV_PREFIX_ . 'hide_editview', PT_CV_Functions::get_option_value( 'hide_edit_view' ) );
if ( !is_admin() && PT_CV_Functions_Pro::user_can_manage_view() && empty( $hide_edit_view ) ) {
$edit_link = PT_CV_Functions::view_link( $pt_cv_id );
$edit_html = '' . __( 'Edit View', 'content-views-query-and-display-post-page' ) . '
';
$args = $edit_html . $args;
}
return $args;
}
/**
* Display Shuffle Filter Options
*
* @global array $view_settings
* @global array $dargs
* @global array $pt_cv_id
* @global array $gl_view_styles
* @global array $gl_view_styles
* @param array $args
* @return array
*/
public static function before_output_html_shuffle_filter( &$args ) {
global $pt_cv_glb, $pt_cv_id;
$dargs = PT_CV_Functions::get_global_variable( 'dargs' );
if ( !isset( $pt_cv_glb[ 'view_styles' ] ) ) {
$pt_cv_glb[ 'view_styles' ] = array();
}
$sanitized_terms = array();
// Check if Taxonomy is selected in Advanced filters
$advanced_settings = (array) PT_CV_Functions::setting_value( PT_CV_PREFIX . 'advanced-settings' );
if ( !in_array( 'taxonomy', $advanced_settings ) ) {
return sprintf( '%s
', __( 'Please enable Taxonomy under Advanced filters section', 'content-views-pro' ) );
}
// Get selected taxonomy
$taxonomies_to_get = isset( $dargs[ 'taxonomy-filter' ] ) ? $dargs[ 'taxonomy-filter' ] : NULL;
if ( !is_array( $taxonomies_to_get ) ) {
return sprintf( '%s
', __( 'Please select at least one taxonomy', 'content-views-pro' ) );
}
// Get selected terms or all terms of selected taxonomies
$selected_terms_of_taxonomies = apply_filters( PT_CV_PREFIX_ . 'terms_to_filter', (array) PT_CV_Functions_Pro::get_selected_terms( $taxonomies_to_get ) );
if ( !$selected_terms_of_taxonomies ) {
return sprintf( '%s
', __( 'There is no terms to filter', 'content-views-pro' ) );
}
foreach ( $selected_terms_of_taxonomies as $taxonomy => $terms ) {
$this_term = array();
foreach ( $terms as $term ) {
if ( empty( $term->name ) ) {
continue;
}
$this_term[ PT_CV_Functions_Pro::shuffle_filter_key( $term ) ] = apply_filters( PT_CV_PREFIX_ . 'sf_term_text', $term->name, $term );
}
$sanitized_terms[ $taxonomy ] = $this_term;
}
$sanitized_terms = apply_filters( PT_CV_PREFIX_ . 'shuffle_filter_extra', $sanitized_terms );
// Get filter settings
$prefix = 'taxonomy-filter';
$filter_settings = PT_CV_Functions::settings_values_by_prefix( PT_CV_PREFIX . $prefix . '-' );
$filter_class = PT_CV_PREFIX . 'filter-bar';
$class = implode( ' ', apply_filters( PT_CV_PREFIX_ . 'shuffle_filter_class', array( $filter_class ) ) );
// Show Filter bar for each Taxonomy
$output = array();
$sfilter_type = apply_filters( PT_CV_PREFIX_ . 'sfilter_type', $filter_settings[ 'type' ] );
// Single filter
if ( $sfilter_type != 'group_by_taxonomy' ) {
// Get position
$position = $filter_settings[ 'position' ];
switch ( $position ) {
case 'left':
$class .= ' pull-left';
break;
case 'center':
$class .= ' ' . PT_CV_PREFIX . 'center';
break;
case 'right':
$class .= ' pull-right';
break;
}
$idx_tax = 0;
foreach ( $sanitized_terms as $idx => $selected_terms ) {
// Generate id for each filter bar
$filter_id = $filter_class . '-' . $pt_cv_id . '-' . $idx;
// Margin bottom
$margin_bottom = $filter_settings[ 'margin-bottom' ];
if ( isset( $margin_bottom ) ) {
$pt_cv_glb[ 'view_styles' ][] = sprintf( '#%s { margin-bottom: %spx !important; }', $filter_id, (int) $margin_bottom );
}
switch ( $sfilter_type ) {
case 'btn-group':
// Custom css
$space = $filter_settings[ 'space' ];
$pt_cv_glb[ 'view_styles' ][] = sprintf( '#%s .btn { margin-right: %spx !important; }', $filter_id, $space );
$output[] = PT_CV_Html_Pro::filter_html_btn_group( $class, $selected_terms, $filter_id, $idx_tax, false );
break;
case 'breadcrumb':
$output[] = PT_CV_Html_Pro::filter_html_breadcrumb( $class, $selected_terms, $filter_id, $idx_tax );
break;
case 'vertical-dropdown':
$output[] = PT_CV_Html_Pro::filter_html_vertical_dropdown( $class, $selected_terms, $filter_id, $idx_tax, false );
break;
}
$idx_tax++;
}
}
// Filter by Group of terms
else {
$class .= ' ' . PT_CV_PREFIX . 'filter-group';
// Group options by Taxonomy
list( $columns, $span_width_last, $span_width, $span_class ) = PT_CV_Html_ViewType::process_column_width( count( $sanitized_terms ), false );
// Get all current taxonomies
$all_taxonomies = apply_filters( PT_CV_PREFIX_ . 'all_taxonomies', PT_CV_Values::taxonomy_list() );
$row_html = array();
$idx_tax = 0;
foreach ( $sanitized_terms as $taxonomy => $terms ) {
$column_html = array();
// Heading text
$filter_title_class = apply_filters( PT_CV_PREFIX_ . 'shuffle_title_class', PT_CV_PREFIX . 'filter-title' );
$heading_text = PT_CV_Functions_Pro::shuffle_filter_group_setting( $idx_tax );
if ( $heading_text == __( 'All', 'content-views-pro' ) || empty( $heading_text ) ) {
$heading_text = $all_taxonomies[ $taxonomy ];
}
$column_html[] = sprintf( '%s
', esc_attr( $filter_title_class ), esc_attr( $taxonomy ), apply_filters( PT_CV_PREFIX_ . 'shuffle_title_text', esc_html( $heading_text ) ) );
// Terms list
$terms_html = array();
foreach ( $terms as $key => $text ) {
$terms_html[] = sprintf( '%s', PT_CV_PREFIX . 'filter-option', esc_attr( $key ), esc_html( $text ) );
}
$column_html[] = sprintf( '', implode( "\n", $terms_html ) );
// Operator for frontend
$sf_taxo_operator = PT_CV_Functions_Pro::shuffle_filter_group_setting( $idx_tax, 'operator' );
$operator_options = array();
foreach ( array( 'and' => __( 'AND', 'content-views-pro' ), 'or' => __( 'OR', 'content-views-pro' ) ) as $option => $text ) {
$operator_options[] = sprintf( '', $option, 'cvp-filter-operator-' . $idx_tax, checked( $sf_taxo_operator, $option, false ), $text );
}
$operator_selection = sprintf( '%s
', implode( '', $operator_options ) );
$label = __( 'Operator', 'content-views-query-and-display-post-page' );
$column_html[] = sprintf( '%s
', PT_CV_PREFIX . 'filter-operator' . ' hidden', $label, $operator_selection );
// Get HTML of each column
$classes = array( PT_CV_PREFIX . 'filter-egroup' );
$classes[] = $span_class . $span_width;
$classes[] = 'col-sm-' . ($span_width >= 3 ? $span_width : 6);
// By default, disable 2 columns for Mobile devices
if ( apply_filters( PT_CV_PREFIX_ . 'shuffle_2col_mobile', false ) ) {
$classes[] = 'col-xs-6';
}
$row_html[] = sprintf( '%s
', esc_attr( implode( ' ', $classes ) ), implode( "\n", $column_html ) );
$idx_tax++;
}
// Wrap columns of Taxonomies group to a row
$filter_id = $filter_class . '-' . $pt_cv_id;
$output[] = sprintf( '%s
', esc_attr( $class ), esc_attr( $filter_id ), implode( "\n", $row_html ) );
}
$args = implode( '', $output );
}
/**
* Display Header text for Glossary list
*
* @global array $content_items
* @param array $args
*/
public static function before_output_html_glossary_header( &$args ) {
if ( PT_CV_Functions::get_global_variable( 'no_post_found' ) ) {
return;
}
$glb_content_items = PT_CV_Functions::get_global_variable( 'content_items' );
// Get list of post objects, title as key
$all_posts = isset( $GLOBALS[ 'cv_posts' ] ) ? $GLOBALS[ 'cv_posts' ] : array();
$content_items = array();
foreach ( $glb_content_items as $pid => $item ) {
$post = isset( $all_posts[ $pid ] ) ? $all_posts[ $pid ] : null;
$title = isset( $post->post_title ) ? $post->post_title : strip_tags( $item );
$title = apply_filters( PT_CV_PREFIX_ . 'glossary_from', $title, $post );
$content_items[ $title ] = $item;
}
$glossary_list = array();
foreach ( $content_items as $title => $item ) {
/**
* Remove special chars before extract index
* @since 4.3
*/
$special_chars = array( "?", "[", "]", "/", "\\", "=", "<", ">", ":", ";", ",", "\"", "&", "$", "#", "*", "(", ")", "|", "~", "`", "!", "{", "}", "%", "+", chr( 0 ) );
$title = str_replace( $special_chars, '', $title );
/**
* Remove stop words before extract index
* @since 4.3
*/
if ( PT_CV_Functions::setting_value( PT_CV_PREFIX . 'glossary-stop-words' ) ) {
$words = explode( ',', PT_CV_Functions::setting_value( PT_CV_PREFIX . 'glossary-stop-words' ) );
$words = array_map( 'cvp_stripallslashes', $words );
$title = str_replace( $words, '', $title );
}
/**
* @since 5.8.0
*/
if ( PT_CV_Functions::setting_value( PT_CV_PREFIX . 'glossary-remove-accent' ) ) {
$title = remove_accents( $title );
}
$title = trim( $title );
// fix untrackable 500 error in hosting which doesn't enable/install relative module
$st = (function_exists( 'mb_strtoupper' ) && function_exists( 'mb_substr' )) ? mb_strtoupper( mb_substr( $title, 0, 1, CVP_ENCODING ) ) : strtoupper( substr( $title, 0, 1 ) );
$key = apply_filters( PT_CV_PREFIX_ . 'glossary_key', $st, $title );
if ( $key != '' ) {
if ( !isset( $glossary_list[ $key ] ) ) {
$glossary_list[ $key ] = array();
}
$glossary_list[ $key ][] = $item;
}
}
// Get indexes
$indexes = array_keys( $glossary_list );
// Sort/Order indexes
natsort( $indexes );
// Restructure the list: index (in sorted order) => posts (no order change)
$glossary_list = PT_CV_Functions_Pro::_array_replace( array_flip( $indexes ), $glossary_list );
PT_CV_Functions::set_global_variable( 'glossary_list', $glossary_list );
// Get HTML of Glossary menu
$args = PT_CV_Html_Pro::glossary_menu( $indexes );
}
/**
* Show data-type of each post
*
* @param string $args The output HTML
* @param string $post_id The post ID
*
* @return string
*/
public static function filter_content_item_filter_value( $args, $post_id ) {
if ( PT_CV_Functions::get_global_variable( 'enable_shuffle_filter' ) ) {
$group = 0;
if ( is_int( $post_id ) ) {
global $pt_cv_glb;
if ( empty( $pt_cv_glb[ 'item_terms' ][ $post_id ] ) ) {
PT_CV_Functions::post_terms( $post_id );
}
$terms_of_post = !empty( $pt_cv_glb[ 'item_terms' ][ $post_id ] ) ? $pt_cv_glb[ 'item_terms' ][ $post_id ] : array();
if ( $terms_of_post ) {
$sanitized_terms = array();
foreach ( $terms_of_post as $term ) {
$sanitized_terms[] = PT_CV_Functions_Pro::shuffle_filter_key( $term );
}
$group = implode( ' ', apply_filters( PT_CV_PREFIX_ . 'post_groups', $sanitized_terms, $post_id ) );
$args .= sprintf( 'data-groups="%s"', esc_attr( $group ) );
}
}
// For posts which have no terms, or for none post item (advertisements)
if ( !$group ) {
$args .= 'data-groups=""';
}
// [shuffle-pagination]
if ( PT_CV_Functions::setting_value( PT_CV_PREFIX . 'enable-pagination' ) && PT_CV_Functions::get_global_variable( 'current_page' ) > 1 ) {
// Hide post before append to output by shuffle animation
if ( PT_CV_Functions::setting_value( PT_CV_PREFIX . 'pagination-type' ) === 'ajax' ) {
$args .= ' style="opacity:0"';
}
}
}
// Show post ID
$args .= sprintf( ' data-pid="%s"', $post_id );
return $args;
}
public static function filter_content_no_post_found_text( $args ) {
if ( PT_CV_Functions_Pro::user_can_manage_view() ) {
$query_args = PT_CV_Functions::get_global_variable( 'args' );
// Parent page
if ( !empty( $query_args[ 'post_parent' ] ) ) {
$args .= '
' . sprintf( __( 'For Administrator only: %s Parent page %s setting might cause this result', 'content-views-pro' ), '', '.' );
}
// If enable Sort by custom field
if ( !empty( $query_args[ 'orderby' ] ) && $query_args[ 'orderby' ] === 'meta_value' ) {
$args .= '
' . sprintf( __( 'For Administrator only: %s Sort by %s setting (using custom field %s) might cause this result', 'content-views-pro' ), '', '', " {$query_args[ 'meta_key' ]}" );
}
}
return $args;
}
/**
* Filter $content_items variable before display
*
* @param type $args
*/
public static function filter_content_items( $args, $view_type ) {
$args = CVP_ADVERT::insert_ads_to_page( $args, $view_type );
$args = self::sort_post_dragdrop( $args );
return $args;
}
/** Handle sticky posts options
* @return array
*/
public static function prepend_all_sticky_posts( $posts, $query ) {
remove_filter( 'the_posts', array( __CLASS__, 'prepend_all_sticky_posts' ), 999, 2 );
$sticky_post_ids = get_option( 'sticky_posts' );
if ( $sticky_post_ids && PT_CV_Functions::get_global_variable( 'current_page' ) === 1 ) {
$params = array(
'post__in' => $sticky_post_ids,
'post__not_in' => PT_CV_Functions::setting_value( PT_CV_PREFIX . 'post__not_in' ),
'post_type' => PT_CV_Functions::get_global_variable( 'content_type' ),
'post_status' => 'publish',
'nopaging' => true,
);
$stickies = $params ? get_posts( $params ) : null;
if ( $stickies ) {
// Add sticky posts to the list
$sticky_offset = 0;
foreach ( $stickies as $sticky_post ) {
array_splice( $posts, $sticky_offset, 0, array( $sticky_post ) );
$sticky_offset++;
}
// Respect the Limit
if ( !PT_CV_Functions::setting_value( PT_CV_PREFIX . 'enable-pagination' ) ) {
$limit = (int) PT_CV_Functions::setting_value( PT_CV_PREFIX . 'limit' );
if ( $limit > 0 && count( $posts ) > $limit ) {
$posts = array_slice( $posts, 0, $limit, true );
}
}
}
}
return $posts;
}
public static function prepend_matched_sticky_posts( $order_stat, $query ) {
remove_filter( 'posts_orderby', array( __CLASS__, 'prepend_matched_sticky_posts' ), 999, 2 );
global $wpdb;
$extra_order = '';
$sticky_post_ids = get_option( 'sticky_posts' );
if ( $sticky_post_ids ) {
$list = implode( ', ', $sticky_post_ids );
$extra_order = "CASE WHEN $wpdb->posts.ID IN ($list) THEN 2 ELSE 1 END DESC";
$order_stat = $order_stat ? $extra_order . ', ' . $order_stat : $extra_order;
}
return $order_stat;
}
private static function sort_post_dragdrop( $args ) {
$rebuild = PT_CV_Functions::setting_value( PT_CV_PREFIX . 'rebuild' );
if ( PT_CV_Functions::get_global_variable( 'reused_view' ) || !empty( $rebuild ) ) {
return $args;
}
$advanced_settings = (array) PT_CV_Functions::setting_value( PT_CV_PREFIX . 'advanced-settings' );
if ( in_array( 'order', $advanced_settings ) ) {
$orderby = (array) PT_CV_Functions::setting_value( PT_CV_PREFIX . 'orderby' );
if ( $orderby[ 0 ] === 'dragdrop' ) {
$tpids = PT_CV_Functions::setting_value( PT_CV_PREFIX . 'order-dragdrop-pids' );
$apids = json_decode( cvp_stripallslashes( $tpids ), true );
// Posts order for current page
$current_page = PT_CV_Functions::get_global_variable( 'current_page' );
if ( !empty( $apids[ "$current_page" ] ) ) {
$pids_here = array_map( 'intval', $apids[ "$current_page" ] );
// Reorder posts by drag&drop order
$args = PT_CV_Functions_Pro::_array_replace( array_flip( $pids_here ), $args, 'prepend' );
}
}
}
return $args;
}
/**
* Filter span with
*
* @param array $args
* @param int $span_width
*
* @return array
*/
public static function filter_item_col_class( $args, $span_width ) {
$allow_xs = $allow_sm = 1;
if ( in_array( PT_CV_PREFIX . 'omain', $args ) ) {
$allow_xs = $allow_sm = 0;
}
if ( in_array( PT_CV_PREFIX . 'ocol', $args ) && PT_CV_Functions::get_global_variable( 'one_above' ) ) {
$allow_xs = $allow_sm = 0;
}
$others_one_col = in_array( PT_CV_PREFIX . 'oothers', $args ) && PT_CV_Functions::get_global_variable( 'other_columns' ) == 1;
if ( $allow_sm ) {
// One (on left) & others: respect the width proportion on tablet
if ( in_array( PT_CV_PREFIX . 'ocol', $args ) ) {
$args[] = 'col-sm-' . $span_width;
} else {
$tablet_col = (int) PT_CV_Functions::setting_value( PT_CV_PREFIX . 'resp-tablet-number-columns' );
if ( $others_one_col ) {
$tablet_col = 1;
}
$args[] = 'col-sm-' . (int) ( 12 / ($tablet_col ? $tablet_col : 2) );
}
}
if ( $allow_xs ) {
$mobile_col = (int) PT_CV_Functions::setting_value( PT_CV_PREFIX . 'resp-number-columns' );
// One (on left) & others: ensure each ocol shows in >= 50% of mobile screen
if ( in_array( PT_CV_PREFIX . 'ocol', $args ) && $mobile_col > 2 ) {
$mobile_col = 2;
}
if ( $others_one_col ) {
$mobile_col = 1;
}
$args[] = 'col-xs-' . (int) ( 12 / ($mobile_col ? $mobile_col : 1) );
}
return $args;
}
public static function filter_collapsible_open_all( $args ) {
$args = PT_CV_Functions::setting_value( PT_CV_PREFIX . 'collapsible-open-all' );
return $args;
}
/**
* Exclude sticky posts completely
*
* @param int $args
* @param array $settings The settings array of View
*
* @return int
*/
public static function filter_post__not_in( $args, $settings ) {
if ( in_array( PT_CV_Functions::setting_value( PT_CV_PREFIX . 'sticky-posts' ), array( 'exclude', 'prepend-all' ) ) ) {
$args = array_merge( (array) $args, get_option( 'sticky_posts', array() ) );
}
return $args;
}
/**
* Filter parent page ID
*
* @param array $args
*/
public static function filter_post_parent_id( $args ) {
global $pt_cv_glb;
$current_post = cvp_get_current_post_across_pagination( 'object' );
$post_id = !empty( $current_post->ID ) ? $current_post->ID : 0;
$post_parent = !empty( $current_post->post_parent ) ? $current_post->post_parent : 0;
// Current page of WP front-end
$pt_cv_glb[ 'current_post' ] = 0;
if ( PT_CV_Functions::setting_value( PT_CV_PREFIX . 'post_parent-current' ) ) {
$parent_page_opt = PT_CV_Functions::setting_value( PT_CV_PREFIX . 'post_parent-auto' );
if ( $current_post && !empty( $parent_page_opt ) ) {
switch ( $parent_page_opt ) {
case 'child-sib':
case 'yes':
$args = $post_parent ? $post_parent : $post_id;
break;
case 'siblings':
$args = $post_parent ? $post_parent : $args;
break;
case 'children':
$args = $post_id;
break;
}
if ( apply_filters( PT_CV_PREFIX_ . 'pp_exclude_current_post', true ) ) {
$pt_cv_glb[ 'current_post' ] = $post_id;
}
}
}
if ( $args ) {
$pt_cv_glb[ 'parent_page' ] = $args;
}
return $args;
}
/**
* Show this post or not
*
* @param array $args
*
* @return array
*/
public static function filter_show_this_post( $args ) {
global $pt_cv_glb;
if ( !empty( $pt_cv_glb[ 'current_post' ] ) && $args->ID === $pt_cv_glb[ 'current_post' ] ) {
$args = 0;
return $args;
}
/**
* Translation plugin: Hide posts if not translated
*/
$translation_plugin = PT_CV_Functions_Pro::has_translation_plugin();
if ( $translation_plugin ) {
if ( $translation_plugin === 'Polylang' ) {
$language = pll_current_language();
$post_lang = pll_get_post_language( $args->ID );
if ( $language && $post_lang && $post_lang !== $language ) {
$args = 0;
}
} elseif ( $translation_plugin === 'qTranslate' ) {
if ( function_exists( 'qtranxf_getAvailableLanguages' ) ) {
$available_languages = qtranxf_getAvailableLanguages( $args->post_content );
if ( $available_languages !== false ) {
global $q_config;
if ( !in_array( $q_config[ 'language' ], $available_languages ) ) {
$args = 0;
}
}
}
}
}
return $args;
}
/** New way to show/hide posts using restriction of Membership plugin
* Might use it for translation plugin too
* @since 5.9.0
*
* @param array $posts
* @param object $query
* @return array
*/
public static function filter_check_post_visibility( $posts, $query ) {
global $cvp_process_settings;
$advanced_settings = (array) PT_CV_Functions::setting_value( PT_CV_PREFIX . 'advanced-settings' );
$membership_plugin = PT_CV_Functions_Pro::has_access_restriction_plugin();
if ( $query->get( 'by_contentviews' ) && $cvp_process_settings && $membership_plugin && in_array( 'check_access_restriction', $advanced_settings ) ) {
foreach ( $posts as $idx => $item ) {
if ( $membership_plugin === 'Members' ) {
if ( !members_can_current_user_view_post( $item->ID ) ) {
unset( $posts[ $idx ] );
}
} elseif ( $membership_plugin === 'Paid Memberships Pro' ) {
$hasaccess = pmpro_has_membership_access( $item->ID );
if ( !$hasaccess ) {
unset( $posts[ $idx ] );
}
} elseif ( $membership_plugin === 'MemberMouse' ) {
if ( !mm_access_decision( array( "id" => $item->ID, "access" => "true" ) ) ) {
unset( $posts[ $idx ] );
}
} elseif ( $membership_plugin === 'Restrict Content Pro' ) {
if ( !rcp_user_can_access( get_current_user_id(), $item->ID ) ) {
unset( $posts[ $idx ] );
}
} elseif ( $membership_plugin === 's2Member' ) {
if ( !is_permitted_by_s2member( $item->ID ) ) {
unset( $posts[ $idx ] );
}
} elseif ( $membership_plugin === 'MemberPress' ) {
if ( class_exists( 'MeprRule' ) && method_exists( 'MeprRule', 'is_locked' ) && MeprRule::is_locked( $item ) ) {
unset( $posts[ $idx ] );
}
}
}
// then return only posts that belong to current page, need to test with Offset > 0
$query_args = PT_CV_Functions::get_global_variable( 'args' );
$ppp = PT_CV_Functions_Pro::get_limit_value( null, null, $query_args[ 'limit' ] );
if ( $ppp > $query_args[ 'posts_per_page_backup' ] ) {
$ppp = $query_args[ 'posts_per_page_backup' ];
}
$offset = (int) $query_args[ 'offset_backup' ];
$posts = array_slice( $posts, $offset, $ppp ); // don't use true for the 4th parameter
}
return $posts;
}
/**
* Add more fields to display, such as Social buttons...
*
* @param array $args
* @param object $post Current post object
*/
public static function filter_fields_html( $args, $post ) {
$dargs = PT_CV_Functions::get_global_variable( 'dargs' );
// Move special field to top
if ( !empty( $args[ 'special-field' ] ) ) {
$special_html = $args[ 'special-field' ];
unset( $args[ 'special-field' ] );
$args = array_merge( array( 'special-field' => $special_html ), $args );
}
// Move thumbnail top top (if it is at bottom) to ensure that Format works
if ( $dargs[ 'layout-format' ] === '2-col' ) {
$sfields = array_keys( $args );
if ( array_pop( $sfields ) === 'thumbnail' ) {
$thumb_html = $args[ 'thumbnail' ];
unset( $args[ 'thumbnail' ] );
$args = array_merge( array( 'thumbnail' => $thumb_html ), $args );
}
}
// Display social buttons
$other_settings = $dargs[ 'other-settings' ];
if ( isset( $other_settings[ 'social-show' ] ) && isset( $other_settings[ 'social-buttons' ] ) ) {
$buttons_html = array();
// Get post info
$url = apply_filters( PT_CV_PREFIX_ . 'social_url', get_permalink( $post ) );
$title = urlencode( get_the_title( $post ) );
// Get thumbnail
$thumbnail_id = get_post_thumbnail_id( $post->ID );
$media = wp_get_attachment_image_src( $thumbnail_id, 'medium' );
$media_url = is_array( $media ) ? $media[ 0 ] : '';
$media_alt = get_post_meta( $thumbnail_id, '_wp_attachment_image_alt', true );
$description = $media_alt ? urlencode( $media_alt ) : $title;
// Display selected buttons
foreach ( (array) $other_settings[ 'social-buttons' ] as $button ) {
$social_link = '';
// Link
switch ( $button ) {
case 'facebook':
$social_link = sprintf( 'https://www.facebook.com/sharer/sharer.php?u=%s', $url );
break;
case 'twitter':
$social_link = sprintf( 'https://x.com/intent/tweet?url=%s&text=%s', $url, $title );
break;
case 'linkedin':
$social_link = sprintf( 'https://www.linkedin.com/shareArticle?mini=true&url=%s&title=%s&summary=&source=', $url, $title );
break;
case 'pinterest':
$social_link = sprintf( 'https://pinterest.com/pin/create/bookmarklet/?url=%s&media=%s&description=%s', $url, $media_url, $description );
break;
}
if ( $social_link ) {
$buttons_html[] = sprintf( '', esc_url( $social_link ), PT_CV_PREFIX . 'social-' . $button );
}
}
$buttons_html = apply_filters( PT_CV_PREFIX_ . 'social_links', $buttons_html, $url, $title );
$args[ 'social-buttons' ] = sprintf( '%s
', PT_CV_PREFIX . 'social-buttons', implode( '', $buttons_html ) );
}
// Content on hover: Wrap title, content, meta fields... to a mask
if ( PT_CV_Functions_Pro::animate_activated_content_hover() ) {
global $pt_cv_glb, $pt_cv_id;
$exclude_field = apply_filters( PT_CV_PREFIX_ . 'hover_exclude', array() );
if ( !empty( $pt_cv_glb[ $pt_cv_id ][ 'animation' ][ 'exclude-fields' ] ) ) {
$exclude_field = $pt_cv_glb[ $pt_cv_id ][ 'animation' ][ 'exclude-fields' ];
}
if ( PT_CV_Functions::get_global_variable( 'view_type' ) === 'collapsible' ) {
$exclude_field[] = 'title';
}
$exclude_field = array_unique( $exclude_field );
$mask_wrapper = array();
$index = 0;
foreach ( $args as $field => $html ) {
$extra = $exclude_field ? !in_array( $field, (array) $exclude_field ) : true;
if ( $field != 'thumbnail' && $extra ) {
$index++;
// Add class to this field
$class = PT_CV_PREFIX . (($index % 2 == 1) ? 'animation-left' : 'animation-right');
$html = preg_replace( '/class="/', 'class="' . $class . ' ', $html, 1 );
$mask_wrapper[] = $html;
unset( $args[ $field ] );
}
}
if ( $mask_wrapper ) {
$mask_html = sprintf( '%s
', PT_CV_PREFIX . 'mask', implode( '', $mask_wrapper ) );
$extra_class = (PT_CV_Functions::setting_value( PT_CV_PREFIX . 'field-thumbnail-style' ) === 'img-circle') ? ' img-circle' : '';
$hover_html = sprintf( '%s
', PT_CV_PREFIX . 'hover-wrapper' . $extra_class, $args[ 'thumbnail' ] . $mask_html );
$position_order = array_keys( $args );
unset( $args[ 'thumbnail' ] );
$args = $args + array( 'thumbnail' => $hover_html );
// If title is always visible => Display Title in correct position with Thumbnail
if ( count( $position_order ) > 1 ) {
$args = PT_CV_Functions_Pro::_array_replace( array_flip( $position_order ), $args );
}
}
}
return $args;
}
/**
* Filter terms list in output
*
* @param mixed $args
* @return bool
*/
public static function filter_terms_to_filter( $args ) {
if ( PT_CV_Functions::get_global_variable( 'enable_shuffle_filter' ) ) {
// Hide filters of taxonomies
$hide_taxos = PT_CV_Functions::setting_value( PT_CV_PREFIX . 'taxonomy-filter-to-hide' );
if ( !empty( $hide_taxos ) ) {
foreach ( $hide_taxos as $taxonomy ) {
unset( $args[ $taxonomy ] );
}
}
}
/**
* Sort taxonomies by selected order
* @since 4.3
*/
$sf_display_order = PT_CV_Functions::setting_value( PT_CV_PREFIX . 'taxonomy-filter-display-order' );
if ( count( $args ) > 1 && !empty( $sf_display_order ) ) {
$args = PT_CV_Functions_Pro::_array_replace( array_flip( $sf_display_order ), $args );
}
return $args;
}
/**
* Detect is mobile
* @param bool $args
* @return bool
*/
public static function filter_is_mobile( $args ) {
$args = PT_CV_Functions_Pro::check_device( 'mobile' );
return $args;
}
public static function filter_public_localize_script_extra( $args ) {
$args[ 'is_mobile_tablet' ] = PT_CV_Functions_Pro::check_device( 'mobile_tablet' );
$args[ 'sf_no_post_found' ] = PT_CV_Html::no_post_found();
$args[ 'lf__separator' ] = CVP_LF_SEPARATOR;
return $args;
}
/**
* Format 2 columns: Exclude fields from wrapping
* @param type $args
* @return type
*/
public static function filter_2col_nowrap_fields( $args ) {
if ( PT_CV_Html_ViewType_Pro::ancient_timeline() ) {
$args[] = 'title';
$args[] = 'meta-fields';
}
return $args;
}
public static function filter_posts_orderby( $args, $query ) {
$query_args = PT_CV_Functions::get_global_variable( 'args' );
if ( cvp_is_main_view_query( $query ) ) {
$mto = PT_CV_Functions::get_global_variable( 'meta_query_origin' );
$cmto = is_array( $mto ) ? count( $mto ) : 0;
// Live filter might modify it, so need to confirm it is still random
if ( isset( $query_args[ PT_CV_PREFIX . 'orp' ], $query_args[ 'orderby' ] ) && $query_args[ 'orderby' ] === 'rand' ) {
// Fix: duplicated posts when order randonly & pagination
global $pt_cv_id;
$transient = 'cvp_seed_' . $pt_cv_id;
// Reset seed on first page
if ( PT_CV_Functions::get_global_variable( 'current_page' ) === 1 ) {
cvp_delete_transient( $transient );
}
// Get seed
$seed = cvp_get_transient( $transient );
if ( empty( $seed ) ) {
$seed = rand();
cvp_set_transient( $transient, $seed, 30 * MINUTE_IN_SECONDS );
}
$args = "RAND($seed)";
} elseif ( isset( $query_args[ PT_CV_PREFIX . 'ctf_sort_dfm' ] ) ) {
global $wpdb;
foreach ( $query_args[ PT_CV_PREFIX . 'ctf_sort_dfm' ] as $idx => $value ) {
$num = $cmto + $idx;
$tb_name = ($num === 0) ? $wpdb->postmeta : "mt{$num}";
if ( $value === '_UNIX_TIMESTAMP_' ) {
$dfm = '%Y-%m-%d' . (preg_match( "/CAST\($tb_name\.meta_value AS DATETIME\)/", $args ) ? ' %H:%i:%s' : '');
$args = preg_replace( "/CAST\($tb_name\.meta_value AS (DATE|DATETIME)\)/", "FROM_UNIXTIME($tb_name.meta_value, '$dfm')", $args );
} else {
$args = preg_replace( "/CAST\($tb_name\.meta_value AS (DATE|DATETIME)\)/", "STR_TO_DATE($tb_name.meta_value, '$value')", $args );
}
}
} elseif ( isset( $query_args[ PT_CV_PREFIX . 'ctftcm' ] ) ) {
global $wpdb;
foreach ( $query_args[ PT_CV_PREFIX . 'ctftcm' ] as $idx => $value ) {
$num = $cmto + $idx;
$tb_name = ($num === 0) ? $wpdb->postmeta : "mt{$num}";
$args = preg_replace( "/CAST\($tb_name\.meta_value AS SIGNED\)/", "CAST(REPLACE($tb_name.meta_value,',','') AS SIGNED)", $args );
}
} elseif ( isset( $query_args[ PT_CV_PREFIX . 'human_sort' ], $query_args[ 'orderby' ] ) && $query_args[ 'orderby' ] === 'post_title' ) {
global $wpdb;
$args = str_replace( "$wpdb->posts.post_title", "LENGTH($wpdb->posts.post_title), $wpdb->posts.post_title", $args );
}
}
return $args;
}
public static function filter_posts_where( $args, $query ) {
$query_args = PT_CV_Functions::get_global_variable( 'args' );
if ( cvp_is_main_view_query( $query ) ) {
if ( isset( $query_args[ PT_CV_PREFIX . 'ctf_filter_dfm' ] ) ) {
global $wpdb;
foreach ( $query_args[ PT_CV_PREFIX . 'ctf_filter_dfm' ] as $idx => $value ) {
$tb_name = ($idx === 0) ? $wpdb->postmeta : "mt{$idx}";
if ( $value === '_UNIX_TIMESTAMP_' ) {
$dfm = '%Y-%m-%d' . (preg_match( "/CAST\($tb_name\.meta_value AS DATETIME\)/", $args ) ? ' %H:%i:%s' : '');
$args = preg_replace( "/CAST\($tb_name\.meta_value AS (DATE|DATETIME)\)/", "CONVERT_TZ(FROM_UNIXTIME($tb_name.meta_value, '$dfm'),@@session.time_zone,'+0:00')", $args );
/* FROM_UNIXTIME(timestamp of date1) returns (date1 + time zone) value, so need to convert to get original date1 */
} else {
$args = preg_replace( "/CAST\($tb_name\.meta_value AS (DATE|DATETIME)\)/", "STR_TO_DATE($tb_name.meta_value, '$value')", $args );
}
}
}
}
return $args;
}
/**
* Store data of embed video for lazy load
*/
public static function filter_oembed_dataparse( $return, $data, $url ) {
if ( PT_CV_Functions::get_global_variable( 'do-lazy-load' ) ) {
global $cvp_oembed_data;
$cvp_oembed_data = $data;
}
return $return;
}
/**
* Make images lazy-loadable: replace src, srset attributes, add lazy class
*
* @param type $attr
* @param type $attachment
* @param type $size
* @return string
*/
public static function filter_wp_get_attachment_image_attributes( $attr, $attachment = null, $size = null ) {
if ( empty( $GLOBALS[ 'cvp_prevent_lazyload' ] ) && PT_CV_Functions::get_global_variable( 'do-lazy-load' ) ) {
$attr[ 'data-cvpsrc' ] = apply_filters( PT_CV_PREFIX_ . 'lazy_load_src', $attr[ 'src' ] );
$attr[ 'src' ] = plugins_url( 'public/assets/images/lazy_image.png', PT_CV_FILE_PRO );
$attr[ 'class' ] .= ' cvplazy';
// a valid srcset must contain space
if ( !empty( $attr[ 'srcset' ] ) && preg_match( '/\s+/', $attr[ 'srcset' ] ) ) {
$attr[ 'data-cvpset' ] = $attr[ 'srcset' ];
unset( $attr[ 'srcset' ] );
unset( $attr[ 'sizes' ] );
}
}
/**
* Asign post title for Featured image, if empty
* @since 4.6.0
*/
global $cvp_process_settings, $post;
if ( $cvp_process_settings && empty( $attr[ 'alt' ] ) && !empty( $post->post_title ) ) {
$attr[ 'alt' ] = apply_filters( PT_CV_PREFIX_ . 'alt_for_image', $post->post_title );
}
return $attr;
}
/**
* Reuse a View
* operator: IN (default), AND, NOT IN
* relation: AND, OR
*
* [pt_view id="A" author=1]
* [pt_view id="A" cat="foo,bar,content"]
* [pt_view id="A" tag="foo,bar,content"]
* [pt_view id="A" cat="1,2,3" field=id]
* [pt_view id="A" tag="1,2,3" field=id]
* [pt_view id="A" tag="666" field="slug"] # for numeric value
* [pt_view id="A" taxonomy="testimonial" terms="foo,bar"]
* [pt_view id="A" taxonomy="testimonial" terms="foo,bar" operator="NOT IN"]
* [pt_view id="A" cat="foo,bar" tag="1,2" relation="AND" ] // don't support "operator" of multiple taxonomies
* [pt_view id="A" taxonomy="testimonial" terms="foo,bar" taxonomy2="customer" terms2="boo,far"] @since 1.8.9
*
* @param array $args
*
* @return int
*/
public static function reuse_view( $args ) {
$sc_params = PT_CV_Functions::get_global_variable( 'shortcode_params' );
if ( !$sc_params ) {
return $args;
}
$cur_pid = get_queried_object_id();
$reuse = 0;
// Store taxonomy filter query parameters
$taxonomies = $terms = array();
if ( !empty( $sc_params[ 'cat' ] ) ) {
$taxonomies[] = 'category';
$terms[] = explode( ',', trim( $sc_params[ 'cat' ] ) );
}
if ( !empty( $sc_params[ 'tag' ] ) ) {
$taxonomies[] = 'post_tag';
$terms[] = explode( ',', trim( $sc_params[ 'tag' ] ) );
}
if ( !empty( $sc_params[ 'taxonomy' ] ) ) {
$taxonomies[] = cv_esc_sql( $sc_params[ 'taxonomy' ] );
$terms[] = explode( ',', trim( $sc_params[ 'terms' ] ) );
}
if ( !empty( $sc_params[ 'taxonomy2' ] ) ) {
$taxonomies[] = cv_esc_sql( $sc_params[ 'taxonomy2' ] );
$terms[] = explode( ',', trim( $sc_params[ 'terms2' ] ) );
}
if ( $taxonomies && $terms ) {
$filter_taxonomies = array();
// Get operator
$operator = !empty( $sc_params[ 'operator' ] ) ? strtoupper( $sc_params[ 'operator' ] ) : 'IN';
if ( !in_array( $operator, array( 'IN', 'NOT IN', 'AND' ) ) ) {
$operator = 'IN';
}
$_field = !empty( $sc_params[ 'field' ] ) ? $sc_params[ 'field' ] : 'slug';
// Generate array of filter parameters
foreach ( $taxonomies as $idx => $taxonomy ) {
// Term of taxonomy
$term = (array) $terms[ $idx ];
// Filter by id or slug
$terms_check = array_map( 'intval', $term );
$field = $_field ? $_field : ( ( $terms_check[ 0 ] != 0 ) ? 'id' : 'slug' );
// Get terms of current post
if ( isset( $term[ 0 ] ) && $term[ 0 ] === 'GET_CURRENT' ) {
$term = cvp_get_same_terms( $taxonomy );
if ( $term ) {
$field = 'id';
if ( !empty( $cur_pid ) ) {
$args[ 'post__not_in' ] = array_merge( (array) $args[ 'post__not_in' ], array( $cur_pid ) );
}
}
}
// Get current term
if ( isset( $term[ 0 ] ) && $term[ 0 ] === 'GET_CURRENT_TERM' ) {
$qobj = get_queried_object();
if ( isset( $qobj->term_id ) ) {
$term = $qobj->term_id;
$field = 'id';
}
}
// Get current author archive id
if ( isset( $term[ 0 ] ) && $term[ 0 ] === 'GET_CURRENT_AUTHOR' ) {
$term = $cur_pid;
$field = 'id';
}
// Able to use operator2, operator3, operator4
if ( $idx > 0 && !empty( $sc_params[ 'operator' . ($idx + 1) ] ) ) {
$operator = strtoupper( $sc_params[ 'operator' . ($idx + 1) ] );
if ( !in_array( $operator, array( 'IN', 'NOT IN', 'AND' ) ) ) {
$operator = 'IN';
}
}
$filter_taxonomies[] = array(
'taxonomy' => $taxonomy,
'field' => $field,
'terms' => $term,
'operator' => $operator,
'include_children' => apply_filters( PT_CV_PREFIX_ . 'include_children', $operator == 'AND' ? false : true )
);
}
// Multiple taxonomies filter
if ( count( $taxonomies ) > 1 ) {
// Get relation
$relation = strtoupper( !empty( $sc_params[ 'relation' ] ) ? $sc_params[ 'relation' ] : 'AND' );
if ( !in_array( $relation, array( 'OR', 'AND' ) ) ) {
$relation = 'AND';
}
$filter_taxonomies[ 'relation' ] = $relation;
}
if ( $filter_taxonomies ) {
if ( empty( $sc_params[ 'reuse_tax_query' ] ) || empty( $args[ 'tax_query' ] ) ) {
$args[ 'tax_query' ] = $filter_taxonomies;
} else {
$args[ 'tax_query' ] = array_merge( $args[ 'tax_query' ], $filter_taxonomies );
}
$reuse++;
}
}
if ( !empty( $sc_params[ 'post_id' ] ) ) {
$values = explode( ',', trim( $sc_params[ 'post_id' ] ) );
if ( $values[ 0 ] === 'GET_CURRENT' && !empty( $cur_pid ) ) {
$values = array( $cur_pid );
}
if ( is_array( $values ) ) {
$args[ 'post__in' ] = array_map( 'intval', $values );
$reuse++;
}
}
if ( !empty( $sc_params[ 'author' ] ) ) {
$values = explode( ',', trim( $sc_params[ 'author' ] ) );
$args[ 'author__in' ] = array_map( 'intval', $values );
$reuse++;
}
if ( !empty( $sc_params[ 'post_type' ] ) ) {
$args[ 'post_type' ] = $sc_params[ 'post_type' ];
$reuse++;
}
if ( !empty( $sc_params[ 'post_parent' ] ) ) {
$parent = $sc_params[ 'post_parent' ];
if ( $parent === 'GET_CURRENT' && !empty( $cur_pid ) ) {
$parent = $cur_pid;
}
$args[ 'post_parent__in' ] = array_map( 'intval', explode( ',', $parent ) );
unset( $args[ 'post_parent' ] );
$reuse++;
}
if ( !empty( $sc_params[ 'keyword' ] ) ) {
$args[ 's' ] = $sc_params[ 'keyword' ];
$reuse++;
}
if ( !empty( $sc_params[ 'custom_field_value' ] ) ) {
$values = explode( ',', $sc_params[ 'custom_field_value' ] );
foreach ( $values as $idx => $value ) {
if ( isset( $args[ 'meta_query' ][ $idx ][ 'value' ] ) && $args[ 'meta_query' ][ $idx ][ 'value' ] !== '' ) {
$args[ 'meta_query' ][ $idx ][ 'value' ] = $value;
$reuse++;
}
}
}
if ( !empty( $sc_params[ 'limit' ] ) || !empty( $sc_params[ 'offset' ] ) ) {
$reuse++;
}
if ( $reuse ) {
PT_CV_Functions::set_global_variable( 'reused_view', true );
}
do_action( PT_CV_PREFIX_ . 'custom_view_parameters' );
return $args;
}
/**
* Print style of views
*/
public static function action_print_view_style() {
$dargs = PT_CV_Functions::get_global_variable( 'dargs' );
if ( !isset( $dargs ) ) {
return '';
}
ob_start();
$style_fonts = PT_CV_Html_Pro::view_styles( $dargs[ 'view-style' ] );
// Print inline style (font family, font style, font size...)
if ( !empty( $style_fonts[ 'css' ] ) ) {
echo PT_CV_Html::inline_style( $style_fonts[ 'css' ] );
}
// Attach link of google fonts if have
if ( $style_fonts && is_array( $style_fonts[ 'links' ] ) ) {
foreach ( $style_fonts[ 'links' ] as $link ) {
$view_fonts = (array) PT_CV_Functions::get_global_variable( 'included-fonts' );
if ( !in_array( $link, $view_fonts ) ) {
printf( "", urlencode( $link ) );
$view_fonts[] = $link;
PT_CV_Functions::set_global_variable( 'included-fonts', $view_fonts );
}
}
}
$view_style = ob_get_clean();
if ( apply_filters( PT_CV_PREFIX_ . 'inline_view_style', 1 ) ) {
echo $view_style;
} else {
global $cvp_view_css;
if ( !$cvp_view_css ) {
$cvp_view_css = array();
}
$cvp_view_css[] = $view_style;
}
}
/**
* Filter before run query
*/
public static function action_before_query() {
$action = 'add_filter';
self::_abq_product( $action );
}
/**
* Filter after run query
*
*/
public static function action_after_query() {
$action = 'remove_filter';
self::_abq_product( $action );
}
private static function _abq_product( $function ) {
$view_settings = PT_CV_Functions::get_global_variable( 'view_settings' );
$content_type = PT_CV_Functions::setting_value( PT_CV_PREFIX . 'content-type', $view_settings );
if ( $content_type === 'product' ) {
$products_list = PT_CV_Functions::setting_value( PT_CV_PREFIX . 'products-list', $view_settings );
if ( $products_list === 'top_rated_products' ) {
$function( 'posts_clauses', array( 'PT_CV_WooCommerce', 'order_by_rating_post_clauses' ) );
}
}
}
/**
* Add custom global variables
*/
public static function action_add_global_variables() {
$enabled_shuffle = PT_CV_Functions::setting_value( PT_CV_PREFIX . 'enable-taxonomy-filter' ) && PT_CV_Functions_Pro::check_dependences( 'taxonomy-filter' );
PT_CV_Functions::set_global_variable( 'enable_shuffle_filter', $enabled_shuffle );
if ( PT_CV_Functions::setting_value( PT_CV_PREFIX . 'show-field-format-icon' ) ) {
PT_CV_Functions::set_global_variable( 'dashicons', 1 );
}
$do_lazy = apply_filters( PT_CV_PREFIX_ . 'do_lazy_image', PT_CV_Functions::setting_value( PT_CV_PREFIX . 'field-thumbnail-lazyload' ) );
PT_CV_Functions::set_global_variable( 'do-lazy-load', $do_lazy );
$collapsible_shuffle = $enabled_shuffle && PT_CV_Functions::get_global_variable( 'view_type' ) === 'collapsible';
PT_CV_Functions::set_global_variable( 'collapsible_shuffle', $collapsible_shuffle );
}
/**
* Enqueue special assets on the fly
*/
public static function action_enqueue_assets() {
if ( PT_CV_Functions::get_global_variable( 'dashicons' ) ) {
wp_enqueue_style( 'dashicons' );
}
}
/**
* Append HTML to post title
*
* @param string $args The excerpt output
* @param int $post Post object
*
* @return string
*/
public static function action_item_extra_html( $post ) {
echo PT_CV_Functions_Pro::show_edit_button( $post );
}
public static function action_view_process_start() {
global $cvp_process_settings;
$cvp_process_settings = true;
}
/**
* Flush view data if not needed, or cause conflicts
*/
public static function action_view_process_end() {
PT_CV_Functions::set_global_variable( 'do-lazy-load', 0 );
global $cvp_process_settings;
$cvp_process_settings = false;
}
private static function _is_attachment( $post ) {
return get_post_type( $post->ID ) === 'attachment';
}
}
}
/**
* Content Views for Public
*
* @package PT_Content_Views_Pro
* @author PT Guy
* @license GPL-2.0+
* @link http://www.contentviewspro.com/
* @copyright 2014 PT Guy
*/
if ( !defined( 'ABSPATH' ) ) {
exit;
}
class PT_Content_Views_Pro {
/**
* The variable name is used as the text domain when internationalizing strings
* of text. Its value should match the Text Domain file header in the main
* plugin file.
*
* @since 1.0.0
*
* @var string
*/
protected $plugin_slug = 'content-views-pro';
/**
* Instance of this class.
*
* @since 1.0.0
*
* @var object
*/
protected static $instance = null;
/**
* Initialize the plugin by setting localization and loading public scripts
* and styles.
*
* @since 1.0.0
*/
private function __construct() {
// Load plugin text domain
add_action( 'init', array( $this, 'load_plugin_textdomain' ), 30 );
// Activate plugin when new blog is added
add_action( 'wpmu_new_blog', array( $this, 'activate_new_site' ) );
// Load public-facing style sheet and JavaScript.
add_action( PT_CV_PREFIX_ . 'frontend_styles', array( $this, 'enqueue_styles' ) );
add_action( PT_CV_PREFIX_ . 'frontend_scripts', array( $this, 'enqueue_scripts' ) );
// Output assets content at footer of page
add_action( 'wp_head', array( __CLASS__, 'print_custom_css' ), 100 );
add_action( 'wp_footer', array( __CLASS__, 'print_custom_js' ), 100 );
add_action( 'current_screen', array( __CLASS__, 'action_ck_lcs' ) );
// Ajax action
$action = 'share_count';
add_action( 'wp_ajax_' . $action, array( 'PT_CV_Functions_Pro', 'ajax_callback_' . $action ) );
add_action( 'wp_ajax_nopriv_' . $action, array( 'PT_CV_Functions_Pro', 'ajax_callback_' . $action ) );
// Custom hooks for both preview & frontend
PT_CV_Hooks_Pro::init();
}
/**
* Return the plugin slug.
*
* @since 1.0.0
*
* @return Plugin slug variable.
*/
public function get_plugin_slug() {
return $this->plugin_slug;
}
/**
* Return an instance of this class.
*
* @since 1.0.0
*
* @return object A single instance of this class.
*/
public static function get_instance() {
// If the single instance hasn't been set, set it now.
if ( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
/**
* Fired when a new site is activated with a WPMU environment.
*
* @since 1.0.0
*
* @param int $blog_id ID of the new blog.
*/
public function activate_new_site( $blog_id ) {
if ( 1 !== did_action( 'wpmu_new_blog' ) ) {
return;
}
switch_to_blog( $blog_id );
PT_CV_Plugin_Pro_Actions::single_activate();
restore_current_blog();
}
/**
* Load the plugin text domain for translation.
*
* @since 1.0.0
*/
public function load_plugin_textdomain() {
// WPLANG is no longer needed since 4.0
$locale = get_locale();
$old_lang_file = WP_LANG_DIR . "/content-views-pro/content-views-pro-{$locale}.mo";
$lang_pack = WP_LANG_DIR . "/plugins/content-views-pro-{$locale}.mo";
$plugin_lang_dir = dirname( plugin_basename( PT_CV_FILE_PRO ) ) . '/languages/';
if ( file_exists( $old_lang_file ) ) {
load_textdomain( 'content-views-pro', $old_lang_file );
} elseif ( file_exists( $lang_pack ) ) {
load_textdomain( 'content-views-pro', $lang_pack );
} else {
load_plugin_textdomain( 'content-views-pro', FALSE, $plugin_lang_dir );
}
}
/**
* Register and enqueue public-facing style sheet.
*
* @since 1.0.0
*/
public function enqueue_styles() {
PT_CV_Html_Pro::frontend_styles();
}
/**
* Register and enqueues public-facing JavaScript files.
*
* @since 1.0.0
*/
public function enqueue_scripts() {
PT_CV_Html_Pro::frontend_scripts();
}
/**
* Print custom CSS
*
* @return void
*/
public static function print_custom_css() {
$custom_css = PT_CV_Functions::get_option_value( 'custom_css' );
if ( $custom_css ) {
echo PT_CV_Html::inline_style( $custom_css, 'custom' );
}
}
/**
* Print custom JS
*
* @return void
*/
public static function print_custom_js() {
// Print custom JS
$custom_js = PT_CV_Functions::get_option_value( 'custom_js' );
$custom_js = apply_filters( PT_CV_PREFIX_ . 'extra_custom_js', $custom_js );
if ( $custom_js ) {
echo PT_CV_Html::inline_script( $custom_js, true, 'custom' );
}
// Print View JS if it is not printed before
global $cvp_view_css;
if ( !empty( $cvp_view_css ) ) {
foreach ( (array) $cvp_view_css as $css ) {
print apply_filters( PT_CV_PREFIX_ . 'delayed_css', $css );
}
}
}
public static function action_ck_lcs( $screen ) {
if ( isset( $screen->id ) && strpos( $screen->id, 'content-views-setting' ) !== false ) {
if ( !get_option( 'pt_cv_pro_activate' ) && get_option( 'pt_cv_action_fail', 0 ) < 30 && !get_transient( 'pt_cv_active_fail' ) ) {
PT_CV_Plugin_Pro_Actions::request_cvpsys( 'activate' );
}
}
}
}