/**
  * @param string $template e.g. "@YourBundle/Some/someTemplate.twig"
  * @return array [name=> "template name", source => "template source"]
  */
 public function find($template)
 {
     $sources = $this->parser->parse($template);
     $result = [];
     foreach ($sources as $name => $source) {
         $result[] = ['name' => $name, 'source' => $source];
     }
     return $result;
 }
 public function display()
 {
     //将变量放入到该方法中,进而可以在数组中进行展现..
     //其他没有通过exportVariables () 函数导入的变量将不会显示在模板中.
     $this->sendHeader();
     $mode = strtolower($this->mode);
     if ($mode == 'html') {
         //加载模板页面..
         extract($this->variables);
         $template = $this->findTemplate();
         if (file_exists($template)) {
             //这里需要进行模板的解析操作..
             $file_path = TemplateParser::parse($template, $this->request->module, $this->request->action);
             require $file_path;
             //这里还有很多要做的事情..
         } else {
             throw new VException("Sorry, file:" . $template . " doesn't exists!!", 400);
         }
     } else {
         if ($mode == 'json') {
             $this->echoJson();
         } else {
             if ($mode == 'xml') {
                 //这里缺少一个将PHP数组转化xml的类型转化器.
                 header("Content-type: text/xml");
                 echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
                 echo "<users><user><name>小小菜鸟</name><age>24</age><sex>男</sex></user>";
                 echo "<user><name>艳艳</name><age>23</age><sex>女</sex></user></users>";
             } else {
                 throw new VException("不支持的数据输出格式!", 1);
             }
         }
     }
 }
示例#3
0
 function parse_template()
 {
     $data = TemplateParser::parse($this->data, $this->template_file);
     # post-parse JSON
     if (strtolower($this->template_type) == 'json') {
         $data = $this->clean_json($data);
     }
     return $data;
 }
示例#4
0
 function parse_template()
 {
     $data = TemplateParser::parse($this->data, file_get_contents($this->template_file));
     # post-parse JSON
     if (strtolower($this->template_type) == 'json') {
         # minfy it
         $data = json_minify($data);
         # strip any trailing commas
         # (run it twice to get partial matches)
         $data = preg_replace('/([}\\]"]),([}\\]])/', '$1$2', $data);
         $data = preg_replace('/([}\\]"]),([}\\]])/', '$1$2', $data);
     }
     return $data;
 }
 function parse_template()
 {
     return TemplateParser::parse($this->data, file_get_contents($this->template_file));
 }
