diff --git a/includes/class-tika-doc-pdf-indexer-functions.php b/includes/class-tika-doc-pdf-indexer-functions.php index 4a711a8..9646499 100644 --- a/includes/class-tika-doc-pdf-indexer-functions.php +++ b/includes/class-tika-doc-pdf-indexer-functions.php @@ -102,13 +102,13 @@ function tdpi_restrict_mimetypes( $mimes ) { $allowed_array = array(); if ( in_array( 'pdf', $allowed, true ) ) { - $allowed_array['pdf'] = 'application/pdf'; + $allowed_array['pdf'] = array( 'application/pdf' ); } if ( in_array( 'txt', $allowed, true ) ) { - $allowed_array['txt'] = 'text/plain'; + $allowed_array['txt'] = array( 'text/plain' ); } if ( in_array( 'doc', $allowed, true ) ) { - $allowed_array['doc'] = 'application/msword'; + $allowed_array['doc'] = array( 'application/msword' ); } global $post_type; if ( 'tdpi_doc' === $post_type ) { @@ -280,3 +280,4 @@ function tdpi_save_tika_meta( $post_id, $post ) { // on upload existing file, attach data. // make the upload file required // default to upload and restric from selcting uploaded file or the recent file should be indexed. +// Settings should file checks if correct or existing.. diff --git a/includes/class-tika-doc-pdf-indexer-settings.php b/includes/class-tika-doc-pdf-indexer-settings.php index 428d4c3..4fd9ce7 100644 --- a/includes/class-tika-doc-pdf-indexer-settings.php +++ b/includes/class-tika-doc-pdf-indexer-settings.php @@ -50,6 +50,91 @@ class Tika_Doc_PDF_Indexer_Settings { */ public $settings = array(); + /** + * Allowed html. + * + * @var array + */ + public $allowed_htmls_form = [ + 'a' => [ + 'href' => [], + 'title' => [], + ], + 'input' => [ + 'id' => [], + 'type' => [], + 'name' => [], + 'placeholder' => [], + 'value' => [], + 'class' => [], + ], + 'select' => [ + 'id' => [], + 'type' => [], + 'name' => [], + 'placeholder' => [], + 'value' => [], + 'multiple' => [], + ], + 'option' => [ + 'id' => [], + 'type' => [], + 'name' => [], + 'placeholder' => [], + 'value' => [], + 'multiple' => [], + 'selected' => [], + ], + 'label' => [ + 'for' => [], + 'title' => [], + ], + 'span' => [ + 'class' => [], + 'title' => [], + ], + 'div' => [ + 'class' => [], + 'id' => [], + ], + 'table' => [ + 'scope' => [], + 'title' => [], + 'class' => [], + 'role' => [], + ], + 'tbody' => [ + 'scope' => [], + 'title' => [], + 'class' => [], + 'role' => [], + ], + 'th' => [ + 'scope' => [], + 'title' => [], + ], + 'tr' => [], + 'td' => [], + 'p' => [], + 'br' => [], + 'h2' => [], + 'em' => [], + 'strong' => [], + 'th' => [], + 'form' => [ + 'method' => [], + 'type' => [], + 'name' => [], + 'placeholder' => [], + 'value' => [], + 'multiple' => [], + 'selected' => [], + 'action' => [], + 'enctype' => [], + ], + + ]; + /** * Constructor function. * @@ -195,17 +280,7 @@ public function register_settings() { if ( is_array( $this->settings ) ) { // Check posted/selected tab. - //phpcs:disable $current_section = ''; - if ( isset( $_POST['tab'] ) && $_POST['tab'] ) { - $current_section = $_POST['tab']; - } else { - if ( isset( $_GET['tab'] ) && $_GET['tab'] ) { - $current_section = $_GET['tab']; - } - } - //phpcs:enable - foreach ( $this->settings as $section => $data ) { if ( $current_section && $current_section !== $section ) { @@ -256,8 +331,8 @@ public function register_settings() { * @return void */ public function settings_section( $section ) { - $html = '
' . $this->settings[ $section['id'] ]['description'] . '
' . "\n"; - echo $html; //phpcs:ignore + $html = $this->settings[ $section['id'] ]['description'] . "\n"; + echo esc_html( $html ); } /** @@ -288,7 +363,7 @@ public function settings_page() { $html .= '' . "\n"; $html .= '' . "\n"; - echo $html; //phpcs:ignore + echo wp_kses( $html, $this->allowed_htmls_form ); } /** diff --git a/includes/class-tika-doc-pdf-indexer.php b/includes/class-tika-doc-pdf-indexer.php index 8b84d43..4a86d13 100644 --- a/includes/class-tika-doc-pdf-indexer.php +++ b/includes/class-tika-doc-pdf-indexer.php @@ -272,20 +272,25 @@ private function _log_version_number() { //phpcs:ignore update_option( $this->_token . '_version', $this->_version ); } // End _log_version_number () + /** + * Register document post type. + * + * @return void + */ public function register_doc_postype() { - $options = array( + $options = array( 'menu_icon' => 'dashicons-media-document', 'supports' => array( 'title', 'thumbnail' ), ); $description = ''; $this->register_post_type( - 'tdpi_doc', - __( 'Documents', 'tika-doc-pdf-indexer' ), + 'tdpi_doc', + __( 'Documents', 'tika-doc-pdf-indexer' ), __( 'Document', 'tika-doc-pdf-indexer' ), $description, $options - ); + ); } /** @@ -315,7 +320,6 @@ public function __construct( $file = '', $version = '1.0.0' ) { // Load admin JS & CSS. add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ), 10, 1 ); add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_styles' ), 10, 1 ); - // Load API for generic admin functions. if ( is_admin() ) { diff --git a/includes/lib/class-tika-doc-pdf-indexer-admin-api.php b/includes/lib/class-tika-doc-pdf-indexer-admin-api.php index 3cb87fa..da92175 100644 --- a/includes/lib/class-tika-doc-pdf-indexer-admin-api.php +++ b/includes/lib/class-tika-doc-pdf-indexer-admin-api.php @@ -21,6 +21,54 @@ public function __construct() { add_action( 'save_post', array( $this, 'save_meta_boxes' ), 10, 1 ); } + /** + * Allowed html. + * + * @var array + */ + public $allowed_htmls = [ + 'a' => [ + 'href' => [], + 'title' => [], + ], + 'input' => [ + 'id' => [], + 'type' => [], + 'name' => [], + 'placeholder' => [], + 'value' => [], + ], + 'select' => [ + 'id' => [], + 'type' => [], + 'name' => [], + 'placeholder' => [], + 'value' => [], + 'multiple' => [], + ], + 'option' => [ + 'id' => [], + 'type' => [], + 'name' => [], + 'placeholder' => [], + 'value' => [], + 'multiple' => [], + 'selected' => [], + ], + 'label' => [ + 'for' => [], + 'title' => [], + ], + 'span' => [ + 'class' => [], + 'title' => [], + ], + 'br' => [], + 'em' => [], + 'strong' => [], + + ]; + /** * Generate HTML for displaying fields. * @@ -171,16 +219,6 @@ public function display_field( $data = array(), $post = false, $echo = true ) { $html .= '