<?php
/**
 * Helper functions for the plugin.
 *
 * @package HAS
 */

namespace DLXPlugins\HAS;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Class Functions
 */
class Functions {

	/**
	 * Checks if the plugin is on a multisite install.
	 *
	 * @since 1.0.0
	 *
	 * @param bool $network_admin Check if in network admin.
	 *
	 * @return true if multisite, false if not.
	 */
	public static function is_multisite( $network_admin = false ) {
		if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
			require_once ABSPATH . '/wp-admin/includes/plugin.php';
		}
		$is_network_admin = false;
		if ( $network_admin ) {
			if ( is_network_admin() ) {
				if ( is_multisite() && is_plugin_active_for_network( self::get_plugin_slug() ) ) {
					return true;
				}
			} else {
				return false;
			}
		}
		if ( is_multisite() && is_plugin_active_for_network( self::get_plugin_slug() ) ) {
			return true;
		}
		return false;
	}

	/**
	 * Whether stats (dataLayer, gtag, synthetic events) are enabled for the frontend.
	 * Respects the HAS_STATS_ENABLED constant and the has_stats_enabled filter (filter overrides constant).
	 *
	 * @since 5.4.0
	 *
	 * @return bool True if stats are enabled, false otherwise.
	 */
	public static function is_stats_enabled() {
		$enabled = defined( 'HAS_STATS_ENABLED' ) ? (bool) constant( 'HAS_STATS_ENABLED' ) : true;
		/**
		 * Filter: has_stats_enabled
		 *
		 * Whether stats are enabled for the frontend.
		 *
		 * @param bool $enabled True if stats are enabled, false otherwise.
		 * @since 6.0.0
		 */
		return (bool) apply_filters( 'has_stats_enabled', $enabled );
	}

	/**
	 * Whether enhanced stats (URL, share text, title) are sent to dataLayer/gtag/CustomEvent.
	 * Default false for privacy; set HAS_STATS_ENHANCED or use has_stats_enhanced filter to enable.
	 *
	 * @since 5.4.0
	 *
	 * @return bool True if enhanced fields may be sent, false otherwise.
	 */
	public static function is_stats_enhanced() {
		$enhanced = defined( 'HAS_STATS_ENHANCED' ) ? (bool) constant( 'HAS_STATS_ENHANCED' ) : false;
		/**
		 * Filter: has_stats_enhanced
		 *
		 * Whether to send URL, share text, and title in stats (default false for privacy).
		 *
		 * @param bool $enhanced True to send enhanced fields, false to omit them.
		 * @since 7.0.0
		 */
		return (bool) apply_filters( 'has_stats_enhanced', $enhanced );
	}

	/**
	 * Sanitize an attribute based on type.
	 *
	 * @param array  $attributes Array of attributes.
	 * @param string $attribute  The attribute to sanitize.
	 * @param string $type       The type of sanitization you need (values can be integer, text, float, boolean, url).
	 *
	 * @return mixed Sanitized attribute. wp_error on failure.
	 */
	public static function sanitize_attribute( $attributes, $attribute, $type = 'text' ) {
		if ( isset( $attributes[ $attribute ] ) ) {
			switch ( $type ) {
				case 'raw':
					return $attributes[ $attribute ];
				case 'post_text':
				case 'post':
					return wp_kses_post( $attributes[ $attribute ] );
				case 'string':
				case 'text':
					return sanitize_text_field( $attributes[ $attribute ] );
				case 'bool':
				case 'boolean':
					return filter_var( $attributes[ $attribute ], FILTER_VALIDATE_BOOLEAN );
				case 'int':
				case 'integer':
					return absint( $attributes[ $attribute ] );
				case 'float':
					if ( is_float( $attributes[ $attribute ] ) ) {
						return $attributes[ $attribute ];
					}
					return 0;
				case 'url':
					return esc_url( $attributes[ $attribute ] );
				case 'default':
					return new \WP_Error( 'has_dlx_unknown_type', __( 'Unknown type.', 'highlight-and-share' ) );
			}
		}
		return new \WP_Error( 'has_dlx_attribute_not_found', __( 'Attribute not found.', 'highlight-and-share' ) );
	}

	/**
	 * Get the current admin tab.
	 *
	 * @return null|string Current admin tab.
	 */
	public static function get_admin_tab() {
		$tab = filter_input( INPUT_GET, 'tab', FILTER_DEFAULT );
		if ( $tab && is_string( $tab ) ) {
			return sanitize_text_field( sanitize_title( $tab ) );
		}
		return null;
	}

	/**
	 * Return the URL to the admin screen
	 *
	 * @param string $tab     Tab path to load.
	 * @param string $sub_tab Subtab path to load.
	 *
	 * @return string URL to admin screen. Output is not escaped.
	 */
	public static function get_settings_url( $tab = '', $sub_tab = '' ) {
		$options_url = admin_url( 'options-general.php?page=highlight-and-share' );
		if ( ! empty( $tab ) ) {
			$options_url = add_query_arg( array( 'tab' => sanitize_title( $tab ) ), $options_url );
			if ( ! empty( $sub_tab ) ) {
				$options_url = add_query_arg( array( 'subtab' => sanitize_title( $sub_tab ) ), $options_url );
			}
		}
		return $options_url;
	}

	/**
	 * Allow display and visiblity to style attributes.
	 *
	 * @param array $css CSS rules.
	 */
	public static function safe_css( $css = array() ) {
		$css[] = 'display';
		$css[] = 'visibility';
		return $css;
	}

	/**
	 * Retrieve a post's URL
	 *
	 * Retrieve a post's URL (may be shortened)
	 *
	 * @since 1.1
	 *
	 * @param int $post_id Post ID to retrieve the URL for.
	 * @return string $url URL to the post
	 */
	public static function get_content_url( $post_id ) {
		$settings          = Options::get_plugin_options();
		$enable_shortlinks = isset( $settings['shortlinks'] ) ? (bool) $settings['shortlinks'] : false;
		$url               = get_permalink( $post_id );
		if ( $enable_shortlinks ) {
			$maybe_url = wp_get_shortlink( $post_id );
			if ( ! empty( $maybe_url ) ) {
				$url = $maybe_url;
			}
		}

		/**
		 * Filter: has_content_url
		 *
		 * Modify the post or page URL that Highlight and Share uses for sharing.
		 *
		 * @param string Post or Page URL (may be shortened).
		 * @param int    The post or page ID.
		 */
		return apply_filters( 'has_content_url', $url, $post_id );
	}

	/**
	 * Checks to see if an asset is activated or not.
	 *
	 * @since 1.0.0
	 *
	 * @param string $path Path to the asset.
	 * @param string $type Type to check if it is activated or not.
	 *
	 * @return bool true if activated, false if not.
	 */
	public static function is_activated( $path, $type = 'plugin' ) {

		// Gets all active plugins on the current site.
		$active_plugins = self::is_multisite() ? get_site_option( 'active_sitewide_plugins' ) : get_option( 'active_plugins', array() );
		if ( in_array( $path, $active_plugins, true ) ) {
			return true;
		}
		return false;
	}

	/**
	 * Array data that must be sanitized.
	 *
	 * @param array $data Data to be sanitized.
	 *
	 * @return array Sanitized data.
	 */
	public static function sanitize_array_recursive( array $data ) {
		$sanitized_data = array();
		foreach ( $data as $key => $value ) {
			if ( '0' === $value ) {
				$value = 0;
			}
			if ( 'true' === $value ) {
				$value = true;
			} elseif ( 'false' === $value ) {
				$value = false;
			}
			if ( is_array( $value ) ) {
				$value                  = self::sanitize_array_recursive( $value );
				$sanitized_data[ $key ] = $value;
				continue;
			}
			if ( is_bool( $value ) ) {
				$sanitized_data[ $key ] = (bool) $value;
				continue;
			}
			if ( is_int( $value ) ) {
				$sanitized_data[ $key ] = (int) $value;
				continue;
			}
			if ( is_string( $value ) ) {
				// Preserve literal < and > for prefix/suffix (sanitize_text_field converts < to entity).
				if ( in_array( $key, array( 'sharing_prefix', 'sharing_suffix' ), true ) ) {
					$sanitized_data[ $key ] = trim( wp_check_invalid_utf8( $value ) );
				} else {
					$sanitized_data[ $key ] = sanitize_text_field( $value );
				}
				continue;
			}
		}
		return $sanitized_data;
	}

	/**
	 * Get available fonts for the block editor.
	 *
	 * @return array Array of fonts.
	 */
	public static function get_typography_fonts() {
		// Get the adobe fonts.
		$fonts_group = array();
		// Get Adobe fonts from https://wordpress.org/plugins/custom-typekit-fonts/.
		if ( defined( 'CUSTOM_TYPEKIT_FONTS_FILE' ) ) {
			$adobe_fonts = get_option( 'custom-typekit-fonts', array() );
			if ( isset( $adobe_fonts['custom-typekit-font-details'] ) ) {
				foreach ( $adobe_fonts['custom-typekit-font-details'] as $font_name => $font_details ) {
					$fonts_group[] = array(
						'value' => $font_name,
						'label' => $font_name,
					);
				}
			}
		}

		// Get blocksy adobe fonts.
		$options       = get_option( 'blocksy_ext_adobe_typekit_settings', array() );
		$font_families = $options['fonts'] ?? array();
		$project_id    = $options['project_id'] ?? '';
		if ( ! empty( $project_id ) ) {
			if ( function_exists( 'blc_get_ext' ) ) {
				$typekit = blc_get_ext( 'adobe-typekit' );
				// Add fonts to list.
				if ( $typekit ) {
					if ( ! empty( $font_families ) ) {
						foreach ( $font_families as $font_family ) {
							$fonts_group[] = array(
								'value' => $font_family['slug'],
								'label' => $font_family['name'],
							);
						}
					}
				}
			}
		}

		// Get blocksy google fonts.
		$google_fonts = get_option( 'blocksy_ext_local_google_fonts_settings', array() );
		if ( $google_fonts && isset( $google_fonts['fonts'] ) ) {
			if ( function_exists( 'blc_get_ext' ) && blc_get_ext( 'local-google-fonts' ) ) {
				foreach ( $google_fonts['fonts'] as $font_family ) {
					$fonts_group[] = array(
						'value' => $font_family['name'],
						'label' => $font_family['name'],
					);
				}
			}
		}

		// Get Custom Fonts (Local Google Fonts) plugin fonts. https://wordpress.org/plugins/custom-fonts/.
		if ( class_exists( 'BCF_Custom_Font_Families' ) ) {
			$local_google_fonts = \BCF_Custom_Font_Families::get_existing_google_fonts();
			if ( ! empty( $local_google_fonts ) ) {
				foreach ( $local_google_fonts as $font_name ) {
					$fonts_group[] = array(
						'value' => $font_name,
						'label' => $font_name,
					);
				}
			}
		}

		return $fonts_group;
	}

	/**
	 * Get all fonts used for the blocks.
	 *
	 * @param array $blocks Array of blocks/innerblocks.
	 * @param array $fonts  Array of fonts.
	 */
	public static function get_block_fonts( $blocks, $fonts = array() ) {
		$devices = array(
			'desktop',
			'mobile',
			'tablet',
		);
		if ( ! empty( $blocks ) ) {
			foreach ( $blocks as $block ) {
				if ( 'has/click-to-share' === $block['blockName'] ) {
					$quote_font = $block['attrs']['typographyQuote'] ?? false;
					$cts_font   = $block['attrs']['typographyShareText'] ?? false;
					if ( $quote_font ) {
						foreach ( $devices as $device ) {
							$font      = $quote_font[ $device ];
							$font_slug = $font['fontFamilySlug'];
							if ( ! isset( $fonts[ $font_slug ] ) ) {
								$fonts[ $font_slug ] = $font;
							}
						}
					}
					if ( $cts_font ) {
						foreach ( $devices as $device ) {
							$font      = $cts_font[ $device ];
							$font_slug = $font['fontFamilySlug'];
							if ( ! isset( $fonts[ $font_slug ] ) ) {
								$fonts[ $font_slug ] = $font;
							}
						}
					}
				}
				if ( ! empty( $block['innerBlocks'] ) ) {
					self::get_block_fonts( $block['innerBlocks'], $fonts );
				}
			}
		}
		return $fonts;
	}

	/**
	 * Check if Adobe Fonts are enabled or not.
	 *
	 * @return bool True if enabled, false if not.
	 */
	public static function is_adobe_fonts_enabled() {
		$options             = Options::get_plugin_options( true );
		$adobe_project_id    = $options['adobe_project_id'] ?? '';
		$adobe_fonts         = $options['adobe_fonts'] ?? false;
		$adobe_fonts_enabled = $options['enable_adobe_fonts'] ?? false;

		if ( $adobe_fonts_enabled && ! empty( $adobe_fonts ) && ! empty( $adobe_project_id ) ) {
			return true;
		}
		return false;
	}

	/**
	 * Get's a user's IP address (or at least tries to).
	 */
	public static function get_user_ip() {
		if ( array_key_exists( 'HTTP_X_FORWARDED_FOR', $_SERVER ) && ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
			if ( strpos( sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ), ',' ) > 0 ) {
				$addr = explode( ',', sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) );
				return trim( $addr[0] );
			} else {
				return sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_FORWARDED_FOR'] ) );
			}
		} else {
			if ( array_key_exists( 'REMOTE_ADDR', $_SERVER ) && ! empty( $_SERVER['REMOTE_ADDR'] ) ) {
				return trim( sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) );
			}
		}
		return '';
	}

	/**
	 * Take a _ separated field and convert to camelcase.
	 *
	 * @param array $fields Array of fields to convert to camelcase.
	 *
	 * @return string camelCased field.
	 */
	public static function to_camelcase_recursive( array $fields ) {
		foreach ( $fields as $key => $value ) {
			if ( is_numeric( $key ) || is_bool( $key ) ) {
				continue;
			}
			// Store old key.
			$old_key = $key;
			if ( is_array( $value ) ) {
				$value = self::to_camelcase_recursive( $value );
			}
			$key = self::to_camelcase( $key );
			if ( $key !== $old_key ) {
				unset( $fields[ $old_key ] );
			}
			$fields[ $key ] = $value;
		}
		return $fields;
	}

	/**
	 * Take a _ separated field and convert to camelcase.
	 *
	 * @param string $field Field to convert to camelcase.
	 *
	 * @return string camelCased field.
	 */
	public static function to_camelcase( string $field ) {
		return str_replace( '_', '', lcfirst( ucwords( $field, '_' ) ) );
	}

	/**
	 * Take a camelcase field and converts it to underline case.
	 *
	 * @param string $field Field to convert to camelcase.
	 *
	 * @return string $field Field name in camelCase..
	 */
	public static function to_underlines( string $field ) {
		$regex = '/([a-z])([A-Z])/';
		if ( preg_match( $regex, $field ) ) {
			$field = strtolower( preg_replace( $regex, '$1_$2', $field ) );
		}
		return $field;
	}

	/**
	 * Take a camelcase key and converts it to underline case.
	 *
	 * @param array $fields Array of fields to convert to underline case.
	 *
	 * @return array $fields Array of fields in underline case.
	 */
	public static function to_underlines_recursive( array $fields ) {
		foreach ( $fields as $key => $value ) {
			if ( is_numeric( $key ) || is_bool( $key ) ) {
				continue;
			}
			// Store old key.
			$old_key = $key;

			// Convert key to underline case.
			$key            = self::to_underlines( $key );
			$fields[ $key ] = $value;

			// Unset old key if it has changed.
			if ( $key !== $old_key ) {
				unset( $fields[ $old_key ] );
			}

			// Recursively convert array values to underline case.
			if ( is_array( $value ) ) {
				$fields[ $key ] = self::to_underlines_recursive( $value );
			}
		}
		return $fields;
	}

	/**
	 * Get all public post types.
	 *
	 * @return array Array of post type objects.
	 */
	public static function get_post_types() {
		$post_types          = get_post_types(
			array(
				'public' => true,
			),
			'objects'
		);
		$excluded_post_types = array( 'attachment', 'revision', 'nav_menu_item', 'ct_content_block' );
		return array_filter(
			$post_types,
			function ( $post_type ) use ( $excluded_post_types ) {
				return ! in_array( $post_type->name, $excluded_post_types, true );
			}
		);
	}

	/**
	 * Return the plugin slug.
	 *
	 * @return string plugin slug.
	 */
	public static function get_plugin_slug() {
		return dirname( plugin_basename( HIGHLIGHT_AND_SHARE_FILE ) );
	}

	/**
	 * Return the basefile for the plugin.
	 *
	 * @return string base file for the plugin.
	 */
	public static function get_plugin_file() {
		return plugin_basename( HIGHLIGHT_AND_SHARE_FILE );
	}

	/**
	 * Return the version for the plugin.
	 *
	 * @return float version for the plugin.
	 */
	public static function get_plugin_version() {
		return HIGHLIGHT_AND_SHARE_VERSION;
	}

	/**
	 * Get the plugin author name.
	 */
	public static function get_plugin_author() {
		/**
		 * Filer the output of the plugin Author.
		 *
		 * Potentially change branding of the plugin.
		 *
		 * @since 1.0.0
		 *
		 * @param string Plugin Author name.
		 */
		$plugin_author = apply_filters( 'has_dlx_plugin_author', 'MediaRon LLC' );
		return $plugin_author;
	}

	/**
	 * Return the Plugin author URI.
	 */
	public static function get_plugin_author_uri() {
		/**
		 * Filer the output of the plugin Author URI.
		 *
		 * Potentially change branding of the plugin.
		 *
		 * @since 1.0.0
		 *
		 * @param string Plugin Author URI.
		 */
		$plugin_author = apply_filters( 'has_dlx_plugin_author_uri', 'https://mediaron.com' );
		return $plugin_author;
	}

	/**
	 * Return the plugin name for the plugin.
	 *
	 * @return string Plugin name.
	 */
	public static function get_plugin_name() {
		/**
		 * Filer the output of the plugin name.
		 *
		 * Potentially change branding of the plugin.
		 *
		 * @since 1.0.0
		 *
		 * @param string Plugin name.
		 */
		return apply_filters( 'has_dlx_plugin_name', __( 'Highlight and Share', 'highlight-and-share' ) );
	}

	/**
	 * Return the plugin description for the plugin.
	 *
	 * @return string plugin description.
	 */
	public static function get_plugin_description() {
		/**
		 * Filer the output of the plugin name.
		 *
		 * Potentially change branding of the plugin.
		 *
		 * @since 1.0.0
		 *
		 * @param string Plugin description.
		 */
		return apply_filters( 'has_dlx_plugin_description', __( 'An alert and notification block inspired by Bootstrap, Material UI, and Chakra UI.', 'highlight-and-share' ) );
	}

	/**
	 * Retrieve the plugin URI.
	 */
	public static function get_plugin_uri() {
		/**
		 * Filer the output of the plugin URI.
		 *
		 * Potentially change branding of the plugin.
		 *
		 * @since 1.0.0
		 *
		 * @param string Plugin URI.
		 */
		return apply_filters( 'has_dlx_plugin_uri', 'https://dlxplugins.com/plugins/highlight-and-share' );
	}

	/**
	 * Retrieve the plugin support URI.
	 */
	public static function get_plugin_support_uri() {
		/**
		 * Filer the output of the plugin support URI.
		 *
		 * Potentially change branding of the plugin.
		 *
		 * @since 1.0.0
		 *
		 * @param string Plugin Support URI.
		 */
		return apply_filters( 'has_dlx_plugin_support_uri', 'https://dlxplugins.com/support/' );
	}

	/**
	 * Retrieve the plugin documentation URI.
	 */
	public static function get_plugin_docs_uri() {
		/**
		 * Filer the output of the plugin docs URI.
		 *
		 * Potentially change branding of the plugin.
		 *
		 * @since 1.0.0
		 *
		 * @param string Plugin Docs URI.
		 */
		return apply_filters( 'has_dlx_plugin_docs_uri', 'https://has.dlxplugins.com/' );
	}

	/**
	 * Retrieve the plugin documentation URI.
	 */
	public static function get_plugin_ratings_uri() {
		/**
		 * Filer the output of the plugin ratings URI.
		 *
		 * Potentially change branding of the plugin.
		 *
		 * @since 1.0.0
		 *
		 * @param string Plugin ratings URI.
		 */
		return apply_filters( 'has_dlx_plugin_docs_uri', 'https://dlxplugins.com/support/' );
	}

	/**
	 * Retrieve the plugin title.
	 */
	public static function get_plugin_title() {
		/**
		 * Filer the output of the plugin title.
		 *
		 * Potentially change branding of the plugin.
		 *
		 * @since 1.0.0
		 *
		 * @param string Plugin Menu Name.
		 */
		return apply_filters( 'has_dlx_plugin_menu_title', self::get_plugin_name() );
	}

	/**
	 * Returns appropriate html for KSES.
	 *
	 * @param bool $svg         Whether to add SVG data to KSES.
	 * @param bool $with_tables Whether to add tables to KSES.
	 */
	public static function get_kses_allowed_html( $svg = true, $with_tables = false ) {
		$allowed_tags = wp_kses_allowed_html( 'post' );

		$allowed_tags['nav']        = array(
			'class' => array(),
		);
		$allowed_tags['a']['class'] = array();

		// Add form input fields.
		$allowed_tags['input'] = array(
			'type'        => array(),
			'class'       => array(),
			'id'          => array(),
			'name'        => array(),
			'value'       => array(),
			'placeholder' => array(),
			'required'    => array(),
			'checked'     => array(),
		);

		// Add button fields.
		$allowed_tags['button'] = array(
			'type'      => array(),
			'class'     => array(),
			'id'        => array(),
			'name'      => array(),
			'data-type' => array(),
		);

		// Add select field.
		$allowed_tags['select'] = array(
			'class' => array(),
			'id'    => array(),
			'name'  => array(),
		);

		// Add options field.
		$allowed_tags['option'] = array(
			'value'    => array(),
			'selected' => array(),
		);

		if ( ! $svg && ! $with_tables ) {
			return $allowed_tags;
		}
		if ( $svg ) {
			$allowed_tags['svg'] = array(
				'xmlns'       => array(),
				'fill'        => array(),
				'viewbox'     => array(),
				'role'        => array(),
				'aria-hidden' => array(),
				'focusable'   => array(),
				'class'       => array(),
				'width'       => array(),
				'height'      => array(),
			);

			$allowed_tags['path'] = array(
				'd'       => array(),
				'fill'    => array(),
				'opacity' => array(),
			);

			$allowed_tags['g'] = array();

			$allowed_tags['circle'] = array(
				'cx'     => array(),
				'cy'     => array(),
				'r'      => array(),
				'fill'   => array(),
				'stroke' => array(),
			);

			$allowed_tags['use'] = array(
				'xlink:href' => array(),
			);

			$allowed_tags['symbol'] = array(
				'aria-hidden' => array(),
				'viewBox'     => array(),
				'id'          => array(),
				'xmls'        => array(),
			);
		}

		// Add HTML table markup.
		if ( $with_tables ) {
			$allowed_tags['html']  = array(
				'lang' => array(),
			);
			$allowed_tags['head']  = array();
			$allowed_tags['title'] = array();
			$allowed_tags['meta']  = array(
				'http-equiv' => array(),
				'content'    => array(),
				'name'       => array(),
			);
			$allowed_tags['body']  = array(
				'style' => array(),
			);
			$allowed_tags['style'] = array();
			$allowed_tags['table'] = array(
				'class'        => array(),
				'width'        => array(),
				'border'       => array(),
				'cellpadding'  => array(),
				'cellspacing'  => array(),
				'role'         => array(),
				'presentation' => array(),
				'align'        => array(),
				'bgcolor'      => array(),
			);
			$allowed_tags['tbody'] = array();
			$allowed_tags['thead'] = array();
			$allowed_tags['tr']    = array(
				'bgcolor' => array(),
				'align'   => array(),
				'style'   => array(),
			);
			$allowed_tags['th']    = array();
			$allowed_tags['td']    = array(
				'class' => array(),
				'width' => array(),
				'style' => array(),
			);
			if ( ! isset( $allowed_tags['div'] ) ) {
				$allowed_tags['div'] = array(
					'style' => array(),
					'align' => array(),
					'class' => array(),
				);
			} else {
				$allowed_tags['div']['style'] = array();
				$allowed_tags['div']['align'] = array();
				$allowed_tags['div']['class'] = array();
			}
			if ( ! isset( $allowed_tags['p'] ) ) {
				$allowed_tags['p'] = array(
					'style' => array(),
				);
			} else {
				$allowed_tags['p']['style'] = array();
			}
			$allowed_tags['h1'] = array(
				'style' => array(),
			);
			$allowed_tags['h2'] = array(
				'style' => array(),
			);
		}

		return $allowed_tags;
	}

	/**
	 * Get the plugin directory for a path.
	 *
	 * @param string $path The path to the file.
	 *
	 * @return string The new path.
	 */
	public static function get_plugin_dir( $path = '' ) {
		$dir = rtrim( plugin_dir_path( HIGHLIGHT_AND_SHARE_FILE ), '/' );
		if ( ! empty( $path ) && is_string( $path ) ) {
			$dir .= '/' . ltrim( $path, '/' );
		}
		return $dir;
	}

	/**
	 * Return a plugin URL path.
	 *
	 * @param string $path Path to the file.
	 *
	 * @return string URL to to the file.
	 */
	public static function get_plugin_url( $path = '' ) {
		$dir = rtrim( plugin_dir_url( HIGHLIGHT_AND_SHARE_FILE ), '/' );
		if ( ! empty( $path ) && is_string( $path ) ) {
			$dir .= '/' . ltrim( $path, '/' );
		}
		return $dir;
	}

	/**
	 * Gets the highest priority for a filter.
	 *
	 * @param int $subtract The amount to subtract from the high priority.
	 *
	 * @return int priority.
	 */
	public static function get_highest_priority( $subtract = 0 ) {
		$highest_priority = PHP_INT_MAX;
		$subtract         = absint( $subtract );
		if ( 0 === $subtract ) {
			--$highest_priority;
		} else {
			$highest_priority = absint( $highest_priority - $subtract );
		}
		return $highest_priority;
	}
}