示例#6
0
function queue_email($controller_dblink, $to, $from, $subject, $email_data, $constants, $variables, $app_id, $send_date, $bcc_available = true)
{
    # Reply to
    $reply_to = $from;
    # Separating for validation
    $p = explode('@', $to, 2);
    # Bailing if not someone@someplace.com format
    if (count($p) < 2) {
        return false;
    }
    # Checking if the email is blocked
    $query = "\tSELECT\n\t\t\t\t\t\t`email`\n\t\t\t\t\tFROM\n\t\t\t\t\t\t" . NQ_BLOCKED_EMAILS_TABLE . "\n\t\t\t\t\tWHERE\n\t\t\t\t\t\t`app_id`\t=" . (int) $app_id . " AND\n\t\t\t\t\t\t`email`\t='" . mysqli_escape_string($controller_dblink, $to) . "'\n\t\t\t\t\tLIMIT 1";
    $blocked_data = mysqli_single_result_query($controller_dblink, $query);
    # This user has blocked the app from sending emails
    if (isset($blocked_data)) {
        # Adding our analytics
        $query = "\tINSERT INTO\n\t\t\t\t\t\t\t" . NQ_ANALYTICS_BLOCKED_TABLE . "\n\t\t\t\t\t\tSET\n\t\t\t\t\t\t\t`app_id`\t\t=" . (int) $app_id . ",\n\t\t\t\t\t\t\t`template_id`\t=" . (int) $email_data['id'] . ",\n\t\t\t\t\t\t\t`sender`\t\t='" . mysqli_escape_string($controller_dblink, $from) . "',\n\t\t\t\t\t\t\t`recipient`\t='" . mysqli_escape_string($controller_dblink, $to) . "',\n\t\t\t\t\t\t\t`created`\t\t=NOW()";
        mysqli_sub_query($controller_dblink, $query);
        # Blocked
        return -1;
    } else {
        # Applying our constants and variables
        $attachments_list = [];
        $body = TemplateParser::parse($email_data['body'], $constants, $variables, $app_id, $attachments_list);
        # Applying our unsubscribe
        if ($email_data['requires_unsubscribe'] == 1 && strpos($body, '%unsubscribe%') === false) {
            $body .= '	<div style="margin-top:10px;">%unsubscribe% from ' . $G_APP_DATA['name'] . '</div>';
        }
        # If we are going to track
        $mail_body = $body;
        $bcc_body = $body;
        # Adding our analytics
        $query = "\tINSERT INTO\n\t\t\t\t\t\t" . NQ_ANALYTICS_SENT_TABLE . "\n\t\t\t\t\tSET\n\t\t\t\t\t\t`app_id`\t\t=" . (int) $app_id . ",\n\t\t\t\t\t\t`template_id`\t\t=" . (int) $email_data['id'] . ",\n\t\t\t\t\t\t`sender`\t\t='" . mysqli_escape_string($controller_dblink, $from) . "',\n\t\t\t\t\t\t`recipient`\t\t='" . mysqli_escape_string($controller_dblink, $to) . "',\n\t\t\t\t\t\t`created`\t\t=NOW(),\n\t\t\t\t\t\t`requested_date`\t=NOW()";
        mysqli_sub_query($controller_dblink, $query);
        $analytics_id = mysqli_insert_id($controller_dblink);
        # If we are going to track
        $mail_body = $body;
        $bcc_body = $body;
        if ($email_data['track'] == 1) {
            # Our ids
            $hash_id = hash('sha256', $analytics_id . $to);
            # Updating the hash id
            $query = "\tUPDATE\n\t\t\t\t\t\t\t" . NQ_ANALYTICS_SENT_TABLE . "\n\t\t\t\t\t\tSET\n\t\t\t\t\t\t\t`hash_id`\t='" . $hash_id . "'\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t`id`\t\t=" . (int) $analytics_id . "\n\t\t\t\t\t\tLIMIT 1";
            mysqli_sub_query($controller_dblink, $query);
            # Customizing the body
            $mail_body .= '<img style="display:none;" src="' . NQ_DOMAIN_ROOT . '/' . $app_id . '/track?ref=' . $hash_id . '" width="1" height="1" />';
        }
        # Inserting our unsubscribe link
        $keys = ['/%unsubscribe%/'];
        $values = ['<a href="' . NQ_DOMAIN_ROOT . '/' . $app_id . '/unsubscribe?ref=' . $hash_id . '&email=' . urlencode($to) . '" style="color:inherit;text-decoration:inherit;"> Unsubscribe </a>'];
        $mail_body = preg_replace($keys, $values, $mail_body);
        # Adding to the queue
        $query = "\tINSERT INTO\n\t\t\t\t\t\t" . NQ_QUEUE_TABLE . "\n\t\t\t\t\tSET\n\t\t\t\t\t\t`app_id`\t=" . (int) $app_id . ",\n\t\t\t\t\t\t`analytics_id`\t=" . (int) $analytics_id . ",\n\t\t\t\t\t\t`sender`\t='" . mysqli_escape_string($controller_dblink, $from) . "',\n\t\t\t\t\t\t`recipient`\t='" . mysqli_escape_string($controller_dblink, $to) . "',\n\t\t\t\t\t\t`subject`\t='" . mysqli_escape_string($controller_dblink, $subject) . "',\n\t\t\t\t\t\t`raw`\t\t='" . mysqli_escape_string($controller_dblink, build_raw_email($to, $from, $reply_to, $subject, $mail_body, $attachments_list, $app_id)) . "',\n\t\t\t\t\t\t`send_date`\t='" . date('Y-m-d H:i:s', $send_date) . "',\n\t\t\t\t\t\t`priority`\t=1";
        mysqli_sub_query($controller_dblink, $query);
        # Sending the bcc
        if ($bcc_available) {
            # Modifying to add our bcc header
            $bcc_body = trim('<div style="padding:10px;border-bottom:solid #E9E9E9 1px;margin-bottom:1px;line-height:2.0;">
									<div style="width:75px;color:#999;display:inline-block;text-align:right;padding-right:10px;"></div><b>BCC Email</b><br />
									<div style="width:75px;color:#999;display:inline-block;text-align:right;padding-right:10px;">sent to:</div>' . $to . '<br />
									<div style="width:75px;color:#999;display:inline-block;text-align:right;padding-right:10px;">from:</div>' . htmlentities($from) . '<br />
									<div style="width:75px;color:#999;display:inline-block;text-align:right;padding-right:10px;">date:</div>' . date('r') . '<br />
									<div style="width:75px;color:#999;display:inline-block;text-align:right;padding-right:10px;">send date:</div>' . date('r', $send_date) . '<br />
									<div style="width:75px;color:#999;display:inline-block;text-align:right;padding-right:10px;">tracking:</div>' . ($email_data['track'] == 1 ? 'Yes' : 'No') . '<br />
								</div>
								' . $bcc_body);
            # Sending bcc emails
            foreach (explode(',', $email_data['bcc']) as $bcc) {
                # Adding to the queue
                if (trim($bcc) != '') {
                    $query = "\tINSERT INTO\n\t\t\t\t\t\t\t\t\t" . NQ_QUEUE_TABLE . "\n\t\t\t\t\t\t\t\tSET\n\t\t\t\t\t\t\t\t\t`app_id`\t=" . (int) $app_id . ",\n\t\t\t\t\t\t\t\t\t`sender`\t='" . mysqli_escape_string($controller_dblink, $from) . "',\n\t\t\t\t\t\t\t\t\t`recipient`\t='" . mysqli_escape_string($controller_dblink, trim($bcc)) . "',\n\t\t\t\t\t\t\t\t\t`subject`\t='" . mysqli_escape_string($controller_dblink, $subject) . "',\n\t\t\t\t\t\t\t\t\t`raw`\t\t='" . mysqli_escape_string($controller_dblink, build_raw_email(trim($bcc), $from, $reply_to, $subject, $bcc_body, $attachments_list, $app_id)) . "',\n\t\t\t\t\t\t\t\t\t`send_date`\t=NOW(),\n\t\t\t\t\t\t\t\t\t`priority`\t=255";
                    mysqli_sub_query($controller_dblink, $query);
                }
            }
        }
        # Sent
        return 1;
    }
}
示例#7
0
 function render()
 {
     // if page doesn't contain a content file or have a matching template file, redirect to it or return 404
     if (!$this->page || !$this->page->template_file) {
         return $this->render_404();
     }
     // create new cache object
     $cache = new Cache($this->page);
     // check etags
     header('Etag: "' . $cache->hash . '"');
     if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && stripslashes($_SERVER['HTTP_IF_NONE_MATCH']) == '"' . $cache->hash . '"') {
         // local cache is still fresh, so return 304
         header("HTTP/1.0 304 Not Modified");
         header('Content-Length: 0');
     } else {
         // check if cache needs to be expired
         if ($cache->check_expired()) {
             // start output buffer
             ob_start();
             // render page
             $t = new TemplateParser();
             $c = new ContentParser();
             echo $t->parse($this->page, $c->parse($this->page));
             // cache folder is writable, write to it
             if (is_writable('./cache')) {
                 $cache->write_cache();
             } else {
                 echo "\n" . '<!-- Stacey(' . Stacey::$version . '). -->';
             }
             // end buffer
             ob_end_flush();
         } else {
             // else cache hasn't expired, so use existing cache
             echo file_get_contents($cache->cachefile) . "\n" . '<!-- Cached. -->';
         }
     }
 }
