PluginProbe
Extendify / 3.1.5
Extendify v3.1.5
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / app / Shared / Services / ApexDomain / ApexDomain.php

ApexDomain.php in Extendify 3.1.5, at app/Shared/Services/ApexDomain/ApexDomain.php

61 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Imports the public suffix list.
5 */
6
7 namespace Extendify\Shared\Services\ApexDomain;
8
9 defined('ABSPATH') || die('No direct access.');
10
11 use Extendify\PartnerData;
12
13 /**
14 * Get the apex domain for a given URL.
15 */
16
17 class ApexDomain
18 {
19 /**
20 * Get the apex domain for a given URL.
21 *
22 * @param string $url - The URL to get the apex domain for.
23 * @return string|null
24 */
25 public static function getApexDomain($url)
26 {
27 $homeUrl = \wp_parse_url(\get_home_url(), PHP_URL_HOST);
28
29 if (get_transient('extendify_apex_domain') && get_transient('extendify_site_url') === $homeUrl) {
30 return get_transient('extendify_apex_domain');
31 }
32
33 if (!file_exists(__DIR__ . '/suffixes.php')) {
34 return null;
35 }
36
37 $suffixes = require 'suffixes.php';
38
39 if (!preg_match('~^(?:f|ht)tps?://~i', $url)) {
40 $url = 'http://' . $url;
41 }
42
43 $parsed = wp_parse_url($url, PHP_URL_HOST);
44 $domainParts = explode('.', $parsed);
45 $domainsPartsCount = count($domainParts);
46
47 for ($i = 0; $i < $domainsPartsCount; $i++) {
48 $candidate = implode('.', array_slice($domainParts, $i));
49 if (in_array($candidate, $suffixes, true)) {
50 $parsed = implode('.', array_slice($domainParts, ($i - 1)));
51 break;
52 }
53 }
54
55 set_transient('extendify_apex_domain', $parsed);
56 set_transient('extendify_home_url', $homeUrl);
57
58 return $parsed;
59 }
60 }
61