<?php
/**
 * @copyright	Copyright (c) 2016 AmyTheme (http://www.amytheme.com). All rights reserved.
 * @license		http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
 */

defined( 'ABSPATH' ) or die;

/**
 * Get image otpion
 */
if ( ! function_exists( 'amy_get_image_option' ) ) {
	function amy_get_image_option( $option_name = '', $default = '', $type = '' ) {
		return $default;
	}
}

/**
 * Get option
 */
if ( ! function_exists( 'amy_get_option' ) ) {
	function amy_get_option( $option_name = '', $default = '' ) {
		return $default;
	}
}

/**
 * Get all option
 */
if ( ! function_exists( 'amy_get_all_option' ) ) {
	function amy_get_all_option() {
		return false;
	}
}

/**
 * Multi language option
 */
if ( ! function_exists( 'amy_get_multilang_option' ) ) {
	function amy_get_multilang_option( $option_name = '', $default = '' ) {
		$value		= amy_get_option( $option_name, $default );
		$languages	= amy_language_defaults();
		$default	= $languages['default'];
		$current	= $languages['current'];

		if ( is_array( $value ) && is_array( $languages ) && isset( $value[ $current ] ) ) {
			return $value[ $current ];
		} else if ( $default != $current ) {
			return '';
		}

		return $value;
	}
}

/**
 * Multi language value
 */
if ( ! function_exists( 'amy_get_multilang_value' ) ) {
	function amy_get_multilang_value( $value = '', $default = '' ) {
		$languages	= amy_language_defaults();
		$default	= $languages['default'];
		$current	= $languages['current'];

		if ( is_array( $value ) && is_array( $languages ) && isset( $value[ $current ] ) ) {
			return $value[ $current ];
		} else if ( $default != $current ) {
			return '';
		}

		return $value;
	}
}

/**
 * Get customize option
 */
if ( ! function_exists( 'amy_get_customize_option' ) ) {
	function amy_get_customize_option( $option_name = '', $default = '' ) {
		return ( ! empty( $default )) ? $default : null;
	}
}

/**
 * Set customize option
 */
if ( ! function_exists( 'amy_set_customize_option' ) ) {
	function amy_set_customize_option( $option_name = '', $new_value = '' ) {

	}
}

/**
 * Get all customize option
 */
if ( ! function_exists( 'amy_get_all_customize_option' ) ) {
	function amy_get_all_customize_option() {
		return false;
	}
}

/**
 * WPML plugin is activated
 */
if ( ! function_exists( 'amy_is_wpml_activated' ) ) {
	function amy_is_wpml_activated() {
		if ( class_exists( 'SitePress' ) ) {
			return true;
		} else {
			return false;
		}
	}
}

/**
 * qTranslate plugin is activated
 */
if ( ! function_exists( 'amy_is_qtranslate_activated' ) ) {
	function amy_is_qtranslate_activated() {
		if ( function_exists( 'qtrans_getSortedLanguages' ) ) {
			return true;
		} else {
			return false;
		}
	}
}

/**
 * Polylang plugin is activated
 */
if ( ! function_exists( 'amy_is_polylang_activated' ) ) {
	function amy_is_polylang_activated() {
		if ( class_exists( 'Polylang' ) ) {
			return true;
		} else {
			return false;
		}
	}
}

/**
 * Get language defaults
 */
if ( ! function_exists( 'amy_language_defaults' ) ) {
	function amy_language_defaults() {
		$multilang	= array();

		if ( amy_is_wpml_activated() || amy_is_qtranslate_activated() || amy_is_polylang_activated() ) {
			if ( amy_is_wpml_activated() ) {
				global $sitepress;

				$multilang['default']	= $sitepress->get_default_language();
				$multilang['current']	= $sitepress->get_current_language();
				$multilang['languages']	= $sitepress->get_active_languages();
			} else if ( amy_is_polylang_activated() ) {
				global $polylang;

				$current	= pll_current_language();
				$default	= pll_default_language();
				$current	= (empty( $current )) ? $default : $current;
				$poly_langs	= $polylang->model->get_languages_list();
				$languages	= array();

				foreach ( $poly_langs as $p_lang ) {
					$languages[ $p_lang->slug ]	= $p_lang->slug;
				}

				$multilang['default']	= $default;
				$multilang['current']	= $current;
				$multilang['languages']	= $languages;
			} else if ( amy_is_qtranslate_activated() ) {
				global $q_config;

				$multilang['default']	= $q_config['default_language'];
				$multilang['current']	= $q_config['language'];
				$multilang['languages']	= array_flip( qtrans_getSortedLanguages() );
			}
		}

		$multilang	= apply_filters( 'amy_language_defaults', $multilang );

		return ( ! empty( $multilang )) ? $multilang : false;

	}
}

/**
 * Visual Composer plugin is activated
 */
if ( ! function_exists( 'is_vc_activated' ) ) {
	function is_vc_activated() {
		if ( class_exists( 'Vc_Manager' ) && defined( 'WPB_VC_VERSION' ) && version_compare( WPB_VC_VERSION, '4.2.3', '>=' ) ) {
			return true;
		} else {
			return false;
		}
	}
}

/**
 * Get locate for load textdomain
 */
if ( ! function_exists( 'amy_get_locale' ) ) {
	function amy_get_locale() {
		global $locale, $wp_local_package;

		if ( isset( $locale ) ) {
			return apply_filters( 'locale', $locale );
		}

		if ( isset( $wp_local_package ) ) {
			$locale	= $wp_local_package;
		}

		if ( defined( 'WPLANG' ) ) {
			$locale	= WPLANG;
		}

		if ( is_multisite() ) {
			if ( defined( 'WP_INSTALLING' ) || (false === $ms_locale = get_option( 'WPLANG' )) ) {
				$ms_locale	= get_site_option( 'WPLANG' );
			}

			if ( $ms_locale !== false ) {
				$locale	= $ms_locale;
			}
		} else {

			$db_locale	= get_option( 'WPLANG' );

			if ( $db_locale !== false ) {
				$locale	= $db_locale;
			}
		}

		if ( empty( $locale ) ) {
			$locale	= 'en_US';
		}

		return apply_filters( 'locale', $locale );
	}
}

/**
 * Get google fonts.
 */
if ( ! function_exists( 'amy_get_google_fonts' ) && ! defined( 'AMY_VERSION' ) ) {
	function amy_get_google_fonts() {
		return array();
	}
}
