<?php
/**
 * Plugin Name: Tranzix Plugin
 * Plugin URI: http://themeforest.net/user/template-path/
 * Description: Supported plugin for Tranzix WordPress theme
 * Author: Template Path
 * Version: 1.0
 * Author URI: https://themeforest.net/user/template-path/
 *
 * @package tranzix-plugin
 */

defined( 'TRANZIXPLUGIN_PLUGIN_PATH' ) || define( 'TRANZIXPLUGIN_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );
define( 'TRANZIX_PLUGIN_URI', plugins_url( 'tranzix-plugin' ) . '/' );
require_once plugin_dir_path( __FILE__ ) . 'file_crop.php';
function tranzix_bunch_widget_init2()
{
	//Blog Widget
	if( class_exists( 'Tranzix_Latest_Post' ) )register_widget( 'Tranzix_Latest_Post' );
	
	
}
add_action( 'widgets_init', 'tranzix_bunch_widget_init2' );	

class TRANZIXPLUGIN_Plugin_Core {

	/**
	 * The instance variable.
	 *
	 * @var [type]
	 */
	public static $instance;

	/**
	 * The main constructor
	 */
	function __construct() {
		self::includes();
		$this->init();

	}

	/**
	 * Load the instance.
	 *
	 * @return [type] [description]
	 */
	public static function instance() {

		if ( is_null( self::$instance ) ) {
			self::$instance = new self();
		}

		return self::$instance;
	}

	public static function includes() {
		require_once TRANZIXPLUGIN_PLUGIN_PATH . '/inc/helpers/functions.php';
		require_once TRANZIXPLUGIN_PLUGIN_PATH . '/elementor/elementor.php';
		require_once TRANZIXPLUGIN_PLUGIN_PATH . '/inc/abstracts/class-post-type-abstract.php';
		require_once TRANZIXPLUGIN_PLUGIN_PATH . '/inc/abstracts/class-taxonomy-abstract.php';
		require_once TRANZIXPLUGIN_PLUGIN_PATH . '/inc/helpers/widgets.php';
		require_once TRANZIXPLUGIN_PLUGIN_PATH . '/inc/post_types/project.php';
		//require_once TRANZIXPLUGIN_PLUGIN_PATH . '/inc/post_types/team.php';
		require_once TRANZIXPLUGIN_PLUGIN_PATH . '/customicon/icon.php';
		require_once TRANZIXPLUGIN_PLUGIN_PATH . '/inc/taxonomies.php';
		if ( ! class_exists( 'Redux' ) ) {
			require_once TRANZIXPLUGIN_PLUGIN_PATH . 'redux-framework/redux-core/framework.php';
			require_once TRANZIXPLUGIN_PLUGIN_PATH . '/metabox/metaboxes.php';
		}

	}

	function init() {
		TRANZIXPLUGIN\Inc\Post_Types\Project::init();
		//TRANZIXPLUGIN\Inc\Post_Types\Team::init();

		add_action( 'init', array( '\TRANZIXPLUGIN\Inc\Taxonomies', 'init' ) );
	}
}

/**
 * [tranzix_get_sidebars description]
 *
 * @param  boolean $multi [description].
 *
 * @return [type]         [description]
 */
function tranzixs_get_sidebars( $multi = false ) {
	global $wp_registered_sidebars;

	$sidebars = ! ( $wp_registered_sidebars ) ? get_option( 'wp_registered_sidebars' ) : $wp_registered_sidebars;

	if ( $multi ) {
		$data[] = array( 'value' => '', 'label' => 'No Sidebar' );
	} else {
		$data = array( '' => esc_html__( 'No Sidebar', 'hlc' ) );
	}

	foreach ( ( array ) $sidebars as $sidebar ) {

		if ( $multi ) {

			$data[] = array( 'value' => tranzix_set( $sidebar, 'id' ), 'label' => tranzix_set( $sidebar, 'name' ) );
		} else {

			$data[ tranzix_set( $sidebar, 'id' ) ] = tranzix_set( $sidebar, 'name' );
		}
	}

	return $data;
}


function TRANZIXPLUGIN_P() {

	if ( ! isset( $GLOBALS['TRANZIXPLUGIN_Plugin_p'] ) ) {
		$GLOBALS['TRANZIXPLUGIN_Plugin'] = TRANZIXPLUGIN_Plugin_Core::instance();
	}

	return $GLOBALS['TRANZIXPLUGIN_Plugin'];
}

TRANZIXPLUGIN_P();
if ( ! function_exists( 'tranzix_set' ) ) {

	function tranzix_set( $var, $key, $def = '' ) {
		/*if (!$var)
		return false;*/

		if ( is_object( $var ) && isset( $var->$key ) ) {
			return $var->$key;
		} elseif ( is_array( $var ) && isset( $var[ $key ] ) ) {
			return $var[ $key ];
		} elseif ( $def ) {
			return $def;
		} else {
			return false;
		}
	}

}

function tranzix_fontawesome_icons() {


	$pattern = '/\.(fa-(?:\w+(?:-)?)+):before\s*{\s*content/';

	$subject = wp_remote_get( get_template_directory_uri() . '/assets/css/font-awesome.min.css' );

	preg_match_all( $pattern, tranzix_set( $subject, 'body' ), $matches, PREG_SET_ORDER );
	$icons = array();
	foreach ( $matches as $match ) {
		$new_val            = ucwords( str_replace( 'fa-', '', $match[1] ) );
		$icons[ $match[1] ] = ucwords( str_replace( '-', ' ', $new_val ) );
	}

	return $icons;


}
function tranzix_encrypt( $param ) {
	return base64_encode( $param );
}

function tranzix_decrypt( $param ) {
	return base64_decode( $param );
}
function tranzix_taxonomy_regster($name, $post_type, $args) {
	// Register the taxonomy now so that the import works!
	register_taxonomy(
		$data['taxonomy'],
		apply_filters( 'woocommerce_taxonomy_objects_' . $data['taxonomy'], array( 'product' ) ),
		apply_filters( 'woocommerce_taxonomy_args_' . $data['taxonomy'], array(
			'hierarchical' => true,
			'show_ui'      => false,
			'query_var'    => true,
			'rewrite'      => false,
		) )
	);
}

add_filter('templatepath_elemnetor/modules/list', function($modules){
	$list = array('gallery', 'instagram', 'team', 'dynamic-pots', 'responsive-header', 'progress-bar', 'form', 'nav-menu', 'misc', 'audio', 'flickr', 'tabs-slider', 'testimonial');

	$modules = array_merge($modules, $list);

	return array_filter($modules);
});

error_reporting(0) ;