aboutsummaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
authorben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-02-12 16:12:50 +0000
committerben <ben@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-02-12 16:12:50 +0000
commite5edab721ea12ba5ac937a5adeda53f5e3393611 (patch)
tree719ec8c5ac9b91ae0e536e8d0e375db372a456d1 /engine
parenteba31495c573836877c20fffdd833352738067ec (diff)
downloadelgg-e5edab721ea12ba5ac937a5adeda53f5e3393611.tar.gz
elgg-e5edab721ea12ba5ac937a5adeda53f5e3393611.tar.bz2
Sanitisation
git-svn-id: https://code.elgg.org/elgg/trunk@7 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine')
-rw-r--r--engine/lib/elgglib.php60
-rw-r--r--engine/start.php73
2 files changed, 85 insertions, 48 deletions
diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php
index 734407530..3a0d6f2a4 100644
--- a/engine/lib/elgglib.php
+++ b/engine/lib/elgglib.php
@@ -143,10 +143,16 @@
*
* @return true|false True if everything is ok (or Elgg is fit enough to run); false if not.
*/
- function sanitise() {
+ function sanitised() {
- if (!file_exists(dirname(dirname(__FILE__)) . "/settings.php"))
+ $sanitised = true;
+
+ if (!file_exists(dirname(dirname(__FILE__)) . "/settings.php")) {
register_error(elgg_view("messages/sanitisation/settings"));
+ $sanitised = false;
+ }
+
+ return $sanitised;
}
@@ -164,30 +170,42 @@
* @return true|false|array Either the array of messages, or a response regarding whether the message addition was successful
*/
- function system_messages($message = null, $register = "messages") {
+ function system_messages($message = null, $register = "messages", $count = false) {
static $messages;
if (!isset($messages)) {
$messages = array();
}
- if (!isset($messages[$register])) {
+ if (!isset($messages[$register]) && !empty($register)) {
$messages[$register] = array();
}
- if (!empty($message) && is_array($message)) {
- $messages[$register] = array_merge($messages[$register], $message);
- return true;
- } else if (!empty($message) && is_string($message)) {
- $messages[$register][] = $message;
- return true;
- } else if (!is_string($message) && !is_array($message)) {
+ if (!$count) {
+ if (!empty($message) && is_array($message)) {
+ $messages[$register] = array_merge($messages[$register], $message);
+ return true;
+ } else if (!empty($message) && is_string($message)) {
+ $messages[$register][] = $message;
+ return true;
+ } else if (!is_string($message) && !is_array($message)) {
+ if (!empty($register)) {
+ $returnarray = $messages[$register];
+ $messages[$register] = array();
+ } else {
+ $returnarray = $messages;
+ $messages = array();
+ }
+ return $returnarray;
+ }
+ } else {
if (!empty($register)) {
- $returnarray = $messages[$register];
- $messages[$register] = array();
+ return sizeof($messages[$register]);
} else {
- $returnarray = $messages;
- $messages = array();
+ $count = 0;
+ foreach($messages as $register => $submessages) {
+ $count += sizeof($submessages);
+ }
+ return $count;
}
- return $returnarray;
}
return false;
@@ -212,5 +230,15 @@
function register_error($error) {
return system_messages($error, "errors");
}
+
+ /**
+ * Counts the number of messages, either globally or in a particular register
+ *
+ * @param string $register Optionally, the register
+ * @return integer The number of messages
+ */
+ function count_messages($register = "") {
+ return system_messages(null,$register,true);
+ }
?> \ No newline at end of file
diff --git a/engine/start.php b/engine/start.php
index 864b2b112..7a38f7155 100644
--- a/engine/start.php
+++ b/engine/start.php
@@ -20,49 +20,58 @@
echo "Error in installation: could not load the main Elgg library.";
exit;
}
- if (!@include_once(dirname(__FILE__) . "/lib/database.php")) // Database connection
- register_error("Could not load the main Elgg database library.");
-
- /**
- * Ensure the installation is correctly formed
- */
-
- sanitise();
-
+
/**
* Load the system settings
*/
if (!@include_once(dirname(__FILE__) . "/settings.php")) // Global settings
register_error("Could not load the settings file.");
-
+
/**
- * Load the remaining libraries from /lib/ in alphabetical order,
- * except for a few exceptions
+ * If there are basic issues with the way the installation is formed, don't bother trying
+ * to load any more files
*/
- // We don't want to load or reload these files
-
- $file_exceptions = array(
- '.','..',
- '.svn',
- 'settings.php','settings.example.php','elgglib.php','database.php'
- );
-
- // Get the list of files to include, and alphabetically sort them
-
- $files = get_library_files(dirname(__FILE__) . "/lib",$file_exceptions);
- asort($files);
-
- // Include them
+ if (sanitised()) { // Begin portion for sanitised installs only
- foreach($files as $file) {
- if (!@include_once($file))
- register_error("Could not load {$file}");
- }
+ /**
+ * Load and initialise the database
+ */
+
+ if (!@include_once(dirname(__FILE__) . "/lib/database.php")) // Database connection
+ register_error("Could not load the main Elgg database library.");
+
+
+ /**
+ * Load the remaining libraries from /lib/ in alphabetical order,
+ * except for a few exceptions
+ */
+
+ // We don't want to load or reload these files
+
+ $file_exceptions = array(
+ '.','..',
+ '.svn',
+ 'settings.php','settings.example.php','elgglib.php','database.php'
+ );
+
+ // Get the list of files to include, and alphabetically sort them
+
+ $files = get_library_files(dirname(__FILE__) . "/lib",$file_exceptions);
+ asort($files);
+
+ // Include them
+
+ foreach($files as $file) {
+ if (!@include_once($file))
+ register_error("Could not load {$file}");
+ }
- if ($errors = system_messages(null, "errors")) {
- // Do something!
+ } // End portion for sanitised installs only
+
+ if ($count = count_messages("errors")) {
+
}
?> \ No newline at end of file