Marcos_Alexandre

FIlter Progress Map

Mar 23rd, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.20 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * Limit excerpt to a number of characters
  5.  *
  6.  * @param string $excerpt
  7.  * @return string
  8.  */
  9. function custom_short_excerpt($excerpt){
  10.     return substr($excerpt, 0, 200);
  11. }
  12. add_filter('the_excerpt', 'custom_short_excerpt');
  13.  
  14.  
  15. /* Funtion Count Posts in Category */
  16.  
  17. function number_postpercat($idcat) {
  18.     global $wpdb;
  19.     $query = "SELECT count FROM $wpdb->term_taxonomy WHERE term_id = $idcat";
  20.     $num = $wpdb->get_col($query);
  21.     echo $num[0];
  22. }
  23.  
  24. /**
  25.  * Change the default settings of a map
  26.  *
  27.  * @since "Progress Map v3"
  28.  */
  29. function cspm_update_map_settings($map_settings, $map_id){
  30.  
  31.     if (!class_exists('CspmMainMap'))
  32.      return;
  33.    
  34.     $CspmMainMap = CspmMainMap::this();
  35.    
  36.     $fields_prefix = $CspmMainMap->metafield_prefix;
  37.    
  38.     if(is_tax() || is_category() || is_tag() || is_archive()){
  39.        
  40.         $queried_object = get_queried_object();
  41.  
  42.         $taxonomy = (isset($queried_object->taxonomy)) ? $queried_object->taxonomy : ''; // The taxonomy slug/name
  43.         $term_id = (isset($queried_object->term_id)) ? $queried_object->term_id : ''; // The term ID
  44.            
  45.         $map_settings[$fields_prefix.'_taxonomie_'.$taxonomy] = serialize(array($term_id));
  46.        
  47.     }
  48.    
  49.     return $map_settings;
  50.    
  51. }
  52. add_filter('cspm_map_settings', 'cspm_update_map_settings', 10, 2);
  53.  
  54.  
  55. /**
  56.  * List & Filter!
  57.  * This will change the content of the items displayed for the list
  58.  *
  59.  * @default_content | The default content when there's no custom content to display.
  60.  * @post_id | The ID of the post.
  61.  * @view | List view. Possible value are "list" & "grid".
  62.  * @filter | Whether the search filter is used or not. Possible values are "yes" and "no".
  63.  * @map_id | The ID of the map
  64.  * @latLng | The coordinates (Latitude & Longitude) of the post on the map. Laitude and Longitude separated by underscore, for example, (15.6540_50.54802)
  65.  *
  66.  */
  67. function cspml_change_list_items_content($default_content, $post_id, $view, $filter, $map_id, $latLng){
  68.  
  69.  
  70.     global $post;
  71.  
  72.     $output = '';    
  73.  
  74.     $post_record = get_post( $post_id, ARRAY_A, 'display' );
  75.  
  76.     $output .= trim(preg_replace('/\s+/', ' ', $post_record['post_excerpt']));        
  77.        
  78.         include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
  79.  
  80.         // Check for plugin using plugin name
  81.             if ( is_plugin_active( 'reviewer/reviewer.php' ) ):
  82.  
  83.             //plugin is activated
  84.             $output = do_shortcode('[rwp_users_rating_stars id="-1" template="rwp_template_5aa830c899604"]');
  85.                        
  86.         endif;
  87.        
  88.  
  89.         $price = get_field('ticket_price');
  90.         $time = get_field('time_duration_tour');
  91.         $from_tour = get_field('from_tour');
  92.         $link = get_post_permalink();
  93.         //$text_from =  esc_html( 'From', 'veditalia' );
  94.         $text_button =  esc_html( 'Book now', 'veditalia' );
  95.         $simbol = esc_html( '€', 'veditalia' );
  96.  
  97.         $output .= '<p class="hour-tour">';
  98.  
  99.         if ( $time != '' ): ?>
  100.  
  101.             <?php $output .= '<p class="time_duration_tour">'.$time.'</p>' ?>
  102.  
  103.         <?php
  104.  
  105.         endif;
  106.  
  107.         if ( $from_tour != '' ): ?>
  108.  
  109.             <?php $output .= '<p class="from_tour">' . '&nbsp' . $from_tour . '</p>' ?>
  110.  
  111.         <?php
  112.  
  113.         endif; 
  114.  
  115.         $output .= '</p>';                       
  116.        
  117.  
  118.         if ( $price != '' ): ?>
  119.  
  120.             <?php $output .= '<p class="price-tour-p"><span class="price-tour">' . $simbol . $price . '</span>' ?>
  121.         <?php
  122.  
  123.         endif; ?>
  124.  
  125.             <?php $output .= '<span class="btn-book"><a class="btn btn-primary pull-right btn-sm book-now" itemprop="url" href="'. $link . '">'.$text_button.'</a></span></p>' ?>
  126.  
  127.  
  128.         <?php
  129.  
  130.     wp_reset_postdata();
  131.  
  132.     return !empty($output) ? $output : $default_content;
  133.  
  134. }
  135. add_filter('cspml_list_item_description', 'cspml_change_list_items_content', 10, 6);
  136. add_filter('cspml_grid_item_description', 'cspml_change_list_items_content', 10, 6);
  137.  
  138.  
  139. /**
  140.  * List & Filter!
  141.  * This will change the content of the items displayed for the list
  142.  *
  143.  * @default_content | The default content when there's no custom content to display.
  144.  * @post_id | The ID of the post.
  145.  * @view | List view. Possible value are "list" & "grid".
  146.  * @filter | Whether the search filter is used or not. Possible values are "yes" and "no".
  147.  * @map_id | The ID of the map
  148.  * @latLng | The coordinates (Latitude & Longitude) of the post on the map. Laitude and Longitude separated by underscore, for example, (15.6540_50.54802)
  149.  *
  150.  *
  151.  *
  152.  */
  153.  
  154.  
  155. //add_action( 'admin_footer', 'cspml_change_image' ); // Write our JS below here
  156.  
  157. function cspml_change_image($default_content, $post_id, $view, $filter, $map_id, $latLng){
  158.  
  159.     if (!class_exists('CspmMainMap'))
  160.      return;
  161.    
  162.     $CspmMainMap = CspmMainMap::this();
  163.    
  164.     $fields_prefix = $CspmMainMap->metafield_prefix;
  165.  
  166.     global $post;
  167.  
  168.     $output = '';
  169.  
  170.     $marker_img_array = apply_filters('cspml_post_thumb', wp_get_attachment_image_src( get_post_thumbnail_id($post_id), 'cspml-listings-thumbnail' ), $post_id);
  171.  
  172.         /*
  173.          * Item's Label's */
  174.  
  175.         if( have_rows('tag_tour') !='' ): ?>
  176.  
  177.             <?php while( have_rows('tag_tour') ): the_row();
  178.  
  179.                 $tag_type = get_sub_field('tag_type');
  180.                 $tag_discount_value = get_sub_field('tag_discount_value'); ?>                                                              
  181.  
  182.                 <?php if( get_sub_field('tag_type') == 'Top Attraction' ): ?>
  183.  
  184.                     <?php $output .= '<div class="tag tag-top-attraction">' ?>
  185.                            
  186.                         <?php $output .= '<span class="discounts"></span> '.$tag_type.'</span>' ?>
  187.  
  188.                     <?php $output .= '</div>'?>
  189.  
  190.                 <?php elseif( get_sub_field('tag_type') == 'Special Offer' ): ?>
  191.  
  192.                     <?php $output .= '<div class="tag tag-special-offer">' ?>
  193.                            
  194.                         <?php $output .= '<span class="discounts"></span> '.$tag_type.'</span>' ?>
  195.  
  196.                     <?php $output .= '</div>'?>
  197.  
  198.                 <?php elseif( get_sub_field('tag_type') == 'Likely to sell out' ): ?>
  199.  
  200.                     <?php $output .= '<div class="tag tag-likely-to-sell-out">' ?>
  201.                            
  202.                         <?php $output .= '<span class="discounts"></span> '.$tag_type.'</span>' ?>
  203.  
  204.                     <?php $output .= '</div>'?>
  205.  
  206.                 <?php elseif( get_sub_field('tag_type') == 'New Experience' ): ?>
  207.  
  208.                     <?php $output .= '<div class="tag tag-new-experience">' ?>
  209.                            
  210.                         <?php $output .= '<span class="discounts"></span> '.$tag_type.'</span>' ?>
  211.  
  212.                     <?php $output .= '</div>'?>
  213.  
  214.                 <?php elseif( get_sub_field('tag_type') == 'Best Seller' ): ?>
  215.  
  216.                     <?php $output .= '<div class="tag tag-best-seller">' ?>
  217.                            
  218.                         <?php $output .= '<span class="discounts"></span> '.$tag_type.'</span>' ?>
  219.  
  220.                     <?php $output .= '</div>' ?>
  221.  
  222.                 <?php elseif( get_sub_field('tag_type') == 'Default' ): ?>
  223.  
  224.                     <?php $output .= '<div class="tag-discounts"></div>' ?>
  225.  
  226.                 <?php elseif( get_sub_field('tag_type') == 'Discount' ): ?>
  227.  
  228.                     <?php if($tag_discount_value !=''):
  229.  
  230.                         $off_simbol = esc_html( '% ', 'veditalia' );
  231.                         $off_text = esc_html( 'OFF ', 'veditalia' ); ?>
  232.  
  233.  
  234.                         <?php $output .= '<div class="tag tag-discont">' ?>
  235.                                
  236.                             <?php $output .= '<span class="discounts"></span> '.$tag_discount_value.'</span><span class="after-discounts-1">'.$off_simbol.'</span><span class="after-discounts-2">'.$off_text.'</span>' ?>
  237.  
  238.                         <?php $output .= '</div>' ?>
  239.  
  240.                     <?php endif;
  241.  
  242.                 endif;
  243.  
  244.             endwhile;
  245.  
  246.         endif;
  247.  
  248.  
  249.         /**
  250.          * Item's Gallery */
  251.        
  252.    
  253.     $images = get_field( 'gallery_tour' );
  254.  
  255.  
  256.         if( $images !='' ):
  257.  
  258.             $output .= '<div id="slider" class="flex-tour" itemscope >';
  259.  
  260.             $custom_js2 = "$(document).ready(function($) { $('.flex-tour').addClass('flexslider flexslider-tour'); });";
  261.  
  262.             $custom_js = "$(document).ready(function($) { $('.flexslider.flexslider-tour').flexslider({ animation: 'slide', controlNav: false, animationLoop: false, slideshow: false, }); });";
  263.  
  264.             wp_add_inline_script('custom', $custom_js2);
  265.  
  266.             wp_add_inline_script('custom', $custom_js);
  267.            
  268.  
  269.             $output .= '<ul class="slides">' ?>    
  270.  
  271.  
  272.             <?php foreach( $images as $image ):
  273.  
  274.                 $carousel = $image['sizes']['tour-home'];
  275.                 $alt = $image['alt'];
  276.  
  277.                 $output .= '<li><figure><img src="'.$carousel.'" alt="'.$alt.'" class="thumb img-responsive" /></figure></li>'; ?>
  278.                    
  279.             <?php endforeach; ?>
  280.  
  281.            
  282.             <?php $output .= '</ul></div>' ?>
  283.            
  284.  
  285.         <?php endif;
  286.  
  287.     wp_reset_postdata();
  288.  
  289.     return !empty($output) ? $output : $default_content;
  290.  
  291. }
  292.  
  293. add_filter('cspml_before_listing_thumb', 'cspml_change_image', 10, 6);
Advertisement
Add Comment
Please, Sign In to add comment