<?php

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}

global $wpdb;

// Plugin versions
$gigneo_version        = GIGNEO_VERSION;
$gigneo_pro_version    = gigneo_pro_is_active() ? GIGNEO_PRO_VERSION : 'N/A';
$wp_url                = get_bloginfo( 'wpurl' );
$site_url              = get_bloginfo( 'url' );
$wpi_version           = get_bloginfo( 'version' );
$is_multisite          = is_multisite() ? esc_html__( 'Yes', 'gigneo' ) : '&ndash;';
$language              = get_locale();
$memory_limit          = WP_MEMORY_LIMIT;
$debug_mode            = defined( 'WP_DEBUG' ) && WP_DEBUG;
$wp_cron               = ! defined( 'DISABLE_WP_CRON' ) || ! DISABLE_WP_CRON;
$external_object_cache = wp_using_ext_object_cache() ? '<mark class="yes"><span class="dashicons dashicons-yes"></span></mark>' : '<mark class="no">&ndash;</mark>';

// Server environment
$server_software     = isset( $_SERVER['SERVER_SOFTWARE'] ) ? sanitize_text_field( wp_unslash( $_SERVER['SERVER_SOFTWARE'] ?? '' ) ) : 'N/A';
$php_version         = phpversion();
$post_max_size       = ini_get( 'post_max_size' );
$time_limit          = ini_get( 'max_execution_time' );
$max_input_vars      = ini_get( 'max_input_vars' );
$curl_info           = function_exists( 'curl_version' ) ? curl_version() : false;
$curl_version        = $curl_info ? $curl_info['version'] . ', ' . $curl_info['ssl_version'] : 'N/A';
$suhosin_installed   = extension_loaded( 'suhosin' ) ? __( 'Yes', 'gigneo' ) : '&ndash;';
$mysql_version       = $wpdb->db_version();
$max_upload_size     = size_format( wp_max_upload_size() );
$timezone            = date_default_timezone_get() === 'UTC' ? '<mark class="yes"><span class="dashicons dashicons-yes"></span></mark>' : '<mark class="no">&ndash;</mark>';
$functions_available = array(
	'fsockopen'   => function_exists( 'fsockopen' ),
	'SoapClient'  => class_exists( 'SoapClient' ),
	'DOMDocument' => class_exists( 'DOMDocument' ),
	'gzopen'      => function_exists( 'gzopen' ),
	'mbstring'    => extension_loaded( 'mbstring' ),
	'RemotePost'  => wp_remote_post( home_url(), array( 'timeout' => 5 ) ) !== new WP_Error(),
	'RemoteGet'   => wp_remote_get( home_url(), array( 'timeout' => 5 ) ) !== new WP_Error(),
);
?>
<table class="gn_status_table widefat" id="gn_status">
	<thead>
	<tr>
		<th colspan="3"><h2><?php echo esc_attr__( 'WordPress environment', 'gigneo' ); ?></h2></th>
	</tr>
	</thead>
	<tbody>
	<tr>
		<td><?php echo esc_attr__( 'WordPress address (URL):', 'gigneo' ); ?></td>
		<td class="help"><span class="gn-help-tip" tabindex="0" aria-label="<?php echo esc_attr__( 'The root URL of your site.', 'gigneo' ); ?>"></span></td>
		<td><?php echo esc_url( $wp_url ); ?></td>
	</tr>
	<tr>
		<td><?php echo esc_attr__( 'Site address (URL):', 'gigneo' ); ?></td>
		<td class="help"><span class="gn-help-tip" tabindex="0" aria-label="<?php echo esc_attr__( 'The homepage URL of your site.', 'gigneo' ); ?>"></span></td>
		<td><?php echo esc_url( $site_url ); ?></td>
	</tr>
	<tr>
		<td><?php echo esc_attr__( 'Gigneo version:', 'gigneo' ); ?></td>
		<td class="help"><span class="gn-help-tip" tabindex="0" aria-label="<?php echo esc_attr__( 'The version of the Gigneo plugin.', 'gigneo' ); ?>"></span></td>
		<td><?php echo esc_html( $gigneo_version ); ?></td>
	</tr>
	<tr>
		<td><?php echo esc_attr__( 'Gigneo - Pro version:', 'gigneo' ); ?></td>
		<td class="help"><span class="gn-help-tip" tabindex="0" aria-label="<?php echo esc_attr__( 'Number of active modules of Gigneo plugin.', 'gigneo' ); ?>"></span></td>
		<td><?php echo esc_html( $gigneo_pro_version ); ?></td>
	</tr>
	<tr>
		<td><?php echo esc_attr__( 'Gigneo active modules:', 'gigneo' ); ?></td>
		<td class="help"><span class="gn-help-tip" tabindex="0" aria-label="<?php echo esc_attr__( 'The version of the Gigneo Pro plugin.', 'gigneo' ); ?>"></span></td>
		<td><?php echo esc_html( count( \Gigneo\Modules::active_modules() ) ); ?></td>
	</tr>
	<tr>
		<td><?php echo esc_attr__( 'WordPress version:', 'gigneo' ); ?></td>
		<td class="help"><span class="gn-help-tip" tabindex="0" aria-label="<?php echo esc_attr__( 'The version of WordPress installed on your site.', 'gigneo' ); ?>"></span></td>
		<td><mark class="yes"><?php echo esc_html( $wpi_version ); ?></mark></td>
	</tr>
	<tr>
		<td><?php echo esc_attr__( 'WordPress multisite:', 'gigneo' ); ?></td>
		<td class="help"><span class="gn-help-tip" tabindex="0" aria-label="<?php echo esc_attr__( 'Whether or not you have WordPress Multisite enabled.', 'gigneo' ); ?>"></span></td>
		<td><?php echo esc_html( $is_multisite ); ?></td>
	</tr>
	<tr>
		<td><?php echo esc_attr__( 'WordPress memory limit:', 'gigneo' ); ?></td>
		<td class="help"><span class="gn-help-tip" tabindex="0" aria-label="<?php echo esc_attr__( 'The maximum amount of memory (RAM) that your site can use at one time.', 'gigneo' ); ?>"></span></td>
		<td>
			<mark class="<?php echo ( intval( $memory_limit ) < 64 ) ? 'error' : 'yes'; ?>">
				<?php echo esc_html( $memory_limit ); ?>
				<?php if ( intval( $memory_limit ) < 64 ) : ?>
					- <?php echo esc_attr__( 'Required 64MB', 'gigneo' ); ?>
				<?php endif; ?>
			</mark>
		</td>
	</tr>
	<tr>
		<td><?php echo esc_attr__( 'WordPress debug mode:', 'gigneo' ); ?></td>
		<td class="help"><span class="gn-help-tip" tabindex="0" aria-label="<?php echo esc_attr__( 'Displays whether or not WordPress is in Debug Mode.', 'gigneo' ); ?>"></span></td>
		<td><mark class="<?php echo $debug_mode ? 'yes' : 'no'; ?>"><span class="dashicons dashicons-<?php echo $debug_mode ? 'yes' : 'no'; ?>"></span></mark></td>
	</tr>
	<tr>
		<td><?php echo esc_attr__( 'WordPress cron:', 'gigneo' ); ?></td>
		<td class="help"><span class="gn-help-tip" tabindex="0" aria-label="<?php echo esc_attr__( 'Displays whether or not WP Cron Jobs are enabled.', 'gigneo' ); ?>"></span></td>
		<td><mark class="<?php echo $wp_cron ? 'yes' : 'no'; ?>"><span class="dashicons dashicons-<?php echo $wp_cron ? 'yes' : 'no'; ?>"></span></mark></td>
	</tr>
	<tr>
		<td><?php echo esc_attr__( 'Language:', 'gigneo' ); ?></td>
		<td class="help"><span class="gn-help-tip" tabindex="0" aria-label="<?php echo esc_attr__( 'The current language used by WordPress. Default = English', 'gigneo' ); ?>"></span></td>
		<td><?php echo esc_html( $language ); ?></td>
	</tr>
	<tr>
		<td><?php echo esc_attr__( 'External object cache:', 'gigneo' ); ?></td>
		<td class="help"><span class="gn-help-tip" tabindex="0" aria-label="<?php echo esc_attr__( 'Displays whether or not WordPress is using an external object cache.', 'gigneo' ); ?>"></span></td>
		<td><?php echo wp_kses_post( $external_object_cache ); ?></td>
	</tr>
	</tbody>
