}
// $called_api is the API path exploded on / and is expected to have at least 2 elements
- if (is_null($user) && ($a->argc > (count($called_api) - 1)) && (count($called_api) > 0)) {
+ if (is_null($user) && (DI::args()->getArgc() > (count($called_api) - 1)) && (count($called_api) > 0)) {
$argid = count($called_api);
- if (!empty($a->argv[$argid])) {
- $data = explode(".", $a->argv[$argid]);
+ if (!empty(DI::args()->getArgv()[$argid])) {
+ $data = explode(".", DI::args()->getArgv()[$argid]);
if (count($data) > 1) {
list($user, $null) = $data;
}
}
$txt = HTML::toBBCode($txt);
- $a->argv[1] = $user_info['screen_name']; //should be set to username?
+ DI::args()->getArgv()[1] = $user_info['screen_name']; //should be set to username?
$picture = wall_upload_post($a, false);
}
// params
- $id = intval($a->argv[3] ?? 0);
+ $id = intval(DI::args()->getArgv()[3] ?? 0);
if ($id == 0) {
$id = intval($_REQUEST['id'] ?? 0);
// Hotot workaround
if ($id == 0) {
- $id = intval($a->argv[4] ?? 0);
+ $id = intval(DI::args()->getArgv()[4] ?? 0);
}
Logger::log('API: api_statuses_show: ' . $id);
}
// params
- $id = intval($a->argv[3] ?? 0);
+ $id = intval(DI::args()->getArgv()[3] ?? 0);
$since_id = intval($_REQUEST['since_id'] ?? 0);
$max_id = intval($_REQUEST['max_id'] ?? 0);
$count = intval($_REQUEST['count'] ?? 20);
// Hotot workaround
if ($id == 0) {
- $id = intval($a->argv[4] ?? 0);
+ $id = intval(DI::args()->getArgv()[4] ?? 0);
}
Logger::info(API_LOG_PREFIX . '{subaction}', ['module' => 'api', 'action' => 'conversation', 'subaction' => 'show', 'id' => $id]);
api_get_user($a);
// params
- $id = intval($a->argv[3] ?? 0);
+ $id = intval(DI::args()->getArgv()[3] ?? 0);
if ($id == 0) {
$id = intval($_REQUEST['id'] ?? 0);
// Hotot workaround
if ($id == 0) {
- $id = intval($a->argv[4] ?? 0);
+ $id = intval(DI::args()->getArgv()[4] ?? 0);
}
Logger::log('API: api_statuses_repeat: '.$id);
api_get_user($a);
// params
- $id = intval($a->argv[3] ?? 0);
+ $id = intval(DI::args()->getArgv()[3] ?? 0);
if ($id == 0) {
$id = intval($_REQUEST['id'] ?? 0);
// Hotot workaround
if ($id == 0) {
- $id = intval($a->argv[4] ?? 0);
+ $id = intval(DI::args()->getArgv()[4] ?? 0);
}
Logger::log('API: api_statuses_destroy: '.$id);
// for versioned api.
/// @TODO We need a better global soluton
$action_argv_id = 2;
- if (count($a->argv) > 1 && $a->argv[1] == "1.1") {
+ if (count(DI::args()->getArgv()) > 1 && DI::args()->getArgv()[1] == "1.1") {
$action_argv_id = 3;
}
- if ($a->argc <= $action_argv_id) {
+ if (DI::args()->getArgc() <= $action_argv_id) {
throw new BadRequestException("Invalid request.");
}
- $action = str_replace("." . $type, "", $a->argv[$action_argv_id]);
- if ($a->argc == $action_argv_id + 2) {
- $itemid = intval($a->argv[$action_argv_id + 1] ?? 0);
+ $action = str_replace("." . $type, "", DI::args()->getArgv()[$action_argv_id]);
+ if (DI::args()->getArgc() == $action_argv_id + 2) {
+ $itemid = intval(DI::args()->getArgv()[$action_argv_id + 1] ?? 0);
} else {
$itemid = intval($_REQUEST['id'] ?? 0);
}
if (api_user() === false) {
throw new ForbiddenException();
}
- $verb = strtolower($a->argv[3]);
+ $verb = strtolower(DI::args()->getArgv()[3]);
$verb = preg_replace("|\..*$|", "", $verb);
$id = $_REQUEST['id'] ?? 0;
if (api_user() === false) {
throw new ForbiddenException();
}
- if ($a->argc!==3) {
+ if (DI::args()->getArgc()!==3) {
throw new BadRequestException("Invalid argument count");
}
if (api_user() === false || $user_info === false) {
throw new ForbiddenException();
}
- if ($a->argc !== 4) {
+ if (DI::args()->getArgc() !== 4) {
throw new BadRequestException("Invalid argument count");
}
{
$tabs = '';
- if ($a->argc > 1 && is_numeric($a->argv[1])) {
+ if (DI::args()->getArgc() > 1 && is_numeric(DI::args()->getArgv()[1])) {
$tabs = render_messages(get_messages(local_user(), 0, 5), 'mail_list.tpl');
}
$new = [
'label' => DI::l10n()->t('New Message'),
'url' => 'message/new',
- 'sel' => $a->argc > 1 && $a->argv[1] == 'new',
+ 'sel' => DI::args()->getArgc() > 1 && DI::args()->getArgv()[1] == 'new',
'accesskey' => 'm',
];
// fake it to go back to the input form if no recipient listed
if ($norecip) {
- $a->argc = 2;
- $a->argv[1] = 'new';
+ DI::args()->setArgv(['message', 'new']);
} else {
DI::baseUrl()->redirect(DI::args()->getCommand() . '/' . $ret);
}
$myprofile = DI::baseUrl() . '/profile/' . $a->user['nickname'];
$tpl = Renderer::getMarkupTemplate('mail_head.tpl');
- if ($a->argc > 1 && $a->argv[1] == 'new') {
+ if (DI::args()->getArgc() > 1 && DI::args()->getArgv()[1] == 'new') {
$button = [
'label' => DI::l10n()->t('Discard'),
'url' => '/message',
'$button' => $button,
]);
- if (($a->argc == 3) && ($a->argv[1] === 'drop' || $a->argv[1] === 'dropconv')) {
- if (!intval($a->argv[2])) {
+ if ((DI::args()->getArgc() == 3) && (DI::args()->getArgv()[1] === 'drop' || DI::args()->getArgv()[1] === 'dropconv')) {
+ if (!intval(DI::args()->getArgv()[2])) {
return;
}
- $cmd = $a->argv[1];
+ $cmd = DI::args()->getArgv()[1];
if ($cmd === 'drop') {
- $message = DBA::selectFirst('mail', ['convid'], ['id' => $a->argv[2], 'uid' => local_user()]);
+ $message = DBA::selectFirst('mail', ['convid'], ['id' => DI::args()->getArgv()[2], 'uid' => local_user()]);
if(!DBA::isResult($message)){
notice(DI::l10n()->t('Conversation not found.'));
DI::baseUrl()->redirect('message');
}
- if (!DBA::delete('mail', ['id' => $a->argv[2], 'uid' => local_user()])) {
+ if (!DBA::delete('mail', ['id' => DI::args()->getArgv()[2], 'uid' => local_user()])) {
notice(DI::l10n()->t('Message was not deleted.'));
}
DI::baseUrl()->redirect('message/' . $conversation['id'] );
} else {
$r = q("SELECT `parent-uri`,`convid` FROM `mail` WHERE `id` = %d AND `uid` = %d LIMIT 1",
- intval($a->argv[2]),
+ intval(DI::args()->getArgv()[2]),
intval(local_user())
);
if (DBA::isResult($r)) {
}
}
- if (($a->argc > 1) && ($a->argv[1] === 'new')) {
+ if ((DI::args()->getArgc() > 1) && (DI::args()->getArgv()[1] === 'new')) {
$o .= $header;
$tpl = Renderer::getMarkupTemplate('msg-header.tpl');
'$linkurl' => DI::l10n()->t('Please enter a link URL:')
]);
- $recipientId = $a->argv[2] ?? null;
+ $recipientId = DI::args()->getArgv()[2] ?? null;
$select = ACL::getMessageContactSelectHTML($recipientId);
$_SESSION['return_path'] = DI::args()->getQueryString();
- if ($a->argc == 1) {
+ if (DI::args()->getArgc() == 1) {
// List messages
return $o;
}
- if (($a->argc > 1) && (intval($a->argv[1]))) {
+ if ((DI::args()->getArgc() > 1) && (intval(DI::args()->getArgv()[1]))) {
$o .= $header;
WHERE `mail`.`uid` = ? AND `mail`.`id` = ?
LIMIT 1",
local_user(),
- $a->argv[1]
+ DI::args()->getArgv()[1]
);
if (DBA::isResult($message)) {
$contact_id = $message['contact-id'];
$tpl = Renderer::getMarkupTemplate('mail_display.tpl');
$o = Renderer::replaceMacros($tpl, [
- '$thread_id' => $a->argv[1],
+ '$thread_id' => DI::args()->getArgv()[1],
'$thread_subject' => $message['title'],
'$thread_seen' => $seen,
'$delete' => DI::l10n()->t('Delete conversation'),
$r_json = (!empty($_GET['response']) && $_GET['response'] == 'json');
$album = trim($_GET['album'] ?? '');
- if ($a->argc > 1) {
+ if (DI::args()->getArgc() > 1) {
if (empty($_FILES['media'])) {
- $nick = $a->argv[1];
+ $nick = DI::args()->getArgv()[1];
$user = DBA::selectFirst('owner-view', ['id', 'uid', 'nickname', 'page-flags'], ['nickname' => $nick, 'blocked' => false]);
if (!DBA::isResult($user)) {
if ($r_json) {
return $this->argc;
}
+ public function setArgv(array $argv)
+ {
+ $this->argv = $argv;
+ $this->argc = count($argv);
+ }
+
+ public function setArgc(int $argc)
+ {
+ $this->argc = $argc;
+ }
+
/**
* Returns the value of a argv key
* @todo there are a lot of $a->argv usages in combination with ?? which can be replaced with this method
/** @var App app */
$this->app = DI::app();
- $this->app->argc = 1;
- $this->app->argv = [''];
+ DI::args()->setArgc(1);
// User data that the test database is populated with
$this->selfUser = [
{
global $called_api;
$called_api = ['api_path'];
- $this->app->argv[1] = $this->otherUser['id'] . '.json';
+ DI::args()->setArgv(['', $this->otherUser['id'] . '.json']);
self::assertOtherUser(api_get_user($this->app));
}
*/
public function testApiStatusesMediap()
{
- $this->app->argc = 2;
+ DI::args()->setArgc(2);
$_FILES = [
'media' => [
]
];
$app = DI::app();
- $app->argc = 2;
+ DI::args()->setArgc(2);
$result = api_media_upload();
self::assertEquals('image/png', $result['media']['image']['image_type']);
*/
public function testApiStatusesShowWithId()
{
- $this->app->argv[3] = 1;
- $result = api_statuses_show('json');
+ DI::args()->setArgv(['', '', '', 1]);
+ $result = api_statuses_show('json');
self::assertStatus($result['status']);
}
*/
public function testApiStatusesShowWithConversation()
{
- $this->app->argv[3] = 1;
+ DI::args()->setArgv(['', '', '', 1]);
$_REQUEST['conversation'] = 1;
$result = api_statuses_show('json');
self::assertNotEmpty($result['status']);
*/
public function testApiConversationShowWithId()
{
- $this->app->argv[3] = 1;
+ DI::args()->setArgv(['', '', '', 1]);
$_REQUEST['max_id'] = 10;
$_REQUEST['page'] = -2;
$result = api_conversation_show('json');
*/
public function testApiStatusesRepeatWithId()
{
- $this->app->argv[3] = 1;
- $result = api_statuses_repeat('json');
+ DI::args()->setArgv(['', '', '', 1]);
+ $result = api_statuses_repeat('json');
self::assertStatus($result['status']);
// Also test with a shared status
- $this->app->argv[3] = 5;
- $result = api_statuses_repeat('json');
+ DI::args()->setArgv(['', '', '', 5]);
+ $result = api_statuses_repeat('json');
self::assertStatus($result['status']);
}
*/
public function testApiStatusesDestroyWithId()
{
- $this->app->argv[3] = 1;
- $result = api_statuses_destroy('json');
+ DI::args()->setArgv(['', '', '', 1]);
+ $result = api_statuses_destroy('json');
self::assertStatus($result['status']);
}
public function testApiFavoritesCreateDestroy()
{
$this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
- $this->app->argv = ['api', '1.1', 'favorites', 'create'];
- $this->app->argc = count($this->app->argv);
+ DI::args()->setArgv(['api', '1.1', 'favorites', 'create']);
api_favorites_create_destroy('json');
}
public function testApiFavoritesCreateDestroyWithInvalidId()
{
$this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
- $this->app->argv = ['api', '1.1', 'favorites', 'create', '12.json'];
- $this->app->argc = count($this->app->argv);
+ DI::args()->setArgv(['api', '1.1', 'favorites', 'create', '12.json']);
api_favorites_create_destroy('json');
}
public function testApiFavoritesCreateDestroyWithInvalidAction()
{
$this->expectException(\Friendica\Network\HTTPException\BadRequestException::class);
- $this->app->argv = ['api', '1.1', 'favorites', 'change.json'];
- $this->app->argc = count($this->app->argv);
- $_REQUEST['id'] = 1;
+ DI::args()->setArgv(['api', '1.1', 'favorites', 'change.json']);
+ $_REQUEST['id'] = 1;
api_favorites_create_destroy('json');
}
*/
public function testApiFavoritesCreateDestroyWithCreateAction()
{
- $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
- $this->app->argc = count($this->app->argv);
- $_REQUEST['id'] = 3;
- $result = api_favorites_create_destroy('json');
+ DI::args()->setArgv(['api', '1.1', 'favorites', 'create.json']);
+ $_REQUEST['id'] = 3;
+ $result = api_favorites_create_destroy('json');
self::assertStatus($result['status']);
}
*/
public function testApiFavoritesCreateDestroyWithCreateActionAndRss()
{
- $this->app->argv = ['api', '1.1', 'favorites', 'create.rss'];
- $this->app->argc = count($this->app->argv);
- $_REQUEST['id'] = 3;
- $result = api_favorites_create_destroy('rss');
+ DI::args()->setArgv(['api', '1.1', 'favorites', 'create.rss']);
+ $_REQUEST['id'] = 3;
+ $result = api_favorites_create_destroy('rss');
self::assertXml($result, 'status');
}
*/
public function testApiFavoritesCreateDestroyWithDestroyAction()
{
- $this->app->argv = ['api', '1.1', 'favorites', 'destroy.json'];
- $this->app->argc = count($this->app->argv);
- $_REQUEST['id'] = 3;
- $result = api_favorites_create_destroy('json');
+ DI::args()->setArgv(['api', '1.1', 'favorites', 'destroy.json']);
+ $_REQUEST['id'] = 3;
+ $result = api_favorites_create_destroy('json');
self::assertStatus($result['status']);
}
public function testApiFavoritesCreateDestroyWithoutAuthenticatedUser()
{
$this->expectException(\Friendica\Network\HTTPException\ForbiddenException::class);
- $this->app->argv = ['api', '1.1', 'favorites', 'create.json'];
- $this->app->argc = count($this->app->argv);
+ DI::args()->setArgv(['api', '1.1', 'favorites', 'create.json']);
$_SESSION['authenticated'] = false;
api_favorites_create_destroy('json');
}
*/
public function testApiFriendicaNotificationWithEmptyResult()
{
- $this->app->argv = ['api', 'friendica', 'notification'];
- $this->app->argc = count($this->app->argv);
+ DI::args()->setArgv(['api', 'friendica', 'notification']);
$_SESSION['uid'] = 41;
$result = api_friendica_notification('json');
self::assertEquals(['note' => false], $result);
*/
public function testApiFriendicaNotificationWithXmlResult()
{
- $this->app->argv = ['api', 'friendica', 'notification'];
- $this->app->argc = count($this->app->argv);
- $result = api_friendica_notification('xml');
+ DI::args()->setArgv(['api', 'friendica', 'notification']);
+ $result = api_friendica_notification('xml');
$dateRel = Temporal::getRelativeDate('2020-01-01 12:12:02');
$assertXml=<<<XML
<?xml version="1.0"?>
*/
public function testApiFriendicaNotificationWithJsonResult()
{
- $this->app->argv = ['api', 'friendica', 'notification'];
- $this->app->argc = count($this->app->argv);
- $result = json_encode(api_friendica_notification('json'));
+ DI::args()->setArgv(['api', 'friendica', 'notification']);
+ $result = json_encode(api_friendica_notification('json'));
self::assertJson($result);
}