<?php

/**
 * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 * @package clearFusionCMS
 * @copyright Copyright (c) 2016 clearFusionCMS. All rights reserved.
 * @link http://clearfusioncms.com
 */

/**
 * Class cfContentFilter
 *
 * Static class to aid in applying content filter snippets.
 */
abstract class cfContentFilter {

	/**
	 * The template engine instance being used to the the filters.
	 *
	 * @var cfTemplateEngine
	 */
	static protected $tpl = null;

	/**
	 * Set the template engine to use for running the filters.
	 *
	 * @param cfTemplateEngine $tpl The template engine.
	 */
	static function useTemplateEngine($tpl) {
		self::$tpl = $tpl;
	}

	/**
	 * Apply a filter to the given content.
	 *
	 * @param string $filter The name of the filter snippet to apply.
	 * @param string $content The content to filter.
	 * @return string The filtered content.
	 */
	static function apply($filter, $content) {
		if(!empty($filter)) {

			// Make sure we have a template engine instance to work with
			if(!self::$tpl) {
				self::$tpl = new cfTemplateEngine(clearFusionCMS::getController());
			}

			// Apply the filter
			$content = self::$tpl->runSnippet($filter, array(
				'content' => $content
			));
		}

		return $content;
	}
}