Permalink
Browse files

Adds new methods in url library dedicated to URL auto formatting and …

…display.
  • Loading branch information...
JB Lebrun
JB Lebrun committed Sep 19, 2018
1 parent 8073f64 commit 606f6f2e969bd8b378dd63fde48b0cc9b3c209a6
Showing with 35 additions and 5 deletions.
  1. +35 −5 engine/lib/tool/url.php.inc
@@ -4,11 +4,11 @@
* @details Engine / Tool Library
* @file engine/lib/tool/url.php.inc
* @author CaMykS Team <camyks.contact@gmail.com>
* @version 1.0
* @version 1.0.1
* @date Creation: Apr 2018
* @date Modification: Apr 2018
* @date Modification: Sep 2018
* @copyright 2018 CaMykS Team
* @note This program is distributed as is - WITHOUT ANY WARRANTY;
* @note This program is distributed as is - WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* @warning This library is not loaded with CaMykS initialisation.
*/
@@ -27,7 +27,7 @@ function url_areInSameDomain($urls=array(), $strict=false) {
foreach ($urls as $url) {
/* Load hostname from url */
$v = strToLower(parse_url($url, PHP_URL_HOST));
if ($domain == '') {
/* Initialise first value. */
if ($strict)
@@ -53,4 +53,34 @@ function url_areInSameDomain($urls=array(), $strict=false) {
}
return true;
}
?>
/**
* Return completed URL with scheme when needed.
* @param string $url
* @param string $scheme
* @return string
*/
function url_getAsComplete($url, $scheme='http') {
$url = trim($url);
if ($url == '')
return '';
if (!preg_match('#:\/\/#', $url))
$url = $scheme.'://'.$url;
return $url;
}
/**
* Return smart display for URL.
* @param string $url
* @return string
*/
function url_getAsSmart($url) {
$url = explode('://', $url);
if (count($url) == 1)
return $url[0];
return $url[1];
}
?>

0 comments on commit 606f6f2

Please sign in to comment.