UserSession class [5] - Refactor src/Module/ files with DI

This commit is contained in:
Philipp
2022-10-20 22:59:12 +02:00
parent a729f3255d
commit eecc456e0c
78 changed files with 455 additions and 530 deletions

View File

@@ -22,7 +22,6 @@
namespace Friendica\Module\Settings\Profile\Photo;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Contact;
@@ -35,7 +34,7 @@ class Crop extends BaseSettings
{
protected function post(array $request = [])
{
if (!Session::isAuthenticated()) {
if (!DI::userSession()->isAuthenticated()) {
return;
}
@@ -58,7 +57,7 @@ class Crop extends BaseSettings
$path = 'profile/' . DI::app()->getLoggedInUserNickname();
$base_image = Photo::selectFirst([], ['resource-id' => $resource_id, 'uid' => Session::getLocalUser(), 'scale' => $scale]);
$base_image = Photo::selectFirst([], ['resource-id' => $resource_id, 'uid' => DI::userSession()->getLocalUserId(), 'scale' => $scale]);
if (DBA::isResult($base_image)) {
$Image = Photo::getImageForPhoto($base_image);
if (empty($Image)) {
@@ -67,7 +66,7 @@ class Crop extends BaseSettings
if ($Image->isValid()) {
// If setting for the default profile, unset the profile photo flag from any other photos I own
DBA::update('photo', ['profile' => 0], ['uid' => Session::getLocalUser()]);
DBA::update('photo', ['profile' => 0], ['uid' => DI::userSession()->getLocalUserId()]);
// Normalizing expected square crop parameters
$selectionW = $selectionH = min($selectionW, $selectionH);
@@ -92,11 +91,11 @@ class Crop extends BaseSettings
$Image->scaleDown(300);
}
$condition = ['resource-id' => $resource_id, 'uid' => Session::getLocalUser(), 'contact-id' => 0];
$condition = ['resource-id' => $resource_id, 'uid' => DI::userSession()->getLocalUserId(), 'contact-id' => 0];
$r = Photo::store(
$Image,
Session::getLocalUser(),
DI::userSession()->getLocalUserId(),
0,
$resource_id,
$base_image['filename'],
@@ -114,7 +113,7 @@ class Crop extends BaseSettings
$r = Photo::store(
$Image,
Session::getLocalUser(),
DI::userSession()->getLocalUserId(),
0,
$resource_id,
$base_image['filename'],
@@ -132,7 +131,7 @@ class Crop extends BaseSettings
$r = Photo::store(
$Image,
Session::getLocalUser(),
DI::userSession()->getLocalUserId(),
0,
$resource_id,
$base_image['filename'],
@@ -146,12 +145,12 @@ class Crop extends BaseSettings
Photo::update(['profile' => true], array_merge($condition, ['scale' => 6]));
}
Contact::updateSelfFromUserID(Session::getLocalUser(), true);
Contact::updateSelfFromUserID(DI::userSession()->getLocalUserId(), true);
DI::sysmsg()->addInfo(DI::l10n()->t('Shift-reload the page or clear browser cache if the new photo does not display immediately.'));
// Update global directory in background
Profile::publishUpdate(Session::getLocalUser());
Profile::publishUpdate(DI::userSession()->getLocalUserId());
} else {
DI::sysmsg()->addNotice(DI::l10n()->t('Unable to process image'));
}
@@ -162,7 +161,7 @@ class Crop extends BaseSettings
protected function content(array $request = []): string
{
if (!Session::isAuthenticated()) {
if (!DI::userSession()->isAuthenticated()) {
throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
}
@@ -170,7 +169,7 @@ class Crop extends BaseSettings
$resource_id = $this->parameters['guid'];
$photos = Photo::selectToArray([], ['resource-id' => $resource_id, 'uid' => Session::getLocalUser()], ['order' => ['scale' => false]]);
$photos = Photo::selectToArray([], ['resource-id' => $resource_id, 'uid' => DI::userSession()->getLocalUserId()], ['order' => ['scale' => false]]);
if (!DBA::isResult($photos)) {
throw new HTTPException\NotFoundException(DI::l10n()->t('Photo not found.'));
}
@@ -185,14 +184,14 @@ class Crop extends BaseSettings
// set an already uloaded photo as profile photo
// if photo is in 'Profile Photos', change it in db
if ($photos[0]['photo-type'] == Photo::USER_AVATAR && $havescale) {
Photo::update(['profile' => false], ['uid' => Session::getLocalUser()]);
Photo::update(['profile' => false], ['uid' => DI::userSession()->getLocalUserId()]);
Photo::update(['profile' => true], ['resource-id' => $resource_id, 'uid' => Session::getLocalUser()]);
Photo::update(['profile' => true], ['resource-id' => $resource_id, 'uid' => DI::userSession()->getLocalUserId()]);
Contact::updateSelfFromUserID(Session::getLocalUser(), true);
Contact::updateSelfFromUserID(DI::userSession()->getLocalUserId(), true);
// Update global directory in background
Profile::publishUpdate(Session::getLocalUser());
Profile::publishUpdate(DI::userSession()->getLocalUserId());
DI::sysmsg()->addInfo(DI::l10n()->t('Profile picture successfully updated.'));

View File

@@ -22,7 +22,6 @@
namespace Friendica\Module\Settings\Profile\Photo;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Model\Photo;
@@ -36,7 +35,7 @@ class Index extends BaseSettings
{
protected function post(array $request = [])
{
if (!Session::isAuthenticated()) {
if (!DI::userSession()->isAuthenticated()) {
return;
}
@@ -92,13 +91,13 @@ class Index extends BaseSettings
$filename = '';
if (!Photo::store($Image, Session::getLocalUser(), 0, $resource_id, $filename, DI::l10n()->t(Photo::PROFILE_PHOTOS), 0, Photo::USER_AVATAR)) {
if (!Photo::store($Image, DI::userSession()->getLocalUserId(), 0, $resource_id, $filename, DI::l10n()->t(Photo::PROFILE_PHOTOS), 0, Photo::USER_AVATAR)) {
DI::sysmsg()->addNotice(DI::l10n()->t('Image upload failed.'));
}
if ($width > 640 || $height > 640) {
$Image->scaleDown(640);
if (!Photo::store($Image, Session::getLocalUser(), 0, $resource_id, $filename, DI::l10n()->t(Photo::PROFILE_PHOTOS), 1, Photo::USER_AVATAR)) {
if (!Photo::store($Image, DI::userSession()->getLocalUserId(), 0, $resource_id, $filename, DI::l10n()->t(Photo::PROFILE_PHOTOS), 1, Photo::USER_AVATAR)) {
DI::sysmsg()->addNotice(DI::l10n()->t('Image size reduction [%s] failed.', '640'));
}
}
@@ -108,7 +107,7 @@ class Index extends BaseSettings
protected function content(array $request = []): string
{
if (!Session::isAuthenticated()) {
if (!DI::userSession()->isAuthenticated()) {
throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
}
@@ -118,7 +117,7 @@ class Index extends BaseSettings
$newuser = $args->get($args->getArgc() - 1) === 'new';
$contact = Contact::selectFirst(['avatar'], ['uid' => Session::getLocalUser(), 'self' => true]);
$contact = Contact::selectFirst(['avatar'], ['uid' => DI::userSession()->getLocalUserId(), 'self' => true]);
$tpl = Renderer::getMarkupTemplate('settings/profile/photo/index.tpl');
$o = Renderer::replaceMacros($tpl, [