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: abstract class Mage_XmlConnect_Model_Preview_Abstract extends Varien_Object
35: {
36: 37: 38: 39: 40:
41: private $_activeTab = false;
42:
43: 44: 45: 46: 47:
48: protected $_categoryItemTintColor = '';
49:
50: 51: 52: 53: 54:
55: protected $_appModel = null;
56:
57: 58: 59: 60: 61: 62:
63: final function _construct()
64: {
65: parent::_construct();
66: $this->setApplicationModel();
67: }
68:
69: 70: 71: 72: 73:
74: protected function setApplicationModel()
75: {
76: if ($this->_appModel === null) {
77: $this->_appModel = Mage::helper('xmlconnect')->getApplication();
78: }
79: return $this;
80: }
81:
82:
83: 84: 85: 86: 87:
88: public function getApplicationModel()
89: {
90: return $this->setApplicationModel()->_appModel;
91: }
92:
93: 94: 95: 96: 97: 98:
99: public function setActiveTab($tab)
100: {
101: $this->_activeTab = $tab;
102: return $this;
103: }
104:
105: 106: 107: 108: 109: 110:
111: public function isItemExists($tabAction)
112: {
113: $tabs = $this->getTabItems();
114: return (bool) isset($tabs[$tabAction]);
115: }
116:
117: 118: 119: 120: 121:
122: public function getTabItems()
123: {
124: $items = array();
125: $model = $this->getApplicationModel();
126: $tabs = $model->getEnabledTabsArray();
127: $tabLimit = (int) Mage::getStoreConfig('xmlconnect/devices/'.strtolower($model->getType()).'/tab_limit');
128: $showedTabs = 0;
129: foreach ($tabs as $tab) {
130: if (++$showedTabs > $tabLimit) {
131: break;
132: }
133: $items[$tab->action] = array(
134: 'label' => Mage::helper('xmlconnect')->getTabLabel($tab->action),
135: 'image' => $tab->image,
136: 'action' => $tab->action,
137: 'active' => strtolower($tab->action) == strtolower($this->_activeTab),
138: );
139: }
140: return $items;
141: }
142:
143: 144: 145: 146: 147: 148:
149: public function setConf($conf)
150: {
151: if (!is_array($conf)) {
152: $conf = array();
153: }
154: $tabs = isset($conf['tabBar']['tabs']) ? $conf['tabBar']['tabs'] : false;
155: if ($tabs !== false) {
156: foreach ($tabs->getEnabledTabs() as $tab) {
157: $tab = (array) $tab;
158: $conf['tabBar'][$tab['action']]['label'] = $tab['label'];
159: $conf['tabBar'][$tab['action']]['image'] = $this->getPreviewImagesUrl($tab['image']);
160: }
161: }
162: $this->setData('conf', $conf);
163: }
164:
165: 166: 167: 168: 169: 170:
171: public function getPreviewImagesUrl($name = '')
172: {
173: return Mage::helper('xmlconnect/image')->getSkinImagesUrl('mobile_preview/' . $name);
174: }
175:
176: 177: 178: 179: 180:
181: abstract public function getBannerImage();
182:
183: 184: 185: 186: 187:
188: abstract public function getBackgroundImage();
189:
190: 191: 192: 193: 194: 195:
196: public function getConfigFontInfo($path)
197: {
198: return $this->getData('conf/fonts/' . $path);
199: }
200:
201: 202: 203: 204: 205:
206: public function getLogoUrl()
207: {
208: $configPath = 'conf/navigationBar/icon';
209: if ($this->getData($configPath)) {
210: return $this->getData($configPath);
211: } else {
212: return $this->getPreviewImagesUrl('smallIcon.png');
213: }
214: }
215:
216: 217: 218: 219: 220:
221: public function getCategoryItemTintColor()
222: {
223: if (!strlen($this->_categoryItemTintColor)) {
224: $percent = 0.4;
225: $mask = 255;
226:
227: $hex = str_replace('#', '', $this->getData('conf/categoryItem/tintColor'));
228: $hex2 = '';
229: $_rgb = array();
230:
231: $hexChars = '[a-fA-F0-9]';
232:
233: if (preg_match("/^($hexChars{2})($hexChars{2})($hexChars{2})$/", $hex, $rgb)) {
234: $_rgb = array(hexdec($rgb[1]), hexdec($rgb[2]), hexdec($rgb[3]));
235: } elseif (preg_match("/^($hexChars)($hexChars)($hexChars)$/", $hex, $rgb)) {
236: $_rgb = array(hexdec($rgb[1] . $rgb[1]), hexdec($rgb[2] . $rgb[2]), hexdec($rgb[3] . $rgb[3]));
237: }
238:
239: for ($i = 0; $i < 3; $i++) {
240: $_rgb[$i] = round($_rgb[$i] * $percent) + round($mask * (1 - $percent));
241: if ($_rgb[$i] > 255) {
242: $_rgb[$i] = 255;
243: }
244: $hex_digit = dechex($_rgb[$i]);
245: if (strlen($hex_digit) == 1) {
246: $hex_digit = "0" . $hex_digit;
247: }
248: $hex2 .= $hex_digit;
249: }
250:
251: if ($hex && $hex2) {
252:
253: $this->_categoryItemTintColor .= "filter: progid:DXImageTransform.Microsoft.gradient";
254: $this->_categoryItemTintColor .= "(startColorstr='#" . $hex2 . "', endColorstr='#" . $hex . "');";
255:
256: $this->_categoryItemTintColor .= "background:-webkit-gradient";
257: $this->_categoryItemTintColor .= "(linear, left top, left bottom,";
258: $this->_categoryItemTintColor .= " from(#" . $hex2 . "), to(#" . $hex . "));";
259:
260: $this->_categoryItemTintColor .= "background:-moz-linear-gradient";
261: $this->_categoryItemTintColor .= "(top, #" . $hex2 . ", #" . $hex . ");";
262: }
263: }
264: return $this->_categoryItemTintColor;
265: }
266: }
267: