/**
  * Create a new translatable email
  * 
  * @param DBObject $context
  * @param string $translation_id
  * @param array $variables
  * 
  * @return TranslatableEmail
  */
 public static function create($translation_id, $variables)
 {
     $email = new self();
     // Get translation data and variables
     $email->translation_id = $translation_id;
     $email->variables = array();
     if ($variables) {
         foreach ($variables as $k => $v) {
             // Convert DBObject types to type/id pairs for saving
             if ($v instanceof DBObject) {
                 $v = array('dbobject_type' => get_class($v), 'dbobject_id' => $v->id);
             }
             $email->variables[$k] = $v;
         }
     }
     // Add meta
     $email->created = time();
     // Generate token until it is indeed unique
     $email->token = Utilities::generateUID(function ($token) {
         $statement = DBI::prepare('SELECT * FROM ' . TranslatableEmail::getDBTable() . ' WHERE token = :token');
         $statement->execute(array(':token' => $token));
         $data = $statement->fetch();
         return !$data;
     });
     $email->save();
     return $email;
 }
Пример #2
0
if (!array_key_exists($lang, $available)) {
    $lang = Lang::getCode();
}
$url = '?s=translate_email&token=' . $token . '&lang=';
if (count($available) > 1) {
    echo '<div class="buttons">';
    foreach ($available as $id => $dfn) {
        if ($id == $lang) {
            echo '<span class="selected">' . Utilities::sanitizeOutput($dfn['name']) . '</span>';
        } else {
            echo '<a href="' . $url . $id . '">' . Utilities::sanitizeOutput($dfn['name']) . '</a>';
        }
    }
    echo '</div>';
}
$translatable = TranslatableEmail::fromToken($token);
$translation = $translatable->translate($lang);
/*
 * Do not call Template::sanitizeOutput on email contents after that because
 * TranslatableEmail::translate calls Translation::replace which itself calls
 * Utilities::sanitizeOutput, use Template::sanitize instead !
 */
$subject = array_filter($translation->subject->out());
?>
    
    <dl>
        <dt data-property="subject">{tr:subject} :</dt>
        <dd data-property="subject"><?php 
echo Template::sanitize(array_pop($subject));
?>
</dd>