aboutsummaryrefslogtreecommitdiff
path: root/engine/lib
diff options
context:
space:
mode:
authorBrett Profitt <brett.profitt@gmail.com>2011-08-25 10:00:38 -0700
committerBrett Profitt <brett.profitt@gmail.com>2011-08-25 10:00:38 -0700
commitdccc333c765bb28da55b4a55d9c916acdb88413a (patch)
treebdd26a0b4cd85241a19b7fcb2c0770f0ac3eb9f0 /engine/lib
parentec7b94a64aef23b85866ecdac8e8acc712d29bb6 (diff)
parent003cb81c7888f4d2fd763e5814027c6f8d71186f (diff)
downloadelgg-dccc333c765bb28da55b4a55d9c916acdb88413a.tar.gz
elgg-dccc333c765bb28da55b4a55d9c916acdb88413a.tar.bz2
Merge branch 'master' of github.com:brettp/Elgg
Diffstat (limited to 'engine/lib')
-rw-r--r--engine/lib/actions.php3
-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/elgglib.php130
-rw-r--r--engine/lib/entities.php9
-rw-r--r--engine/lib/group.php2
-rw-r--r--engine/lib/input.php5
-rw-r--r--engine/lib/navigation.php66
-rw-r--r--engine/lib/relationships.php33
-rw-r--r--engine/lib/river.php8
-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.php39
-rw-r--r--engine/lib/views.php92
16 files changed, 355 insertions, 171 deletions
diff --git a/engine/lib/actions.php b/engine/lib/actions.php
index ff598916f..4ccffd267 100644
--- a/engine/lib/actions.php
+++ b/engine/lib/actions.php
@@ -384,7 +384,8 @@ function actions_init() {
*/
function elgg_is_xhr() {
return isset($_SERVER['HTTP_X_REQUESTED_WITH'])
- && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest';
+ && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ||
+ get_input('X-Requested-With') === 'XMLHttpRequest';
}
/**
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/elgglib.php b/engine/lib/elgglib.php
index df78515f2..198ffe60c 100644
--- a/engine/lib/elgglib.php
+++ b/engine/lib/elgglib.php
@@ -167,12 +167,12 @@ function forward($location = "", $reason = 'system') {
* @param string $name An identifier for the JavaScript library
* @param string $url URL of the JavaScript file
* @param string $location Page location: head or footer. (default: head)
- * @param int $priority Priority of the CSS file (lower numbers load earlier)
+ * @param int $priority Priority of the JS file (lower numbers load earlier)
*
* @return bool
* @since 1.8.0
*/
-function elgg_register_js($name, $url, $location = 'head', $priority = 500) {
+function elgg_register_js($name, $url, $location = 'head', $priority = null) {
return elgg_register_external_file('js', $name, $url, $location, $priority);
}
@@ -225,7 +225,7 @@ function elgg_get_loaded_js($location = 'head') {
* @return bool
* @since 1.8.0
*/
-function elgg_register_css($name, $url, $priority = 500) {
+function elgg_register_css($name, $url, $priority = null) {
return elgg_register_external_file('css', $name, $url, 'head', $priority);
}
@@ -278,7 +278,7 @@ function elgg_get_loaded_css() {
* @return bool
* @since 1.8.0
*/
-function elgg_register_external_file($type, $name, $url, $location, $priority = 500) {
+function elgg_register_external_file($type, $name, $url, $location, $priority = null) {
global $CONFIG;
if (empty($name) || empty($url)) {
@@ -288,32 +288,36 @@ function elgg_register_external_file($type, $name, $url, $location, $priority =
$url = elgg_format_url($url);
$url = elgg_normalize_url($url);
- if (!isset($CONFIG->externals)) {
- $CONFIG->externals = array();
- }
-
- if (!isset($CONFIG->externals[$type])) {
- $CONFIG->externals[$type] = array();
- }
+ elgg_bootstrap_externals_data_structure($type);
$name = trim(strtolower($name));
-
- if (isset($CONFIG->externals[$type][$name])) {
- // update a registered item
- $item = $CONFIG->externals[$type][$name];
-
+ $priority = max((int)$priority, 0);
+ $item = elgg_extract($name, $CONFIG->externals_map[$type]);
+
+ if ($item) {
+ // updating a registered item
+ // don't update loaded because it could already be set
+ $item->url = $url;
+ $item->location = $location;
+
+ // if loaded before registered, that means it hasn't been added to the list yet
+ if ($CONFIG->externals[$type]->contains($item)) {
+ $priority = $CONFIG->externals[$type]->move($item, $priority);
+ } else {
+ $priority = $CONFIG->externals[$type]->add($item, $priority);
+ }
} else {
$item = new stdClass();
$item->loaded = false;
- }
+ $item->url = $url;
+ $item->location = $location;
- $item->url = $url;
- $item->priority = max((int)$priority, 0);
- $item->location = $location;
+ $priority = $CONFIG->externals[$type]->add($item, $priority);
+ }
- $CONFIG->externals[$type][$name] = $item;
+ $CONFIG->externals_map[$type][$name] = $item;
- return true;
+ return $priority !== false;
}
/**
@@ -328,19 +332,14 @@ function elgg_register_external_file($type, $name, $url, $location, $priority =
function elgg_unregister_external_file($type, $name) {
global $CONFIG;
- if (!isset($CONFIG->externals)) {
- return false;
- }
-
- if (!isset($CONFIG->externals[$type])) {
- return false;
- }
+ elgg_bootstrap_externals_data_structure($type);
$name = trim(strtolower($name));
-
- if (array_key_exists($name, $CONFIG->externals[$type])) {
- unset($CONFIG->externals[$type][$name]);
- return true;
+ $item = elgg_extract($name, $CONFIG->externals_map[$type]);
+
+ if ($item) {
+ unset($CONFIG->externals_map[$type][$name]);
+ return $CONFIG->externals[$type]->remove($item);
}
return false;
@@ -358,27 +357,23 @@ function elgg_unregister_external_file($type, $name) {
function elgg_load_external_file($type, $name) {
global $CONFIG;
- if (!isset($CONFIG->externals)) {
- $CONFIG->externals = array();
- }
-
- if (!isset($CONFIG->externals[$type])) {
- $CONFIG->externals[$type] = array();
- }
+ elgg_bootstrap_externals_data_structure($type);
$name = trim(strtolower($name));
- if (isset($CONFIG->externals[$type][$name])) {
+ $item = elgg_extract($name, $CONFIG->externals_map[$type]);
+
+ if ($item) {
// update a registered item
- $CONFIG->externals[$type][$name]->loaded = true;
+ $item->loaded = true;
} else {
$item = new stdClass();
$item->loaded = true;
$item->url = '';
$item->location = '';
- $item->priority = 500;
- $CONFIG->externals[$type][$name] = $item;
+ $priority = $CONFIG->externals[$type]->add($item);
+ $CONFIG->externals_map[$type][$name] = $item;
}
}
@@ -394,13 +389,12 @@ function elgg_load_external_file($type, $name) {
function elgg_get_loaded_external_files($type, $location) {
global $CONFIG;
- if (isset($CONFIG->externals) && isset($CONFIG->externals[$type])) {
- $items = array_values($CONFIG->externals[$type]);
+ if (isset($CONFIG->externals) && $CONFIG->externals[$type] instanceof ElggPriorityList) {
+ $items = $CONFIG->externals[$type]->getElements();
$callback = "return \$v->loaded == true && \$v->location == '$location';";
$items = array_filter($items, create_function('$v', $callback));
if ($items) {
- usort($items, create_function('$a,$b','return $a->priority >= $b->priority;'));
array_walk($items, create_function('&$v,$k', '$v = $v->url;'));
}
return $items;
@@ -409,6 +403,31 @@ function elgg_get_loaded_external_files($type, $location) {
}
/**
+ * Bootstraps the externals data structure in $CONFIG.
+ *
+ * @param string $type The type of external, js or css.
+ */
+function elgg_bootstrap_externals_data_structure($type) {
+ global $CONFIG;
+
+ if (!isset($CONFIG->externals)) {
+ $CONFIG->externals = array();
+ }
+
+ if (!$CONFIG->externals[$type] instanceof ElggPriorityList) {
+ $CONFIG->externals[$type] = new ElggPriorityList();
+ }
+
+ if (!isset($CONFIG->externals_map)) {
+ $CONFIG->externals_map = array();
+ }
+
+ if (!isset($CONFIG->externals_map[$type])) {
+ $CONFIG->externals_map[$type] = array();
+ }
+}
+
+/**
* Returns a list of files in $directory.
*
* Only returns files. Does not recurse into subdirs.
@@ -1678,17 +1697,26 @@ function elgg_normalise_plural_options_array($options, $singulars) {
* useful. Servers will hold pages until processing is done before sending
* them out to the browser.
*
+ * @see http://www.php.net/register-shutdown-function
+ *
* @return void
* @see register_shutdown_hook()
*/
function _elgg_shutdown_hook() {
global $START_MICROTIME;
- elgg_trigger_event('shutdown', 'system');
+ try {
+ elgg_trigger_event('shutdown', 'system');
- $time = (float)(microtime(TRUE) - $START_MICROTIME);
- // demoted to NOTICE from DEBUG so javascript is not corrupted
- elgg_log("Page {$_SERVER['REQUEST_URI']} generated in $time seconds", 'NOTICE');
+ $time = (float)(microtime(TRUE) - $START_MICROTIME);
+ // demoted to NOTICE from DEBUG so javascript is not corrupted
+ elgg_log("Page {$_SERVER['REQUEST_URI']} generated in $time seconds", 'NOTICE');
+ } catch (Exception $e) {
+ $message = 'Error: ' . get_class($e) . ' thrown within the shutdown handler. ';
+ $message .= "Message: '{$e->getMessage()}' in file {$e->getFile()} (line {$e->getLine()})";
+ error_log($message);
+ error_log("Exception trace stack: {$e->getTraceAsString()}");
+ }
}
/**
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/group.php b/engine/lib/group.php
index 755482b00..e7b70fd10 100644
--- a/engine/lib/group.php
+++ b/engine/lib/group.php
@@ -294,6 +294,7 @@ function group_gatekeeper($forward = true) {
* @param bool $default_on True if this option should be active by default
*
* @return void
+ * @since 1.5.0
*/
function add_group_tool_option($name, $label, $default_on = true) {
global $CONFIG;
@@ -319,6 +320,7 @@ function add_group_tool_option($name, $label, $default_on = true) {
* @param string $name Name of the group tool option
*
* @return void
+ * @since 1.7.5
*/
function remove_group_tool_option($name) {
global $CONFIG;
diff --git a/engine/lib/input.php b/engine/lib/input.php
index 84752bc7d..56ec214dc 100644
--- a/engine/lib/input.php
+++ b/engine/lib/input.php
@@ -10,8 +10,13 @@
/**
* Get some input from variables passed on the GET or POST line.
*
+ * If using any data obtained from get_input() in a web page, please be aware that
+ * it is a possible vector for a reflected XSS attack. If you are expecting an
+ * integer, cast it to an int. If it is a string, escape quotes.
+ *
* Note: this function does not handle nested arrays (ex: form input of param[m][n])
* because of the filtering done in htmlawed from the filter_tags call.
+ * @todo Is this ^ still?
*
* @param string $variable The variable we want to return.
* @param mixed $default A default value for the variable if it is not found.
diff --git a/engine/lib/navigation.php b/engine/lib/navigation.php
index b51c63b49..cefe40ecf 100644
--- a/engine/lib/navigation.php
+++ b/engine/lib/navigation.php
@@ -154,6 +154,44 @@ function elgg_is_menu_item_registered($menu_name, $item_name) {
}
/**
+ * Convenience function for registering a button to title menu
+ *
+ * The URL must be $handler/$name/$guid where $guid is the guid of the page owner.
+ * The label of the button is "$handler:$name" so that must be defined in a
+ * language file.
+ *
+ * This is used primarily to support adding an add content button
+ *
+ * @param string $handler The handler to use or null to autodetect from context
+ * @param string $name Name of the button
+ * @return void
+ * @since 1.8.0
+ */
+function elgg_register_title_button($handler = null, $name = 'add') {
+ if (elgg_is_logged_in()) {
+
+ if (!$handler) {
+ $handler = elgg_get_context();
+ }
+
+ $owner = elgg_get_page_owner_entity();
+ if (!$owner) {
+ // no owns the page so this is probably an all site list page
+ $owner = elgg_get_logged_in_user_entity();
+ }
+ if ($owner && $owner->canWriteToContainer()) {
+ $guid = $owner->getGUID();
+ elgg_register_menu_item('title', array(
+ 'name' => $name,
+ 'href' => "$handler/$name/$guid",
+ 'text' => elgg_echo("$handler:$name"),
+ 'link_class' => 'elgg-button elgg-button-action',
+ ));
+ }
+ }
+}
+
+/**
* Adds a breadcrumb to the breadcrumbs stack.
*
* @param string $title The title to display
@@ -276,7 +314,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",
+ 'rel' => 'toggle',
'priority' => 50,
);
$return[] = ElggMenuItem::factory($options);
@@ -335,12 +373,38 @@ function elgg_entity_menu_setup($hook, $type, $return, $params) {
}
/**
+ * Adds a delete link to "generic_comment" annotations
+ */
+function elgg_annotation_menu_setup($hook, $type, $return, $params) {
+ $annotation = $params['annotation'];
+
+ if ($annotation->name == 'generic_comment' && $annotation->canEdit()) {
+ $url = elgg_http_add_url_query_elements('action/comments/delete', array(
+ 'annotation_id' => $annotation->id,
+ ));
+
+ $options = array(
+ 'name' => 'delete',
+ 'href' => $url,
+ 'text' => "<span class=\"elgg-icon elgg-icon-delete\"></span>",
+ 'confirm' => elgg_echo('deleteconfirm'),
+ 'text_encode' => false
+ );
+ $return[] = ElggMenuItem::factory($options);
+ }
+
+ return $return;
+}
+
+
+/**
* Navigation initialization
*/
function elgg_nav_init() {
elgg_register_plugin_hook_handler('prepare', 'menu:site', 'elgg_site_menu_setup');
elgg_register_plugin_hook_handler('register', 'menu:river', 'elgg_river_menu_setup');
elgg_register_plugin_hook_handler('register', 'menu:entity', 'elgg_entity_menu_setup');
+ elgg_register_plugin_hook_handler('register', 'menu:annotation', 'elgg_annotation_menu_setup');
}
elgg_register_event_handler('init', 'system', 'elgg_nav_init');
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/river.php b/engine/lib/river.php
index 36dde7f05..64ddcfdc1 100644
--- a/engine/lib/river.php
+++ b/engine/lib/river.php
@@ -185,6 +185,9 @@ function elgg_delete_river(array $options = array()) {
$query = "DELETE rv.* FROM {$CONFIG->dbprefix}river rv ";
+ // remove identical join clauses
+ $joins = array_unique($options['joins']);
+
// add joins
foreach ($joins as $j) {
$query .= " $j ";
@@ -469,7 +472,7 @@ function elgg_get_river_type_subtype_where_sql($table, $types, $subtypes, $pairs
}
if (is_array($wheres) && count($wheres)) {
- $wheres = array(implode(' AND ', $wheres));
+ $wheres = array(implode(' OR ', $wheres));
}
} else {
// using type/subtype pairs
@@ -589,10 +592,13 @@ function elgg_river_page_handler($page) {
elgg_set_page_owner_guid(elgg_get_logged_in_user_guid());
+ // make a URL segment available in page handler script
$page_type = elgg_extract(0, $page, 'all');
+ $page_type = preg_replace('[\W]', '', $page_type);
if ($page_type == 'owner') {
$page_type = 'mine';
}
+ set_input('page_type', $page_type);
// content filter code here
$entity_type = '';
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..48f10f974 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");
+ $time = time() - $seconds;
- $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}";
-
- 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;
}
/**
@@ -1377,7 +1383,10 @@ function elgg_profile_fields_setup() {
function elgg_avatar_page_handler($page) {
global $CONFIG;
- set_input('username', $page[1]);
+ $user = get_user_by_username($page[1]);
+ if ($user) {
+ elgg_set_page_owner_guid($user->getGUID());
+ }
if ($page[0] == 'edit') {
require_once("{$CONFIG->path}pages/avatar/edit.php");
diff --git a/engine/lib/views.php b/engine/lib/views.php
index 45b2c35f8..fe3265347 100644
--- a/engine/lib/views.php
+++ b/engine/lib/views.php
@@ -309,6 +309,11 @@ function elgg_view_exists($view, $viewtype = '', $recurse = true) {
}
}
+ // Now check if the default view exists if the view is registered as a fallback
+ if ($viewtype != 'default' && elgg_does_viewtype_fallback($viewtype)) {
+ return elgg_view_exists($view, 'default');
+ }
+
return false;
}
@@ -950,9 +955,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 +971,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 +1003,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);
@@ -1073,21 +1081,24 @@ function elgg_view_entity_annotations(ElggEntity $entity, $full_view = true) {
}
/**
- * Returns a rendered title.
+ * Renders a title.
*
* This is a shortcut for {@elgg_view page/elements/title}.
*
- * @param string $title The page title
- * @param string $submenu Should a submenu be displayed? (deprecated)
+ * @param string $title The page title
+ * @param string $vars View variables (was submenu be displayed? (deprecated))
*
* @return string The HTML (etc)
*/
-function elgg_view_title($title, $submenu = false) {
- if ($submenu !== false) {
+function elgg_view_title($title, $vars = array()) {
+ if (!is_array($vars)) {
elgg_deprecated_notice('setting $submenu in elgg_view_title() is deprecated', 1.8);
+ $vars = array('submenu' => $vars);
}
- return elgg_view('page/elements/title', array('title' => $title, 'submenu' => $submenu));
+ $vars['title'] = $title;
+
+ return elgg_view('page/elements/title', $vars);
}
/**
@@ -1203,7 +1214,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);
}
/**
@@ -1469,21 +1480,6 @@ function autoregister_views($view_base, $folder, $base_location_path, $viewtype)
}
/**
- * Add the core Elgg head elements that could be cached
- *
- * @return void
- */
-function elgg_views_register_core_head_elements() {
- $url = elgg_get_simplecache_url('js', 'elgg');
- elgg_register_js('elgg', $url, 'head', 10);
- elgg_load_js('elgg');
-
- $url = elgg_get_simplecache_url('css', 'elgg');
- elgg_register_css('elgg', $url, 10);
- elgg_load_css('elgg');
-}
-
-/**
* Add the rss link to the extras when if needed
*
* @return void
@@ -1509,6 +1505,19 @@ function elgg_views_add_rss_link() {
}
/**
+ * Registers deprecated views to avoid making some pages from older plugins
+ * completely empty.
+ *
+ * @private
+ */
+function elgg_views_handle_deprecated_views() {
+ $location = elgg_get_view_location('page_elements/contentwrapper');
+ if ($location === "/var/www/views/") {
+ elgg_extend_view('page_elements/contentwrapper', 'page/elements/wrapper');
+ }
+}
+
+/**
* Initialize viewtypes on system boot event
* This ensures simplecache is cleared during upgrades. See #2252
*
@@ -1524,12 +1533,17 @@ function elgg_views_boot() {
elgg_register_simplecache_view('css/ie6');
elgg_register_simplecache_view('js/elgg');
- elgg_register_js('jquery', '/vendors/jquery/jquery-1.5.min.js', 'head', 1);
- elgg_register_js('jquery-ui', '/vendors/jquery/jquery-ui-1.8.9.min.js', 'head', 2);
+ elgg_register_js('jquery', '/vendors/jquery/jquery-1.6.2.min.js', 'head');
+ elgg_register_js('jquery-ui', '/vendors/jquery/jquery-ui-1.8.16.min.js', 'head');
elgg_register_js('jquery.form', '/vendors/jquery/jquery.form.js');
+
+ $elgg_js_url = elgg_get_simplecache_url('js', 'elgg');
+ elgg_register_js('elgg', $elgg_js_url, 'head');
+
elgg_load_js('jquery');
elgg_load_js('jquery-ui');
elgg_load_js('jquery.form');
+ elgg_load_js('elgg');
elgg_register_simplecache_view('js/lightbox');
$lightbox_js_url = elgg_get_simplecache_url('js', 'lightbox');
@@ -1537,7 +1551,10 @@ function elgg_views_boot() {
$lightbox_css_url = 'vendors/jquery/fancybox/jquery.fancybox-1.3.4.css';
elgg_register_css('lightbox', $lightbox_css_url);
- elgg_register_event_handler('ready', 'system', 'elgg_views_register_core_head_elements');
+ $elgg_css_url = elgg_get_simplecache_url('css', 'elgg');
+ elgg_register_css('elgg', $elgg_css_url, 1);
+ elgg_load_css('elgg');
+
elgg_register_event_handler('pagesetup', 'system', 'elgg_views_add_rss_link');
// discover the built-in view types
@@ -1554,3 +1571,4 @@ function elgg_views_boot() {
}
elgg_register_event_handler('boot', 'system', 'elgg_views_boot', 1000);
+elgg_register_event_handler('init', 'system', 'elgg_views_handle_deprecated_views');