PATH:
home
/
fengshp
/
www
/
wp-content
/
plugins
/
themify-builder-pro
/
includes
/
dynamic-content
<?php /** * @package Themify Builder Pro * @link https://themify.me/ */ class Tbp_Dynamic_Item_PTBRelations extends Tbp_Dynamic_Item { public static function is_available():bool { return class_exists( 'Themify_Builder_Plugin_Compat_ptb',false ); } public static function get_category():string { return 'ptb'; } public static function get_type():array { return array( 'wp_editor' ); } public static function get_label():string { return __( 'PTB (Relations)', 'tbp' ); } public static function get_value(array $args = array()):?string { $args = wp_parse_args( $args, array( 'show' => 'grid', 'columns' => 1, 'minSlides' => 1, 'autoHover' => 1, 'pause' => 1, 'hide_pager' => 0, 'hide_controls' => 0, 'orderby' => 'post__in', 'order' => 'asc', 'limit' => '', 'masonry' => 0, ) ); if ( empty( $args['field'] ) ) { return ''; } list( $post_type, $field_name ) = explode( ':', $args['field'] ); $ptb_options = PTB::get_option(); $fields = $ptb_options->get_cpt_cmb_options( $post_type ); $def = isset( $fields[ $field_name ] ) ? $fields[ $field_name ] : false; if ( $def === false ) { return ''; } $related_type = $def['post_type']; $rel_options = PTB_Relation::get_option(); $template = PTB::get_option()->get_post_type_template_by_type( $related_type ); if ( ! $template ) { return ''; } $content = ''; $is_shortcode = PTB_Public::$shortcode; PTB_Public::$shortcode = true; $ver = PTB::get_plugin_version( WP_PLUGIN_DIR . '/themify-ptb-relation/themify-ptb-relation.php' ); $themplate = new PTB_Form_PTT_Them( 'ptb', $ver ); $cf_value = get_post_meta( $args['post_id'] ?? get_the_ID(), "ptb_{$field_name}", true ); $relType = ! empty( $cf_value['relType'] ) ? (int) $cf_value['relType'] : 1; $ids = ! empty( $cf_value['ids'] ) ? $cf_value['ids'] : $cf_value; $ids = array_filter( is_array($ids)?$ids:explode( ', ', $ids ) ); if ( empty( $ids ) ) { return ''; } $query_args = array( 'post_type' => $related_type, 'post_status' => 'publish', 'order' => $args['order'], 'orderby' => $args['orderby'], 'no_found_rows' => 1, ); if ( $relType === 1 ) { $query_args['post__in'] = $ids; $query_args['posts_per_page'] = empty( $args['limit'] ) ? count( $ids ) : $args['limit']; } else { $tmp = array(); $terms = get_terms( array( 'include' => $ids ) ); foreach ( $terms as $term ) { $tmp[ $term->taxonomy ][] = $term->term_id; } $value = array(); $temp = array(); foreach ( $tmp as $k => $v ) { $value[] = array( 'taxonomy' => $k, 'field' => 'term_id', 'terms' => $v ); } if ( ! empty( $value ) ) { $value['relation'] = 'AND'; $query_args['tax_query'] = $value; } if ( empty( $args['limit'] ) ) { $query_args['nopaging'] = 1; } else { $query_args['posts_per_page'] = $args['limit']; } } global $post; if(isset($post)){ $saved_post = clone $post; } $query = new WP_Query($query_args); $item_tag = 'div'; if ( ! empty( $args[$related_type . '_template'] ) && $template->get_custom_template( $args[$related_type . '_template'] ) ) { $themplate_layout = $template->get_custom_template( $args[$related_type . '_template'] ); } else { $themplate_layout = empty( $template->get_archive() ) ? PTB_Post_Type_Template::get_default_archive_template() : $template->get_archive(); } while ( $query->have_posts() ) { $query->the_post(); $cmb_options = $post_support = $post_meta = $post_taxonomies = array(); $ptb_options->get_post_type_data( $related_type, $cmb_options, $post_support, $post_taxonomies ); $post_meta['post_url'] = get_permalink(); $post_meta['taxonomies'] = ! empty( $post_taxonomies ) ? wp_get_post_terms( get_the_ID(), array_values($post_taxonomies ) ) : array(); $post_meta = array_merge( $post_meta, get_post_custom(), get_post( '', ARRAY_A ) ); $item_class = 'ptb_relation_item ptb_post'; if ( $args['show'] === 'slider' ) { $item_class .= ' tf_swiper-slide'; } $content .= '<' . $item_tag . ' class="' . $item_class . '">' . $themplate->display_public_themplate( $themplate_layout, $post_support, $cmb_options, $post_meta, $related_type, false ) . '</' . $item_tag . '>'; } PTB_Public::$shortcode = $is_shortcode; $query=null; /* reset query back to original */ if ( isset( $saved_post )) { $post = $saved_post; setup_postdata( $saved_post ); unset($saved_post); } $wrap_class = 'ptb_loops_shortcode ptb_relation_posts tf_clearfix'; if ( $args['show'] === 'slider' ) { if ( ! wp_script_is( 'ptb-relation' ) ) { wp_enqueue_script( 'ptb-relation' ); } wp_enqueue_style( 'ptb-slider' ); $content = '<div class="ptb_slider tf_carousel tf_swiper-container" data-visible="' . $args['minSlides'] .'" data-pause_hover="' . $args['autoHover'] . '" data-auto="' . $args['pause'] .'" data-pager="' . ( (int) $args['hide_pager'] === 1 ? 0 : 1 ) . '" data-slider_nav="' . ( (int) $args['hide_controls'] === 1 ? 0 : 1 ) . '" data-speed="1000" > <div class="tf_swiper-wrapper">' . $content . '</div>' . '</div>'; } else { $wrap_class .= ' ptb_loops_wrapper ptb_grid'; $wrap_class .= ' ptb_grid' . $args['columns']; if ( $args['masonry'] ) { wp_enqueue_script( 'ptb-relation' ); $wrap_class .= ' ptb_relation_masonry'; } } if ( ! empty( $content ) ) { $content = '<div class="ptb_module ptb_relation">' . '<div class="' . $wrap_class . '">' . $content . '</div>' . '</div>'; } return $content; } public static function get_options():array { return array( array( 'type' => 'ptb_relation', ), array( 'label' => 's', 'id' => 'show', 'type' => 'select', 'options' => array( 'grid' => 'grid', 'slider' => 'slider', ), 'binding' => array( 'grid' => array( 'show' => array( 'columns', 'masonry' ), 'hide' => array( 'minSlides', 'autoHover', 'pause', 'hide_pager', 'hide_controls' ) ), 'slider' => array( 'hide' => array( 'columns', 'masonry' ), 'show' => array( 'minSlides', 'autoHover', 'pause', 'hide_pager', 'hide_controls' ) ), ), 'bindingContext' => '.tb_field_group', ), array( 'label' => __( 'Grid Columns', 'tbp' ), 'id' => 'columns', 'type' => 'select', 'options' => array( 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6 ), ), array( 'label' => 'masnry', 'id' => 'masonry', 'type' => 'select', 'options' => array( 'no', 'y' ), ), array( 'label' => 'visibsl', 'id' => 'minSlides', 'type' => 'select', 'options' => array( 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7 ), ), array( 'label' => 'pauseonh', 'id' => 'autoHover', 'type' => 'select', 'options' => array( 1=> 'y', 0 => 'no' ), ), array( 'label' => 'ascroll', 'id' => 'pause', 'type' => 'select', 'options' => array( 1 => '1s', 2 => '2s', 3 => '3s', 4 => '4s', 5 => '5s', 6 => '6s', 7 => '7s', 8 => '8s', 9 => '9s', 0 => 'off' ), ), array( 'label' => __( 'Hide Slider Pagination', 'tbp' ), 'id' => 'hide_pager', 'type' => 'select', 'options' => array( 1 => 'y', 0=> 'no'), ), array( 'label' => __( 'Hide Slider arrow buttons', 'tbp' ), 'id' => 'hide_controls', 'type' => 'select', 'options' => array( 'no', 'y' ), ), array( 'label' => 'npost', 'id' => 'limit', 'type' => 'text', 'help' => 'nposth' ), array( 'label' => 'order', 'id' => 'order', 'type' => 'select', 'options' => array( 'asc' => 'asc', 'desc' => 'descend' ), ), array( 'label' => 'orderby', 'id' => 'orderby', 'type' => 'select', 'options' => array( 'date' => 'date', 'id' => 'id', 'author' => 'author', 'title' => 'title', 'name' => 'name', 'modified' => 'md', 'rand' => 'rand', 'comment_count' => 'com_count', 'menu_order' => __( 'Menu Order', 'tbp' ), ), ), ); } }
[+]
..
[-] ProductSalePrice.php
[edit]
[-] PTBGallery.php
[edit]
[-] WCCheckoutURL.php
[edit]
[-] PostDate.php
[edit]
[-] ACFURL.php
[edit]
[-] PostTermsClass.php
[edit]
[-] PostAuthorURL.php
[edit]
[-] ACFWysiwyg.php
[edit]
[-] PostAuthorEmail.php
[edit]
[-] PTBGalleryAsText.php
[edit]
[-] PTBAudioPlaylist.php
[edit]
[-] ProductTitle.php
[edit]
[-] PTBIconAsIcon.php
[edit]
[-] PTBTelephone.php
[edit]
[-] PTBSelectClass.php
[edit]
[-] ProductCartUrl.php
[edit]
[-] PostAuthorMeta.php
[edit]
[-] tbpTermCover.php
[edit]
[-] PTBEmail.php
[edit]
[-] ArchiveTitle.php
[edit]
[-] SiteURL.php
[edit]
[-] PostAuthorBio.php
[edit]
[-] ACFChoice.php
[edit]
[-] PTBDateAsText.php
[edit]
[-] ACFGallery.php
[edit]
[-] PTBRatingAsText.php
[edit]
[-] ACFEmail.php
[edit]
[-] Option.php
[edit]
[-] PostAuthorClass.php
[edit]
[-] PostCommentCount.php
[edit]
[-] ProductAttributes.php
[edit]
[-] PTBRadioButtonClass.php
[edit]
[-] ACFNumber.php
[edit]
[-] PTBAudio.php
[edit]
[-] PTBTextarea.php
[edit]
[-] PostTerms.php
[edit]
[-] ACFDate.php
[edit]
[-] PTBText.php
[edit]
[-] PostFeaturedImage.php
[edit]
[-] PTBAccordion.php
[edit]
[-] ACFoEmbed.php
[edit]
[-] ProductSKU.php
[edit]
[-] Shortcode.php
[edit]
[-] CurrentDate.php
[edit]
[-] PTBFile.php
[edit]
[-] PTBLinkButton.php
[edit]
[-] PTBMap.php
[edit]
[-] PTBRadioButton.php
[edit]
[-] CustomField.php
[edit]
[-] PTBRating.php
[edit]
[-] ACFFile.php
[edit]
[-] PTBCheckboxClass.php
[edit]
[-] FileContent.php
[edit]
[-] PTBVideoPlaylist.php
[edit]
[-] PTBRepeatableText.php
[edit]
[-] ProductDescription.php
[edit]
[-] PTBIcon.php
[edit]
[-] ArchiveDescription.php
[edit]
[-] PostImageAttachments.php
[edit]
[-] ACFMap.php
[edit]
[-] PTBRelations.php
[edit]
[-] PostAuthorName.php
[edit]
[-] PostAuthorAvatar.php
[edit]
[-] PTBVideo.php
[edit]
[-] ACFText.php
[edit]
[-] PTBDate.php
[edit]
[-] ACFImage.php
[edit]
[-] ACFTextarea.php
[edit]
[-] ProductImage.php
[edit]
[-] PTBNumber.php
[edit]
[-] ProductRating.php
[edit]
[-] ProductStock.php
[edit]
[-] PTBImage.php
[edit]
[-] ProductPrice.php
[edit]
[-] SiteDescription.php
[edit]
[-] EventPostDate.php
[edit]
[-] SiteTitle.php
[edit]
[-] ProductGallery.php
[edit]
[-] MediaLibrary.php
[edit]
[-] RandomNumber.php
[edit]
[-] PostExcerpt.php
[edit]
[-] PTBCheckbox.php
[edit]
[-] ProductCatImage.php
[edit]
[-] PostTitle.php
[edit]
[-] PostClass.php
[edit]
[-] PTBProgressBar.php
[edit]
[-] PTBIconAsText.php
[edit]
[-] ACFPageLink.php
[edit]
[-] PostPermalink.php
[edit]
[-] SiteIcon.php
[edit]
[-] PTBAcc.php
[edit]
[-] PTBSelect.php
[edit]