示例#8
0
# Handling our global json parsing
$_JPOST = PostParser::decode();
# Getting our template
$query = "\tSELECT\n\t\t\t\t*\n\t\t\tFROM\n\t\t\t\t" . NQ_TEMPLATE_TABLE . "\n\t\t\tWHERE\n\t\t\t\t`app_id`\t=" . (int) $G_APP_DATA['id'] . " AND\n\t\t\t\t`environment`\tIN ('*','" . mysqli_escape_string($G_STORAGE_CONTROLLER_DBLINK, $G_APP_ENVIRONMENT) . "') AND\n\t\t\t\t`tag`\t\t='" . mysqli_escape_string($G_STORAGE_CONTROLLER_DBLINK, $_JPOST->tag) . "'\n\t\t\tLIMIT 1";
$email_data = mysqli_single_result_query($G_STORAGE_CONTROLLER_DBLINK, $query);
# Error checking
if (!isset($email_data['app_id'])) {
    exit_fail(NQ_ERROR_INVALID_VALUE, LANG_INVALID_TEMPLATE);
}
# Adding our constants
$query = "\tSELECT\n\t\t\t\t`tag`,\n\t\t\t\t`text`\n\t\t\tFROM\n\t\t\t\t" . NQ_CONSTANT_TABLE . "\n\t\t\tWHERE\n\t\t\t\t`app_id`\t=" . (int) $G_APP_DATA['id'] . " AND\n\t\t\t\t`environment`\tIN ('*','" . mysqli_escape_string($G_STORAGE_CONTROLLER_DBLINK, $G_APP_ENVIRONMENT) . "')";
$result = mysqli_multi_result_query($G_STORAGE_CONTROLLER_DBLINK, $query);
$constants = mysqli_fetch_all($result, MYSQLI_ASSOC);
# Applying our constants and variables
$attachment_list = [];
$body = TemplateParser::parse($email_data['body'], $constants, $_JPOST->variables, $G_APP_DATA['id'], $attachment_list, true);
# Applying our unsubscribe
if ($email_data['requires_unsubscribe'] == 1 && strpos($body, '%unsubscribe%') === false) {
    $body .= '	<div style="margin-top:10px;">%unsubscribe% from ' . $G_APP_DATA['name'] . '</div>';
}
# Our return value
$content = new stdClass();
$content->subject = $email_data['subject'];
$content->body = $body;
# Sending our content
PostParser::send($content);
/* --- Connection closed wit PostParser::send --- Below this point things need to be tracked and cleaned up --- */
# Closing the storage connection
mysqli_shared_close($G_STORAGE_CONTROLLER_DBLINK, $G_SHARED_DBLINKS);
# Closing controller if tracking is different
if (NQ_CONTROLLER_HOST != NQ_TRACKING_HOST) {