Using getter/setter functions

This commit is contained in:
Michael 2021-07-24 20:34:07 +00:00
parent b4aa796e75
commit 8f46064430
14 changed files with 55 additions and 34 deletions

View file

@ -177,9 +177,9 @@ function display_content(App $a, $update = false, $update_uid = 0)
$item = Post::selectFirst(['uid', 'parent-uri-id'], ['uri-id' => $uri_id, 'uid' => $update_uid]);
if (!empty($item)) {
if ($item['uid'] != 0) {
$a->profile_owner = intval($item['uid']);
$a->setProfileOwner($item['uid']);
} else {
$a->profile_owner = intval($update_uid);
$a->setProfileOwner($update_uid);
}
$parent_uri_id = $item['parent-uri-id'];
}

View file

@ -64,11 +64,11 @@ function notes_content(App $a, $update = false)
'acl_data' => '',
];
$o .= status_editor($a, $x, $a->contact_id);
$o .= status_editor($a, $x, $a->getContactId());
}
$condition = ['uid' => local_user(), 'post-type' => Item::PT_PERSONAL_NOTE, 'gravity' => GRAVITY_PARENT,
'contact-id'=> $a->contact_id];
'contact-id'=> $a->getContactId()];
if (DI::mode()->isMobile()) {
$itemsPerPage = DI::pConfig()->get(local_user(), 'system', 'itemspage_mobile_network',

View file

@ -58,7 +58,7 @@ function redir_init(App $a) {
$contact_url = $contact['url'];
if (!empty($a->contact_id) && $a->contact_id == $cid) {
if (!empty($a->getContactId()) && $a->getContactId() == $cid) {
// Local user is already authenticated.
redir_check_url($contact_url, $url);
$a->redirect($url ?: $contact_url);
@ -73,7 +73,7 @@ function redir_init(App $a) {
$cid = $contact['id'];
}
if (!empty($a->contact_id) && $a->contact_id == $cid) {
if (!empty($a->getContactId()) && $a->getContactId() == $cid) {
// Local user is already authenticated.
redir_check_url($contact_url, $url);
$target_url = $url ?: $contact_url;

View file

@ -56,8 +56,9 @@ use Psr\Log\LoggerInterface;
*/
class App
{
public $profile_owner;
public $contact_id;
private $profile_owner;
private $contact_id;
public $user;
public $data = [];
/** @deprecated 2019.09 - use App\Arguments->getArgv() or Arguments->get() */
@ -129,6 +130,26 @@ class App
*/
private $pConfig;
public function setProfileOwner(int $owner_id)
{
$this->profile_owner = $owner_id;
}
public function getProfileOwner()
{
return $this->profile_owner;
}
public function setContactId(int $contact_id)
{
$this->contact_id = $contact_id;
}
public function getContactId()
{
return $this->contact_id;
}
/**
* Returns the current config cache of this node
*

View file

@ -334,7 +334,7 @@ class Widget
{
$a = DI::app();
$uid = intval($a->profile_owner);
$uid = intval($a->getProfileOwner());
if (!Feature::isEnabled($uid, 'categories')) {
return '';

View file

@ -2685,7 +2685,7 @@ class Item
continue;
}
if ((local_user() == $item['uid']) && ($item['private'] == self::PRIVATE) && ($item['contact-id'] != $app->contact_id) && ($item['network'] == Protocol::DFRN)) {
if ((local_user() == $item['uid']) && ($item['private'] == self::PRIVATE) && ($item['contact-id'] != $app->getContactId()) && ($item['network'] == Protocol::DFRN)) {
$img_url = 'redir/' . $item['contact-id'] . '?url=' . urlencode($mtch[1]);
$item['body'] = str_replace($mtch[0], '[img]' . $img_url . '[/img]', $item['body']);
}

View file

@ -219,13 +219,13 @@ class Profile
return [];
}
$a->profile_owner = $profile['uid'];
$a->setProfileOwner($profile['uid']);
DI::page()['title'] = $profile['name'] . ' @ ' . DI::config()->get('config', 'sitename');
if (!DI::pConfig()->get(local_user(), 'system', 'always_my_theme')) {
$a->setCurrentTheme($profile['theme']);
$a->setCurrentMobileTheme(DI::pConfig()->get($a->profile_owner, 'system', 'mobile_theme'));
$a->setCurrentMobileTheme(DI::pConfig()->get($a->getProfileOwner(), 'system', 'mobile_theme'));
}
/*
@ -768,7 +768,7 @@ class Profile
Session::setVisitorsContacts();
$a->contact_id = $visitor['id'];
$a->setContactId($visitor['id']);
Logger::info('Authenticated visitor', ['url' => $visitor['url']]);
@ -829,7 +829,7 @@ class Profile
*/
Hook::callAll('magic_auth_success', $arr);
$a->contact_id = $arr['visitor']['id'];
$a->setContactId($arr['visitor']['id']);
info(DI::l10n()->t('OpenWebAuth: %1$s welcomes %2$s', DI::baseUrl()->getHostname(), $visitor['name']));
@ -871,7 +871,7 @@ class Profile
*/
public static function getThemeUid(App $a)
{
$uid = !empty($a->profile_owner) ? intval($a->profile_owner) : 0;
$uid = !empty($a->getProfileOwner()) ? intval($a->getProfileOwner()) : 0;
if (local_user() && (DI::pConfig()->get(local_user(), 'system', 'always_my_theme') || !$uid)) {
return local_user();
}

View file

@ -60,7 +60,7 @@ class Poke extends BaseModule
$deny_cid = ($private ? '' : $a->user['deny_cid']);
$deny_gid = ($private ? '' : $a->user['deny_gid']);
$actor = Contact::getById($a->contact_id);
$actor = Contact::getById($a->getContactId());
$uri = Model\Item::newURI($uid);

View file

@ -87,7 +87,7 @@ class Compose extends BaseModule
$compose_title = DI::l10n()->t('Compose new personal note');
$type = 'note';
$doesFederate = false;
$contact_allow_list = [$a->contact_id];
$contact_allow_list = [$a->getContactId()];
$group_allow_list = [];
$contact_deny_list = [];
$group_deny_list = [];
@ -130,7 +130,7 @@ class Compose extends BaseModule
DI::page()->registerFooterScript(Theme::getPathForFile('js/linkPreview.js'));
DI::page()->registerFooterScript(Theme::getPathForFile('js/compose.js'));
$contact = Contact::getById($a->contact_id);
$contact = Contact::getById($a->getContactId());
$tpl = Renderer::getMarkupTemplate('item/compose.tpl');
return Renderer::replaceMacros($tpl, [

View file

@ -65,7 +65,7 @@ class Magic extends BaseModule
$contact = DBA::selectFirst('contact', ['id', 'nurl', 'url'], ['id' => $cid]);
// Redirect if the contact is already authenticated on this site.
if (!empty($a->contact_id) && strpos($contact['nurl'], Strings::normaliseLink(DI::baseUrl()->get())) !== false) {
if (!empty($a->getContactId()) && strpos($contact['nurl'], Strings::normaliseLink(DI::baseUrl()->get())) !== false) {
if ($test) {
$ret['success'] = true;
$ret['message'] .= 'Local site - you are already authenticated.' . EOL;

View file

@ -40,18 +40,18 @@ class Profile extends BaseModule
$a = DI::app();
// Ensure we've got a profile owner if updating.
$a->profile_owner = intval($_GET['p'] ?? 0);
$a->setProfileOwner($_GET['p'] ?? 0);
if (DI::config()->get('system', 'block_public') && !local_user() && !Session::getRemoteContactID($a->profile_owner)) {
if (DI::config()->get('system', 'block_public') && !local_user() && !Session::getRemoteContactID($a->getProfileOwner())) {
throw new ForbiddenException();
}
$remote_contact = Session::getRemoteContactID($a->profile_owner);
$is_owner = local_user() == $a->profile_owner;
$last_updated_key = "profile:" . $a->profile_owner . ":" . local_user() . ":" . $remote_contact;
$remote_contact = Session::getRemoteContactID($a->getProfileOwner());
$is_owner = local_user() == $a->getProfileOwner();
$last_updated_key = "profile:" . $a->getProfileOwner() . ":" . local_user() . ":" . $remote_contact;
if (!$is_owner && !$remote_contact) {
$user = User::getById($a->profile_owner, ['hidewall']);
$user = User::getById($a->getProfileOwner(), ['hidewall']);
if ($user['hidewall']) {
throw new ForbiddenException(DI::l10n()->t('Access to this profile has been restricted.'));
}
@ -64,7 +64,7 @@ class Profile extends BaseModule
}
// Get permissions SQL - if $remote_contact is true, our remote user has been pre-verified and we already have fetched his/her groups
$sql_extra = Item::getPermissionsSQLByUserId($a->profile_owner);
$sql_extra = Item::getPermissionsSQLByUserId($a->getProfileOwner());
$last_updated_array = Session::get('last_updated', []);
@ -88,7 +88,7 @@ class Profile extends BaseModule
AND `visible` AND (NOT `deleted` OR `gravity` = ?)
AND `wall` $sql_extra4 $sql_extra
GROUP BY `parent-uri-id` ORDER BY `received` DESC",
$a->profile_owner,
$a->getProfileOwner(),
GRAVITY_ACTIVITY
);
@ -101,7 +101,7 @@ class Profile extends BaseModule
$last_updated_array[$last_updated_key] = time();
Session::set('last_updated', $last_updated_array);
if ($is_owner && !$a->profile_owner && !DI::config()->get('theme', 'hide_eventlist')) {
if ($is_owner && !$a->getProfileOwner() && !DI::config()->get('theme', 'hide_eventlist')) {
$o .= ProfileModel::getBirthdays();
$o .= ProfileModel::getEventsReminderHTML();
}
@ -115,7 +115,7 @@ class Profile extends BaseModule
$items = DBA::toArray($items_stmt);
$o .= conversation($a, $items, 'profile', $a->profile_owner, false, 'received', $a->profile_owner);
$o .= conversation($a, $items, 'profile', $a->getProfileOwner(), false, 'received', $a->getProfileOwner());
System::htmlUpdateExit($o);
}

View file

@ -936,7 +936,7 @@ class Post
$uid = $conv->getProfileOwner();
$parent_uid = $this->getDataValue('uid');
$contact = Contact::getById($a->contact_id);
$contact = Contact::getById($a->getContactId());
$default_text = $this->getDefaultText();

View file

@ -79,11 +79,11 @@ class Thread
$this->writable = true;
break;
case 'profile':
$this->profile_owner = $a->profile_owner;
$this->profile_owner = $a->getProfileOwner();
$this->writable = Security::canWriteToUserWall($this->profile_owner);
break;
case 'display':
$this->profile_owner = $a->profile_owner;
$this->profile_owner = $a->getProfileOwner();
$this->writable = Security::canWriteToUserWall($this->profile_owner) || $writable;
break;
case 'community':

View file

@ -144,7 +144,7 @@ class Authentication
if ($this->session->get('visitor_id') && !$this->session->get('uid')) {
$contact = $this->dba->selectFirst('contact', ['id'], ['id' => $this->session->get('visitor_id')]);
if ($this->dba->isResult($contact)) {
$a->contact_id = $contact['id'];
$a->setContactId($contact['id']);
}
}
@ -312,7 +312,7 @@ class Authentication
$contact = $this->dba->selectFirst('contact', ['id'], ['uid' => $user_record['uid'], 'self' => true]);
if ($this->dba->isResult($contact)) {
$a->contact_id = $contact['id'];
$a->setContactId($contact['id']);
$this->session->set('cid', $contact['id']);
}