PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 11.0.2
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v11.0.2
11.1.1 11.1.0 11.0.5 11.0.4 11.0.3 11.0.2 11.0.1 11.0.0 10.11.1 10.11.0 10.10.2 10.10.1 10.10.0 10.9.1 trunk 10.0.0 10.0.1 10.1.0 10.1.1 10.1.2 10.1.3 10.1.4 10.2.0 10.2.1 10.2.2 All 62 releases
acymailing / back / Helpers / global / url.php

url.php in AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress 11.0.2, at back/Helpers/global/url.php

187 lines 6.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 defined('ABSPATH') || die('Restricted Access');
3
4 function acym_absoluteURL(string $text): string
5 {
6 static $mainurl = '';
7 if (empty($mainurl)) {
8 $urls = acym_parseUrl(ACYM_LIVE);
9 if (!empty($urls['path'])) {
10 $mainurl = substr(ACYM_LIVE, 0, strrpos(ACYM_LIVE, $urls['path'])).'/';
11 } else {
12 $mainurl = ACYM_LIVE;
13 }
14 }
15
16 //It will remove the undefined thing added by tinyMCE
17 // And URL with twice the domain
18 $text = str_replace(
19 [
20 'href="../undefined/',
21 'href="../../undefined/',
22 'href="../../../undefined//',
23 'href="undefined/',
24 ACYM_LIVE.'http://',
25 ACYM_LIVE.'https://',
26 ],
27 [
28 'href="'.$mainurl,
29 'href="'.$mainurl,
30 'href="'.$mainurl,
31 'href="'.ACYM_LIVE,
32 'http://',
33 'https://',
34 ],
35 $text
36 );
37 //We remove errors with /administrator links and our tags
38 //We replace /{ by { , it's also a bug with the editor...
39 $text = preg_replace('#href="(/?administrator)?/({|%7B)#Ui', 'href="$2', $text);
40
41 //We replace http:/ by http:// , it will avoid a user bug! seriously we are nice guys...
42 $text = preg_replace('#href="http:/([^/])#Ui', 'href="http://$1', $text);
43
44 //Sometimes clients add links without http:// but directly with their website url... let's try to catch some of these errors
45 $text = preg_replace(
46 '#href="'.preg_quote(str_replace(['http://', 'https://'], '', $mainurl), '#').'#Ui',
47 'href="'.$mainurl,
48 $text
49 );
50
51 $replace = [];
52 $replaceBy = [];
53 //We don't convert urls starting with { or [ into absolute url otherwise it could break a tag
54 //WE don't modify links starting with \\ as it replaces the protocole http / https
55 if ($mainurl !== ACYM_LIVE) {
56 //url like ../ your site...
57 //We don't transform mailto: # http:// ...
58
59 $replace[] = '#(href|src|action|background)[ ]*=[ ]*\"(?!(\{|%7B|\[|\#|\\\\|[a-z]{3,15}:|/))(?:\.\./)#i';
60 $replaceBy[] = '$1="'.substr(ACYM_LIVE, 0, strrpos(rtrim(ACYM_LIVE, '/'), '/') + 1);
61
62 //sub folder : substr(ACYM_LIVE,strrpos(rtrim(ACYM_LIVE,'/'),'/'))
63 //We remove the sub folder if there is a tag... otherwise we will break the whole thing.
64 //We had an issue with that when selecting the readonline link via the front-end
65
66 $subfolder = substr(ACYM_LIVE, strrpos(rtrim(ACYM_LIVE, '/'), '/'));
67 $replace[] = '#(href|src|action|background)[ ]*=[ ]*\"'.preg_quote($subfolder, '#').'(\{|%7B)#i';
68 $replaceBy[] = '$1="$2';
69 }
70
71 $replace[] = '#(href|src|action|background)[ ]*=[ ]*\"(?!(\{|%7B|\[|\#|\\\\|[a-z]{3,15}:|/))(?:\.\./|\./)?#i';
72 $replaceBy[] = '$1="'.ACYM_LIVE;
73 $replace[] = '#(href|src|action|background)[ ]*=[ ]*\"(?!(\{|%7B|\[|\#|\\\\|[a-z]{3,15}:))/#i';
74 $replaceBy[] = '$1="'.$mainurl;
75
76 //background images for div
77 $replace[] = '#((?:background-image|background)[ ]*:[ ]*url\((?:\'|"|&quot;)?(?!(\\\\|[a-z]{3,15}:|/|\'|"|&quot;))(?:\.\./|\./)?)#i';
78 $replaceBy[] = '$1'.ACYM_LIVE;
79
80 return preg_replace($replace, $replaceBy, $text);
81 }
82
83 function acym_mainURL(string &$link): string
84 {
85 static $baseUrl = '';
86 static $otherArguments = false;
87 if (empty($baseUrl)) {
88 $urls = acym_parseUrl(ACYM_LIVE);
89 if (isset($urls['path']) && strlen($urls['path']) > 0) {
90 $baseUrl = substr(ACYM_LIVE, 0, strrpos(ACYM_LIVE, $urls['path'])).'/';
91 $otherArguments = trim(str_replace($baseUrl, '', ACYM_LIVE), '/');
92 if (strlen($otherArguments) > 0) {
93 $otherArguments .= '/';
94 }
95 } else {
96 $baseUrl = ACYM_LIVE;
97 }
98 }
99
100 if ($otherArguments && strpos($link, $otherArguments) === false) {
101 $link = $otherArguments.$link;
102 }
103
104 return $baseUrl;
105 }
106
107 function acym_currentURL(): string
108 {
109 $protocol = isset($_SERVER['HTTPS']) || !empty($_SERVER['HTTP_UPGRADE_INSECURE_REQUESTS']) ? 'https' : 'http';
110
111 $httpHost = acym_getVar('string', 'HTTP_HOST', '', 'SERVER');
112 $serverName = acym_getVar('string', 'SERVER_NAME', '', 'SERVER');
113
114 $host = empty($httpHost)
115 ? (
116 empty($serverName)
117 ? getenv('HTTP_HOST')
118 : $serverName
119 )
120 : $httpHost;
121
122 $requestUri = acym_getVar('string', 'REQUEST_URI', '', 'SERVER');
123
124 return $protocol.'://'.$host.$requestUri;
125 }
126
127 function acym_cleanUrl(string $url, array $parametersToRemove): string
128 {
129 $parts = acym_parseUrl($url);
130
131 if (empty($parts['query'])) {
132 return $url;
133 }
134
135 $queryParams = [];
136 parse_str($parts['query'], $queryParams);
137
138 foreach ($parametersToRemove as $parameter) {
139 unset($queryParams[$parameter]);
140 }
141
142 return $parts['scheme'].'://'.$parts['host'].$parts['path'].'?'.http_build_query($queryParams);
143 }
144
145 function acym_isLocalWebsite(): bool
146 {
147 return strpos(ACYM_LIVE, 'localhost') !== false || strpos(ACYM_LIVE, '127.0.0.1') !== false;
148 }
149
150 function acym_internalUrlToPath(string $url): string
151 {
152 $base = str_replace(['http://www.', 'https://www.', 'http://', 'https://'], '', ACYM_LIVE);
153 $replacements = ['https://www.'.$base, 'http://www.'.$base, 'https://'.$base, 'http://'.$base];
154 foreach ($replacements as $oneReplacement) {
155 if (strpos($url, $oneReplacement) === false) {
156 continue;
157 }
158
159 return str_replace([$oneReplacement, '/'], [ACYM_ROOT, DS], urldecode($url));
160 }
161
162 return $url;
163 }
164
165 function acym_isValidUrl(string $url): bool
166 {
167 // If this option is not activated in the php.ini file, we return true because the function get_headers will not work
168 if (empty(ini_get('allow_url_fopen'))) {
169 return true;
170 }
171 // If we detect youtu.be url, we don't check the headers because it's a redirection to a valid Url
172 if (strpos($url, 'youtu.be') !== false) {
173 return true;
174 }
175
176 $headers = @get_headers($url);
177
178 return !empty($headers) && strpos($headers[0], '200');
179 }
180
181 function acym_isImageUrl(string $url): bool
182 {
183 $extension = strtolower(pathinfo($url, PATHINFO_EXTENSION));
184
185 return in_array($extension, acym_getImageFileExtensions(true));
186 }
187