</table>

<table class="gn_status_table widefat" id="gn_status_server">
	<thead>
	<tr>
		<th colspan="3"><h2><?php echo esc_attr__( 'Server environment', 'gigneo' ); ?></h2></th>
	</tr>
	</thead>
	<tbody>
	<tr>
		<td><?php echo esc_attr__( 'Server info:', 'gigneo' ); ?></td>
		<td class="help"><span class="gn-help-tip" tabindex="0" aria-label="<?php echo esc_attr__( 'Information about the web server that is currently hosting your site.', 'gigneo' ); ?>"></span></td>
		<td><?php echo esc_html( $server_software ); ?></td>
	</tr>
	<tr>
		<td><?php echo esc_attr__( 'PHP version:', 'gigneo' ); ?></td>
		<td class="help"><span class="gn-help-tip" tabindex="0" aria-label="<?php echo esc_attr__( 'The version of PHP installed on your hosting server.', 'gigneo' ); ?>"></span></td>
		<td><mark class="yes"><?php echo esc_html( $php_version ); ?></mark></td>
	</tr>
	<tr>
		<td><?php echo esc_attr__( 'PHP post max size:', 'gigneo' ); ?></td>
		<td class="help"><span class="gn-help-tip" tabindex="0" aria-label="<?php echo esc_attr__( 'The largest size of a POST request allowed.', 'gigneo' ); ?>"></span></td>
		<td><?php echo esc_html( $post_max_size ); ?></td>
	</tr>
	<tr>
		<td><?php echo esc_attr__( 'PHP max execution time:', 'gigneo' ); ?></td>
		<td class="help"><span class="gn-help-tip" tabindex="0" aria-label="<?php echo esc_attr__( 'The amount of time (in seconds) PHP scripts are allowed to run.', 'gigneo' ); ?>"></span></td>
		<td><?php echo esc_html( $time_limit ); ?>s</td>
	</tr>
	<tr>
		<td><?php echo esc_attr__( 'PHP max input variables:', 'gigneo' ); ?></td>
		<td class="help"><span class="gn-help-tip" tabindex="0" aria-label="<?php echo esc_attr__( 'The maximum number of input variables allowed per request.', 'gigneo' ); ?>"></span></td>
		<td><?php echo esc_html( $max_input_vars ); ?></td>
	</tr>
	<tr>
		<td><?php echo esc_attr__( 'cURL version:', 'gigneo' ); ?></td>
		<td class="help"><span class="gn-help-tip" tabindex="0" aria-label="<?php echo esc_attr__( 'The version of cURL installed on your server.', 'gigneo' ); ?>"></span></td>
		<td><?php echo esc_html( $curl_version ); ?></td>
	</tr>
	<tr>
		<td><?php echo esc_attr__( 'SUHOSIN installed:', 'gigneo' ); ?></td>
		<td class="help"><span class="gn-help-tip" tabindex="0" aria-label="<?php echo esc_attr__( 'SUHOSIN is an advanced protection system for PHP installations.', 'gigneo' ); ?>"></span></td>
		<td><?php echo esc_html( $suhosin_installed ); ?></td>
	</tr>
	<tr>
		<td><?php echo esc_attr__( 'MySQL version:', 'gigneo' ); ?></td>
		<td class="help"><span class="gn-help-tip" tabindex="0" aria-label="<?php echo esc_attr__( 'The version of MySQL installed on your hosting server.', 'gigneo' ); ?>"></span></td>
		<td><?php echo esc_html( $mysql_version ); ?></td>
	</tr>
	<tr>
		<td><?php echo esc_attr__( 'Max upload size:', 'gigneo' ); ?></td>
		<td class="help"><span class="gn-help-tip" tabindex="0" aria-label="<?php echo esc_attr__( 'The largest file size that can be uploaded.', 'gigneo' ); ?>"></span></td>
		<td><?php echo esc_html( $max_upload_size ); ?></td>
	</tr>
	<tr>
		<td><?php echo esc_attr__( 'Default timezone is UTC:', 'gigneo' ); ?></td>
		<td class="help"><span class="gn-help-tip" tabindex="0" aria-label="<?php echo esc_attr__( 'Whether the server is using UTC as the default timezone.', 'gigneo' ); ?>"></span></td>
		<td><?php echo wp_kses_post( $timezone ); ?></td>
	</tr>
	<?php foreach ( $functions_available as $func => $is_available ) : ?>
		<tr>
			<td><?php echo esc_html( ucfirst( $func ) ); ?>:</td>
			<td class="help"><span class="gn-help-tip" tabindex="0" aria-label="
			<?php
			echo esc_attr(
				sprintf(
					// translators: %s: status available on server
					esc_html__( 'Whether %s is available on this server.', 'gigneo' ),
					ucfirst( $func )
				)
			);
			?>
			"></span></td>
			<td>
				<mark class="<?php echo esc_attr( $is_available ? 'yes' : 'no' ); ?>">
					<span class="dashicons dashicons-<?php echo esc_attr( $is_available ? 'yes' : 'no' ); ?>"></span>
				</mark>
			</td>
		</tr>
	<?php endforeach; ?>
	</tbody>
