PluginProbe
Redirection / 4.2.2
Redirection v4.2.2
5.10.0 5.9.0 5.8.1 5.8.0 3.7.2 3.7.3 4.0 4.0.1 4.1 4.1.1 4.2 4.2.1 4.2.2 4.2.3 4.3 4.3.1 4.3.2 4.3.3 4.4 4.4.1 4.4.2 4.5 4.5.1 4.6.2 4.7.1 All 130 releases
redirection / redirection-front.php

redirection-front.php in Redirection 4.2.2, at redirection-front.php

104 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 include_once dirname( __FILE__ ) . '/modules/wordpress.php';
4 include_once dirname( __FILE__ ) . '/database/database-status.php';
5
6 class Redirection {
7 private static $instance = null;
8 private $module;
9
10 static function init() {
11 if ( is_null( self::$instance ) ) {
12 self::$instance = new Redirection();
13 }
14
15 return self::$instance;
16 }
17
18 public function __construct() {
19 if ( ! $this->can_start() ) {
20 return;
21 }
22
23 $this->module = Red_Module::get( WordPress_Module::MODULE_ID );
24 $this->module->start();
25
26 add_action( Red_Flusher::DELETE_HOOK, array( $this, 'clean_redirection_logs' ) );
27 add_filter( 'redirection_url_target', array( $this, 'replace_special_tags' ) );
28
29 $options = red_get_options();
30 if ( $options['ip_logging'] === 0 ) {
31 add_filter( 'redirection_request_ip', array( $this, 'no_ip_logging' ) );
32 } elseif ( $options['ip_logging'] === 2 ) {
33 add_filter( 'redirection_request_ip', array( $this, 'mask_ip' ) );
34 }
35 }
36
37 public function can_start() {
38 $status = new Red_Database_Status();
39 if ( $status->needs_installing() ) {
40 return false;
41 }
42
43 return true;
44 }
45
46 public function no_ip_logging( $ip ) {
47 return '';
48 }
49
50 public function mask_ip( $ip ) {
51 $ip = trim( $ip );
52
53 if ( strpos( $ip, ':' ) !== false ) {
54 $ip = @inet_pton( trim( $ip ) );
55
56 return @inet_ntop( $ip & pack( 'a16', 'ffff:ffff:ffff:ffff::ff00::0000::0000::0000' ) );
57 }
58
59 $parts = [];
60 if ( strlen( $ip ) > 0 ) {
61 $parts = explode( '.', $ip );
62 }
63
64 if ( count( $parts ) > 0 ) {
65 $parts[ count( $parts ) - 1 ] = 0;
66 }
67
68 return implode( '.', $parts );
69 }
70
71 public function clean_redirection_logs() {
72 $flusher = new Red_Flusher();
73 $flusher->flush();
74 }
75
76 /**
77 * From the distant Redirection past. Undecided whether to keep
78 */
79 public function replace_special_tags( $url ) {
80 if ( is_numeric( $url ) ) {
81 $url = get_permalink( $url );
82 } else {
83 $user = wp_get_current_user();
84
85 if ( ! empty( $user ) ) {
86 $url = str_replace( '%userid%', $user->ID, $url );
87 $url = str_replace( '%userlogin%', isset( $user->user_login ) ? $user->user_login : '', $url );
88 $url = str_replace( '%userurl%', isset( $user->user_url ) ? $user->user_url : '', $url );
89 }
90 }
91
92 return $url;
93 }
94
95 /**
96 * Used for unit tests
97 */
98 public function get_module() {
99 return $this->module;
100 }
101 }
102
103 add_action( 'plugins_loaded', array( 'Redirection', 'init' ) );
104