Elgg  Version 4.x
ElggSite.php
Go to the documentation of this file.
1 <?php
2 
4 
26 class ElggSite extends \ElggEntity {
27 
31  protected function initializeAttributes() {
32  // Using ElggData for testing purposes
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() {
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($recursive = true) {
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($reason = "", $recursive = true) {
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  parent::__set($name, $value);
125  }
126 
130  public function __get($name) {
131  if ($name === 'url') {
132  return $this->getURL();
133  }
134  return parent::__get($name);
135  }
136 
142  public function getURL() {
143  return _elgg_services()->config->wwwroot;
144  }
145 
149  public function isCacheable() {
150  return false;
151  }
152 
156  protected function prepareObject(\Elgg\Export\Entity $object) {
157  $object = parent::prepareObject($object);
158  $object->name = $this->getDisplayName();
159  $object->description = $this->description;
160  unset($object->read_access);
161  return $object;
162  }
163 
170  public function getDomain() {
171  $breakdown = parse_url($this->url);
172  return $breakdown['host'];
173  }
174 
183  public function getEmailAddress() {
185  if (empty($email)) {
186  // If all else fails, use the domain of the site.
187  $token = _elgg_services()->crypto->getRandomString(24);
188  $email = "noreply-{$token}@{$this->getDomain()}";
189  }
190 
191  return $email;
192  }
193 
197  public function updateLastAction($posted = null) {
198  // setting last action on ElggSite makes no sense... just returning current value to be compliant
199  return $this->last_action;
200  }
201 }
getDatabase()
Provides a pointer to the database object.
Definition: ElggData.php:44
if(!$user||!$user->canDelete()) $name
Definition: delete.php:22
__set($name, $value)
{}
Definition: ElggSite.php:119
__get($name)
{}
Definition: ElggSite.php:130
getType()
{}
Definition: ElggSite.php:51
save()
{}
Definition: ElggSite.php:58
$email
Definition: change_email.php:7
elgg parse_url
Parse a URL into its parts.
Definition: elgglib.js:135
getEmailAddress()
Get the email address for the site.
Definition: ElggSite.php:183
$value
Definition: generic.php:51
Throw when a Security Exception occurs.
disable($reason="", $recursive=true)
Disable the site.
Definition: ElggSite.php:108
foreach($recommendedExtensions as $extension) if(empty(ini_get('session.gc_probability'))||empty(ini_get('session.gc_divisor'))) $db
initializeAttributes()
Initialize the attributes array.
Definition: ElggData.php:35
prepareObject(\Elgg\Export\Entity $object)
{}
Definition: ElggSite.php:156
updateLastAction($posted=null)
Definition: ElggSite.php:197
$description
Definition: record.php:15
$token
getURL()
Returns the URL for this site.
Definition: ElggSite.php:142
$posted
Definition: comment.php:86
if($email instanceof\Elgg\Email) $object
Definition: body.php:24
isCacheable()
{}
Definition: ElggSite.php:149
const ELGG_VALUE_STRING
Definition: constants.php:127
_elgg_services()
Get the global service provider.
Definition: elgglib.php:777
const ACCESS_PUBLIC
Definition: constants.php:14
getDomain()
Get the domain for this site.
Definition: ElggSite.php:170
$qb
Definition: queue.php:11
getDisplayName()
Get the entity&#39;s display name.
Definition: ElggEntity.php:318
initializeAttributes()
{}
Definition: ElggSite.php:31