</table>

<table class="gn_status_table widefat">
	<thead>
	<tr>
		<th colspan="3"><h2><?php echo esc_html__( 'Gigneo pages', 'gigneo' ); ?></h2></th>
	</tr>
	</thead>
	<tbody>
	<?php
	$gigneo_pages = array(
		'dashboard'           => array(
			'title' => esc_html__( 'Dashboard', 'gigneo' ),
			'id'    => gigneo_option( '_gigneo_ts_template_dashboard' ),
			'desc'  => esc_html__( 'Platform dashboard page', 'gigneo' ),
		),
		'hire'                => array(
			'title' => esc_html__( 'Hire', 'gigneo' ),
			'id'    => gigneo_option( '_gigneo_ts_template_hire' ),
			'desc'  => esc_html__( 'Platform hire page', 'gigneo' ),
		),
		'privacy_policy'      => array(
			'title' => esc_html__( 'Privacy Policy', 'gigneo' ),
			'id'    => gigneo_option( '_gigneo_ts_template_privacy_policy' ),
			'desc'  => esc_html__( 'Privacy policy', 'gigneo' ),
		),
		'terms_and_condition' => array(
			'title' => esc_html__( 'Terms and Condition', 'gigneo' ),
			'id'    => gigneo_option( '_gigneo_ts_template_terms_and_condition' ),
			'desc'  => esc_html__( 'Terms and condition page', 'gigneo' ),
		),
		'login'               => array(
			'title'     => esc_html__( 'Login', 'gigneo' ),
			'id'        => gigneo_option( '_gigneo_ts_template_login' ),
			'desc'      => esc_html__( 'Login page', 'gigneo' ),
			'shortcode' => '[gigneo_login]',
		),
		'register'            => array(
			'title'     => esc_html__( 'Register', 'gigneo' ),
			'id'        => gigneo_option( '_gigneo_ts_template_register' ),
			'desc'      => esc_html__( 'Register page', 'gigneo' ),
			'shortcode' => '[gigneo_register]',
		),
		'forgot_password'     => array(
			'title'     => esc_html__( 'Forgot Password', 'gigneo' ),
			'id'        => gigneo_option( '_gigneo_ts_template_forgot_password' ),
			'desc'      => esc_html__( 'Forgot password page', 'gigneo' ),
			'shortcode' => '[gigneo_forgot_password]',
		),
		'freelancer_archive'  => array(
			'title'     => esc_html__( 'Freelancer Archive', 'gigneo' ),
			'id'        => gigneo_option( '_gigneo_ts_template_freelancers' ),
			'desc'      => esc_html__( 'Freelancer archive page', 'gigneo' ),
			'shortcode' => '[gigneo_freelancers]',
		),
		'service_archive'     => array(
			'title'     => esc_html__( 'Service Archive', 'gigneo' ),
			'id'        => gigneo_option( '_gigneo_ts_template_services' ),
			'desc'      => esc_html__( 'Service archive page', 'gigneo' ),
			'shortcode' => '[gigneo_services]',
		),
		'employer_archive'    => array(
			'title'     => esc_html__( 'Employer Archive', 'gigneo' ),
			'id'        => gigneo_option( '_gigneo_ts_template_employers' ),
			'desc'      => esc_html__( 'Employer archive page', 'gigneo' ),
			'shortcode' => '[gigneo_employers]',
		),
		'job_archive'         => array(
			'title'     => esc_html__( 'Job Archive', 'gigneo' ),
			'id'        => gigneo_option( '_gigneo_ts_template_jobs' ),
			'desc'      => esc_html__( 'Job archive page', 'gigneo' ),
			'shortcode' => '[gigneo_jobs]',
		),
	);

	foreach ( $gigneo_pages as $gn_slug => $gn_page ) :
		$gn_page_title = $gn_page['title'];
		$gn_page_id    = $gn_page['id'];
		$gn_page_desc  = $gn_page['desc'];
		$gn_page_url   = $gn_page_id ? get_permalink( $gn_page_id ) : '';
		$shortcode     = isset( $gn_page['shortcode'] ) ?? $gn_page['shortcode'];
		?>
		<tr>
			<td><?php echo esc_html( $gn_page_title ); ?>:</td>
			<td class="help"><span class="gn-help-tip" tabindex="0" aria-label="<?php echo esc_attr( $gn_page_desc ); ?>"></span></td>
			<td>
				<?php if ( $gn_page_id && $gn_page_url ) : ?>
					<mark class="yes">
						<a href="<?php echo esc_url( $gn_page_url ); ?>" target="_blank"><?php echo esc_html( get_the_title( $gn_page_id ) ); ?></a>
						<?php
						if ( ! empty( $shortcode ) ) :
							?>
							<span class="gn_shortcode"> -
							<?php
							printf(
								// translators: %s is a shortcode.
								esc_html__( 'Page must contain the %s shortcode.', 'gigneo' ),
								esc_attr( $shortcode )
							);
							?>
							</span>
						<?php endif; ?>
					</mark>
				<?php else : ?>
					<mark class="error"><?php echo esc_attr__( 'Page not set.', 'gigneo' ); ?></mark>
				<?php endif; ?>
			</td>
		</tr>
	<?php endforeach; ?>
	
	</tbody>
