| 1 |
<?php |
| 2 |
|
| 3 |
namespace Kibo\PhastPlugins\PhastPress; |
| 4 |
|
| 5 |
use Kibo\Phast\ValueObjects\URL; |
| 6 |
use Kibo\PhastPlugins\SDK\Common\PluginHostTrait; |
| 7 |
use Kibo\PhastPlugins\SDK\PluginHost; |
| 8 |
|
| 9 |
class PluginHostImplementation extends ServiceSDKImplementation implements PluginHost { |
| 10 |
use PluginHostTrait; |
| 11 |
|
| 12 |
public function getPluginName() { |
| 13 |
return 'PhastPress'; |
| 14 |
} |
| 15 |
|
| 16 |
public function getPluginHostName() { |
| 17 |
return 'PhastPress'; |
| 18 |
} |
| 19 |
|
| 20 |
public function getPluginHostVersion() { |
| 21 |
$plugin_info = get_file_data(PHASTPRESS_PLUGIN_FILE, ['Version' => 'Version']); |
| 22 |
return $plugin_info['Version']; |
| 23 |
} |
| 24 |
|
| 25 |
public function getKeyValueStore() { |
| 26 |
return new KeyValueStoreImplementation(); |
| 27 |
} |
| 28 |
|
| 29 |
public function getHostURLs() { |
| 30 |
return new HostURLsImplementation(); |
| 31 |
} |
| 32 |
|
| 33 |
public function getScriptSourceURLs() { |
| 34 |
$urls = [ |
| 35 |
home_url('/'), |
| 36 |
site_url('/'), |
| 37 |
content_url('/'), |
| 38 |
plugins_url('/'), |
| 39 |
includes_url('/'), |
| 40 |
]; |
| 41 |
|
| 42 |
if (is_multisite()) { |
| 43 |
$urls[] = network_home_url('/'); |
| 44 |
$urls[] = network_site_url('/'); |
| 45 |
} |
| 46 |
|
| 47 |
$hostURLs = $this->getHostURLs(); |
| 48 |
$urls = array_map([URL::class, 'fromString'], array_unique($urls)); |
| 49 |
$cdnURLs = []; |
| 50 |
foreach ($urls as $url) { |
| 51 |
$cdnURLs[] = $hostURLs->getCDNURL($url); |
| 52 |
} |
| 53 |
$urls = array_merge($urls, $cdnURLs); |
| 54 |
|
| 55 |
$unique = []; |
| 56 |
foreach ($urls as $url) { |
| 57 |
$unique[$url->toString()] = $url; |
| 58 |
} |
| 59 |
return array_values($unique); |
| 60 |
} |
| 61 |
|
| 62 |
public function getInstallNoticeRenderer() { |
| 63 |
return new InstallNoticeRendererImplementation(); |
| 64 |
} |
| 65 |
|
| 66 |
public function getNonce() { |
| 67 |
return NonceCheckerImplementation::makeNonce(); |
| 68 |
} |
| 69 |
|
| 70 |
public function getNonceChecker() { |
| 71 |
return new NonceCheckerImplementation(); |
| 72 |
} |
| 73 |
|
| 74 |
public function getPhastUser() { |
| 75 |
return new PhastUserImplementation(); |
| 76 |
} |
| 77 |
|
| 78 |
public function getSecurityTokenRoot() { |
| 79 |
if (defined('AUTH_KEY')) { |
| 80 |
return AUTH_KEY; |
| 81 |
} |
| 82 |
return null; |
| 83 |
} |
| 84 |
|
| 85 |
public function onPhastConfigurationLoad(array $config) { |
| 86 |
$nonce = apply_filters('phastpress_csp_nonce', null); |
| 87 |
if ($nonce !== null) { |
| 88 |
$config['csp']['nonce'] = $nonce; |
| 89 |
} |
| 90 |
|
| 91 |
return $config; |
| 92 |
} |
| 93 |
} |
| 94 |
|