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_XmlConnect_Helper_Android extends Mage_Core_Helper_Abstract
35: {
36: 37: 38:
39: const SUBMISSION_TITLE_LENGTH = 30;
40:
41: 42: 43:
44: const SUBMISSION_DESCRIPTION_LENGTH = 4000;
45:
46: 47: 48:
49: const PREVIEW_BANNER_WIDTH = 320;
50:
51: 52: 53:
54: const PREVIEW_BANNER_HEIGHT = 258;
55:
56: 57: 58:
59: const TAGS_ID_FOR_TITLE_BAR = 1;
60:
61: 62: 63:
64: const = 2;
65:
66: 67: 68:
69: const SUBMISSION_COUNTRY_RENDERER = 'androidmarket';
70:
71: 72: 73:
74: const SUBMISSION_COUNTRY_COLUMNS = 2;
75:
76: 77: 78: 79: 80:
81: protected $_imageIds = array('icon', 'android_loader_image', 'android_logo', 'big_logo');
82:
83: 84: 85: 86: 87:
88: protected $_countryRenderer = null;
89:
90: 91: 92: 93: 94: 95: 96: 97: 98:
99: protected $_allowedCountries = array(
100: 'Argentina' => 'AR',
101: 'Australia' => 'AU',
102: 'Austria' => 'AT',
103: 'Belgium' => 'BE',
104: 'Brazil' =>'BR',
105: 'Canada' => 'CA',
106: 'Denmark' => 'DK',
107: 'Finland' => 'FI',
108: 'France' => 'FR',
109: 'Germany' => 'DE',
110: 'Hong Kong SAR China' => 'HK',
111: 'Ireland' => 'IE',
112: 'Israel' => 'IL',
113: 'Italy' => 'IT',
114: 'Japan' => 'JP',
115: 'Mexico' => 'MX',
116: 'Netherlands' => 'NL',
117: 'New Zealand' => 'NZ',
118: 'Norway' => 'NO',
119: 'Portugal' => 'PT',
120: 'Russia' => 'RU',
121: 'Singapore' => 'SG',
122: 'Spain' => 'ES',
123: 'South Korea' => 'KR',
124: 'Sweden' => 'SE',
125: 'Switzerland' => 'CH',
126: 'Taiwan' => 'TW',
127: 'United Kingdom' => 'GB',
128: 'United States' => 'US',
129: );
130:
131: 132: 133: 134: 135:
136: public function getSubmitImages()
137: {
138: return $this->_imageIds;
139: }
140:
141: 142: 143: 144: 145:
146: public function getDefaultDesignTabs()
147: {
148: if (!isset($this->_tabs)) {
149: $this->_tabs = array(
150: array(
151: 'label' => Mage::helper('xmlconnect')->__('Home'),
152: 'image' => 'tab_home_android.png',
153: 'action' => 'Home',
154: 'menu' => self::TAGS_ID_FOR_TITLE_BAR,
155: ),
156: array(
157: 'label' => Mage::helper('xmlconnect')->__('Search'),
158: 'image' => 'tab_search_android.png',
159: 'action' => 'Search',
160: 'menu' => self::TAGS_ID_FOR_TITLE_BAR,
161: ),
162: array(
163: 'label' => Mage::helper('xmlconnect')->__('Account'),
164: 'image' => 'tab_account_android.png',
165: 'action' => 'Account',
166: 'menu' => self::TAGS_ID_FOR_TITLE_BAR,
167: ),
168: array(
169: 'label' => Mage::helper('xmlconnect')->__('Shop'),
170: 'image' => 'tab_shop_android.png',
171: 'action' => 'Shop',
172: 'menu' => self::TAGS_ID_FOR_OPTION_MENU,
173: ),
174: array(
175: 'label' => Mage::helper('xmlconnect')->__('Cart'),
176: 'image' => 'tab_cart_android.png',
177: 'action' => 'Cart',
178: 'menu' => self::TAGS_ID_FOR_OPTION_MENU,
179: ),
180: array(
181: 'label' => Mage::helper('xmlconnect')->__('More Info'),
182: 'image' => 'tab_info_android.png',
183: 'action' => 'AboutUs',
184: 'menu' => self::TAGS_ID_FOR_OPTION_MENU,
185: ),
186: );
187: }
188: return $this->_tabs;
189: }
190:
191: 192: 193: 194: 195:
196: public function getDefaultConfiguration()
197: {
198: return array(
199: 'native' => array(
200: 'body' => array(
201: 'backgroundColor' => '#ABABAB',
202: 'scrollBackgroundColor' => '#EDEDED',
203: ),
204: 'itemActions' => array(
205: 'relatedProductBackgroundColor' => '#404040',
206: ),
207: 'fonts' => array(
208: 'Title1' => array(
209: 'name' => 'HelveticaNeue-Bold',
210: 'size' => '14',
211: 'color' => '#FEFEFE',
212: ),
213: 'Title2' => array(
214: 'name' => 'HelveticaNeue-Bold',
215: 'size' => '12',
216: 'color' => '#222222',
217: ),
218: 'Title3' => array(
219: 'name' => 'HelveticaNeue',
220: 'size' => '13',
221: 'color' => '#000000',
222: ),
223: 'Title4' => array(
224: 'name' => 'HelveticaNeue',
225: 'size' => '12',
226: 'color' => '#FFFFFF',
227: ),
228: 'Title5' => array(
229: 'name' => 'HelveticaNeue-Bold',
230: 'size' => '13',
231: 'color' => '#dc5f02',
232: ),
233: 'Title6' => array(
234: 'name' => 'HelveticaNeue-Bold',
235: 'size' => '16',
236: 'color' => '#222222',
237: ),
238: 'Title7' => array(
239: 'name' => 'HelveticaNeue-Bold',
240: 'size' => '13',
241: 'color' => '#000000',
242: ),
243: 'Title8' => array(
244: 'name' => 'HelveticaNeue-Bold',
245: 'size' => '11',
246: 'color' => '#FFFFFF',
247: ),
248: 'Title9' => array(
249: 'name' => 'HelveticaNeue-Bold',
250: 'size' => '12',
251: 'color' => '#FFFFFF',
252: ),
253: 'Text1' => array(
254: 'name' => 'HelveticaNeue-Bold',
255: 'size' => '12',
256: 'color' => '#777777',
257: ),
258: 'Text2' => array(
259: 'name' => 'HelveticaNeue',
260: 'size' => '10',
261: 'color' => '#555555',
262: ),
263: ),
264: ),
265: );
266: }
267:
268: 269: 270: 271: 272:
273: public function getFontList()
274: {
275: return array(
276: array(
277: 'value' => 'HiraKakuProN-W3',
278: 'label' => 'HiraKakuProN-W3',
279: ),
280: array(
281: 'value' => 'Courier',
282: 'label' => 'Courier',
283: ),
284: array(
285: 'value' => 'Courier-BoldOblique',
286: 'label' => 'Courier-BoldOblique',
287: ),
288: array(
289: 'value' => 'Courier-Oblique',
290: 'label' => 'Courier-Oblique',
291: ),
292: array(
293: 'value' => 'Courier-Bold',
294: 'label' => 'Courier-Bold',
295: ),
296: array(
297: 'value' => 'ArialMT',
298: 'label' => 'ArialMT',
299: ),
300: array(
301: 'value' => 'Arial-BoldMT',
302: 'label' => 'Arial-BoldMT',
303: ),
304: array(
305: 'value' => 'Arial-BoldItalicMT',
306: 'label' => 'Arial-BoldItalicMT',
307: ),
308: array(
309: 'value' => 'Arial-ItalicMT',
310: 'label' => 'Arial-ItalicMT',
311: ),
312: array(
313: 'value' => 'STHeitiTC-Light',
314: 'label' => 'STHeitiTC-Light',
315: ),
316: array(
317: 'value' => 'STHeitiTC-Medium',
318: 'label' => 'STHeitiTC-Medium',
319: ),
320: array(
321: 'value' => 'AppleGothic',
322: 'label' => 'AppleGothic',
323: ),
324: array(
325: 'value' => 'CourierNewPS-BoldMT',
326: 'label' => 'CourierNewPS-BoldMT',
327: ),
328: array(
329: 'value' => 'CourierNewPS-ItalicMT',
330: 'label' => 'CourierNewPS-ItalicMT',
331: ),
332: array(
333: 'value' => 'CourierNewPS-BoldItalicMT',
334: 'label' => 'CourierNewPS-BoldItalicMT',
335: ),
336: array(
337: 'value' => 'CourierNewPSMT',
338: 'label' => 'CourierNewPSMT',
339: ),
340: array(
341: 'value' => 'Zapfino',
342: 'label' => 'Zapfino',
343: ),
344: array(
345: 'value' => 'HiraKakuProN-W6',
346: 'label' => 'HiraKakuProN-W6',
347: ),
348: array(
349: 'value' => 'ArialUnicodeMS',
350: 'label' => 'ArialUnicodeMS',
351: ),
352: array(
353: 'value' => 'STHeitiSC-Medium',
354: 'label' => 'STHeitiSC-Medium',
355: ),
356: array(
357: 'value' => 'STHeitiSC-Light',
358: 'label' => 'STHeitiSC-Light',
359: ),
360: array(
361: 'value' => 'AmericanTypewriter',
362: 'label' => 'AmericanTypewriter',
363: ),
364: array(
365: 'value' => 'AmericanTypewriter-Bold',
366: 'label' => 'AmericanTypewriter-Bold',
367: ),
368: array(
369: 'value' => 'Helvetica-Oblique',
370: 'label' => 'Helvetica-Oblique',
371: ),
372: array(
373: 'value' => 'Helvetica-BoldOblique',
374: 'label' => 'Helvetica-BoldOblique',
375: ),
376: array(
377: 'value' => 'Helvetica',
378: 'label' => 'Helvetica',
379: ),
380: array(
381: 'value' => 'Helvetica-Bold',
382: 'label' => 'Helvetica-Bold',
383: ),
384: array(
385: 'value' => 'MarkerFelt-Thin',
386: 'label' => 'MarkerFelt-Thin',
387: ),
388: array(
389: 'value' => 'HelveticaNeue',
390: 'label' => 'HelveticaNeue',
391: ),
392: array(
393: 'value' => 'HelveticaNeue-Bold',
394: 'label' => 'HelveticaNeue-Bold',
395: ),
396: array(
397: 'value' => 'DBLCDTempBlack',
398: 'label' => 'DBLCDTempBlack',
399: ),
400: array(
401: 'value' => 'Verdana-Bold',
402: 'label' => 'Verdana-Bold',
403: ),
404: array(
405: 'value' => 'Verdana-BoldItalic',
406: 'label' => 'Verdana-BoldItalic',
407: ),
408: array(
409: 'value' => 'Verdana',
410: 'label' => 'Verdana',
411: ),
412: array(
413: 'value' => 'Verdana-Italic',
414: 'label' => 'Verdana-Italic',
415: ),
416: array(
417: 'value' => 'TimesNewRomanPSMT',
418: 'label' => 'TimesNewRomanPSMT',
419: ),
420: array(
421: 'value' => 'TimesNewRomanPS-BoldMT',
422: 'label' => 'TimesNewRomanPS-BoldMT',
423: ),
424: array(
425: 'value' => 'TimesNewRomanPS-BoldItalicMT',
426: 'label' => 'TimesNewRomanPS-BoldItalicMT',
427: ),
428: array(
429: 'value' => 'TimesNewRomanPS-ItalicMT',
430: 'label' => 'TimesNewRomanPS-ItalicMT',
431: ),
432: array(
433: 'value' => 'Georgia-Bold',
434: 'label' => 'Georgia-Bold',
435: ),
436: array(
437: 'value' => 'Georgia',
438: 'label' => 'Georgia',
439: ),
440: array(
441: 'value' => 'Georgia-BoldItalic',
442: 'label' => 'Georgia-BoldItalic',
443: ),
444: array(
445: 'value' => 'Georgia-Italic',
446: 'label' => 'Georgia-Italic',
447: ),
448: array(
449: 'value' => 'STHeitiJ-Medium',
450: 'label' => 'STHeitiJ-Medium',
451: ),
452: array(
453: 'value' => 'STHeitiJ-Light',
454: 'label' => 'STHeitiJ-Light',
455: ),
456: array(
457: 'value' => 'ArialRoundedMTBold',
458: 'label' => 'ArialRoundedMTBold',
459: ),
460: array(
461: 'value' => 'TrebuchetMS-Italic',
462: 'label' => 'TrebuchetMS-Italic',
463: ),
464: array(
465: 'value' => 'TrebuchetMS',
466: 'label' => 'TrebuchetMS',
467: ),
468: array(
469: 'value' => 'Trebuchet-BoldItalic',
470: 'label' => 'Trebuchet-BoldItalic',
471: ),
472: array(
473: 'value' => 'TrebuchetMS-Bold',
474: 'label' => 'TrebuchetMS-Bold',
475: ),
476: array(
477: 'value' => 'STHeitiK-Medium',
478: 'label' => 'STHeitiK-Medium',
479: ),
480: array(
481: 'value' => 'STHeitiK-Light',
482: 'label' => 'STHeitiK-Light',
483: ),
484: );
485: }
486:
487: 488: 489: 490: 491:
492: public function getFontSizes()
493: {
494: $result = array();
495: for ($i = 6; $i < 32; $i++) {
496: $result[] = array(
497: 'value' => $i,
498: 'label' => $i . ' pt',
499: );
500: }
501: return $result;
502: }
503:
504: 505: 506: 507: 508: 509:
510: public function validateSubmit($params)
511: {
512: $errors = array();
513:
514: if (!Zend_Validate::is(isset($params['title']) ? $params['title'] : null, 'NotEmpty')) {
515: $errors[] = Mage::helper('xmlconnect')->__('Please enter the Title.');
516: }
517:
518: if (isset($params['title'])) {
519: $titleLength = self::SUBMISSION_TITLE_LENGTH;
520: $strRules = array('min' => '1', 'max' => $titleLength);
521: if (!Zend_Validate::is($params['title'], 'StringLength', $strRules)) {
522: $errors[] = Mage::helper('xmlconnect')->__('"Title" is more than %d characters long', $strRules['max']);
523: }
524: }
525:
526: if (!Zend_Validate::is(isset($params['description']) ? $params['description'] : null, 'NotEmpty')) {
527: $errors[] = Mage::helper('xmlconnect')->__('Please enter the Description.');
528: }
529:
530: if (isset($params['description'])) {
531: $descriptionLength = self::SUBMISSION_DESCRIPTION_LENGTH;
532: $strRules = array('min' => '1', 'max' => $descriptionLength);
533: if (!Zend_Validate::is($params['title'], 'StringLength', $strRules)) {
534: $errors[] = Mage::helper('xmlconnect')->__('"Description" is more than %d characters long', $strRules['max']);
535: }
536: }
537:
538: if (!Zend_Validate::is(isset($params['copyright']) ? $params['copyright'] : null, 'NotEmpty')) {
539: $errors[] = Mage::helper('xmlconnect')->__('Please enter the Copyright.');
540: }
541:
542: if (empty($params['price_free'])) {
543: if (!Zend_Validate::is(isset($params['price']) ? $params['price'] : null, 'NotEmpty')) {
544: $errors[] = Mage::helper('xmlconnect')->__('Please enter the Price.');
545: }
546: }
547:
548: if (!Zend_Validate::is(isset($params['country']) ? $params['country'] : null, 'NotEmpty')) {
549: $errors[] = Mage::helper('xmlconnect')->__('Please select at least one country.');
550: }
551:
552: $keyLenght = Mage_XmlConnect_Model_Application::APP_MAX_KEY_LENGTH;
553: if (Mage::helper('xmlconnect')->getApplication()->getIsResubmitAction()) {
554: if (isset($params['resubmission_activation_key'])) {
555: $resubmissionKey = $params['resubmission_activation_key'];
556: } else {
557: $resubmissionKey = null;
558: }
559:
560: if (!Zend_Validate::is($resubmissionKey, 'NotEmpty')) {
561: $errors[] = Mage::helper('xmlconnect')->__('Please enter the Resubmission Key.');
562: } elseif (!Zend_Validate::is($resubmissionKey, 'StringLength', array(1, $keyLenght))) {
563: $errors[] = Mage::helper('xmlconnect')->__('Submit App failure. Invalid activation key provided');
564: }
565: } else {
566: $key = isset($params['key']) ? $params['key'] : null;
567: if (!Zend_Validate::is($key, 'NotEmpty')) {
568: $errors[] = Mage::helper('xmlconnect')->__('Please enter the Activation Key.');
569: } elseif (!Zend_Validate::is($key, 'StringLength', array(1, $keyLenght))) {
570: $errors[] = Mage::helper('xmlconnect')->__('Submit App failure. Invalid activation key provided');
571: }
572: }
573: return $errors;
574: }
575:
576: 577: 578: 579: 580: 581:
582: public function validateConfig($native)
583: {
584: $errors = array();
585: if ($native === false || !isset($native['navigationBar']['icon'])
586: || !Zend_Validate::is($native['navigationBar']['icon'], 'NotEmpty')
587: ) {
588: $errors[] = Mage::helper('xmlconnect')->__('Please upload an image for "Logo in Header" field from Design Tab.');
589: }
590:
591: if (!Mage::helper('xmlconnect')->validateConfFieldNotEmpty('bannerAndroidImage', $native)) {
592: $errors[] = Mage::helper('xmlconnect')->__('Please upload an image for "Banner on Home Screen" field from Design Tab.');
593: }
594:
595: return $errors;
596: }
597:
598: 599: 600: 601: 602:
603: public function getCountryRenderer()
604: {
605: if (empty($this->_countryRenderer)) {
606: $renderer = 'xmlconnect/adminhtml_mobile_submission_renderer_country_'
607: . self::SUBMISSION_COUNTRY_RENDERER;
608: $this->_countryRenderer = Mage::app()->getLayout()->createBlock($renderer);
609: }
610: return $this->_countryRenderer;
611: }
612:
613: 614: 615: 616: 617:
618: public function getCountryLabel()
619: {
620: return Mage::helper('xmlconnect')->__('Locations');
621: }
622:
623: 624: 625: 626: 627:
628: public function getCountryColumns()
629: {
630: return self::SUBMISSION_COUNTRY_COLUMNS;
631: }
632:
633: 634: 635: 636: 637:
638: public function isCountryNamePlaceLeft()
639: {
640: return false;
641: }
642:
643: 644: 645: 646: 647:
648: public function getCountryClass()
649: {
650: return self::SUBMISSION_COUNTRY_RENDERER;
651: }
652:
653: 654: 655: 656: 657:
658: public function getAndroidMarketCountriesArray()
659: {
660: return $this->_allowedCountries;
661: }
662:
663: 664: 665: 666: 667: 668: 669: 670:
671: public function checkImages(array $data)
672: {
673:
674: $helper = Mage::helper('xmlconnect/image');
675:
676: $icon =& $data['conf']['native']['navigationBar']['icon'];
677:
678: if (!empty($icon) && !$helper->checkAndGetImagePath($icon)) {
679: $icon = '';
680: }
681:
682: $banner =& $data['conf']['native']['body']['bannerAndroidImage'];
683: if (!empty($banner) && !$helper->checkAndGetImagePath($banner)) {
684: $banner = '';
685: }
686: return $data;
687: }
688:
689: 690: 691: 692: 693: 694: 695:
696: public function checkRequiredConfigFields($data)
697: {
698: if (!is_array($data)) {
699: return;
700: }
701:
702: if (isset($data['navigationBar']['icon']) && empty($data['navigationBar']['icon'])) {
703: Mage::throwException(Mage::helper('xmlconnect')->__('Logo in Header image missing.'));
704: }
705:
706: if (isset($data['body']['bannerAndroidImage']) && empty($data['body']['bannerAndroidImage'])) {
707: Mage::throwException(Mage::helper('xmlconnect')->__('Banner on Home Screen image missing.'));
708: }
709: }
710:
711: 712: 713: 714: 715:
716: public function isNotificationsAllowed()
717: {
718: return true;
719: }
720: }
721: