Completely removed argc/argv

This commit is contained in:
Michael 2021-07-25 15:23:37 +00:00
parent 540ddb9265
commit df558d4056
18 changed files with 70 additions and 114 deletions

View File

@ -58,10 +58,6 @@ class App
{
public $user;
public $data = [];
/** @deprecated 2019.09 - use App\Arguments->getArgv() or Arguments->get() */
public $argv;
/** @deprecated 2019.09 - use App\Arguments->getArgc() */
public $argc;
public $theme_info = [];
// Allow themes to control internal parameters
// by changing App values in theme.php
@ -254,9 +250,6 @@ class App
$this->process = $process;
$this->pConfig = $pConfig;
$this->argv = $args->getArgv();
$this->argc = $args->getArgc();
$this->load();
}

View File

@ -37,12 +37,11 @@ class Attach extends BaseModule
public static function rawContent(array $parameters = [])
{
$a = DI::app();
if ($a->argc != 2) {
if (empty($parameters['item'])) {
throw new \Friendica\Network\HTTPException\BadRequestException();
}
// @TODO: Replace with parameter from router
$item_id = intval($a->argv[1]);
$item_id = intval($parameters['item']);
// Check for existence
$item = MAttach::exists(['id' => $item_id]);

View File

@ -42,21 +42,21 @@ class BaseSettings extends BaseModule
$tabs[] = [
'label' => DI::l10n()->t('Account'),
'url' => 'settings',
'selected' => (($a->argc == 1) && ($a->argv[0] === 'settings') ? 'active' : ''),
'selected' => ((DI::args()->getArgc() == 1) && (DI::args()->getArgv() === 'settings') ? 'active' : ''),
'accesskey' => 'o',
];
$tabs[] = [
'label' => DI::l10n()->t('Two-factor authentication'),
'url' => 'settings/2fa',
'selected' => (($a->argc > 1) && ($a->argv[1] === '2fa') ? 'active' : ''),
'selected' => ((DI::args()->getArgc() > 1) && (DI::args()->getArgv()[1] === '2fa') ? 'active' : ''),
'accesskey' => 'o',
];
$tabs[] = [
'label' => DI::l10n()->t('Profile'),
'url' => 'settings/profile',
'selected' => (($a->argc > 1) && ($a->argv[1] === 'profile') ? 'active' : ''),
'selected' => ((DI::args()->getArgc() > 1) && (DI::args()->getArgv()[1] === 'profile') ? 'active' : ''),
'accesskey' => 'p',
];
@ -64,7 +64,7 @@ class BaseSettings extends BaseModule
$tabs[] = [
'label' => DI::l10n()->t('Additional features'),
'url' => 'settings/features',
'selected' => (($a->argc > 1) && ($a->argv[1] === 'features') ? 'active' : ''),
'selected' => ((DI::args()->getArgc() > 1) && (DI::args()->getArgv()[1] === 'features') ? 'active' : ''),
'accesskey' => 't',
];
}
@ -72,49 +72,49 @@ class BaseSettings extends BaseModule
$tabs[] = [
'label' => DI::l10n()->t('Display'),
'url' => 'settings/display',
'selected' => (($a->argc > 1) && ($a->argv[1] === 'display') ? 'active' : ''),
'selected' => ((DI::args()->getArgc() > 1) && (DI::args()->getArgv()[1] === 'display') ? 'active' : ''),
'accesskey' => 'i',
];
$tabs[] = [
'label' => DI::l10n()->t('Social Networks'),
'url' => 'settings/connectors',
'selected' => (($a->argc > 1) && ($a->argv[1] === 'connectors') ? 'active' : ''),
'selected' => ((DI::args()->getArgc() > 1) && (DI::args()->getArgv()[1] === 'connectors') ? 'active' : ''),
'accesskey' => 'w',
];
$tabs[] = [
'label' => DI::l10n()->t('Addons'),
'url' => 'settings/addon',
'selected' => (($a->argc > 1) && ($a->argv[1] === 'addon') ? 'active' : ''),
'selected' => ((DI::args()->getArgc() > 1) && (DI::args()->getArgv()[1] === 'addon') ? 'active' : ''),
'accesskey' => 'l',
];
$tabs[] = [
'label' => DI::l10n()->t('Manage Accounts'),
'url' => 'settings/delegation',
'selected' => (($a->argc > 1) && ($a->argv[1] === 'delegation') ? 'active' : ''),
'selected' => ((DI::args()->getArgc() > 1) && (DI::args()->getArgv()[1] === 'delegation') ? 'active' : ''),
'accesskey' => 'd',
];
$tabs[] = [
'label' => DI::l10n()->t('Connected apps'),
'url' => 'settings/oauth',
'selected' => (($a->argc > 1) && ($a->argv[1] === 'oauth') ? 'active' : ''),
'selected' => ((DI::args()->getArgc() > 1) && (DI::args()->getArgv()[1] === 'oauth') ? 'active' : ''),
'accesskey' => 'b',
];
$tabs[] = [
'label' => DI::l10n()->t('Export personal data'),
'url' => 'settings/userexport',
'selected' => (($a->argc > 1) && ($a->argv[1] === 'userexport') ? 'active' : ''),
'selected' => ((DI::args()->getArgc() > 1) && (DI::args()->getArgv()[1] === 'userexport') ? 'active' : ''),
'accesskey' => 'e',
];
$tabs[] = [
'label' => DI::l10n()->t('Remove account'),
'url' => 'removeme',
'selected' => (($a->argc == 1) && ($a->argv[0] === 'removeme') ? 'active' : ''),
'selected' => ((DI::args()->getArgc() == 1) && (DI::args()->getArgv() === 'removeme') ? 'active' : ''),
'accesskey' => 'r',
];

View File

@ -106,13 +106,13 @@ class Contact extends BaseModule
}
// @TODO: Replace with parameter from router
if ($a->argv[1] === 'batch') {
if (DI::args()->getArgv()[1] === 'batch') {
self::batchActions();
return;
}
// @TODO: Replace with parameter from router
$contact_id = intval($a->argv[1]);
$contact_id = intval(DI::args()->getArgv()[1]);
if (!$contact_id) {
return;
}
@ -271,10 +271,10 @@ class Contact extends BaseModule
$contact = null;
// @TODO: Replace with parameter from router
if ($a->argc == 2 && intval($a->argv[1])
|| $a->argc == 3 && intval($a->argv[1]) && in_array($a->argv[2], ['posts', 'conversations'])
if (DI::args()->getArgc() == 2 && intval(DI::args()->getArgv()[1])
|| DI::args()->getArgc() == 3 && intval(DI::args()->getArgv()[1]) && in_array(DI::args()->getArgv()[2], ['posts', 'conversations'])
) {
$contact_id = intval($a->argv[1]);
$contact_id = intval(DI::args()->getArgv()[1]);
// Ensure to use the user contact when the public contact was provided
$data = Model\Contact::getPublicAndUserContactID($contact_id, local_user());
@ -293,7 +293,7 @@ class Contact extends BaseModule
if (DBA::isResult($contact)) {
if ($contact['self']) {
// @TODO: Replace with parameter from router
if (($a->argc == 3) && intval($a->argv[1]) && in_array($a->argv[2], ['posts', 'conversations'])) {
if ((DI::args()->getArgc() == 3) && intval(DI::args()->getArgv()[1]) && in_array(DI::args()->getArgv()[2], ['posts', 'conversations'])) {
DI::baseUrl()->redirect('profile/' . $contact['nick']);
} else {
DI::baseUrl()->redirect('profile/' . $contact['nick'] . '/profile');
@ -343,14 +343,14 @@ class Contact extends BaseModule
return Login::form();
}
if ($a->argc == 3) {
$contact_id = intval($a->argv[1]);
if (DI::args()->getArgc() == 3) {
$contact_id = intval(DI::args()->getArgv()[1]);
if (!$contact_id) {
throw new BadRequestException();
}
// @TODO: Replace with parameter from router
$cmd = $a->argv[2];
$cmd = DI::args()->getArgv()[2];
$orig_record = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => [0, local_user()], 'self' => false, 'deleted' => false]);
if (!DBA::isResult($orig_record)) {
@ -637,7 +637,7 @@ class Contact extends BaseModule
$sql_values = [local_user()];
// @TODO: Replace with parameter from router
$type = $a->argv[1] ?? '';
$type = DI::args()->getArgv()[1] ?? '';
switch ($type) {
case 'blocked':

View File

@ -23,7 +23,6 @@ namespace Friendica\Module\Debug;
use Friendica\BaseModule;
use Friendica\DI;
use Friendica\Model\Item;
use Friendica\Model\Post;
use Friendica\Network\HTTPException;
@ -38,16 +37,13 @@ class ItemBody extends BaseModule
throw new HTTPException\UnauthorizedException(DI::l10n()->t('Access denied.'));
}
$app = DI::app();
// @TODO: Replace with parameter from router
$itemId = (($app->argc > 1) ? intval($app->argv[1]) : 0);
if (!$itemId) {
if (empty($parameters['item'])) {
throw new HTTPException\NotFoundException(DI::l10n()->t('Item not found.'));
}
$item = Post::selectFirst(['body'], ['uid' => local_user(), 'uri-id' => $itemId]);
$itemId = intval($parameters['item']);
$item = Post::selectFirst(['body'], ['uid' => [0, local_user()], 'uri-id' => $itemId]);
if (!empty($item)) {
if (DI::mode()->isAjax()) {

View File

@ -40,15 +40,11 @@ class Fetch extends BaseModule
{
public static function rawContent(array $parameters = [])
{
$app = DI::app();
// @TODO: Replace with parameter from router
if (($app->argc != 3) || (!in_array($app->argv[1], ["post", "status_message", "reshare"]))) {
if (empty($parameters['guid'])) {
throw new HTTPException\NotFoundException();
}
// @TODO: Replace with parameter from router
$guid = $app->argv[2];
$guid = $parameters['guid'];
// Fetch the item
$fields = [
@ -68,7 +64,7 @@ class Fetch extends BaseModule
$host = $parts["scheme"] . "://" . $parts["host"];
if (Strings::normaliseLink($host) != Strings::normaliseLink(DI::baseUrl()->get())) {
$location = $host . "/fetch/" . $app->argv[1] . "/" . urlencode($guid);
$location = $host . "/fetch/" . DI::args()->getArgv()[1] . "/" . urlencode($guid);
System::externalRedirect($location, 301);
}
}

View File

@ -76,12 +76,6 @@ class Directory extends BaseModule
if ($profiles['total'] === 0) {
notice(DI::l10n()->t('No entries (some entries may be hidden).'));
} else {
if (in_array('small', $app->argv)) {
$photo = 'thumb';
} else {
$photo = 'photo';
}
foreach ($profiles['entries'] as $entry) {
$contact = Model\Contact::getByURLForUser($entry['url'], local_user());
if (!empty($contact)) {

View File

@ -48,15 +48,10 @@ class Feed extends BaseModule
$last_update = $_GET['last_update'] ?? '';
$nocache = !empty($_GET['nocache']) && local_user();
// @TODO: Replace with parameter from router
if ($a->argc < 2) {
throw new \Friendica\Network\HTTPException\BadRequestException();
}
$type = null;
// @TODO: Replace with parameter from router
if ($a->argc > 2) {
$type = $a->argv[2];
if (DI::args()->getArgc() > 2) {
$type = DI::args()->getArgv()[2];
}
switch ($type) {
@ -72,10 +67,8 @@ class Feed extends BaseModule
$type = 'posts';
}
// @TODO: Replace with parameter from router
$nickname = $a->argv[1];
header("Content-type: application/atom+xml; charset=utf-8");
echo ProtocolFeed::atom($nickname, $last_update, 10, $type, $nocache, true);
echo ProtocolFeed::atom($parameters['nickname'], $last_update, 10, $type, $nocache, true);
exit();
}
}

View File

@ -39,10 +39,9 @@ class RemoveTag extends BaseModule
throw new HTTPException\ForbiddenException();
}
$app = DI::app();
$logger = DI::logger();
$item_id = (($app->argc > 1) ? intval($app->argv[1]) : 0);
$item_id = $parameters['id'] ?? 0;
$term = XML::unescape(trim($_GET['term'] ?? ''));
$cat = XML::unescape(trim($_GET['cat'] ?? ''));

View File

@ -44,12 +44,11 @@ class SaveTag extends BaseModule
public static function rawContent(array $parameters = [])
{
$a = DI::app();
$logger = DI::logger();
$term = XML::unescape(trim($_GET['term'] ?? ''));
// @TODO: Replace with parameter from router
$item_id = (($a->argc > 1) ? intval($a->argv[1]) : 0);
$item_id = $parameters['id'] ?? 0;
$logger->info('filer', ['tag' => $term, 'item' => $item_id]);

View File

@ -120,10 +120,8 @@ class Friendica extends BaseModule
}
}
$app = DI::app();
// @TODO: Replace with parameter from router
if ($app->argc <= 1 || ($app->argv[1] !== 'json')) {
if (DI::args()->getArgc() <= 1 || (DI::args()->getArgv()[1] !== 'json')) {
return;
}

View File

@ -47,7 +47,7 @@ class Group extends BaseModule
}
// @TODO: Replace with parameter from router
if (($a->argc == 2) && ($a->argv[1] === 'new')) {
if ((DI::args()->getArgc() == 2) && (DI::args()->getArgv()[1] === 'new')) {
BaseModule::checkFormSecurityTokenRedirectOnError('/group/new', 'group_edit');
$name = Strings::escapeTags(trim($_POST['groupname']));
@ -64,10 +64,10 @@ class Group extends BaseModule
}
// @TODO: Replace with parameter from router
if (($a->argc == 2) && intval($a->argv[1])) {
if ((DI::args()->getArgc() == 2) && intval(DI::args()->getArgv()[1])) {
BaseModule::checkFormSecurityTokenRedirectOnError('/group', 'group_edit');
$group = DBA::selectFirst('group', ['id', 'name'], ['id' => $a->argv[1], 'uid' => local_user()]);
$group = DBA::selectFirst('group', ['id', 'name'], ['id' => DI::args()->getArgv()[1], 'uid' => local_user()]);
if (!DBA::isResult($group)) {
notice(DI::l10n()->t('Group not found.'));
DI::baseUrl()->redirect('contact');
@ -93,8 +93,8 @@ class Group extends BaseModule
// POST /group/123/add/123
// POST /group/123/remove/123
// @TODO: Replace with parameter from router
if ($a->argc == 4) {
list($group_id, $command, $contact_id) = array_slice($a->argv, 1);
if (DI::args()->getArgc() == 4) {
list($group_id, $command, $contact_id) = array_slice(DI::args()->getArgv(), 1);
if (!Model\Group::exists($group_id, local_user())) {
throw new \Exception(DI::l10n()->t('Unknown group.'), 404);
@ -149,11 +149,11 @@ class Group extends BaseModule
$a = DI::app();
DI::page()['aside'] = Model\Group::sidebarWidget('contact', 'group', 'extended', (($a->argc > 1) ? $a->argv[1] : 'everyone'));
DI::page()['aside'] = Model\Group::sidebarWidget('contact', 'group', 'extended', ((DI::args()->getArgc() > 1) ? DI::args()->getArgv()[1] : 'everyone'));
// With no group number provided we jump to the unassigned contacts as a starting point
// @TODO: Replace with parameter from router
if ($a->argc == 1) {
if (DI::args()->getArgc() == 1) {
DI::baseUrl()->redirect('group/none');
}
@ -172,7 +172,7 @@ class Group extends BaseModule
];
// @TODO: Replace with parameter from router
if (($a->argc == 2) && ($a->argv[1] === 'new')) {
if ((DI::args()->getArgc() == 2) && (DI::args()->getArgv()[1] === 'new')) {
return Renderer::replaceMacros($tpl, $context + [
'$title' => DI::l10n()->t('Create a group of contacts/friends.'),
'$gname' => ['groupname', DI::l10n()->t('Group Name: '), '', ''],
@ -184,8 +184,8 @@ class Group extends BaseModule
$nogroup = false;
// @TODO: Replace with parameter from router
if (($a->argc == 2) && ($a->argv[1] === 'none') ||
($a->argc == 1) && ($a->argv[0] === 'nogroup')) {
if ((DI::args()->getArgc() == 2) && (DI::args()->getArgv()[1] === 'none') ||
(DI::args()->getArgc() == 1) && (DI::args()->getArgv()[0] === 'nogroup')) {
$id = -1;
$nogroup = true;
$group = [
@ -205,17 +205,17 @@ class Group extends BaseModule
}
// @TODO: Replace with parameter from router
if (($a->argc == 3) && ($a->argv[1] === 'drop')) {
if ((DI::args()->getArgc() == 3) && (DI::args()->getArgv()[1] === 'drop')) {
BaseModule::checkFormSecurityTokenRedirectOnError('/group', 'group_drop', 't');
// @TODO: Replace with parameter from router
if (intval($a->argv[2])) {
if (!Model\Group::exists($a->argv[2], local_user())) {
if (intval(DI::args()->getArgv()[2])) {
if (!Model\Group::exists(DI::args()->getArgv()[2], local_user())) {
notice(DI::l10n()->t('Group not found.'));
DI::baseUrl()->redirect('contact');
}
if (!Model\Group::remove($a->argv[2])) {
if (!Model\Group::remove(DI::args()->getArgv()[2])) {
notice(DI::l10n()->t('Unable to remove group.'));
}
}
@ -223,17 +223,17 @@ class Group extends BaseModule
}
// @TODO: Replace with parameter from router
if (($a->argc > 2) && intval($a->argv[1]) && intval($a->argv[2])) {
if ((DI::args()->getArgc() > 2) && intval(DI::args()->getArgv()[1]) && intval(DI::args()->getArgv()[2])) {
BaseModule::checkFormSecurityTokenForbiddenOnError('group_member_change', 't');
if (DBA::exists('contact', ['id' => $a->argv[2], 'uid' => local_user(), 'self' => false, 'pending' => false, 'blocked' => false])) {
$change = intval($a->argv[2]);
if (DBA::exists('contact', ['id' => DI::args()->getArgv()[2], 'uid' => local_user(), 'self' => false, 'pending' => false, 'blocked' => false])) {
$change = intval(DI::args()->getArgv()[2]);
}
}
// @TODO: Replace with parameter from router
if (($a->argc > 1) && intval($a->argv[1])) {
$group = DBA::selectFirst('group', ['id', 'name'], ['id' => $a->argv[1], 'uid' => local_user(), 'deleted' => false]);
if ((DI::args()->getArgc() > 1) && intval(DI::args()->getArgv()[1])) {
$group = DBA::selectFirst('group', ['id', 'name'], ['id' => DI::args()->getArgv()[1], 'uid' => local_user(), 'deleted' => false]);
if (!DBA::isResult($group)) {
notice(DI::l10n()->t('Group not found.'));
DI::baseUrl()->redirect('contact');

View File

@ -45,11 +45,11 @@ class Help extends BaseModule
$lang = $config->get('system', 'language');
// @TODO: Replace with parameter from router
if ($a->argc > 1) {
if (DI::args()->getArgc() > 1) {
$path = '';
// looping through the argv keys bigger than 0 to build
// a path relative to /help
for ($x = 1; $x < $a->argc; $x ++) {
for ($x = 1; $x < DI::args()->getArgc(); $x ++) {
if (strlen($path)) {
$path .= '/';
}

View File

@ -39,26 +39,24 @@ class Oembed extends BaseModule
{
public static function content(array $parameters = [])
{
$a = DI::app();
// Unused form: /oembed/b2h?url=...
if ($a->argv[1] == 'b2h') {
if (DI::args()->getArgv()[1] == 'b2h') {
$url = ["", trim(hex2bin($_REQUEST['url']))];
echo Content\OEmbed::replaceCallback($url);
exit();
}
// Unused form: /oembed/h2b?text=...
if ($a->argv[1] == 'h2b') {
if (DI::args()->getArgv()[1] == 'h2b') {
$text = trim(hex2bin($_REQUEST['text']));
echo Content\OEmbed::HTML2BBCode($text);
exit();
}
// @TODO: Replace with parameter from router
if ($a->argc == 2) {
if (DI::args()->getArgc() == 2) {
echo '<html><body>';
$url = Strings::base64UrlDecode($a->argv[1]);
$url = Strings::base64UrlDecode(DI::args()->getArgv()[1]);
$j = Content\OEmbed::fetchURL($url);
// workaround for media.ccc.de (and any other endpoint that return size 0)

View File

@ -27,7 +27,6 @@ use Friendica\Model\User;
use Friendica\Network\HTTPException\BadRequestException;
use Friendica\Util\Crypto;
use Friendica\Util\Strings;
use phpseclib\File\ASN1;
/**
* prints the public RSA key of a user
@ -36,15 +35,11 @@ class PublicRSAKey extends BaseModule
{
public static function rawContent(array $parameters = [])
{
$app = DI::app();
// @TODO: Replace with parameter from router
if ($app->argc !== 2) {
if (empty($parameters['nick'])) {
throw new BadRequestException();
}
// @TODO: Replace with parameter from router
$nick = $app->argv[1];
$nick = $parameters['nick'];
$user = User::getByNickname($nick, ['spubkey']);
if (empty($user) || empty($user['spubkey'])) {

View File

@ -23,6 +23,7 @@ namespace Friendica\Module;
use Friendica\BaseModule;
use Friendica\Content;
use Friendica\Core\Logger;
use Friendica\Core\Renderer;
use Friendica\Core\System;
use Friendica\DI;
@ -34,9 +35,7 @@ class Smilies extends BaseModule
{
public static function rawContent(array $parameters = [])
{
$app = DI::app();
if (!empty($app->argv[1]) && ($app->argv[1] === "json")) {
if (!empty(DI::args()->getArgv()[1]) && (DI::args()->getArgv()[1] === "json")) {
$smilies = Content\Smilies::getList();
$results = [];
for ($i = 0; $i < count($smilies['texts']); $i++) {

View File

@ -40,10 +40,8 @@ class Xrd extends BaseModule
{
public static function rawContent(array $parameters = [])
{
$app = DI::app();
// @TODO: Replace with parameter from router
if ($app->argv[0] == 'xrd') {
if (DI::args()->getArgv()[0] == 'xrd') {
if (empty($_GET['uri'])) {
return;
}

View File

@ -343,7 +343,7 @@ class Authentication
}
}
$this->redirectForTwoFactorAuthentication($user_record['uid'], $a);
$this->redirectForTwoFactorAuthentication($user_record['uid']);
if ($interactive) {
if ($user_record['login_date'] <= DBA::NULL_DATETIME) {
@ -369,12 +369,11 @@ class Authentication
* All return calls in this method skip two-factor authentication
*
* @param int $uid The User Identified
* @param App $a The Friendica Application context
*
* @throws HTTPException\ForbiddenException In case the two factor authentication is forbidden (e.g. for AJAX calls)
* @throws HTTPException\InternalServerErrorException
*/
private function redirectForTwoFactorAuthentication(int $uid, App $a)
private function redirectForTwoFactorAuthentication(int $uid)
{
// Check user setting, if 2FA disabled return
if (!$this->pConfig->get($uid, '2fa', 'verified')) {
@ -382,7 +381,7 @@ class Authentication
}
// Check current path, if public or 2fa module return
if ($a->argc > 0 && in_array($a->argv[0], ['2fa', 'view', 'help', 'api', 'proxy', 'logout'])) {
if (DI::args()->getArgc() > 0 && in_array(DI::args()->getArgv()[0], ['2fa', 'view', 'help', 'api', 'proxy', 'logout'])) {
return;
}