Elgg
Version 5.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\Exceptions\SecurityException
;
4
26
class
ElggSite
extends
\ElggEntity
{
27
31
protected
function
initializeAttributes
() {
32
// Using ElggData for testing purposes
33
ElggData::initializeAttributes
();
34
35
$this->attributes[
'guid'
] = null;
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
$this->attributes[
'time_updated'
] = null;
44
$this->attributes[
'last_action'
] = null;
45
$this->attributes[
'enabled'
] =
'yes'
;
46
}
47
51
public
function
getType
(): string {
52
return
'site'
;
53
}
54
58
public
function
save
(): bool {
59
$db
= $this->
getDatabase
();
60
$qb
= \Elgg\Database\Select::fromTable(
'entities'
,
'e'
);
61
$qb
->select(
'e.*'
)
62
->where(
$qb
->compare(
'e.type'
,
'='
,
'site'
,
ELGG_VALUE_STRING
));
63
64
$row =
$db
->getDataRow(
$qb
);
65
66
if
(!empty($row)) {
67
if
($row->guid == $this->attributes[
'guid'
]) {
68
// can save active site
69
return
parent::save();
70
}
71
72
_elgg_services
()->logger->error(
'More than 1 site entity cannot be created.'
);
73
return
false
;
74
}
75
76
return
parent::save();
77
}
78
89
public
function
delete
(
bool
$recursive =
true
):
bool
{
90
if
($this->guid == 1) {
91
throw
new
SecurityException
(
'You cannot delete the current site'
);
92
}
93
94
return
parent::delete($recursive);
95
}
96
108
public
function
disable
(
string
$reason =
''
,
bool
$recursive =
true
): bool {
109
if
($this->guid == 1) {
110
throw
new
SecurityException
(
'You cannot disable the current site'
);
111
}
112
113
return
parent::disable($reason, $recursive);
114
}
115
119
public
function
__set
(
$name
,
$value
) {
120
if
(
$name
===
'url'
) {
121
_elgg_services
()->logger->warning(
'ElggSite::url cannot be set'
);
122
return
;
123
}
124
125
parent::__set(
$name
,
$value
);
126
}
127
131
public
function
__get
(
$name
) {
132
if
(
$name
===
'url'
) {
133
return
$this->
getURL
();
134
}
135
136
return
parent::__get(
$name
);
137
}
138
144
public
function
getURL
(): string {
145
return
_elgg_services
()->config->wwwroot;
146
}
147
151
public
function
isCacheable
(): bool {
152
return
false
;
153
}
154
158
protected
function
prepareObject
(\
Elgg
\Export\Entity
$object
) {
159
$object = parent::prepareObject($object);
160
$object->name = $this->
getDisplayName
();
161
$object->description =
$this->description
;
162
unset($object->read_access);
163
return
$object
;
164
}
165
172
public
function
getDomain
(): string {
173
$breakdown =
parse_url
($this->url);
174
return
$breakdown[
'host'
];
175
}
176
185
public
function
getEmailAddress
(): string {
186
$email
=
$this->email
;
187
if
(empty(
$email
)) {
188
// If all else fails, use the domain of the site.
189
$token
=
_elgg_services
()->crypto->getRandomString(24);
190
$email
=
"noreply-{$token}@{$this->getDomain()}"
;
191
}
192
193
return
$email
;
194
}
195
199
public
function
updateLastAction
(
int
$posted
= null): int {
200
// setting last action on ElggSite makes no sense... just returning current value to be compliant
201
return
$this->last_action;
202
}
203
}
ElggData\getDatabase
getDatabase()
Provides a pointer to the database object.
Definition:
ElggData.php:43
ElggSite\__set
__set($name, $value)
{}
Definition:
ElggSite.php:119
$name
if(!$user||!$user->canDelete()) $name
Definition:
delete.php:22
ElggSite\__get
__get($name)
{}
Definition:
ElggSite.php:131
ElggSite\getType
getType()
{}
Definition:
ElggSite.php:51
ElggSite\save
save()
{}
Definition:
ElggSite.php:58
$email
$email
Definition:
change_email.php:7
parse_url
elgg parse_url
Parse a URL into its parts.
Definition:
elgglib.js:139
ElggSite\getEmailAddress
getEmailAddress()
Get the email address for the site.
Definition:
ElggSite.php:185
$value
$value
Definition:
generic.php:51
ElggSite\updateLastAction
updateLastAction(int $posted=null)
Definition:
ElggSite.php:199
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:108
$db
foreach($recommendedExtensions as $extension) if(empty(ini_get('session.gc_probability'))||empty(ini_get('session.gc_divisor'))) $db
Definition:
requirements.php:93
ElggData\initializeAttributes
initializeAttributes()
Initialize the attributes array.
Definition:
ElggData.php:34
ElggSite\prepareObject
prepareObject(\Elgg\Export\Entity $object)
{}
Definition:
ElggSite.php:158
$description
$description
Definition:
record.php:15
$token
$token
Definition:
securitytoken.php:9
ElggSite\getURL
getURL()
Returns the URL for this site.
Definition:
ElggSite.php:144
$posted
$posted
Definition:
comment.php:86
$object
if($email instanceof\Elgg\Email) $object
Definition:
body.php:24
ElggSite\isCacheable
isCacheable()
{}
Definition:
ElggSite.php:151
ELGG_VALUE_STRING
const ELGG_VALUE_STRING
Definition:
constants.php:112
ElggEntity
Definition:
ElggEntity.php:46
_elgg_services
_elgg_services()
Get the global service provider.
Definition:
elgglib.php:346
ACCESS_PUBLIC
const ACCESS_PUBLIC
Definition:
constants.php:12
ElggSite\getDomain
getDomain()
Get the domain for this site.
Definition:
ElggSite.php:172
$qb
$qb
Definition:
queue.php:11
ElggSite
Definition:
ElggSite.php:26
ElggEntity\getDisplayName
getDisplayName()
Get the entity's display name.
Definition:
ElggEntity.php:312
ElggSite\initializeAttributes
initializeAttributes()
{}
Definition:
ElggSite.php:31
Generated on Tue Dec 5 2023 00:00:20 for Elgg by
1.8.11