Newer
Older
// Check if a path is fully a subpath of another - no way to create symlink in the case
if (count($a1) == 0 || count($a2) == 0) return false;
// Add ($cnt_to-1) number of "../" elements to left side of $cfrom
for ($c = 0; $c < (count($a2)-1); $c++) { $cfrom = '../'.$cfrom; }
return symlink($cfrom, $to);
}
private function _rewrite_quote($string) {
return str_replace(array('.', '*', '?', '+'), array('\\.', '\\*', '\\?', '\\+'), $string);
}
private function url_is_local($hostname, $domain_id){
global $app;
// ORDER BY clause makes sure wildcard subdomains (*) are listed last in the result array so that we can find direct matches first
$webs = $app->db->queryAllRecords("SELECT * FROM web_domain WHERE active = 'y' ORDER BY subdomain ASC");
if(is_array($webs) && !empty($webs)){
foreach($webs as $web){
// web domain doesn't match hostname
if(substr($hostname, -strlen($web['domain'])) != $web['domain']) continue;
// own vhost and therefore server {} container of its own
//if($web['type'] == 'vhostsubdomain' || $web['type'] == 'vhostalias') continue;
// alias domains/subdomains using rewrites and therefore a server {} container of their own
//if(($web['type'] == 'alias' || $web['type'] == 'subdomain') && $web['redirect_type'] != '' && $web['redirect_path'] != '') continue;
if($web['subdomain'] == '*'){
$pattern = '/\.?'.str_replace('.', '\.', $web['domain']).'$/i';
}
if($web['subdomain'] == 'none'){
if($web['domain'] == $hostname){
if($web['domain_id'] == $domain_id || $web['parent_domain_id'] == $domain_id){
// own vhost and therefore server {} container of its own
if($web['type'] == 'vhostsubdomain' || $web['type'] == 'vhostalias') return false;
// alias domains/subdomains using rewrites and therefore a server {} container of their own
if(($web['type'] == 'alias' || $web['type'] == 'subdomain') && $web['redirect_type'] != '' && $web['redirect_path'] != '') return false;
return true;
} else {
return false;
}
}
$pattern = '/^'.str_replace('.', '\.', $web['domain']).'$/i';
}
if($web['subdomain'] == 'www'){
if($web['domain'] == $hostname || $web['subdomain'].'.'.$web['domain'] == $hostname){
if($web['domain_id'] == $domain_id || $web['parent_domain_id'] == $domain_id){
// own vhost and therefore server {} container of its own
if($web['type'] == 'vhostsubdomain' || $web['type'] == 'vhostalias') return false;
// alias domains/subdomains using rewrites and therefore a server {} container of their own
if(($web['type'] == 'alias' || $web['type'] == 'subdomain') && $web['redirect_type'] != '' && $web['redirect_path'] != '') return false;
return true;
} else {
return false;
}
}
$pattern = '/^(www\.)?'.str_replace('.', '\.', $web['domain']).'$/i';
}
if(preg_match($pattern, $hostname)){
if($web['domain_id'] == $domain_id || $web['parent_domain_id'] == $domain_id){
// own vhost and therefore server {} container of its own
if($web['type'] == 'vhostsubdomain' || $web['type'] == 'vhostalias') return false;
// alias domains/subdomains using rewrites and therefore a server {} container of their own
if(($web['type'] == 'alias' || $web['type'] == 'subdomain') && $web['redirect_type'] != '' && $web['redirect_path'] != '') return false;
return true;
} else {
return false;
}
}
}
}
return false;
}
private function get_seo_redirects($web, $prefix = '', $force_subdomain = false){
// $force_subdomain = 'none|www'
$seo_redirects = array();
if(substr($web['domain'], 0, 2) === '*.') $web['subdomain'] = '*';
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
if(($web['subdomain'] == 'www' || $web['subdomain'] == '*') && $force_subdomain != 'www'){
if($web['seo_redirect'] == 'non_www_to_www'){
$seo_redirects[$prefix.'seo_redirect_origin_domain'] = $web['domain'];
$seo_redirects[$prefix.'seo_redirect_target_domain'] = 'www.'.$web['domain'];
$seo_redirects[$prefix.'seo_redirect_operator'] = '=';
}
if($web['seo_redirect'] == '*_domain_tld_to_www_domain_tld'){
// ^(example\.com|(?!\bwww\b)\.example\.com)$
// ^(example\.com|((?:\w+(?:-\w+)*\.)*)((?!www\.)\w+(?:-\w+)*)(\.example\.com))$
$seo_redirects[$prefix.'seo_redirect_origin_domain'] = '^('.str_replace('.', '\.', $web['domain']).'|((?:\w+(?:-\w+)*\.)*)((?!www\.)\w+(?:-\w+)*)(\.'.str_replace('.', '\.', $web['domain']).'))$';
$seo_redirects[$prefix.'seo_redirect_target_domain'] = 'www.'.$web['domain'];
$seo_redirects[$prefix.'seo_redirect_operator'] = '~*';
}
if($web['seo_redirect'] == '*_to_www_domain_tld'){
$seo_redirects[$prefix.'seo_redirect_origin_domain'] = 'www.'.$web['domain'];
$seo_redirects[$prefix.'seo_redirect_target_domain'] = 'www.'.$web['domain'];
$seo_redirects[$prefix.'seo_redirect_operator'] = '!=';
}
}
if($force_subdomain != 'none'){
if($web['seo_redirect'] == 'www_to_non_www'){
$seo_redirects[$prefix.'seo_redirect_origin_domain'] = 'www.'.$web['domain'];
$seo_redirects[$prefix.'seo_redirect_target_domain'] = $web['domain'];
$seo_redirects[$prefix.'seo_redirect_operator'] = '=';
}
if($web['seo_redirect'] == '*_domain_tld_to_domain_tld'){
// ^(.+)\.example\.com$
$seo_redirects[$prefix.'seo_redirect_origin_domain'] = '^(.+)\.'.str_replace('.', '\.', $web['domain']).'$';
$seo_redirects[$prefix.'seo_redirect_target_domain'] = $web['domain'];
$seo_redirects[$prefix.'seo_redirect_operator'] = '~*';
}
if($web['seo_redirect'] == '*_to_domain_tld'){
$seo_redirects[$prefix.'seo_redirect_origin_domain'] = $web['domain'];
$seo_redirects[$prefix.'seo_redirect_target_domain'] = $web['domain'];
$seo_redirects[$prefix.'seo_redirect_operator'] = '!=';
}
}
return $seo_redirects;
}
} // end class
?>