1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_Catalog
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27:
28: /**
29: * Catalog Template Filter Model
30: *
31: * @category Mage
32: * @package Mage_Catalog
33: * @author Magento Core Team <core@magentocommerce.com>
34: * @todo Needs to be reimplemented to get rid of the copypasted methods
35: */
36: class Mage_Catalog_Model_Template_Filter extends Varien_Filter_Template
37: {
38: /**
39: * Use absolute links flag
40: *
41: * @var bool
42: */
43: protected $_useAbsoluteLinks = false;
44:
45: /**
46: * Whether to allow SID in store directive: NO
47: *
48: * @var bool
49: */
50: protected $_useSessionInUrl = false;
51:
52: /**
53: * Set use absolute links flag
54: *
55: * @param bool $flag
56: * @return Mage_Core_Model_Email_Template_Filter
57: */
58: public function setUseAbsoluteLinks($flag)
59: {
60: $this->_useAbsoluteLinks = $flag;
61: return $this;
62: }
63:
64: /**
65: * Setter whether SID is allowed in store directive
66: * Doesn't set anything intentionally, since SID is not allowed in any kind of emails
67: *
68: * @param bool $flag
69: * @return Mage_Core_Model_Email_Template_Filter
70: */
71: public function setUseSessionInUrl($flag)
72: {
73: $this->_useSessionInUrl = $flag;
74: return $this;
75: }
76:
77: /**
78: * Retrieve Skin URL directive
79: *
80: * @param array $construction
81: * @return string
82: * @see Mage_Core_Model_Email_Template_Filter::skinDirective() method has been copypasted
83: */
84: public function skinDirective($construction)
85: {
86: $params = $this->_getIncludeParameters($construction[2]);
87: $params['_absolute'] = $this->_useAbsoluteLinks;
88:
89: $url = Mage::getDesign()->getSkinUrl($params['url'], $params);
90:
91: return $url;
92: }
93:
94: /**
95: * Retrieve media file URL directive
96: *
97: * @param array $construction
98: * @return string
99: * @see Mage_Core_Model_Email_Template_Filter::mediaDirective() method has been copypasted
100: */
101: public function mediaDirective($construction)
102: {
103: $params = $this->_getIncludeParameters($construction[2]);
104: return Mage::getBaseUrl('media') . $params['url'];
105: }
106:
107: /**
108: * Retrieve store URL directive
109: * Support url and direct_url properties
110: *
111: * @param array $construction
112: * @return string
113: * @see Mage_Core_Model_Email_Template_Filter::storeDirective() method has been copypasted
114: */
115: public function storeDirective($construction)
116: {
117: $params = $this->_getIncludeParameters($construction[2]);
118: if (!isset($params['_query'])) {
119: $params['_query'] = array();
120: }
121: foreach ($params as $k => $v) {
122: if (strpos($k, '_query_') === 0) {
123: $params['_query'][substr($k, 7)] = $v;
124: unset($params[$k]);
125: }
126: }
127: $params['_absolute'] = $this->_useAbsoluteLinks;
128:
129: if ($this->_useSessionInUrl === false) {
130: $params['_nosid'] = true;
131: }
132:
133: if (isset($params['direct_url'])) {
134: $path = '';
135: $params['_direct'] = $params['direct_url'];
136: unset($params['direct_url']);
137: }
138: else {
139: $path = isset($params['url']) ? $params['url'] : '';
140: unset($params['url']);
141: }
142:
143: return Mage::app()->getStore(Mage::getDesign()->getStore())->getUrl($path, $params);
144: }
145: }
146: