aboutsummaryrefslogtreecommitdiff
path: root/engine/lib
diff options
context:
space:
mode:
Diffstat (limited to 'engine/lib')
-rw-r--r--engine/lib/admin.php2
-rw-r--r--engine/lib/configuration.php19
-rw-r--r--engine/lib/deprecated-1.8.php7
-rw-r--r--engine/lib/entities.php9
-rw-r--r--engine/lib/navigation.php2
-rw-r--r--engine/lib/relationships.php33
-rw-r--r--engine/lib/statistics.php2
-rw-r--r--engine/lib/upgrade.php104
-rw-r--r--engine/lib/upgrades/2011010101.php5
-rw-r--r--engine/lib/users.php34
-rw-r--r--engine/lib/views.php29
11 files changed, 153 insertions, 93 deletions
diff --git a/engine/lib/admin.php b/engine/lib/admin.php
index 3bfb69102..c16da9295 100644
--- a/engine/lib/admin.php
+++ b/engine/lib/admin.php
@@ -348,7 +348,7 @@ function elgg_admin_add_plugin_settings_menu() {
'parent_name' => 'settings',
'context' => 'admin',
'section' => 'configure',
- ));
+ ));
}
}
}
diff --git a/engine/lib/configuration.php b/engine/lib/configuration.php
index cbc083bd0..b756d2e70 100644
--- a/engine/lib/configuration.php
+++ b/engine/lib/configuration.php
@@ -282,8 +282,8 @@ function datalist_set($name, $value) {
return false;
}
- $name = sanitise_string($name);
- $value = sanitise_string($value);
+ $sanitised_name = sanitise_string($name);
+ $sanitised_value = sanitise_string($value);
// If memcache is available then invalidate the cached copy
static $datalist_memcache;
@@ -295,13 +295,16 @@ function datalist_set($name, $value) {
$datalist_memcache->delete($name);
}
- insert_data("INSERT into {$CONFIG->dbprefix}datalists"
- . " set name = '{$name}', value = '{$value}'"
- . " ON DUPLICATE KEY UPDATE value='{$value}'");
-
- $DATALIST_CACHE[$name] = $value;
+ $success = insert_data("INSERT into {$CONFIG->dbprefix}datalists"
+ . " set name = '{$sanitised_name}', value = '{$sanitised_value}'"
+ . " ON DUPLICATE KEY UPDATE value='{$sanitised_value}'");
- return true;
+ if ($success) {
+ $DATALIST_CACHE[$name] = $value;
+ return true;
+ } else {
+ return false;
+ }
}
/**
diff --git a/engine/lib/deprecated-1.8.php b/engine/lib/deprecated-1.8.php
index d92257a09..ff4fa0756 100644
--- a/engine/lib/deprecated-1.8.php
+++ b/engine/lib/deprecated-1.8.php
@@ -20,7 +20,7 @@
* @param string $fromdir Optional directory to load upgrades from. default: engine/schema/upgrades/
* @param bool $quiet If true, suppress all error messages. Only use for the upgrade from <=1.6.
*
- * @return bool
+ * @return int The number of upgrades run.
* @see upgrade.php
* @see version.php
* @deprecated 1.8 Use PHP upgrades for sql changes.
@@ -35,6 +35,8 @@ function db_upgrade($version, $fromdir = "", $quiet = FALSE) {
if (!$fromdir) {
$fromdir = $CONFIG->path . 'engine/schema/upgrades/';
}
+
+ $i = 0;
if ($handle = opendir($fromdir)) {
$sqlupgrades = array();
@@ -65,11 +67,12 @@ function db_upgrade($version, $fromdir = "", $quiet = FALSE) {
} else {
run_sql_script($fromdir . $sqlfile);
}
+ $i++;
}
}
}
- return TRUE;
+ return $i;
}
/**
diff --git a/engine/lib/entities.php b/engine/lib/entities.php
index cb197b569..10313fc8c 100644
--- a/engine/lib/entities.php
+++ b/engine/lib/entities.php
@@ -1190,10 +1190,10 @@ $time_created_lower = NULL, $time_updated_upper = NULL, $time_updated_lower = NU
* @internal This also provides the views for elgg_view_annotation().
*
* @param array $options Any options from $getter options plus:
- * full_view => BOOL Display full view entities
- * list_type_toggle => BOOL Display gallery / list switch
- * pagination => BOOL Display pagination links
- * gallery => BOOL display in gallery view
+ * full_view => BOOL Display full view entities
+ * list_type => STR 'list' or 'gallery'
+ * list_type_toggle => BOOL Display gallery / list switch
+ * pagination => BOOL Display pagination links
*
* @param mixed $getter The entity getter function to use to fetch the entities
* @param mixed $viewer The function to use to view the entity list.
@@ -1216,7 +1216,6 @@ function elgg_list_entities(array $options = array(), $getter = 'elgg_get_entiti
'full_view' => TRUE,
'list_type_toggle' => FALSE,
'pagination' => TRUE,
- 'gallery' => FALSE,
);
$options = array_merge($defaults, $options);
diff --git a/engine/lib/navigation.php b/engine/lib/navigation.php
index b51c63b49..4b2c998a2 100644
--- a/engine/lib/navigation.php
+++ b/engine/lib/navigation.php
@@ -276,7 +276,7 @@ function elgg_river_menu_setup($hook, $type, $return, $params) {
'href' => "#comments-add-$object->guid",
'text' => elgg_view_icon('speech-bubble'),
'title' => elgg_echo('comment:this'),
- 'link_class' => "elgg-toggler",
+ 'link_rel' => 'toggle',
'priority' => 50,
);
$return[] = ElggMenuItem::factory($options);
diff --git a/engine/lib/relationships.php b/engine/lib/relationships.php
index 5224efaf1..9d5fd39b6 100644
--- a/engine/lib/relationships.php
+++ b/engine/lib/relationships.php
@@ -593,38 +593,31 @@ function export_relationship_plugin_hook($hook, $entity_type, $returnvalue, $par
}
/**
- * An event listener which will notify users based on certain events.
+ * Notify user that someone has friended them
*
- * @param string $event Event name
- * @param string $object_type Object type
- * @param mixed $object Object
+ * @param string $event Event name
+ * @param string $type Object type
+ * @param mixed $object Object
*
* @return bool
*/
-function relationship_notification_hook($event, $object_type, $object) {
- global $CONFIG;
+function relationship_notification_hook($event, $type, $object) {
- if (
- ($object instanceof ElggRelationship) &&
- ($event == 'create') &&
- ($object_type == 'friend')
- ) {
- $user_one = get_entity($object->guid_one);
- $user_two = get_entity($object->guid_two);
+ $user_one = get_entity($object->guid_one);
+ $user_two = get_entity($object->guid_two);
- // Notify target user
- return notify_user($object->guid_two, $object->guid_one,
+ return notify_user($object->guid_two,
+ $object->guid_one,
elgg_echo('friend:newfriend:subject', array($user_one->name)),
elgg_echo("friend:newfriend:body", array($user_one->name, $user_one->getURL()))
- );
- }
+ );
}
-/** Register the import hook */
+// Register the import hook
elgg_register_plugin_hook_handler("import", "all", "import_relationship_plugin_hook", 3);
-/** Register the hook, ensuring entities are serialised first */
+// Register the hook, ensuring entities are serialised first
elgg_register_plugin_hook_handler("export", "all", "export_relationship_plugin_hook", 3);
-/** Register event to listen to some events **/
+// Register event to listen to some events
elgg_register_event_handler('create', 'friend', 'relationship_notification_hook');
diff --git a/engine/lib/statistics.php b/engine/lib/statistics.php
index cd2b7a6a1..1232c6128 100644
--- a/engine/lib/statistics.php
+++ b/engine/lib/statistics.php
@@ -96,7 +96,7 @@ function get_number_users($show_deactivated = false) {
*/
function get_online_users() {
$offset = get_input('offset', 0);
- $count = count(find_active_users(600, 9999));
+ $count = find_active_users(600, 10, $offset, true);
$objects = find_active_users(600, 10, $offset);
if ($objects) {
diff --git a/engine/lib/upgrade.php b/engine/lib/upgrade.php
index 85810956b..dc3911062 100644
--- a/engine/lib/upgrade.php
+++ b/engine/lib/upgrade.php
@@ -20,15 +20,15 @@ function upgrade_code($version, $quiet = FALSE) {
$version = (int) $version;
$upgrade_path = elgg_get_config('path') . 'engine/lib/upgrades/';
- $processed_upgrades = unserialize(datalist_get('processed_upgrades'));
- // the day we started the new upgrade names
- $upgrade_epoch = 2011021700;
+ $processed_upgrades = elgg_get_processed_upgrades();
+ // upgrading from 1.7 to 1.8. Need to bootstrap.
if (!$processed_upgrades) {
- $processed_upgrades = array();
- }
+ elgg_upgrade_bootstrap_17_to_18();
- $upgrades = array();
+ // grab accurate processed upgrades
+ $processed_upgrades = elgg_get_processed_upgrades();
+ }
$upgrade_files = elgg_get_upgrade_files($upgrade_path);
@@ -36,23 +36,7 @@ function upgrade_code($version, $quiet = FALSE) {
return false;
}
- // if before the new upgrade system, run through all upgrades and check
- // version number. After the upgrade epoch, pull run upgrades from db
- if ($version < $upgrade_epoch) {
- foreach ($upgrade_files as $upgrade_file) {
- $upgrade_version = elgg_get_upgrade_file_version($upgrade_file);
-
- if ($version < $upgrade_version) {
- $upgrades[] = $upgrade_file;
- } else {
- // set this upgrade as processed so that we don't run it again
- $processed_upgrades[] = $upgrade_file;
- }
- }
- } else {
- // add any upgrades that haven't been run to the upgrades list
- $upgrades = elgg_get_unprocessed_upgrades($upgrade_files, $processed_upgrades);
- }
+ $upgrades = elgg_get_unprocessed_upgrades($upgrade_files, $processed_upgrades);
// Sort and execute
sort($upgrades);
@@ -67,7 +51,7 @@ function upgrade_code($version, $quiet = FALSE) {
try {
if (!@include("$upgrade_path/$upgrade")) {
$success = false;
- error_log($e->getmessage());
+ error_log("Could not include $upgrade_path/$upgrade");
}
} catch (Exception $e) {
$success = false;
@@ -76,6 +60,7 @@ function upgrade_code($version, $quiet = FALSE) {
} else {
if (!include("$upgrade_path/$upgrade")) {
$success = false;
+ error_log("Could not include $upgrade_path/$upgrade");
}
}
@@ -84,13 +69,12 @@ function upgrade_code($version, $quiet = FALSE) {
$processed_upgrades[] = $upgrade;
// don't set the version to a lower number in instances where an upgrade
- // has been merged from a lower version
+ // has been merged from a lower version of Elgg
if ($upgrade_version > $version) {
datalist_set('version', $upgrade_version);
}
- $processed_upgrades = array_unique($processed_upgrades);
- datalist_set('processed_upgrades', serialize($processed_upgrades));
+ elgg_set_processed_upgrades($processed_upgrades);
} else {
return false;
}
@@ -100,6 +84,29 @@ function upgrade_code($version, $quiet = FALSE) {
}
/**
+ * Saves the processed upgrades to a dataset.
+ *
+ * @param array $processed_upgrades An array of processed upgrade filenames
+ * (not the path, just the file)
+ * @return bool
+ */
+function elgg_set_processed_upgrades(array $processed_upgrades) {
+ $processed_upgrades = array_unique($processed_upgrades);
+ return datalist_set('processed_upgrades', serialize($processed_upgrades));
+}
+
+/**
+ * Gets a list of processes upgrades
+ *
+ * @return mixed Array of processed upgrade filenames or false
+ */
+function elgg_get_processed_upgrades() {
+ $upgrades = datalist_get('processed_upgrades');
+ $unserialized = unserialize($upgrades);
+ return $unserialized;
+}
+
+/**
* Returns the version of the upgrade filename.
*
* @param string $filename The upgrade filename. No full path.
@@ -248,3 +255,46 @@ function version_upgrade() {
return false;
}
+
+/**
+ * Boot straps into 1.8 upgrade system from 1.7
+ *
+ * This runs all the 1.7 upgrades, then sets the processed_upgrades to all existing 1.7 upgrades.
+ * Control is then passed back to the main upgrade function which detects and runs the
+ * 1.8 upgrades, regardless of filename convention.
+ *
+ * @return bool
+ */
+function elgg_upgrade_bootstrap_17_to_18() {
+ $db_version = (int) datalist_get('version');
+
+ // the 1.8 upgrades before the upgrade system change that are interspersed with 1.7 upgrades.
+ $upgrades_18 = array(
+ '2010111501.php',
+ '2010121601.php',
+ '2010121602.php',
+ '2010121701.php',
+ '2010123101.php',
+ '2011010101.php',
+ );
+
+ $upgrades_17 = array();
+ $upgrade_files = elgg_get_upgrade_files();
+ $processed_upgrades = array();
+
+ foreach ($upgrade_files as $upgrade_file) {
+ // ignore if not in 1.7 format or if it's a 1.8 upgrade
+ if (in_array($upgrade_file, $upgrades_18) || !preg_match("/[0-9]{10}\.php/", $upgrade_file)) {
+ continue;
+ }
+
+ $upgrade_version = elgg_get_upgrade_file_version($upgrade_file);
+
+ // this has already been run in a previous 1.7.X -> 1.7.X upgrade
+ if ($upgrade_version < $db_version) {
+ $processed_upgrades[] = $upgrade_file;
+ }
+ }
+
+ return elgg_set_processed_upgrades($processed_upgrades);
+}
diff --git a/engine/lib/upgrades/2011010101.php b/engine/lib/upgrades/2011010101.php
index 9dbaff1e4..b063c249b 100644
--- a/engine/lib/upgrades/2011010101.php
+++ b/engine/lib/upgrades/2011010101.php
@@ -87,7 +87,10 @@ if ($upgrade_version > $version) {
datalist_set('version', $upgrade_version);
}
+// add ourselves to the processed_upgrades.
+$processed_upgrades[] = '2011010101.php';
+
$processed_upgrades = array_unique($processed_upgrades);
-datalist_set('processed_upgrades', serialize($processed_upgrades));
+elgg_set_processed_upgrades($processed_upgrades);
forward('upgrade.php');
diff --git a/engine/lib/users.php b/engine/lib/users.php
index 59bfa1259..e7e1a57f0 100644
--- a/engine/lib/users.php
+++ b/engine/lib/users.php
@@ -625,31 +625,37 @@ function get_user_by_email($email) {
/**
* A function that returns a maximum of $limit users who have done something within the last
- * $seconds seconds.
+ * $seconds seconds or the total count of active users.
*
* @param int $seconds Number of seconds (default 600 = 10min)
* @param int $limit Limit, default 10.
- * @param int $offset Offset, defualt 0.
+ * @param int $offset Offset, default 0.
+ * @param bool $count Count, default false.
*
* @return mixed
*/
-function find_active_users($seconds = 600, $limit = 10, $offset = 0) {
- global $CONFIG;
-
+function find_active_users($seconds = 600, $limit = 10, $offset = 0, $count = false) {
$seconds = (int)$seconds;
$limit = (int)$limit;
$offset = (int)$offset;
+ $params = array('seconds' => $seconds, 'limit' => $limit, 'offset' => $offset, 'count' => $count);
+ $data = elgg_trigger_plugin_hook('find_active_users', 'system', $params, NULL);
+ if (!$data) {
+ global $CONFIG;
- $time = time() - $seconds;
-
- $access = get_access_sql_suffix("e");
-
- $query = "SELECT distinct e.* from {$CONFIG->dbprefix}entities e
- join {$CONFIG->dbprefix}users_entity u on e.guid = u.guid
- where u.last_action >= {$time} and $access
- order by u.last_action desc limit {$offset}, {$limit}";
+ $time = time() - $seconds;
- return get_data($query, "entity_row_to_elggstar");
+ $data = elgg_get_entities(array(
+ 'type' => 'user',
+ 'limit' => $limit,
+ 'offset' => $offset,
+ 'count' => $count,
+ 'joins' => array("join {$CONFIG->dbprefix}users_entity u on e.guid = u.guid"),
+ 'wheres' => array("u.last_action >= {$time}"),
+ 'order_by' => "u.last_action desc"
+ ));
+ }
+ return $data;
}
/**
diff --git a/engine/lib/views.php b/engine/lib/views.php
index 45b2c35f8..7358fc0ba 100644
--- a/engine/lib/views.php
+++ b/engine/lib/views.php
@@ -950,9 +950,10 @@ function elgg_view_annotation(ElggAnnotation $annotation, array $vars = array(),
* 'offset' The current indexing offset
* 'limit' The number of entities to display per page
* 'full_view' Display the full view of the entities?
- * 'list_class' CSS Class applied to the list
+ * 'list_class' CSS class applied to the list
+ * 'item_class' CSS class applied to the list items
* 'pagination' Display pagination?
- * 'gallery' Display as gallery?
+ * 'list_type' List type: 'list' (default), 'gallery'
* 'list_type_toggle' Display the list type toggle?
*
* @return string The rendered list of entities
@@ -965,14 +966,21 @@ $list_type_toggle = true, $pagination = true) {
$offset = (int)get_input('offset', 0);
}
+ // list type can be passed as request parameter
+ $list_type = get_input('list_type', 'list');
+ if (get_input('listtype')) {
+ elgg_deprecated_notice("'listtype' has been deprecated by 'list_type' for lists", 1.8);
+ $list_type = get_input('listtype');
+ }
+
if (is_array($vars)) {
// new function
$defaults = array(
'items' => $entities,
- 'list_class' => 'elgg-entity-list',
+ 'list_class' => 'elgg-list-entity',
'full_view' => true,
'pagination' => true,
- 'gallery' => false,
+ 'list_type' => $list_type,
'list_type_toggle' => false,
'offset' => $offset,
);
@@ -990,18 +998,13 @@ $list_type_toggle = true, $pagination = true) {
'limit' => (int) $limit,
'full_view' => $full_view,
'pagination' => $pagination,
- 'gallery' => false,
+ 'list_type' => $list_type,
'list_type_toggle' => $list_type_toggle,
- 'list_class' => 'elgg-entity-list',
+ 'list_class' => 'elgg-list-entity',
);
}
- $listtype = get_input('listtype', 'list');
- if ($listtype != 'list') {
- $vars['gallery'] = true;
- }
-
- if ($vars['gallery']) {
+ if ($vars['list_type'] != 'list') {
return elgg_view('page/components/gallery', $vars);
} else {
return elgg_view('page/components/list', $vars);
@@ -1203,7 +1206,7 @@ function elgg_view_river_item($item, array $vars = array()) {
$vars['item'] = $item;
- return elgg_view('river/item', $vars);
+ return elgg_view($item->getView(), $vars);
}
/**