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