2021-08-02 14:10:03 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2022-01-02 08:27:47 +01:00
|
|
|
* @copyright Copyright (C) 2010-2022, the Friendica project
|
2021-08-02 14:10:03 +02:00
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* 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 <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Friendica\Module\Profile;
|
|
|
|
|
2021-08-02 19:03:06 +02:00
|
|
|
use Friendica\BaseModule;
|
|
|
|
use Friendica\Content\Text\BBCode;
|
|
|
|
use Friendica\Core\Renderer;
|
|
|
|
use Friendica\Database\DBA;
|
2021-08-02 14:10:03 +02:00
|
|
|
use Friendica\DI;
|
2021-08-02 19:03:06 +02:00
|
|
|
use Friendica\Model\Post;
|
2021-08-02 14:10:03 +02:00
|
|
|
use Friendica\Module\BaseProfile;
|
|
|
|
use Friendica\Network\HTTPException;
|
2021-08-04 07:58:07 +02:00
|
|
|
use Friendica\Util\DateTimeFormat;
|
2021-08-02 14:10:03 +02:00
|
|
|
|
|
|
|
class Schedule extends BaseProfile
|
|
|
|
{
|
2021-11-28 13:44:42 +01:00
|
|
|
protected function post(array $request = [])
|
2021-08-02 14:10:03 +02:00
|
|
|
{
|
2022-10-20 22:59:12 +02:00
|
|
|
if (!DI::userSession()->getLocalUserId()) {
|
2021-08-02 14:10:03 +02:00
|
|
|
throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
|
|
|
|
}
|
|
|
|
|
2021-08-02 21:18:44 +02:00
|
|
|
if (empty($_REQUEST['delete'])) {
|
|
|
|
throw new HTTPException\BadRequestException();
|
|
|
|
}
|
2021-08-02 22:56:34 +02:00
|
|
|
|
2022-10-20 22:59:12 +02:00
|
|
|
if (!DBA::exists('delayed-post', ['id' => $_REQUEST['delete'], 'uid' => DI::userSession()->getLocalUserId()])) {
|
2021-08-02 22:56:34 +02:00
|
|
|
throw new HTTPException\NotFoundException();
|
|
|
|
}
|
|
|
|
|
|
|
|
Post\Delayed::deleteById($_REQUEST['delete']);
|
2021-08-02 21:18:44 +02:00
|
|
|
}
|
|
|
|
|
2021-11-20 15:38:03 +01:00
|
|
|
protected function content(array $request = []): string
|
2021-08-02 21:18:44 +02:00
|
|
|
{
|
2022-10-20 22:59:12 +02:00
|
|
|
if (!DI::userSession()->getLocalUserId()) {
|
2021-08-02 21:18:44 +02:00
|
|
|
throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
|
2021-08-02 19:03:06 +02:00
|
|
|
}
|
|
|
|
|
2021-08-02 14:10:03 +02:00
|
|
|
$a = DI::app();
|
|
|
|
|
2021-08-09 21:48:39 +02:00
|
|
|
$o = self::getTabsHTML($a, 'schedule', true, $a->getLoggedInUserNickname(), false);
|
2021-08-02 14:10:03 +02:00
|
|
|
|
2021-08-02 19:03:06 +02:00
|
|
|
$schedule = [];
|
2022-10-20 22:59:12 +02:00
|
|
|
$delayed = DBA::select('delayed-post', [], ['uid' => DI::userSession()->getLocalUserId()]);
|
2021-08-02 19:03:06 +02:00
|
|
|
while ($row = DBA::fetch($delayed)) {
|
|
|
|
$parameter = Post\Delayed::getParametersForid($row['id']);
|
|
|
|
if (empty($parameter)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$schedule[] = [
|
|
|
|
'id' => $row['id'],
|
2021-08-04 07:58:07 +02:00
|
|
|
'scheduled_at' => DateTimeFormat::local($row['delayed']),
|
2021-08-02 19:03:06 +02:00
|
|
|
'content' => BBCode::toPlaintext($parameter['item']['body'], false)
|
|
|
|
];
|
|
|
|
}
|
|
|
|
DBA::close($delayed);
|
|
|
|
|
|
|
|
$tpl = Renderer::getMarkupTemplate('profile/schedule.tpl');
|
|
|
|
$o .= Renderer::replaceMacros($tpl, [
|
|
|
|
'$form_security_token' => BaseModule::getFormSecurityToken("profile_schedule"),
|
|
|
|
'$baseurl' => DI::baseUrl()->get(true),
|
|
|
|
'$title' => DI::l10n()->t('Scheduled Posts'),
|
2021-11-14 23:19:25 +01:00
|
|
|
'$nickname' => $this->parameters['nickname'] ?? '',
|
2021-08-02 19:03:06 +02:00
|
|
|
'$scheduled_at' => DI::l10n()->t('Scheduled'),
|
|
|
|
'$content' => DI::l10n()->t('Content'),
|
|
|
|
'$delete' => DI::l10n()->t('Remove post'),
|
|
|
|
'$schedule' => $schedule,
|
|
|
|
]);
|
|
|
|
|
2021-08-02 14:10:03 +02:00
|
|
|
return $o;
|
|
|
|
}
|
|
|
|
}
|