Example #1
0
    public static function inject(array $source, $template)
    {
        $ob_size = strlen(self::OPEN_BRACKET);
        $cb_size = strlen(self::CLOSE_BRACKET);
        $pos = 0;
        $end = strlen($template);
        while ($pos <= $end) {
            if ($pos_1 = strpos($template, self::OPEN_BRACKET, $pos)) {
                if ($pos_1) {
                    $pos_2 = strpos($template, self::CLOSE_BRACKET, $pos_1);
                    if ($pos_2) {
                        $return_length = $pos_2 - $cb_size - $pos_1;
                        $var = substr($template, $pos_1 + $ob_size, $return_length);
                        $template = str_replace(self::OPEN_BRACKET . $var . self::CLOSE_BRACKET, $source[$var], $template);
                        $pos = $pos_2 + $cb_size;
                    } else {
                        throw new exception("Incorrectly formed template - missing closing bracket. Please check your syntax.");
                        break;
                    }
                }
            } else {
                break;
            }
        }
        return $template;
    }
}
$array = array("NAME" => "John Doe", "DOB" => "12/21/1986", "ACL" => "Super Administrator");
$template = "This is your template, {NAME}. You were born on {DOB} and you are a {ACL} on this system.";
echo Template::inject($array, $template);
Example #2
0
<?php

require '../lib/mailer/email.php';
require '../lib/template/template.php';
//dados do usuario
$dados = (object) $_GET;
//template do email
$template = new Template(file_get_contents(__DIR__ . '/orcamento.html'));
//dados da empresa
$template->inject('#SITE#', 'http://www.zappragas.com.br');
$template->inject('#DATA#', date('d/m/Y'));
//injeta dados do usuario no email
$template->inject('#NOME#', $dados->nome);
$template->inject('#EMAIL#', $dados->email);
$template->inject('#TELEFONE#', $dados->telefone);
$template->inject('#PRAGA_ALVO#', $dados->pragaAlvo);
$template->inject('#DESCRICAO#', $dados->descricao);
//injeta dados da empresa no email
$template->inject('#EMAIL_EMPRESA#', '');
$template->inject('#TELEFONE_EMPRESA#', '');
//envia o email
$email = new Email();
$email->de = '*****@*****.**';
$email->nome = 'ZapContato';
$email->assunto = 'ORCAMENTO - Site';
$email->conteudo = $template->render();
$email->enviar(array('*****@*****.**'));
$email->enviar(array($dados->email));
Example #3
0
<?php

require '../lib/mailer/email.php';
require '../lib/template/template.php';
//dados do usuario
$dados = (object) $_GET;
//template do email
$template = new Template(file_get_contents(__DIR__ . '/email.html'));
//dados da empresa
$template->inject('#SITE#', 'http://www.zappragas.com.br');
$template->inject('#DATA#', date('d/m/Y'));
//injeta dados do usuario no email
$template->inject('#NOME#', $dados->nome);
$template->inject('#TELEFONE#', $dados->telefone);
$template->inject('#NESTA_DATA#', $dados->data);
$template->inject('#NESTA_HORA#', $dados->hora);
$template->inject('#ASSUNTO#', $dados->assunto);
//injeta dados da empresa no email
$template->inject('#EMAIL_EMPRESA#', '');
$template->inject('#TELEFONE_EMPRESA#', '');
//envia o email
$email = new Email();
$email->de = '*****@*****.**';
$email->nome = 'ZapContato';
$email->assunto = 'ME LIGUE - Site';
$email->conteudo = $template->render();
$email->enviar(array('*****@*****.**'));
Example #4
0
function get_all_posts()
{
    global $user;
    $tpl = get_post_tpl();
    $tpl_posts = "";
    $pst = new Post();
    $posts = $pst->get_all();
    if (count($posts) >= 1) {
        foreach ($posts as $key => $post) {
            $tmpl_posts = new Template(get_post_tpl());
            $cmts = new Comment($post['post_id']);
            $comments = $cmts->get_all();
            if ($comments->num_rows >= 1) {
                $tpl_comments = "";
                foreach ($comments as $comment) {
                    $comment['comment_timestamp'] = date('h:i A, F d, o', strtotime($comment['comment_timestamp']));
                    $tmpl_comments = new Template(get_comment_tpl());
                    $tpl_comments .= $tmpl_comments->inject($comment);
                }
                $post['comment_list'] = $tpl_comments;
                $post['comment_count'] = $comments->num_rows;
            } else {
                $post['comment_count'] = 0;
                $post['comment_list'] = '';
            }
            $post['current_user_id'] = $user['user_id'];
            $post['current_user_name'] = $user['user_name'];
            $post['post_timestamp'] = date('h:i A, F d, o', strtotime($post['post_timestamp']));
            $tpl_posts .= $tmpl_posts->inject($post);
            //\$tpl_posts .= sprintf($tpl, $user['user_name'],$user['user_fullname'],date('h:i A, F d, o', strtotime($post['post_timestamp'])),$post['post_body'], $post['post_id']);
        }
    }
    echo $tpl_posts;
}