<?php
/**
 * Plugin Name: Ximsa Plugin
 * Plugin URI: http://themeforest.net/user/themexriver
 * Description: Supported plugin for Ximsa WordPress theme
 * Author: ThemeXriver
 * Version: 2.5
 * Author URI: http://themeforest.net/user/themexriver
 *
 * @package ximsa-plugin
 */
define( 'XIMSA_VERSION', '1.9' );
defined( 'XIMSAPLUGIN_PLUGIN_PATH' ) || define( 'XIMSAPLUGIN_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );
define( 'XIMSA_PLUGIN_URI', plugins_url( 'ximsa-plugin' ) . '/' );
define( 'XIMSA_PLUGIN_URL', plugin_dir_url(__FILE__));
require_once plugin_dir_path( __FILE__ ) . 'file_crop.php';
function ximsa_bunch_widget_init2()
{
	//footer Widget
	if( class_exists( 'Ximsa_About_Company' ) )register_widget( 'Ximsa_About_Company' );
	if( class_exists( 'Ximsa_Contact_Info' ) )register_widget( 'Ximsa_Contact_Info' );

	//footer Two Widget
	if( class_exists( 'Ximsa_About_Company_V2' ) )register_widget( 'Ximsa_About_Company_V2' );
	if( class_exists( 'Ximsa_Contact_Info_V2' ) )register_widget( 'Ximsa_Contact_Info_V2' );

	//footer Three Widget
	if( class_exists( 'Ximsa_About_Company_V3' ) )register_widget( 'Ximsa_About_Company_V3' );

	//Services Widget
	if( class_exists( 'Ximsa_Quick_Contact' ) )register_widget( 'Ximsa_Quick_Contact' );
	if( class_exists( 'Ximsa_Download_Brochure' ) )register_widget( 'Ximsa_Download_Brochure' );

	//Blog Widget
	if( class_exists( 'Ximsa_Popular_Post' ) )register_widget( 'Ximsa_Popular_Post' );

}
add_action( 'widgets_init', 'ximsa_bunch_widget_init2' );

class XIMSAPLUGIN_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() {

		if (!class_exists('EFramework_MegaMenu_Register')) {
            require_once XIMSAPLUGIN_PLUGIN_PATH . '/inc/mega-menu/class-megamenu.php';
            EFramework_MegaMenu_Register::get_instance();
        }

		require_once XIMSAPLUGIN_PLUGIN_PATH . '/inc/helpers/functions.php';
		require_once XIMSAPLUGIN_PLUGIN_PATH . '/inc/ele-fontawesome-pro.php';
		require_once XIMSAPLUGIN_PLUGIN_PATH . '/elementor/elementor.php';
		require_once XIMSAPLUGIN_PLUGIN_PATH . '/inc/abstracts/class-post-type-abstract.php';
		require_once XIMSAPLUGIN_PLUGIN_PATH . '/inc/abstracts/class-taxonomy-abstract.php';
		require_once XIMSAPLUGIN_PLUGIN_PATH . '/inc/helpers/widgets.php';
		require_once XIMSAPLUGIN_PLUGIN_PATH . '/inc/post_types/project.php';
		require_once XIMSAPLUGIN_PLUGIN_PATH . '/inc/post_types/team.php';
		require_once XIMSAPLUGIN_PLUGIN_PATH . '/inc/post_types/testimonials.php';
		require_once XIMSAPLUGIN_PLUGIN_PATH . '/inc/post_types/services.php';
		require_once XIMSAPLUGIN_PLUGIN_PATH . '/inc/post_types/faqs.php';
		require_once XIMSAPLUGIN_PLUGIN_PATH . '/inc/taxonomies.php';
		// require_once XIMSAPLUGIN_PLUGIN_PATH . '/demo-import/functions.php';
		// require_once XIMSAPLUGIN_PLUGIN_PATH . '/demo-import/inc/index.php';

		if ( ! class_exists( 'Redux' ) ) {
			require_once XIMSAPLUGIN_PLUGIN_PATH . 'redux-framework/redux-framework.php';
			require_once XIMSAPLUGIN_PLUGIN_PATH . '/metabox/metaboxes.php';
		}

	}

	function init() {
		XIMSAPLUGIN\Inc\Post_Types\Project::init();
		XIMSAPLUGIN\Inc\Post_Types\Team::init();
		XIMSAPLUGIN\Inc\Post_Types\Testimonials::init();
		XIMSAPLUGIN\Inc\Post_Types\Services::init();
		XIMSAPLUGIN\Inc\Post_Types\Faqs::init();
	}
}

/**
 * [ximsa_get_sidebars description]
 *
 * @param  boolean $multi [description].
 *
 * @return [type]         [description]
 */
function ximsas_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' => ximsa_set( $sidebar, 'id' ), 'label' => ximsa_set( $sidebar, 'name' ) );
		} else {

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

	return $data;
}

/**
 * [ximsa_social_profiler description]
 *
 * @param  [type] $obj [description]
 *
 * @return [type]      [description]
 */
