<?php
/*
Plugin Name: Site Plugin for danix.xyz
Description: Site specific code changes for danix.xyz
Plugin URI: https://danix.xyz
Version: 0.7.3
Author: Danilo 'danix' Macri
Author URI: https://danix.xyz
*/

/**
 * Disable admin bar sitewide
 */
show_admin_bar( __return_false() );

/**
 * Allow Shortcodes inside the html widget
 */
//add_filter( 'widget_text', 'do_shortcode' );

/**
 * make sure the links menu in the admin is visible
 */
add_filter( 'pre_option_link_manager_enabled', '__return_true' );

/**
 * The gravatar shortcode
 *
 * @param email $email email address used to retrieve the gravatar image
 * @return string HTML the image tag which will display the gravatar image.
 *
 */
function danix_gravatar( $atts ) {
	extract(
		shortcode_atts(
			array(
				'email'        => '',
				'size'         => '200',
				'default'      => '',
				'alt'          => '',
			),
			$atts
		)
	);

	if ( empty( $email ) ) {
		return '';
	}

	$output = get_avatar( $email, $size, $default, $alt );

	return $output;
}
add_shortcode( 'gravatar', 'danix_gravatar' );

/**
 * Added baguette.js to display a lightbox for images and galleries
 */
function baguette_register_assets() {
	wp_register_script( 'baguettebox', plugin_dir_url( __FILE__ ) . '/baguette/baguetteBox.min.js', array(), '1.11.1', true );
	wp_register_script( 'baguetteload', plugin_dir_url( __FILE__ ) . '/baguette/baguetteLoad.js', array(), '1.11.1', true );
	wp_register_style( 'baguettebox-css', plugin_dir_url( __FILE__ ) . '/baguette/baguetteBox.min.css', array(), '1.11.1' );
}
add_action( 'wp_enqueue_scripts', 'baguette_register_assets' );

function baguette_enqueue_assets() {
	if ( has_block( 'gallery' ) || has_block( 'image' ) ) {
		wp_enqueue_script( 'baguettebox' );
		wp_enqueue_script( 'baguetteload' );
		wp_enqueue_style( 'baguettebox-css' );
	}
}
add_action( 'wp_enqueue_scripts', 'baguette_enqueue_assets' );

/*
 * Do not translate smileys into emoticons.
 */
add_filter( 'option_use_smilies', '__return_false' );

/*
 # Add matomo tracking js code to head
 */
if ( ! function_exists( 'matomo_tracking' ) ) :
	function matomo_tracking() {
		?>
<!-- Matomo -->
<script type="text/javascript">
	var _paq = window._paq = window._paq || [];
	/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
	_paq.push(['trackPageView']);
	_paq.push(['enableLinkTracking']);
	(function() {
		var u="//lucky.danix.xyz/";
		_paq.push(['setTrackerUrl', u+'matomo.php']);
		_paq.push(['setSiteId', '1']);
		var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
		g.type='text/javascript'; g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
	})();
</script>
<!-- End Matomo Code -->
	<?php
	}
endif;
add_action( 'wp_head', 'matomo_tracking' );
