\ElggSite represents a single site entity.
An \ElggSite object is an \ElggEntity child class with the subtype
of "site." It is created upon installation and holds information about a site:
- name
- description
- url
Every \ElggEntity belongs to a site.
public function testGetEmailAddress() { $site = new \ElggSite(); $site->url = 'https://example.com/'; $site->email = '*****@*****.**'; $this->assertEquals('*****@*****.**', $site->getEmailAddress()); }
/** * Get an access token for signing API requests */ public function getAccessToken() { if (!elgg_instanceof($this->entity)) { return false; } switch ($this->entity->getType()) { case 'site': return StripeClientFactory::getSecretKey(); break; default: return $this->entity->getPrivateSetting('stripe_access_token'); break; } }
/** * Initialize the site including site entity, plugins, and configuration * * @param array $submissionVars Submitted vars * * @return bool */ protected function saveSiteSettings($submissionVars) { global $CONFIG; // ensure that file path, data path, and www root end in / $submissionVars['path'] = sanitise_filepath($submissionVars['path']); $submissionVars['dataroot'] = sanitise_filepath($submissionVars['dataroot']); $submissionVars['wwwroot'] = sanitise_filepath($submissionVars['wwwroot']); $site = new ElggSite(); $site->name = $submissionVars['sitename']; $site->url = $submissionVars['wwwroot']; $site->access_id = ACCESS_PUBLIC; $site->email = $submissionVars['siteemail']; $guid = $site->save(); if (!$guid) { register_error(elgg_echo('install:error:createsite')); return FALSE; } // bootstrap site info $CONFIG->site_guid = $guid; $CONFIG->site = $site; datalist_set('installed', time()); datalist_set('path', $submissionVars['path']); datalist_set('dataroot', $submissionVars['dataroot']); datalist_set('default_site', $site->getGUID()); datalist_set('version', get_version()); datalist_set('simplecache_enabled', 1); datalist_set('system_cache_enabled', 1); // new installations have run all the upgrades $upgrades = elgg_get_upgrade_files($submissionVars['path'] . 'engine/lib/upgrades/'); datalist_set('processed_upgrades', serialize($upgrades)); set_config('view', 'default', $site->getGUID()); set_config('language', 'en', $site->getGUID()); set_config('default_access', $submissionVars['siteaccess'], $site->getGUID()); set_config('allow_registration', TRUE, $site->getGUID()); set_config('walled_garden', FALSE, $site->getGUID()); set_config('allow_user_default_access', '', $site->getGUID()); $this->enablePlugins(); return TRUE; }
/** * Utility function used by import_entity_plugin_hook() to * process an ODDEntity into an unsaved ElggEntity. * * @param ODDEntity $element The OpenDD element * * @return ElggEntity the unsaved entity which should be populated by items. * @todo Remove this. * @access private */ function oddentity_to_elggentity(ODDEntity $element) { $class = $element->getAttribute('class'); $subclass = $element->getAttribute('subclass'); // See if we already have imported this uuid $tmp = get_entity_from_uuid($element->getAttribute('uuid')); if (!$tmp) { // Construct new class with owner from session $classname = get_subtype_class($class, $subclass); if ($classname != "") { if (class_exists($classname)) { $tmp = new $classname(); if (!$tmp instanceof ElggEntity) { $msg = elgg_echo('ClassException:ClassnameNotClass', array($classname, get_class())); throw new ClassException($msg); } } else { error_log(elgg_echo('ClassNotFoundException:MissingClass', array($classname))); } } else { switch ($class) { case 'object': $tmp = new ElggObject($row); break; case 'user': $tmp = new ElggUser($row); break; case 'group': $tmp = new ElggGroup($row); break; case 'site': $tmp = new ElggSite($row); break; default: $msg = elgg_echo('InstallationException:TypeNotSupported', array($class)); throw new InstallationException($msg); } } } if ($tmp) { if (!$tmp->import($element)) { $msg = elgg_echo('ImportException:ImportFailed', array($element->getAttribute('uuid'))); throw new ImportException($msg); } return $tmp; } return NULL; }
/** * Utility function used by import_entity_plugin_hook() to * process an ODDEntity into an unsaved \ElggEntity. * * @param ODDEntity $element The OpenDD element * * @return \ElggEntity the unsaved entity which should be populated by items. * @todo Remove this. * @access private * * @throws ClassException|InstallationException|ImportException * @deprecated 1.9 */ function oddentity_to_elggentity(ODDEntity $element) { elgg_deprecated_notice(__FUNCTION__ . ' is deprecated', 1.9); $class = $element->getAttribute('class'); $subclass = $element->getAttribute('subclass'); // See if we already have imported this uuid $tmp = get_entity_from_uuid($element->getAttribute('uuid')); if (!$tmp) { // Construct new class with owner from session $classname = get_subtype_class($class, $subclass); if ($classname) { if (class_exists($classname)) { $tmp = new $classname(); if (!$tmp instanceof \ElggEntity) { $msg = $classname . " is not a " . get_class() . "."; throw new \ClassException($msg); } } else { error_log("Class '" . $classname . "' was not found, missing plugin?"); } } else { switch ($class) { case 'object': $tmp = new \ElggObject(); break; case 'user': $tmp = new \ElggUser(); break; case 'group': $tmp = new \ElggGroup(); break; case 'site': $tmp = new \ElggSite(); break; default: $msg = "Type " . $class . " is not supported. This indicates an error in your installation, most likely caused by an incomplete upgrade."; throw new \InstallationException($msg); } } } if ($tmp) { if (!$tmp->import($element)) { $msg = "Could not import element " . $element->getAttribute('uuid'); throw new \ImportException($msg); } return $tmp; } return NULL; }
/** * Initialize the site including site entity, plugins, and configuration * * @param array $submissionVars Submitted vars * * @return bool */ protected function saveSiteSettings($submissionVars) { // ensure that file path, data path, and www root end in / $submissionVars['dataroot'] = sanitise_filepath($submissionVars['dataroot']); $submissionVars['wwwroot'] = sanitise_filepath($submissionVars['wwwroot']); $site = new ElggSite(); $site->name = strip_tags($submissionVars['sitename']); $site->url = $submissionVars['wwwroot']; $site->access_id = ACCESS_PUBLIC; $site->email = $submissionVars['siteemail']; $guid = $site->save(); if (!$guid) { register_error(_elgg_services()->translator->translate('install:error:createsite')); return FALSE; } // bootstrap site info $this->CONFIG->site_guid = $guid; $this->CONFIG->site = $site; _elgg_services()->configTable->set('installed', time()); _elgg_services()->configTable->set('dataroot', $submissionVars['dataroot']); _elgg_services()->configTable->set('default_site', $site->getGUID()); _elgg_services()->configTable->set('version', elgg_get_version()); _elgg_services()->configTable->set('simplecache_enabled', 1); _elgg_services()->configTable->set('system_cache_enabled', 1); _elgg_services()->configTable->set('simplecache_lastupdate', time()); // new installations have run all the upgrades $upgrades = elgg_get_upgrade_files(\Elgg\Application::elggDir()->getPath("/engine/lib/upgrades/")); _elgg_services()->configTable->set('processed_upgrades', $upgrades); _elgg_services()->configTable->set('view', 'default', $site->getGUID()); _elgg_services()->configTable->set('language', 'en', $site->getGUID()); _elgg_services()->configTable->set('default_access', $submissionVars['siteaccess'], $site->getGUID()); _elgg_services()->configTable->set('allow_registration', TRUE, $site->getGUID()); _elgg_services()->configTable->set('walled_garden', FALSE, $site->getGUID()); _elgg_services()->configTable->set('allow_user_default_access', '', $site->getGUID()); _elgg_services()->configTable->set('default_limit', 10, $site->getGUID()); _elgg_services()->configTable->set('security_protect_upgrade', true, $site->getGUID()); _elgg_services()->configTable->set('security_notify_admins', true, $site->getGUID()); _elgg_services()->configTable->set('security_notify_user_password', true, $site->getGUID()); _elgg_services()->configTable->set('security_email_require_password', true, $site->getGUID()); $this->setSubtypeClasses(); $this->enablePlugins(); return TRUE; }
public function testElggSiteGetUrl() { $this->site->url = 'http://example.com/'; $this->assertIdentical($this->site->getURL(), 'http://example.com/'); }
// Sanitise $path = sanitise_filepath(get_input('path')); $dataroot = sanitise_filepath(get_input('dataroot')); // Blank? if ($dataroot == "/") { throw new InstallationException(elgg_echo('InstallationException:DatarootBlank')); } // That it's valid if (stripos($dataroot, $path) !== false) { throw new InstallationException(sprintf(elgg_echo('InstallationException:DatarootUnderPath'), $dataroot)); } // Check data root is writable if (!is_writable($dataroot)) { throw new InstallationException(sprintf(elgg_echo('InstallationException:DatarootNotWritable'), $dataroot)); } $site = new ElggSite(); $site->name = get_input('sitename'); $site->url = get_input('wwwroot'); $site->description = get_input('sitedescription'); $site->email = get_input('siteemail'); $site->access_id = ACCESS_PUBLIC; $guid = $site->save(); if (!$guid) { throw new InstallationException(sprintf(elgg_echo('InstallationException:CantCreateSite'), get_input('sitename'), get_input('wwwroot'))); } datalist_set('installed', time()); datalist_set('path', $path); datalist_set('dataroot', $dataroot); datalist_set('default_site', $site->getGUID()); set_config('view', get_input('view'), $site->getGUID()); set_config('language', get_input('language'), $site->getGUID());
/** * Returns a formatted site emailaddress * * @param ElggSite $site the site to get the emailaddress from * * @return string */ protected function getSiteEmailAddress(ElggSite $site) { $site_from = ''; if ($site->email) { if ($site->name) { $site_from = $site->name . " <" . $site->email . ">"; } else { $site_from = $site->email; } } else { // no site email, so make one up if ($site->name) { $site_from = $site->name . " <noreply@" . $site->getDomain() . ">"; } else { $site_from = "noreply@" . $site->getDomain(); } } return $site_from; }
function getMembers($options = array(), $offset = 0) { if (elgg_extract("count", $options, false) === true) { $member_count = $this->member_count; $bypass = elgg_extract("force_update_member_count", $options, false); if ($member_count === NULL || $bypass) { $member_count = parent::getMembers($options, $offset); $this->member_count = $member_count; } return $member_count; } return parent::getMembers($options, $offset); }
/** * Initialize the site including site entity, plugins, and configuration * * @param array $submissionVars Submitted vars * * @return bool */ protected function saveSiteSettings($submissionVars) { // ensure that file path, data path, and www root end in / $submissionVars['dataroot'] = sanitise_filepath($submissionVars['dataroot']); $submissionVars['wwwroot'] = sanitise_filepath($submissionVars['wwwroot']); $site = new ElggSite(); $site->name = strip_tags($submissionVars['sitename']); $site->url = $submissionVars['wwwroot']; $site->access_id = ACCESS_PUBLIC; $site->email = $submissionVars['siteemail']; $guid = $site->save(); if (!$guid) { register_error(_elgg_services()->translator->translate('install:error:createsite')); return FALSE; } // bootstrap site info $this->CONFIG->site_guid = $guid; $this->CONFIG->site_id = $guid; $this->CONFIG->site = $site; _elgg_services()->datalist->set('installed', time()); _elgg_services()->datalist->set('dataroot', $submissionVars['dataroot']); _elgg_services()->datalist->set('default_site', $site->getGUID()); _elgg_services()->datalist->set('version', elgg_get_version()); _elgg_services()->datalist->set('simplecache_enabled', 1); _elgg_services()->datalist->set('system_cache_enabled', 1); _elgg_services()->datalist->set('simplecache_lastupdate', time()); // @todo plugins might use this, but core doesn't. remove in 2.0 _elgg_services()->datalist->set('path', $this->CONFIG->path); // new installations have run all the upgrades $upgrades = elgg_get_upgrade_files("{$this->CONFIG->path}engine/lib/upgrades/"); _elgg_services()->datalist->set('processed_upgrades', serialize($upgrades)); _elgg_services()->configTable->set('view', 'default', $site->getGUID()); _elgg_services()->configTable->set('language', 'en', $site->getGUID()); _elgg_services()->configTable->set('default_access', $submissionVars['siteaccess'], $site->getGUID()); _elgg_services()->configTable->set('allow_registration', TRUE, $site->getGUID()); _elgg_services()->configTable->set('walled_garden', FALSE, $site->getGUID()); _elgg_services()->configTable->set('allow_user_default_access', '', $site->getGUID()); _elgg_services()->configTable->set('default_limit', 10, $site->getGUID()); $this->setSubtypeClasses(); $this->enablePlugins(); return TRUE; }
/** * @SWG\Definition( * definition="Site", * required={"guid","name", "url", "membership"}, * @SWG\Property(property="guid", type="integer"), * @SWG\Property(property="name", type="string"), * @SWG\Property(property="url", type="string"), * @SWG\Property(property="membership", type="string", description="Can be open or closed."), * @SWG\Property(property="icon_url", type="string"), * @SWG\Property(property="time_created", type="string", description="In ISO-8601 format.") * ) */ private function parseSite(\ElggSite $site) { $user = elgg_get_logged_in_user_entity(); return array('guid' => $site->guid, 'name' => html_entity_decode($site->name, ENT_QUOTES), 'url' => $site->url, 'membership' => $site instanceof Subsite ? $site->getMembership() : "open", 'icon_url' => $site->getIconURL(), 'groups_unread_count' => $this->handler->getUnreadGroupsCount($user, $site), 'time_created' => date('c', $site->time_created)); }