Skip to content

Commit

Permalink
Plugin updates January 2024.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean12mps committed Jan 25, 2024
1 parent c948f9a commit 80ee065
Show file tree
Hide file tree
Showing 185 changed files with 1,210 additions and 921 deletions.
6 changes: 3 additions & 3 deletions wp-content/plugins/redirection/actions/pass.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Pass_Action extends Url_Action {
/**
* Process an external passthrough - a URL that lives external to this server.
*
* @param String $url Target URL.
* @param string $url Target URL.
* @return void
*/
public function process_external( $url ) {
Expand All @@ -21,7 +21,7 @@ public function process_external( $url ) {
/**
* Process an internal passthrough - a URL that lives on the same server. Here we change the request URI and continue without making a remote request.
*
* @param String $target Target URL.
* @param string $target Target URL.
* @return void
*/
public function process_internal( $target ) {
Expand All @@ -42,7 +42,7 @@ public function process_internal( $target ) {
/**
* Is a URL external?
*
* @param String $target URL to test.
* @param string $target URL to test.
* @return boolean
*/
public function is_external( $target ) {
Expand Down
2 changes: 1 addition & 1 deletion wp-content/plugins/redirection/api/api-404.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class Redirection_Api_404 extends Redirection_Api_Filter_Route {
/**
* 404 API endpoint constructor
*
* @param String $namespace Namespace.
* @param string $namespace Namespace.
*/
public function __construct( $namespace ) {
$orders = [ 'url', 'ip', 'total', 'count', '' ];
Expand Down
2 changes: 1 addition & 1 deletion wp-content/plugins/redirection/api/api-group.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class Redirection_Api_Group extends Redirection_Api_Filter_Route {
/**
* 404 API endpoint constructor
*
* @param String $namespace Namespace.
* @param string $namespace Namespace.
*/
public function __construct( $namespace ) {
$orders = [ 'name', 'id', '' ];
Expand Down
2 changes: 1 addition & 1 deletion wp-content/plugins/redirection/api/api-log.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class Redirection_Api_Log extends Redirection_Api_Filter_Route {
/**
* Log API endpoint constructor
*
* @param String $namespace Namespace.
* @param string $namespace Namespace.
*/
public function __construct( $namespace ) {
$orders = [ 'url', 'ip', 'total', 'count', '' ];
Expand Down
2 changes: 1 addition & 1 deletion wp-content/plugins/redirection/api/api-redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class Redirection_Api_Redirect extends Redirection_Api_Filter_Route {
/**
* Redirect API endpoint constructor
*
* @param String $namespace Namespace.
* @param string $namespace Namespace.
*/
public function __construct( $namespace ) {
$orders = [ 'source', 'last_count', 'last_access', 'position', 'id', '' ];
Expand Down
4 changes: 2 additions & 2 deletions wp-content/plugins/redirection/api/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ protected function get_filter_args( $order_fields, $filters = [] ) {
/**
* Register a bulk action route
*
* @param String $namespace Namespace.
* @param String $route Route.
* @param string $namespace Namespace.
* @param string $route Route.
* @param Array $orders
* @param Array $filters
* @param Object $callback
Expand Down
13 changes: 9 additions & 4 deletions wp-content/plugins/redirection/fileio/csv.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function force_download() {
}

public function get_data( array $items, array $groups ) {
$lines = [ implode( ',', array( 'source', 'target', 'regex', 'code', 'type', 'match', 'hits', 'title', 'status' ) ) ];
$lines = [ implode( ',', array( 'source', 'target', 'regex', 'code', 'type', 'hits', 'title', 'status' ) ) ];

foreach ( $items as $line ) {
$lines[] = $this->item_as_csv( $line );
Expand Down Expand Up @@ -90,9 +90,13 @@ public function load_from_file( $group_id, $file, $separator ) {
global $wpdb;

$count = 0;
$group = Red_Group::get( $group_id );
if ( ! $group ) {
return 0;
}

while ( ( $csv = fgetcsv( $file, 5000, $separator ) ) ) {
$item = $this->csv_as_item( $csv, $group_id );
$item = $this->csv_as_item( $csv, $group );

if ( $item && $this->item_is_valid( $item ) ) {
$created = Red_Item::create( $item );
Expand Down Expand Up @@ -137,18 +141,19 @@ private function get_action_type( $code ) {
return 'url';
}

public function csv_as_item( $csv, $group ) {
public function csv_as_item( $csv, Red_Group $group ) {
if ( count( $csv ) > 1 && $csv[ self::CSV_SOURCE ] !== 'source' && $csv[ self::CSV_TARGET ] !== 'target' ) {
$code = isset( $csv[ self::CSV_CODE ] ) ? $this->get_valid_code( $csv[ self::CSV_CODE ] ) : 301;

return array(
'url' => trim( $csv[ self::CSV_SOURCE ] ),
'action_data' => array( 'url' => trim( $csv[ self::CSV_TARGET ] ) ),
'regex' => isset( $csv[ self::CSV_REGEX ] ) ? $this->parse_regex( $csv[ self::CSV_REGEX ] ) : $this->is_regex( $csv[ self::CSV_SOURCE ] ),
'group_id' => $group,
'group_id' => $group->get_id(),
'match_type' => 'url',
'action_type' => $this->get_action_type( $code ),
'action_code' => $code,
'status' => $group->is_enabled() ? 'enabled' : 'disabled',
);
}

Expand Down
2 changes: 1 addition & 1 deletion wp-content/plugins/redirection/matches/from-notfrom.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private function get_matched_target( $matched ) {
/**
* Load the data into the instance.
*
* @param String $values Serialized PHP data.
* @param string $values Serialized PHP data.
* @return array
*/
private function load_data( $values ) {
Expand Down
2 changes: 1 addition & 1 deletion wp-content/plugins/redirection/matches/from-url.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private function get_matched_target( $matched ) {
/**
* Load the data into the instance.
*
* @param String $values Serialized PHP data.
* @param string $values Serialized PHP data.
* @return array
*/
private function load_data( $values ) {
Expand Down
2 changes: 1 addition & 1 deletion wp-content/plugins/redirection/matches/http-header.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function get_data() {
/**
* Load the match data into this instance.
*
* @param String $values Match values, as read from the database (plain text or serialized PHP).
* @param string $values Match values, as read from the database (plain text or serialized PHP).
* @return void
*/
public function load( $values ) {
Expand Down
6 changes: 3 additions & 3 deletions wp-content/plugins/redirection/matches/ip.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public function save( array $details, $no_target_url = false ) {
/**
* Sanitize a single IP
*
* @param String $ip IP.
* @return String|false
* @param string $ip IP.
* @return string|false
*/
private function sanitize_single_ip( $ip ) {
$ip = @inet_pton( trim( sanitize_text_field( $ip ) ) );
Expand All @@ -52,7 +52,7 @@ private function sanitize_ips( array $ips ) {
/**
* Get a list of IPs that match.
*
* @param String $match_ip IP to match.
* @param string $match_ip IP to match.
* @return string[]
*/
private function get_matching_ips( $match_ip ) {
Expand Down
6 changes: 3 additions & 3 deletions wp-content/plugins/redirection/matches/language.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public function save( array $details, $no_target_url = false ) {
/**
* Sanitize the language value to a CSV string
*
* @param String $language User supplied language strings.
* @return String
* @param string $language User supplied language strings.
* @return string
*/
private function sanitize_language( $language ) {
$parts = explode( ',', str_replace( ' ', '', sanitize_text_field( $language ) ) );
Expand Down Expand Up @@ -56,7 +56,7 @@ public function get_data() {
/**
* Load the match data into this instance.
*
* @param String $values Match values, as read from the database (plain text or serialized PHP).
* @param string $values Match values, as read from the database (plain text or serialized PHP).
* @return void
*/
public function load( $values ) {
Expand Down
2 changes: 1 addition & 1 deletion wp-content/plugins/redirection/matches/login.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function get_data() {
/**
* Load the match data into this instance.
*
* @param String $values Match values, as read from the database (plain text or serialized PHP).
* @param string $values Match values, as read from the database (plain text or serialized PHP).
* @return void
*/
public function load( $values ) {
Expand Down
2 changes: 1 addition & 1 deletion wp-content/plugins/redirection/matches/page.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function get_data() {
/**
* Load the match data into this instance.
*
* @param String $values Match values, as read from the database (plain text or serialized PHP).
* @param string $values Match values, as read from the database (plain text or serialized PHP).
* @return void
*/
public function load( $values ) {
Expand Down
2 changes: 1 addition & 1 deletion wp-content/plugins/redirection/matches/referrer.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function get_data() {
/**
* Load the match data into this instance.
*
* @param String $values Match values, as read from the database (plain text or serialized PHP).
* @param string $values Match values, as read from the database (plain text or serialized PHP).
* @return void
*/
public function load( $values ) {
Expand Down
2 changes: 1 addition & 1 deletion wp-content/plugins/redirection/matches/server.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function get_data() {
/**
* Load the match data into this instance.
*
* @param String $values Match values, as read from the database (plain text or serialized PHP).
* @param string $values Match values, as read from the database (plain text or serialized PHP).
* @return void
*/
public function load( $values ) {
Expand Down
2 changes: 1 addition & 1 deletion wp-content/plugins/redirection/matches/user-agent.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function get_data() {
/**
* Load the match data into this instance.
*
* @param String $values Match values, as read from the database (plain text or serialized PHP).
* @param string $values Match values, as read from the database (plain text or serialized PHP).
* @return void
*/
public function load( $values ) {
Expand Down
2 changes: 1 addition & 1 deletion wp-content/plugins/redirection/matches/user-role.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function get_data() {
/**
* Load the match data into this instance.
*
* @param String $values Match values, as read from the database (plain text or serialized PHP).
* @param string $values Match values, as read from the database (plain text or serialized PHP).
* @return void
*/
public function load( $values ) {
Expand Down
4 changes: 2 additions & 2 deletions wp-content/plugins/redirection/models/action.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function get_type() {
/**
* Set the target for this action
*
* @param String $target_url The original URL from the client.
* @param string $target_url The original URL from the client.
* @return void
*/
public function set_target( $target_url ) {
Expand All @@ -112,7 +112,7 @@ public function set_target( $target_url ) {
/**
* Get the target for this action
*
* @return String|null
* @return string|null
*/
public function get_target() {
return $this->target;
Expand Down
2 changes: 1 addition & 1 deletion wp-content/plugins/redirection/models/group.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Red_Group {
/**
* Constructor
*
* @param String|Object $values Values.
* @param string|Object $values Values.
*/
public function __construct( $values = '' ) {
if ( is_object( $values ) ) {
Expand Down
6 changes: 5 additions & 1 deletion wp-content/plugins/redirection/models/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ private function normalize( $header ) {

if ( isset( $header['headerSettings'] ) && is_array( $header['headerSettings'] ) ) {
foreach ( $header['headerSettings'] as $key => $setting_value ) {
$settings[ $this->sanitize( sanitize_text_field( $key ) ) ] = $this->sanitize( $setting_value );
if ( is_array( $setting_value ) && isset( $setting_value['value'] ) ) {
$settings[ $this->sanitize( sanitize_text_field( $key ) ) ] = $this->sanitize( $setting_value['value'] );
} else {
$settings[ $this->sanitize( sanitize_text_field( $key ) ) ] = $this->sanitize( $setting_value );
}
}
}

Expand Down
26 changes: 26 additions & 0 deletions wp-content/plugins/redirection/models/ip.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

class Redirection_IP {
private $ip;

public function __construct( $ip = '' ) {
$this->ip = '';

$ip = sanitize_text_field( $ip );
$ip = explode( ',', $ip );
$ip = array_shift( $ip );
$ip = filter_var( $ip, FILTER_VALIDATE_IP );

// Convert to binary
// phpcs:ignore
$ip = @inet_pton( trim( $ip ) );
if ( $ip !== false ) {
// phpcs:ignore
$this->ip = @inet_ntop( $ip ); // Convert back to string
}
}

public function get() {
return $this->ip;
}
}
2 changes: 1 addition & 1 deletion wp-content/plugins/redirection/models/log/log-404.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Red_404_Log extends Red_Log {
* Get's the table name for this log object
*
* @param Object $wpdb WPDB object.
* @return String
* @return string
*/
protected static function get_table_name( $wpdb ) {
return "{$wpdb->prefix}redirection_404";
Expand Down
4 changes: 2 additions & 2 deletions wp-content/plugins/redirection/models/log/log-redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Red_Redirect_Log extends Red_Log {
* Get's the table name for this log object
*
* @param Object $wpdb WPDB object.
* @return String
* @return string
*/
protected static function get_table_name( $wpdb ) {
return "{$wpdb->prefix}redirection_logs";
Expand Down Expand Up @@ -150,7 +150,7 @@ private function get_redirect_name( $agent ) {
/**
* Convert a log entry to JSON
*
* @return Array
* @return array
*/
public function to_json() {
return array_merge( parent::to_json(), [
Expand Down
15 changes: 10 additions & 5 deletions wp-content/plugins/redirection/models/log/log.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ final public function __construct( array $values ) {
* Get's the table name for this log object
*
* @param Object $wpdb WPDB object.
* @return String
* @return string
*/
protected static function get_table_name( $wpdb ) {
return '';
Expand Down Expand Up @@ -173,7 +173,7 @@ public static function delete_all( array $params = [] ) {
/**
* Convert a log entry to JSON
*
* @return Array
* @return array
*/
public function to_json() {
return [
Expand All @@ -195,7 +195,7 @@ public function to_json() {
* Get filtered log entries
*
* @param array $params Filters.
* @return Array{items: Array, total: integer}
* @return array{items: Array, total: integer}
*/
public static function get_filtered( array $params ) {
global $wpdb;
Expand Down Expand Up @@ -234,7 +234,7 @@ public static function get_filtered( array $params ) {
*
* @param string $group Group type.
* @param array $params Filter params.
* @return Array{items: mixed, total: integer}
* @return array{items: mixed, total: integer}
*/
public static function get_grouped( $group, array $params ) {
global $wpdb;
Expand Down Expand Up @@ -280,7 +280,7 @@ public static function get_grouped( $group, array $params ) {
* Convert a set of filters to a SQL query.
*
* @param array $params Filters.
* @return Array{orderby: string, direction: string, limit: integer, offset: integer, where: string}
* @return array{orderby: string, direction: string, limit: integer, offset: integer, where: string}
*/
public static function get_query( array $params ) {
$query = [
Expand Down Expand Up @@ -390,6 +390,7 @@ protected static function get_query_filter( array $filter ) {
* @return array
*/
protected static function sanitize_create( $domain, $url, $ip, array $details = [] ) {
$url = urldecode( $url );
$insert = [
'url' => substr( sanitize_text_field( $url ), 0, self::MAX_URL_LENGTH ),
'domain' => substr( sanitize_text_field( $domain ), 0, self::MAX_DOMAIN_LENGTH ),
Expand Down Expand Up @@ -482,6 +483,10 @@ public static function export_to_csv() {

// phpcs:ignore
$stdout = fopen( 'php://output', 'w' );
if ( ! $stdout ) {
return;
}

fputcsv( $stdout, static::get_csv_header() );

global $wpdb;
Expand Down
Loading

0 comments on commit 80ee065

Please sign in to comment.