Advertisement
Guest User

helpers.php

a guest
Dec 6th, 2016
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 25.36 KB | None | 0 0
  1. <?php
  2. // Verify if woocommerce is active
  3. if ( ! function_exists( 'villenoir_is_wc_activated' ) ) {
  4.     function villenoir_is_wc_activated() {
  5.         if ( class_exists( 'woocommerce' ) ) {
  6.             return true;
  7.         } else {
  8.             return false;
  9.         }
  10.     }
  11. }
  12.  
  13. // Verify if WPML is active
  14. if ( ! function_exists( 'villenoir_is_wpml_activated' ) ) {
  15.     function villenoir_is_wpml_activated() {
  16.         if ( class_exists( 'SitePressLanguageSwitcher' ) ) {
  17.             return true;
  18.         } else {
  19.             return false;
  20.         }
  21.     }
  22. }
  23.  
  24. if ( villenoir_is_wpml_activated() ) {
  25.   //Disable WPML styles
  26.   define('ICL_DONT_LOAD_NAVIGATION_CSS', true);
  27.   define('ICL_DONT_LOAD_LANGUAGE_SELECTOR_CSS', true);
  28.   define('ICL_DONT_LOAD_LANGUAGES_JS', true);
  29. }
  30.  
  31. // Set VC as part of the theme
  32. if( function_exists('vc_set_as_theme') ) {
  33.  
  34.   add_action( 'vc_before_init', 'villenoir_vcSetAsTheme' );
  35.   function villenoir_vcSetAsTheme() {
  36.       vc_set_as_theme();
  37.   }
  38.  
  39.     $list = array(
  40.         'page',
  41.         'product',
  42.     );
  43.     vc_set_default_editor_post_types( $list );
  44. }
  45.  
  46. // Hide activation and update specific parts of Slider Revolution
  47. if( function_exists('set_revslider_as_theme') ) {
  48.     //Disable the activation nag
  49.     update_option('revslider-valid-notice', 'false');
  50.     update_option('revslider-valid', 'true');
  51.  
  52.     add_action( 'init', 'villenoir_rev_slider' );
  53.     function villenoir_rev_slider() {
  54.         set_revslider_as_theme();
  55.     }
  56. }
  57.  
  58. //Include the forms
  59. include (get_template_directory() . '/lib/forms/cf_ajax.php');
  60. include (get_template_directory() . '/lib/forms/cmf_ajax.php');
  61.  
  62. //Page container
  63. if (! function_exists('villenoir_page_container')) :
  64. function villenoir_page_container( $post_id = NULL ) {
  65.        
  66.         global $post, $product;
  67.  
  68.         if ( $post_id != FALSE || $post_id == 'special_page' ) {
  69.             $post = get_post( $post_id );
  70.         }
  71.  
  72.         //Get page layout options
  73.         if ( is_search() ) {
  74.             $page_layout = _get_field('gg_search_page_layout', 'option', 'with_left_sidebar');
  75.         } elseif ( villenoir_is_wc_activated() && ( is_shop() || is_product_category() ) ) {
  76.             $page_layout = _get_field('gg_page_layout_select', get_option( 'woocommerce_shop_page_id' ), 'with_left_sidebar');
  77.         } elseif ( is_archive() || is_category() || is_tag() ) {
  78.             $page_layout = _get_field('gg_cat_page_layout', 'option', 'with_left_sidebar');
  79.         } elseif ( is_singular('product') ) {
  80.             $page_layout = 'no_sidebar';
  81.             //$page_layout = _get_field('gg_page_layout_select', $product->ID, 'no_sidebar');
  82.         } else {
  83.             $page_layout = _get_field('gg_page_layout_select', $post->ID, 'with_left_sidebar');
  84.         }
  85.  
  86.  
  87.   switch ($page_layout) {
  88.       case "with_right_sidebar":
  89.           $page_content_class = 'col-xs-12 col-md-9 pull-left';
  90.           break;
  91.       case "with_left_sidebar":
  92.           $page_content_class = 'col-xs-12 col-md-9 pull-right';
  93.           break;
  94.       case "no_sidebar":
  95.           $page_content_class = 'col-xs-12 col-md-12';
  96.           break;
  97.       case NULL:
  98.           $page_content_class = 'col-xs-12 col-md-9 pull-left';
  99.           break;        
  100.   }
  101.  
  102.   echo esc_attr($page_content_class);
  103. }
  104. endif;
  105.  
  106. //Page sidebar
  107. if (! function_exists('villenoir_page_sidebar')) :
  108. function villenoir_page_sidebar( $post_id = NULL ) {
  109.    
  110.         global $post, $product;
  111.  
  112.         if ( $post_id != FALSE || $post_id == 'special_page' ) {
  113.             $post = get_post( $post_id );
  114.         }
  115.        
  116.         //Get page layout options
  117.         if ( is_search() ) {
  118.             $page_layout = _get_field('gg_search_page_layout', 'option','with_left_sidebar');
  119.         } elseif ( villenoir_is_wc_activated() && ( is_shop() || is_product_category() ) ) {
  120.             $page_layout = _get_field('gg_page_layout_select', get_option( 'woocommerce_shop_page_id' ), 'with_left_sidebar');
  121.         } elseif ( is_archive() || is_category() || is_tag() ) {
  122.             $page_layout = _get_field('gg_cat_page_layout', 'option','with_left_sidebar');
  123.         } elseif ( is_singular('product') ) {
  124.             $page_layout = 'no_sidebar';
  125.             //$page_layout = _get_field('gg_page_layout_select', $product->ID, 'no_sidebar');
  126.         } else {
  127.             $page_layout = _get_field('gg_page_layout_select', $post->ID, 'with_left_sidebar');
  128.         }
  129.  
  130.   switch ($page_layout) {
  131.       case "with_right_sidebar":
  132.           $page_sidebar_class = 'col-xs-12 col-md-3 pull-right';
  133.           break;
  134.       case "with_left_sidebar":
  135.            $page_sidebar_class = 'col-xs-12 col-md-3 pull-left';
  136.           break;
  137.       case "no_sidebar":
  138.           $page_sidebar_class = '';
  139.           break;
  140.       case NULL:
  141.           $page_sidebar_class = 'col-xs-12 col-md-3 pull-right';
  142.           break;        
  143.   }
  144.  
  145.   if ($page_layout !== 'no_sidebar') {
  146.   ?>
  147.   <div class="<?php echo esc_attr($page_sidebar_class); ?>">
  148.       <aside class="sidebar-nav">
  149.           <?php get_sidebar(); ?>
  150.       </aside>
  151.       <!--/aside .sidebar-nav -->
  152.   </div><!-- /.col-3 col-sm-3 col-lg-3 -->
  153.   <?php } ?>
  154. <?php }
  155. endif;
  156.  
  157.  
  158.  
  159. //Get the global page id
  160. if (! function_exists('villenoir_global_page_id')) :
  161. function villenoir_global_page_id() {
  162.  
  163.   global $wp_query;
  164.  
  165.   if ( villenoir_is_wc_activated() && is_shop() ) {
  166.     $current_page_id = get_option( 'woocommerce_shop_page_id' );
  167.   // If there is a post
  168.   } elseif ( is_single() || ( is_home() && !is_front_page() ) || ( is_page() && !is_front_page() ) ) {
  169.     $current_page_id = $wp_query->post->ID;
  170.  
  171.   } else {
  172.     $current_page_id = '';
  173.   }
  174.  
  175.   if(is_home()){
  176.       if('page' == get_option('show_on_front')){
  177.           if(is_front_page()){
  178.               $current_page_id = get_option('page_on_front');
  179.           }else{
  180.               $current_page_id = get_option('page_for_posts');
  181.           }
  182.       }
  183.   }
  184.  
  185.   return $current_page_id;
  186.  
  187. }
  188. endif;
  189.  
  190. if (! function_exists('villenoir_wp_title')) :
  191. function villenoir_wp_title( $display = true ) {
  192.   global $page, $paged;
  193.  
  194.   $search = get_query_var('s');
  195.   $title = '';
  196.  
  197.   // If there is a post
  198.   if ( is_single() || ( is_home() && !is_front_page() ) || ( is_page() && !is_front_page() ) ) {
  199.     $title = single_post_title( '', false );
  200.   }
  201.  
  202.   // If there's a post type archive
  203.   if ( is_post_type_archive() ) {
  204.     $post_type = get_query_var( 'post_type' );
  205.     if ( is_array( $post_type ) )
  206.       $post_type = reset( $post_type );
  207.     $post_type_object = get_post_type_object( $post_type );
  208.     if ( ! $post_type_object->has_archive )
  209.       $title = post_type_archive_title( '', false );
  210.   }
  211.  
  212.   // If there's a category or tag
  213.   if ( is_category() || is_tag() ) {
  214.     $title = single_term_title( '', false );
  215.   }
  216.  
  217.   // If there's a taxonomy
  218.   if ( is_tax() ) {
  219.     $term = get_queried_object();
  220.     if ( $term ) {
  221.       $tax = get_taxonomy( $term->taxonomy );
  222.       $title = single_term_title( false );
  223.     }
  224.   }
  225.  
  226.   // If there's an author
  227.   if ( is_author() && ! is_post_type_archive() ) {
  228.     $author = get_queried_object();
  229.     if ( $author )
  230.       $title = $author->display_name;
  231.   }
  232.  
  233.   // Post type archives with has_archive should override terms.
  234.   if ( is_post_type_archive() && $post_type_object->has_archive )
  235.     $title = post_type_archive_title( '', false );
  236.  
  237.   if ( is_year() || is_month() || is_day() ) {
  238.     $title = get_the_archive_title();
  239.   }
  240.  
  241.   // If it's a search
  242.   if ( is_search() ) {
  243.     /* translators: 1 search phrase */
  244.     $title = sprintf(esc_html__('Search Results For: %1$s','villenoir'), strip_tags($search));
  245.   }
  246.  
  247.   if ( villenoir_is_wc_activated() && (is_shop()) ) {
  248.     $title = get_the_title(woocommerce_get_page_id( 'shop' ));
  249.   }
  250.  
  251.   if ( villenoir_is_wc_activated() && is_page() && is_wc_endpoint_url() ) {
  252.     $endpoint = WC()->query->get_current_endpoint();
  253.     if ( $endpoint_title = WC()->query->get_endpoint_title( $endpoint ) ) {
  254.         $title = $endpoint_title;
  255.     }
  256.   }
  257.  
  258.   /**
  259.    * Filter the text of the page title.
  260.    *
  261.    * @since 2.0.0
  262.    *
  263.    * @param string $title       Page title.
  264.    */
  265.   $title = apply_filters( 'villenoir_wp_title', $title );
  266.  
  267.   // Send it out
  268.   if ( $display )
  269.     echo $title;
  270.   else
  271.     return $title;
  272.  
  273. }
  274.  
  275. endif;
  276.  
  277. function villenoir_add_wpb_to_body_if_shortcode($classes) {
  278.     global $post;
  279.     if (isset($post->post_content) && false !== stripos($post->post_content, '[vc_row')) {
  280.         array_push($classes, 'wpb-is-on');
  281.     } else {
  282.         array_push($classes, 'wpb-is-off');
  283.     }
  284.     return $classes;
  285. }
  286. add_filter('body_class', 'villenoir_add_wpb_to_body_if_shortcode', 100, 1);
  287.  
  288.  
  289.  
  290. /**
  291.  * Display an optional post thumbnail.
  292.  */
  293. if ( ! function_exists( 'villenoir_post_thumbnail' ) ) :
  294. function villenoir_post_thumbnail() {
  295.   if ( post_password_required() || is_attachment() || ! has_post_thumbnail() ) {
  296.     return;
  297.   }
  298.  
  299.   if ( is_single() ) :
  300.   ?>
  301.  
  302.   <div class="post-thumbnail">
  303.     <?php the_post_thumbnail(); ?>
  304.   </div><!-- .post-thumbnail -->
  305.  
  306.   <?php else : ?>
  307.  
  308.   <a class="post-thumbnail" href="<?php the_permalink(); ?>" aria-hidden="true">
  309.     <?php
  310.       the_post_thumbnail( 'post-thumbnail', array( 'alt' => get_the_title() ) );
  311.     ?>
  312.   </a>
  313.  
  314.   <?php endif; // End is_singular()
  315. }
  316. endif;
  317.  
  318. /**
  319.  * Add class to next post link
  320.  */
  321. function villenoir_next_posts_link_css($content) {
  322.     return 'class="btn btn-primary"';
  323. }
  324. add_filter('next_posts_link_attributes', 'villenoir_next_posts_link_css' );
  325.  
  326.  
  327. /**
  328.  * Infinite Scroll
  329.  */
  330. function villenoir_infinite_scroll_js() { ?>
  331.   <script>
  332.  
  333.   if(jQuery('.el-grid[data-pagination="ajax_load"]').length > 0) {
  334.  
  335.     var container = jQuery('ul.el-grid');
  336.     var infinite_scroll = {
  337.       loading: {
  338.         selector: '.load-more-anim',
  339.         img: "<?php echo get_template_directory_uri(); ?>/images/animated-ring.gif",
  340.         msgText: "<?php esc_html_e( 'Loading the next set of posts...', 'villenoir' ); ?>",
  341.         finishedMsg: "<?php esc_html_e( 'All posts loaded.', 'villenoir' ); ?>"
  342.       },
  343.       bufferPx     : 140,
  344.       behavior: "twitter",
  345.       nextSelector:".pagination-span a",
  346.       navSelector:".pagination-load-more",
  347.       itemSelector:"ul.el-grid li",
  348.       contentSelector:"ul.el-grid",
  349.       animate: false,
  350.       debug: false,
  351.  
  352.     };
  353.  
  354.     jQuery( infinite_scroll.contentSelector ).infinitescroll(
  355.       infinite_scroll,
  356.      
  357.       // Infinite Scroll Callback
  358.       function( newElements ) {
  359.        
  360.         var newElems = jQuery( newElements ).hide();
  361.         newElems.imagesLoaded(function(){
  362.           newElems.fadeIn();
  363.  
  364.           if(jQuery('.el-grid[data-layout-mode="masonry"], .el-grid[data-layout-mode="fitRows"]').length > 0) {
  365.             container.isotope( 'appended', newElems );
  366.           }
  367.          
  368.         });
  369.        
  370.       }
  371.      
  372.  
  373.     );
  374.   }
  375.   </script>
  376.  
  377.   <?php
  378. }
  379. add_action( 'wp_footer', 'villenoir_infinite_scroll_js',100 );
  380.  
  381. /**
  382.  * Infinite Scroll
  383.  */
  384. function villenoir_vc_rtl_row() { ?>
  385.   <script>
  386.   if(jQuery('body.rtl').length > 0){
  387.     jQuery( '.vc_row[data-vc-full-width="true"]' ).each(function(){
  388.       //VC Row RTL
  389.       var jQuerythis = jQuery(this);
  390.       var vc_row = jQuerythis.offset().left;
  391.       jQuerythis.css('right', - vc_row)
  392.     });
  393.  
  394.   }
  395.   </script>
  396.  
  397.   <?php
  398. }
  399. add_action( 'wp_footer', 'villenoir_vc_rtl_row',100 );
  400.  
  401. /**
  402.  * Prints HTML with meta information for the categories, tags.
  403.  */
  404. if ( ! function_exists( 'villenoir_entry_meta' ) ) :
  405. function villenoir_entry_meta() {
  406.   if ( is_sticky() && is_home() && ! is_paged() ) {
  407.     printf( '<span class="sticky-post">%s</span>', esc_html__( 'Featured', 'villenoir' ) );
  408.   }
  409.  
  410.   $format = get_post_format();
  411.   if ( current_theme_supports( 'post-formats', $format ) ) {
  412.     printf( '<span class="entry-format">%1$s<a href="%2$s">%3$s</a></span>',
  413.       sprintf( '<span>%s: </span>', _x( 'Format', 'Used before post format.', 'villenoir' ) ),
  414.       esc_url( get_post_format_link( $format ) ),
  415.       get_post_format_string( $format )
  416.     );
  417.   }
  418.  
  419.   if ( 'post' == get_post_type() ) {
  420.     $tags_list = get_the_tag_list();
  421.     if ( $tags_list ) {
  422.       printf( '<span class="tags-links">%1$s</span>',
  423.         $tags_list
  424.       );
  425.     }
  426.   }
  427.  
  428.   if ( is_attachment() && wp_attachment_is_image() ) {
  429.     // Retrieve attachment metadata.
  430.     $metadata = wp_get_attachment_metadata();
  431.  
  432.     printf( '<span class="full-size-link"><span>%1$s: </span><a href="%2$s">%3$s &times; %4$s</a></span>',
  433.       _x( 'Full size', 'Used before full size attachment link.', 'villenoir' ),
  434.       esc_url( wp_get_attachment_url() ),
  435.       $metadata['width'],
  436.       $metadata['height']
  437.     );
  438.   }
  439.  
  440.   if ( ! is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
  441.     echo '<span class="comments-link">';
  442.     comments_popup_link( esc_html__( 'Leave a comment', 'villenoir' ), esc_html__( '1 Comment', 'villenoir' ), esc_html__( '% Comments', 'villenoir' ) );
  443.     echo '</span>';
  444.   }
  445. }
  446. endif;
  447.  
  448.  
  449. /**
  450.  * Excerpt read more
  451.  *
  452.  */
  453.  
  454. function villenoir_excerpt_more( $more ) {
  455.     return '<br class="read-more-spacer"> <a class="more-link" href="'. esc_url(get_permalink( get_the_ID() )) . '">' . esc_html__('Read More', 'villenoir') . '</a>';
  456. }
  457. add_filter( 'excerpt_more', 'villenoir_excerpt_more' );
  458.  
  459. /**
  460.  * Tags widget style
  461.  *
  462.  */
  463. function villenoir_tag_cloud_widget($args) {
  464.     $args['number'] = 0; //adding a 0 will display all tags
  465.     $args['largest'] = 11; //largest tag
  466.     $args['smallest'] = 11; //smallest tag
  467.     $args['unit'] = 'px'; //tag font unit
  468.     $args['format'] = 'list'; //ul with a class of wp-tag-cloud
  469.     return $args;
  470. }
  471. add_filter( 'widget_tag_cloud_args', 'villenoir_tag_cloud_widget' );
  472.  
  473. /**
  474.  * Determine whether blog/site has more than one category.
  475.  *
  476.  */
  477. function villenoir_categorized_blog() {
  478.   if ( false === ( $all_the_cool_cats = get_transient( 'gg_categories' ) ) ) {
  479.     // Create an array of all the categories that are attached to posts.
  480.     $all_the_cool_cats = get_categories( array(
  481.       'fields'     => 'ids',
  482.       'hide_empty' => 1,
  483.  
  484.       // We only need to know if there is more than one category.
  485.       'number'     => 2,
  486.     ) );
  487.  
  488.     // Count the number of categories that are attached to the posts.
  489.     $all_the_cool_cats = count( $all_the_cool_cats );
  490.  
  491.     set_transient( 'gg_categories', $all_the_cool_cats );
  492.   }
  493.  
  494.   if ( $all_the_cool_cats > 1 ) {
  495.     // This blog has more than 1 category so villenoir_categorized_blog should return true.
  496.     return true;
  497.   } else {
  498.     // This blog has only 1 category so villenoir_categorized_blog should return false.
  499.     return false;
  500.   }
  501. }
  502.  
  503. /**
  504.  * Flush out the transients used in {@see villenoir_categorized_blog()}.
  505.  *
  506.  */
  507. function villenoir_category_transient_flusher() {
  508.   // Like, beat it. Dig?
  509.   delete_transient( 'gg_categories' );
  510. }
  511. add_action( 'edit_category', 'villenoir_category_transient_flusher' );
  512. add_action( 'save_post',     'villenoir_category_transient_flusher' );
  513.  
  514.  
  515.  
  516. function villenoir_check_email($email) {
  517.     if (is_email($email)) {
  518.         return 1;
  519.     } else {
  520.         return esc_html__( 'The entered email address isn\'t valid.', 'villenoir' );
  521.     }
  522. }
  523.  
  524. if (! function_exists('villenoir_hex_r')) :
  525. function villenoir_hex_r($hex) {
  526.    $hex = str_replace("#", "", $hex);
  527.  
  528.    if(strlen($hex) == 3) {
  529.       $r = hexdec(substr($hex,0,1).substr($hex,0,1));
  530.       $g = hexdec(substr($hex,1,1).substr($hex,1,1));
  531.       $b = hexdec(substr($hex,2,1).substr($hex,2,1));
  532.    } else {
  533.       $r = hexdec(substr($hex,0,2));
  534.       $g = hexdec(substr($hex,2,2));
  535.       $b = hexdec(substr($hex,4,2));
  536.    }
  537.    $rgb = array($r, $g, $b);
  538.    return implode(",", $rgb); // returns the rgb values separated by commas
  539.    //return $rgb; // returns an array with the rgb values
  540. }
  541. endif;
  542.  
  543. /**
  544.  * Color shift a hex value by a specific percentage factor
  545.  *
  546.  * @param string $supplied_hex Any valid hex value. Short forms e.g. #333 accepted.
  547.  * @param string $shift_method How to shift the value e.g( +,up,lighter,>)
  548.  * @param integer $percentage Percentage in range of [0-100] to shift provided hex value by
  549.  * @return string shifted hex value
  550.  * @version 1.0 2008-03-28
  551.  */
  552. if (!function_exists('villenoir_hex_shift')) :
  553.     function villenoir_hex_shift( $supplied_hex, $shift_method, $percentage = 50 ) {
  554.         $shifted_hex_value = null;
  555.         $valid_shift_option = FALSE;
  556.         $current_set = 1;
  557.         $RGB_values = array( );
  558.         $valid_shift_up_args = array( 'up', '+', 'lighter', '>' );
  559.         $valid_shift_down_args = array( 'down', '-', 'darker', '<' );
  560.         $shift_method = strtolower( trim( $shift_method ) );
  561.  
  562.         // Check Factor
  563.         if ( !is_numeric( $percentage ) || ($percentage = ( int ) $percentage) < 0 || $percentage > 100 ) {
  564.             trigger_error( "Invalid factor", E_USER_ERROR );
  565.         }
  566.  
  567.         // Check shift method
  568.         foreach ( array( $valid_shift_down_args, $valid_shift_up_args ) as $options ) {
  569.             foreach ( $options as $method ) {
  570.                 if ( $method == $shift_method ) {
  571.                     $valid_shift_option = !$valid_shift_option;
  572.                     $shift_method = ( $current_set === 1 ) ? '+' : '-';
  573.                     break 2;
  574.                 }
  575.             }
  576.             ++$current_set;
  577.         }
  578.  
  579.         if ( !$valid_shift_option ) {
  580.             trigger_error( "Invalid shift method", E_USER_ERROR );
  581.         }
  582.  
  583.         // Check Hex string
  584.         switch ( strlen( $supplied_hex = ( str_replace( '#', '', trim( $supplied_hex ) ) ) ) ) {
  585.             case 3:
  586.                 if ( preg_match( '/^([0-9a-f])([0-9a-f])([0-9a-f])/i', $supplied_hex ) ) {
  587.                     $supplied_hex = preg_replace( '/^([0-9a-f])([0-9a-f])([0-9a-f])/i', '\\1\\1\\2\\2\\3\\3', $supplied_hex );
  588.                 } else {
  589.                     trigger_error( "Invalid hex color value", E_USER_ERROR );
  590.                 }
  591.                 break;
  592.             case 6:
  593.                 if ( !preg_match( '/^[0-9a-f]{2}[0-9a-f]{2}[0-9a-f]{2}$/i', $supplied_hex ) ) {
  594.                     trigger_error( "Invalid hex color value", E_USER_ERROR );
  595.                 }
  596.                 break;
  597.             default:
  598.                 trigger_error( "Invalid hex color length", E_USER_ERROR );
  599.         }
  600.  
  601.         // Start shifting
  602.         $RGB_values['R'] = hexdec( $supplied_hex{0} . $supplied_hex{1} );
  603.         $RGB_values['G'] = hexdec( $supplied_hex{2} . $supplied_hex{3} );
  604.         $RGB_values['B'] = hexdec( $supplied_hex{4} . $supplied_hex{5} );
  605.  
  606.         foreach ( $RGB_values as $c => $v ) {
  607.             switch ( $shift_method ) {
  608.                 case '-':
  609.                     $amount = round( ((255 - $v) / 100) * $percentage ) + $v;
  610.                     break;
  611.                 case '+':
  612.                     $amount = $v - round( ($v / 100) * $percentage );
  613.                     break;
  614.                 default:
  615.                     trigger_error( "Oops. Unexpected shift method", E_USER_ERROR );
  616.             }
  617.  
  618.             $shifted_hex_value .= $current_value = (
  619.                 strlen( $decimal_to_hex = dechex( $amount ) ) < 2
  620.                 ) ? '0' . $decimal_to_hex : $decimal_to_hex;
  621.         }
  622.  
  623.         return '#' . $shifted_hex_value;
  624.     }
  625. endif;
  626.  
  627. /**
  628.  * Display template for pagination.
  629.  *
  630.  */
  631. if (!function_exists('villenoir_pagination')) :
  632. function villenoir_pagination($query=null) {
  633.    
  634.     $prev_arrow = is_rtl() ? '<i class="fa fa-chevron-right"></i>' : '<i class="fa fa-chevron-left"></i>';
  635.     $next_arrow = is_rtl() ? '<i class="fa fa-chevron-left"></i>' : '<i class="fa fa-chevron-right"></i>';
  636.    
  637.     global $wp_query;
  638.     $query = $query ? $query : $wp_query;
  639.     $total = $query->max_num_pages;
  640.     $big = 999999999; // need an unlikely integer
  641.  
  642.     if( !$current_page = get_query_var('paged') )
  643.       $current_page = 1;
  644.     if( get_option('permalink_structure') ) {
  645.       $format = 'page/%#%/';
  646.     } else {
  647.       $format = '&paged=%#%';
  648.     }
  649.  
  650.     $paginate_links = paginate_links(array(
  651.       'base'      => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
  652.       'format'    => $format,
  653.       'current'   => max( 1, get_query_var('paged') ),
  654.       'total'     => $total,
  655.       'mid_size'    => 3,
  656.       'type'      => 'list',
  657.       'prev_text'   => $prev_arrow,
  658.       'next_text'   => $next_arrow,
  659.      ) );
  660.  
  661.     $paginate_links = str_replace( "<ul class='page-numbers'>", "<ul class='pagination'>", $paginate_links );
  662.     $paginate_links = str_replace( '<li><span class="page-numbers dots">', "<li><a href='#'>", $paginate_links );
  663.     $paginate_links = str_replace( "<li><span class='page-numbers current'>", "<li class='current'><a href='#'>", $paginate_links );
  664.     $paginate_links = str_replace( '</span>', '</a>', $paginate_links );
  665.     $paginate_links = str_replace( "<li><a href='#'>&hellip;</a></li>", "<li><span class='dots'>&hellip;</span></li>", $paginate_links );
  666.     $paginate_links = preg_replace( '/\s*page-numbers/', '', $paginate_links );
  667.     // Display the pagination if more than one page is found
  668.     if ( $paginate_links ) {
  669.       echo '<div class="pagination">';
  670.       echo wp_kses_post($paginate_links);
  671.       echo '</div><!--// end .pagination -->';
  672.     }
  673.  
  674. }
  675. endif;
  676.  
  677. /**
  678.  * Display template for comments and pingbacks.
  679.  *
  680.  */
  681. if (!function_exists('villenoir_comment')) :
  682.     function villenoir_comment($comment, $args, $depth)
  683.     {
  684.         $GLOBALS['comment'] = $comment;
  685.         switch ($comment->comment_type) :
  686.             case 'pingback' :
  687.             case 'trackback' : ?>
  688.  
  689.                 <li <?php comment_class('media, comment'); ?> id="comment-<?php comment_ID(); ?>">
  690.                     <div class="media-body">
  691.                         <p>
  692.                             <?php esc_html_e('Pingback:', 'villenoir'); ?> <?php comment_author_link(); ?>
  693.                         </p>
  694.                     </div><!--/.media-body -->
  695.                 <?php
  696.                 break;
  697.             default :
  698.                 // Proceed with normal comments.
  699.                 global $post; ?>
  700.  
  701.                 <li <?php comment_class('media'); ?> id="li-comment-<?php comment_ID(); ?>">
  702.                         <a href="<?php echo esc_url($comment->comment_author_url); ?>" class="pull-left avatar-holder">
  703.                             <?php echo get_avatar($comment, 70); ?>
  704.                         </a>
  705.                         <div class="media-body">
  706.                             <h4 class="media-heading comment-author vcard">
  707.                                 <?php
  708.                                 printf('<cite class="fn">%1$s %2$s</cite>',
  709.                                     get_comment_author_link(),
  710.                                     // If current post author is also comment author, make it known visually.
  711.                                     ($comment->user_id === $post->post_author) ? '<span class="label"> ' . esc_html__(
  712.                                         'Post author',
  713.                                         'villenoir'
  714.                                     ) . '</span> ' : ''); ?>
  715.                             </h4>
  716.                             <p class="meta">
  717.                                 <?php printf('<a href="%1$s"><time datetime="%2$s">%3$s</time></a>',
  718.                                         esc_url(get_comment_link($comment->comment_ID)),
  719.                                         get_comment_time('c'),
  720.                                         sprintf(
  721.                                             esc_html__('%1$s at %2$s', 'villenoir'),
  722.                                             get_comment_date(),
  723.                                             get_comment_time()
  724.                                         )
  725.                                     ); ?>
  726.                             </p>
  727.                             <p class="reply">
  728.                                 <?php comment_reply_link( array_merge($args, array(
  729.                                             'reply_text' => '<i class="arrow_back"></i> '. esc_html__('Reply', 'villenoir'),
  730.                                             'depth'      => $depth,
  731.                                             'max_depth'  => $args['max_depth']
  732.                                         )
  733.                                     )); ?>
  734.                             </p>
  735.  
  736.                             <?php if ('0' == $comment->comment_approved) : ?>
  737.                                 <p class="comment-awaiting-moderation"><?php esc_html_e(
  738.                                     'Your comment is awaiting moderation.',
  739.                                     'villenoir'
  740.                                 ); ?></p>
  741.                             <?php endif; ?>
  742.  
  743.                             <?php comment_text(); ?>
  744.                                                    
  745.                         </div>
  746.                         <!--/.media-body -->
  747.                 <?php
  748.                 break;
  749.         endswitch;
  750.     }
  751. endif;
  752.  
  753. /**
  754.  * Function for aq_resize
  755.  */
  756. if (!function_exists('villenoir_aq_resize')) :
  757. function villenoir_aq_resize( $attachment_id, $width = null, $height = null, $crop = true, $single = true ) {
  758.  
  759.     if ( is_null( $attachment_id ) )
  760.         return null;
  761.  
  762.     $image = wp_get_attachment_image_src( $attachment_id, 'full' );
  763.  
  764.     $return = aq_resize( $image[0], $width, $height, $crop, $single );
  765.  
  766.     if ( $return ) {
  767.         return $return;
  768.     }
  769.     else {
  770.         return $image[0];
  771.     }
  772. }
  773. endif;
  774.  
  775. /**
  776.  * Check if element comes from VC
  777.  */
  778. if (!function_exists('villenoir_is_in_vc')) :
  779. function villenoir_is_in_vc() {
  780.     $classes = get_body_class();
  781.     if (in_array('blog',$classes) || in_array('single',$classes) || in_array('search',$classes) || in_array('archive',$classes) || in_array('category',$classes)) {
  782.         return false;
  783.     } else {
  784.         return true;
  785.     }
  786. }
  787. endif;
  788.  
  789. /**
  790.  * strpos with needles as an array function
  791.  **/
  792. if ( ! function_exists('villenoir_strpos_array') ) :
  793.   function villenoir_strpos_array($haystack, $needles) {
  794.       if ( is_array($needles) ) {
  795.           foreach ($needles as $str) {
  796.               if ( is_array($str) ) {
  797.                   $pos = villenoir_strpos_array($haystack, $str);
  798.               } else {
  799.                   $pos = strpos($haystack, $str);
  800.               }
  801.               if ($pos !== FALSE) {
  802.                   return $pos;
  803.               }
  804.           }
  805.       } else {
  806.           return strpos($haystack, $needles);
  807.       }
  808.   }
  809. endif;
  810.  
  811.  
  812. /**
  813.  * Searchform function
  814.  **/
  815. if ( ! function_exists('villenoir_extras_menu') ) {
  816.     function villenoir_extras_menu() {
  817.     ob_start();
  818.     ?>
  819.     <a href="#fullscreen-searchform" title="<?php esc_html_e('Search products', 'villenoir'); ?>">
  820.         <span><i class="fa fa-search"></i></span>
  821.         <em class="visible-sm-inline"><?php esc_html_e('Search for products', 'villenoir'); ?></em>
  822.     </a>
  823.  
  824.     <?php
  825.     return ob_get_clean();
  826.     }
  827. }
  828.  
  829. /**
  830.  * WPML Multi currency function
  831.  **/
  832. if ( ! function_exists('villenoir_currency_switcher') ) {
  833.     function villenoir_currency_switcher() {
  834.     ob_start();
  835.     if ( class_exists('woocommerce_wpml') && villenoir_is_wc_activated() ) {
  836.     ?>
  837.  
  838.     <a href="" data-toggle="dropdown" aria-haspopup="true" class="dropdown-toggle">
  839.         <span><?php echo get_woocommerce_currency_symbol(); ?></span>
  840.         <span class="hidden-sm hidden-xs hidden"><?php echo get_woocommerce_currency(); ?></span>
  841.     </a>
  842.     <?php do_action('currency_switcher', array('format' => '%symbol%')); ?>
  843.  
  844.     <?php
  845.     }
  846.     return ob_get_clean();
  847.     }
  848. }
  849.  
  850. /**
  851.  * WPML - Language dropdown with flags
  852.  **/
  853.  
  854. if ( ! function_exists('villenoir_wpml_language_sel') ) {
  855.    
  856.     function villenoir_wpml_language_sel(){
  857.         if (villenoir_is_wpml_activated()) {
  858.             if (function_exists('icl_get_languages')) {
  859.               $languages = icl_get_languages('skip_missing=0&orderby=custom&order=asc');
  860.               if ($languages) {
  861.                   $out = '';
  862.                   $dropdown = '';
  863.                   foreach ($languages as $lang) {
  864.                       $lcode = explode('-',$lang['language_code']);
  865.            
  866.                       if ($lang['active']) {
  867.                           $button = '<a href="#" data-toggle="dropdown" aria-haspopup="true" class="dropdown-toggle"><span>'.$lang['language_code'].'</span><span class="hidden-sm hidden-xs hidden">'.$lang['translated_name'].'</span></a>';
  868.                       } else {
  869.                           $dropdown .= '<li><a href="'.esc_url($lang['url']).'" title="'.esc_html($lang['native_name']).'"><img src="'.esc_url($lang['country_flag_url']).'" alt="'.esc_html($lang['translated_name']).'" /></a></li>';
  870.                       }
  871.                   }
  872.                   $out .= $button;
  873.                   $out .= '<ul id="langswitch" class="dropdown-menu noclose">'.$dropdown.'</ul>';
  874.                   return $out;
  875.               }
  876.             }
  877.         }
  878.     }
  879.    
  880. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement