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: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53:
54: class Mage_XmlConnect_Model_Application extends Mage_Core_Model_Abstract
55: {
56: 57: 58:
59: const APP_CODE_COOKIE_NAME = 'app_code';
60:
61: 62: 63:
64: const APP_SCREEN_SIZE_NAME = 'screen_size';
65:
66: 67: 68:
69: const APP_SCREEN_SIZE_DEFAULT = '320x480';
70:
71: 72: 73:
74: const APP_SCREEN_SOURCE_DEFAULT = 'default';
75:
76: 77: 78:
79: const APP_STATUS_SUCCESS = 1;
80:
81: 82: 83:
84: const APP_STATUS_INACTIVE = 0;
85:
86: 87: 88:
89: const APP_PREFIX_CUT_LENGTH = 3;
90:
91: 92: 93: 94: 95:
96: protected $_lastParams;
97:
98: 99: 100: 101: 102:
103: protected $submit_params = array();
104:
105: 106: 107: 108: 109:
110: protected $is_resubmit_action = false;
111:
112: 113: 114: 115: 116:
117: protected $code;
118:
119: 120: 121: 122: 123: 124:
125: protected $conf;
126:
127: 128: 129: 130: 131:
132: protected $_configModel;
133:
134: 135: 136: 137: 138:
139: protected $_isConfigurationLoaded = false;
140:
141: 142: 143: 144: 145: 146: 147: 148: 149: 150:
151: protected $_socialNetValidationArray = array(
152: Mage_XmlConnect_Helper_Data::SOCIAL_NETWORK_TWITTER,
153: Mage_XmlConnect_Helper_Data::SOCIAL_NETWORK_FACEBOOK,
154: Mage_XmlConnect_Helper_Data::SOCIAL_NETWORK_LINKEDIN,
155: );
156:
157: 158: 159:
160: const APP_MAX_KEY_LENGTH = 40;
161:
162: 163: 164: 165: 166:
167: const XML_PATH_CONTACT_CREDENTIALS_EMAIL = 'xmlconnect/mobile_application/urbanairship_credentials_email';
168:
169: 170: 171:
172: const XML_PATH_URBAN_AIRSHIP_TOS_URL = 'xmlconnect/mobile_application/urbanairship_terms_of_service_url';
173:
174: 175: 176:
177: const XML_PATH_URBAN_AIRSHIP_PARTNER_LOGIN_URL = 'xmlconnect/mobile_application/urbanairship_login_url';
178:
179: 180: 181:
182: const XML_PATH_URBAN_AIRSHIP_ABOUT_PUSH_URL = 'xmlconnect/mobile_application/urbanairship_push_url';
183:
184: 185: 186:
187: const XML_PATH_URBAN_AIRSHIP_ABOUT_RICH_PUSH_URL = 'xmlconnect/mobile_application/urbanairship_rich_push_url';
188:
189: 190: 191:
192: const = 'design/footer/copyright';
193:
194: 195: 196: 197:
198: const XML_PATH_GENERAL_RESTRICTION_IS_ACTIVE = 'general/restriction/is_active';
199:
200: 201: 202: 203:
204: const XML_PATH_GENERAL_RESTRICTION_MODE = 'general/restriction/mode';
205:
206: 207: 208:
209: const XML_PATH_SECURE_BASE_LINK_URL = 'web/secure/base_link_url';
210:
211: 212: 213:
214: const XML_PATH_PAYPAL_BUSINESS_ACCOUNT = 'paypal/general/business_account';
215:
216: 217: 218:
219: const XML_PATH_DEFAULT_CACHE_LIFETIME = 'xmlconnect/mobile_application/cache_lifetime';
220:
221: 222: 223:
224: const = 'xmlconnect/social_networking/howto_twitter_url';
225:
226: 227: 228:
229: const XML_PATH_HOWTO_FACEBOOK_URL = 'xmlconnect/social_networking/howto_facebook_url';
230:
231: 232: 233:
234: const XML_PATH_HOWTO_LINKEDIN_URL = 'xmlconnect/social_networking/howto_linkedin_url';
235:
236: 237: 238:
239: const XML_PATH_MODULE_VERSION = 'modules/Mage_XmlConnect/innerVersion';
240:
241: 242: 243: 244: 245:
246: const DEPRECATED_CONFIG_FLAG = 'deprecated';
247:
248: 249: 250: 251: 252:
253: protected $_deleteOnUpdateConfig = array(
254: self::DEPRECATED_CONFIG_FLAG => 'native/pages'
255: );
256:
257: 258: 259: 260: 261:
262: protected function _construct()
263: {
264: $this->_init('xmlconnect/application');
265: $this->_configModel = Mage::getModel('xmlconnect/configData');
266: $this->_configModel->setDeleteOnUpdate($this->getDeleteOnUpdateConfig());
267: }
268:
269: 270: 271: 272: 273: 274:
275: public function getIsSubmitted()
276: {
277: return $this->getStatus() == Mage_XmlConnect_Model_Application::APP_STATUS_SUCCESS;
278: }
279:
280: 281: 282: 283: 284:
285: public function getFormData()
286: {
287: $data = $this->getData();
288: $data = Mage::helper('xmlconnect')->getDeviceHelper()->checkImages($data);
289: return $this->_flatArray($data);
290: }
291:
292: 293: 294: 295: 296: 297: 298:
299: protected function _flatArray($subtree, $prefix=null)
300: {
301: $result = array();
302: foreach ($subtree as $key => $value) {
303: if (is_null($prefix)) {
304: $name = $key;
305: } else {
306: $name = $prefix . '[' . $key . ']';
307: }
308:
309: if (is_array($value)) {
310: $result = array_merge($result, $this->_flatArray($value, $name));
311: } else {
312: $result[$name] = $value;
313: }
314: }
315: return $result;
316: }
317:
318: 319: 320: 321: 322: 323: 324:
325: protected function _configMerge(array $array1, array $array2)
326: {
327: $result = array();
328: $keys = array_unique(array_merge(array_keys($array1), array_keys($array2)));
329: foreach ($keys as $key) {
330: if (!isset($array1[$key])) {
331: $result[$key] = $array2[$key];
332: } elseif (!isset($array2[$key])) {
333: $result[$key] = $array1[$key];
334: } elseif (is_scalar($array1[$key]) || is_scalar($array2[$key])) {
335: $result[$key] = $array2[$key];
336: } else {
337: $result[$key] = $this->_configMerge($array1[$key], $array2[$key]);
338: }
339: }
340: return $result;
341: }
342:
343: 344: 345: 346: 347:
348: public function loadDefaultConfiguration()
349: {
350: $this->setCode($this->getCodePrefix());
351: $this->setConf(Mage::helper('xmlconnect')->getDeviceHelper()->getDefaultConfiguration());
352: }
353:
354: 355: 356: 357: 358:
359: public function getCodePrefix()
360: {
361: return substr(Mage::app()->getStore($this->getStoreId())->getCode(), 0, self::APP_PREFIX_CUT_LENGTH)
362: . substr($this->getType(), 0, self::APP_PREFIX_CUT_LENGTH);
363: }
364:
365: 366: 367: 368: 369:
370: public function isCodePrefixed()
371: {
372: $suffix = substr($this->getCode(), self::APP_PREFIX_CUT_LENGTH * 2);
373: return !empty($suffix);
374: }
375:
376: 377: 378: 379: 380: 381:
382: public function prepareConfiguration()
383: {
384: return $this->getData('conf');
385: }
386:
387: 388: 389: 390: 391:
392: public function getRenderConf()
393: {
394: $result = Mage::helper('xmlconnect')->getDeviceHelper()->getDefaultConfiguration();
395: $result = $result['native'];
396:
397: if (isset($this->_data['conf'])) {
398: if (isset($this->_data['conf']['native'])) {
399: $result = $this->_configMerge($result, $this->_data['conf']['native']);
400: }
401: if (isset($this->_data['conf']['extra'])) {
402: $extra = $this->_data['conf']['extra'];
403: if (isset($extra['tabs'])) {
404: $tabs = Mage::getModel('xmlconnect/tabs', $extra['tabs']);
405: $result['tabBar']['tabs'] = $tabs;
406: }
407: if (isset($extra['fontColors'])) {
408: if (!empty($extra['fontColors']['header'])) {
409: $result['fonts']['Title1']['color'] = $extra['fontColors']['header'];
410: }
411: if (!empty($extra['fontColors']['primary'])) {
412: $result['fonts']['Title2']['color'] = $extra['fontColors']['primary'];
413: $result['fonts']['Title3']['color'] = $extra['fontColors']['primary'];
414: $result['fonts']['Text1']['color'] = $extra['fontColors']['primary'];
415: $result['fonts']['Text2']['color'] = $extra['fontColors']['primary'];
416: $result['fonts']['Title7']['color'] = $extra['fontColors']['primary'];
417: }
418: if (!empty($extra['fontColors']['secondary'])) {
419: $result['fonts']['Title4']['color'] = $extra['fontColors']['secondary'];
420: $result['fonts']['Title6']['color'] = $extra['fontColors']['secondary'];
421: $result['fonts']['Title8']['color'] = $extra['fontColors']['secondary'];
422: $result['fonts']['Title9']['color'] = $extra['fontColors']['secondary'];
423: }
424: if (!empty($extra['fontColors']['price'])) {
425: $result['fonts']['Title5']['color'] = $extra['fontColors']['price'];
426: }
427: }
428: }
429: }
430:
431:
432: $helperImage = Mage::helper('xmlconnect/image');
433: $paths = $helperImage->getInterfaceImagesPathsConf();
434:
435: foreach ($paths as $confPath => $dataPath) {
436: $imageNodeValue =& $helperImage->findPath($result, $dataPath);
437:
438: if (!$helperImage->checkAndGetImagePath($imageNodeValue)) {
439: 440: 441:
442: $imageNodeValue = '';
443: } else {
444: 445: 446:
447: $imageNodeValue = $helperImage->getFileCustomDirSuffixAsUrl($confPath, $imageNodeValue);
448: }
449: }
450: $result = $this->_absPath($result);
451:
452: 453: 454:
455: $result['general']['updateTimeUTC'] = strtotime($this->getUpdatedAt());
456: $result['general']['browsingMode'] = $this->getBrowsingMode();
457: $result['general']['currencyCode'] = Mage::app()->getStore($this->getStoreId())->getDefaultCurrencyCode();
458: $result['general']['secureBaseUrl'] = $this->getSecureBaseUrl();
459:
460: $maxRecipients = 0;
461: $allowGuest = 0;
462: if (Mage::getStoreConfig(Mage_Sendfriend_Helper_Data::XML_PATH_ENABLED)) {
463: $maxRecipients = Mage::getStoreConfig(Mage_Sendfriend_Helper_Data::XML_PATH_MAX_RECIPIENTS);
464: $allowGuest = Mage::getStoreConfig(Mage_Sendfriend_Helper_Data::XML_PATH_ALLOW_FOR_GUEST);
465: }
466: $result['general']['emailToFriendMaxRecepients'] = $maxRecipients;
467: $result['general']['emailAllowGuest'] = $allowGuest;
468: $result['general']['primaryStoreLang'] = Mage::app()
469: ->getStore($this->getStoreId())->getConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_LOCALE);
470: $result['general']['magentoVersion'] = Mage::getVersion();
471: $result['general']['copyright'] = Mage::getStoreConfig(
472: self::XML_PATH_DESIGN_FOOTER_COPYRIGHT, $this->getStoreId()
473: );
474: $result['general']['xmlconnectVersion'] = Mage::getConfig()->getNode(self::XML_PATH_MODULE_VERSION);
475:
476: $result['general']['isAllowedGuestCheckout'] = (int)Mage::getSingleton('checkout/session')
477: ->getQuote()->isAllowedGuestCheckout();
478:
479: 480: 481:
482: if (Mage::helper('review')->getIsGuestAllowToWrite()) {
483: $result['general']['isAllowedGuestReview'] = '1';
484: } else {
485: $result['general']['isAllowedGuestReview'] = '0';
486: }
487:
488: 489: 490:
491: if (Mage::getStoreConfigFlag('wishlist/general/active')) {
492: $result['general']['wishlistEnable'] = '1';
493: } else {
494: $result['general']['wishlistEnable'] = '0';
495: }
496:
497: 498: 499:
500: $result['general']['useSecureURLInFrontend'] = $this->getUseSecureURLInFrontend();
501:
502: 503: 504:
505: if (is_object(Mage::getConfig()->getNode('modules/Enterprise_CustomerBalance'))) {
506: $storeCreditFlag = Mage::getStoreConfig(Enterprise_CustomerBalance_Helper_Data::XML_PATH_ENABLED);
507: $isStoreCreditEnable = (int)$storeCreditFlag;
508: $canShowHistoryFlag = (int) Mage::getStoreConfigFlag(
509: 'customer/enterprise_customerbalance/show_history'
510: );
511: } else {
512: $isStoreCreditEnable = $canShowHistoryFlag = 0;
513: }
514: $result['general']['isStoreCreditEnabled'] = $isStoreCreditEnable;
515: $result['general']['isStoreCreditHistoryEnabled'] = $canShowHistoryFlag;
516:
517: 518: 519:
520: $result['general']['isGiftcardEnabled'] = (int) is_object(
521: Mage::getConfig()->getNode('modules/Enterprise_GiftCard')
522: );
523:
524: 525: 526:
527: $result['paypal']['businessAccount'] = Mage::getModel('paypal/config')->businessAccount;
528: $result['paypal']['merchantLabel'] = $this->getData('conf/special/merchantLabel');
529:
530: $isActive = 0;
531: $paypalMepIsAvailable = Mage::getModel('xmlconnect/payment_method_paypal_mep')->isAvailable(null);
532: if ($paypalMepIsAvailable && isset($result['paypal']['isActive'])) {
533: $isActive = (int) $result['paypal']['isActive'];
534: }
535: $result['paypal']['isActive'] = $isActive;
536:
537: $paypalMeclIsAvailable = Mage::getModel('xmlconnect/payment_method_paypal_mecl')->isAvailable(null);
538:
539: 540: 541:
542: $result['paypalMecl']['isActive'] = (int) (
543: $paypalMeclIsAvailable
544: && $this->getData('config_data/payment/paypalmecl_is_active')
545: );
546:
547: if ((int)Mage::getStoreConfig(self::XML_PATH_GENERAL_RESTRICTION_IS_ACTIVE)) {
548: $result['website_restrictions']['mode'] = (int)Mage::getStoreConfig(
549: self::XML_PATH_GENERAL_RESTRICTION_MODE
550: );
551: }
552:
553: ksort($result);
554: return $result;
555: }
556:
557: 558: 559: 560: 561:
562: public function getSecureBaseUrl()
563: {
564: return Mage::getStoreConfig(self::XML_PATH_SECURE_BASE_LINK_URL, $this->getStoreId());
565: }
566:
567: 568: 569: 570: 571:
572: public function getUseSecureURLInFrontend()
573: {
574: return (int) Mage::getStoreConfigFlag(Mage_Core_Model_Store::XML_PATH_SECURE_IN_FRONTEND);
575: }
576:
577: 578: 579: 580: 581:
582: public function getScreenSize()
583: {
584: if (!isset($this->_data['screen_size'])) {
585: $this->_data['screen_size'] = self::APP_SCREEN_SIZE_DEFAULT;
586: }
587: return $this->_data['screen_size'];
588: }
589:
590: 591: 592: 593: 594: 595: 596:
597: public function setScreenSize($screenSize)
598: {
599: $this->_data['screen_size'] = Mage::helper('xmlconnect/image')->filterScreenSize((string) $screenSize);
600: return $this;
601: }
602:
603: 604: 605: 606: 607:
608: public function getEnabledTabsArray()
609: {
610: if ($this->getData('conf/extra/tabs')) {
611: return Mage::getModel('xmlconnect/tabs', $this->getData('conf/extra/tabs'))->getRenderTabs();
612: }
613: return array();
614: }
615:
616: 617: 618: 619: 620: 621:
622: protected function _absPath($subtree)
623: {
624: foreach ($subtree as $key => $value) {
625: if (!empty($value)) {
626: if (is_array($value)) {
627: $subtree[$key] = $this->_absPath($value);
628: } elseif (strtolower(substr($key, -4)) == 'icon' || strtolower(substr($key, -5)) == 'image') {
629: $subtree[$key] = Mage::getBaseUrl('media') . 'xmlconnect/' . $value;
630: }
631: }
632: }
633: return $subtree;
634: }
635:
636: 637: 638: 639: 640:
641: public function getPages()
642: {
643: if (isset($this->_data['conf']['native']['pages'])) {
644: return $this->_data['conf']['native']['pages'];
645: }
646: return array();
647: }
648:
649: 650: 651: 652: 653:
654: public function getConfigModel()
655: {
656: return $this->_configModel;
657: }
658:
659: 660: 661: 662: 663:
664: protected function _beforeSave()
665: {
666: $this->setUpdatedAt(Mage::getSingleton('core/date')->gmtDate());
667: return $this;
668: }
669:
670: 671: 672: 673: 674:
675: protected function _afterSave()
676: {
677: $this->_saveConfigData();
678: $this->_saveDeprecatedConfig();
679: parent::_afterSave();
680: return $this;
681: }
682:
683: 684: 685: 686: 687:
688: protected function _saveConfigData()
689: {
690: $configuration = $this->getData('config_data');
691: if (is_array($configuration)) {
692: $this->getConfigModel()->setConfigData($this->getId(), $configuration)->initSaveConfig();
693: }
694: return $this;
695: }
696:
697: 698: 699: 700: 701: 702:
703: private function _saveDeprecatedConfig()
704: {
705: $deprecatedConfig = $this->getData('conf');
706: if (is_array($deprecatedConfig)) {
707: $this->getConfigModel()->saveConfig(
708: $this->getId(), $this->convertOldConfing($deprecatedConfig), self::DEPRECATED_CONFIG_FLAG
709: );
710: }
711: return $this;
712: }
713:
714: 715: 716: 717: 718: 719: 720: 721:
722: public function convertOldConfing(array $conf, $path = false)
723: {
724: $result = array();
725: foreach ($conf as $key => $val) {
726: $key = $path ? $path . '/' . $key : $key;
727: if (is_array($val)) {
728: $result += $this->convertOldConfing($val, $key);
729: } else {
730: $result[$key] = $val;
731: }
732: }
733: return $result;
734: }
735:
736: 737: 738: 739: 740:
741: public function loadConfiguration()
742: {
743: if (!$this->_isConfigurationLoaded) {
744: if ($this->getId()) {
745: $this->_loadDeprecatedConfig()->_loadConfigData();
746: $this->_isConfigurationLoaded = true;
747: }
748: }
749: return $this;
750: }
751:
752: 753: 754: 755: 756: 757:
758: protected function _loadConfigData()
759: {
760: $configuration = $this->getConfigModel()->getCollection()->addArrayFilter(array(
761: 'application_id' => $this->getId(),
762: 'category' => 'payment'
763: ))->toOptionArray();
764:
765: $this->setData('config_data', $configuration);
766: return $this;
767: }
768:
769: 770: 771: 772: 773: 774:
775: private function _loadDeprecatedConfig()
776: {
777: $configuration = $this->_convertConfig(
778: $this->getConfigModel()->getCollection()->addArrayFilter(array(
779: 'application_id' => $this->getId(),
780: 'category' => self::DEPRECATED_CONFIG_FLAG
781: ))->toOptionArray()
782: );
783: $this->setData('conf', $configuration);
784: return $this;
785: }
786:
787: 788: 789: 790: 791: 792: 793:
794: protected function _convertConfig($config)
795: {
796: $result = array();
797: foreach ($config as $values) {
798: foreach ($values as $path => $value) {
799: if (preg_match('@[^\w\/]@', $path)) {
800: Mage::throwException(
801: Mage::helper('xmlconnect')->__('Unsupported character in path: "%s"', $path)
802: );
803: }
804: $keyArray = explode('/', $path);
805: $keys = '$result["' . implode('"]["', $keyArray) . '"]';
806: eval($keys . ' = $value;');
807: }
808: }
809: return $result;
810: }
811:
812: 813: 814: 815: 816: 817:
818: public function loadByCode($code)
819: {
820: $this->_getResource()->load($this, $code, 'code');
821: return $this;
822: }
823:
824: 825: 826: 827: 828:
829: public function loadSubmit()
830: {
831: $isResubmitAction = false;
832: if ($this->getId()) {
833: $params = $this->getLastParams();
834: if (!empty($params)) {
835:
836: $conf = &$this->_data['conf'];
837: if (!isset($conf['submit_text']) || !is_array($conf['submit_text'])) {
838: $conf['submit_text'] = array();
839: }
840: if (!isset($conf['submit_restore']) || !is_array($conf['submit_restore'])) {
841: $conf['submit_restore'] = array();
842: }
843: foreach ($params as $id => $value) {
844: $deviceImages = Mage::helper('xmlconnect')->getDeviceHelper()->getSubmitImages();
845:
846: if (!in_array($id, $deviceImages)) {
847: $conf['submit_text'][$id] = $value;
848: } else {
849: $conf['submit_restore'][$id] = $value;
850: }
851: $isResubmitAction = true;
852: }
853: }
854: }
855: $this->setIsResubmitAction($isResubmitAction);
856: return $isResubmitAction;
857: }
858:
859: 860: 861: 862: 863:
864: public function getImages()
865: {
866: $images = array();
867: $params = $this->getLastParams();
868: $deviceImages = Mage::helper('xmlconnect')
869: ->getDeviceHelper()
870: ->getSubmitImages();
871:
872: foreach ($deviceImages as $id) {
873: $path = $this->getData('conf/submit/'.$id);
874: $basename = null;
875: if (!empty($path)) {
876: 877: 878:
879: $basename = basename($path);
880: } elseif (isset($params[$id])) {
881: 882: 883: 884: 885: 886:
887: $basename = basename($params[$id]);
888: }
889: if (!empty($basename)) {
890: $images['conf/submit/'.$id] = Mage::getBaseUrl('media') . 'xmlconnect/'
891: . Mage::helper('xmlconnect/image')->getFileDefaultSizeSuffixAsUrl($basename);
892: }
893: }
894: return $images;
895: }
896:
897: 898: 899: 900: 901:
902: public function getLastParams()
903: {
904: if (!isset($this->_lastParams)) {
905: $this->_lastParams = Mage::getModel('xmlconnect/history')->getLastParams($this->getId());
906: }
907: return $this->_lastParams;
908: }
909:
910: 911: 912: 913: 914:
915: public function validate()
916: {
917: $errors = array();
918:
919: $validateConf = $this->_validateConf();
920: if ($validateConf !== true) {
921: $errors = $validateConf;
922: }
923:
924: if (!Zend_Validate::is($this->getName(), 'NotEmpty')) {
925: $errors[] = Mage::helper('xmlconnect')->__('Please enter "App Title".');
926: }
927:
928: if (empty($errors)) {
929: return true;
930: }
931: return $errors;
932: }
933:
934: 935: 936: 937: 938: 939:
940: public function validateSubmit($params)
941: {
942: $errors = array();
943: $validateConf = $this->_validateConf();
944: if ($validateConf !== true) {
945: $errors = $validateConf;
946: }
947:
948: $submitErrors = Mage::helper('xmlconnect')->getDeviceHelper($this)->validateSubmit($params);
949:
950: if (count($submitErrors)) {
951: $errors = array_merge($errors, $submitErrors);
952: }
953: if (empty($errors)) {
954: return true;
955: }
956: return $errors;
957: }
958:
959: 960: 961: 962: 963:
964: protected function _validateConf()
965: {
966: $conf = $this->getConf();
967: $native = isset($conf['native']) && is_array($conf['native']) ? $conf['native'] : false;
968: $errors = Mage::helper('xmlconnect')->getDeviceHelper($this)->validateConfig($native);
969:
970: foreach ($this->_socialNetValidationArray as $networkKey) {
971: if (isset($native['socialNetworking'][$networkKey]['isActive'])
972: && $native['socialNetworking'][$networkKey]['isActive']
973: ) {
974: if ($networkKey !== Mage_XmlConnect_Helper_Data::SOCIAL_NETWORK_FACEBOOK) {
975: $networkName = ucfirst($networkKey);
976: if (!isset($native['socialNetworking'][$networkKey]['apiKey'])
977: || !Zend_Validate::is($native['socialNetworking'][$networkKey]['apiKey'], 'NotEmpty')
978: ) {
979: $errors[] = Mage::helper('xmlconnect')->__('%s API Key required.', $networkName);
980: }
981: if (!isset($native['socialNetworking'][$networkKey]['secretKey'])
982: || !Zend_Validate::is($native['socialNetworking'][$networkKey]['secretKey'], 'NotEmpty')
983: ) {
984: $errors[] = Mage::helper('xmlconnect')->__('%s Secret Key required.', $networkName);
985: }
986: } else {
987: $networkName = ucfirst($networkKey);
988: if (!isset($native['socialNetworking'][$networkKey]['appID'])
989: || !Zend_Validate::is($native['socialNetworking'][$networkKey]['appID'], 'NotEmpty')
990: ) {
991: $errors[] = Mage::helper('xmlconnect')->__('%s Application ID required.', $networkName);
992: }
993: }
994: }
995: }
996:
997: if (empty($errors)) {
998: return true;
999: }
1000: return $errors;
1001: }
1002:
1003: 1004: 1005: 1006: 1007: 1008:
1009: public function prepareSubmitParams($data)
1010: {
1011: $params = array();
1012: if (isset($data['conf']) && is_array($data['conf'])) {
1013:
1014: if (isset($data['conf']['submit_text']) && is_array($data['conf']['submit_text'])) {
1015: $params = $data['conf']['submit_text'];
1016: }
1017:
1018: $params['name'] = $this->getName();
1019: $params['code'] = $this->getCode();
1020: $params['type'] = $this->getType();
1021: $params['url'] = Mage::getUrl('xmlconnect/configuration/index', array(
1022: '_store' => $this->getStoreId(), '_nosid' => true, 'app_code' => $this->getCode()
1023: ));
1024:
1025: $params['magentoversion'] = Mage::getVersion();
1026:
1027: if (isset($params['country']) && is_array($params['country'])) {
1028: $params['country'] = implode(',', $params['country']);
1029: }
1030: if ($this->getIsResubmitAction()) {
1031: if (isset($params['resubmission_activation_key'])) {
1032: $params['resubmission_activation_key'] = trim($params['resubmission_activation_key']);
1033: $params['key'] = $params['resubmission_activation_key'];
1034: } else {
1035: $params['key'] = '';
1036: }
1037: } else {
1038: $params['key'] = isset($params['key']) ? trim($params['key']) : '';
1039: }
1040:
1041:
1042: $submit = array();
1043: if (isset($this->_data['conf']['submit']) && is_array($this->_data['conf']['submit'])) {
1044: $submit = $this->_data['conf']['submit'];
1045: }
1046:
1047: $submitRestore = array();
1048: if (isset($this->_data['conf']['submit_restore']) && is_array($this->_data['conf']['submit_restore'])) {
1049: $submitRestore = $this->_data['conf']['submit_restore'];
1050: }
1051:
1052: $deviceImages = Mage::helper('xmlconnect')->getDeviceHelper()->getSubmitImages();
1053:
1054: foreach ($deviceImages as $id) {
1055: if (isset($submit[$id])) {
1056: $params[$id] = '@' . Mage::helper('xmlconnect/image')->getDefaultSizeUploadDir() . DS
1057: . $submit[$id];
1058: } elseif (isset($submitRestore[$id])) {
1059: $params[$id] = $submitRestore[$id];
1060: }
1061: }
1062: }
1063: $this->setSubmitParams($params);
1064: return $params;
1065: }
1066:
1067: 1068: 1069: 1070: 1071:
1072: public function getStoreId()
1073: {
1074: if ($this->hasData('store_id')) {
1075: return $this->getData('store_id');
1076: }
1077: return Mage::app()->getStore()->getId();
1078: }
1079:
1080: 1081: 1082: 1083: 1084:
1085: public function getActivationKey()
1086: {
1087: $key = null;
1088: if (isset($this->_data['conf']['submit_text']['key'])) {
1089: $key = $this->_data['conf']['submit_text']['key'];
1090: }
1091: return $key;
1092: }
1093:
1094: 1095: 1096: 1097: 1098:
1099: public function updateAllAppsUpdatedAtParameter()
1100: {
1101: $this->_getResource()->updateAllAppsUpdatedAtParameter();
1102: return $this;
1103: }
1104:
1105: 1106: 1107: 1108: 1109:
1110: public function isNotificationsActive()
1111: {
1112: return (boolean)$this->loadConfiguration()->getData('conf/native/notifications/isActive');
1113: }
1114:
1115: 1116: 1117: 1118: 1119:
1120: public function getUserpwd()
1121: {
1122: return $this->loadConfiguration()->getAppKey() . ':' . $this->getAppMasterSecret();
1123: }
1124:
1125: 1126: 1127: 1128: 1129:
1130: public function getAppKey()
1131: {
1132: return $this->getData('conf/native/notifications/applicationKey');
1133: }
1134:
1135: 1136: 1137: 1138: 1139:
1140: public function getAppSecret()
1141: {
1142: return $this->getData('conf/native/notifications/applicationSecret');
1143: }
1144:
1145: 1146: 1147: 1148: 1149:
1150: public function getAppMasterSecret()
1151: {
1152: return $this->getData('conf/native/notifications/applicationMasterSecret');
1153: }
1154:
1155: 1156: 1157: 1158: 1159:
1160: public function getCacheLifetime()
1161: {
1162: $lifetime = (int)$this->loadConfiguration()->getData('conf/native/cacheLifetime');
1163: return $lifetime <= 0 ? '' : $lifetime;
1164: }
1165:
1166: 1167: 1168: 1169: 1170:
1171: public function getDeleteOnUpdateConfig()
1172: {
1173: return $this->_deleteOnUpdateConfig;
1174: }
1175:
1176: 1177: 1178: 1179: 1180: 1181:
1182: public function setDeleteOnUpdateConfig(array $pathsToDelete)
1183: {
1184: $this->_deleteOnUpdateConfig = array_merge($this->_deleteOnUpdateConfig, $pathsToDelete);
1185: return $this;
1186: }
1187: }
1188: