123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- <?php
- namespace Elgg;
- class Config {
-
- private $CONFIG;
-
- public function __construct() {
- global $CONFIG;
- $this->CONFIG = $CONFIG;
- }
-
- function getSiteUrl($site_guid = 0) {
- if ($site_guid == 0) {
-
- return $this->CONFIG->wwwroot;
- }
-
- $site = get_entity($site_guid);
-
- if (!$site instanceof \ElggSite) {
- return false;
- }
-
-
- return $site->url;
- }
-
-
- function getPluginsPath() {
-
- return $this->CONFIG->pluginspath;
- }
-
-
- function getDataPath() {
-
- return $this->CONFIG->dataroot;
- }
-
-
- function getRootPath() {
-
- return $this->CONFIG->path;
- }
-
-
- function get($name, $site_guid = 0) {
-
-
- $name = trim($name);
-
-
- if (($site_guid === 0 || $site_guid === null || $site_guid == $this->CONFIG->site_guid) && isset($this->CONFIG->$name)) {
- return $this->CONFIG->$name;
- }
-
- if ($site_guid === null) {
-
- $value = _elgg_services()->datalist->get($name);
- } else {
- if ($site_guid == 0) {
- $site_guid = (int) $this->CONFIG->site_guid;
- }
-
-
- if (!isset($this->CONFIG->site_config_loaded) || $site_guid != $this->CONFIG->site_guid) {
-
- $value = _elgg_services()->configTable->get($name, $site_guid);
- } else {
- $value = null;
- }
- }
-
-
- if ($value === false) {
- return null;
- }
-
- if ($site_guid == $this->CONFIG->site_guid || $site_guid === null) {
- $this->CONFIG->$name = $value;
- }
-
- return $value;
- }
-
-
- function set($name, $value) {
-
-
- $name = trim($name);
-
- $this->CONFIG->$name = $value;
- }
-
-
- function save($name, $value, $site_guid = 0) {
-
-
- $name = trim($name);
-
- if (strlen($name) > 255) {
- _elgg_services()->logger->error("The name length for configuration variables cannot be greater than 255");
- return false;
- }
-
- if ($site_guid === null) {
- if (is_array($value) || is_object($value)) {
- return false;
- }
- $result = _elgg_services()->datalist->set($name, $value);
- } else {
- if ($site_guid == 0) {
- $site_guid = (int) $this->CONFIG->site_guid;
- }
- $result = _elgg_services()->configTable->set($name, $value, $site_guid);
- }
-
- if ($site_guid === null || $site_guid == $this->CONFIG->site_guid) {
- _elgg_services()->config->set($name, $value);
- }
-
- return $result;
- }
- }
|