FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
redirection/redirection-front.php at trunk · johngodley/redirection · GitHub
johngodley
/
redirection
Public
Notifications
You must be signed in to change notification settings
Fork
157
Star
632
Code
Issues
97
Pull requests
11
Actions
Projects
Security and quality
1
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
redirection
/
redirection-front.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
158 lines (133 loc) · 2.99 KB
Breadcrumbs
redirection
/
redirection-front.php
Copy path
File metadata and controls
158 lines (133 loc) · 2.99 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?php
require_once
__DIR__
.
'
/modules/wordpress.php
'
;
require_once
__DIR__
.
'
/models/canonical.php
'
;
use
Redirection
\
Database
\
Status
;
/**
* This powers all of the front-end redirecting
*/
class
Redirection {
/**
* Instance variable
*
* @var Redirection|null
*/
private
static
$
instance
=
null
;
/**
* WordPress module
*
* @var WordPress_Module|false
*/
private
$
module
=
false
;
/**
* Singleton
*
* @return Redirection
*/
public
static
function
init
() {
if
(
is_null
(
self
::
$
instance
) ) {
self
::
$
instance
=
new
Redirection
();
}
return
self
::
$
instance
;
}
/**
* Constructor
*/
public
function
__construct
() {
if
( !
$
this
->
can_start
() ) {
return
;
}
/** @var WordPress_Module|false */
$
module
= Red_Module::
get
( WordPress_Module::
MODULE_ID
);
$
this
->
module
=
$
module
;
if
(
$
this
->
module
!==
false
) {
$
this
->
module
->
start
();
}
add_action
( Red_Flusher::
DELETE_HOOK
,
array
(
$
this
,
'
clean_redirection_logs
'
) );
add_filter
(
'
redirection_url_target
'
, [
$
this
,
'
transform_url
'
] );
$
options
= Red_Options::
get
();
if
(
$
options
[
'
ip_logging
'
] ===
0
) {
add_filter
(
'
redirection_request_ip
'
,
array
(
$
this
,
'
no_ip_logging
'
) );
}
elseif
(
$
options
[
'
ip_logging
'
] ===
2
) {
add_filter
(
'
redirection_request_ip
'
,
array
(
$
this
,
'
mask_ip
'
) );
}
}
/**
* @param string $url
* @return string
*/
public
function
transform_url
(
$
url
) {
$
transformer
=
new
Red_Url_Transform
();
return
$
transformer
->
transform
(
$
url
);
}
/**
* Check if Redirection can run. We require the database to be installed.
*
* @return boolean
*/
public
function
can_start
() {
$
status
=
new
Status
();
if
(
$
status
->
needs_installing
() ) {
return
false
;
}
return
true
;
}
/**
* Override the IP with an empty value
*
* @param string $ip IP.
* @return string
*/
public
function
no_ip_logging
(
$
ip
) {
return
''
;
}
/**
* Override the IP with a masked IP
*
* @param string $ip IP.
* @return string
*/
public
function
mask_ip
(
$
ip
) {
$
ip
=
trim
(
$
ip
);
if
(
strpos
(
$
ip
,
'
:
'
) !==
false
) {
$
packed
=
inet_pton
(
trim
(
$
ip
) );
if
(
$
packed
===
false
) {
return
''
;
}
// Mask lower 64 bits of the IPv6 address (keep the upper 64 bits).
$
mask
=
str_repeat
(
"\xff"
,
8
) .
str_repeat
(
"\x00"
,
8
);
$
masked
=
$
packed
&
$
mask
;
$
converted
=
inet_ntop
(
$
masked
);
if
(
$
converted
===
false
) {
return
''
;
}
return
$
converted
;
}
$
parts
= [];
if
(
strlen
(
$
ip
) >
0
) {
$
parts
=
explode
(
'
.
'
,
$
ip
);
}
if
(
count
(
$
parts
) >
0
) {
$
parts
[
count
(
$
parts
) -
1
] =
0
;
}
return
implode
(
'
.
'
,
$
parts
);
}
/**
* Hook to flush the logs
*
* @return void
*/
public
function
clean_redirection_logs
() {
$
flusher
=
new
Red_Flusher
();
$
flusher
->
flush
();
}
/**
* Used for unit tests
*
* @return WordPress_Module|false
*/
public
function
get_module
() {
return
$
this
->
module
;
}
}
// @phpstan-ignore return.void
add_action
(
'
plugins_loaded
'
,
array
(
'
Redirection
'
,
'
init
'
) );
Back
|
FazBrowse Home
|
New Git URL