<?php

namespace matador\MatadorJobs\Jobs;

use matador\Matador;

final class JobHelper {

	/**
	 * Job Description Allowed HTML Tags
	 *
	 * Allowed tags array to pass to `wp_kses()` when run on the imported job description.
	 *
	 * @since 3.0.0
	 * @since 3.9.6 moved from Bullhorn Job Import into Job Helper
	 *
	 * @return array
	 */
	public static function job_description_allowed_tags(): array {

		$allowed_tags = [
			'a'          => [
				'href'   => true,
				'title'  => true,
				'target' => true,
			],
			'br'         => [],
			'hr'         => [],
			'em'         => [],
			'i'          => [],
			'strong'     => [],
			'b'          => [],
			'p'          => [
				'align' => true,
			],
			'blockquote' => true,
			'img'        => [
				'alt'    => true,
				'align'  => true,
				'height' => true,
				'src'    => true,
				'width'  => true,
			],
			'div'        => [
				'align' => true,
			],
			'table'      => [
				'border'      => true,
				'cellspacing' => true,
				'cellpadding' => true,
			],
			'thead'      => [],
			'tbody'      => [],
			'tr'         => [],
			'th'         => [
				'colspan' => true,
				'rowspan' => true,
			],
			'td'         => [
				'colspan' => true,
				'rowspan' => true,
			],
			'span'       => [],
			'h1'         => [
				'align' => true,
			],
			'h2'         => [
				'align' => true,
			],
			'h3'         => [
				'align' => true,
			],
			'h4'         => [
				'align' => true,
			],
			'h5'         => [
				'align' => true,
			],
			'h6'         => [
				'align' => true,
			],
			'ul'         => [],
			'ol'         => [],
			'li'         => [],
			'dl'         => [],
			'dt'         => [],
			'dd'         => [],
			's'          => [],
			'sub'        => [],
			'sup'        => [],
			'video'      => [
				'autoplay' => true,
				'controls' => true,
				'height'   => true,
				'loop'     => true,
				'muted'    => true,
				'poster'   => true,
				'preload'  => true,
				'src'      => true,
				'width'    => true,
			],
			'u'          => [],
		];

		/**
		 * @deprecated 4.0.0
		 */
		$allowed_tags = apply_filters( 'matador_the_jobs_description_allowed_tags', $allowed_tags );

		/**
		 * @wordpress-filter `matador_job_description_allowed_tags`
		 * Job Description Allowed HTML Tags
		 *
		 * Allowed fields array for the wp_kses() filter on the description imported from Bullhorn.
		 *
		 * @see https://developer.wordpress.org/reference/functions/wp_kses/
		 *
		 * @since 3.0.0 as `matador_the_jobs_description_allowed_tags`
		 * @since 4.0.0
		 *
		 * @return array
		 */
		return apply_filters( 'matador_job_description_allowed_tags', $allowed_tags );
	}

	/**
	 * Job Description Allowed Protocols
	 *
	 * Allowed protocols array to pass to `wp_kses()` when run on the imported job description.
	 *
	 * @since 3.6.4
	 * @since 3.9.6 moved from Bullhorn Job Import into Job Helper
	 *
	 * @return array
	 */
	public static function job_description_allowed_protocols(): array {

		$allowed_protocols = wp_allowed_protocols();

		/**
		 * @deprecated 4.0.0
		 */
		$allowed_protocols = apply_filters( 'matador_the_jobs_description_allowed_protocols', $allowed_protocols );

		/**
		 * @wordpress-filter `matador_job_description_allowed_protocols`
		 * Job Description Allowed HTTP Protocols
		 *
		 * WARNING: Allowing additional protocols deemed unsafe by WordPress is DANGEROUS. Only do so if you know what you
		 * are doing and the implications of such. Matador Jobs provides this filter as a tool to limit additional allowed
		 * protocols to only job descriptions, but provides no warranty of the security of what you let through.
		 *
		 * @since 3.6.4 as `matador_the_jobs_description_allowed_protocols`
		 * @since 4.0.0
		 *
		 * @param array $protocols Default is returned value from wp_allowed_protocols(), subject to any global-level
		 *                         filtered values.
		 *
		 * @return array
		 */
		return apply_filters( 'matador_job_description_allowed_protocols', $allowed_protocols );
	}
}