forked from devsam/core
phpuri 추가. root, shredIcon, gameIage 경로 계산 코드를 추가
This commit is contained in:
@@ -29,11 +29,7 @@ d_pic/*.gif
|
||||
d_pic/*.png
|
||||
|
||||
d_setting/*.php
|
||||
!d_setting/*.orig.php
|
||||
!d_setting/_*.php
|
||||
*/d_setting/*.php
|
||||
!*/d_setting/*.orig.php
|
||||
!*/d_setting/_*.php
|
||||
|
||||
**/old/*
|
||||
test.php
|
||||
|
||||
+2
-1
@@ -15,7 +15,8 @@
|
||||
"monolog/monolog": "^1.23",
|
||||
"firephp/firephp-core": "^0.4.0",
|
||||
"vlucas/valitron": "^1.4",
|
||||
"php-extended/php-tail": "^2.1"
|
||||
"php-extended/php-tail": "^2.1",
|
||||
"pguardiario/phpuri": "^1.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
||||
Generated
+25
-1
@@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "4b18f5660106f71d2aba7f1dcee07033",
|
||||
"content-hash": "1753c2c2ad9fe40ecc5c6ae541dd2e78",
|
||||
"packages": [
|
||||
{
|
||||
"name": "brandonwamboldt/utilphp",
|
||||
@@ -454,6 +454,30 @@
|
||||
],
|
||||
"time": "2017-06-19T01:22:40+00:00"
|
||||
},
|
||||
{
|
||||
"name": "pguardiario/phpuri",
|
||||
"version": "1.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/monkeysuffrage/phpuri.git",
|
||||
"reference": "ad0a5ec033fe616cfef55578b9c7f2458be8fbfc"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/monkeysuffrage/phpuri/zipball/ad0a5ec033fe616cfef55578b9c7f2458be8fbfc",
|
||||
"reference": "ad0a5ec033fe616cfef55578b9c7f2458be8fbfc",
|
||||
"shasum": ""
|
||||
},
|
||||
"type": "project",
|
||||
"autoload": {
|
||||
"files": [
|
||||
"phpuri.php"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"description": "A php library for converting relative urls to absolute.",
|
||||
"time": "2015-05-24T09:13:17+00:00"
|
||||
},
|
||||
{
|
||||
"name": "php-extended/php-system",
|
||||
"version": "1.3.0",
|
||||
|
||||
+86
-34
@@ -12,28 +12,28 @@ $servHost = Util::getReq('serv_host');
|
||||
$sharedIconPath = Util::getReq('shared_icon_path');
|
||||
$gameImagePath = Util::getReq('game_image_path');
|
||||
|
||||
if(!$host || !$port || !$username || !$password || !$dbName || !$servHost || !$sharedIconPath || !$gameImagePath){
|
||||
if (!$host || !$port || !$username || !$password || !$dbName || !$servHost || !$sharedIconPath || !$gameImagePath) {
|
||||
Json::die([
|
||||
'result'=>false,
|
||||
'reason'=>'입력 값이 올바르지 않습니다'
|
||||
]);
|
||||
}
|
||||
|
||||
if(!filter_var($servHost, FILTER_VALIDATE_URL)){
|
||||
Json::die([
|
||||
if (!filter_var($servHost, FILTER_VALIDATE_URL)) {
|
||||
Json::die([
|
||||
'result'=>false,
|
||||
'reason'=>'접속 경로가 올바르지 않습니다.'
|
||||
]);
|
||||
}
|
||||
|
||||
if(file_exists(ROOT.'/d_setting/RootDB.php') && is_dir(ROOT.'/d_setting/RootDB.php')){
|
||||
if (file_exists(ROOT.'/d_setting/RootDB.php') && is_dir(ROOT.'/d_setting/RootDB.php')) {
|
||||
Json::die([
|
||||
'result'=>false,
|
||||
'reason'=>'d_setting/RootDB.php 가 디렉토리입니다'
|
||||
]);
|
||||
}
|
||||
|
||||
if(class_exists('\\sammo\\RootDB')){
|
||||
if (class_exists('\\sammo\\RootDB')) {
|
||||
Json::die([
|
||||
'result'=>false,
|
||||
'reason'=>'이미 RootDB.php 파일이 있습니다'
|
||||
@@ -41,35 +41,39 @@ if(class_exists('\\sammo\\RootDB')){
|
||||
}
|
||||
|
||||
//파일 권한 검사
|
||||
if(file_exists(AppConf::getUserIconPathFS()) && !is_dir(AppConf::getUserIconPathFS())){
|
||||
if (file_exists(AppConf::getUserIconPathFS()) && !is_dir(AppConf::getUserIconPathFS())) {
|
||||
Json::die([
|
||||
'result'=>false,
|
||||
'reason'=>AppConf::$userIconPath.' 이 디렉토리가 아닙니다'
|
||||
]);
|
||||
}
|
||||
|
||||
if(file_exists(ROOT.'/d_log') && !is_dir(ROOT.'/d_log')){
|
||||
if (file_exists(ROOT.'/d_log') && !is_dir(ROOT.'/d_log')) {
|
||||
Json::die([
|
||||
'result'=>false,
|
||||
'reason'=>'d_log 가 디렉토리가 아닙니다'
|
||||
]);
|
||||
}
|
||||
|
||||
if(file_exists(ROOT.'/d_shared') && !is_dir(ROOT.'/d_shared')){
|
||||
if (file_exists(ROOT.'/d_shared') && !is_dir(ROOT.'/d_shared')) {
|
||||
Json::die([
|
||||
'result'=>false,
|
||||
'reason'=>'d_shared 가 디렉토리가 아닙니다'
|
||||
]);
|
||||
}
|
||||
|
||||
if(!file_exists(ROOT.'/d_setting')){
|
||||
if (file_exists(ROOT.'/d_setting') && !is_dir(ROOT.'/d_setting')) {
|
||||
Json::die([
|
||||
'result'=>false,
|
||||
'reason'=>'d_setting 이 존재하지 않습니다'
|
||||
'reason'=>'d_shared 가 디렉토리가 아닙니다'
|
||||
]);
|
||||
}
|
||||
|
||||
if (!file_exists(ROOT.'/d_log') || !file_exists(ROOT.'/d_shared') || !file_exists(AppConf::getUserIconPathFS())) {
|
||||
if (!file_exists(ROOT.'/d_log')
|
||||
|| !file_exists(ROOT.'/d_shared')
|
||||
|| !file_exists(ROOT.'/d_setting')
|
||||
|| !file_exists(AppConf::getUserIconPathFS())
|
||||
) {
|
||||
if (!is_writable(ROOT)) {
|
||||
Json::die([
|
||||
'result'=>false,
|
||||
@@ -78,42 +82,46 @@ if (!file_exists(ROOT.'/d_log') || !file_exists(ROOT.'/d_shared') || !file_exist
|
||||
}
|
||||
|
||||
//기본 파일 생성
|
||||
if(!file_exists(AppConf::getUserIconPathFS())){
|
||||
if (!file_exists(AppConf::getUserIconPathFS())) {
|
||||
mkdir(AppConf::getUserIconPathFS());
|
||||
}
|
||||
|
||||
if(!file_exists(ROOT.'/d_log')){
|
||||
if (!file_exists(ROOT.'/d_log')) {
|
||||
mkdir(ROOT.'/d_log');
|
||||
}
|
||||
|
||||
if(!file_exists(ROOT.'/d_shared')){
|
||||
if (!file_exists(ROOT.'/d_setting')) {
|
||||
mkdir(ROOT.'/d_setting');
|
||||
}
|
||||
|
||||
if (!file_exists(ROOT.'/d_shared')) {
|
||||
mkdir(ROOT.'/d_shared');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(!is_writable(AppConf::getUserIconPathFS())){
|
||||
if (!is_writable(AppConf::getUserIconPathFS())) {
|
||||
Json::die([
|
||||
'result'=>false,
|
||||
'reason'=>AppConf::$userIconPath.' 디렉토리의 쓰기 권한이 없습니다'
|
||||
]);
|
||||
}
|
||||
|
||||
if(!is_writable(ROOT.'/d_log')){
|
||||
if (!is_writable(ROOT.'/d_log')) {
|
||||
Json::die([
|
||||
'result'=>false,
|
||||
'reason'=>'d_log 디렉토리의 쓰기 권한이 없습니다'
|
||||
]);
|
||||
}
|
||||
|
||||
if(!is_writable(ROOT.'/d_shared')){
|
||||
if (!is_writable(ROOT.'/d_shared')) {
|
||||
Json::die([
|
||||
'result'=>false,
|
||||
'reason'=>'d_shared 디렉토리의 쓰기 권한이 없습니다'
|
||||
]);
|
||||
}
|
||||
|
||||
if(!is_writable(ROOT.'/d_setting')){
|
||||
if (!is_writable(ROOT.'/d_setting')) {
|
||||
Json::die([
|
||||
'result'=>false,
|
||||
'reason'=>'d_setting 디렉토리의 쓰기 권한이 없습니다.'
|
||||
@@ -122,28 +130,28 @@ if(!is_writable(ROOT.'/d_setting')){
|
||||
|
||||
|
||||
|
||||
if(!file_exists(ROOT.'/d_log/.htaccess')){
|
||||
if (!file_exists(ROOT.'/d_log/.htaccess')) {
|
||||
@file_put_contents(ROOT.'/d_log/.htaccess', 'Deny from all');
|
||||
}
|
||||
|
||||
if(!file_exists(ROOT.'/d_setting/.htaccess')){
|
||||
if (!file_exists(ROOT.'/d_setting/.htaccess')) {
|
||||
@file_put_contents(ROOT.'/d_setting/.htaccess', 'Deny from all');
|
||||
}
|
||||
|
||||
//DB 접근 권한 검사
|
||||
|
||||
$rootDB = new \MeekroDB($host,$username,$password,$dbName,$port,'utf8mb4');
|
||||
$rootDB = new \MeekroDB($host, $username, $password, $dbName, $port, 'utf8mb4');
|
||||
$rootDB->connect_options[MYSQLI_OPT_INT_AND_FLOAT_NATIVE] = true;
|
||||
|
||||
$rootDB->throw_exception_on_nonsql_error = false;
|
||||
$rootDB->nonsql_error_handler = function($params){
|
||||
$rootDB->nonsql_error_handler = function ($params) {
|
||||
Json::die([
|
||||
'result'=>false,
|
||||
'reason'=>'DB 접속에 실패했습니다.'
|
||||
]);
|
||||
};
|
||||
|
||||
$rootDB->error_handler = function($params){
|
||||
$rootDB->error_handler = function ($params) {
|
||||
Json::die([
|
||||
'result'=>false,
|
||||
'reason'=>'SQL을 제대로 실행하지 못했습니다. DB상태를 확인해 주세요.'
|
||||
@@ -152,12 +160,12 @@ $rootDB->error_handler = function($params){
|
||||
|
||||
$mysqli_obj = $rootDB->get(); //로그인에 실패할 경우 자동으로 dbConnFail()이 실행됨.
|
||||
|
||||
if($mysqli_obj->multi_query(file_get_contents(__dir__.'/sql/common_schema.sql'))){
|
||||
while(true){
|
||||
if ($mysqli_obj->multi_query(file_get_contents(__dir__.'/sql/common_schema.sql'))) {
|
||||
while (true) {
|
||||
if (!$mysqli_obj->more_results()) {
|
||||
break;
|
||||
}
|
||||
if(!$mysqli_obj->next_result()){
|
||||
if (!$mysqli_obj->next_result()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -172,16 +180,21 @@ $rootDB->insert('system', array(
|
||||
|
||||
$globalSalt = bin2hex(random_bytes(16));
|
||||
|
||||
$sharedIconPath = WebUtil::resolveRelativePath($sharedIconPath, $servHost);
|
||||
$gameImagePath = WebUtil::resolveRelativePath($gameImagePath, $servHost);
|
||||
|
||||
$result = Util::generateFileUsingSimpleTemplate(
|
||||
ROOT.'/d_setting/ServConfig.orig.php',
|
||||
ROOT.'/d_setting/ServConfig.php',[
|
||||
__dir__.'/templates/ServConfig.orig.php',
|
||||
ROOT.'/d_setting/ServConfig.php',
|
||||
[
|
||||
'serverBasePath'=>$servHost,
|
||||
'sharedIconPath'=>$sharedIconPath,
|
||||
'gameImagePath'=>$gameImagePath
|
||||
]
|
||||
, true);
|
||||
],
|
||||
true
|
||||
);
|
||||
|
||||
if($result !== true){
|
||||
if ($result !== true) {
|
||||
Json::die([
|
||||
'result'=>false,
|
||||
'reason'=>$result
|
||||
@@ -189,8 +202,47 @@ if($result !== true){
|
||||
}
|
||||
|
||||
$result = Util::generateFileUsingSimpleTemplate(
|
||||
ROOT.'/d_setting/RootDB.orig.php',
|
||||
ROOT.'/d_setting/RootDB.php',[
|
||||
__dir__.'/templates/common_path.orig.js',
|
||||
ROOT.'/d_shared/common_path.js',
|
||||
[
|
||||
'serverBasePath'=>$servHost,
|
||||
'sharedIconPath'=>$sharedIconPath,
|
||||
'gameImagePath'=>$gameImagePath
|
||||
],
|
||||
true
|
||||
);
|
||||
|
||||
if ($result !== true) {
|
||||
Json::die([
|
||||
'result'=>false,
|
||||
'reason'=>$result
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
$result = Util::generateFileUsingSimpleTemplate(
|
||||
__dir__.'/templates/common.orig.css',
|
||||
ROOT.'/d_shared/common.css',
|
||||
[
|
||||
'serverBasePath'=>$servHost,
|
||||
'sharedIconPath'=>$sharedIconPath,
|
||||
'gameImagePath'=>$gameImagePath
|
||||
],
|
||||
true
|
||||
);
|
||||
|
||||
if ($result !== true) {
|
||||
Json::die([
|
||||
'result'=>false,
|
||||
'reason'=>$result
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
$result = Util::generateFileUsingSimpleTemplate(
|
||||
__dir__.'/templates/RootDB.orig.php',
|
||||
ROOT.'/d_setting/RootDB.php',
|
||||
[
|
||||
'host'=>$host,
|
||||
'user'=>$username,
|
||||
'password'=>$password,
|
||||
@@ -200,7 +252,7 @@ $result = Util::generateFileUsingSimpleTemplate(
|
||||
]
|
||||
);
|
||||
|
||||
if($result !== true){
|
||||
if ($result !== true) {
|
||||
Json::die([
|
||||
'result'=>false,
|
||||
'reason'=>$result
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
Deny from all
|
||||
@@ -0,0 +1,58 @@
|
||||
@charset "utf-8";
|
||||
|
||||
.bg0 { background-image:url('_tK_gameImagePath_/back_walnut.jpg'); }
|
||||
.bg1 { background-image:url('_tK_gameImagePath_/back_green.jpg'); }
|
||||
.bg2 { background-image:url('_tK_gameImagePath_/back_blue.jpg'); }
|
||||
|
||||
.img_back {background-image:url('_tK_gameImagePath_/back.jpg'); }
|
||||
|
||||
/* 레거시. */
|
||||
#bg0 { background-image:url('_tK_gameImagePath_/back_walnut.jpg'); }
|
||||
#bg1 { background-image:url('_tK_gameImagePath_/back_green.jpg'); }
|
||||
#bg2 { background-image:url('_tK_gameImagePath_/back_blue.jpg'); }
|
||||
|
||||
.map_detail .map_title{
|
||||
background:
|
||||
url('_tK_gameImagePath_/ltitle.jpg') no-repeat left,
|
||||
url('_tK_gameImagePath_/rtitle.jpg') no-repeat right;
|
||||
}
|
||||
|
||||
.map_detail.map_spring .map_title_text{
|
||||
background:
|
||||
url('_tK_gameImagePath_/ad.gif') no-repeat left,
|
||||
url('_tK_gameImagePath_/spring.gif') no-repeat right;
|
||||
}
|
||||
|
||||
.map_detail.map_summer .map_title_text{
|
||||
background:
|
||||
url('_tK_gameImagePath_/ad.gif') no-repeat left,
|
||||
url('_tK_gameImagePath_/summer.gif') no-repeat right;
|
||||
}
|
||||
|
||||
.map_detail.map_fall .map_title_text{
|
||||
background:
|
||||
url('_tK_gameImagePath_/ad.gif') no-repeat left,
|
||||
url('_tK_gameImagePath_/fall.gif') no-repeat right;
|
||||
}
|
||||
|
||||
.map_detail.map_winter .map_title_text{
|
||||
background:
|
||||
url('_tK_gameImagePath_/ad.gif') no-repeat left,
|
||||
url('_tK_gameImagePath_/winter.gif') no-repeat right;
|
||||
}
|
||||
|
||||
.map_spring .map_body{
|
||||
background: url('_tK_gameImagePath_/map1.jpg') no-repeat;
|
||||
}
|
||||
|
||||
.map_summer .map_body{
|
||||
background: url('_tK_gameImagePath_/map2.jpg') no-repeat;
|
||||
}
|
||||
|
||||
.map_fall .map_body{
|
||||
background: url('_tK_gameImagePath_/map3.jpg') no-repeat;
|
||||
}
|
||||
|
||||
.map_winter .map_body{
|
||||
background: url('_tK_gameImagePath_/map4.jpg') no-repeat;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
window.pathConfig = {
|
||||
root:"_tK_serverBasePath_",
|
||||
sharedIcon:"_tK_sharedIconPath_",
|
||||
gameImage:"_tK_gameImagePath_"
|
||||
};
|
||||
@@ -12,6 +12,11 @@ class WebUtil
|
||||
return str_replace('.', '\\.', $ip);
|
||||
}
|
||||
|
||||
public static function resolveRelativePath(string $path, string $basepath) : string
|
||||
{
|
||||
return \phpUri::parse($basepath)->join($path);
|
||||
}
|
||||
|
||||
public static function setHeaderNoCache()
|
||||
{
|
||||
if (!headers_sent()) {
|
||||
|
||||
Vendored
+1
@@ -9,5 +9,6 @@ return array(
|
||||
'c964ee0ededf28c96ebd9db5099ef910' => $vendorDir . '/guzzlehttp/promises/src/functions_include.php',
|
||||
'a0edc8309cc5e1d60e3047b5df6b7052' => $vendorDir . '/guzzlehttp/psr7/src/functions_include.php',
|
||||
'37a3dc5111fe8f707ab4c132ef1dbc62' => $vendorDir . '/guzzlehttp/guzzle/src/functions_include.php',
|
||||
'5b154887902198b16314243c6e0e3e19' => $vendorDir . '/pguardiario/phpuri/phpuri.php',
|
||||
'870dc64919afa8b0f700701bb2c6a783' => $baseDir . '/f_config/config.php',
|
||||
);
|
||||
|
||||
Vendored
+1
@@ -10,6 +10,7 @@ class ComposerStaticInit67b09c83b85c3bc0027caefe5bba171a
|
||||
'c964ee0ededf28c96ebd9db5099ef910' => __DIR__ . '/..' . '/guzzlehttp/promises/src/functions_include.php',
|
||||
'a0edc8309cc5e1d60e3047b5df6b7052' => __DIR__ . '/..' . '/guzzlehttp/psr7/src/functions_include.php',
|
||||
'37a3dc5111fe8f707ab4c132ef1dbc62' => __DIR__ . '/..' . '/guzzlehttp/guzzle/src/functions_include.php',
|
||||
'5b154887902198b16314243c6e0e3e19' => __DIR__ . '/..' . '/pguardiario/phpuri/phpuri.php',
|
||||
'870dc64919afa8b0f700701bb2c6a783' => __DIR__ . '/../..' . '/f_config/config.php',
|
||||
);
|
||||
|
||||
|
||||
Vendored
+26
@@ -463,6 +463,32 @@
|
||||
"psr-3"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "pguardiario/phpuri",
|
||||
"version": "1.0",
|
||||
"version_normalized": "1.0.0.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/monkeysuffrage/phpuri.git",
|
||||
"reference": "ad0a5ec033fe616cfef55578b9c7f2458be8fbfc"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/monkeysuffrage/phpuri/zipball/ad0a5ec033fe616cfef55578b9c7f2458be8fbfc",
|
||||
"reference": "ad0a5ec033fe616cfef55578b9c7f2458be8fbfc",
|
||||
"shasum": ""
|
||||
},
|
||||
"time": "2015-05-24T09:13:17+00:00",
|
||||
"type": "project",
|
||||
"installation-source": "dist",
|
||||
"autoload": {
|
||||
"files": [
|
||||
"phpuri.php"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"description": "A php library for converting relative urls to absolute."
|
||||
},
|
||||
{
|
||||
"name": "php-extended/php-system",
|
||||
"version": "1.3.0",
|
||||
|
||||
Vendored
+18
@@ -0,0 +1,18 @@
|
||||
Phpuri
|
||||
=========
|
||||
|
||||
A php library for converting relative urls to absolute.
|
||||
|
||||
```php
|
||||
require 'phpuri.php';
|
||||
echo phpUri::parse('https://www.google.com/')->join('foo');
|
||||
//==> https://www.google.com/foo
|
||||
```
|
||||
|
||||
### Benchmark
|
||||
<pre>
|
||||
php test.php
|
||||
rel2abs: successes -> 26, failures => 9, elapsed time: 0.001301
|
||||
url_to_absolute: successes -> 32, failures => 3, elapsed time: 0.0029089999999999
|
||||
phpuri: successes -> 35, failures => 0, elapsed time: 0.002402
|
||||
</pre>
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "pguardiario/phpuri",
|
||||
"type": "project",
|
||||
"version": "1.0",
|
||||
"description": "A php library for converting relative urls to absolute.",
|
||||
"autoload" : {
|
||||
"files": [
|
||||
"phpuri.php"
|
||||
]
|
||||
}
|
||||
}
|
||||
Vendored
+197
@@ -0,0 +1,197 @@
|
||||
<?php
|
||||
/**
|
||||
* A php library for converting relative urls to absolute.
|
||||
* Website: https://github.com/monkeysuffrage/phpuri
|
||||
*
|
||||
* <pre>
|
||||
* echo phpUri::parse('https://www.google.com/')->join('foo');
|
||||
* //==> https://www.google.com/foo
|
||||
* </pre>
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @author P Guardiario <pguardiario@gmail.com>
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* phpUri
|
||||
*/
|
||||
class phpUri
|
||||
{
|
||||
|
||||
/**
|
||||
* http(s)://
|
||||
* @var string
|
||||
*/
|
||||
public $scheme;
|
||||
|
||||
/**
|
||||
* www.example.com
|
||||
* @var string
|
||||
*/
|
||||
public $authority;
|
||||
|
||||
/**
|
||||
* /search
|
||||
* @var string
|
||||
*/
|
||||
public $path;
|
||||
|
||||
/**
|
||||
* ?q=foo
|
||||
* @var string
|
||||
*/
|
||||
public $query;
|
||||
|
||||
/**
|
||||
* #bar
|
||||
* @var string
|
||||
*/
|
||||
public $fragment;
|
||||
|
||||
private function __construct( $string )
|
||||
{
|
||||
preg_match_all( '/^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/', $string, $m );
|
||||
$this->scheme = $m[ 2 ][ 0 ];
|
||||
$this->authority = $m[ 4 ][ 0 ];
|
||||
|
||||
/**
|
||||
* CHANGE:
|
||||
* @author Dominik Habichtsberg <Dominik.Habichtsberg@Hbg-IT.de>
|
||||
* @since 24 Mai 2015 10:02 Uhr
|
||||
*
|
||||
* Former code: $this->path = ( empty( $m[ 5 ][ 0 ] ) ) ? '/' : $m[ 5 ][ 0 ];
|
||||
* No tests failed, when the path is empty.
|
||||
* With the former code, the relative urls //g and #s failed
|
||||
*/
|
||||
$this->path = $m[ 5 ][ 0 ];
|
||||
$this->query = $m[ 7 ][ 0 ];
|
||||
$this->fragment = $m[ 9 ][ 0 ];
|
||||
}
|
||||
|
||||
private function to_str()
|
||||
{
|
||||
$ret = '';
|
||||
if ( !empty( $this->scheme ) )
|
||||
{
|
||||
$ret .= "{$this->scheme}:";
|
||||
}
|
||||
|
||||
if ( !empty( $this->authority ) )
|
||||
{
|
||||
$ret .= "//{$this->authority}";
|
||||
}
|
||||
|
||||
$ret .= $this->normalize_path( $this->path );
|
||||
|
||||
if ( !empty( $this->query ) )
|
||||
{
|
||||
$ret .= "?{$this->query}";
|
||||
}
|
||||
|
||||
if ( !empty( $this->fragment ) )
|
||||
{
|
||||
$ret .= "#{$this->fragment}";
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
private function normalize_path( $path )
|
||||
{
|
||||
if ( empty( $path ) )
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
$normalized_path = $path;
|
||||
$normalized_path = preg_replace( '`//+`', '/', $normalized_path, -1, $c0 );
|
||||
$normalized_path = preg_replace( '`^/\\.\\.?/`', '/', $normalized_path, -1, $c1 );
|
||||
$normalized_path = preg_replace( '`/\\.(/|$)`', '/', $normalized_path, -1, $c2 );
|
||||
|
||||
/**
|
||||
* CHANGE:
|
||||
* @author Dominik Habichtsberg <Dominik.Habichtsberg@Hbg-IT.de>
|
||||
* @since 24 Mai 2015 10:05 Uhr
|
||||
* changed limit form -1 to 1, because climbing up the directory-tree failed
|
||||
*/
|
||||
$normalized_path = preg_replace( '`/[^/]*?/\\.\\.(/|$)`', '/', $normalized_path, 1, $c3 );
|
||||
$num_matches = $c0 + $c1 + $c2 + $c3;
|
||||
|
||||
return ( $num_matches > 0 ) ? $this->normalize_path( $normalized_path ) : $normalized_path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse an url string
|
||||
*
|
||||
* @param string $url the url to parse
|
||||
*
|
||||
* @return phpUri
|
||||
*/
|
||||
public static function parse( $url )
|
||||
{
|
||||
$uri = new phpUri( $url );
|
||||
|
||||
return $uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Join with a relative url
|
||||
*
|
||||
* @param string $relative the relative url to join
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function join( $relative )
|
||||
{
|
||||
$uri = new phpUri( $relative );
|
||||
switch ( TRUE )
|
||||
{
|
||||
case !empty( $uri->scheme ):
|
||||
break;
|
||||
|
||||
case !empty( $uri->authority ):
|
||||
break;
|
||||
|
||||
case empty( $uri->path ):
|
||||
$uri->path = $this->path;
|
||||
if ( empty( $uri->query ) )
|
||||
{
|
||||
$uri->query = $this->query;
|
||||
}
|
||||
break;
|
||||
|
||||
case strpos( $uri->path, '/' ) === 0:
|
||||
break;
|
||||
|
||||
default:
|
||||
$base_path = $this->path;
|
||||
if ( strpos( $base_path, '/' ) === FALSE )
|
||||
{
|
||||
$base_path = '';
|
||||
}
|
||||
else
|
||||
{
|
||||
$base_path = preg_replace( '/\/[^\/]+$/', '/', $base_path );
|
||||
}
|
||||
if ( empty( $base_path ) && empty( $this->authority ) )
|
||||
{
|
||||
$base_path = '/';
|
||||
}
|
||||
$uri->path = $base_path . $uri->path;
|
||||
}
|
||||
|
||||
if ( empty( $uri->scheme ) )
|
||||
{
|
||||
$uri->scheme = $this->scheme;
|
||||
if ( empty( $uri->authority ) )
|
||||
{
|
||||
$uri->authority = $this->authority;
|
||||
}
|
||||
}
|
||||
|
||||
return $uri->to_str();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user