Location: PHPKode > projects > Anahita Social Engine > dependencies/plg_system_socialengine/socialengine/model/story/template/abstract.php
<?php

/**
 * 
 */
abstract class AnModelStoryTemplateAbstract extends KObject
{
	/**
	 * Filters that parses the text of the template
	 * 
	 * @var array
	 * 
	 */
	protected $_filters = array();
	
	/**
	 * Template name
	 */
	protected $_name;
	
	/**
	 * Template type
	 * 
	 * @var string
	 */
	protected $_type;
		
	/**
	 * cache the tokens within a text
	 * 
	 * @var array
	 */
	protected $_tokens = array();
	
	/**
	 * Return type
	 * @return string
	 */
	public function getType()
	{
		return $this->_type;
	}
	
	/**
	 * Return name 
	 * @return 
	 */
	public function getName()
	{
		return $this->_name;	
	}
				
	/**
	 * Add a filter to parse the data in the template
	 * @return 
	 * @param $filter Object
	 */
	public function addFilter($filter)
	{
		array_unshift($this->_filters, $filter);
	}
	
	/**
	 * Parse out the tokens within a text. It caches the result to avoid double parsing of the same text
	 * @return array
	 * @param $text string
	 */
	protected function _parseTokens($text)
	{
		if ( !isset($this->_tokens[$text]) ) {				
			
			$tokens = array();	
			
			preg_match_all('/\$\{(.*?)\}/', $text, $tokens);
			
			$tokens = array_pop($tokens);
			
			$this->_tokens[$text] = $tokens;
		}
		
		return $this->_tokens[$text];		
	}
	
	/**
	 * Parse the tokens of the text using the data of a story
	 * @return 
	 * @param $text  string
	 * @param $tokens array
	 * @param $story AnModelStoryAbstract
	 */
	protected function _parse(&$text, $story)
	{
		$tokens = $this->_parseTokens($text);
		
		foreach($this->_filters as $filter)
			$filter->parse($text, $tokens, $story);
	}	
			
}
Return current item: Anahita Social Engine