HEX
Server: nginx/1.26.1
System: Linux 850a3e23ecee 5.15.0-122-generic #132-Ubuntu SMP Thu Aug 29 13:45:52 UTC 2024 x86_64
User: (1000)
PHP: 8.2.27
Disabled: NONE
Upload Files
File: /var/www/html/wp-content/plugins/fixed-toc/frontend/data/class-datum-origin-title.php
<?php
/**
 * Generate an original title datum
 *
 * @since 3.0.0
 *
 * @see Fixedtoc_Datum
 */

class Fixedtoc_Datum_Origin_Title extends Fixedtoc_Datum {

	private $excludes;

	/**
	 * @since 3.0.0
	 */
	public function set_name() {
		$this->name = 'origin_title';
	}

	/**
	 * @since 3.0.0
	 *
	 * @param Fixedtoc_Data $obj_data
	 */
	public function set_value( Fixedtoc_Data $obj_data ) {
		$title       = trim( strip_tags( $obj_data->get_match() ) );
		$this->value = $this->filter_title( $title );
	}

	/**
	 * Filter title.
	 *
	 * @since 3.0.0
	 * @access private
	 *
	 * @param string $title
	 *
	 * @return string
	 */
	private function filter_title( $title ) {
		if ( empty( $title ) ) {
			return '';
		}

		if ( is_null( $this->excludes ) ) {
			$exclude = trim( fixedtoc_get_option( 'general_exclude_keywords' ) );
			$exclude .= "\n" . trim( fixedtoc_get_meta( 'general_exclude_keywords' ) );
			if ( empty( $exclude ) ) {
				return $title;
			}

			$exclude .= "\n" . wptexturize( htmlentities($exclude, ENT_NOQUOTES)  );

			$excludes       = explode( "\n", $exclude );
			$excludes       = array_map( array( $this, 'sanitize_keyword' ), $excludes );
			$excludes       = array_filter( $excludes );
			$this->excludes = $excludes;
		}

		if ( $this->excludes && in_array( $title, $this->excludes ) ) {
			return '';
		}

		return $title;

	}

	public function sanitize_keyword( $keyword ) {
		return trim( $keyword );
	}

}