Deprecated upload function relocates to a replacement

This commit is contained in:
Michael 2021-11-27 13:41:49 +00:00 committed by Hypolite Petovan
parent e381ca6ba0
commit 14ec87e68c
2 changed files with 7 additions and 51 deletions

View File

@ -646,53 +646,6 @@ function group_create($name, $uid, $users = [])
* TWITTER API
*/
/**
* Deprecated function to upload media.
*
* @param string $type Return type (atom, rss, xml, json)
*
* @return array|string
* @throws BadRequestException
* @throws ForbiddenException
* @throws ImagickException
* @throws InternalServerErrorException
* @throws UnauthorizedException
*/
function api_statuses_mediap($type)
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
$uid = BaseApi::getCurrentUserID();
$a = DI::app();
$_REQUEST['profile_uid'] = $uid;
$_REQUEST['api_source'] = true;
$txt = $_REQUEST['status'] ?? '';
if ((strpos($txt, '<') !== false) || (strpos($txt, '>') !== false)) {
$txt = HTML::toBBCodeVideo($txt);
$config = HTMLPurifier_Config::createDefault();
$config->set('Cache.DefinitionImpl', null);
$purifier = new HTMLPurifier($config);
$txt = $purifier->purify($txt);
}
$txt = HTML::toBBCode($txt);
$picture = Photo::upload($uid, $_FILES['media']);
// now that we have the img url in bbcode we can add it to the status and insert the wall item.
$_REQUEST['body'] = $txt . "\n\n" . '[url=' . $picture["albumpage"] . '][img]' . $picture["preview"] . "[/img][/url]";
$item_id = item_post($a);
$include_entities = strtolower(($_REQUEST['include_entities'] ?? 'false') == 'true');
// output the post that we just posted.
$status_info = DI::twitterStatus()->createFromItemId($item_id, $uid, $include_entities)->toArray();
return DI::apiResponse()->formatData('statuses', $type, ['status' => $status_info]);
}
api_register_func('api/statuses/mediap', 'api_statuses_mediap', true);
/**
* Updates the users current status.
*
@ -876,6 +829,7 @@ function api_statuses_update($type)
api_register_func('api/statuses/update', 'api_statuses_update', true);
api_register_func('api/statuses/update_with_media', 'api_statuses_update', true);
api_register_func('api/statuses/mediap', 'api_statuses_update', true);
/**
* Repeats a status.

View File

@ -875,6 +875,7 @@ class ApiTest extends FixtureTest
*/
public function testApiStatusesMediap()
{
/*
DI::args()->setArgc(2);
$_FILES = [
@ -892,6 +893,7 @@ class ApiTest extends FixtureTest
$result = api_statuses_mediap('json');
self::assertStatus($result['status']);
*/
}
/**
@ -901,10 +903,10 @@ class ApiTest extends FixtureTest
*/
public function testApiStatusesMediapWithoutAuthenticatedUser()
{
$this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
BasicAuth::setCurrentUserID();
$_SESSION['authenticated'] = false;
api_statuses_mediap('json');
// $this->expectException(\Friendica\Network\HTTPException\UnauthorizedException::class);
// BasicAuth::setCurrentUserID();
// $_SESSION['authenticated'] = false;
// api_statuses_mediap('json');
}
/**