1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: 28: 29: 30: 31: 32: 33:
34: class Mage_Adminhtml_Block_Newsletter_Template_Preview extends Mage_Adminhtml_Block_Widget
35: {
36:
37: protected function _toHtml()
38: {
39:
40: $template = Mage::getModel('newsletter/template');
41:
42: if($id = (int)$this->getRequest()->getParam('id')) {
43: $template->load($id);
44: } else {
45: $template->setTemplateType($this->getRequest()->getParam('type'));
46: $template->setTemplateText($this->getRequest()->getParam('text'));
47: $template->setTemplateStyles($this->getRequest()->getParam('styles'));
48: }
49:
50: $storeId = (int)$this->getRequest()->getParam('store_id');
51: if(!$storeId) {
52: $storeId = Mage::app()->getDefaultStoreView()->getId();
53: }
54:
55: Varien_Profiler::start("newsletter_template_proccessing");
56: $vars = array();
57:
58: $vars['subscriber'] = Mage::getModel('newsletter/subscriber');
59: if($this->getRequest()->getParam('subscriber')) {
60: $vars['subscriber']->load($this->getRequest()->getParam('subscriber'));
61: }
62:
63: $template->emulateDesign($storeId);
64: $templateProcessed = $template->getProcessedTemplate($vars, true);
65: $template->revertDesign();
66:
67: if($template->isPlain()) {
68: $templateProcessed = "<pre>" . htmlspecialchars($templateProcessed) . "</pre>";
69: }
70:
71: Varien_Profiler::stop("newsletter_template_proccessing");
72:
73: return $templateProcessed;
74: }
75:
76: }
77: