00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 class Mage_Core_Model_Email_Template_Filter extends Varien_Filter_Template
00036 {
00037
00038
00039
00040
00041
00042 protected $_useAbsoluteLinks = false;
00043
00044
00045
00046
00047
00048
00049 protected $_useSessionInUrl;
00050
00051
00052
00053
00054
00055
00056 protected static $_urlInstance;
00057
00058
00059
00060
00061
00062
00063
00064 public function setUseAbsoluteLinks($flag)
00065 {
00066 $this->_useAbsoluteLinks = $flag;
00067 return $this;
00068 }
00069
00070
00071
00072
00073
00074
00075
00076 public function setUseSessionInUrl($flag)
00077 {
00078 $this->_useSessionInUrl = (bool)$flag;
00079 return $this;
00080 }
00081
00082
00083
00084
00085
00086
00087
00088 public function blockDirective($construction)
00089 {
00090 $skipParams = array('type', 'id', 'output');
00091 $blockParameters = $this->_getIncludeParameters($construction[2]);
00092 $layout = Mage::app()->getLayout();
00093
00094 if (isset($blockParameters['type'])) {
00095 $type = $blockParameters['type'];
00096 $block = $layout->createBlock($type, null, $blockParameters);
00097 } elseif (isset($blockParameters['id'])) {
00098 $block = $layout->createBlock('cms/block');
00099 if ($block) {
00100 $block->setBlockId($blockParameters['id'])
00101 ->setBlockParams($blockParameters);
00102 foreach ($blockParameters as $k => $v) {
00103 if (in_array($k, $skipParams)) {
00104 continue;
00105 }
00106 $block->setDataUsingMethod($k, $v);
00107 }
00108 }
00109 }
00110 if (!$block) {
00111 return '';
00112 }
00113 if (isset($blockParameters['output'])) {
00114 $method = $blockParameters['output'];
00115 }
00116 if (!isset($method) || !is_string($method) || !is_callable(array($block, $method))) {
00117 $method = 'toHtml';
00118 }
00119 return $block->$method();
00120 }
00121
00122
00123
00124
00125
00126
00127
00128 public function layoutDirective($construction)
00129 {
00130 $skipParams = array('handle', 'area');
00131
00132 $params = $this->_getIncludeParameters($construction[2]);
00133 $layout = Mage::getModel('core/layout');
00134
00135 if (isset($params['area'])) {
00136 $layout->setArea($params['area']);
00137 }
00138 else {
00139 $layout->setArea(Mage::app()->getLayout()->getArea());
00140 }
00141
00142 $layout->getUpdate()->addHandle($params['handle']);
00143 $layout->getUpdate()->load();
00144
00145 $layout->generateXml();
00146 $layout->generateBlocks();
00147
00148 foreach ($layout->getAllBlocks() as $blockName => $block) {
00149
00150 foreach ($params as $k => $v) {
00151 if (in_array($k, $skipParams)) {
00152 continue;
00153 }
00154
00155 $block->setDataUsingMethod($k, $v);
00156 $layout->addOutputBlock($blockName);
00157 }
00158 }
00159
00160 $layout->setDirectOutput(false);
00161 return $layout->getOutput();
00162 }
00163
00164
00165
00166
00167
00168
00169
00170 protected function _getBlockParameters($value)
00171 {
00172 $tokenizer = new Varien_Filter_Template_Tokenizer_Parameter();
00173 $tokenizer->setString($value);
00174
00175 return $tokenizer->tokenize();
00176 }
00177
00178
00179
00180
00181
00182
00183
00184 public function skinDirective($construction)
00185 {
00186 $params = $this->_getIncludeParameters($construction[2]);
00187 $params['_absolute'] = $this->_useAbsoluteLinks;
00188
00189 $url = Mage::getDesign()->getSkinUrl($params['url'], $params);
00190
00191 return $url;
00192 }
00193
00194
00195
00196
00197
00198
00199
00200 public function mediaDirective($construction)
00201 {
00202 $params = $this->_getIncludeParameters($construction[2]);
00203 return Mage::getBaseUrl('media') . $params['url'];
00204 }
00205
00206
00207
00208
00209
00210
00211
00212
00213 public function storeDirective($construction)
00214 {
00215 $params = $this->_getIncludeParameters($construction[2]);
00216 if (!isset($params['_query'])) {
00217 $params['_query'] = array();
00218 }
00219 foreach ($params as $k => $v) {
00220 if (strpos($k, '_query_') === 0) {
00221 $params['_query'][substr($k, 7)] = $v;
00222 unset($params[$k]);
00223 }
00224 }
00225 $params['_absolute'] = $this->_useAbsoluteLinks;
00226
00227 if ($this->_useSessionInUrl === false) {
00228 $params['_nosid'] = true;
00229 }
00230
00231 if (isset($params['direct_url'])) {
00232 $path = '';
00233 $params['_direct'] = $params['direct_url'];
00234 unset($params['direct_url']);
00235 }
00236 else {
00237 $path = $params['url'];
00238 unset($params['url']);
00239 }
00240
00241 if (!self::$_urlInstance) {
00242 self::$_urlInstance = Mage::getModel('core/url')->setStore(
00243 Mage::app()->getStore(Mage::getDesign()->getStore())->getId()
00244 );
00245 }
00246 $_urlInstanceOldStore = null;
00247 if (!empty($path) && !Mage::getStoreConfigFlag(Mage_Core_Model_Store::XML_PATH_STORE_IN_URL)
00248 && !Mage::app()->isSingleStoreMode())
00249 {
00250 $params['_query']['___store'] = Mage::app()->getStore(Mage::getDesign()->getStore())->getCode();
00251 } elseif (!empty($path) && Mage::getStoreConfigFlag(Mage_Core_Model_Store::XML_PATH_STORE_IN_URL)
00252 && !Mage::app()->isSingleStoreMode())
00253 {
00254 $_urlInstanceOldStore = self::$_urlInstance->getStore();
00255 self::$_urlInstance->setStore(Mage::app()->getStore(Mage::getDesign()->getStore())->getCode());
00256 }
00257
00258 $url = self::$_urlInstance->getUrl($path, $params);
00259 if (null ==! $_urlInstanceOldStore) {
00260 self::$_urlInstance->setStore($_urlInstanceOldStore);
00261 }
00262
00263 return $url;
00264 }
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274 public function htmlescapeDirective($construction)
00275 {
00276 $params = $this->_getIncludeParameters($construction[2]);
00277 if (!isset($params['var'])) {
00278 return '';
00279 }
00280
00281 $allowedTags = null;
00282 if (isset($params['allowed_tags'])) {
00283 $allowedTags = preg_split('/\s*\,\s*/', $params['allowed_tags'], 0, PREG_SPLIT_NO_EMPTY);
00284 }
00285
00286 return Mage::helper('core')->htmlEscape($params['var'], $allowedTags);
00287 }
00288 }