/**
 * Show a snippet
 */
function smarty_function_snippet($params, &$smarty)
{
    /**
     * Supported parameters:
     *   - source (the source file in WEB_PATH . /snippet/
     *   - * (will be converted to <snippet_name>_*
     */
    $template = new \Skeleton\Template\Template();
    if (empty($params['source'])) {
        throw new Exception('source required for snippet');
    } else {
        $source = $params['source'];
        $var_identifier = substr($source, 0, -4);
    }
    foreach ($smarty->getTemplateVars() as $key => $value) {
        $template->assign($key, $value);
    }
    foreach ($params as $key => $value) {
        $template->assign($var_identifier . '_' . $key, $value);
    }
    foreach ($params as $key => $value) {
        $template->assign($key, $value);
    }
    $template->set_template_directory(\Skeleton\Core\Application::Get()->template_path);
    $content = $template->render('../snippet/' . $source);
    return $content;
}
예제 #2
0
 /**
  * Send email
  *
  * @access public
  */
 public function send()
 {
     if (!$this->validate($errors)) {
         throw new \Exception('Cannot send email, Mail not validated. Errored fields: ' . implode(', ', $errors));
     }
     if (Config::$archive_mailbox !== null) {
         $this->add_bcc(Config::$archive_mailbox);
     }
     $template = new \Skeleton\Template\Template();
     if ($this->translation !== null) {
         $template->set_translation($this->translation);
     }
     $template->set_template_directory(Config::$email_directory . '/template/');
     foreach ($this->assigns as $key => $value) {
         $template->assign($key, $value);
     }
     $transport = \Swift_MailTransport::newInstance();
     $mailer = \Swift_Mailer::newInstance($transport);
     $message = \Swift_Message::newInstance()->setBody($template->render($this->type . '/html.twig'), 'text/html')->addPart($template->render($this->type . '/text.twig'), 'text/plain')->setSubject(trim($template->render($this->type . '/subject.twig')));
     if (isset($this->sender['name'])) {
         $message->setFrom([$this->sender['email'] => $this->sender['name']]);
     } else {
         $message->setFrom($this->sender['email']);
     }
     $this->add_html_images($message);
     $this->attach_files($message);
     foreach ($this->recipients as $type => $recipients) {
         foreach ($recipients as $recipient) {
             if (isset(\Skeleton\Email\Config::$redirect_all_mailbox) and \Skeleton\Email\Config::$redirect_all_mailbox !== null) {
                 $recipient['email'] = \Skeleton\Email\Config::$redirect_all_mailbox;
             }
             if ($recipient['name'] != '') {
                 $addresses[$recipient['email']] = $recipient['name'];
             } else {
                 $addresses[] = $recipient['email'];
             }
         }
         $set_to = 'set' . ucfirst($type);
         call_user_func([$message, $set_to], $addresses);
     }
     $mailer->send($message);
     unset($template);
 }