<?php if (!defined('APS_ADS_VER')) exit('restricted access');
/*
 * @package WordPress
 * @subpackage APS Ads
*/

	function get_aps_ads_settings() {
		// get groups
		$groups = get_all_aps_groups();
		$groups_hooks = array();
		
		if ($groups) {
			foreach ($groups as $group) {
				$groups_hooks['after_aps_specs_group_' .$group->term_id] = __('After', 'aps-ads') .' ' .$group->name;
			}
		}
		
		// define settings fields
		$settings = array(
			'catalog' => array(
				'title' => __('Main Catalog', 'aps-ads'),
				'hooks' => array(
					'aps_catalog_before_title' => __('Before Title', 'aps-ads'),
					'aps_catalog_after_title' => __('After Title', 'aps-ads'),
					'aps_catalog_after_controls' => __('After Controls', 'aps-ads'),
					'aps_catalog_after_results' => __('After Results', 'aps-ads')
				)
			),
			'search' => array(
				'title' => __('Search Archive', 'aps-ads'),
				'hooks' => array(
					'aps_search_archive_before_title' => __('Before Title', 'aps-ads'),
					'aps_search_archive_after_title' => __('After Title', 'aps-ads'),
					'aps_search_archive_after_controls' => __('After Controls', 'aps-ads'),
					'aps_search_archive_after_results' => __('After Results', 'aps-ads')
				)
			),
			'category' => array(
				'title' => __('Category Archive', 'aps-ads'),
				'hooks' => array(
					'aps_cat_archive_before_title' => __('Before Title', 'aps-ads'),
					'aps_cat_archive_after_title' => __('After Title', 'aps-ads'),
					'aps_cat_archive_after_controls' => __('After Controls', 'aps-ads'),
					'aps_cat_archive_after_results' => __('After Results', 'aps-ads')
				)
			),
			'brand' => array(
				'title' => __('Brand Archive', 'aps-ads'),
				'hooks' => array(
					'aps_brand_archive_before_title' => __('Before Title', 'aps-ads'),
					'aps_brand_archive_after_title' => __('After Title', 'aps-ads'),
					'aps_brand_archive_after_controls' => __('After Controls', 'aps-ads'),
					'aps_brand_archive_after_results' => __('After Results', 'aps-ads')
				)
			),
			'compare' => array(
				'title' => __('Products Compare', 'aps-ads'),
				'hooks' => array(
					'aps_compare_after_search' => __('After Search', 'aps-ads'),
					'aps_compare_before_title' => __('Before Title', 'aps-ads'),
					'aps_compare_after_title' => __('After Title', 'aps-ads'),
					'aps_compare_after_comparison' => __('After Comparison', 'aps-ads')
				)
			),
			'single' => array(
				'title' => __('Single Product', 'aps-ads'),
				'hooks' => array(
					'aps_single_before_title' => __('Before Title', 'aps-ads'),
					'aps_single_after_title' => __('After Title', 'aps-ads'),
					'aps_single_after_features' => __('After Features', 'aps-ads'),
					'aps_single_before_overview' => __('Before Overview', 'aps-ads'),
					'aps_single_before_content' => __('Before Content', 'aps-ads'),
					'aps_single_after_content' => __('After Content', 'aps-ads'),
					'aps_single_before_specs' => __('Before Attributes', 'aps-ads'),
					'aps_single_after_specs' => __('After Attributes', 'aps-ads'),
					'aps_single_before_reviews' => __('Before Reviews', 'aps-ads'),
					'aps_single_after_reviews' => __('After Reviews', 'aps-ads'),
					'aps_single_before_videos' => __('Before Videos', 'aps-ads'),
					'aps_single_after_videos' => __('After Videos', 'aps-ads'),
					'aps_single_before_offers' => __('Before Offers', 'aps-ads'),
					'aps_single_after_offers' => __('After Offers', 'aps-ads'),
					'aps_single_before_custom1' => __('Before Custom Tab1', 'aps-ads'),
					'aps_single_after_custom1' => __('After Custom Tab1', 'aps-ads'),
					'aps_single_before_custom2' => __('Before Custom Tab2', 'aps-ads'),
					'aps_single_after_custom2' => __('After Custom Tab2', 'aps-ads'),
					'aps_single_before_custom3' => __('Before Custom Tab3', 'aps-ads'),
					'aps_single_after_custom3' => __('After Custom Tab3', 'aps-ads'),
					'aps_single_before_related' => __('Before Related Products', 'aps-ads'),
					'aps_single_after_related' => __('After Related Products', 'aps-ads')
				)
			),
			'brands' => array(
				'title' => __('Brands List', 'aps-ads'),
				'hooks' => array(
					'aps_brands_list_before_title' => __('Before Title', 'aps-ads'),
					'aps_brands_list_after_title' => __('After Title', 'aps-ads'),
					'aps_brands_list_after_alphabet' => __('After Alphabet', 'aps-ads')
				)
			),
			'comparisons' => array(
				'title' => __('Comparisons List', 'aps-ads'),
				'hooks' => array(
					'aps_comparisons_before_title' => __('Before Title', 'aps-ads'),
					'aps_comparisons_after_title' => __('After Title', 'aps-ads'),
					'aps_comparisons_before_pagination' => __('Before Pagination', 'aps-ads'),
					'aps_comparisons_after_results' => __('After Results', 'aps-ads')
				)
			),
			'groups' => array(
				'title' => __('Attributes Groups', 'aps-ads'),
				'hooks' => $groups_hooks
			)
		);
		
		return apply_filters('get_aps_ads_settings', $settings);
	}
	
	// ad posts data
	function aps_ads_posts_data() {
		// get ad posts
		global $post;
		$ad_posts = get_posts( 'post_type=aps-ads&posts_per_page=-1' );
		
		if ($ad_posts) {
			$ads_array = array();
			foreach ($ad_posts as $post) {
				setup_postdata( $post );
				$ad_format = get_post_meta($post->ID, 'aps-ad-format', true);
				$ad_size = get_post_meta($post->ID, 'aps-ad-size', true);
				$ad_type = get_readable_aps_ad_format($ad_format);
				
				$ads_array[$post->ID] = array(
					'title' => get_the_title(),
					'type' => $ad_type
				);
			}
			wp_reset_postdata();
			return $ads_array;
		}
		return false;
	}
	
	// ad display conditions
	function aps_ads_display_conditions() {
		$conditions = array(
			'mb' => __('Mobiles Only', 'aps-ads'),
			'tb' => __('Tablets Only', 'aps-ads'),
			'ds' => __('Desktops Only', 'aps-ads'),
			'dm' => __('Desktops + Mobiles', 'aps-ads'),
			'dt' => __('Desktops + Tablets', 'aps-ads'),
			'tm' => __('Tablets + Mobiles', 'aps-ads'),
			'dtm' => __('Desktops + Tablets + Mobiles', 'aps-ads'),
			'dd' => __('Don\'t Display', 'aps-ads')
		);
		
		return $conditions;
	}
	
	// add ads css styles to stylesheet
	add_filter('add_aps_css_styles', 'aps_ads_add_css_styles');
	
	function aps_ads_add_css_styles($styles) {
		$styles .= '.aps-ads-row {margin-left:-10px; margin-right:-10px;}';
		$styles .= '.aps-ads-row:before, .aps-ads-row:after {content:""; display:table; clear:both;}';
		$styles .= '.aps-ad {max-width:100%; height:auto; padding-left:10px; padding-right:10px;}';
		$styles .= '.aps-ad-align-l {float:left;}';
		$styles .= '.aps-ad-align-r {float:right;}';
		$styles .= '.aps-ad-align-c {text-align:center; margin-left:auto !important; margin-right:auto !important;}';
		
		// return all the styles
		return $styles;
	}
	