[RSSCloud] Avoid the deprecated in PHP each() function
This commit is contained in:
parent
d045bf6f5c
commit
fc7925f4c8
|
@ -1,45 +1,39 @@
|
||||||
<?php
|
<?php
|
||||||
|
// This file is part of GNU social - https://www.gnu.org/software/social
|
||||||
|
//
|
||||||
|
// GNU social is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// GNU social is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Affero General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
|
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Action to let RSSCloud aggregators request update notification when
|
* Action to let RSSCloud aggregators request update notification when
|
||||||
* user profile feeds change.
|
* user profile feeds change.
|
||||||
*
|
*
|
||||||
* PHP version 5
|
|
||||||
*
|
|
||||||
* @category Plugin
|
* @category Plugin
|
||||||
* @package StatusNet
|
* @package GNUsocial
|
||||||
* @author Zach Copley <zach@status.net>
|
* @author Zach Copley <zach@status.net>
|
||||||
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
|
* @copyright 2009 StatusNet, Inc.
|
||||||
* @link http://status.net/
|
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
||||||
*
|
|
||||||
* StatusNet - the distributed open-source microblogging tool
|
|
||||||
* Copyright (C) 2009, StatusNet, Inc.
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!defined('STATUSNET')) {
|
defined('GNUSOCIAL') || die();
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Action class to handle RSSCloud notification (subscription) requests
|
* Action class to handle RSSCloud notification (subscription) requests
|
||||||
*
|
*
|
||||||
* @category Plugin
|
* @category Plugin
|
||||||
* @package StatusNet
|
* @package GNUsocial
|
||||||
* @author Zach Copley <zach@status.net>
|
* @author Zach Copley <zach@status.net>
|
||||||
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
||||||
* @link http://status.net/
|
|
||||||
*/
|
*/
|
||||||
class RSSCloudRequestNotifyAction extends Action
|
class RSSCloudRequestNotifyAction extends Action
|
||||||
{
|
{
|
||||||
|
@ -47,10 +41,9 @@ class RSSCloudRequestNotifyAction extends Action
|
||||||
* Initialization.
|
* Initialization.
|
||||||
*
|
*
|
||||||
* @param array $args Web and URL arguments
|
* @param array $args Web and URL arguments
|
||||||
*
|
* @return bool false if user doesn't exist
|
||||||
* @return boolean false if user doesn't exist
|
|
||||||
*/
|
*/
|
||||||
function prepare(array $args = array())
|
public function prepare(array $args = [])
|
||||||
{
|
{
|
||||||
parent::prepare($args);
|
parent::prepare($args);
|
||||||
|
|
||||||
|
@ -82,7 +75,7 @@ class RSSCloudRequestNotifyAction extends Action
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
parent::handle();
|
parent::handle();
|
||||||
|
|
||||||
|
@ -104,7 +97,7 @@ class RSSCloudRequestNotifyAction extends Action
|
||||||
|
|
||||||
if (empty($this->protocol)) {
|
if (empty($this->protocol)) {
|
||||||
$missing[] = 'protocol';
|
$missing[] = 'protocol';
|
||||||
} else if (strtolower($this->protocol) != 'http-post') {
|
} elseif (strtolower($this->protocol) !== 'http-post') {
|
||||||
// TRANS: Form validation error displayed when HTTP POST is not used.
|
// TRANS: Form validation error displayed when HTTP POST is not used.
|
||||||
$msg = _m('Only HTTP POST notifications are supported at this time.');
|
$msg = _m('Only HTTP POST notifications are supported at this time.');
|
||||||
$this->showResult(false, $msg);
|
$this->showResult(false, $msg);
|
||||||
|
@ -117,10 +110,13 @@ class RSSCloudRequestNotifyAction extends Action
|
||||||
|
|
||||||
if (!empty($missing)) {
|
if (!empty($missing)) {
|
||||||
// TRANS: List separator.
|
// TRANS: List separator.
|
||||||
$separator = _m('SEPARATOR',', ');
|
$separator = _m('SEPARATOR', ', ');
|
||||||
// TRANS: Form validation error displayed when a request body is missing expected parameters.
|
// TRANS: Form validation error displayed when a request body is missing expected parameters.
|
||||||
// TRANS: %s is a list of parameters separated by a list separator (default: ", ").
|
// TRANS: %s is a list of parameters separated by a list separator (default: ", ").
|
||||||
$msg = sprintf(_m('The following parameters were missing from the request body: %s.'),implode($separator, $missing));
|
$msg = sprintf(
|
||||||
|
_m('The following parameters were missing from the request body: %s.'),
|
||||||
|
implode($separator, $missing)
|
||||||
|
);
|
||||||
$this->showResult(false, $msg);
|
$this->showResult(false, $msg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -139,8 +135,10 @@ class RSSCloudRequestNotifyAction extends Action
|
||||||
foreach ($this->feeds as $feed) {
|
foreach ($this->feeds as $feed) {
|
||||||
if (!$this->validateFeed($feed)) {
|
if (!$this->validateFeed($feed)) {
|
||||||
$nh = $this->getNotifyUrl();
|
$nh = $this->getNotifyUrl();
|
||||||
common_log(LOG_WARNING,
|
common_log(
|
||||||
"RSSCloud plugin - $nh tried to subscribe to invalid feed: $feed");
|
LOG_WARNING,
|
||||||
|
"RSSCloud plugin - {$nh} tried to subscribe to invalid feed: {$feed}"
|
||||||
|
);
|
||||||
|
|
||||||
// TRANS: Form validation error displayed when not providing a valid feed URL.
|
// TRANS: Form validation error displayed when not providing a valid feed URL.
|
||||||
$msg = _m('Feed subscription failed: Not a valid feed.');
|
$msg = _m('Feed subscription failed: Not a valid feed.');
|
||||||
|
@ -176,10 +174,9 @@ class RSSCloudRequestNotifyAction extends Action
|
||||||
* up via RSSCloud.
|
* up via RSSCloud.
|
||||||
*
|
*
|
||||||
* @param string $feed the feed in question
|
* @param string $feed the feed in question
|
||||||
*
|
* @return bool
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
function validateFeed($feed)
|
private function validateFeed(string $feed): bool
|
||||||
{
|
{
|
||||||
$user = $this->userFromFeed($feed);
|
$user = $this->userFromFeed($feed);
|
||||||
|
|
||||||
|
@ -196,11 +193,11 @@ class RSSCloudRequestNotifyAction extends Action
|
||||||
*
|
*
|
||||||
* @return array $feeds the list of feeds
|
* @return array $feeds the list of feeds
|
||||||
*/
|
*/
|
||||||
function getFeeds()
|
public function getFeeds()
|
||||||
{
|
{
|
||||||
$feeds = array();
|
$feeds = [];
|
||||||
|
|
||||||
while (list($key, $feed) = each($this->args)) {
|
foreach ($this->args as $key => $feed) {
|
||||||
if (preg_match('/^url\d*$/', $key)) {
|
if (preg_match('/^url\d*$/', $key)) {
|
||||||
$feeds[] = $feed;
|
$feeds[] = $feed;
|
||||||
}
|
}
|
||||||
|
@ -214,10 +211,9 @@ class RSSCloudRequestNotifyAction extends Action
|
||||||
* correctly. This is called before adding a subscription.
|
* correctly. This is called before adding a subscription.
|
||||||
*
|
*
|
||||||
* @param string $feed the feed to verify
|
* @param string $feed the feed to verify
|
||||||
*
|
* @return bool success result
|
||||||
* @return boolean success result
|
|
||||||
*/
|
*/
|
||||||
function testNotificationHandler($feed)
|
private function testNotificationHandler(string $feed): bool
|
||||||
{
|
{
|
||||||
$notifyUrl = $this->getNotifyUrl();
|
$notifyUrl = $this->getNotifyUrl();
|
||||||
|
|
||||||
|
@ -225,13 +221,18 @@ class RSSCloudRequestNotifyAction extends Action
|
||||||
|
|
||||||
if (isset($this->domain)) {
|
if (isset($this->domain)) {
|
||||||
// 'domain' param set, so we have to use GET and send a challenge
|
// 'domain' param set, so we have to use GET and send a challenge
|
||||||
common_log(LOG_INFO,
|
common_log(
|
||||||
'RSSCloud plugin - Testing notification handler with challenge: ' .
|
LOG_INFO,
|
||||||
$notifyUrl);
|
'RSSCloud plugin - Testing notification handler with '
|
||||||
|
. "challenge: {$notifyUrl}"
|
||||||
|
);
|
||||||
return $notifier->challenge($notifyUrl, $feed);
|
return $notifier->challenge($notifyUrl, $feed);
|
||||||
} else {
|
} else {
|
||||||
common_log(LOG_INFO, 'RSSCloud plugin - Testing notification handler: ' .
|
common_log(
|
||||||
$notifyUrl);
|
LOG_INFO,
|
||||||
|
'RSSCloud plugin - Testing notification handler: '
|
||||||
|
. $notifyUrl
|
||||||
|
);
|
||||||
|
|
||||||
return $notifier->postUpdate($notifyUrl, $feed);
|
return $notifier->postUpdate($notifyUrl, $feed);
|
||||||
}
|
}
|
||||||
|
@ -243,7 +244,7 @@ class RSSCloudRequestNotifyAction extends Action
|
||||||
*
|
*
|
||||||
* @return string notification handler url
|
* @return string notification handler url
|
||||||
*/
|
*/
|
||||||
function getNotifyUrl()
|
private function getNotifyUrl(): string
|
||||||
{
|
{
|
||||||
if (isset($this->domain)) {
|
if (isset($this->domain)) {
|
||||||
return 'http://' . $this->domain . ':' . $this->port . $this->path;
|
return 'http://' . $this->domain . ':' . $this->port . $this->path;
|
||||||
|
@ -258,10 +259,9 @@ class RSSCloudRequestNotifyAction extends Action
|
||||||
* validate feeds before adding a subscription.
|
* validate feeds before adding a subscription.
|
||||||
*
|
*
|
||||||
* @param string $feed the feed in question
|
* @param string $feed the feed in question
|
||||||
*
|
* @return bool success
|
||||||
* @return boolean success
|
|
||||||
*/
|
*/
|
||||||
function userFromFeed($feed)
|
private function userFromFeed(string $feed): bool
|
||||||
{
|
{
|
||||||
// We only do canonical RSS2 profile feeds (specified by ID), e.g.:
|
// We only do canonical RSS2 profile feeds (specified by ID), e.g.:
|
||||||
// http://www.example.com/api/statuses/user_timeline/2.rss
|
// http://www.example.com/api/statuses/user_timeline/2.rss
|
||||||
|
@ -282,10 +282,9 @@ class RSSCloudRequestNotifyAction extends Action
|
||||||
* Save an RSSCloud subscription
|
* Save an RSSCloud subscription
|
||||||
*
|
*
|
||||||
* @param string $feed a valid profile feed
|
* @param string $feed a valid profile feed
|
||||||
*
|
* @return bool success result
|
||||||
* @return boolean success result
|
|
||||||
*/
|
*/
|
||||||
function saveSubscription($feed)
|
private function saveSubscription(string $feed): bool
|
||||||
{
|
{
|
||||||
$user = $this->userFromFeed($feed);
|
$user = $this->userFromFeed($feed);
|
||||||
|
|
||||||
|
@ -319,17 +318,18 @@ class RSSCloudRequestNotifyAction extends Action
|
||||||
* Show an XML message indicating the subscription
|
* Show an XML message indicating the subscription
|
||||||
* was successful or failed.
|
* was successful or failed.
|
||||||
*
|
*
|
||||||
* @param boolean $success whether it was good or bad
|
* @param bool $success whether it was good or bad
|
||||||
* @param string $msg the message to output
|
* @param string $msg the message to output
|
||||||
*
|
*
|
||||||
* @return boolean success result
|
* @return bool success result
|
||||||
*/
|
*/
|
||||||
function showResult($success, $msg)
|
public function showResult(bool $success, string $msg): bool
|
||||||
{
|
{
|
||||||
$this->startXML();
|
$this->startXML();
|
||||||
$this->elementStart('notifyResult',
|
$this->elementStart('notifyResult', [
|
||||||
array('success' => ($success) ? 'true' : 'false',
|
'success' => ($success ? 'true' : 'false'),
|
||||||
'msg' => $msg));
|
'msg' => $msg,
|
||||||
|
]);
|
||||||
$this->endXML();
|
$this->endXML();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user