Elgg
Version 6.0
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
// Using ElggData for testing purposes
35
ElggData::initializeAttributes
();
36
37
$this->attributes[
'guid'
] = null;
38
$this->attributes[
'type'
] =
'site'
;
39
$this->attributes[
'subtype'
] =
'site'
;
40
41
$this->attributes[
'owner_guid'
] = 0;
42
$this->attributes[
'container_guid'
] = 0;
43
44
$this->attributes[
'access_id'
] =
ACCESS_PUBLIC
;
45
$this->attributes[
'time_updated'
] = null;
46
$this->attributes[
'last_action'
] = null;
47
$this->attributes[
'enabled'
] =
'yes'
;
48
$this->attributes[
'deleted'
] =
'no'
;
49
$this->attributes[
'time_deleted'
] = null;
50
}
51
55
public
function
getType
(): string {
56
return
'site'
;
57
}
58
62
public
function
save
(): bool {
63
$qb
= Select::fromTable(EntityTable::TABLE_NAME);
64
$qb
->select(
'*'
)
65
->where(
$qb
->compare(
'type'
,
'='
,
'site'
,
ELGG_VALUE_STRING
));
66
67
$row = $this->
getDatabase
()->getDataRow(
$qb
);
68
if
(!empty($row)) {
69
if
($row->guid == $this->attributes[
'guid'
]) {
70
// can save active site
71
return
parent::save();
72
}
73
74
_elgg_services
()->logger->error(
'More than 1 site entity cannot be created.'
);
75
return
false
;
76
}
77
78
return
parent::save();
79
}
80
84
public
function
delete
(
bool
$recursive =
true
,
bool
$persistent
= null):
bool
{
85
if
($this->guid === 1) {
86
throw
new
SecurityException
(
'You cannot delete the current site'
);
87
}
88
89
return
parent::delete($recursive, $persistent);
90
}
91
103
public
function
disable
(
string
$reason =
''
,
bool
$recursive =
true
): bool {
104
if
($this->guid == 1) {
105
throw
new
SecurityException
(
'You cannot disable the current site'
);
106
}
107
108
return
parent::disable($reason, $recursive);
109
}
110
114
public
function
__set
(
$name
,
$value
) {
115
if
(
$name
===
'url'
) {
116
_elgg_services
()->logger->warning(
'ElggSite::url cannot be set'
);
117
return
;
118
}
119
120
parent::__set(
$name
,
$value
);
121
}
122
126
public
function
__get
(
$name
) {
127
if
(
$name
===
'url'
) {
128
return
$this->
getURL
();
129
}
130
131
return
parent::__get(
$name
);
132
}
133
139
public
function
getURL
(): string {
140
return
_elgg_services
()->config->wwwroot;
141
}
142
146
public
function
isCacheable
(): bool {
147
return
false
;
148
}
149
153
protected
function
prepareObject
(\
Elgg
\Export\Entity
$object
) {
154
$object = parent::prepareObject($object);
155
$object->name = $this->
getDisplayName
();
156
$object->description =
$this->description
;
157
unset($object->read_access);
158
return
$object
;
159
}
160
167
public
function
getDomain
(): string {
168
$breakdown = parse_url($this->url);
169
return
$breakdown[
'host'
];
170
}
171
180
public
function
getEmailAddress
(): string {
181
$email
=
$this->email
;
182
if
(empty(
$email
)) {
183
// If all else fails, use the domain of the site.
184
$token
=
_elgg_services
()->crypto->getRandomString(24);
185
$email
=
"noreply-{$token}@{$this->getDomain()}"
;
186
}
187
188
return
$email
;
189
}
190
194
public
function
updateLastAction
(
int
$posted
= null): int {
195
// setting last action on ElggSite makes no sense... just returning current value to be compliant
196
return
$this->last_action;
197
}
198
}
ElggData\getDatabase
getDatabase()
Provides a pointer to the database object.
Definition:
ElggData.php:43
ElggSite\__set
__set($name, $value)
{}
Definition:
ElggSite.php:114
$name
if(!$user||!$user->canDelete()) $name
Definition:
delete.php:22
ElggSite\__get
__get($name)
{}
Definition:
ElggSite.php:126
ElggSite\getType
getType()
{}
Definition:
ElggSite.php:55
ElggSite\save
save()
{}
Definition:
ElggSite.php:62
$email
$email
Definition:
change_email.php:7
ElggSite\getEmailAddress
getEmailAddress()
Get the email address for the site.
Definition:
ElggSite.php:180
EntityTable
$value
$value
Definition:
generic.php:51
ElggSite\updateLastAction
updateLastAction(int $posted=null)
Definition:
ElggSite.php:194
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:103
ElggData\initializeAttributes
initializeAttributes()
Initialize the attributes array.
Definition:
ElggData.php:34
ElggSite\prepareObject
prepareObject(\Elgg\Export\Entity $object)
{}
Definition:
ElggSite.php:153
$description
$description
Definition:
record.php:15
$token
$token
Definition:
securitytoken.php:9
ElggSite\getURL
getURL()
Returns the URL for this site.
Definition:
ElggSite.php:139
$posted
$posted
Definition:
comment.php:77
$object
if($email instanceof\Elgg\Email) $object
Definition:
body.php:24
ElggSite\isCacheable
isCacheable()
{}
Definition:
ElggSite.php:146
ELGG_VALUE_STRING
const ELGG_VALUE_STRING
Definition:
constants.php:112
ElggEntity
Definition:
ElggEntity.php:48
Select
_elgg_services
_elgg_services()
Get the global service provider.
Definition:
elgglib.php:351
$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:167
$qb
$qb
Definition:
queue.php:12
ElggSite
Definition:
ElggSite.php:28
ElggEntity\getDisplayName
getDisplayName()
Get the entity's display name.
Definition:
ElggEntity.php:324
ElggSite\initializeAttributes
initializeAttributes()
{}
Definition:
ElggSite.php:33
Generated on Fri Oct 11 2024 00:00:26 for Elgg by
1.8.11