aboutsummaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
Diffstat (limited to 'engine')
-rw-r--r--engine/lib/configuration.php39
-rw-r--r--engine/lib/database.php2
-rw-r--r--engine/lib/entities.php38
-rw-r--r--engine/lib/install.php33
-rw-r--r--engine/lib/languages.php2
-rw-r--r--engine/lib/metadata.php26
-rw-r--r--engine/lib/relationships.php12
-rw-r--r--engine/lib/users.php9
-rw-r--r--engine/start.php20
9 files changed, 105 insertions, 76 deletions
diff --git a/engine/lib/configuration.php b/engine/lib/configuration.php
index 5144f0b89..9b608f7c4 100644
--- a/engine/lib/configuration.php
+++ b/engine/lib/configuration.php
@@ -70,10 +70,9 @@
function set_default_config() {
global $CONFIG;
-
if (empty($CONFIG->path))
$CONFIG->path = str_replace("\\","/",dirname(dirname(dirname(__FILE__)))) . "/";
-
+
if (empty($CONFIG->viewpath))
$CONFIG->viewpath = $CONFIG->path . "views/";
@@ -81,10 +80,8 @@
$CONFIG->pluginspath = $CONFIG->path . "mod/";
if (empty($CONFIG->wwwroot)) {
- $CONFIG->wwwroot = "http://" . $_SERVER['SERVER_NAME'];
- /*if (strripos($_SERVER['DOCUMENT_ROOT'],"/") < (strlen($_SERVER['DOCUMENT_ROOT']) - 1)) {
- $CONFIG->wwwroot .= "/";
- }*/
+ /*
+ $CONFIG->wwwroot = "http://" . $_SERVER['SERVER_NAME'];
$request = $_SERVER['REQUEST_URI'];
@@ -94,8 +91,8 @@
}
$CONFIG->wwwroot .= $request;
-
- //$CONFIG->wwwroot .= str_replace($_SERVER['DOCUMENT_ROOT'],"",$CONFIG->path);
+ */
+ $CONFIG->wwwroot = "http://" . $_SERVER['HTTP_HOST'] . str_replace("//","/",str_replace($_SERVER['DOCUMENT_ROOT'],"",$CONFIG->path));
}
@@ -107,7 +104,31 @@
if (empty($CONFIG->debug))
$CONFIG->debug = false;
-
+
}
+
+ /**
+ * Function that provides some config initialisation on system init
+ *
+ */
+
+ function configuration_init() {
+
+ global $CONFIG;
+
+ $CONFIG->path = datalist_get('path');
+ $CONFIG->dataroot = datalist_get('dataroot');
+ $CONFIG->wwwroot = $CONFIG->site->url;
+ $CONFIG->sitename = $CONFIG->site->name;
+
+ return true;
+
+ }
+
+ /**
+ * Register config_init
+ */
+ register_event_handler('init','system','configuration_init',10);
+
?> \ No newline at end of file
diff --git a/engine/lib/database.php b/engine/lib/database.php
index 0f4bc89b9..0979592c0 100644
--- a/engine/lib/database.php
+++ b/engine/lib/database.php
@@ -355,7 +355,7 @@
* @param string $string The string to sanitise
* @return string Sanitised string
*/
- function sanitise_string($string) {return $string;
+ function sanitise_string($string) {
return mysql_real_escape_string(trim($string));
}
diff --git a/engine/lib/entities.php b/engine/lib/entities.php
index f3ba92e92..c1168853e 100644
--- a/engine/lib/entities.php
+++ b/engine/lib/entities.php
@@ -712,13 +712,14 @@
/**
* Create a new entity of a given type.
*
- * @param string $type
- * @param string $subtype
- * @param int $owner_guid
- * @param int $access_id
- * @return mixed The new entity's GUID or false.
+ * @param string $type The type of the entity (site, user, object).
+ * @param string $subtype The subtype of the entity.
+ * @param int $owner_guid The GUID of the object's owner.
+ * @param int $access_id The access control group to create the entity with.
+ * @param int $site_guid The site to add this entity to. Leave as 0 (default) for the current site.
+ * @return mixed The new entity's GUID, or false on failure
*/
- function create_entity($type, $subtype, $owner_guid, $access_id)
+ function create_entity($type, $subtype, $owner_guid, $access_id, $site_guid = 0)
{
global $CONFIG;
@@ -726,14 +727,17 @@
$subtype = add_subtype($type, $subtype);
$owner_guid = (int)$owner_guid;
$access_id = (int)$access_id;
- $time = time();
+ $time = time();
+ if ($site_guid == 0)
+ $site_guid = $CONFIG->site_guid;
+ $site_guid = (int) $site_guid;
if ($type=="") throw new InvalidParameterException("Entity type must be set.");
// Erased by Ben: sometimes we need unauthenticated users to create things! (eg users on registration)
// if ($owner_guid==0) throw new InvalidParameterException("owner_guid must not be 0");
- if ($result = insert_data("INSERT into {$CONFIG->dbprefix}entities (type, subtype, owner_guid, access_id, time_created, time_updated) values ('$type',$subtype, $owner_guid, $access_id, $time, $time)")) {
+ if ($result = insert_data("INSERT into {$CONFIG->dbprefix}entities (type, subtype, owner_guid, site_guid, access_id, time_created, time_updated) values ('$type',$subtype, $owner_guid, $site_guid, $access_id, $time, $time)")) {
$entity = get_entity($result);
trigger_event('create',$entity->type,$entity);
}
@@ -745,13 +749,13 @@
*
* You will only get an object if a) it exists, b) you have access to it.
*
- * @param int $guid
+ * @param int $guid The GUID of the object to extract
*/
function get_entity_as_row($guid)
{
global $CONFIG;
- $guid = (int)$guid;
+ $guid = (int) $guid;
$access = get_access_list();
@@ -815,9 +819,10 @@
* @param string $order_by The field to order by; by default, time_created desc
* @param int $limit The number of entities to return; 10 by default
* @param int $offset The indexing offset, 0 by default
- * @param boolean $count Set to true to get a count rather than the entities themselves (limits and offsets don't apply in this context). Defaults to false.
+ * @param boolean $count Set to true to get a count rather than the entities themselves (limits and offsets don't apply in this context). Defaults to false.
+ * @param int $site_guid The site to get entities for. Leave as 0 (default) for the current site; -1 for all sites.
*/
- function get_entities($type = "", $subtype = "", $owner_guid = 0, $order_by = "time_created desc", $limit = 10, $offset = 0, $count = false)
+ function get_entities($type = "", $subtype = "", $owner_guid = 0, $order_by = "time_created desc", $limit = 10, $offset = 0, $count = false, $site_guid = 0)
{
global $CONFIG;
@@ -829,7 +834,10 @@
$order_by = sanitise_string($order_by);
$limit = (int)$limit;
- $offset = (int)$offset;
+ $offset = (int)$offset;
+ $site_guid = (int) $site_guid;
+ if ($site_guid == 0)
+ $site_guid = $CONFIG->site_guid;
$access = get_access_list();
@@ -849,7 +857,9 @@
$owner_guid = implode(",",$owner_guid);
$where[] = "owner_guid in ({$owner_guid})";
}
- }
+ }
+ if ($site_guid > 0)
+ $where[] = "site_guid = {$site_guid}";
if (!$count) {
$query = "SELECT * from {$CONFIG->dbprefix}entities where ";
diff --git a/engine/lib/install.php b/engine/lib/install.php
index 4892be509..2a9026959 100644
--- a/engine/lib/install.php
+++ b/engine/lib/install.php
@@ -41,38 +41,7 @@
return false;
}
-
- /**
- * Function that gets run once, when the system is first installed
- *
- */
- function install_prerequisites() {
-
- // Load existing config
- global $CONFIG;
-
- // Create a new Elgg site
- $site = new ElggSite();
- $site->name = "Elgg site";
- $site->save();
-
- // Set datalist alerting us to the fact that the default site is this one
- datalist_set('default_site',$site->getGUID());
-
- }
-
- /**
- * Functions to be run at install init-time.
- *
- */
- function install_init() {
-
- // Run the install_prerequisites function just once
- run_function_once("install_prerequisites");
-
- }
- // Make sure install_boot gets called on system book
- register_event_handler('init','system','install_init',1);
+ register_action("systemsettings/install",true);
?> \ No newline at end of file
diff --git a/engine/lib/languages.php b/engine/lib/languages.php
index c765bf116..a81cd13b3 100644
--- a/engine/lib/languages.php
+++ b/engine/lib/languages.php
@@ -100,6 +100,6 @@
}
}
- register_event_handler("init","system","load_translations");
+ register_event_handler("boot","system","load_translations");
?> \ No newline at end of file
diff --git a/engine/lib/metadata.php b/engine/lib/metadata.php
index 6bed71eb6..c099d6a9c 100644
--- a/engine/lib/metadata.php
+++ b/engine/lib/metadata.php
@@ -326,9 +326,10 @@
* @param string $entity_subtype The subtype of the entity.
* @param int $limit
* @param int $offset
- * @param string $order_by Optional ordering.
+ * @param string $order_by Optional ordering.
+ * @param int $site_guid The site to get entities for. Leave as 0 (default) for the current site; -1 for all sites.
*/
- function get_entities_from_metadata($meta_name, $meta_value = "", $entity_type = "", $entity_subtype = "", $limit = 10, $offset = 0, $order_by = "e.time_created desc")
+ function get_entities_from_metadata($meta_name, $meta_value = "", $entity_type = "", $entity_subtype = "", $limit = 10, $offset = 0, $order_by = "e.time_created desc", $site_guid = 0)
{
global $CONFIG;
@@ -339,7 +340,10 @@
$entity_subtype = get_subtype_id($entity_type, $entity_subtype);
$limit = (int)$limit;
$offset = (int)$offset;
- $order_by = sanitise_string($order_by);
+ $order_by = sanitise_string($order_by);
+ $site_guid = (int) $site_guid;
+ if ($site_guid == 0)
+ $site_guid = $CONFIG->site_guid;
$access = get_access_list();
@@ -352,7 +356,9 @@
if ($meta_name!="")
$where[] = "m.name_id='$meta_n'";
if ($meta_value!="")
- $where[] = "m.value_id='$meta_v'";
+ $where[] = "m.value_id='$meta_v'";
+ if ($site_guid > 0)
+ $where[] = "e.site_guid = {$site_guid}";
$query = "SELECT distinct e.* from {$CONFIG->dbprefix}entities e JOIN {$CONFIG->dbprefix}metadata m on e.guid = m.entity_guid where";
foreach ($where as $w)
@@ -372,9 +378,10 @@
* @param int $limit
* @param int $offset
* @param string $order_by Optional ordering.
+ * @param int $site_guid The site to get entities for. Leave as 0 (default) for the current site; -1 for all sites.
* @return array List of ElggEntities
*/
- function get_entities_from_metadata_multi($meta_array, $entity_type = "", $entity_subtype = "", $limit = 10, $offset = 0, $order_by = "e.time_created desc")
+ function get_entities_from_metadata_multi($meta_array, $entity_type = "", $entity_subtype = "", $limit = 10, $offset = 0, $order_by = "e.time_created desc", $site_guid = 0)
{
global $CONFIG;
@@ -402,13 +409,18 @@
$limit = (int)$limit;
$offset = (int)$offset;
$order_by = sanitise_string($order_by);
+ $site_guid = (int) $site_guid;
+ if ($site_guid == 0)
+ $site_guid = $CONFIG->site_guid;
$access = get_access_list();
if ($entity_type!="")
- $where[] = "e.type='$entity_type'";
+ $where[] = "e.type = '{$entity_type}'";
if ($entity_subtype)
- $where[] = "e.subtype=$entity_subtype";
+ $where[] = "e.subtype = {$entity_subtype}";
+ if ($site_guid > 0)
+ $where[] = "e.site_guid = {$site_guid}";
$query = "SELECT distinct e.* from {$CONFIG->dbprefix}entities e {$join} where";
foreach ($where as $w)
diff --git a/engine/lib/relationships.php b/engine/lib/relationships.php
index 486005c3f..8e3298a61 100644
--- a/engine/lib/relationships.php
+++ b/engine/lib/relationships.php
@@ -371,9 +371,10 @@
* @param int $limit
* @param int $offset
* @param boolean $count Set to true if you want to count the number of entities instead (default false)
+ * @param int $site_guid The site to get entities for. Leave as 0 (default) for the current site; -1 for all sites.
* @return array|int|false An array of entities, or the number of entities, or false on failure
*/
- function get_entities_from_relationship($relationship, $relationship_guid, $inverse_relationship = false, $type = "", $subtype = "", $owner_guid = 0, $order_by = "time_created desc", $limit = 10, $offset = 0, $count = false)
+ function get_entities_from_relationship($relationship, $relationship_guid, $inverse_relationship = false, $type = "", $subtype = "", $owner_guid = 0, $order_by = "time_created desc", $limit = 10, $offset = 0, $count = false, $site_guid = 0)
{
global $CONFIG;
@@ -385,7 +386,10 @@
$owner_guid = (int)$owner_guid;
$order_by = sanitise_string($order_by);
$limit = (int)$limit;
- $offset = (int)$offset;
+ $offset = (int)$offset;
+ $site_guid = (int) $site_guid;
+ if ($site_guid == 0)
+ $site_guid = $CONFIG->site_guid;
$access = get_access_list();
@@ -400,7 +404,9 @@
if ($subtype)
$where[] = "e.subtype=$subtype";
if ($owner_guid != "")
- $where[] = "e.owner_guid='$owner_guid'";
+ $where[] = "e.owner_guid='$owner_guid'";
+ if ($site_guid > 0)
+ $where[] = "e.site_guid = {$site_guid}";
// Select what we're joining based on the options
$joinon = "e.guid = r.guid_one";
diff --git a/engine/lib/users.php b/engine/lib/users.php
index 90b7622ae..a28a09ac3 100644
--- a/engine/lib/users.php
+++ b/engine/lib/users.php
@@ -576,6 +576,10 @@
return false;
}
+ // Check to see if we've registered the first admin yet.
+ // If not, this is the first admin user!
+ $admin = datalist_get('admin_registered');
+
// Otherwise ...
$user = new ElggUser();
$user->username = $username;
@@ -585,6 +589,11 @@
$user->access_id = 2;
$user->save();
+ if (!$admin) {
+ $user->admin = true;
+ datalist_set('admin_registered',1);
+ }
+
return $user->getGUID();
diff --git a/engine/start.php b/engine/start.php
index 87b8cfb1b..6c85ce75c 100644
--- a/engine/start.php
+++ b/engine/start.php
@@ -15,12 +15,11 @@
/**
* Load important prerequisites
*/
-
+
if (!@include_once(dirname(__FILE__) . "/lib/exceptions.php")) { // Exceptions
echo "Error in installation: could not load the Exceptions library.";
exit;
}
-
if (!@include_once(dirname(__FILE__) . "/lib/elgglib.php")) { // Main Elgg library
throw new InstallationException("Elgg could not load its main library.");
}
@@ -106,20 +105,23 @@
}
- // Autodetect some default configuration settings
- set_default_config();
-
// Trigger events
trigger_event('boot', 'system');
-
// Forward if we haven't been installed
if ((!is_installed() || !is_db_installed()) && !substr_count($_SERVER["PHP_SELF"],"install.php")) {
- forward("install.php");
+ // Autodetect some default configuration settings
+ set_default_config();
+ forward("install.php");
}
-
+
// Trigger events
- if (!substr_count($_SERVER["PHP_SELF"],"install.php")) {
+ if (!substr_count($_SERVER["PHP_SELF"],"install.php") &&
+ !substr_count($_SERVER["PHP_SELF"],"setup.php")) {
+ // If default settings haven't been installed, forward to the default settings page
trigger_event('init', 'system');
+ if (!datalist_get('default_settings')) {
+ //forward("setup.php");
+ }
}
?> \ No newline at end of file