diff --git a/Controller/CaptchaHandlerController.php b/Controller/CaptchaHandlerController.php index 2cbb180..4570aab 100644 --- a/Controller/CaptchaHandlerController.php +++ b/Controller/CaptchaHandlerController.php @@ -2,14 +2,21 @@ namespace Captcha\Bundle\CaptchaBundle\Controller; +use BDC_CaptchaBase; +use BDC_CaptchaHttpCommand; +use BDC_CaptchaScriptsHelper; +use BDC_CryptoHelper; +use BDC_HttpHelper; +use BDC_StringHelper; use Captcha\Bundle\CaptchaBundle\Support\Path; use Captcha\Bundle\CaptchaBundle\Support\LibraryLoader; use Captcha\Bundle\CaptchaBundle\Helpers\BotDetectCaptchaHelper; +use SoundRegenerationMode; use Symfony\Component\HttpFoundation\Response; -use Symfony\Bundle\FrameworkBundle\Controller\Controller; +use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; -class CaptchaHandlerController extends Controller +class CaptchaHandlerController extends AbstractController { /** * @var object @@ -33,31 +40,31 @@ public function indexAction() } $commandString = $this->getUrlParameter('get'); - if (!\BDC_StringHelper::HasValue($commandString)) { - \BDC_HttpHelper::BadRequest('command'); + if (!BDC_StringHelper::HasValue($commandString)) { + BDC_HttpHelper::BadRequest('command'); } - $commandString = \BDC_StringHelper::Normalize($commandString); - $command = \BDC_CaptchaHttpCommand::FromQuerystring($commandString); + $commandString = BDC_StringHelper::Normalize($commandString); + $command = BDC_CaptchaHttpCommand::FromQuerystring($commandString); $responseBody = ''; switch ($command) { - case \BDC_CaptchaHttpCommand::GetImage: + case BDC_CaptchaHttpCommand::GetImage: $responseBody = $this->getImage(); break; - case \BDC_CaptchaHttpCommand::GetSound: + case BDC_CaptchaHttpCommand::GetSound: $responseBody = $this->getSound(); break; - case \BDC_CaptchaHttpCommand::GetValidationResult: + case BDC_CaptchaHttpCommand::GetValidationResult: $responseBody = $this->getValidationResult(); break; - case \BDC_CaptchaHttpCommand::GetScriptInclude: + case BDC_CaptchaHttpCommand::GetScriptInclude: $responseBody = $this->getScriptInclude(); break; - case \BDC_CaptchaHttpCommand::GetP: + case BDC_CaptchaHttpCommand::GetP: $responseBody = $this->getP(); break; default: - \BDC_HttpHelper::BadRequest('command'); + BDC_HttpHelper::BadRequest('command'); break; } @@ -105,7 +112,7 @@ public function getResourceContents() throw new BadRequestHttpException('Invalid file name.'); } - $resourcePath = realpath(Path::getPublicDirPathInLibrary($this->container) . $filename); + $resourcePath = realpath(Path::getPublicDirPathInLibrary() . $filename); if (!is_file($resourcePath)) { throw new BadRequestHttpException(sprintf('File "%s" could not be found.', $filename)); @@ -129,20 +136,20 @@ public function getResourceContents() public function getImage() { if (is_null($this->captcha)) { - \BDC_HttpHelper::BadRequest('captcha'); + BDC_HttpHelper::BadRequest('captcha'); } // identifier of the particular Captcha object instance $instanceId = $this->getInstanceId(); if (is_null($instanceId)) { - \BDC_HttpHelper::BadRequest('instance'); + BDC_HttpHelper::BadRequest('instance'); } // image generation invalidates sound cache, if any $this->clearSoundData($instanceId); // response headers - \BDC_HttpHelper::DisallowCache(); + BDC_HttpHelper::DisallowCache(); // response MIME type & headers $mimeType = $this->captcha->CaptchaBase->ImageMimeType; @@ -167,26 +174,26 @@ public function getImage() public function getSound() { if (is_null($this->captcha)) { - \BDC_HttpHelper::BadRequest('captcha'); + BDC_HttpHelper::BadRequest('captcha'); } // identifier of the particular Captcha object instance $instanceId = $this->getInstanceId(); if (is_null($instanceId)) { - \BDC_HttpHelper::BadRequest('instance'); + BDC_HttpHelper::BadRequest('instance'); } $soundBytes = $this->getSoundData($this->captcha, $instanceId); if (is_null($soundBytes)) { - \BDC_HttpHelper::BadRequest('Please reload the form page before requesting another Captcha sound'); + BDC_HttpHelper::BadRequest('Please reload the form page before requesting another Captcha sound'); exit; } $totalSize = strlen($soundBytes); // response headers - \BDC_HttpHelper::SmartDisallowCache(); + BDC_HttpHelper::SmartDisallowCache(); // response MIME type & headers $mimeType = $this->captcha->CaptchaBase->SoundMimeType; @@ -194,7 +201,7 @@ public function getSound() header('Content-Transfer-Encoding: binary'); if (!array_key_exists('d', $_GET)) { // javascript player not used, we send the file directly as a download - $downloadId = \BDC_CryptoHelper::GenerateGuid(); + $downloadId = BDC_CryptoHelper::GenerateGuid(); header("Content-Disposition: attachment; filename=captcha_{$downloadId}.wav"); } @@ -210,7 +217,7 @@ public function getSound() // end of sound playback, cleanup and tell AppleCoreMedia to stop requesting // invalid "bytes=rangeEnd-rangeEnd" ranges in an infinite(?) loop if ($rangeStart == $rangeEnd || $rangeEnd > $totalSize) { - \BDC_HttpHelper::BadRequest('invalid byte range'); + BDC_HttpHelper::BadRequest('invalid byte range'); } $rangeBytes = substr($soundBytes, $rangeStart, $rangeSize); @@ -238,7 +245,7 @@ public function getSound() public function getSoundData($p_Captcha, $p_InstanceId) { $shouldCache = ( - ($p_Captcha->SoundRegenerationMode == \SoundRegenerationMode::None) || // no sound regeneration allowed, so we must cache the first and only generated sound + ($p_Captcha->SoundRegenerationMode == SoundRegenerationMode::None) || // no sound regeneration allowed, so we must cache the first and only generated sound $this->detectIosRangeRequest() // keep the same Captcha sound across all chunked iOS requests ); @@ -286,20 +293,20 @@ private function clearSoundData($p_InstanceId) private function detectIosRangeRequest() { if (array_key_exists('HTTP_RANGE', $_SERVER) && - \BDC_StringHelper::HasValue($_SERVER['HTTP_RANGE'])) { + BDC_StringHelper::HasValue($_SERVER['HTTP_RANGE'])) { // Safari on MacOS and all browsers on <= iOS 10.x if (array_key_exists('HTTP_X_PLAYBACK_SESSION_ID', $_SERVER) && - \BDC_StringHelper::HasValue($_SERVER['HTTP_X_PLAYBACK_SESSION_ID'])) { + BDC_StringHelper::HasValue($_SERVER['HTTP_X_PLAYBACK_SESSION_ID'])) { return true; } $userAgent = array_key_exists('HTTP_USER_AGENT', $_SERVER) ? $_SERVER['HTTP_USER_AGENT'] : null; // all browsers on iOS 11.x and later - if(\BDC_StringHelper::HasValue($userAgent)) { - $userAgentLC = \BDC_StringHelper::Lowercase($userAgent); - if (\BDC_StringHelper::Contains($userAgentLC, "like mac os") || \BDC_StringHelper::Contains($userAgentLC, "like macos")) { + if(BDC_StringHelper::HasValue($userAgent)) { + $userAgentLC = BDC_StringHelper::Lowercase($userAgent); + if (BDC_StringHelper::Contains($userAgentLC, "like mac os") || BDC_StringHelper::Contains($userAgentLC, "like macos")) { return true; } } @@ -311,7 +318,7 @@ private function getSoundByteRange() { // chunked requests must include the desired byte range $rangeStr = $_SERVER['HTTP_RANGE']; - if (!\BDC_StringHelper::HasValue($rangeStr)) { + if (!BDC_StringHelper::HasValue($rangeStr)) { return; } @@ -328,7 +335,7 @@ private function detectFakeRangeRequest() $detected = false; if (array_key_exists('HTTP_RANGE', $_SERVER)) { $rangeStr = $_SERVER['HTTP_RANGE']; - if (\BDC_StringHelper::HasValue($rangeStr) && + if (BDC_StringHelper::HasValue($rangeStr) && preg_match('/bytes=0-$/', $rangeStr)) { $detected = true; } @@ -339,18 +346,18 @@ private function detectFakeRangeRequest() /** * The client requests the Captcha validation result (used for Ajax Captcha validation). * - * @return json + * @return string */ public function getValidationResult() { if (is_null($this->captcha)) { - \BDC_HttpHelper::BadRequest('captcha'); + BDC_HttpHelper::BadRequest('captcha'); } // identifier of the particular Captcha object instance $instanceId = $this->getInstanceId(); if (is_null($instanceId)) { - \BDC_HttpHelper::BadRequest('instance'); + BDC_HttpHelper::BadRequest('instance'); } $mimeType = 'application/json'; @@ -365,22 +372,20 @@ public function getValidationResult() $result = $this->captcha->AjaxValidate($userInput, $instanceId); $this->captcha->CaptchaBase->Save(); } - $resultJson = $this->getJsonValidationResult($result); - - return $resultJson; + return $this->getJsonValidationResult($result); } public function getScriptInclude() { // saved data for the specified Captcha object in the application if (is_null($this->captcha)) { - \BDC_HttpHelper::BadRequest('captcha'); + BDC_HttpHelper::BadRequest('captcha'); } // identifier of the particular Captcha object instance $instanceId = $this->getInstanceId(); if (is_null($instanceId)) { - \BDC_HttpHelper::BadRequest('instance'); + BDC_HttpHelper::BadRequest('instance'); } // response MIME type & headers @@ -388,7 +393,7 @@ public function getScriptInclude() header('X-Robots-Tag: noindex, nofollow, noarchive, nosnippet'); // 1. load BotDetect script - $resourcePath = realpath(Path::getPublicDirPathInLibrary($this->container) . 'bdc-traditional-api-script-include.js'); + $resourcePath = realpath(Path::getPublicDirPathInLibrary() . 'bdc-traditional-api-script-include.js'); if (!is_file($resourcePath)) { throw new BadRequestHttpException(sprintf('File "%s" could not be found.', $resourcePath)); @@ -397,12 +402,12 @@ public function getScriptInclude() $script = file_get_contents($resourcePath); // 2. load BotDetect Init script - $script .= \BDC_CaptchaScriptsHelper::GetInitScriptMarkup($this->captcha, $instanceId); + $script .= BDC_CaptchaScriptsHelper::GetInitScriptMarkup($this->captcha, $instanceId); // add remote scripts if enabled if ($this->captcha->RemoteScriptEnabled) { $script .= "\r\n"; - $script .= \BDC_CaptchaScriptsHelper::GetRemoteScript($this->captcha); + $script .= BDC_CaptchaScriptsHelper::GetRemoteScript($this->captcha); } return $script; @@ -414,8 +419,8 @@ public function getScriptInclude() private function getInstanceId() { $instanceId = $this->getUrlParameter('t'); - if (!\BDC_StringHelper::HasValue($instanceId) || - !\BDC_CaptchaBase::IsValidInstanceId($instanceId) + if (!BDC_StringHelper::HasValue($instanceId) || + !BDC_CaptchaBase::IsValidInstanceId($instanceId) ) { return; } @@ -450,12 +455,12 @@ private function getUserInput() /** * Encodes the Captcha validation result in a simple JSON wrapper. * + * @param $result * @return string */ private function getJsonValidationResult($result) { - $resultStr = ($result ? 'true': 'false'); - return $resultStr; + return ($result ? 'true': 'false'); } /** @@ -478,13 +483,13 @@ private function getUrlParameter($param) public function getP() { if (is_null($this->captcha)) { - \BDC_HttpHelper::BadRequest('captcha'); + BDC_HttpHelper::BadRequest('captcha'); } // identifier of the particular Captcha object instance $instanceId = $this->getInstanceId(); if (is_null($instanceId)) { - \BDC_HttpHelper::BadRequest('instance'); + BDC_HttpHelper::BadRequest('instance'); } // create new one @@ -497,7 +502,7 @@ public function getP() // response MIME type & headers header('Content-Type: application/json'); header('X-Robots-Tag: noindex, nofollow, noarchive, nosnippet'); - \BDC_HttpHelper::SmartDisallowCache(); + BDC_HttpHelper::SmartDisallowCache(); return $response; } diff --git a/Controller/SimpleCaptchaHandlerController.php b/Controller/SimpleCaptchaHandlerController.php index 37ac9c8..b398305 100644 --- a/Controller/SimpleCaptchaHandlerController.php +++ b/Controller/SimpleCaptchaHandlerController.php @@ -2,14 +2,22 @@ namespace Captcha\Bundle\CaptchaBundle\Controller; +use BDC_HttpHelper; +use BDC_SimpleCaptchaBase; +use BDC_SimpleCaptchaHttpCommand; +use BDC_SimpleCaptchaScriptsHelper; +use BDC_StringHelper; use Captcha\Bundle\CaptchaBundle\Support\Path; use Captcha\Bundle\CaptchaBundle\Support\SimpleLibraryLoader; use Captcha\Bundle\CaptchaBundle\Helpers\BotDetectSimpleCaptchaHelper; -use Symfony\Component\HttpFoundation\Response; -use Symfony\Bundle\FrameworkBundle\Controller\Controller; +use CorsAuth; +use ImageFormat; +use SimpleCaptchaRequestValidator; +use SoundRegenerationMode; +use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; -class SimpleCaptchaHandlerController extends Controller +class SimpleCaptchaHandlerController extends AbstractController { /** * @var object @@ -24,70 +32,70 @@ public function indexAction() $this->captcha = $this->getBotDetectCaptchaInstance(); $commandString = $this->getUrlParameter('get'); - if (!\BDC_StringHelper::HasValue($commandString)) { - \BDC_HttpHelper::BadRequest('command'); + if (!BDC_StringHelper::HasValue($commandString)) { + BDC_HttpHelper::BadRequest('command'); } - $commandString = \BDC_StringHelper::Normalize($commandString); - $command = \BDC_SimpleCaptchaHttpCommand::FromQuerystring($commandString); + $commandString = BDC_StringHelper::Normalize($commandString); + $command = BDC_SimpleCaptchaHttpCommand::FromQuerystring($commandString); $responseBody = ''; switch ($command) { - case \BDC_SimpleCaptchaHttpCommand::GetImage: + case BDC_SimpleCaptchaHttpCommand::GetImage: $responseBody = $this->getImage(); break; - case \BDC_SimpleCaptchaHttpCommand::GetBase64ImageString: + case BDC_SimpleCaptchaHttpCommand::GetBase64ImageString: $responseBody = $this->getBase64ImageString(); break; - case \BDC_SimpleCaptchaHttpCommand::GetSound: + case BDC_SimpleCaptchaHttpCommand::GetSound: $responseBody = $this->getSound(); break; - case \BDC_SimpleCaptchaHttpCommand::GetHtml: + case BDC_SimpleCaptchaHttpCommand::GetHtml: $responseBody = $this->getHtml(); break; - case \BDC_SimpleCaptchaHttpCommand::GetValidationResult: + case BDC_SimpleCaptchaHttpCommand::GetValidationResult: $responseBody = $this->getValidationResult(); break; // Sound icon - case \BDC_SimpleCaptchaHttpCommand::GetSoundIcon: + case BDC_SimpleCaptchaHttpCommand::GetSoundIcon: $responseBody = $this->getSoundIcon(); break; - case \BDC_SimpleCaptchaHttpCommand::GetSoundSmallIcon: + case BDC_SimpleCaptchaHttpCommand::GetSoundSmallIcon: $responseBody = $this->getSmallSoundIcon(); break; - case \BDC_SimpleCaptchaHttpCommand::GetSoundDisabledIcon: + case BDC_SimpleCaptchaHttpCommand::GetSoundDisabledIcon: $responseBody = $this->getDisabledSoundIcon(); break; - case \BDC_SimpleCaptchaHttpCommand::GetSoundSmallDisabledIcon: + case BDC_SimpleCaptchaHttpCommand::GetSoundSmallDisabledIcon: $responseBody = $this->getSmallDisabledSoundIcon(); break; // Reload icon - case \BDC_SimpleCaptchaHttpCommand::GetReloadIcon: + case BDC_SimpleCaptchaHttpCommand::GetReloadIcon: $responseBody = $this->getReloadIcon(); break; - case \BDC_SimpleCaptchaHttpCommand::GetReloadSmallIcon: + case BDC_SimpleCaptchaHttpCommand::GetReloadSmallIcon: $responseBody = $this->getSmallReloadIcon(); break; - case \BDC_SimpleCaptchaHttpCommand::GetReloadDisabledIcon: + case BDC_SimpleCaptchaHttpCommand::GetReloadDisabledIcon: $responseBody = $this->getDisabledReloadIcon(); break; - case \BDC_SimpleCaptchaHttpCommand::GetReloadSmallDisabledIcon: + case BDC_SimpleCaptchaHttpCommand::GetReloadSmallDisabledIcon: $responseBody = $this->getSmallDisabledReloadIcon(); break; // css, js - case \BDC_SimpleCaptchaHttpCommand::GetScriptInclude: + case BDC_SimpleCaptchaHttpCommand::GetScriptInclude: $responseBody = $this->getScriptInclude(); break; - case \BDC_SimpleCaptchaHttpCommand::GetLayoutStyleSheet: + case BDC_SimpleCaptchaHttpCommand::GetLayoutStyleSheet: $responseBody = $this->getLayoutStyleSheet(); break; - case \BDC_SimpleCaptchaHttpCommand::GetP: + case BDC_SimpleCaptchaHttpCommand::GetP: $responseBody = $this->getP(); break; default: - \BDC_HttpHelper::BadRequest('command'); + BDC_HttpHelper::BadRequest('command'); break; } @@ -114,8 +122,8 @@ private function getBotDetectCaptchaInstance() $captchaId = $this->getUrlParameter('t'); if ($captchaId !== null) { - $captchaId = \BDC_StringHelper::Normalize($captchaId); - if (1 !== preg_match(\BDC_SimpleCaptchaBase::VALID_CAPTCHA_ID, $captchaId)) { + $captchaId = BDC_StringHelper::Normalize($captchaId); + if (1 !== preg_match(BDC_SimpleCaptchaBase::VALID_CAPTCHA_ID, $captchaId)) { return null; } } @@ -134,30 +142,30 @@ public function getImage() header("Access-Control-Allow-Origin: *"); // authenticate client-side request - $corsAuth = new \CorsAuth(); + $corsAuth = new CorsAuth(); if (!$corsAuth->IsClientAllowed()) { - \BDC_HttpHelper::BadRequest($corsAuth->GetFrontEnd() . " is not an allowed front-end"); + BDC_HttpHelper::BadRequest($corsAuth->GetFrontEnd() . " is not an allowed front-end"); return null; } if (is_null($this->captcha)) { - \BDC_HttpHelper::BadRequest('captcha'); + BDC_HttpHelper::BadRequest('captcha'); } // identifier of the particular Captcha object instance $captchaId = $this->getCaptchaId(); if (is_null($captchaId)) { - \BDC_HttpHelper::BadRequest('instance'); + BDC_HttpHelper::BadRequest('instance'); } // image generation invalidates sound cache, if any $this->clearSoundData($this->captcha, $captchaId); // response headers - \BDC_HttpHelper::DisallowCache(); + BDC_HttpHelper::DisallowCache(); // response MIME type & headers - $imageType = \ImageFormat::GetName($this->captcha->ImageFormat); + $imageType = ImageFormat::GetName($this->captcha->ImageFormat); $imageType = strtolower($imageType[0]); $mimeType = "image/" . $imageType; header("Content-Type: {$mimeType}"); @@ -179,22 +187,21 @@ public function getBase64ImageString() header("Access-Control-Allow-Origin: *"); // authenticate client-side request - $corsAuth = new \CorsAuth(); + $corsAuth = new CorsAuth(); if (!$corsAuth->IsClientAllowed()) { - \BDC_HttpHelper::BadRequest($corsAuth->GetFrontEnd() . " is not an allowed front-end"); + BDC_HttpHelper::BadRequest($corsAuth->GetFrontEnd() . " is not an allowed front-end"); return null; } // MIME type - $imageType = \ImageFormat::GetName($this->captcha->ImageFormat); + $imageType = ImageFormat::GetName($this->captcha->ImageFormat); $imageType = strtolower($imageType[0]); $mimeType = "image/" . $imageType; $rawImage = $this->getImageData($this->captcha); - $base64ImageString = sprintf('data:%s;base64,%s', $mimeType, base64_encode($rawImage)); - return $base64ImageString; + return sprintf('data:%s;base64,%s', $mimeType, base64_encode($rawImage)); } @@ -203,7 +210,7 @@ private function getImageData($p_Captcha) // identifier of the particular Captcha object instance $captchaId = $this->getCaptchaId(); if (is_null($captchaId)) { - \BDC_HttpHelper::BadRequest('Captcha Id doesn\'t exist'); + BDC_HttpHelper::BadRequest('Captcha Id doesn\'t exist'); } if ($this->isObviousBotRequest($p_Captcha)) { @@ -214,7 +221,7 @@ private function getImageData($p_Captcha) $this->clearSoundData($p_Captcha, $captchaId); // response headers - \BDC_HttpHelper::DisallowCache(); + BDC_HttpHelper::DisallowCache(); // we don't support content chunking, since image files // are regenerated randomly on each request @@ -238,20 +245,20 @@ public function getSound() header("Access-Control-Allow-Origin: *"); // authenticate client-side request - $corsAuth = new \CorsAuth(); + $corsAuth = new CorsAuth(); if (!$corsAuth->IsClientAllowed()) { - \BDC_HttpHelper::BadRequest($corsAuth->GetFrontEnd() . " is not an allowed front-end"); + BDC_HttpHelper::BadRequest($corsAuth->GetFrontEnd() . " is not an allowed front-end"); return null; } if (is_null($this->captcha)) { - \BDC_HttpHelper::BadRequest('captcha'); + BDC_HttpHelper::BadRequest('captcha'); } // identifier of the particular Captcha object instance $captchaId = $this->getCaptchaId(); if (is_null($captchaId)) { - \BDC_HttpHelper::BadRequest('Captcha Id doesn\'t exist'); + BDC_HttpHelper::BadRequest('Captcha Id doesn\'t exist'); } if ($this->isObviousBotRequest($this->captcha)) { @@ -261,14 +268,14 @@ public function getSound() $soundBytes = $this->getSoundData($this->captcha, $captchaId); if (is_null($soundBytes)) { - \BDC_HttpHelper::BadRequest('Please reload the form page before requesting another Captcha sound'); + BDC_HttpHelper::BadRequest('Please reload the form page before requesting another Captcha sound'); exit; } $totalSize = strlen($soundBytes); // response headers - \BDC_HttpHelper::SmartDisallowCache(); + BDC_HttpHelper::SmartDisallowCache(); // response MIME type & headers $mimeType = $this->captcha->CaptchaBase->SoundMimeType; @@ -292,7 +299,7 @@ public function getSound() // end of sound playback, cleanup and tell AppleCoreMedia to stop requesting // invalid "bytes=rangeEnd-rangeEnd" ranges in an infinite(?) loop if ($rangeStart == $rangeEnd || $rangeEnd > $totalSize) { - \BDC_HttpHelper::BadRequest('invalid byte range'); + BDC_HttpHelper::BadRequest('invalid byte range'); } $rangeBytes = substr($soundBytes, $rangeStart, $rangeSize); @@ -319,7 +326,7 @@ public function getSound() public function getSoundData($p_Captcha, $p_CaptchaId) { $shouldCache = ( - ($p_Captcha->SoundRegenerationMode == \SoundRegenerationMode::None) || // no sound regeneration allowed, so we must cache the first and only generated sound + ($p_Captcha->SoundRegenerationMode == SoundRegenerationMode::None) || // no sound regeneration allowed, so we must cache the first and only generated sound $this->detectIosRangeRequest() // keep the same Captcha sound across all chunked iOS requests ); @@ -368,20 +375,20 @@ private function clearSoundData($p_Captcha, $p_CaptchaId) private function detectIosRangeRequest() { if (array_key_exists('HTTP_RANGE', $_SERVER) && - \BDC_StringHelper::HasValue($_SERVER['HTTP_RANGE'])) { + BDC_StringHelper::HasValue($_SERVER['HTTP_RANGE'])) { // Safari on MacOS and all browsers on <= iOS 10.x if (array_key_exists('HTTP_X_PLAYBACK_SESSION_ID', $_SERVER) && - \BDC_StringHelper::HasValue($_SERVER['HTTP_X_PLAYBACK_SESSION_ID'])) { + BDC_StringHelper::HasValue($_SERVER['HTTP_X_PLAYBACK_SESSION_ID'])) { return true; } $userAgent = array_key_exists('HTTP_USER_AGENT', $_SERVER) ? $_SERVER['HTTP_USER_AGENT'] : null; // all browsers on iOS 11.x and later - if(\BDC_StringHelper::HasValue($userAgent)) { - $userAgentLC = \BDC_StringHelper::Lowercase($userAgent); - if (\BDC_StringHelper::Contains($userAgentLC, "like mac os") || \BDC_StringHelper::Contains($userAgentLC, "like macos")) { + if(BDC_StringHelper::HasValue($userAgent)) { + $userAgentLC = BDC_StringHelper::Lowercase($userAgent); + if (BDC_StringHelper::Contains($userAgentLC, "like mac os") || BDC_StringHelper::Contains($userAgentLC, "like macos")) { return true; } } @@ -393,7 +400,7 @@ private function getSoundByteRange() { // chunked requests must include the desired byte range $rangeStr = $_SERVER['HTTP_RANGE']; - if (!\BDC_StringHelper::HasValue($rangeStr)) { + if (!BDC_StringHelper::HasValue($rangeStr)) { return; } @@ -410,7 +417,7 @@ private function detectFakeRangeRequest() $detected = false; if (array_key_exists('HTTP_RANGE', $_SERVER)) { $rangeStr = $_SERVER['HTTP_RANGE']; - if (\BDC_StringHelper::HasValue($rangeStr) && + if (BDC_StringHelper::HasValue($rangeStr) && preg_match('/bytes=0-$/', $rangeStr)) { $detected = true; } @@ -422,13 +429,12 @@ public function getHtml() { header("Access-Control-Allow-Origin: *"); - $corsAuth = new \CorsAuth(); + $corsAuth = new CorsAuth(); if (!$corsAuth->IsClientAllowed()) { - \BDC_HttpHelper::BadRequest($corsAuth->GetFrontEnd() . " is not an allowed front-end"); + BDC_HttpHelper::BadRequest($corsAuth->GetFrontEnd() . " is not an allowed front-end"); } - $html = "