</table>

<table class="gn_status_table widefat">
	<thead>
	<tr>
		<th colspan="3"><h2><?php echo esc_html__( 'Gigneo products', 'gigneo' ); ?></h2></th>
	</tr>
	</thead>
	<tbody>
	<?php
	$gigneo_products = array(
		'wallet'     => array(
			'title' => esc_html__( 'Wallet funds', 'gigneo' ),
			'id'    => gigneo_option( '_gigneo_ts_wallet_product' ),
			'desc'  => esc_html__( 'Product to add funds in wallet.', 'gigneo' ),
		),
		'withdrawal' => array(
			'title' => esc_html__( 'Withdrawal', 'gigneo' ),
			'id'    => gigneo_option( '_gigneo_ts_withdrawal_product' ),
			'desc'  => esc_html__( 'Product for users withdrawals.', 'gigneo' ),
		),
	);

	foreach ( $gigneo_products as $gn_slug => $gn_product ) :
		$gn_product_title = $gn_product['title'];
		$gn_product_id    = gigneo_option( "_gigneo_ts_{$gn_slug}_product" );
		$gn_product_desc  = $gn_product['desc'];
		$gn_product_url   = $gn_product_id ? get_permalink( $gn_product_id ) : '';
		?>
		<tr>
			<td><?php echo esc_html( $gn_product_title ); ?>:</td>
			<td class="help"><span class="gn-help-tip" tabindex="0" aria-label="<?php echo esc_attr( $gn_product_desc ); ?>"></span></td>
			<td>
				<?php if ( $gn_product_id && $gn_product_url ) : ?>
					<mark class="yes">
						<a href="<?php echo esc_url( $gn_product_url ); ?>" target="_blank"><?php echo esc_html( get_the_title( $gn_product_id ) ); ?></a>
					</mark>
				<?php else : ?>
					<mark class="error"><?php echo esc_attr__( 'Product not set.', 'gigneo' ); ?></mark>
				<?php endif; ?>
			</td>
		</tr>
	<?php endforeach; ?>

	</tbody>
