<?php

namespace SovereignStack\SecuritySafe;

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

/**
 * Class AdminPageContent
 *
 * @package SecuritySafe
 * @since   0.2.0
 */
class AdminPageContent extends AdminPage {

	/**
	 * This tab displays file settings.
	 *
	 * @since  0.2.0
	 */
	function tab_settings() {

		$html = '';

		// Shutoff Switch - All Content Policies
		$classes = ( $this->page_settings['on'] ) ? '' : 'notice-warning';

		$rows = $this->form_select( $this->page_settings, __( 'Content Policies', 'security-safe' ), 'on', [
				'0' => __( 'Disabled', 'security-safe' ),
				'1' => __( 'Enabled', 'security-safe' ),
			], __( 'If you experience a problem, you may want to temporarily turn off all content policies at once to troubleshoot the issue. Be sure to clear your cache as well.', 'security-safe' ), $classes );

		$html .= $this->form_table( $rows );

		// Copyright Protection
		$html .= $this->form_section( __( 'Copyright Protection', 'security-safe' ), __( 'Copyright protection is meant to deter the majority of users from copying your content. These settings do not affect the admin area.', 'security-safe' ) );

		$rows = $this->form_checkbox( $this->page_settings, __( 'Highlight Text', 'security-safe' ), 'disable_text_highlight', __( 'Disable Text Highlighting', 'security-safe' ), __( 'Prevent users from highlighting your content text.', 'security-safe' ) );

		$rows .= $this->form_checkbox( $this->page_settings, __( 'Right-Click', 'security-safe' ), 'disable_right_click', __( 'Disable Right-Click', 'security-safe' ), __( 'Prevent users from right-clicking on your site to save images or copy text.', 'security-safe' ) );

		$html .= $this->form_table( $rows );

		// Password Protection
		$html .= $this->form_section( __( 'Password Protected Content', 'security-safe' ), __( 'Sometimes, it is necessary to password protect content for special access without requiring a user to log in. The settings below enhance this WordPress feature.', 'security-safe' ) );

		$rows = $this->form_checkbox( $this->page_settings, __( 'Hide Posts', 'security-safe' ), 'hide_password_protected_posts', __( 'Hide All Protected Posts', 'security-safe' ), __( 'Prevent password protected content from being listed in the blog, search results, and any other public areas. (only affects the loop)', 'security-safe' ) );

		$html .= $this->form_table( $rows );

		// @todo need to convert to esc_html__() but it would break the <b> tags. Need to change this.
		$html .= '<p>' . esc_html__( '<b>NOTICE:</b> Be sure to clear your cache after changing these settings.', 'security-safe' ) . '</p>';

		// Save Button
		$html .= $this->button( __( 'Save Settings', 'security-safe' ) );

		return $html;
	}

	/**
	 * This tab displays the 404 error log.
	 *
	 * @since  2.0.0
	 */
	function tab_404s() {

		require_once( SECSAFE_DIR_ADMIN_TABLES . '/Table404s.php' );

		ob_start();

		$table = new Table404s();
		$table->prepare_items();
		$table->display_charts();
		$table->search_box( __( 'Search 404s', 'security-safe' ), 'log' );
		$table->display();

		return ob_get_clean();
	}

	/**
	 * This sets the variables for the page.
	 *
	 * @since  0.1.0
	 */
	protected function set_page() {

		$this->slug = SECSAFE_SLUG . '-content';

		$this->title = __( 'Content Protection', 'security-safe' );
		$this->description = __( 'Deter visitors from stealing your content.', 'security-safe' );

		$this->tabs[] = [
			'id' => '404s',
			'label' => __( '404 Errors', 'security-safe' ),
			'title' => __( '404 Error Log', 'security-safe' ),
			'heading' => false,
			'intro' => false,
			'classes' => [ 'full' ],
			'content_callback' => 'tab_404s',
		];

		$this->tabs[] = [
			'id' => 'settings',
			'label' => __( 'Settings', 'security-safe' ),
			'title' => __( 'Content Settings', 'security-safe' ),
			'heading' => false,
			'intro' => false,
			'content_callback' => 'tab_settings',
		];
	}
}
