<?php
/**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2022, the Friendica project
*
- * @license GNU AGPL version 3 or any later version
+ * @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
namespace Friendica\Module\Settings;
-use Friendica\App;
use Friendica\Core\Hook;
use Friendica\Core\Renderer;
+use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\Database\DBStructure;
use Friendica\DI;
* If there is an action required through the URL / path, react
* accordingly and export the requested data.
*
- * @param array $parameters Router-supplied parameters
* @return string
* @throws HTTPException\ForbiddenException
* @throws HTTPException\InternalServerErrorException
*/
- public static function content(array $parameters = [])
+ protected function content(array $request = []): string
{
if (!local_user()) {
throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
}
- parent::content($parameters);
+ parent::content();
/**
* options shown on "Export personal data" page
* to the browser which then offers a save / open dialog
* to the user.
*
- * @param array $parameters Router-supplied parameters
* @throws HTTPException\ForbiddenException
*/
- public static function rawContent(array $parameters = [])
+ protected function rawContent(array $request = [])
{
- if (!local_user() || !empty(DI::app()->user['uid']) && DI::app()->user['uid'] != local_user()) {
+ if (!DI::app()->isLoggedIn()) {
throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
}
if ($args->getArgc() == 3) {
// @TODO Replace with router-provided arguments
$action = $args->get(2);
- $user = DI::app()->user;
switch ($action) {
case "backup":
header("Content-type: application/json");
- header('Content-Disposition: attachment; filename="' . $user['nickname'] . '.' . $action . '"');
+ header('Content-Disposition: attachment; filename="' . DI::app()->getLoggedInUserNickname() . '.' . $action . '"');
self::exportAll(local_user());
break;
case "account":
header("Content-type: application/json");
- header('Content-Disposition: attachment; filename="' . $user['nickname'] . '.' . $action . '"');
+ header('Content-Disposition: attachment; filename="' . DI::app()->getLoggedInUserNickname() . '.' . $action . '"');
self::exportAccount(local_user());
break;
case "contact":
header("Content-type: application/csv");
- header('Content-Disposition: attachment; filename="' . $user['nickname'] . '-contacts.csv' . '"');
+ header('Content-Disposition: attachment; filename="' . DI::app()->getLoggedInUserNickname() . '-contacts.csv' . '"');
self::exportContactsAsCSV(local_user());
break;
}
-
- exit();
+ System::exit();
}
}
*/
private static function exportMultiRow(string $query)
{
- $dbStructure = DBStructure::definition(DI::app()->getBasePath(), false);
+ $dbStructure = DI::dbaDefinition()->getAll();
preg_match("/\s+from\s+`?([a-z\d_]+)`?/i", $query, $match);
$table = $match[1];
*/
private static function exportRow(string $query)
{
- $dbStructure = DBStructure::definition(DI::app()->getBasePath(), false);
+ $dbStructure = DI::dbaDefinition()->getAll();
preg_match("/\s+from\s+`?([a-z\d_]+)`?/i", $query, $match);
$table = $match[1];
$result = [];
- $r = q($query);
- if (DBA::isResult($r)) {
- foreach ($r as $rr) {
- foreach ($rr as $k => $v) {
- if (empty($dbStructure[$table]['fields'][$k])) {
- continue;
- }
-
- switch ($dbStructure[$table]['fields'][$k]['type']) {
- case 'datetime':
- $result[$k] = $v ?? DBA::NULL_DATETIME;
- break;
- default:
- $result[$k] = $v;
- break;
- }
+ $rows = DBA::p($query);
+ while ($row = DBA::fetch($rows)) {
+ foreach ($row as $k => $v) {
+ if (empty($dbStructure[$table]['fields'][$k])) {
+ continue;
+ }
+
+ switch ($dbStructure[$table]['fields'][$k]['type']) {
+ case 'datetime':
+ $result[$k] = $v ?? DBA::NULL_DATETIME;
+ break;
+ default:
+ $result[$k] = $v;
+ break;
}
}
}
+ DBA::close($rows);
return $result;
}