<?php
/**
* Story Template filter for data like $target, $subject
*
*/
class AnModelStoryTemplateFilterEmail extends AnModelStoryTemplateFilterAbstract
{
public function parse(&$text, $tokens, $story)
{
$kit = KFactory::get('lib.anahita.uikit.actor.name');
$data = $story->data;
foreach($tokens as $token) {
$value = '';
if ( $token == 'subject' || $token == 'target' || $token == 'owner') {
$actor = $story->$token;
$value = KFactory::tmp('lib.anahita.model.story.data.text', array('text'=>$actor->name, 'href'=>$actor->profileURL));
} else if ( strpos($token, 'Pronoun') ) {
$matches = array();
preg_match('/(subject|target)\.(\w+)Pronoun/', $token, $matches);
$actor = $story->$matches[1];
$noun = $matches[2];
$value = JText::_($kit->setActor($actor)->noune($noun));
} else if (strpos($token, '.')) {
list($actor,$prop) = explode('.', $token);
$value = $story->$actor->$prop;
if ( $prop == 'profileURL' )
$value = JFactory::getURI()->base().$value;
} else if ( isset($data[$token]) ) {
$value = $data[$token];
}
if ( is_array($value) ) {
$value = implode(', ', $value);
} else if ( $value instanceof AnModelStoryDataText ){
$v = $value->text;
$value = $v;
}
$this->_replace($text, $token, $value);
}
}
}