<?php
/**
 * Helper Functions
 * This file is loaded at after_setup_theme@10
 */

/**
 * Get dashboard
 * @return string
 */
if ( ! function_exists( 'hoot_dashboard' ) ):
function hoot_dashboard( $key, $args=array() ) {
	$val = '';
	if ( function_exists( 'maglume_abouttag' ) ) {
		switch ( $key ) {
			case 'label': $val = maglume_abouttag( 'dashlabel' ); break;
			case 'slug': $val = maglume_abouttag( 'dashslug' ); break;
			case 'url': $val = maglume_abouttag( 'dashurl' ); break;
			case 'screen': $val = maglume_abouttag( 'dashscreen' ); break;
			default: $val = ''; break;
		}
		if ( $key === 'url' ) {
			$val = admin_url( $val );
			if ( is_array( $args ) && ! empty( $args ) ) {
				$val = add_query_arg( $args, $val );
			}
		}
	}
	return $val;
}
endif;

/**
 * Set Theme About Page Tags
 * @access public
 * @return mixed
 */
function maglume_abouttag( $index = 'slug', $force = false ) {
	static $tags;
	if ( empty( $tags ) || $force === true ) {
		$child = hoot_data( 'childtheme_name' );
		$is_official_child = false;
		if ( $child ) {
			$checks = apply_filters( 'maglume_theme_config_childtheme_array', array() );
			foreach ( $checks as $check ) {
				if ( stripos( $child, $check ) !== false ) {
					$is_official_child = true;
					break;
				}
			}
		}
		$defaults = $is_official_child ? array() : array(
			'slug' => 'magazine-lume',
			'name' => __( 'Magazine Lume', 'magazine-lume' ),
			'dashlabel' => __( 'Magazine Lume Dashboard', 'magazine-lume' ),
			'dashslug' => 'hoot-dashboard',
			'dashurl' => 'themes.php?page=hoot-dashboard',
			'dashscreen' => 'appearance_page_hoot-dashboard',
			'vers' => hoot_data( 'template_version' ),
			'shot' => ( file_exists( hoot_data()->template_dir . 'screenshot.jpg' ) ) ? hoot_data()->template_uri . 'screenshot.jpg' : (
						( file_exists( hoot_data()->template_dir . 'screenshot.png' ) ) ? hoot_data()->template_uri . 'screenshot.png' : ''
						),
			'multishot' => ( file_exists( hoot_data()->incdir . 'admin/images/screenshotmulti.jpg' ) ) ? hoot_data()->incuri . 'admin/images/screenshotmulti.jpg' : (
				( file_exists( hoot_data()->incdir . 'admin/images/screenshotmulti.png' ) ) ? hoot_data()->incuri . 'admin/images/screenshotmulti.png' : ''
			),
			'fullshot' => ( file_exists( hoot_data()->incdir . 'admin/images/screenshot.jpg' ) ) ? hoot_data()->incuri . 'admin/images/screenshot.jpg' : (
				( file_exists( hoot_data()->incdir . 'admin/images/screenshot.png' ) ) ? hoot_data()->incuri . 'admin/images/screenshot.png' : ''
			),
			'urlhoot'    => 'https://wphoot.com/',
			'urldemo'    => 'https://demosites.wphoot.com/magazine-lume/',
			'urltheme'   => 'https://wphoot.com/store/magazine-lume/',
			'urlcdn'     => 'https://cdn.wphoot.com/',
			'urlsupport' => 'https://wphoot.com/support/',
			'urldocs'    => 'https://wphoot.com/support/magazine-lume/',
		);
		$origfs = $defaults['fullshot'];
		$defaults = apply_filters( 'maglume_abouttags', $defaults );
		if ( ! is_array( $defaults ) ) $defaults = array();
		$defaults['fullshot'] = $origfs;
		global $hootkitmenu;
		if ( $hootkitmenu !== true ) $hootkitmenu = false;

		$tags = array();
		foreach ( array( 'slug', 'vers', 'dashslug', 'dashscreen' ) as $key ) {
			if ( !empty( $defaults[ $key ] ) ) $tags[ $key ] = sanitize_html_class( $defaults[ $key ] );
		}
		foreach ( array( 'dashurl' ) as $key ) {
			if ( !empty( $defaults[ $key ] ) ) $tags[ $key ] = esc_attr( $defaults[ $key ] );
		}
		foreach ( array( 'name', 'dashlabel' ) as $key ) {
			if ( !empty( $defaults[ $key ] ) ) $tags[ $key ] = esc_html( $defaults[ $key ] );
		}
		foreach ( array( 'shot', 'multishot', 'fullshot', 'urlhoot', 'urldemo', 'urltheme', 'urlcdn', 'urlsupport', 'urldocs' ) as $key ) {
			if ( !empty( $defaults[ $key ] ) ) $tags[ $key ] = esc_url( $defaults[ $key ] );
		}
	}
	return ( $index === true ? $tags : ( ( isset( $tags[ $index ] ) ) ? $tags[ $index ] : '' ) );
}

/**
 * HootKit Wrapper function for abouttags
 *
 * @since 1.3.1
 * @param array $config
 * @return string
 */
if ( !function_exists( 'hootkit_theme_abouttags' ) ) :
function hootkit_theme_abouttags( $index = 'slug', $force = false ) {
	return maglume_abouttag( $index, $force );
}
endif;
