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: class Mage_Catalog_Helper_Output extends Mage_Core_Helper_Abstract
28: {
29: 30: 31: 32: 33:
34: protected $_handlers;
35:
36: 37: 38: 39: 40:
41: protected $_templateProcessor = null;
42:
43: 44: 45:
46: public function __construct()
47: {
48: Mage::dispatchEvent('catalog_helper_output_construct', array('helper'=>$this));
49: }
50:
51: protected function _getTemplateProcessor()
52: {
53: if (null === $this->_templateProcessor) {
54: $this->_templateProcessor = Mage::helper('catalog')->getPageTemplateProcessor();
55: }
56:
57: return $this->_templateProcessor;
58: }
59:
60: 61: 62: 63: 64: 65: 66:
67: public function addHandler($method, $handler)
68: {
69: if (!is_object($handler)) {
70: return $this;
71: }
72: $method = strtolower($method);
73:
74: if (!isset($this->_handlers[$method])) {
75: $this->_handlers[$method] = array();
76: }
77:
78: $this->_handlers[$method][] = $handler;
79: return $this;
80: }
81:
82: 83: 84: 85: 86: 87:
88: public function getHandlers($method)
89: {
90: $method = strtolower($method);
91: return isset($this->_handlers[$method]) ? $this->_handlers[$method] : array();
92: }
93:
94: 95: 96: 97: 98: 99: 100: 101:
102: public function process($method, $result, $params)
103: {
104: foreach ($this->getHandlers($method) as $handler) {
105: if (method_exists($handler, $method)) {
106: $result = $handler->$method($this, $result, $params);
107: }
108: }
109: return $result;
110: }
111:
112: 113: 114: 115: 116: 117: 118: 119:
120: public function productAttribute($product, $attributeHtml, $attributeName)
121: {
122: $attribute = Mage::getSingleton('eav/config')->getAttribute(Mage_Catalog_Model_Product::ENTITY, $attributeName);
123: if ($attribute && $attribute->getId() && ($attribute->getFrontendInput() != 'media_image')
124: && (!$attribute->getIsHtmlAllowedOnFront() && !$attribute->getIsWysiwygEnabled())) {
125: if ($attribute->getFrontendInput() != 'price') {
126: $attributeHtml = $this->escapeHtml($attributeHtml);
127: }
128: if ($attribute->getFrontendInput() == 'textarea') {
129: $attributeHtml = nl2br($attributeHtml);
130: }
131: }
132: if ($attribute->getIsHtmlAllowedOnFront() && $attribute->getIsWysiwygEnabled()) {
133: if (Mage::helper('catalog')->isUrlDirectivesParsingAllowed()) {
134: $attributeHtml = $this->_getTemplateProcessor()->filter($attributeHtml);
135: }
136: }
137:
138: $attributeHtml = $this->process('productAttribute', $attributeHtml, array(
139: 'product' => $product,
140: 'attribute' => $attributeName
141: ));
142:
143: return $attributeHtml;
144: }
145:
146: 147: 148: 149: 150: 151: 152: 153:
154: public function categoryAttribute($category, $attributeHtml, $attributeName)
155: {
156: $attribute = Mage::getSingleton('eav/config')->getAttribute(Mage_Catalog_Model_Category::ENTITY, $attributeName);
157:
158: if ($attribute && ($attribute->getFrontendInput() != 'image')
159: && (!$attribute->getIsHtmlAllowedOnFront() && !$attribute->getIsWysiwygEnabled())) {
160: $attributeHtml = $this->escapeHtml($attributeHtml);
161: }
162: if ($attribute->getIsHtmlAllowedOnFront() && $attribute->getIsWysiwygEnabled()) {
163: if (Mage::helper('catalog')->isUrlDirectivesParsingAllowed()) {
164: $attributeHtml = $this->_getTemplateProcessor()->filter($attributeHtml);
165: }
166: }
167: $attributeHtml = $this->process('categoryAttribute', $attributeHtml, array(
168: 'category' => $category,
169: 'attribute' => $attributeName
170: ));
171: return $attributeHtml;
172: }
173: }
174: