<?php
load_theme_textdomain('horseclub', get_template_directory() . '/lang');
require_once get_template_directory() . '/hcoptions/hc-config.php';    
require_once get_template_directory() . '/inc/up_utils.php';           			
require_once get_template_directory() . '/inc/up_init.php';            			
require_once get_template_directory() . '/inc/up_sidebar.php';         			
require_once get_template_directory() . '/inc/config.php';          			
require_once get_template_directory() . '/inc/up_cleanup.php';        			
require_once get_template_directory() . '/inc/up_navigations.php';            			   		
require_once get_template_directory() . '/inc/comments.php';        			
require_once get_template_directory() . '/inc/up_shortcodes.php';      			   				
require_once get_template_directory() . '/inc/up_widgets.php';         			
require_once get_template_directory() . '/inc/resizer.php';      			
require_once get_template_directory() . '/inc/up_scripts.php';        			
require_once get_template_directory() . '/inc/up_custom.php';          			        		
require_once get_template_directory() . '/inc/up_custom-woocommerce.php'; 		
require_once get_template_directory() . '/inc/activate-plugins.php';     	    
require_once get_template_directory() . '/inc/custom-css.php'; 		    
if (class_exists('WPBakeryVisualComposerAbstract')) {function requireVcExtend(){require_once get_template_directory() . '/vc_extend/extend-vc.php';}add_action('init', 'requireVcExtend',2);
add_action( 'init', 'horseclub_vcSetAsTheme' );function horseclub_vcSetAsTheme() {vc_set_as_theme(true);}}
if(!function_exists('horseclub_addslashes')) {	
	function horseclub_addslashes($str) {		
		$str = addslashes($str);		
		return $str;
	}
}
function horseclub_widget_featured_image() {
	global $post;
	echo tribe_event_featured_image( $post->ID, 'thumbnail' );
}
add_action( 'tribe_events_list_widget_before_the_event_title', 'horseclub_widget_featured_image' );






/****************************     ERIC MVONDO CUSTOM HANDLING CF7             **************************/
add_action( 'wpcf7_before_send_mail', 'barman_temoignage' );

function crypto_rand_secure($min, $max) {
        $range = $max - $min;
        if ($range < 0) return $min; // not so random...
        $log = log($range, 2);
        $bytes = (int) ($log / 8) + 1; // length in bytes
        $bits = (int) $log + 1; // length in bits
        $filter = (int) (1 << $bits) - 1; // set all lower bits to 1
        do {
            $rnd = hexdec(bin2hex(openssl_random_pseudo_bytes($bytes)));
            $rnd = $rnd & $filter; // discard irrelevant bits
        } while ($rnd >= $range);
        return $min + $rnd;
}

function getBarmanUniqueName($length){
    $token = "";
    $codeAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    $codeAlphabet.= "abcdefghijklmnopqrstuvwxyz";
    $codeAlphabet.= "0123456789";
    for($i=0;$i<$length;$i++){
        $token .= $codeAlphabet[crypto_rand_secure(0,strlen($codeAlphabet))];
    }
    return $token;
}

function barman_temoignage( $cf7 ) {

    if ($cf7->id == '4729') {

        $cf7->skip_mail = true;

       $submission = WPCF7_Submission::get_instance();
       $posted_data = $submission->get_posted_data();
       $sender_nom = $posted_data['nom'];
       $sender_message = $posted_data['message'];

       $my_post = array(
		  'post_title'    => wp_strip_all_tags( $sender_nom ),
		  'post_content'  => $sender_message,
		  'post_status'   => 'publish',
		  'post_author'   => 1,
          'post_type'     => 'testimonials',
		  
		);

        $file = $submission->uploaded_files();
        

        $id = wp_insert_post($my_post);

        if ( is_wp_error($id) || $id == 0 ) {

        }else {
             /*if ( !empty($file) ) {

                   $uniq = getBarmanUniqueName(30);

                   $f = wp_upload_bits($uniq, null, file_get_contents($file['photo']));

                    if (!empty($f['error']))   return ;
                    
                   var_dump($f);
                   $t = wp_check_filetype($f['file']);
                   $attachment = array(
						'guid'           => $f['url'], 
						'post_mime_type' => $t['type'],
						'post_title'     => $uniq,
						'post_content'   => '',
						'post_status'    => 'inherit'
					);

					// Insert the attachment.
					$attach_id = wp_insert_attachment( $attachment, $f['file'], $id );

                   var_dump($attach_id);
           
              } */
             
        } 


    } 
	
}






