HEX
Server: Apache
System: Linux webd006.cluster128.gra.hosting.ovh.net 6.18.42-ovh-vps-grsec-zfs+ #1 SMP PREEMPT_DYNAMIC Wed Aug 5 15:59:48 CEST 2026 x86_64
User: zwafgyp (177615)
PHP: 7.4.33
Disabled: _dyuweyrj4,_dyuweyrj4r,dl
Upload Files
File: /home/z/w/a/zwafgyp/coolswim/wp-content/mu-plugins/ionos-help-center/inc/class-manager.php
<?php

namespace Ionos\Help_Center;

// Do not allow direct access!
if ( ! \defined( 'ABSPATH' ) ) {
	die();
}

/**
 * Class Ionos_Help_Center_Manager
 */
class Manager {

	public function __construct() {
		// Construct JS to dynamically add help center links
		add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_help_center_resources' ) );
		add_action( 'admin_print_footer_scripts', array( $this, 'enqueue_help_center_page_script' ) );
		add_action( 'admin_head', array( $this, 'add_external_libraries' ) );

		// Add help center static links via hooks
		$this->create_help_center_links();
	}

	/**
	 * Load external resources from IONOS library
	 */
	public function add_external_libraries() {
		echo '<script src="https://ce1.uicdn.net/exos/framework/1.1/ionos.min.js" async="async"></script>';
		echo '<script src="https://frontend-services.ionos.com/t/tag/IONOS/community.js" async="async" defer="defer" id="oaotag" type="text/javascript"></script>';
	}

	/**
	 * Load internal resources
	 */
	public function enqueue_help_center_resources() {
		// Load scripts
		wp_enqueue_script( 'ionos-help-center-js', \Ionos\Help_Center\Helper::get_js_url( 'ionos-help-center.js' ), null, null, true );
		wp_localize_script( 'ionos-help-center-js', 'ionos', array(
			'market' => ( string ) strtolower( get_option( 'ionos_assistant_market', 'us' ) )
		) );

		// Load styles
		wp_enqueue_style( 'ionos-frontend-services-css', 'https://ce1.uicdn.net/exos/framework/1.1/ionos.min.css' );
		wp_enqueue_style( 'ionos-help-center-css', \Ionos\Help_Center\Helper::get_css_url( 'ionos-help-center.css' ), array( 'ionos-frontend-services-css' ) );
	}

	/**
	 * Build help article script & add to footer
	 */
	public function enqueue_help_center_page_script() {
		if ( get_option( 'ionos_help_center_enabled', '1' ) === '1' ) {
			$article_list = $this->get_current_page_help_center_articles();

			if ( count( $article_list ) ) {
				echo sprintf(
					'<script type="text/javascript">%s</script>',
					$this->get_article_integration_js_string( $article_list )
				);
			}
		}
	}

	/**
	 * Build static HTML links via configured hooks
	 */
	public function create_help_center_links() {
		if ( get_option( 'ionos_help_center_enabled', '1' ) === '1' ) {
			$article_list = \Ionos\Help_Center\Helper::get_all_article_parameters( 'hooks' );

			foreach ( $article_list as $hook => $article ) {
				$article_params = \Ionos\Help_Center\Helper::parse_article_properties( $article );
				$domain = \Ionos\Help_Center\Helper::get_config_parameter( $article_params['source'], 'domains' );

				add_filter( $hook, function ( $html ) use ( $article_params, $domain ) {
					return (
						$html . sprintf(
							'<a href="%s?id=%s" class="help-center-article-element exos-icon exos-icon-help-18 %s"></a>',
							__( $domain, 'ionos-help-center' ),
							$article_params['article_id'],
							$article_params['behavior']
						)
					);
				} );
			}
		}
	}

	/**
	 * Collect help information of current page
	 *
	 * @return array
	 */
	public function get_current_page_help_center_articles() {
		global $current_screen;
		$result_array = array();

		if ( ! isset( $current_screen ) ) {
			return array();
		}

		$all_articles = \Ionos\Help_Center\Helper::get_all_article_parameters( 'pages' );

		if ( isset( $all_articles[ $current_screen->id ] ) && ! is_array( $all_articles[ $current_screen->id ] ) ) {
			$article_groups = explode( '|', $all_articles[ $current_screen->id ] );

			foreach ( $article_groups as $article_key => $article_value ) {
				$result_array[ $article_key ] = \Ionos\Help_Center\Helper::parse_article_properties( $article_value );
			}
		}

		return $result_array;
	}

	/**
	 * Build help article script
	 *
	 * @param array $article_list
	 *
	 * @return string
	 */
	public function get_article_integration_js_string( array $article_list ) {
		foreach ( $article_list as $article ) {
			$domain = \Ionos\Help_Center\Helper::get_config_parameter( $article['source'], 'domains' );

			return sprintf(
				'create_help_center_link("%s","%s","%s","%s");',
				$article['article_id'],
				$article['behavior'],
				$article['html_tag'],
				__( $domain, 'ionos-help-center' )
			);
		}

		return '';
	}
}