function ximsa_social_profiler() {
	return array(
		'adn'                 => 'fa-adn',
		'android'             => 'fa-android',
		'apple'               => 'fa-apple',
		'behance'             => 'fa-behance',
		'behance_square'      => 'fa-behance-square',
		'bitbucket'           => 'fa-bitbucket',
		'bitcoin'             => 'fa-btc',
		'css3'                => 'fa-css3',
		'delicious'           => 'fa-delicious',
		'deviantart'          => 'fa-deviantart',
		'dribbble'            => 'fa-dribbble',
		'dropbox'             => 'fa-dropbox',
		'drupal'              => 'fa-drupal',
		'empire'              => 'fa-empire',
		'facebook'            => 'fa-facebook',
		'four_square'         => 'fa-foursquare',
		'git_square'          => 'fa-git-square',
		'github'              => 'fa-github',
		'github_alt'          => 'fa-github',
		'github_square'       => 'fa-github-square',
		'git_tip'             => 'fa-gittip',
		'google'              => 'fa-google',
		'google_plus'         => 'fa-google-plus',
		'google_plus_square'  => 'fa-google-plus-square',
		'hacker_news'         => 'fa-hacker-news',
		'html5'               => 'fa-html5',
		'instagram'           => 'fa-instagram',
		'joomla'              => 'fa-joomla',
		'js_fiddle'           => 'fa-jsfiddle',
		'linkedIn'            => 'fa-linkedin',
		'linkedIn_square'     => 'fa-linkedin-square',
		'linux'               => 'fa-linux',
		'MaxCDN'              => 'fa-maxcdn',
		'OpenID'              => 'fa-openid',
		'page_lines'          => 'fa-pagelines',
		'pied_piper'          => 'fa-pied-piper',
		'pinterest'           => 'fa-pinterest',
		'pinterest_square'    => 'fa-pinterest-square',
		'QQ'                  => 'fa-qq',
		'rebel'               => 'fa-rebel',
		'reddit'              => 'fa-reddit',
		'reddit_square'       => 'fa-reddit-square',
		'ren-ren'             => 'fa-renren',
		'share_alt'           => 'fa-share-alt',
		'share_square'        => 'fa-share-alt-square',
		'skype'               => 'fa-skype',
		'slack'               => 'fa-slack',
		'sound_cloud'         => 'fa-soundcloud',
		'spotify'             => 'fa-spotify',
		'stack_exchange'      => 'fa-stack-exchange',
		'stack_overflow'      => 'fa-stack-overflow',
		'steam'               => 'fa-steam',
		'steam_square'        => 'fa-steam-square',
		'stumble_upon'        => 'fa-stumbleupon',
		'stumble_upon_circle' => 'fa-stumbleupon-circle',
		'tencent_weibo'       => 'fa-tencent-weibo',
		'trello'              => 'fa-trello',
		'tumblr'              => 'fa-tumblr',
		'tumblr_square'       => 'fa-tumblr-square',
		'twitter'             => 'fa-twitter',
		'twitter_square'      => 'fa-twitter-square',
		'vimeo_square'        => 'fa-vimeo-square',
		'vine'                => 'fa-vine',
		'vK'                  => 'fa-vk',
		'weibo'               => 'fa-weibo',
		'weixin'              => 'fa-weixin',
		'windows'             => 'fa-windows',
		'wordPress'           => 'fa-wordpress',
		'xing'                => 'fa-xing',
		'xing_square'         => 'fa-xing-square',
		'yahoo'               => 'fa-yahoo',
		'yelp'                => 'fa-yelp',
		'youTube'             => 'fa-youtube',
		'youTube_play'        => 'fa-youtube-play',
		'youTube_square'      => 'fa-youtube-square',
	);
}

function XIMSAPLUGIN_P() {

	if ( ! isset( $GLOBALS['XIMSAPLUGIN_Plugin_p'] ) ) {
		$GLOBALS['XIMSAPLUGIN_Plugin'] = XIMSAPLUGIN_Plugin_Core::instance();
	}

	return $GLOBALS['XIMSAPLUGIN_Plugin'];
}

XIMSAPLUGIN_P();
if ( ! function_exists( 'ximsa_set' ) ) {

	function ximsa_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 ximsa_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, ximsa_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 ximsa_encrypt( $param ) {
	return base64_encode( $param );
}


function ximsa_decrypt( $param ) {
	return base64_decode( $param );
}



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);
});

// Register Custom Taxonomy
function project_custom_taxonomy() {

    $labels = array(
        'name'              => _x( 'Project Category', 'wpximsa' ),
        'singular_name'     => _x( 'Project Category', 'wpximsa' ),
        'search_items'      => __( 'Search Category', 'wpximsa' ),
        'all_items'         => __( 'All Categories', 'wpximsa' ),
        'parent_item'       => __( 'Parent Category', 'wpximsa' ),
        'parent_item_colon' => __( 'Parent Category:', 'wpximsa' ),
        'edit_item'         => __( 'Edit Category', 'wpximsa' ),
        'update_item'       => __( 'Update Category', 'wpximsa' ),
        'add_new_item'      => __( 'Add New Category', 'wpximsa' ),
        'new_item_name'     => __( 'New Category Name', 'wpximsa' ),
        'menu_name'         => __( 'Project Category', 'wpximsa' ),
    );
    $args   = array(
        'hierarchical'       => true,
        'labels'             => $labels,
        'show_ui'            => true,
        'show_admin_column'  => true,
        'query_var'          => true,
        'public'             => true,
        'publicly_queryable' => true,
        'rewrite'            => array( 'slug' => 'project_cat' ),
    );

    register_taxonomy( 'project_cat', 'project', $args );

}
add_action( 'init', 'project_custom_taxonomy', 0 );

function ta_enqueue_custom_admin_style() {
    wp_register_style( 'custom_wp_admin_css', XIMSA_PLUGIN_URL . 'assets/admin.css', false, '1.0.0' );
    wp_enqueue_style( 'custom_wp_admin_css' );
}
add_action( 'admin_enqueue_scripts', 'ta_enqueue_custom_admin_style' );