2011-07-13 19:47:40 +01:00
|
|
|
<?php
|
2020-08-04 12:12:17 +01:00
|
|
|
// 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/>.
|
|
|
|
|
2011-07-13 19:47:40 +01:00
|
|
|
/**
|
2020-08-04 12:12:17 +01:00
|
|
|
* Action periodically pinged by a page to keep a channel alive
|
2011-07-13 19:47:40 +01:00
|
|
|
*
|
|
|
|
* @category Realtime
|
2020-08-04 12:12:17 +01:00
|
|
|
* @package GNUsocial
|
2011-07-13 19:47:40 +01:00
|
|
|
* @author Evan Prodromou <evan@status.net>
|
|
|
|
* @copyright 2011 StatusNet, Inc.
|
2020-08-04 12:12:17 +01:00
|
|
|
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
2011-07-13 19:47:40 +01:00
|
|
|
*/
|
|
|
|
|
2020-08-04 12:12:17 +01:00
|
|
|
defined('GNUSOCIAL') || die();
|
2011-07-13 19:47:40 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Action periodically pinged by a page to keep a channel alive
|
|
|
|
*
|
|
|
|
* @category Realtime
|
2020-08-04 12:12:17 +01:00
|
|
|
* @package GNUsocial
|
2011-07-13 19:47:40 +01:00
|
|
|
* @author Evan Prodromou <evan@status.net>
|
|
|
|
* @copyright 2011 StatusNet, Inc.
|
2020-08-04 12:12:17 +01:00
|
|
|
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
2011-07-13 19:47:40 +01:00
|
|
|
*/
|
|
|
|
class KeepalivechannelAction extends Action
|
|
|
|
{
|
|
|
|
protected $channelKey = null;
|
2019-04-26 00:34:17 +01:00
|
|
|
protected $channel = null;
|
2011-07-13 19:47:40 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* For initializing members of the class.
|
|
|
|
*
|
2019-04-26 00:34:17 +01:00
|
|
|
* @param array $args misc. arguments
|
2011-07-13 19:47:40 +01:00
|
|
|
*
|
2019-11-03 15:37:49 +00:00
|
|
|
* @return bool true
|
2019-04-26 00:34:17 +01:00
|
|
|
* @throws ClientException
|
2011-07-13 19:47:40 +01:00
|
|
|
*/
|
2019-11-03 15:37:49 +00:00
|
|
|
public function prepare(array $args = []): bool
|
2011-07-13 19:47:40 +01:00
|
|
|
{
|
2019-04-26 00:34:17 +01:00
|
|
|
parent::prepare($args);
|
2011-07-13 19:47:40 +01:00
|
|
|
|
|
|
|
if (!$this->isPost()) {
|
2011-08-19 16:11:29 +01:00
|
|
|
// TRANS: Client exception. Do not translate POST.
|
2011-07-13 19:47:40 +01:00
|
|
|
throw new ClientException(_m('You have to POST it.'));
|
|
|
|
}
|
|
|
|
|
2011-07-13 21:10:08 +01:00
|
|
|
$this->channelKey = $this->trimmed('channelkey');
|
2011-07-13 19:47:40 +01:00
|
|
|
|
|
|
|
if (empty($this->channelKey)) {
|
2011-08-19 16:11:29 +01:00
|
|
|
// TRANS: Client exception thrown when the channel key argument is missing.
|
2011-07-13 19:47:40 +01:00
|
|
|
throw new ClientException(_m('No channel key argument.'));
|
|
|
|
}
|
|
|
|
|
2013-08-18 12:04:58 +01:00
|
|
|
$this->channel = Realtime_channel::getKV('channel_key', $this->channelKey);
|
2011-07-13 19:47:40 +01:00
|
|
|
|
|
|
|
if (empty($this->channel)) {
|
2011-08-19 16:11:29 +01:00
|
|
|
// TRANS: Client exception thrown when referring to a non-existing channel.
|
2011-07-13 19:47:40 +01:00
|
|
|
throw new ClientException(_m('No such channel.'));
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2019-11-03 15:37:49 +00:00
|
|
|
public function handle(): void
|
2011-07-13 19:47:40 +01:00
|
|
|
{
|
|
|
|
$this->channel->touch();
|
|
|
|
|
2020-08-04 12:12:17 +01:00
|
|
|
http_response_code(204);
|
2011-07-13 19:47:40 +01:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return true if read only.
|
|
|
|
*
|
|
|
|
* MAY override
|
|
|
|
*
|
|
|
|
* @param array $args other arguments
|
|
|
|
*
|
2019-11-03 15:37:49 +00:00
|
|
|
* @return bool is read only action?
|
2011-07-13 19:47:40 +01:00
|
|
|
*/
|
2019-11-03 15:37:49 +00:00
|
|
|
public function isReadOnly($args): bool
|
2011-07-13 19:47:40 +01:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|