<?php namespace ProcessWire;

/**
 * ProcessWire Entities Textformatter
 *
 * Formats text with PHP's htmlspecialchars() function.
 * 
 * ProcessWire 3.x, Copyright 2016 by Ryan Cramer
 * https://processwire.com
 *
 *
 */

class TextformatterEntities extends Textformatter {

	public static function getModuleInfo() {
		return array(
			'title' => __('HTML Entity Encoder (htmlspecialchars)', __FILE__), // Module Title
			'summary' => __("Entity encode ampersands, quotes (single and double) and greater-than/less-than signs using htmlspecialchars(str, ENT_QUOTES). It is recommended that you use this on all text/textarea fields except those using a rich text editor or a markup language like Markdown.", __FILE__), // Module Summary
			'version' => 100, 
		); 
	}

	public function format(&$str) {
		static $charset = false;
		if($charset === false) $charset = $this->config->dbCharset;
		if($charset == 'utf8') $str = htmlspecialchars($str, ENT_QUOTES, "UTF-8"); 
			else $str = htmlspecialchars($str, ENT_QUOTES); 
	}
}
