-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Related: #1
- Loading branch information
Daniel Siepmann
committed
Oct 31, 2015
1 parent
ad85d3e
commit 3f30893
Showing
2 changed files
with
104 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?php | ||
namespace WebVision\WvPdfgen\Utility; | ||
|
||
/* | ||
* This file is part of the TYPO3 CMS project. | ||
* | ||
* It is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License, either version 2 | ||
* of the License, or any later version. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
* | ||
* The TYPO3 project - inspiring people to share! | ||
*/ | ||
|
||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
|
||
/** | ||
* Utility to ease work with urls. | ||
* | ||
* @author Daniel Siepmann <[email protected]> | ||
*/ | ||
class UrlUtility | ||
{ | ||
/** | ||
* Check whether the given URL is available (=returns 200). | ||
* | ||
* @param string $urlToCheck | ||
* | ||
* @return bool | ||
*/ | ||
public function urlAvailable($urlToCheck) | ||
{ | ||
$responseHeader = array(); | ||
GeneralUtility::getUrl( | ||
$urlToCheck, | ||
2, | ||
array(), | ||
$responseHeader | ||
); | ||
return ($responseHeader['http_code'] === '200'); | ||
} | ||
|
||
/** | ||
* Remove all parameter from query, except if they are white listed. | ||
* | ||
* @param string $urlToFilter The url to filter. | ||
* @param array $parameterWhitelist The list of parameter which are white listed. | ||
* | ||
* @return string | ||
*/ | ||
public function filterUrl($urlToFilter, array $parameterWhitelist) | ||
{ | ||
$filteredUrl = ''; | ||
$parsedUrl = parse_url($urlToFilter); | ||
if(!isset($parsedUrl['query'])) { | ||
return $urlToFilter; | ||
} | ||
|
||
$filteredUrl = $parsedUrl['scheme'] . '://' . $parsedUrl['host'] . $parsedUrl['path']; | ||
$urlQuery = array_filter( | ||
explode('&', $parsedUrl['query']), | ||
function ($queryParameter) { | ||
list($parameterName) = explode('=', $queryParameter); | ||
if(!in_array($parameterName, $parameterWhitelist)) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
); | ||
|
||
if(count($urlQuery) > 0) { | ||
$filteredUrl .= '?' . implode('&', $urlQuery); | ||
} | ||
|
||
return $filteredUrl; | ||
} | ||
|
||
/** | ||
* Get the current active domain, with protocol. | ||
* | ||
* @return string | ||
*/ | ||
public function getDomain() | ||
{ | ||
return GeneralUtility::getIndpEnv('TYPO3_SITE_URL'); | ||
} | ||
} |