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