</table>

<table class="gn_status_table widefat">
	<thead>
	<tr>
		<th colspan="3"><h2><?php echo esc_html__( 'Gigneo shortcodes', 'gigneo' ); ?></h2></th>
	</tr>
	</thead>
	<tbody>
	<?php
	$gigneo_shortcodes = array(
		'login'           => array(
			'title'     => esc_html__( 'Login', 'gigneo' ),
			'shortcode' => '[gigneo_login]',
			'desc'      => esc_html__( 'Login form shortcode', 'gigneo' ),
			'params'    => '',
		),
		'register'        => array(
			'title'     => esc_html__( 'Register', 'gigneo' ),
			'shortcode' => '[gigneo_register]',
			'desc'      => esc_html__( 'Register form shortcode', 'gigneo' ),
			'params'    => '',
		),
		'forgot_password' => array(
			'title'     => esc_html__( 'Forgot Password', 'gigneo' ),
			'shortcode' => '[gigneo_forgot_password]',
			'desc'      => esc_html__( 'Forgot/Change password form shortcode', 'gigneo' ),
			'params'    => '',
		),
		'freelancers'     => array(
			'title'     => esc_html__( 'Freelancers', 'gigneo' ),
			'shortcode' => '[gigneo_freelancers]',
			'desc'      => esc_html__( 'Freelancer listings shortcode', 'gigneo' ),
			'params'    => 'layout,per_page',
		),
		'services'        => array(
			'title'     => esc_html__( 'Services', 'gigneo' ),
			'desc'      => esc_html__( 'Service listings shortcode', 'gigneo' ),
			'shortcode' => '[gigneo_services]',
			'params'    => 'layout,per_page',
		),
		'jobs'            => array(
			'title'     => esc_html__( 'Jobs', 'gigneo' ),
			'desc'      => esc_html__( 'Job listings shortcode', 'gigneo' ),
			'shortcode' => '[gigneo_jobs]',
			'params'    => 'layout,per_page',
		),
		'employers'       => array(
			'title'     => esc_html__( 'Employers', 'gigneo' ),
			'desc'      => esc_html__( 'Employer listings shortcode', 'gigneo' ),
			'shortcode' => '[gigneo_employers]',
			'params'    => 'layout,per_page',
		),
		'hired'           => array(
			'title'     => esc_html__( 'Hire', 'gigneo' ),
			'desc'      => esc_html__( 'Hiring checkout shortcode', 'gigneo' ),
			'shortcode' => '[gigneo_employers]',
			'params'    => '',
		),
	);

	foreach ( $gigneo_shortcodes as $slug => $shortcode_data ) :
		?>
		<tr>
			<td><?php echo esc_html( $shortcode_data['title'] ); ?>:</td>
			<td class="help">
				<span class="gn-help-tip" tabindex="0" aria-label="
				<?php
				printf(
					// translators: 1: Description, 2: Parameters
					esc_attr__( '%1$s Params: %2$s', 'gigneo' ),
					esc_html( $shortcode_data['desc'] ),
					esc_html( $shortcode_data['params'] )
				);
				?>
				"></span>
			</td>
			<td>
				<code><?php echo esc_html( $shortcode_data['shortcode'] ); ?></code>
				<?php if ( ! empty( $shortcode_data['params'] ) ) : ?>
				<?php endif; ?>
			</td>
		</tr>
	<?php endforeach; ?>
	</tbody>
</table>