<?php
/**
 * ###############################################
 *
 * SWIFT Framework
 * _______________________________________________
 *
 * @author		Varun Shoor
 *
 * @package		SWIFT
 * @copyright	Copyright (c) 2001-2012, Kayako
 * @license		http://www.kayako.com/license
 * @link		http://www.kayako.com
 *
 * ###############################################
 */

require_once './' . SWIFT_BASE_DIRECTORY . '/' . SWIFT_THIRDPARTY_DIRECTORY . '/HTMLPurifier/HTMLPurifier.standalone.php';

/**
 * The HTML Purifier Wrapper Class
 *
 * @author Varun Shoor
 */
class SWIFT_HTMLPurifier extends SWIFT_Library {
	protected $HTMLPurifierConfig = false;
	protected $HTMLPurifier = false;

	/**
	 * Constructor
	 *
	 * @author Varun Shoor
	 * @return bool "true" on Success, "false" otherwise
	 */
	public function __construct() {
		parent::__construct();

	    $this->HTMLPurifierConfig = HTMLPurifier_Config::createDefault();

		$this->HTMLPurifierConfig->set('Cache.SerializerPath', StripTrailingSlash(SWIFT_BASEPATH) . '/' . SWIFT_BASE_DIRECTORY . '/' . SWIFT_CACHE_DIRECTORY);

		if ($this->Settings->Get('t_allowhtml') == '1') {
			$this->HTMLPurifierConfig->set('HTML.Allowed', $this->Settings->Get('t_allowableadvtags'));
		}

		$this->HTMLPurifier = new HTMLPurifier($this->HTMLPurifierConfig);

		return true;
	}

	/**
	 * Destructor
	 *
	 * @author Varun Shoor
	 * @return bool "true" on Success, "false" otherwise
	 */
	public function __destruct() {
		parent::__destruct();

		return true;
	}

	/**
	 * Purify the HTML
	 *
	 * @author Varun Shoor
	 * @param string $_stringContents
	 * @return string
	 * @throws SWIFT_Exception If the Class is not Loaded
	 */
	public function Purify($_stringContents) {
		if (!$this->GetIsClassLoaded()) {
			throw new SWIFT_Exception(SWIFT_CLASSNOTLOADED);

			return false;
		}

		return $this->HTMLPurifier->purify($_stringContents);
	}
}
?>