-
Notifications
You must be signed in to change notification settings - Fork 53
/
domain-mapping.php
executable file
·224 lines (193 loc) · 7.73 KB
/
domain-mapping.php
1
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<?php
/*
Plugin Name: Domain Mapping
Plugin URI: https://premium.wpmudev.org/project/domain-mapping/
Description: The ultimate Multisite domain mapping plugin - sync cookies, sell domains with eNom, and integrate with Pro Sites.
Version: 4.4.3.4
Author: WPMU DEV
Author URI: http://premium.wpmudev.org
WDP ID: 99
Network: true
*/
// +----------------------------------------------------------------------+
// | Copyright Incsub (http://incsub.com/) |
// | Based on an original by Donncha (http://ocaoimh.ie/) |
// +----------------------------------------------------------------------+
// | This program is free software; you can redistribute it and/or modify |
// | it under the terms of the GNU General Public License, version 2, as |
// | published by the Free Software Foundation. |
// | |
// | This program is distributed in the hope that it will be useful, |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
// | GNU General Public License for more details. |
// | |
// | You should have received a copy of the GNU General Public License |
// | along with this program; if not, write to the Free Software |
// | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, |
// | MA 02110-1301 USA |
// +----------------------------------------------------------------------+
// prevent non multisite usage or reloading the plugin, if it has been already loaded
if ( !is_multisite() || class_exists( 'Domainmap_Plugin', false ) ) {
return;
}
// UnComment the line below to allow multiple domain mappings per blog
//define('DOMAINMAPPING_ALLOWMULTI', true);
// main domain mapping class
require_once 'inc/DM_Currencies.php';
require_once 'classes/class.domainmap.php';
/**
* Automatically loads classes for the plugin. Checks a namespace and loads only
* approved classes.
*
* @since 4.0.0
*
* @param string $class The class name to autoload.
* @return boolean Returns TRUE if the class is located. Otherwise FALSE.
*/
function domainmap_autoloader( $class ) {
$basedir = dirname( __FILE__ );
$namespaces = array( 'Domainmap', "Vendor" );
foreach ( $namespaces as $namespace ) {
if ( substr( $class, 0, strlen( $namespace ) ) == $namespace ) {
$filename = $basedir . str_replace( '_', DIRECTORY_SEPARATOR, "_classes_{$class}.php" );
if ( is_readable( $filename ) ) {
require $filename;
return true;
}
}
if( $namespace === "Vendor" ){
$filename = $basedir . str_replace( '_', DIRECTORY_SEPARATOR, "_classes_Vendor_{$class}.php" );
if ( is_readable( $filename ) ) {
require $filename;
return true;
}
}
}
return false;
}
/**
* Setups domain mapping constants.
*
* @since 4.1.2
*
* @global wpdb $wpdb The instance of database connection.
*/
function domainmap_setup_constants() {
global $wpdb;
// setup environment
define( 'DOMAINMAP_BASEFILE', __FILE__ );
define( 'DOMAINMAP_ABSURL', plugins_url( '/', __FILE__ ) );
define( 'DOMAINMAP_ABSPATH', dirname( __FILE__ ) );
/**
* @deprecate DM_FORCE_PROTOCOL_ON_MAPPED_DOMAIN
*/
// if ( !defined( 'DM_FORCE_PROTOCOL_ON_MAPPED_DOMAIN' ) ) {
// define( 'DM_FORCE_PROTOCOL_ON_MAPPED_DOMAIN', false );
// }
/**
* @deprecate DOMAINMAPPING_ALLOWMULTI
*/
// if ( !defined( 'DOMAINMAPPING_ALLOWMULTI' ) ) {
// define( 'DOMAINMAPPING_ALLOWMULTI', false );
// }
// setup db tables
$prefix = isset( $wpdb->base_prefix ) ? $wpdb->base_prefix : $wpdb->prefix;
define( 'DOMAINMAP_TABLE_MAP', "{$prefix}domain_mapping" );
define( 'DOMAINMAP_TABLE_RESELLER_LOG', "{$prefix}domain_mapping_reseller_log" );
// MultiDB compatibility, register global tables
if ( defined( 'MULTI_DB_VERSION' ) && function_exists( 'add_global_table' ) ) {
add_global_table( 'domain_mapping' );
add_global_table( 'domain_mapping_reseller_log' );
}
}
/**
* Instantiates the plugin and setup all modules.
*
* @since 4.0.0
*
* @global domain_map $dm_map The instance of domain_map class.
*/
function domainmap_launch() {
global $dm_map;
domainmap_setup_constants();
// set up the plugin core class
$dm_map = new domain_map();
// instantiate the plugin
$plugin = Domainmap_Plugin::instance();
// set general modules
$plugin->set_module( Domainmap_Module_System::NAME );
$plugin->set_module( Domainmap_Module_Setup::NAME );
$plugin->set_module( Domainmap_Module_Mapping::NAME );
// CDSSO module
if ( defined( 'SUNRISE' ) && filter_var( SUNRISE, FILTER_VALIDATE_BOOLEAN ) && $plugin->get_option( 'map_crossautologin' ) ) {
$plugin->set_module( Domainmap_Module_Cdsso::NAME );
}
// conditional modules
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
// suppresses errors rendering to prevent unexpected issues
set_error_handler( '__return_true' );
set_exception_handler( '__return_true' );
// set ajax modules
$plugin->set_module( Domainmap_Module_Ajax_Map::NAME );
$plugin->set_module( Domainmap_Module_Ajax_Purchase::NAME );
$plugin->set_module( Domainmap_Module_Ajax_Register::NAME );
} else {
if ( is_admin() ) {
// set admin modules
$plugin->set_module( Domainmap_Module_Pages::NAME );
$plugin->set_module( Domainmap_Module_Admin::NAME );
}
}
}
// register autoloader function
spl_autoload_register( 'domainmap_autoloader' );
// launch the plugin
domainmap_launch();
function domainmap_plugin_activate() {
do_action("domainmap_plugin_activated");
}
register_activation_hook( __FILE__, 'domainmap_plugin_activate' );
function domainmap_plugin_deactivate() {
do_action("domainmap_plugin_deactivated");
}
register_deactivation_hook( __FILE__, 'domainmap_plugin_deactivate' );
/*================== Global Functions =======================*/
/**
* Retrieves respective site url with original domain for current site checking weather it's an ssl connection
*
* Returns the 'site_url' option or unswapped site url if it's and ssl connection with the appropriate protocol, 'https' if
* is_ssl() and 'http' otherwise. If $scheme is 'http' or 'https', is_ssl() is
* overridden.
*
* @since 4.1.3
*
* @uses site_url()
*
* @param string $path Optional. Path relative to the site url.
* @param string $scheme Optional. Scheme to give the site url context. See set_url_scheme().
* @return string Site url link with optional path appended.
*/
function dm_site_url( $path = '', $scheme = null ){
$current_site_url = site_url( $path, $scheme );
return domain_map::utils()->unswap_url( $current_site_url, false, (bool) $path );
}
/**
* Retrieves respective home url with original domain for current site checking weather it's an ssl connection
*
* Returns the 'home' option or unswapped home url if it's and ssl connection with the appropriate protocol, 'https' if
* is_ssl() and 'http' otherwise. If $scheme is 'http' or 'https', is_ssl() is
* overridden.
*
* @since 4.1.3
*
* @uses home_url()
*
* @param string $path Optional. Path relative to the site url.
* @param string $scheme Optional. Scheme to give the site url context. See set_url_scheme().
* @return string Site url link with optional path appended.
*/
function dm_home_url( $path = '', $scheme = null ){
$current_home_url = home_url( $path, $scheme );
return domain_map::utils()->unswap_url( $current_home_url, false, (bool) $path );
}