mirror of
https://github.com/friendica/friendica
synced 2025-05-04 19:04:10 +02:00
UserSession class [5] - Refactor src/Module/ files with DI
This commit is contained in:
parent
a729f3255d
commit
eecc456e0c
78 changed files with 455 additions and 530 deletions
|
@ -25,7 +25,6 @@ use Friendica\Core\ACL;
|
|||
use Friendica\Core\Hook;
|
||||
use Friendica\Core\Protocol;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Core\Session;
|
||||
use Friendica\Core\Theme;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
|
@ -44,11 +43,11 @@ class Index extends BaseSettings
|
|||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
if (!Session::getLocalUser()) {
|
||||
if (!DI::userSession()->getLocalUserId()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$profile = Profile::getByUID(Session::getLocalUser());
|
||||
$profile = Profile::getByUID(DI::userSession()->getLocalUserId());
|
||||
if (!DBA::isResult($profile)) {
|
||||
return;
|
||||
}
|
||||
|
@ -102,12 +101,12 @@ class Index extends BaseSettings
|
|||
}
|
||||
|
||||
$profileFieldsNew = self::getProfileFieldsFromInput(
|
||||
Session::getLocalUser(),
|
||||
DI::userSession()->getLocalUserId(),
|
||||
$_REQUEST['profile_field'],
|
||||
$_REQUEST['profile_field_order']
|
||||
);
|
||||
|
||||
DI::profileField()->saveCollectionForUser(Session::getLocalUser(), $profileFieldsNew);
|
||||
DI::profileField()->saveCollectionForUser(DI::userSession()->getLocalUserId(), $profileFieldsNew);
|
||||
|
||||
$result = Profile::update(
|
||||
[
|
||||
|
@ -125,7 +124,7 @@ class Index extends BaseSettings
|
|||
'pub_keywords' => $pub_keywords,
|
||||
'prv_keywords' => $prv_keywords,
|
||||
],
|
||||
Session::getLocalUser()
|
||||
DI::userSession()->getLocalUserId()
|
||||
);
|
||||
|
||||
if (!$result) {
|
||||
|
@ -138,7 +137,7 @@ class Index extends BaseSettings
|
|||
|
||||
protected function content(array $request = []): string
|
||||
{
|
||||
if (!Session::getLocalUser()) {
|
||||
if (!DI::userSession()->getLocalUserId()) {
|
||||
DI::sysmsg()->addNotice(DI::l10n()->t('You must be logged in to use this module'));
|
||||
return Login::form();
|
||||
}
|
||||
|
@ -147,7 +146,7 @@ class Index extends BaseSettings
|
|||
|
||||
$o = '';
|
||||
|
||||
$profile = User::getOwnerDataById(Session::getLocalUser());
|
||||
$profile = User::getOwnerDataById(DI::userSession()->getLocalUserId());
|
||||
if (!DBA::isResult($profile)) {
|
||||
throw new HTTPException\NotFoundException();
|
||||
}
|
||||
|
@ -159,7 +158,7 @@ class Index extends BaseSettings
|
|||
|
||||
$custom_fields = [];
|
||||
|
||||
$profileFields = DI::profileField()->selectByUserId(Session::getLocalUser());
|
||||
$profileFields = DI::profileField()->selectByUserId(DI::userSession()->getLocalUserId());
|
||||
foreach ($profileFields as $profileField) {
|
||||
/** @var ProfileField $profileField */
|
||||
$defaultPermissions = $profileField->permissionSet->withAllowedContacts(
|
||||
|
|
|
@ -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.'));
|
||||
|
||||
|
|
|
@ -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, [
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue