1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_Adminhtml
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27:
28: /**
29: * Adminhtml backend model for "Custom Admin URL" option
30: *
31: * @category Mage
32: * @package Mage_Adminhtml
33: * @author Magento Core Team <core@magentocommerce.com>
34: */
35: class Mage_Adminhtml_Model_System_Config_Backend_Admin_Custom extends Mage_Core_Model_Config_Data
36: {
37: const CONFIG_SCOPE = 'stores';
38: const CONFIG_SCOPE_ID = 0;
39:
40: const XML_PATH_UNSECURE_BASE_URL = 'web/unsecure/base_url';
41: const XML_PATH_SECURE_BASE_URL = 'web/secure/base_url';
42: const XML_PATH_UNSECURE_BASE_LINK_URL = 'web/unsecure/base_link_url';
43: const XML_PATH_SECURE_BASE_LINK_URL = 'web/secure/base_link_url';
44:
45: /**
46: * Validate value before save
47: *
48: * @return Mage_Adminhtml_Model_System_Config_Backend_Admin_Custom
49: */
50: protected function _beforeSave()
51: {
52: $value = $this->getValue();
53:
54: if (!empty($value) && substr($value, -2) !== '}}') {
55: $value = rtrim($value, '/').'/';
56: }
57:
58: $this->setValue($value);
59: return $this;
60: }
61:
62: /**
63: * Change secure/unsecure base_url after use_custom_url was modified
64: *
65: * @return Mage_Adminhtml_Model_System_Config_Backend_Admin_Custom
66: */
67: public function _afterSave()
68: {
69: $useCustomUrl = $this->getData('groups/url/fields/use_custom/value');
70: $value = $this->getValue();
71:
72: if ($useCustomUrl == 1 && empty($value)) {
73: return $this;
74: }
75:
76: if ($useCustomUrl == 1) {
77: Mage::getConfig()->saveConfig(
78: self::XML_PATH_SECURE_BASE_URL,
79: $value,
80: self::CONFIG_SCOPE,
81: self::CONFIG_SCOPE_ID
82: );
83: Mage::getConfig()->saveConfig(
84: self::XML_PATH_UNSECURE_BASE_URL,
85: $value,
86: self::CONFIG_SCOPE,
87: self::CONFIG_SCOPE_ID
88: );
89: }
90:
91: return $this;
92: }
93: }
94: