public function clean_text()

in admin/AmazonAI-Common.php [1498:1564]


	public function clean_text($post_id, $with_title, $only_title)
	{

		#$this->logger->log(sprintf('%s Cleaning text (%s, %s) ', __METHOD__, $with_title, $only_title));

		$clean_text = '';

		// Depending on the plugin configurations, post's title will be added to the audio.
		if ($with_title) {
			if ($this->is_title_adder_enabled()) {
				$clean_text = get_the_title($post_id) . '. **AMAZONPOLLY*SSML*BREAK*time=***1s***SSML** ';
			}
		}


		// Depending on the plugin configurations, post's excerpt will be added to the audio.

		if ($this->is_excerpt_adder_enabled()) {
			$my_excerpt = apply_filters('the_excerpt', get_post_field('post_excerpt', $post_id));
			$clean_text = $clean_text . $my_excerpt . ' **AMAZONPOLLY*SSML*BREAK*time=***1s***SSML** ';
		}

		$clean_text = $clean_text . get_post_field('post_content', $post_id);
		$clean_text = apply_filters('amazon_polly_content', $clean_text);

		if ($only_title) {
			$clean_text = get_the_title($post_id);
		}

		$clean_text = str_replace(' ', ' ', $clean_text);
		$clean_text = do_shortcode($clean_text);

		$clean_text = $this->skip_tags($clean_text);
		$clean_text = $this->add_pauses($clean_text);

		$is_ssml_enabled = $this->is_ssml_enabled();
		if ($is_ssml_enabled) {
			$clean_text = $this->encode_ssml_tags($clean_text);
		}

		// Creating text description for images
		$clean_text = $this->replace_images($clean_text);
		$clean_text = strip_tags($clean_text, '<break>');
		$clean_text = esc_html($clean_text);


		$clean_text = str_replace('&nbsp;', ' ', $clean_text);
		$clean_text = preg_replace("/https:\/\/([^\s]+)/", "", $clean_text);
		$clean_text_temp = '';

		$paragraphs = explode("\n", $clean_text);
		foreach($paragraphs as $paragraph) {
			$paragraph_size = strlen(trim($paragraph));
			if ($paragraph_size > 0) {
				$clean_text_temp = $clean_text_temp . "\n" . $paragraph;
			}
		}

		$clean_text = $clean_text_temp;
		$clean_text = html_entity_decode($clean_text, ENT_QUOTES, 'UTF-8');
		$clean_text = str_replace('&', ' and ', $clean_text);
		$clean_text = str_replace('<', ' ', $clean_text);
		$clean_text = str_replace('>', ' ', $clean_text);


		return $clean_text;
	}