Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 2 additions & 19 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,8 @@ jobs:
uses: wordpress/plugin-check-action@v1
with:
build-dir: "./rsscloud"

phpcs:
name: Coding standards
runs-on: ubuntu-latest
steps:
- name: Check out source code
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
tools: cs2pr

- name: Install Composer dependencies
run: composer install --no-interaction

- name: Run PHPCS
run: vendor/bin/phpcs --standard=phpcs.xml.dist -q --report-checkstyle | cs2pr
exclude-checks: "plugin_header_fields,plugin_readme,late_escaping"
ignore-warnings: true

phpunit:
name: Run tests
Expand Down
2 changes: 1 addition & 1 deletion .wp-env.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"port": 8889,
"core": "WordPress/WordPress#7.0-branch",
"plugins": ["./rsscloud"],
"phpVersion": "7.4",
"phpVersion": "8.2",
"config": {
"WP_DEBUG": false,
"SCRIPT_DEBUG": false
Expand Down
18 changes: 17 additions & 1 deletion phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,23 @@
<ruleset name="WordPress Coding Standards for Plugins">
<description>Generally-applicable sniffs for WordPress plugins</description>

<rule ref="WordPress-Core" />
<rule ref="WordPress-Core">
<!-- Exclude spacing and formatting rules to minimize cosmetic changes. -->
<exclude name="Generic.ControlStructures.InlineControlStructure" />
<exclude name="Generic.Formatting.MultipleStatementAlignment" />
<exclude name="Generic.WhiteSpace.DisallowSpaceIndent" />
<exclude name="Generic.WhiteSpace.ScopeIndent" />
<exclude name="NormalizedArrays.Arrays.ArrayBraceSpacing" />
<exclude name="NormalizedArrays.Arrays.CommaAfterLast" />
<exclude name="PEAR.Functions.FunctionCallSignature" />
<exclude name="PSR2.Methods.FunctionClosingBrace" />
<exclude name="Squiz.ControlStructures.ControlSignature" />
<exclude name="Squiz.Functions.FunctionDeclarationArgumentSpacing" />
<exclude name="Universal.WhiteSpace.DisallowInlineTabs" />
<exclude name="WordPress.Arrays.ArrayDeclarationSpacing" />
<exclude name="WordPress.Arrays.ArrayKeySpacingRestrictions" />
<exclude name="WordPress.WhiteSpace.OperatorSpacing" />
</rule>

<!-- Check all PHP files in directory tree by default. -->
<arg name="extensions" value="php"/>
Expand Down
7 changes: 3 additions & 4 deletions rsscloud/data-storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
if ( ! defined( 'ABSPATH' ) ) {
exit;
}

if ( ! function_exists( 'rsscloud_get_hub_notifications' ) ) {
function rsscloud_get_hub_notifications() {
if ( !function_exists( 'rsscloud_get_hub_notifications' ) ) {
function rsscloud_get_hub_notifications( ) {
return get_option( 'rsscloud_hub_notifications' );
}
}

if ( ! function_exists( 'rsscloud_update_hub_notifications' ) ) {
if ( !function_exists( 'rsscloud_update_hub_notifications' ) ) {
function rsscloud_update_hub_notifications( $notifications ) {
return update_option( 'rsscloud_hub_notifications', (array) $notifications );
}
Expand Down
102 changes: 37 additions & 65 deletions rsscloud/notification-request.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,123 +2,95 @@
if ( ! defined( 'ABSPATH' ) ) {
exit;
}

function rsscloud_hub_process_notification_request() {
// phpcs:disable WordPress.Security.NonceVerification.Missing -- Public RSSCloud hub endpoint, not a WP admin form.
function rsscloud_hub_process_notification_request( ) {
// Get the current set of notifications
$notify = rsscloud_get_hub_notifications();
if ( empty( $notify ) ) {
$notify = array();
}
$notify = rsscloud_get_hub_notifications( );
if ( empty( $notify ) )
$notify = array( );

// Must provide at least one URL to get notifications about
if ( empty( $_POST['url1'] ) ) {
if ( empty( $_POST['url1'] ) )
rsscloud_notify_result( 'false', 'No feed for url1.' );
}

// Only support http-post
$protocol = 'http-post';
if ( ! empty( $_POST['protocol'] ) && strtolower( sanitize_text_field( wp_unslash( $_POST['protocol'] ) ) ) !== 'http-post' ) {
if ( !empty( $_POST['protocol'] ) && strtolower( sanitize_text_field( wp_unslash( $_POST['protocol'] ) ) ) !== 'http-post' ) {
do_action( 'rsscloud_protocol_not_post' );
rsscloud_notify_result( 'false', 'Only http-post notifications are supported at this time.' );
}

// Assume port 80
$port = 80;
if ( ! empty( $_POST['port'] ) ) {
if ( !empty( $_POST['port'] ) )
$port = (int) $_POST['port'];
}

// Path is required
if ( empty( $_POST['path'] ) ) {
if ( empty( $_POST['path'] ) )
rsscloud_notify_result( 'false', 'No path provided.' );
}

$path = str_replace( '@', '', sanitize_text_field( wp_unslash( $_POST['path'] ) ) );
if ( '/' !== $path[0] ) {
if ( $path[0] != '/' )
$path = '/' . $path;
}

// Figure out what the blog and notification URLs are
$rss2_url = get_bloginfo( 'rss2_url' );
if ( defined( 'RSSCLOUD_FEED_URL' ) ) {
if ( defined( 'RSSCLOUD_FEED_URL' ) )
$rss2_url = RSSCLOUD_FEED_URL;
}

$remote_addr = isset( $_SERVER['REMOTE_ADDR'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) : '';
$notify_url = $remote_addr . ':' . $port . $path;
if ( empty( $_POST['domain'] ) && empty( $_SERVER['REMOTE_ADDR'] ) )
rsscloud_notify_result( 'false', 'No domain provided and REMOTE_ADDR is not available.' );

$notify_url = sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) . ':' . $port . $path;

if ( ! empty( $_POST['domain'] ) ) {
$domain = str_replace( '@', '', sanitize_text_field( wp_unslash( $_POST['domain'] ) ) );
if ( !empty( $_POST['domain'] ) ) {
$domain = str_replace( '@', '', sanitize_text_field( wp_unslash( $_POST['domain'] ) ) );
$notify_url = $domain . ':' . $port . $path;
if ( false === strpos( $notify_url, 'http://' ) ) {
if ( false === strpos( $notify_url, 'http://' ) )
$notify_url = 'http://' . $notify_url;
}

$challenge = rsscloud_generate_challenge();

$result = wp_safe_remote_get(
$notify_url . '?url=' . esc_url( sanitize_url( wp_unslash( $_POST['url1'] ) ) ) . '&challenge=' . $challenge,
array(
'method' => 'GET',
'timeout' => RSSCLOUD_HTTP_TIMEOUT,
'user-agent' => RSSCLOUD_USER_AGENT,
'port' => $port,
)
);

$challenge = rsscloud_generate_challenge( );

$result = wp_safe_remote_get( $notify_url . '?url=' . esc_url( wp_unslash( $_POST['url1'] ) ) . '&challenge=' . $challenge, array( 'method' => 'GET', 'timeout' => RSSCLOUD_HTTP_TIMEOUT, 'user-agent' => RSSCLOUD_USER_AGENT, 'port' => $port, ) );
} else {
if ( false === strpos( $notify_url, 'http://' ) ) {
if ( false === strpos( $notify_url, 'http://' ) )
$notify_url = 'http://' . $notify_url;
}

$result = wp_safe_remote_post(
$notify_url,
array(
'method' => 'POST',
'timeout' => RSSCLOUD_HTTP_TIMEOUT,
'user-agent' => RSSCLOUD_USER_AGENT,
'port' => $port,
'body' => array( 'url' => sanitize_url( wp_unslash( $_POST['url1'] ) ) ),
)
);
}

if ( isset( $result->errors['http_request_failed'][0] ) ) {
rsscloud_notify_result( 'false', 'Error testing notification URL : ' . $result->errors['http_request_failed'][0] );
$result = wp_safe_remote_post( $notify_url, array( 'method' => 'POST', 'timeout' => RSSCLOUD_HTTP_TIMEOUT, 'user-agent' => RSSCLOUD_USER_AGENT, 'port' => $port, 'body' => array( 'url' => esc_url_raw( wp_unslash( $_POST['url1'] ) ) ) ) );
}

if ( is_wp_error( $result ) )
rsscloud_notify_result( 'false', 'Error testing notification URL : ' . $result->get_error_message() );

$status_code = (int) $result['response']['code'];

if ( $status_code < 200 || $status_code > 299 ) {
if ( $status_code < 200 || $status_code > 299 )
rsscloud_notify_result( 'false', 'Error testing notification URL. The URL returned HTTP status code: ' . $result['response']['code'] . ' - ' . $result['response']['message'] . '.' );
}

// challenge must match for domain requests
if ( ! empty( $_POST['domain'] ) ) {
if ( empty( $result['body'] ) || $result['body'] !== $challenge ) {
if ( !empty( $_POST['domain'] ) ) {
if ( empty( $result['body'] ) || $result['body'] != $challenge )
rsscloud_notify_result( 'false', 'The response body did not match the challenge string' );
}

}

// Passed all the tests, add this to the list of notifications for
foreach ( $_POST as $key => $feed_url ) {
if ( ! preg_match( '|url\d+|', $key ) ) {
if ( !preg_match( '|url\d+|', $key ) )
continue;
}

$feed_url = esc_url_raw( wp_unslash( $feed_url ) );

// Only allow requests for the RSS2 posts feed
if ( $feed_url !== $rss2_url ) {
if ( $feed_url != $rss2_url )
rsscloud_notify_result( 'false', "You can only request updates for {$rss2_url}" );
}

$notify[ $feed_url ][ $notify_url ]['protocol'] = $protocol;
$notify[ $feed_url ][ $notify_url ]['status'] = 'active';
$notify[ $feed_url ][ $notify_url ]['failure_count'] = 0;
$notify[$feed_url][$notify_url]['protocol'] = $protocol;
$notify[$feed_url][$notify_url]['status'] = 'active';
$notify[$feed_url][$notify_url]['failure_count'] = 0;
}

do_action( 'rsscloud_add_notify_subscription' );

rsscloud_update_hub_notifications( $notify );
rsscloud_notify_result( 'true', 'Registration successful.' );
// phpcs:enable WordPress.Security.NonceVerification.Missing
} // function rsscloud_hub_notify
15 changes: 5 additions & 10 deletions rsscloud/readme.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
=== RSS Cloud ===
=== Plugin Name ===
Contributors: josephscott, automattic
Tags: rss
Requires at least: 2.8
Tested up to: 7.0
Stable tag: 0.5.1
License: GPL-2.0-or-later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Tested up to: 6.1.1
Stable tag: 0.5.0

Adds RSSCloud ( http://rsscloud.co/ ) capabilities to your RSS feed.
Adds RSSCloud ( http://rsscloud.org/ ) capabilities to your RSS feed.

== Description ==

Adds RSSCloud ( http://rsscloud.co/ ) capabilities to your RSS feed.
Adds RSSCloud ( http://rsscloud.org/ ) capabilities to your RSS feed.

== Changelog ==

= 0.5.1 =
* Fix loose comparisons to use strict equality operators per WordPress coding standards

= 0.5.0 =
* Updates to support PHP 8+
* Check for http scheme in the $notify_url, add it if missing
Expand Down
Loading
Loading