Elgg
Version 6.1
Main Page
Related Pages
Namespaces
Classes
Files
Examples
File List
File Members
engine
classes
ElggSite.php
Go to the documentation of this file.
1
<?php
2
3
use
Elgg\Database\EntityTable
;
4
use
Elgg\Database\Select
;
5
use
Elgg\Exceptions\SecurityException
;
6
28
class
ElggSite
extends
\ElggEntity
{
29
33
protected
function
initializeAttributes
() {
34
parent::initializeAttributes();
35
36
$this->attributes[
'type'
] =
'site'
;
37
$this->attributes[
'subtype'
] =
'site'
;
38
39
$this->attributes[
'owner_guid'
] = 0;
40
$this->attributes[
'container_guid'
] = 0;
41
42
$this->attributes[
'access_id'
] =
ACCESS_PUBLIC
;
43
}
44
48
public
function
save
(): bool {
49
$qb
= Select::fromTable(EntityTable::TABLE_NAME);
50
$qb
->select(
'*'
)
51
->where(
$qb
->compare(
'type'
,
'='
,
'site'
,
ELGG_VALUE_STRING
));
52
53
$row = $this->
getDatabase
()->getDataRow(
$qb
);
54
if
(!empty($row)) {
55
if
($row->guid == $this->attributes[
'guid'
]) {
56
// can save active site
57
return
parent::save();
58
}
59
60
_elgg_services
()->logger->error(
'More than 1 site entity cannot be created.'
);
61
return
false
;
62
}
63
64
return
parent::save();
65
}
66
70
public
function
delete
(
bool
$recursive =
true
,
bool
$persistent
= null):
bool
{
71
if
($this->guid === 1) {
72
throw
new
SecurityException
(
'You cannot delete the current site'
);
73
}
74
75
return
parent::delete($recursive, $persistent);
76
}
77
89
public
function
disable
(
string
$reason =
''
,
bool
$recursive =
true
): bool {
90
if
($this->guid == 1) {
91
throw
new
SecurityException
(
'You cannot disable the current site'
);
92
}
93
94
return
parent::disable($reason, $recursive);
95
}
96
100
public
function
__set
(
$name
,
$value
) {
101
if
(
$name
===
'url'
) {
102
_elgg_services
()->logger->warning(
'ElggSite::url cannot be set'
);
103
return
;
104
}
105
106
parent::__set(
$name
,
$value
);
107
}
108
112
public
function
__get
(
$name
) {
113
if
(
$name
===
'url'
) {
114
return
$this->
getURL
();
115
}
116
117
return
parent::__get(
$name
);
118
}
119
125
public
function
getURL
(): string {
126
return
_elgg_services
()->config->wwwroot;
127
}
128
132
public
function
isCacheable
(): bool {
133
return
false
;
134
}
135
139
protected
function
prepareObject
(\
Elgg
\Export\Entity
$object
) {
140
$object = parent::prepareObject($object);
141
$object->name = $this->
getDisplayName
();
142
$object->description =
$this->description
;
143
unset($object->read_access);
144
return
$object
;
145
}
146
153
public
function
getDomain
(): string {
154
$breakdown = parse_url($this->url);
155
return
$breakdown[
'host'
];
156
}
157
166
public
function
getEmailAddress
(): string {
167
$email
=
$this->email
;
168
if
(empty(
$email
)) {
169
// If all else fails, use the domain of the site.
170
$token
=
_elgg_services
()->crypto->getRandomString(24);
171
$email
=
"noreply-{$token}@{$this->getDomain()}"
;
172
}
173
174
return
$email
;
175
}
176
180
public
function
updateLastAction
(
int
$posted
= null): int {
181
// setting last action on ElggSite makes no sense... just returning current value to be compliant
182
return
$this->last_action;
183
}
184
}
ElggData\getDatabase
getDatabase()
Provides a pointer to the database object.
Definition:
ElggData.php:43
ElggSite\__set
__set($name, $value)
{}
Definition:
ElggSite.php:100
$posted
$posted
Definition:
sidebar.php:21
$name
if(!$user||!$user->canDelete()) $name
Definition:
delete.php:22
ElggSite\__get
__get($name)
{}
Definition:
ElggSite.php:112
ElggSite\save
save()
{}
Definition:
ElggSite.php:48
$email
$email
Definition:
change_email.php:7
ElggSite\getEmailAddress
getEmailAddress()
Get the email address for the site.
Definition:
ElggSite.php:166
EntityTable
$value
$value
Definition:
generic.php:51
ElggSite\updateLastAction
updateLastAction(int $posted=null)
Definition:
ElggSite.php:180
Elgg\Exceptions\SecurityException
Throw when a Security Exception occurs.
Definition:
SecurityException.php:10
Elgg
Definition:
ActionsService.php:3
SecurityException
ElggSite\disable
disable(string $reason= '', bool $recursive=true)
Disable the site.
Definition:
ElggSite.php:89
ElggSite\prepareObject
prepareObject(\Elgg\Export\Entity $object)
{}
Definition:
ElggSite.php:139
$description
$description
Definition:
record.php:15
$token
$token
Definition:
securitytoken.php:9
ElggSite\getURL
getURL()
Returns the URL for this site.
Definition:
ElggSite.php:125
$object
if($email instanceof\Elgg\Email) $object
Definition:
body.php:24
ElggSite\isCacheable
isCacheable()
{}
Definition:
ElggSite.php:132
ELGG_VALUE_STRING
const ELGG_VALUE_STRING
Definition:
constants.php:112
ElggEntity
Definition:
ElggEntity.php:52
Select
_elgg_services
_elgg_services()
Get the global service provider.
Definition:
elgglib.php:353
$persistent
$persistent
Definition:
login_as.php:21
ACCESS_PUBLIC
const ACCESS_PUBLIC
Definition:
constants.php:12
ElggSite\getDomain
getDomain()
Get the domain for this site.
Definition:
ElggSite.php:153
$qb
$qb
Definition:
queue.php:12
ElggSite
Definition:
ElggSite.php:28
ElggEntity\getDisplayName
getDisplayName()
Get the entity's display name.
Definition:
ElggEntity.php:306
ElggSite\initializeAttributes
initializeAttributes()
{}
Definition:
ElggSite.php:33
Generated on Wed Dec 4 2024 00:00:22 for Elgg by
1.8.11