@@ -68,10 +68,10 @@ discard block |
||
| 68 | 68 | */ |
| 69 | 69 | public function __construct($plugin_name, $version) |
| 70 | 70 | { |
| 71 | - $this->plugin_name = $plugin_name; |
|
| 72 | - $this->version = $version; |
|
| 71 | + $this->plugin_name=$plugin_name; |
|
| 72 | + $this->version=$version; |
|
| 73 | 73 | |
| 74 | - self::$cache_cleared = get_transient('WORDPRESS_SECURITY_TXT_CACHE_CLEARED'); |
|
| 74 | + self::$cache_cleared=get_transient('WORDPRESS_SECURITY_TXT_CACHE_CLEARED'); |
|
| 75 | 75 | |
| 76 | 76 | if ($this->version != WORDPRESS_SECURITY_TXT_VERSION) { |
| 77 | 77 | throw new Exception('Internal version mismatch in plugin wordpress-security-txt; it needs to be reinstalled.'); |
@@ -85,18 +85,18 @@ discard block |
||
| 85 | 85 | */ |
| 86 | 86 | public function route() |
| 87 | 87 | { |
| 88 | - if (! isset($_SERVER) || ! isset($_SERVER['REQUEST_URI']) || ! isset($_SERVER['HTTP_HOST'])) { |
|
| 88 | + if (!isset($_SERVER) || !isset($_SERVER[ 'REQUEST_URI' ]) || !isset($_SERVER[ 'HTTP_HOST' ])) { |
|
| 89 | 89 | return; |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - $this->options = WordPress_Security_Txt_Admin::get_options($this->plugin_name); |
|
| 92 | + $this->options=WordPress_Security_Txt_Admin::get_options($this->plugin_name); |
|
| 93 | 93 | |
| 94 | - if (! is_array($this->options) || ! isset($this->options['enable']) || ! $this->options['enable']) { |
|
| 94 | + if (!is_array($this->options) || !isset($this->options[ 'enable' ]) || !$this->options[ 'enable' ]) { |
|
| 95 | 95 | return; |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - $request = ($this->is_secure() ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; |
|
| 99 | - $site = get_site_url(); |
|
| 98 | + $request=($this->is_secure() ? 'https' : 'http') . '://' . $_SERVER[ 'HTTP_HOST' ] . $_SERVER[ 'REQUEST_URI' ]; |
|
| 99 | + $site=get_site_url(); |
|
| 100 | 100 | |
| 101 | 101 | if (strpos($request, $site) !== 0) { |
| 102 | 102 | return; |
@@ -112,23 +112,23 @@ discard block |
||
| 112 | 112 | */ |
| 113 | 113 | private function apply_routes($uri) |
| 114 | 114 | { |
| 115 | - $routes = [ |
|
| 116 | - '/security.txt' => ['method' => 'redirect', 'document' => 'security.txt'], |
|
| 117 | - '/.well-known/security.txt' => ['method' => 'show', 'document' => 'security.txt'], |
|
| 115 | + $routes=[ |
|
| 116 | + '/security.txt' => [ 'method' => 'redirect', 'document' => 'security.txt' ], |
|
| 117 | + '/.well-known/security.txt' => [ 'method' => 'show', 'document' => 'security.txt' ], |
|
| 118 | 118 | ]; |
| 119 | 119 | |
| 120 | - if (isset($this->options['encryption']) && isset($this->options['encryption'])) { |
|
| 121 | - $routes = array_merge($routes, [ |
|
| 122 | - '/gpg.txt' => ['method' => 'redirect', 'document' => 'gpg.txt'], |
|
| 123 | - '/.well-known/gpg.txt' => ['method' => 'show', 'document' => 'gpg.txt'], |
|
| 120 | + if (isset($this->options[ 'encryption' ]) && isset($this->options[ 'encryption' ])) { |
|
| 121 | + $routes=array_merge($routes, [ |
|
| 122 | + '/gpg.txt' => [ 'method' => 'redirect', 'document' => 'gpg.txt' ], |
|
| 123 | + '/.well-known/gpg.txt' => [ 'method' => 'show', 'document' => 'gpg.txt' ], |
|
| 124 | 124 | ]); |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | - if (isset($routes[$uri])) { |
|
| 128 | - if ($routes[$uri]['method'] == 'redirect') { |
|
| 129 | - $this->redirect($routes[$uri]['document']); |
|
| 130 | - } elseif ($routes[$uri]['method'] == 'show') { |
|
| 131 | - $this->show($routes[$uri]['document']); |
|
| 127 | + if (isset($routes[ $uri ])) { |
|
| 128 | + if ($routes[ $uri ][ 'method' ] == 'redirect') { |
|
| 129 | + $this->redirect($routes[ $uri ][ 'document' ]); |
|
| 130 | + } elseif ($routes[ $uri ][ 'method' ] == 'show') { |
|
| 131 | + $this->show($routes[ $uri ][ 'document' ]); |
|
| 132 | 132 | } |
| 133 | 133 | } |
| 134 | 134 | } |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | */ |
| 142 | 142 | private function is_secure() |
| 143 | 143 | { |
| 144 | - return (! empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || $_SERVER['SERVER_PORT'] == 443; |
|
| 144 | + return (!empty($_SERVER[ 'HTTPS' ]) && $_SERVER[ 'HTTPS' ] !== 'off') || $_SERVER[ 'SERVER_PORT' ] == 443; |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | /** |
@@ -181,12 +181,12 @@ discard block |
||
| 181 | 181 | */ |
| 182 | 182 | public static function cache_clear() |
| 183 | 183 | { |
| 184 | - $cache_file = self::cache_file(); |
|
| 184 | + $cache_file=self::cache_file(); |
|
| 185 | 185 | |
| 186 | 186 | if (is_file($cache_file)) { |
| 187 | - $result = unlink($cache_file); |
|
| 187 | + $result=unlink($cache_file); |
|
| 188 | 188 | set_transient('WORDPRESS_SECURITY_TXT_CACHE_CLEARED', $result, 5); |
| 189 | - self::$cache_cleared = get_transient('WORDPRESS_SECURITY_TXT_CACHE_CLEARED'); |
|
| 189 | + self::$cache_cleared=get_transient('WORDPRESS_SECURITY_TXT_CACHE_CLEARED'); |
|
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | return false; |
@@ -199,9 +199,9 @@ discard block |
||
| 199 | 199 | * |
| 200 | 200 | * @return bool |
| 201 | 201 | */ |
| 202 | - public static function cache_cleared($reset = false) |
|
| 202 | + public static function cache_cleared($reset=false) |
|
| 203 | 203 | { |
| 204 | - $result = is_null(self::$cache_cleared) ? false : self::$cache_cleared; |
|
| 204 | + $result=is_null(self::$cache_cleared) ? false : self::$cache_cleared; |
|
| 205 | 205 | |
| 206 | 206 | if ($reset) { |
| 207 | 207 | delete_transient('WORDPRESS_SECURITY_TXT_CACHE_CLEARED'); |
@@ -222,9 +222,9 @@ discard block |
||
| 222 | 222 | private function show($document) |
| 223 | 223 | { |
| 224 | 224 | if ($document == 'security.txt') { |
| 225 | - $output = $this->render_security_txt(); |
|
| 225 | + $output=$this->render_security_txt(); |
|
| 226 | 226 | } elseif ($document == 'gpg.txt') { |
| 227 | - $output = $this->render_gpg_txt(); |
|
| 227 | + $output=$this->render_gpg_txt(); |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | if (empty($output)) { |
@@ -246,7 +246,7 @@ discard block |
||
| 246 | 246 | */ |
| 247 | 247 | private function render_gpg_txt() |
| 248 | 248 | { |
| 249 | - return $this->options['encryption']; |
|
| 249 | + return $this->options[ 'encryption' ]; |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | /** |
@@ -256,27 +256,27 @@ discard block |
||
| 256 | 256 | */ |
| 257 | 257 | private function render_security_txt() |
| 258 | 258 | { |
| 259 | - $output = $this->get_security_txt_cache(); |
|
| 259 | + $output=$this->get_security_txt_cache(); |
|
| 260 | 260 | |
| 261 | 261 | if (empty($output)) { |
| 262 | 262 | WordPress_Security_Txt::import_lib(); |
| 263 | 263 | |
| 264 | - $writer = (new \AustinHeap\Security\Txt\Writer)->setDebug(isset($this->options['credits']) ? $this->options['credits'] : false) |
|
| 265 | - ->addContact($this->options['contact']); |
|
| 264 | + $writer=(new \AustinHeap\Security\Txt\Writer)->setDebug(isset($this->options[ 'credits' ]) ? $this->options[ 'credits' ] : false) |
|
| 265 | + ->addContact($this->options[ 'contact' ]); |
|
| 266 | 266 | |
| 267 | - if (! empty($this->options['encryption'])) { |
|
| 267 | + if (!empty($this->options[ 'encryption' ])) { |
|
| 268 | 268 | $writer->setEncryption(get_site_url() . '/.well-known/gpg.txt'); |
| 269 | 269 | } |
| 270 | 270 | |
| 271 | - if (! empty($this->options['disclosure']) && $this->options['disclosure'] != 'default') { |
|
| 272 | - $writer->setDisclosure($this->options['disclosure']); |
|
| 271 | + if (!empty($this->options[ 'disclosure' ]) && $this->options[ 'disclosure' ] != 'default') { |
|
| 272 | + $writer->setDisclosure($this->options[ 'disclosure' ]); |
|
| 273 | 273 | } |
| 274 | 274 | |
| 275 | - if (! empty($this->options['acknowledgement'])) { |
|
| 276 | - $writer->setAcknowledgement($this->options['acknowledgement']); |
|
| 275 | + if (!empty($this->options[ 'acknowledgement' ])) { |
|
| 276 | + $writer->setAcknowledgement($this->options[ 'acknowledgement' ]); |
|
| 277 | 277 | } |
| 278 | 278 | |
| 279 | - $output = $writer->execute()->getText(); |
|
| 279 | + $output=$writer->execute()->getText(); |
|
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | $this->write_security_txt_cache($output); |
@@ -292,7 +292,7 @@ discard block |
||
| 292 | 292 | */ |
| 293 | 293 | private function write_security_txt_cache($data) |
| 294 | 294 | { |
| 295 | - if (isset($this->options['cache']) && $this->options['cache']) { |
|
| 295 | + if (isset($this->options[ 'cache' ]) && $this->options[ 'cache' ]) { |
|
| 296 | 296 | file_put_contents(self::cache_file(), $data); |
| 297 | 297 | WordPress_Security_Txt::event('cache'); |
| 298 | 298 | } |
@@ -305,17 +305,17 @@ discard block |
||
| 305 | 305 | */ |
| 306 | 306 | private function get_security_txt_cache() |
| 307 | 307 | { |
| 308 | - $data = null; |
|
| 308 | + $data=null; |
|
| 309 | 309 | |
| 310 | - if (isset($this->options['cache']) && $this->options['cache']) { |
|
| 311 | - $cache_file = self::cache_file(); |
|
| 310 | + if (isset($this->options[ 'cache' ]) && $this->options[ 'cache' ]) { |
|
| 311 | + $cache_file=self::cache_file(); |
|
| 312 | 312 | |
| 313 | 313 | if (is_file($cache_file) && filemtime($cache_file) < time() - 86400) { |
| 314 | 314 | self::cache_clear(); |
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | if (is_readable($cache_file)) { |
| 318 | - $data = file_get_contents($cache_file); |
|
| 318 | + $data=file_get_contents($cache_file); |
|
| 319 | 319 | } |
| 320 | 320 | } |
| 321 | 321 | |