aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2009-10-15 14:06:51 +0000
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2009-10-15 14:06:51 +0000
commit7e08d8a4b110417ed017749d3183fa07d518a17b (patch)
tree599add016e44129fff7cdbe89192baa9c23a6467
parent54a3c3e7e9e70c4770010e442e95f734200d03f9 (diff)
downloadelgg-7e08d8a4b110417ed017749d3183fa07d518a17b.tar.gz
elgg-7e08d8a4b110417ed017749d3183fa07d518a17b.tar.bz2
Standardized files.
git-svn-id: http://code.elgg.org/elgg/trunk@3549 36083f99-b078-4883-b0ff-0f9b5a30f544
-rw-r--r--engine/lib/widgets.php834
-rw-r--r--engine/settings.example.php251
-rw-r--r--engine/start.php403
3 files changed, 727 insertions, 761 deletions
diff --git a/engine/lib/widgets.php b/engine/lib/widgets.php
index 7adf5ffad..a450d6223 100644
--- a/engine/lib/widgets.php
+++ b/engine/lib/widgets.php
@@ -1,528 +1,506 @@
<?php
+/**
+ * Elgg widgets library.
+ * Contains code for handling widgets.
+ *
+ * @package Elgg
+ * @subpackage Core
+ * @link http://elgg.org/
+ */
+
+/**
+ * Override ElggObject in order to store widget data in ultra-private stores.
+ */
+class ElggWidget extends ElggObject {
+ protected function initialise_attributes() {
+ parent::initialise_attributes();
+
+ $this->attributes['subtype'] = "widget";
+ }
- /**
- * Elgg widgets library.
- * Contains code for handling widgets.
- *
- * @package Elgg
- * @subpackage Core
-
-
- * @link http://elgg.org/
- */
+ public function __construct($guid = null) {
+ parent::__construct($guid);
+ }
/**
- * Override ElggObject in order to store widget data in ultra-private stores.
+ * Override entity get and sets in order to save data to private data store.
*/
- class ElggWidget extends ElggObject
- {
- protected function initialise_attributes()
- {
- parent::initialise_attributes();
-
- $this->attributes['subtype'] = "widget";
+ public function get($name) {
+ // See if its in our base attribute
+ if (isset($this->attributes[$name])) {
+ return $this->attributes[$name];
}
- public function __construct($guid = null) { parent::__construct($guid); }
-
- /**
- * Override entity get and sets in order to save data to private data store.
- */
- public function get($name)
- {
- // See if its in our base attribute
- if (isset($this->attributes[$name])) {
- return $this->attributes[$name];
- }
-
- // No, so see if its in the private data store.
- $meta = get_private_setting($this->guid, $name);
- if ($meta)
- return $meta;
-
- // Can't find it, so return null
- return null;
+ // No, so see if its in the private data store.
+ $meta = get_private_setting($this->guid, $name);
+ if ($meta) {
+ return $meta;
}
- /**
- * Override entity get and sets in order to save data to private data store.
- */
- public function set($name, $value)
- {
- if (array_key_exists($name, $this->attributes))
- {
- // Check that we're not trying to change the guid!
- if ((array_key_exists('guid', $this->attributes)) && ($name=='guid'))
- return false;
-
- $this->attributes[$name] = $value;
- }
- else
- return set_private_setting($this->guid, $name, $value);
-
- return true;
- }
+ // Can't find it, so return null
+ return null;
}
/**
- * Register a particular context for use with widgets.
- *
- * @param string $context The context we wish to enable context for
+ * Override entity get and sets in order to save data to private data store.
*/
- function use_widgets($context) {
-
- global $CONFIG;
- if (!isset($CONFIG->widgets))
- $CONFIG->widgets = new stdClass;
- if (!isset($CONFIG->widgets->contexts)) {
- $CONFIG->widgets->contexts = array();
- }
- if (!empty($context)) {
- $CONFIG->widgets->contexts[] = $context;
- }
-
- }
-
- /**
- * Determines whether or not the current context is using widgets
- *
- * @return true|false Depending on widget status
- */
- function using_widgets() {
-
- global $CONFIG;
- $context = get_context();
- if (isset($CONFIG->widgets->contexts) && is_array($CONFIG->widgets->contexts)) {
- if (in_array($context, $CONFIG->widgets->contexts)) return true;
+ public function set($name, $value) {
+ if (array_key_exists($name, $this->attributes)) {
+ // Check that we're not trying to change the guid!
+ if ((array_key_exists('guid', $this->attributes)) && ($name=='guid')) {
+ return false;
}
- return false;
-
+ $this->attributes[$name] = $value;
+ } else {
+ return set_private_setting($this->guid, $name, $value);
}
- /**
- * When given a widget entity and a new requested location, saves the new location
- * and also provides a sensible ordering for all widgets in that column
- *
- * @param ElggObject $widget The widget entity
- * @param int $order The order within the column
- * @param int $column The column (1, 2 or 3)
- * @return true|false Depending on success
- */
- function save_widget_location(ElggObject $widget, $order, $column) {
-
- if ($widget instanceof ElggObject) {
- if ($widget->subtype == "widget") {
-
- // If you can't move the widget, don't save a new location
- if (!$widget->draggable)
- return false;
-
- // Sanitise the column value
- if ($column != 1 || $column != 2 || $column != 3)
- $column = 1;
-
- $widget->column = (int) $column;
-
- $ordertmp = array();
-
- if ($entities = get_entities_from_metadata_multi(array(
- 'context' => $widget->context,
- 'column' => $column,
- ),'object','widget')) {
- foreach($entities as $entity) {
- $entityorder = $entity->order;
- if ($entityorder < $order) {
- $ordertmp[$entityorder] = $entity;
- }
- if ($entityorder >= $order) {
- $ordertmp[$entityorder + 10000] = $entity;
- }
- }
- }
-
- $ordertmp[$order] = $widget;
- ksort($ordertmp);
+ return true;
+ }
+}
+
+/**
+ * Register a particular context for use with widgets.
+ *
+ * @param string $context The context we wish to enable context for
+ */
+function use_widgets($context) {
+ global $CONFIG;
+
+ if (!isset($CONFIG->widgets)) {
+ $CONFIG->widgets = new stdClass;
+ }
- $orderticker = 10;
- foreach($ordertmp as $orderval => $entity) {
- $entity->order = $orderticker;
- $orderticker += 10;
- }
+ if (!isset($CONFIG->widgets->contexts)) {
+ $CONFIG->widgets->contexts = array();
+ }
- return true;
+ if (!empty($context)) {
+ $CONFIG->widgets->contexts[] = $context;
+ }
+}
+
+/**
+ * Determines whether or not the current context is using widgets
+ *
+ * @return true|false Depending on widget status
+ */
+function using_widgets() {
+ global $CONFIG;
+
+ $context = get_context();
+ if (isset($CONFIG->widgets->contexts) && is_array($CONFIG->widgets->contexts)) {
+ if (in_array($context, $CONFIG->widgets->contexts)) return true;
+ }
- } else {
- register_error($widget->subtype);
- }
+ return false;
+}
+
+/**
+ * When given a widget entity and a new requested location, saves the new location
+ * and also provides a sensible ordering for all widgets in that column
+ *
+ * @param ElggObject $widget The widget entity
+ * @param int $order The order within the column
+ * @param int $column The column (1, 2 or 3)
+ * @return true|false Depending on success
+ */
+function save_widget_location(ElggObject $widget, $order, $column) {
+ if ($widget instanceof ElggObject) {
+ if ($widget->subtype == "widget") {
+ // If you can't move the widget, don't save a new location
+ if (!$widget->draggable) {
+ return false;
+ }
+ // Sanitise the column value
+ if ($column != 1 || $column != 2 || $column != 3) {
+ $column = 1;
}
- return false;
+ $widget->column = (int) $column;
- }
+ $ordertmp = array();
+ $params = array(
+ 'context' => $widget->context,
+ 'column' => $column,
+ );
- /**
- * Get widgets for a particular context and column, in order of display
- *
- * @param int $user_guid The owner user GUID
- * @param string $context The context (profile, dashboard etc)
- * @param int $column The column (1 or 2)
- * @return array|false An array of widget ElggObjects, or false
- */
- function get_widgets($user_guid, $context, $column) {
-
- if ($widgets = get_entities_from_private_setting_multi(array(
- 'column' => $column,
- 'context' => $context), "object", "widget", $user_guid, "", 10000))
- /*if ($widgets = get_user_objects_by_metadata($user_guid, "widget", array(
- 'column' => $column,
- 'context' => $context,
- ), 10000)) {
- */
- {
-
- $widgetorder = array();
- foreach($widgets as $widget) {
- $order = $widget->order;
- while(isset($widgetorder[$order])) {
- $order++;
+ if ($entities = get_entities_from_metadata_multi($params,'object','widget')) {
+ foreach($entities as $entity) {
+ $entityorder = $entity->order;
+ if ($entityorder < $order) {
+ $ordertmp[$entityorder] = $entity;
+ }
+ if ($entityorder >= $order) {
+ $ordertmp[$entityorder + 10000] = $entity;
}
- $widgetorder[$order] = $widget;
}
+ }
- ksort($widgetorder);
-
- return $widgetorder;
+ $ordertmp[$order] = $widget;
+ ksort($ordertmp);
+ $orderticker = 10;
+ foreach($ordertmp as $orderval => $entity) {
+ $entity->order = $orderticker;
+ $orderticker += 10;
}
- return false;
-
+ return true;
+ } else {
+ register_error($widget->subtype);
}
- /**
- * Displays a particular widget
- *
- * @param ElggObject $widget The widget to display
- * @return string The HTML for the widget, including JavaScript wrapper
- */
- function display_widget(ElggObject $widget) {
-
- return elgg_view_entity($widget);
+ }
+ return false;
+}
+
+/**
+ * Get widgets for a particular context and column, in order of display
+ *
+ * @param int $user_guid The owner user GUID
+ * @param string $context The context (profile, dashboard etc)
+ * @param int $column The column (1 or 2)
+ * @return array|false An array of widget ElggObjects, or false
+ */
+function get_widgets($user_guid, $context, $column) {
+ $params = array(
+ 'column' => $column,
+ 'context' => $context
+ );
+ $widgets = get_entities_from_private_setting_multi($params, "object", "widget", $user_guid, "", 10000);
+ if ($widgets) {
+ $widgetorder = array();
+ foreach($widgets as $widget) {
+ $order = $widget->order;
+ while(isset($widgetorder[$order])) {
+ $order++;
+ }
+ $widgetorder[$order] = $widget;
}
- /**
- * Add a new widget
- *
- * @param int $user_guid User GUID to associate this widget with
- * @param string $handler The handler for this widget
- * @param string $context The page context for this widget
- * @param int $order The order to display this widget in
- * @param int $column The column to display this widget in (1, 2 or 3)
- * @param int $access_id If not specified, it is set to the default access level
- * @return true|false Depending on success
- */
- function add_widget($user_guid, $handler, $context, $order = 0, $column = 1, $access_id = null) {
+ ksort($widgetorder);
- if (empty($user_guid) || empty($context) || empty($handler) || !widget_type_exists($handler))
- return false;
-
- if ($user = get_user($user_guid)) {
+ return $widgetorder;
+ }
- $widget = new ElggWidget;
- $widget->owner_guid = $user_guid;
- $widget->container_guid = $user_guid;
- if (isset($access_id)) {
- $widget->access_id = $access_id;
- } else {
- $widget->access_id = get_default_access();
- }
+ return false;
+}
+
+/**
+ * Displays a particular widget
+ *
+ * @param ElggObject $widget The widget to display
+ * @return string The HTML for the widget, including JavaScript wrapper
+ */
+function display_widget(ElggObject $widget) {
+ return elgg_view_entity($widget);
+}
+
+/**
+ * Add a new widget
+ *
+ * @param int $user_guid User GUID to associate this widget with
+ * @param string $handler The handler for this widget
+ * @param string $context The page context for this widget
+ * @param int $order The order to display this widget in
+ * @param int $column The column to display this widget in (1, 2 or 3)
+ * @param int $access_id If not specified, it is set to the default access level
+ * @return true|false Depending on success
+ */
+function add_widget($user_guid, $handler, $context, $order = 0, $column = 1, $access_id = null) {
+ if (empty($user_guid) || empty($context) || empty($handler) || !widget_type_exists($handler)) {
+ return false;
+ }
- if (!$widget->save())
- return false;
+ if ($user = get_user($user_guid)) {
+ $widget = new ElggWidget;
+ $widget->owner_guid = $user_guid;
+ $widget->container_guid = $user_guid;
+ if (isset($access_id)) {
+ $widget->access_id = $access_id;
+ } else {
+ $widget->access_id = get_default_access();
+ }
- $widget->handler = $handler;
- $widget->context = $context;
- $widget->column = $column;
- $widget->order = $order;
+ if (!$widget->save()) {
+ return false;
+ }
- // save_widget_location($widget, $order, $column);
- return true;
+ $widget->handler = $handler;
+ $widget->context = $context;
+ $widget->column = $column;
+ $widget->order = $order;
- }
+ // save_widget_location($widget, $order, $column);
+ return true;
- return false;
+ }
+ return false;
+}
+
+/**
+ * Define a new widget type
+ *
+ * @param string $handler The identifier for the widget handler
+ * @param string $name The name of the widget type
+ * @param string $description A description for the widget type
+ * @param string $context A comma-separated list of contexts where this widget is allowed (default: 'all')
+ * @param true|false $multiple Whether or not multiple instances of this widget are allowed on a single dashboard (default: false)
+ * @param string $position A comma-separated list of positions on the page (side or main) where this widget is allowed (default: "side,main")
+ * @return true|false Depending on success
+ */
+
+function add_widget_type($handler, $name, $description, $context = "all", $multiple = false, $positions = "side,main") {
+ if (!empty($handler) && !empty($name)) {
+ global $CONFIG;
+
+ if (!isset($CONFIG->widgets)) {
+ $CONFIG->widgets = new stdClass;
}
- /**
- * Define a new widget type
- *
- * @param string $handler The identifier for the widget handler
- * @param string $name The name of the widget type
- * @param string $description A description for the widget type
- * @param string $context A comma-separated list of contexts where this widget is allowed (default: 'all')
- * @param true|false $multiple Whether or not multiple instances of this widget are allowed on a single dashboard (default: false)
- * @param string $position A comma-separated list of positions on the page (side or main) where this widget is allowed (default: "side,main")
- * @return true|false Depending on success
- */
+ if (!isset($CONFIG->widgets->handlers)) {
+ $CONFIG->widgets->handlers = array();
+ }
- function add_widget_type($handler, $name, $description, $context = "all", $multiple = false, $positions = "side,main") {
+ $handlerobj = new stdClass;
+ $handlerobj->name = $name;
+ $handlerobj->description = $description;
+ $handlerobj->context = explode(",",$context);
+ $handlerobj->multiple = $multiple;
+ $handlerobj->positions = explode(",",$positions);
- if (!empty($handler) && !empty($name)) {
+ $CONFIG->widgets->handlers[$handler] = $handlerobj;
- global $CONFIG;
+ return true;
+ }
- if (!isset($CONFIG->widgets))
- $CONFIG->widgets = new stdClass;
+ return false;
+}
+
+/**
+ * Determines whether or not widgets with the specified handler have been defined
+ *
+ * @param string $handler The widget handler identifying string
+ * @return true|false Whether or not those widgets exist
+ */
+function widget_type_exists($handler) {
+ global $CONFIG;
+
+ if (!empty($CONFIG->widgets)
+ && !empty($CONFIG->widgets->handlers)
+ && is_array($CONFIG->widgets->handlers)
+ && array_key_exists($handler, $CONFIG->widgets->handlers)) {
+ return true;
+ }
- if (!isset($CONFIG->widgets->handlers))
- $CONFIG->widgets->handlers = array();
+ return false;
+}
- $handlerobj = new stdClass;
- $handlerobj->name = $name;
- $handlerobj->description = $description;
- $handlerobj->context = explode(",",$context);
- $handlerobj->multiple = $multiple;
- $handlerobj->positions = explode(",",$positions);
+/**
+ * Returns an array of stdClass objects representing the defined widget types
+ *
+ * @return array A list of types defined (if any)
+ */
+function get_widget_types() {
+ global $CONFIG;
- $CONFIG->widgets->handlers[$handler] = $handlerobj;
+ if (!empty($CONFIG->widgets)
+ && !empty($CONFIG->widgets->handlers)
+ && is_array($CONFIG->widgets->handlers)) {
- return true;
+ $context = get_context();
+ foreach($CONFIG->widgets->handlers as $key => $handler) {
+ if (!in_array('all',$handler->context) &&
+ !in_array($context,$handler->context)) {
+ unset($CONFIG->widgets->handlers[$key]);
+ }
}
- return false;
-
+ return $CONFIG->widgets->handlers;
}
- /**
- * Determines whether or not widgets with the specified handler have been defined
- *
- * @param string $handler The widget handler identifying string
- * @return true|false Whether or not those widgets exist
- */
- function widget_type_exists($handler) {
+ return array();
+}
- global $CONFIG;
- if (!empty($CONFIG->widgets)
- && !empty($CONFIG->widgets->handlers)
- && is_array($CONFIG->widgets->handlers)
- && array_key_exists($handler, $CONFIG->widgets->handlers))
- return true;
+/**
+ * Saves a widget's settings (by passing an array of (name => value) pairs to save_{$handler}_widget)
+ *
+ * @param int $widget_guid The GUID of the widget we're saving to
+ * @param array $params An array of name => value parameters
+ */
+function save_widget_info($widget_guid, $params) {
+ if ($widget = get_entity($widget_guid)) {
- return false;
+ $subtype = $widget->getSubtype();
+ if ($subtype != "widget") {
+ return false;
+ }
+ $handler = $widget->handler;
+ if (empty($handler) || !widget_type_exists($handler)) {
+ return false;
}
- /**
- * Returns an array of stdClass objects representing the defined widget types
- *
- * @return array A list of types defined (if any)
- */
- function get_widget_types() {
-
- global $CONFIG;
- if (!empty($CONFIG->widgets)
- && !empty($CONFIG->widgets->handlers)
- && is_array($CONFIG->widgets->handlers)) {
+ if (!$widget->canEdit()) {
+ return false;
+ }
- $context = get_context();
+ // Save the params to the widget
+ if (is_array($params) && sizeof($params) > 0) {
+ foreach($params as $name => $value) {
- foreach($CONFIG->widgets->handlers as $key => $handler) {
- if (!in_array('all',$handler->context) &&
- !in_array($context,$handler->context)) {
- unset($CONFIG->widgets->handlers[$key]);
- }
+ if (!empty($name) && !in_array($name, array(
+ 'guid','owner_guid','site_guid'
+ ))) {
+ if (is_array($value)) {
+ // TODO: Handle arrays securely
+ $widget->setMetaData($name, $value, "", true);
+ } else {
+ $widget->$name = $value;
}
-
- return $CONFIG->widgets->handlers;
-
}
-
- return array();
-
+ }
+ $widget->save();
}
- /**
- * Saves a widget's settings (by passing an array of (name => value) pairs to save_{$handler}_widget)
- *
- * @param int $widget_guid The GUID of the widget we're saving to
- * @param array $params An array of name => value parameters
- */
- function save_widget_info($widget_guid, $params) {
-
- if ($widget = get_entity($widget_guid)) {
+ $function = "save_{$handler}_widget";
+ if (is_callable($function)) {
+ return $function($params);
+ }
- $subtype = $widget->getSubtype();
+ return true;
+ }
- if ($subtype != "widget") return false;
- $handler = $widget->handler;
- if (empty($handler) || !widget_type_exists($handler)) return false;
+ return false;
+}
- if (!$widget->canEdit()) return false;
+function reorder_widgets_from_panel($panelstring1, $panelstring2, $panelstring3, $context, $owner) {
+ $return = true;
- // Save the params to the widget
- if (is_array($params) && sizeof($params) > 0) {
- foreach($params as $name => $value) {
+ $mainwidgets = explode('::',$panelstring1);
+ $sidewidgets = explode('::',$panelstring2);
+ $rightwidgets = explode('::',$panelstring3);
- if (!empty($name) && !in_array($name,array(
- 'guid','owner_guid','site_guid'
- ))) {
- if (is_array($value))
- {
- // TODO: Handle arrays securely
- $widget->setMetaData($name, $value, "", true);
- }else
- $widget->$name = $value;
- }
- }
- $widget->save();
- }
+ $handlers = array();
+ $guids = array();
- $function = "save_{$handler}_widget";
- if (is_callable($function)) {
- return $function($params);
- }
+ if (is_array($mainwidgets) && sizeof($mainwidgets) > 0) {
+ foreach($mainwidgets as $widget) {
- return true;
+ $guid = (int) $widget;
+ if ("{$guid}" == "{$widget}") {
+ $guids[1][] = $widget;
+ } else {
+ $handlers[1][] = $widget;
}
-
- return false;
-
}
+ }
+ if (is_array($sidewidgets) && sizeof($sidewidgets) > 0) {
+ foreach($sidewidgets as $widget) {
- function reorder_widgets_from_panel($panelstring1, $panelstring2, $panelstring3, $context, $owner) {
-
- $return = true;
-
- $mainwidgets = explode('::',$panelstring1);
- $sidewidgets = explode('::',$panelstring2);
- $rightwidgets = explode('::',$panelstring3);
-
- $handlers = array();
- $guids = array();
+ $guid = (int) $widget;
- if (is_array($mainwidgets) && sizeof($mainwidgets) > 0) {
- foreach($mainwidgets as $widget) {
+ if ("{$guid}" == "{$widget}") {
+ $guids[2][] = $widget;
+ } else {
+ $handlers[2][] = $widget;
+ }
- $guid = (int) $widget;
+ }
+ }
+ if (is_array($rightwidgets) && sizeof($rightwidgets) > 0) {
+ foreach($rightwidgets as $widget) {
- if ("{$guid}" == "{$widget}") {
- $guids[1][] = $widget;
- } else {
- $handlers[1][] = $widget;
- }
+ $guid = (int) $widget;
- }
+ if ("{$guid}" == "{$widget}") {
+ $guids[3][] = $widget;
+ } else {
+ $handlers[3][] = $widget;
}
- if (is_array($sidewidgets) && sizeof($sidewidgets) > 0) {
- foreach($sidewidgets as $widget) {
- $guid = (int) $widget;
+ }
+ }
- if ("{$guid}" == "{$widget}") {
- $guids[2][] = $widget;
+ // Reorder existing widgets or delete ones that have vanished
+ foreach (array(1,2,3) as $column) {
+ if ($dbwidgets = get_widgets($owner,$context,$column)) {
+
+ foreach($dbwidgets as $dbwidget) {
+ if (in_array($dbwidget->getGUID(),$guids[1]) || in_array($dbwidget->getGUID(),$guids[2]) || in_array($dbwidget->getGUID(),$guids[3])) {
+ if (in_array($dbwidget->getGUID(),$guids[1])) {
+ $pos = array_search($dbwidget->getGUID(),$guids[1]);
+ $col = 1;
+ } else if (in_array($dbwidget->getGUID(),$guids[2])) {
+ $pos = array_search($dbwidget->getGUID(),$guids[2]);
+ $col = 2;
} else {
- $handlers[2][] = $widget;
+ $pos = array_search($dbwidget->getGUID(),$guids[3]);
+ $col = 3;
}
-
- }
- }
- if (is_array($rightwidgets) && sizeof($rightwidgets) > 0) {
- foreach($rightwidgets as $widget) {
-
- $guid = (int) $widget;
-
- if ("{$guid}" == "{$widget}") {
- $guids[3][] = $widget;
+ $pos = ($pos + 1) * 10;
+ $dbwidget->column = $col;
+ $dbwidget->order = $pos;
+ } else {
+ $dbguid = $dbwidget->getGUID();
+ if (!$dbwidget->delete()) {
+ $return = false;
} else {
- $handlers[3][] = $widget;
+ // Remove state cookie
+ setcookie('widget' + $dbguid, null);
}
-
}
}
- // Reorder existing widgets or delete ones that have vanished
- foreach (array(1,2,3) as $column) {
- if ($dbwidgets = get_widgets($owner,$context,$column)) {
-
- foreach($dbwidgets as $dbwidget) {
- if (in_array($dbwidget->getGUID(),$guids[1]) || in_array($dbwidget->getGUID(),$guids[2]) || in_array($dbwidget->getGUID(),$guids[3])) {
- if (in_array($dbwidget->getGUID(),$guids[1])) {
- $pos = array_search($dbwidget->getGUID(),$guids[1]);
- $col = 1;
- } else if (in_array($dbwidget->getGUID(),$guids[2])) {
- $pos = array_search($dbwidget->getGUID(),$guids[2]);
- $col = 2;
- } else {
- $pos = array_search($dbwidget->getGUID(),$guids[3]);
- $col = 3;
- }
- $pos = ($pos + 1) * 10;
- $dbwidget->column = $col;
- $dbwidget->order = $pos;
- } else {
- $dbguid = $dbwidget->getGUID();
- if (!$dbwidget->delete()) {
- $return = false;
- } else {
- // Remove state cookie
- setcookie('widget' + $dbguid, null);
- }
- }
- }
-
- }
- // Add new ones
- if (sizeof($guids[$column]) > 0) {
- foreach($guids[$column] as $key => $guid) {
- if ($guid == 0) {
- $pos = ($key + 1) * 10;
- $handler = $handlers[$column][$key];
- if (!add_widget($owner,$handler,$context,$pos,$column))
- $return = false;
- }
+ }
+ // Add new ones
+ if (sizeof($guids[$column]) > 0) {
+ foreach($guids[$column] as $key => $guid) {
+ if ($guid == 0) {
+ $pos = ($key + 1) * 10;
+ $handler = $handlers[$column][$key];
+ if (!add_widget($owner,$handler,$context,$pos,$column)) {
+ $return = false;
}
}
}
-
- return $return;
-
- }
-
- /**
- * Run some things once.
- *
- */
- function widget_run_once()
- {
- // Register a class
- add_subtype("object", "widget", "ElggWidget");
- }
-
- /**
- * Function to initialise widgets functionality on Elgg init
- *
- */
- function widgets_init() {
-
- register_action('widgets/reorder');
- register_action('widgets/save');
- register_action('widgets/add');
-
- // Now run this stuff, but only once
- run_function_once("widget_run_once");
}
+ }
- // Register event
- register_elgg_event_handler('init','system','widgets_init');
-
- // Use widgets on the dashboard
- use_widgets('dashboard');
-
-
-?> \ No newline at end of file
+ return $return;
+}
+
+/**
+ * Run some things once.
+ *
+ */
+function widget_run_once() {
+ // Register a class
+ add_subtype("object", "widget", "ElggWidget");
+}
+
+/**
+ * Function to initialise widgets functionality on Elgg init
+ *
+ */
+function widgets_init() {
+ register_action('widgets/reorder');
+ register_action('widgets/save');
+ register_action('widgets/add');
+
+ // Now run this stuff, but only once
+ run_function_once("widget_run_once");
+}
+
+// Register event
+register_elgg_event_handler('init','system','widgets_init');
+
+// Use widgets on the dashboard
+use_widgets('dashboard'); \ No newline at end of file
diff --git a/engine/settings.example.php b/engine/settings.example.php
index 4fbc716a3..30d832456 100644
--- a/engine/settings.example.php
+++ b/engine/settings.example.php
@@ -1,129 +1,126 @@
<?php
+/**
+ * Elgg settings
+ *
+ * Elgg manages most of its configuration from the admin panel. However, we need you to
+ * include your database settings below.
+ *
+ * @todo Turn this into something we handle more automatically.
+ */
- /**
- * Elgg settings
- *
- * Elgg manages most of its configuration from the admin panel. However, we need you to
- * include your database settings below.
- *
- * @todo Turn this into something we handle more automatically.
- */
-
- global $CONFIG;
- if (!isset($CONFIG))
- $CONFIG = new stdClass;
-
- /*
- * Standard configuration
- *
- * You will use the same database connection for reads and writes.
- * This is the easiest configuration, and will suit 99.99% of setups. However, if you're
- * running a really popular site, you'll probably want to spread out your database connections
- * and implement database replication. That's beyond the scope of this configuration file
- * to explain, but if you know you need it, skip past this section.
- */
-
- // Database username
- $CONFIG->dbuser = '{{CONFIG_DBUSER}}';
-
- // Database password
- $CONFIG->dbpass = '{{CONFIG_DBPASS}}';
-
- // Database name
- $CONFIG->dbname = '{{CONFIG_DBNAME}}';
-
- // Database server
- // (For most configurations, you can leave this as 'localhost')
- $CONFIG->dbhost = '{{CONFIG_DBHOST}}';
-
- // Database table prefix
- // If you're sharing a database with other applications, you will want to use this
- // to differentiate Elgg's tables.
- $CONFIG->dbprefix = '{{CONFIG_DBPREFIX}}';
-
- /*
- * Multiple database connections
- *
- * Here you can set up multiple connections for reads and writes. To do this, uncomment out
- * the lines below.
- */
-
- /*
-
- // Yes! We want to split reads and writes
- $CONFIG->db->split = true;
-
- // READS
- // Database username
- $CONFIG->db['read']->dbuser = "";
-
- // Database password
- $CONFIG->db['read']->dbpass = "";
-
- // Database name
- $CONFIG->db['read']->dbname = "";
-
- // Database server
- // (For most configurations, you can leave this as 'localhost')
- $CONFIG->db['read']->dbhost = "localhost";
-
- // WRITES
- // Database username
- $CONFIG->db['write']->dbuser = "";
-
- // Database password
- $CONFIG->db['write']->dbpass = "";
-
- // Database name
- $CONFIG->db['write']->dbname = "";
-
- // Database server
- // (For most configurations, you can leave this as 'localhost')
- $CONFIG->db['write']->dbhost = "localhost";
-
-
- */
-
- /*
- * For extra connections for both reads and writes, you can turn both
- * $CONFIG->db['read'] and $CONFIG->db['write'] into an array, eg:
- *
- * $CONFIG->db['read'][0]->dbhost = "localhost";
- *
- * Note that the array keys must be numeric and consecutive, i.e., they start
- * at 0, the next one must be at 1, etc.
- */
-
-
- /**
- * Memcache setup (optional)
- * This is where you may optionally set up memcache.
- *
- * Requirements:
- * 1) One or more memcache servers (http://www.danga.com/memcached/)
- * 2) PHP memcache wrapper (http://uk.php.net/manual/en/memcache.setup.php)
- *
- * Note: Multiple server support is only available on server 1.2.1 or higher with PECL library > 2.0.0
- */
- //$CONFIG->memcache = true;
- //
- //$CONFIG->memcache_servers = array (
- // array('server1', 11211),
- // array('server2', 11211)
- //);
-
- /**
- * Some work-around flags.
- */
-
- // Try uncommenting the below if your notification emails are not being sent
- // $CONFIG->broken_mta = true;
-
- /**
- * Url - I am not sure if this will be here ?
- **/
-
- // URL
- $CONFIG->url = "";
-
-?> \ No newline at end of file
+global $CONFIG;
+if (!isset($CONFIG)) {
+ $CONFIG = new stdClass;
+}
+
+/*
+ * Standard configuration
+ *
+ * You will use the same database connection for reads and writes.
+ * This is the easiest configuration, and will suit 99.99% of setups. However, if you're
+ * running a really popular site, you'll probably want to spread out your database connections
+ * and implement database replication. That's beyond the scope of this configuration file
+ * to explain, but if you know you need it, skip past this section.
+ */
+
+// Database username
+$CONFIG->dbuser = '{{CONFIG_DBUSER}}';
+
+// Database password
+$CONFIG->dbpass = '{{CONFIG_DBPASS}}';
+
+// Database name
+$CONFIG->dbname = '{{CONFIG_DBNAME}}';
+
+// Database server
+// (For most configurations, you can leave this as 'localhost')
+$CONFIG->dbhost = '{{CONFIG_DBHOST}}';
+
+// Database table prefix
+// If you're sharing a database with other applications, you will want to use this
+// to differentiate Elgg's tables.
+$CONFIG->dbprefix = '{{CONFIG_DBPREFIX}}';
+
+/*
+ * Multiple database connections
+ *
+ * Here you can set up multiple connections for reads and writes. To do this, uncomment out
+ * the lines below.
+ */
+
+/*
+
+// Yes! We want to split reads and writes
+$CONFIG->db->split = true;
+
+// READS
+// Database username
+$CONFIG->db['read']->dbuser = "";
+
+// Database password
+$CONFIG->db['read']->dbpass = "";
+
+// Database name
+$CONFIG->db['read']->dbname = "";
+
+// Database server
+// (For most configurations, you can leave this as 'localhost')
+$CONFIG->db['read']->dbhost = "localhost";
+
+// WRITES
+// Database username
+$CONFIG->db['write']->dbuser = "";
+
+// Database password
+$CONFIG->db['write']->dbpass = "";
+
+// Database name
+$CONFIG->db['write']->dbname = "";
+
+// Database server
+// (For most configurations, you can leave this as 'localhost')
+$CONFIG->db['write']->dbhost = "localhost";
+
+ */
+
+/*
+ * For extra connections for both reads and writes, you can turn both
+ * $CONFIG->db['read'] and $CONFIG->db['write'] into an array, eg:
+ *
+ * $CONFIG->db['read'][0]->dbhost = "localhost";
+ *
+ * Note that the array keys must be numeric and consecutive, i.e., they start
+ * at 0, the next one must be at 1, etc.
+ */
+
+
+/**
+ * Memcache setup (optional)
+ * This is where you may optionally set up memcache.
+ *
+ * Requirements:
+ * 1) One or more memcache servers (http://www.danga.com/memcached/)
+ * 2) PHP memcache wrapper (http://uk.php.net/manual/en/memcache.setup.php)
+ *
+ * Note: Multiple server support is only available on server 1.2.1 or higher with PECL library > 2.0.0
+ */
+//$CONFIG->memcache = true;
+//
+//$CONFIG->memcache_servers = array (
+// array('server1', 11211),
+// array('server2', 11211)
+//);
+
+/**
+ * Some work-around flags.
+ */
+
+// Try uncommenting the below if your notification emails are not being sent
+// $CONFIG->broken_mta = true;
+
+/**
+ * Url - I am not sure if this will be here ?
+ **/
+
+// URL
+$CONFIG->url = ""; \ No newline at end of file
diff --git a/engine/start.php b/engine/start.php
index 23a04cb60..b6699309b 100644
--- a/engine/start.php
+++ b/engine/start.php
@@ -1,219 +1,210 @@
<?php
+/**
+ * Elgg engine bootstrapper
+ * Loads the various elements of the Elgg engine
+ *
+ * @package Elgg
+ * @subpackage Core
+ * @author Curverider Ltd
+ * @link http://elgg.org/
+ */
- /**
- * Elgg engine bootstrapper
- * Loads the various elements of the Elgg engine
- *
- * @package Elgg
- * @subpackage Core
+/*
+ * Basic profiling
+ */
+global $START_MICROTIME;
+$START_MICROTIME = microtime(true);
- * @author Curverider Ltd
+/**
+ * Load important prerequisites
+ */
- * @link http://elgg.org/
- */
+if (!include_once(dirname(__FILE__) . "/lib/exceptions.php")) { // Exceptions
+ echo "Error in installation: could not load the Exceptions library.";
+ exit;
+}
- /*
- * Basic profiling
- */
- global $START_MICROTIME;
- $START_MICROTIME = microtime(true);
+if (!include_once(dirname(__FILE__) . "/lib/elgglib.php")) { // Main Elgg library
+ echo "Elgg could not load its main library.";
+ exit;
+}
+if (!include_once(dirname(__FILE__) . "/lib/access.php")) { // Access library
+ echo "Error in installation: could not load the Access library.";
+ exit;
+}
+
+if (!include_once(dirname(__FILE__) . "/lib/system_log.php")) { // Logging library
+ echo "Error in installation: could not load the System Log library.";
+ exit;
+}
+
+if (!include_once(dirname(__FILE__) . "/lib/export.php")) { // Export library
+ echo "Error in installation: could not load the Export library.";
+ exit;
+}
+
+if (!include_once(dirname(__FILE__) . "/lib/sessions.php")) {
+ echo ("Error in installation: Elgg could not load the Sessions library");
+ exit;
+}
+
+if (!include_once(dirname(__FILE__) . "/lib/languages.php")) { // Languages library
+ echo "Error in installation: could not load the languages library.";
+ exit;
+}
+
+if (!include_once(dirname(__FILE__) . "/lib/input.php")) { // Input library
+ echo "Error in installation: could not load the input library.";
+ exit;
+}
+
+if (!include_once(dirname(__FILE__) . "/lib/install.php")) { // Installation library
+ echo "Error in installation: could not load the installation library.";
+ exit;
+}
+
+if (!include_once(dirname(__FILE__) . "/lib/cache.php")) { // Installation library
+ echo "Error in installation: could not load the cache library.";
+ exit;
+}
+
+
+
+// Use fallback view until sanitised
+$oldview = get_input('view');
+set_input('view', 'failsafe');
+
+/**
+ * Set light mode default
+ */
+$lightmode = false;
+
+/**
+ * Establish handlers
+ */
+
+// Register the error handler
+set_error_handler('__elgg_php_error_handler');
+set_exception_handler('__elgg_php_exception_handler');
+
+/**
+ * If there are basic issues with the way the installation is formed, don't bother trying
+ * to load any more files
+ */
+// Begin portion for sanitised installs only
+if ($sanitised = sanitised()) {
/**
- * 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
- echo "Elgg could not load its main library.";
- exit;
- }
-
- if (!include_once(dirname(__FILE__) . "/lib/access.php")) { // Access library
- echo "Error in installation: could not load the Access library.";
- exit;
- }
-
- if (!include_once(dirname(__FILE__) . "/lib/system_log.php")) { // Logging library
- echo "Error in installation: could not load the System Log library.";
- exit;
- }
-
- if (!include_once(dirname(__FILE__) . "/lib/export.php")) { // Export library
- echo "Error in installation: could not load the Export library.";
- exit;
- }
-
- if (!include_once(dirname(__FILE__) . "/lib/sessions.php")) {
- echo ("Error in installation: Elgg could not load the Sessions library");
- exit;
- }
-
- if (!include_once(dirname(__FILE__) . "/lib/languages.php")) { // Languages library
- echo "Error in installation: could not load the languages library.";
- exit;
- }
-
- if (!include_once(dirname(__FILE__) . "/lib/input.php")) { // Input library
- echo "Error in installation: could not load the input library.";
- exit;
- }
-
- if (!include_once(dirname(__FILE__) . "/lib/install.php")) { // Installation library
- echo "Error in installation: could not load the installation library.";
- exit;
- }
-
- if (!include_once(dirname(__FILE__) . "/lib/cache.php")) { // Installation library
- echo "Error in installation: could not load the cache library.";
- exit;
- }
-
-
-
- // Use fallback view until sanitised
- $oldview = get_input('view');
- set_input('view', 'failsafe');
-
- /**
- * Set light mode default
+ * Load the system settings
*/
- $lightmode = false;
-
+ if (!include_once(dirname(__FILE__) . "/settings.php")) {
+ throw new InstallationException("Elgg could not load the settings file.");
+ }
+
/**
- * Establish handlers
+ * Load and initialise the database
*/
-
- // Register the error handler
- set_error_handler('__elgg_php_error_handler');
- set_exception_handler('__elgg_php_exception_handler');
-
+ if (!include_once(dirname(__FILE__) . "/lib/database.php")) {
+ throw new InstallationException("Elgg could not load the main Elgg database library.");
+ }
+
/**
- * If there are basic issues with the way the installation is formed, don't bother trying
- * to load any more files
+ * Load the remaining libraries from /lib/ in alphabetical order,
+ * except for a few exceptions
*/
-
- if ($sanitised = sanitised()) { // Begin portion for sanitised installs only
-
- /**
- * Load the system settings
- */
-
- if (!include_once(dirname(__FILE__) . "/settings.php")) // Global settings
- throw new InstallationException("Elgg could not load the settings file.");
-
- /**
- * Load and initialise the database
- */
-
- if (!include_once(dirname(__FILE__) . "/lib/database.php")) // Database connection
- throw new InstallationException("Elgg could not load the main Elgg database library.");
-
- /**
- * Load the remaining libraries from /lib/ in alphabetical order,
- * except for a few exceptions
- */
-
- if (!include_once(dirname(__FILE__) . "/lib/actions.php")) {
- throw new InstallationException("Elgg could not load the Actions library");
- }
-
-
-
- // We don't want to load or reload these files
-
- $file_exceptions = array(
- '.','..',
- '.DS_Store',
- 'Thumbs.db',
- '.svn',
- 'CVS','cvs',
- 'settings.php','settings.example.php','languages.php','exceptions.php','elgglib.php','access.php','database.php','actions.php','sessions.php'
- );
-
- // Get the list of files to include, and alphabetically sort them
-
- $files = get_library_files(dirname(__FILE__) . "/lib",$file_exceptions);
- asort($files);
-
- // Get config
- global $CONFIG;
-
- // Include them
- foreach($files as $file) {
- if (isset($CONFIG->debug) && $CONFIG->debug) error_log("Loading $file...");
- if (!include_once($file))
- throw new InstallationException("Could not load {$file}");
- }
-
- } else { // End portion for sanitised installs only
-
- throw new InstallationException(elgg_echo('installation:error:configuration'));
-
+ if (!include_once(dirname(__FILE__) . "/lib/actions.php")) {
+ throw new InstallationException("Elgg could not load the Actions library");
+ }
+
+ // We don't want to load or reload these files
+ $file_exceptions = array(
+ '.', '..', '.DS_Store', 'Thumbs.db', '.svn',
+ 'CVS', 'cvs', 'settings.php', 'settings.example.php',
+ 'languages.php', 'exceptions.php', 'elgglib.php', 'access.php',
+ 'database.php', 'actions.php', 'sessions.php'
+ );
+
+ // Get the list of files to include, and alphabetically sort them
+ $files = get_library_files(dirname(__FILE__) . "/lib",$file_exceptions);
+ asort($files);
+
+ // Get config
+ global $CONFIG;
+
+ // Include them
+ foreach($files as $file) {
+ if (isset($CONFIG->debug) && $CONFIG->debug) {
+ error_log("Loading $file...");
+ }
+ if (!include_once($file)) {
+ throw new InstallationException("Could not load {$file}");
}
-
- // Autodetect some default configuration settings
- set_default_config();
-
- // Trigger events
- trigger_elgg_event('boot', 'system');
-
- // Load plugins
-
- $installed = is_installed();
- $db_installed = is_db_installed();
-
- // Determine light mode
- $lm = strtolower(get_input('lightmode'));
- if ($lm == 'true') $lightmode = true;
-
- // Load plugins, if we're not in light mode
- if (($installed) && ($db_installed) && ($sanitised) && (!$lightmode)) {
- load_plugins();
-
- trigger_elgg_event('plugins_boot', 'system');
- }
-
- // Forward if we haven't been installed
- if ((!$installed || !$db_installed) && !substr_count($_SERVER["PHP_SELF"],"install.php") && !substr_count($_SERVER["PHP_SELF"],"css.php") && !substr_count($_SERVER["PHP_SELF"],"action_handler.php")) {
- header("Location: install.php");
- exit;
- }
-
- // Trigger events
- if (!substr_count($_SERVER["PHP_SELF"],"install.php") &&
- !substr_count($_SERVER["PHP_SELF"],"setup.php") &&
- !$lightmode
- && !(defined('upgrading') && upgrading == 'upgrading')) {
- // If default settings haven't been installed, forward to the default settings page
- trigger_elgg_event('init', 'system');
- //if (!datalist_get('default_settings')) {
- //forward("setup.php");
- //}
- }
-
- // System booted, return to normal view
- set_input('view', $oldview);
- if (empty($oldview)) {
- if (empty($CONFIG->view))
- $oldview = 'default';
- else
- $oldview = $CONFIG->view;
- }
-
- if (($installed) && ($db_installed))
- {
- $lastupdate = datalist_get('simplecache_lastupdate');
- $lastcached = datalist_get('simplecache_'.$oldview);
- if ($lastupdate == 0 || $lastcached < $lastupdate) {
- elgg_view_regenerate_simplecache();
- $lastcached = time();
- datalist_set('simplecache_lastupdate',$lastcached);
- datalist_set('simplecache_'.$oldview,$lastcached);
- }
- $CONFIG->lastcache = $lastcached;
- }
-?> \ No newline at end of file
+ }
+} else { // End portion for sanitised installs only
+ throw new InstallationException(elgg_echo('installation:error:configuration'));
+}
+
+// Autodetect some default configuration settings
+set_default_config();
+
+// Trigger events
+trigger_elgg_event('boot', 'system');
+
+// Load plugins
+$installed = is_installed();
+$db_installed = is_db_installed();
+
+// Determine light mode
+$lm = strtolower(get_input('lightmode'));
+if ($lm == 'true') {
+ $lightmode = true;
+}
+
+// Load plugins, if we're not in light mode
+if (($installed) && ($db_installed) && ($sanitised) && (!$lightmode)) {
+ load_plugins();
+
+ trigger_elgg_event('plugins_boot', 'system');
+}
+
+// Forward if we haven't been installed
+if ((!$installed || !$db_installed)
+ && !substr_count($_SERVER["PHP_SELF"], "install.php")
+ && !substr_count($_SERVER["PHP_SELF"],"css.php")
+ && !substr_count($_SERVER["PHP_SELF"],"action_handler.php")) {
+
+ header("Location: install.php");
+ exit;
+}
+
+// Trigger events
+if (!substr_count($_SERVER["PHP_SELF"],"install.php") &&
+ !substr_count($_SERVER["PHP_SELF"],"setup.php") &&
+ !$lightmode
+ && !(defined('upgrading') && upgrading == 'upgrading')) {
+
+
+ trigger_elgg_event('init', 'system');
+}
+
+// System booted, return to normal view
+set_input('view', $oldview);
+if (empty($oldview)) {
+ if (empty($CONFIG->view)) {
+ $oldview = 'default';
+ } else {
+ $oldview = $CONFIG->view;
+ }
+}
+
+if (($installed) && ($db_installed)) {
+ $lastupdate = datalist_get('simplecache_lastupdate');
+ $lastcached = datalist_get('simplecache_'.$oldview);
+ if ($lastupdate == 0 || $lastcached < $lastupdate) {
+ elgg_view_regenerate_simplecache();
+ $lastcached = time();
+ datalist_set('simplecache_lastupdate',$lastcached);
+ datalist_set('simplecache_'.$oldview,$lastcached);
+ }
+ $CONFIG->lastcache = $lastcached;
+} \ No newline at end of file