| @@ -1,8 +1,7 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -include_once dirname( __FILE__ ) . '/modules/wordpress.php'; | |
| 4 | -include_once dirname( __FILE__ ) . '/database/database-status.php'; | |
| 3 | +include_once dirname( __FILE__ ).'/modules/wordpress.php'; | |
| 5 | 4 | |
| 6 | 5 | class Redirection { |
| 7 | 6 | private static $instance = null; |
| 8 | 7 | private $module; |
| @@ -15,60 +14,15 @@ | ||
| 15 | 14 | return self::$instance; |
| 16 | 15 | } |
| 17 | 16 | |
| 18 | 17 | public function __construct() { |
| 19 | - if ( ! $this->can_start() ) { | |
| 20 | - return; | |
| 21 | - } | |
| 22 | - | |
| 23 | 18 | $this->module = Red_Module::get( WordPress_Module::MODULE_ID ); |
| 24 | 19 | $this->module->start(); |
| 25 | 20 | |
| 26 | 21 | 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 | - } | |
| 22 | + add_action( 'redirection_url_target', array( $this, 'replace_special_tags' ) ); | |
| 35 | 23 | } |
| 36 | 24 | |
| 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 | 25 | public function clean_redirection_logs() { |
| 72 | 26 | $flusher = new Red_Flusher(); |
| 73 | 27 | $flusher->flush(); |
| 74 | 28 | } |
| @@ -89,15 +43,8 @@ | ||
| 89 | 43 | } |
| 90 | 44 | } |
| 91 | 45 | |
| 92 | 46 | return $url; |
| 93 | - } | |
| 94 | - | |
| 95 | - /** | |
| 96 | - * Used for unit tests | |
| 97 | - */ | |
| 98 | - public function get_module() { | |
| 99 | - return $this->module; | |
| 100 | 47 | } |
| 101 | 48 | } |
| 102 | 49 | |
| 103 | 50 | add_action( 'plugins_loaded', array( 'Redirection', 'init' ) ); |