Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Q
question2answer
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
outils
question2answer
Commits
08e398ec
Commit
08e398ec
authored
Sep 04, 2014
by
Scott Vivian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor qa-index.php (mainly coding style)
parent
b1d9d397
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
69 additions
and
76 deletions
+69
-76
qa-index.php
qa-include/qa-index.php
+69
-76
No files found.
qa-include/qa-index.php
View file @
08e398ec
...
...
@@ -32,13 +32,13 @@
// If this is an special non-page request, branch off here
if
(
@
$_POST
[
'qa'
]
==
'ajax'
)
if
(
isset
(
$_POST
[
'qa'
])
&&
$_POST
[
'qa'
]
==
'ajax'
)
require
'qa-ajax.php'
;
elseif
(
@
$_GET
[
'qa'
]
==
'image'
)
elseif
(
isset
(
$_GET
[
'qa'
])
&&
$_GET
[
'qa'
]
==
'image'
)
require
'qa-image.php'
;
elseif
(
@
$_GET
[
'qa'
]
==
'blob'
)
elseif
(
isset
(
$_GET
[
'qa'
])
&&
$_GET
[
'qa'
]
==
'blob'
)
require
'qa-blob.php'
;
else
{
...
...
@@ -47,41 +47,41 @@
require
'qa-base.php'
;
// Determine the request and root of the installation, and the requested start position used by many pages
/**
* Determine the request and root of the installation, and the requested start position used by many pages.
*
* Apache and Nginx behave slightly differently:
* Apache qa-rewrite unescapes characters, converts `+` to ` `, cuts off at `#` or `&`
* Nginx qa-rewrite unescapes characters, retains `+`, contains true path
*/
function
qa_index_set_request
()
/*
Apache and Nginx behave slightly differently:
- Apache qa-rewrite unescapes characters, converts `+` to ` `, cuts off at `#` or `&`
- Nginx qa-rewrite unescapes characters, retains `+`, contains true path
*/
{
if
(
qa_to_override
(
__FUNCTION__
))
{
$args
=
func_get_args
();
return
qa_call_override
(
__FUNCTION__
,
$args
);
}
$relativedepth
=
0
;
$relativedepth
=
0
;
if
(
isset
(
$_GET
[
'qa-rewrite'
]))
{
// URLs rewritten by .htaccess or
n
ginx
$urlformat
=
QA_URL_FORMAT_NEAT
;
if
(
isset
(
$_GET
[
'qa-rewrite'
]))
{
// URLs rewritten by .htaccess or
N
ginx
$urlformat
=
QA_URL_FORMAT_NEAT
;
$qa_rewrite
=
strtr
(
qa_gpc_to_string
(
$_GET
[
'qa-rewrite'
]),
'+'
,
' '
);
// strtr required by Nginx
$requestparts
=
explode
(
'/'
,
$qa_rewrite
);
$requestparts
=
explode
(
'/'
,
$qa_rewrite
);
unset
(
$_GET
[
'qa-rewrite'
]);
if
(
!
empty
(
$_SERVER
[
'REQUEST_URI'
]))
{
// workaround for the fact that Apache unescapes characters while rewriting
$origpath
=
$_SERVER
[
'REQUEST_URI'
];
$_GET
=
array
();
$origpath
=
$_SERVER
[
'REQUEST_URI'
];
$_GET
=
array
();
$questionpos
=
strpos
(
$origpath
,
'?'
);
$questionpos
=
strpos
(
$origpath
,
'?'
);
if
(
is_numeric
(
$questionpos
))
{
$params
=
explode
(
'&'
,
substr
(
$origpath
,
$questionpos
+
1
));
$params
=
explode
(
'&'
,
substr
(
$origpath
,
$questionpos
+
1
));
foreach
(
$params
as
$param
)
foreach
(
$params
as
$param
)
{
if
(
preg_match
(
'/^([^\=]*)(\=(.*))?$/'
,
$param
,
$matches
))
{
$argument
=
strtr
(
urldecode
(
$matches
[
1
]),
'.'
,
'_'
);
// simulate PHP's $_GET behavior
$_GET
[
$argument
]
=
qa_string_to_gpc
(
urldecode
(
@
$matches
[
3
]));
$argument
=
strtr
(
urldecode
(
$matches
[
1
]),
'.'
,
'_'
);
// simulate PHP's $_GET behavior
$_GET
[
$argument
]
=
qa_string_to_gpc
(
urldecode
(
@
$matches
[
3
]));
}
}
$origpath
=
substr
(
$origpath
,
0
,
$questionpos
);
$origpath
=
substr
(
$origpath
,
0
,
$questionpos
);
}
// Generally we assume that $_GET['qa-rewrite'] has the right path depth, but this won't be the case if there's
...
...
@@ -89,72 +89,74 @@
// If 'REQUEST_URI' and 'qa-rewrite' already match (as on Nginx), we can skip this.
$normalizedpath
=
urldecode
(
$origpath
);
if
(
substr
(
$normalizedpath
,
-
strlen
(
$qa_rewrite
))
!==
$qa_rewrite
)
{
$keepparts
=
count
(
$requestparts
);
$requestparts
=
explode
(
'/'
,
urldecode
(
$origpath
));
// new request calculated from $_SERVER['REQUEST_URI']
$keepparts
=
count
(
$requestparts
);
$requestparts
=
explode
(
'/'
,
urldecode
(
$origpath
));
// new request calculated from $_SERVER['REQUEST_URI']
// loop forwards so we capture all parts
for
(
$part
=
0
,
$max
=
count
(
$requestparts
);
$part
<
$max
;
$part
++
)
{
for
(
$part
=
0
,
$max
=
count
(
$requestparts
);
$part
<
$max
;
$part
++
)
{
if
(
is_numeric
(
strpos
(
$requestparts
[
$part
],
'&'
))
||
is_numeric
(
strpos
(
$requestparts
[
$part
],
'#'
)))
{
$keepparts
+=
count
(
$requestparts
)
-
$part
-
1
;
// this is how many parts remain
break
;
}
}
$requestparts
=
array_slice
(
$requestparts
,
-
$keepparts
);
// remove any irrelevant parts from the beginning
$requestparts
=
array_slice
(
$requestparts
,
-
$keepparts
);
// remove any irrelevant parts from the beginning
}
}
$relativedepth
=
count
(
$requestparts
);
}
elseif
(
isset
(
$_GET
[
'qa'
]))
{
if
(
strpos
(
$_GET
[
'qa'
],
'/'
)
===
false
)
{
$urlformat
=
(
(
empty
(
$_SERVER
[
'REQUEST_URI'
]))
||
(
strpos
(
$_SERVER
[
'REQUEST_URI'
],
'/index.php'
)
!==
false
)
)
$relativedepth
=
count
(
$requestparts
);
}
elseif
(
isset
(
$_GET
[
'qa'
]))
{
if
(
strpos
(
$_GET
[
'qa'
],
'/'
)
===
false
)
{
$urlformat
=
(
empty
(
$_SERVER
[
'REQUEST_URI'
])
||
strpos
(
$_SERVER
[
'REQUEST_URI'
],
'/index.php'
)
!==
false
)
?
QA_URL_FORMAT_SAFEST
:
QA_URL_FORMAT_PARAMS
;
$requestparts
=
array
(
qa_gpc_to_string
(
$_GET
[
'qa'
]));
$requestparts
=
array
(
qa_gpc_to_string
(
$_GET
[
'qa'
]));
for
(
$part
=
1
;
$part
<
10
;
$part
++
)
for
(
$part
=
1
;
$part
<
10
;
$part
++
)
{
if
(
isset
(
$_GET
[
'qa_'
.
$part
]))
{
$requestparts
[]
=
qa_gpc_to_string
(
$_GET
[
'qa_'
.
$part
]);
$requestparts
[]
=
qa_gpc_to_string
(
$_GET
[
'qa_'
.
$part
]);
unset
(
$_GET
[
'qa_'
.
$part
]);
}
}
else
{
$urlformat
=
QA_URL_FORMAT_PARAM
;
$requestparts
=
explode
(
'/'
,
qa_gpc_to_string
(
$_GET
[
'qa'
]));
}
}
else
{
$urlformat
=
QA_URL_FORMAT_PARAM
;
$requestparts
=
explode
(
'/'
,
qa_gpc_to_string
(
$_GET
[
'qa'
]));
}
unset
(
$_GET
[
'qa'
]);
}
else
{
$phpselfunescaped
=
strtr
(
$_SERVER
[
'PHP_SELF'
],
'+'
,
' '
);
// seems necessary, and plus does not work with this scheme
$indexpath
=
'/index.php/'
;
$indexpos
=
strpos
(
$phpselfunescaped
,
$indexpath
);
}
else
{
$phpselfunescaped
=
strtr
(
$_SERVER
[
'PHP_SELF'
],
'+'
,
' '
);
// seems necessary, and plus does not work with this scheme
$indexpath
=
'/index.php/'
;
$indexpos
=
strpos
(
$phpselfunescaped
,
$indexpath
);
if
(
is_numeric
(
$indexpos
))
{
$urlformat
=
QA_URL_FORMAT_INDEX
;
$requestparts
=
explode
(
'/'
,
substr
(
$phpselfunescaped
,
$indexpos
+
strlen
(
$indexpath
)));
$relativedepth
=
1
+
count
(
$requestparts
);
}
else
{
$urlformat
=
null
;
// at home page so can't identify path type
$requestparts
=
array
();
$urlformat
=
QA_URL_FORMAT_INDEX
;
$requestparts
=
explode
(
'/'
,
substr
(
$phpselfunescaped
,
$indexpos
+
strlen
(
$indexpath
)));
$relativedepth
=
1
+
count
(
$requestparts
);
}
else
{
$urlformat
=
null
;
// at home page so can't identify path type
$requestparts
=
array
();
}
}
foreach
(
$requestparts
as
$part
=>
$requestpart
)
// remove any blank parts
foreach
(
$requestparts
as
$part
=>
$requestpart
)
{
// remove any blank parts
if
(
!
strlen
(
$requestpart
))
unset
(
$requestparts
[
$part
]);
}
reset
(
$requestparts
);
$key
=
key
(
$requestparts
);
$key
=
key
(
$requestparts
);
$replacement
=
array_search
(
@
$requestparts
[
$key
],
qa_get_request_map
())
;
if
(
$replacement
!==
false
)
$requestparts
[
$key
]
=
$replacement
;
$replacement
=
isset
(
$requestparts
[
$key
])
?
array_search
(
$requestparts
[
$key
],
qa_get_request_map
())
:
false
;
if
(
$replacement
!==
false
)
$requestparts
[
$key
]
=
$replacement
;
qa_set_request
(
implode
(
'/'
,
$requestparts
),
(
$relativedepth
>
1
)
?
str_repeat
(
'../'
,
$relativedepth
-
1
)
:
'./'
,
(
$relativedepth
>
1
?
str_repeat
(
'../'
,
$relativedepth
-
1
)
:
'./'
)
,
$urlformat
);
}
...
...
@@ -164,24 +166,21 @@
// Branch off to appropriate file for further handling
$requestlower
=
strtolower
(
qa_request
());
$requestlower
=
strtolower
(
qa_request
());
if
(
$requestlower
==
'install'
)
if
(
$requestlower
==
'install'
)
require
QA_INCLUDE_DIR
.
'qa-install.php'
;
elseif
(
$requestlower
==
(
'url/test/'
.
QA_URL_TEST_STRING
))
elseif
(
$requestlower
==
'url/test/'
.
QA_URL_TEST_STRING
)
require
QA_INCLUDE_DIR
.
'qa-url-test.php'
;
else
{
// enable gzip compression for output (needs to come early)
// skip admin pages since some of these contain lengthy processes
if
(
QA_HTML_COMPRESSION
&&
substr
(
$requestlower
,
0
,
6
)
!=
'admin/'
)
{
if
(
extension_loaded
(
'zlib'
)
&&
!
headers_sent
())
ob_start
(
'ob_gzhandler'
);
}
// Enable gzip compression for output (needs to come early)
if
(
QA_HTML_COMPRESSION
)
// on by default
if
(
substr
(
$requestlower
,
0
,
6
)
!=
'admin/'
)
// not for admin pages since some of these contain lengthy processes
if
(
extension_loaded
(
'zlib'
)
&&
!
headers_sent
())
ob_start
(
'ob_gzhandler'
);
if
(
substr
(
$requestlower
,
0
,
5
)
==
'feed/'
)
if
(
substr
(
$requestlower
,
0
,
5
)
==
'feed/'
)
require
QA_INCLUDE_DIR
.
'qa-feed.php'
;
else
require
QA_INCLUDE_DIR
.
'qa-page.php'
;
...
...
@@ -189,8 +188,3 @@
}
qa_report_process_stage
(
'shutdown'
);
/*
Omit PHP closing tag to help avoid accidental output
*/
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment