Permalink
Browse files

Move http_build_url out to /vendor

Will make things cleaner.

Also, refactored a bit yourls_lowercase_scheme_domain() for clarity.
  • Loading branch information...
ozh committed Sep 7, 2017
1 parent f9ad93d commit c524b94b51878dc40056457b394a7db30fc25052
@@ -107,17 +107,6 @@ function bcpow( $base, $power ) {
}
}
/**
* http_build_url compatibility function
*
* @since 1.7.1
*/
if ( !function_exists( 'http_build_url' ) ) {
include YOURLS_INC . '/http_build_url/http_build_url.php';
}
/**
* mb_substr compatibility function. Stolen from WP
*
@@ -561,55 +561,44 @@ function yourls_esc_url( $url, $context = 'display', $protocols = array() ) {
function yourls_lowercase_scheme_domain( $url ) {
$scheme = yourls_get_protocol( $url );
if( '' == $scheme ) {
if ('' == $scheme) {
// Scheme not found, malformed URL? Something else? Not sure.
return $url;
}
// Case 1 : scheme like "stuff://" (eg "http://example.com/" or "ssh://joe@joe.com")
if( substr( $scheme, -2, 2 ) == '//' ) {
$parts = parse_url( $url );
// Most likely malformed stuff, could not parse : we'll just lowercase the scheme and leave the rest untouched
if( false == $parts ) {
$url = str_replace( $scheme, strtolower( $scheme ), $url );
// URL seems parsable, let's do the best we can
} else {
$lower = array();
$lower['scheme'] = strtolower( $parts['scheme'] );
if( isset( $parts['host'] ) ) {
$lower['host'] = strtolower( $parts['host'] );
} else {
$parts['host'] = '***';
}
// We're not going to glue back things that could be modified in the process
unset( $parts['path'] );
unset( $parts['query'] );
unset( $parts['fragment'] );
// original beginning of the URL and its lowercase-where-needed counterpart
// We trim the / after the domain to avoid avoid "http://example.com" being reconstructed as "http://example.com/"
$partial_original_url = trim( http_build_url( $parts ), '/' );
$partial_lower_original_url = trim( http_build_url( $parts, $lower ), '/' );
$url = str_replace( $partial_original_url , $partial_lower_original_url, $url );
}
/**
* Case 1 : scheme like "stuff:", as opposed to "stuff://"
* Examples: "mailto:joe@joe.com" or "bitcoin:15p1o8vnWqNkJBJGgwafNgR1GCCd6EGtQR?amount=1&label=Ozh"
* In this case, we only lowercase the scheme, because depending on it, things after should or should not be lowercased
*/
if (substr($scheme, -2, 2) != '//') {
$url = str_replace( $scheme, strtolower( $scheme ), $url );
return $url;
}
// Case 2 : scheme like "stuff:" (eg "mailto:joe@joe.com" or "bitcoin:15p1o8vnWqNkJBJGgwafNgR1GCCd6EGtQR?amount=1&label=Ozh")
// In this case, we only lowercase the scheme, because depending on it, things after should or should not be lowercased
} else {
/**
* Case 2 : scheme like "stuff://" (eg "http://example.com/" or "ssh://joe@joe.com")
* Here we lowercase the scheme and domain parts
*/
$parts = parse_url($url);
// Most likely malformed stuff, could not parse : we'll just lowercase the scheme and leave the rest untouched
if (false == $parts) {
$url = str_replace( $scheme, strtolower( $scheme ), $url );
return $url;
}
// URL seems parsable, let's do the best we can
$lower = array();
$lower['scheme'] = strtolower( $parts['scheme'] );
if( isset( $parts['host'] ) ) {
$lower['host'] = strtolower( $parts['host'] );
} else {
$parts['host'] = '***';
}
$url = http_build_url($url, $lower);
return $url;
}

This file was deleted.

Oops, something went wrong.
@@ -0,0 +1,10 @@
<?php
// autoload_files.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname(dirname($vendorDir));
return array(
'b45b351e6b6f7487d819961fef2fda77' => $vendorDir . '/jakeasmith/http_build_url/src/http_build_url.php',
);
@@ -47,6 +47,24 @@ public static function getLoader()
$loader->register(true);
if ($useStaticLoader) {
$includeFiles = Composer\Autoload\ComposerStaticInit2d6d15a8f6cc4bfbfd4a2943a6c4df59::$files;
} else {
$includeFiles = require __DIR__ . '/autoload_files.php';
}
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequire2d6d15a8f6cc4bfbfd4a2943a6c4df59($fileIdentifier, $file);
}
return $loader;
}
}
function composerRequire2d6d15a8f6cc4bfbfd4a2943a6c4df59($fileIdentifier, $file)
{
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
require $file;
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
}
}
@@ -6,6 +6,10 @@
class ComposerStaticInit2d6d15a8f6cc4bfbfd4a2943a6c4df59
{
public static $files = array (
'b45b351e6b6f7487d819961fef2fda77' => __DIR__ . '/..' . '/jakeasmith/http_build_url/src/http_build_url.php',
);
public static $prefixLengthsPsr4 = array (
'Y' =>
array (
@@ -470,5 +470,40 @@
"sqlserver",
"sqlsrv"
]
},
{
"name": "jakeasmith/http_build_url",
"version": "1.0.1",
"version_normalized": "1.0.1.0",
"source": {
"type": "git",
"url": "https://github.com/jakeasmith/http_build_url.git",
"reference": "93c273e77cb1edead0cf8bcf8cd2003428e74e37"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/jakeasmith/http_build_url/zipball/93c273e77cb1edead0cf8bcf8cd2003428e74e37",
"reference": "93c273e77cb1edead0cf8bcf8cd2003428e74e37",
"shasum": ""
},
"time": "2017-05-01T15:36:40+00:00",
"type": "library",
"installation-source": "dist",
"autoload": {
"files": [
"src/http_build_url.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Jake A. Smith",
"email": "theman@jakeasmith.com"
}
],
"description": "Provides functionality for http_build_url() to environments without pecl_http."
}
]
@@ -0,0 +1,20 @@
# http_build_url() for PHP
[![Build Status](https://travis-ci.org/jakeasmith/http_build_url.png)](https://travis-ci.org/jakeasmith/http_build_url)
[![Code Climate](https://codeclimate.com/github/jakeasmith/http_build_url/badges/gpa.svg)](https://codeclimate.com/github/jakeasmith/http_build_url)
[![Latest Stable Version](https://poser.pugx.org/jakeasmith/http_build_url/v/stable.png)](https://packagist.org/packages/jakeasmith/http_build_url)
[![Total Downloads](https://poser.pugx.org/jakeasmith/http_build_url/downloads.png)](https://packagist.org/packages/jakeasmith/http_build_url)
This simple library provides functionality for [`http_build_url()`](http://us2.php.net/manual/en/function.http-build-url.php) to environments without pecl_http. It aims to mimic the functionality of the pecl function in every way and ships with a full suite of tests that have been run against both the original function and the one in this package.
## Installation
The easiest way to install this library is to use [Composer](https://getcomposer.org/) from the command line.
```
$ composer require jakeasmith/http_build_url ^1
```
## License
This project is licensed under the MIT License - see the LICENSE file for details.
@@ -137,7 +137,7 @@ function http_build_url($url, $parts = array(), $flags = HTTP_URL_REPLACE, &$new
$parsed_string .= $url['scheme'] . '://';
}
if (isset($url['user'])) {
if (!empty($url['user'])) {
$parsed_string .= $url['user'];
if (isset($url['pass'])) {

0 comments on commit c524b94

Please sign in to comment.