diff options
Diffstat (limited to 'engine')
30 files changed, 300 insertions, 119 deletions
diff --git a/engine/classes/ElggFile.php b/engine/classes/ElggFile.php index fe25491a8..f21621ffd 100644 --- a/engine/classes/ElggFile.php +++ b/engine/classes/ElggFile.php @@ -121,6 +121,47 @@ class ElggFile extends ElggObject { } /** + * Detects mime types based on filename or actual file. + * + * @param mixed $file The full path of the file to check. For uploaded files, use tmp_name. + * @param mixed $default A default. Useful to pass what the browser thinks it is. + * @since 1.7.12 + * + * @return mixed Detected type on success, false on failure. + */ + static function detectMimeType($file = null, $default = null) { + if (!$file) { + if (isset($this) && $this->filename) { + $file = $this->filename; + } else { + return false; + } + } + + $mime = false; + + // for PHP5 folks. + if (function_exists('finfo_file') && defined('FILEINFO_MIME_TYPE')) { + $resource = finfo_open(FILEINFO_MIME_TYPE); + if ($resource) { + $mime = finfo_file($resource, $file); + } + } + + // for everyone else. + if (!$mime && function_exists('mime_content_type')) { + $mime = mime_content_type($file); + } + + // default + if (!$mime) { + return $default; + } + + return $mime; + } + + /** * Set the optional file description. * * @param string $description The description. diff --git a/engine/classes/ElggPlugin.php b/engine/classes/ElggPlugin.php index d837431fc..4aee1e898 100644 --- a/engine/classes/ElggPlugin.php +++ b/engine/classes/ElggPlugin.php @@ -116,6 +116,21 @@ class ElggPlugin extends ElggObject { } /** + * Returns the manifest's name if available, otherwise the ID. + * + * @return string + * @since 1.8.1 + */ + public function getFriendlyName() { + $manifest = $this->getManifest(); + if ($manifest) { + return $manifest->getName(); + } + + return $this->getID(); + } + + /** * Returns the plugin's full path with trailing slash. * * @return string @@ -597,7 +612,12 @@ class ElggPlugin extends ElggObject { */ public function canActivate($site_guid = null) { if ($this->getPackage()) { - return $this->getPackage()->isValid() && $this->getPackage()->checkDependencies(); + $result = $this->getPackage()->isValid() && $this->getPackage()->checkDependencies(); + if (!$result) { + $this->errorMsg = $this->getPackage()->getError(); + } + + return $result; } return false; diff --git a/engine/classes/ElggPluginManifest.php b/engine/classes/ElggPluginManifest.php index 0f3b1d7a8..0e47f388d 100644 --- a/engine/classes/ElggPluginManifest.php +++ b/engine/classes/ElggPluginManifest.php @@ -224,20 +224,15 @@ class ElggPluginManifest { /** * Returns the plugin name * - * @param bool $elgg_echo Run the name through elgg_echo. * @return string */ - public function getName($elgg_echo = true) { + public function getName() { $name = $this->parser->getAttribute('name'); if (!$name && $this->pluginID) { $name = ucwords(str_replace('_', ' ', $this->pluginID)); } - if ($elgg_echo) { - $name = elgg_echo($name); - } - return $name; } @@ -245,33 +240,21 @@ class ElggPluginManifest { /** * Return the description * - * @param bool $elgg_echo Run the description through elgg_echo. * @return string */ - public function getDescription($elgg_echo = true) { - $desc = $this->parser->getAttribute('description'); - - if ($elgg_echo) { - return elgg_echo($desc); - } else { - return $desc; - } + public function getDescription() { + return $this->parser->getAttribute('description'); } /** * Return the short description * - * @param bool $elgg_echo Run the blurb through elgg_echo. * @return string */ - public function getBlurb($elgg_echo = true) { + public function getBlurb() { $blurb = $this->parser->getAttribute('blurb'); - if ($blurb) { - if ($elgg_echo) { - $blurb = elgg_echo($blurb); - } - } else { + if (!$blurb) { $blurb = elgg_get_excerpt($this->getDescription()); } @@ -348,10 +331,9 @@ class ElggPluginManifest { /** * Return the screenshots listed. * - * @param bool $elgg_echo Run the screenshot's description through elgg_echo. * @return array */ - public function getScreenshots($elgg_echo = true) { + public function getScreenshots() { $ss = $this->parser->getAttribute('screenshot'); if (!$ss) { @@ -360,13 +342,7 @@ class ElggPluginManifest { $normalized = array(); foreach ($ss as $s) { - $normalized_s = $this->buildStruct($this->screenshotStruct, $s); - - if ($elgg_echo) { - $normalized_s['description'] = elgg_echo($normalized_s['description']); - } - - $normalized[] = $normalized_s; + $normalized[] = $this->buildStruct($this->screenshotStruct, $s); } return $normalized; diff --git a/engine/classes/ElggPluginPackage.php b/engine/classes/ElggPluginPackage.php index 02b985285..145f71fcd 100644 --- a/engine/classes/ElggPluginPackage.php +++ b/engine/classes/ElggPluginPackage.php @@ -347,6 +347,7 @@ class ElggPluginPackage { $conflict['name'] = $plugin->getManifest()->getName(); if (!$full_report && !$result['status']) { + $this->errorMsg = "Conflicts with plugin \"{$plugin->getManifest()->getName()}\"."; return $result['status']; } else { $report[] = array( @@ -399,6 +400,7 @@ class ElggPluginPackage { // unless we're doing a full report, break as soon as we fail. if (!$full_report && !$result['status']) { + $this->errorMsg = "Missing dependencies."; return $result['status']; } else { // build report element and comment diff --git a/engine/handlers/cache_handler.php b/engine/handlers/cache_handler.php index 7d6f42dc3..94a0e64e9 100644 --- a/engine/handlers/cache_handler.php +++ b/engine/handlers/cache_handler.php @@ -64,7 +64,7 @@ $view = $matches[3]; switch ($type) { case 'css': header("Content-type: text/css", true); - header('Expires: ' . date('r', time() + 86400000), true); + header('Expires: ' . date('r', strtotime("+6 months")), true); header("Pragma: public", true); header("Cache-Control: public", true); @@ -72,7 +72,7 @@ switch ($type) { break; case 'js': header('Content-type: text/javascript', true); - header('Expires: ' . date('r', time() + 864000000), true); + header('Expires: ' . date('r', strtotime("+6 months")), true); header("Pragma: public", true); header("Cache-Control: public", true); diff --git a/engine/lib/access.php b/engine/lib/access.php index 6da747463..1fe21861d 100644 --- a/engine/lib/access.php +++ b/engine/lib/access.php @@ -776,7 +776,7 @@ function elgg_view_access_collections($owner_guid) { * access_id => int The access ID of the entity. * * @see elgg_get_entities() - * @return array + * @return mixed if count, int. if not count, array or false if no entities. false also on errors. * @since 1.7.0 */ function elgg_get_entities_from_access_id(array $options = array()) { diff --git a/engine/lib/annotations.php b/engine/lib/annotations.php index 80ffbe74e..14893aee6 100644 --- a/engine/lib/annotations.php +++ b/engine/lib/annotations.php @@ -285,14 +285,12 @@ function elgg_list_annotations($options) { */ /** - * Returns entities based upon annotations. Accepts the same values as - * elgg_get_entities_from_metadata() but uses the annotations table. + * Returns entities based upon annotations. Also accepts all options available + * to elgg_get_entities() and elgg_get_entities_from_metadata(). * - * NB: Entity creation time is selected as max_time. To sort based upon + * Entity creation time is selected as max_time. To sort based upon * this, pass 'order_by' => 'maxtime asc' || 'maxtime desc' * - * time_created in this case will be the time the annotation was created. - * * @see elgg_get_entities * @see elgg_get_entities_from_metadata * @@ -321,7 +319,7 @@ function elgg_list_annotations($options) { * * annotation_ids => NULL|ARR Annotation IDs * - * @return array + * @return mixed if count, int. if not count, array or false if no entities. false also on errors. * @since 1.7.0 */ function elgg_get_entities_from_annotations(array $options = array()) { diff --git a/engine/lib/configuration.php b/engine/lib/configuration.php index b756d2e70..3a2364057 100644 --- a/engine/lib/configuration.php +++ b/engine/lib/configuration.php @@ -464,11 +464,6 @@ function get_config($name, $site_guid = 0) { $dep_version = 1.8; break; - case 'wwwroot': - $new_name = 'www_root'; - $dep_version = 1.8; - break; - case 'sitename': $new_name = 'site_name'; $dep_version = 1.8; @@ -553,7 +548,7 @@ function set_default_config() { 'path' => "$install_root/", 'view_path' => "$install_root/views/", 'plugins_path' => "$install_root/mod/", - 'www_root' => $www_root, + 'wwwroot' => $www_root, 'url' => $www_root, 'site_name' => 'New Elgg site', 'language' => 'en', @@ -561,8 +556,6 @@ function set_default_config() { // compatibility with old names for ppl not using get_config() 'viewpath' => "$install_root/views/", 'pluginspath' => "$install_root/mod/", - 'wwwroot' => $www_root, - 'url' => $www_root, 'sitename' => 'New Elgg site', ); diff --git a/engine/lib/database.php b/engine/lib/database.php index 7747eb0d5..f12b50079 100644 --- a/engine/lib/database.php +++ b/engine/lib/database.php @@ -163,10 +163,17 @@ function db_delayedexecution_shutdown_hook() { global $DB_DELAYED_QUERIES; foreach ($DB_DELAYED_QUERIES as $query_details) { - // use one of our db functions so it is included in profiling. - $result = execute_query($query_details['q'], $query_details['l']); - try { + $link = $query_details['l']; + + if ($link == 'read' || $link == 'write') { + $link = get_db_link($link); + } elseif (!is_resource($link)) { + elgg_log("Link for delayed query not valid resource or db_link type. Query: {$query_details['q']}", 'WARNING'); + } + + $result = execute_query($query_details['q'], $link); + if ((isset($query_details['h'])) && (is_callable($query_details['h']))) { $query_details['h']($result); } @@ -272,7 +279,7 @@ function execute_query($query, $dblink) { * the raw result from {@link mysql_query()}. * * @param string $query The query to execute - * @param resource $dblink The database link to use + * @param resource $dblink The database link to use or the link type (read | write) * @param string $handler A callback function to pass the results array to * * @return true @@ -284,6 +291,10 @@ function execute_delayed_query($query, $dblink, $handler = "") { $DB_DELAYED_QUERIES = array(); } + if (!is_resource($dblink) && $dblink != 'read' && $dblink != 'write') { + return false; + } + // Construct delayed query $delayed_query = array(); $delayed_query['q'] = $query; @@ -306,7 +317,7 @@ function execute_delayed_query($query, $dblink, $handler = "") { * @uses get_db_link() */ function execute_delayed_write_query($query, $handler = "") { - return execute_delayed_query($query, get_db_link('write'), $handler); + return execute_delayed_query($query, 'write', $handler); } /** @@ -320,7 +331,7 @@ function execute_delayed_write_query($query, $handler = "") { * @uses get_db_link() */ function execute_delayed_read_query($query, $handler = "") { - return execute_delayed_query($query, get_db_link('read'), $handler); + return execute_delayed_query($query, 'read', $handler); } /** diff --git a/engine/lib/deprecated-1.8.php b/engine/lib/deprecated-1.8.php index f0f4bd9dc..beba7d2b7 100644 --- a/engine/lib/deprecated-1.8.php +++ b/engine/lib/deprecated-1.8.php @@ -2424,7 +2424,7 @@ $posted_max = 0, $pagination = true) { 'offset' => $offset, 'limit' => $limit, 'pagination' => $pagination, - 'list-class' => 'elgg-river-list', + 'list-class' => 'elgg-list-river', ); return elgg_view('page/components/list', $params); diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php index 8358b08ab..64bdf9276 100644 --- a/engine/lib/elgglib.php +++ b/engine/lib/elgglib.php @@ -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 = null) { +function elgg_register_external_file($type, $name, $url, $location, $priority = 500) { global $CONFIG; if (empty($name) || empty($url)) { @@ -291,7 +291,15 @@ function elgg_register_external_file($type, $name, $url, $location, $priority = elgg_bootstrap_externals_data_structure($type); $name = trim(strtolower($name)); + + // normalize bogus priorities, but allow empty, null, and false to be defaults. + if (!is_numeric($priority)) { + $priority = 500; + } + + // no negative priorities right now. $priority = max((int)$priority, 0); + $item = elgg_extract($name, $CONFIG->externals_map[$type]); if ($item) { @@ -2023,7 +2031,10 @@ function elgg_init() { elgg_register_js('elgg.userpicker', 'js/lib/userpicker.js'); elgg_register_js('elgg.friendspicker', 'js/lib/friends_picker.js'); elgg_register_js('jquery.easing', 'vendors/jquery/jquery.easing.1.3.packed.js'); + elgg_register_js('jquery.imgareaselect', 'vendors/jquery/jquery.imgareaselect-0.9.8/scripts/jquery.imgareaselect.min.js'); + elgg_register_css('jquery.imgareaselect', 'vendors/jquery/jquery.imgareaselect-0.9.8/css/imgareaselect-deprecated.css'); + // Trigger the shutdown:system event upon PHP shutdown. register_shutdown_function('_elgg_shutdown_hook'); diff --git a/engine/lib/entities.php b/engine/lib/entities.php index cea8af1da..927be4b1d 100644 --- a/engine/lib/entities.php +++ b/engine/lib/entities.php @@ -772,7 +772,7 @@ function elgg_entity_exists($guid) { * * callback => string A callback function to pass each row through * - * @return mixed int if count is true, an array of entity objects, or false on failure + * @return mixed if count, int. if not count, array or false if no entities. false also on errors. * @since 1.7.0 * @see elgg_get_entities_from_metadata() * @see elgg_get_entities_from_relationship() @@ -846,9 +846,6 @@ function elgg_get_entities(array $options = array()) { $wheres[] = elgg_get_entity_time_where_sql('e', $options['created_time_upper'], $options['created_time_lower'], $options['modified_time_upper'], $options['modified_time_lower']); - // remove identical where clauses - $wheres = array_unique($wheres); - // see if any functions failed // remove empty strings on successful functions foreach ($wheres as $i => $where) { @@ -859,6 +856,9 @@ function elgg_get_entities(array $options = array()) { } } + // remove identical where clauses + $wheres = array_unique($wheres); + // evaluate join clauses if (!is_array($options['joins'])) { $options['joins'] = array($options['joins']); @@ -1521,8 +1521,8 @@ function delete_entity($guid, $recursive = true) { $entity->deleteOwnedAnnotations(); $entity->deleteRelationships(); - remove_from_river_by_subject($guid); - remove_from_river_by_object($guid); + elgg_delete_river(array('subject_guid' => $guid)); + elgg_delete_river(array('object_guid' => $guid)); remove_all_private_settings($guid); $res = delete_data("DELETE from {$CONFIG->dbprefix}entities where guid={$guid}"); diff --git a/engine/lib/metadata.php b/engine/lib/metadata.php index a6b1bb43a..e5389df38 100644 --- a/engine/lib/metadata.php +++ b/engine/lib/metadata.php @@ -366,7 +366,6 @@ function elgg_enable_metadata(array $options) { * When in doubt, use name_value_pairs. * * @see elgg_get_entities - * @see elgg_get_entities_from_annotations * * @param array $options Array in format: * @@ -398,7 +397,7 @@ function elgg_enable_metadata(array $options) { * * metadata_owner_guids => NULL|ARR guids for metadata owners * - * @return array + * @return mixed if count, int. if not count, array or false if no entities. false also on errors. * @since 1.7.0 */ function elgg_get_entities_from_metadata(array $options = array()) { diff --git a/engine/lib/metastrings.php b/engine/lib/metastrings.php index d444121d0..8c00fb2ad 100644 --- a/engine/lib/metastrings.php +++ b/engine/lib/metastrings.php @@ -360,9 +360,6 @@ function elgg_get_metastring_based_objects($options) { $wheres[] = elgg_get_guid_based_where_sql('n_table.owner_guid', $options['metastring_owner_guids']); - // remove identical where clauses - $wheres = array_unique($wheres); - // see if any functions failed // remove empty strings on successful functions foreach ($wheres as $i => $where) { @@ -373,6 +370,9 @@ function elgg_get_metastring_based_objects($options) { } } + // remove identical where clauses + $wheres = array_unique($wheres); + // evaluate join clauses if (!is_array($options['joins'])) { $options['joins'] = array($options['joins']); diff --git a/engine/lib/navigation.php b/engine/lib/navigation.php index 0e9ec1c17..3f3a8ecd5 100644 --- a/engine/lib/navigation.php +++ b/engine/lib/navigation.php @@ -20,20 +20,20 @@ * Menus * Elgg uses a single interface to manage its menus. Menu items are added with * {@link elgg_register_menu_item()}. This is generally used for menus that - * appear only once per page. For context-sensitive menus (such as the hover + * appear only once per page. For dynamic menus (such as the hover * menu for user's avatar), a plugin hook is emitted when the menu is being * created. The hook is 'register', 'menu:<menu_name>'. For more details on this, * @see elgg_view_menu(). * * Menus supported by the Elgg core * Standard menus: - * site Site navihgation shown on every page. + * site Site navigation shown on every page. * page Page menu usually shown in a sidebar. Uses Elgg's context. * topbar Topbar menu shown on every page. The default has two sections. * footer Like the topbar but in the footer. * extras Links about content on the page. The RSS link is added to this. * - * Context-sensitive (also called just-in-time menus): + * Dynamic menus (also called just-in-time menus): * user_hover Avatar hover menu. The user entity is passed as a parameter. * entity The set of links shown in the summary of an entity. * river Links shown on river items. @@ -51,7 +51,7 @@ * * @warning Generally you should not use this in response to the plugin hook: * 'register', 'menu:<menu_name>'. If you do, you may end up with many incorrect - * links on a context-sensitive menu. + * links on a dynamic menu. * * @warning A menu item's name must be unique per menu. If more than one menu * item with the same name are registered, the last menu item takes priority. @@ -285,7 +285,9 @@ function elgg_site_menu_setup($hook, $type, $return, $params) { } $return['default'] = $featured; - $return['more'] = $registered; + if (count($registered) > 0) { + $return['more'] = $registered; + } } else { // no featured menu items set $max_display_items = 5; @@ -391,7 +393,7 @@ function elgg_annotation_menu_setup($hook, $type, $return, $params) { 'href' => $url, 'text' => "<span class=\"elgg-icon elgg-icon-delete\"></span>", 'confirm' => elgg_echo('deleteconfirm'), - 'text_encode' => false + 'encode_text' => false ); $return[] = ElggMenuItem::factory($options); } diff --git a/engine/lib/output.php b/engine/lib/output.php index 04c737062..9479fee53 100644 --- a/engine/lib/output.php +++ b/engine/lib/output.php @@ -215,6 +215,14 @@ function elgg_clean_vars(array $vars = array()) { unset($vars['internalid']); } + if (isset($vars['__ignoreInternalid'])) { + unset($vars['__ignoreInternalid']); + } + + if (isset($vars['__ignoreInternalname'])) { + unset($vars['__ignoreInternalname']); + } + return $vars; } diff --git a/engine/lib/plugins.php b/engine/lib/plugins.php index fd85ed9f0..365ef6fdf 100644 --- a/engine/lib/plugins.php +++ b/engine/lib/plugins.php @@ -978,7 +978,7 @@ function elgg_unset_all_plugin_settings($plugin_id = null) { * plugin_user_setting_name_value_pairs_operator => NULL|STR The operator to use for combining * (name = value) OPERATOR (name = value); default AND * - * @return mixed + * @return mixed int if count is true, an array of entity objects, or false on failure */ function elgg_get_entities_from_plugin_user_settings(array $options = array()) { // if they're passing it don't bother diff --git a/engine/lib/private_settings.php b/engine/lib/private_settings.php index e5e7b2213..d7d819e1c 100644 --- a/engine/lib/private_settings.php +++ b/engine/lib/private_settings.php @@ -38,7 +38,7 @@ * their own settings. * * - * @return array + * @return mixed int if count is true, an array of entity objects, or false on failure * @since 1.8.0 */ function elgg_get_entities_from_private_settings(array $options = array()) { diff --git a/engine/lib/relationships.php b/engine/lib/relationships.php index 9d5fd39b6..ede5ca1eb 100644 --- a/engine/lib/relationships.php +++ b/engine/lib/relationships.php @@ -235,6 +235,11 @@ function get_entity_relationships($guid, $inverse_relationship = FALSE) { /** * Return entities matching a given query joining against a relationship. + * Also accepts all options available to elgg_get_entities() and + * elgg_get_entities_from_metadata(). + * + * @see elgg_get_entities + * @see elgg_get_entities_from_metadata * * @param array $options Array in format: * @@ -244,7 +249,7 @@ function get_entity_relationships($guid, $inverse_relationship = FALSE) { * * inverse_relationship => BOOL Inverse the relationship * - * @return array + * @return mixed if count, int. if not count, array or false if no entities. false also on errors. * @since 1.7.0 */ function elgg_get_entities_from_relationship($options) { @@ -365,7 +370,7 @@ function elgg_list_entities_from_relationship(array $options = array()) { * * @param array $options An options array compatible with * elgg_get_entities_from_relationship() - * @return array + * @return mixed int if count is true, an array of entity objects, or false on failure * @since 1.8.0 */ function elgg_get_entities_from_relationship_count(array $options = array()) { diff --git a/engine/lib/river.php b/engine/lib/river.php index 64ddcfdc1..e283c0595 100644 --- a/engine/lib/river.php +++ b/engine/lib/river.php @@ -170,9 +170,6 @@ function elgg_delete_river(array $options = array()) { $wheres[] = "rv.posted <= {$options['posted_time_upper']}"; } - // remove identical where clauses - $wheres = array_unique($wheres); - // see if any functions failed // remove empty strings on successful functions foreach ($wheres as $i => $where) { @@ -183,6 +180,9 @@ function elgg_delete_river(array $options = array()) { } } + // remove identical where clauses + $wheres = array_unique($wheres); + $query = "DELETE rv.* FROM {$CONFIG->dbprefix}river rv "; // remove identical join clauses @@ -304,9 +304,6 @@ function elgg_get_river(array $options = array()) { } } - // remove identical where clauses - $wheres = array_unique($wheres); - // see if any functions failed // remove empty strings on successful functions foreach ($wheres as $i => $where) { @@ -317,6 +314,9 @@ function elgg_get_river(array $options = array()) { } } + // remove identical where clauses + $wheres = array_unique($wheres); + if (!$options['count']) { $query = "SELECT DISTINCT rv.* FROM {$CONFIG->dbprefix}river rv "; } else { @@ -378,7 +378,7 @@ function elgg_list_river(array $options = array()) { 'offset' => (int) max(get_input('offset', 0), 0), 'limit' => (int) max(get_input('limit', 20), 0), 'pagination' => TRUE, - 'list_class' => 'elgg-river', + 'list_class' => 'elgg-list-river elgg-river', // @todo remove elgg-river in Elgg 1.9 ); $options = array_merge($defaults, $options); diff --git a/engine/lib/tags.php b/engine/lib/tags.php index 1116d63f3..64feed5b2 100644 --- a/engine/lib/tags.php +++ b/engine/lib/tags.php @@ -184,9 +184,6 @@ function elgg_get_tags(array $options = array()) { $wheres[] = elgg_get_entity_time_where_sql('e', $options['created_time_upper'], $options['created_time_lower'], $options['modified_time_upper'], $options['modified_time_lower']); - // remove identical where clauses - $wheres = array_unique($wheres); - // see if any functions failed // remove empty strings on successful functions foreach ($wheres as $i => $where) { @@ -197,6 +194,8 @@ function elgg_get_tags(array $options = array()) { } } + // remove identical where clauses + $wheres = array_unique($wheres); $joins = $options['joins']; diff --git a/engine/lib/upgrade.php b/engine/lib/upgrade.php index dc3911062..dc1213187 100644 --- a/engine/lib/upgrade.php +++ b/engine/lib/upgrade.php @@ -160,7 +160,7 @@ function elgg_get_upgrade_files($upgrade_path = null) { } /** - * Get the current version information + * Get the current Elgg version information * * @param bool $humanreadable Whether to return a human readable version (default: false) * @@ -169,13 +169,18 @@ function elgg_get_upgrade_files($upgrade_path = null) { function get_version($humanreadable = false) { global $CONFIG; + static $version, $release; + if (isset($CONFIG->path)) { - if (include($CONFIG->path . "version.php")) { - return (!$humanreadable) ? $version : $release; + if (!isset($version) || !isset($release)) { + if (!include($CONFIG->path . "version.php")) { + return false; + } } + return (!$humanreadable) ? $version : $release; } - return FALSE; + return false; } /** diff --git a/engine/lib/upgrades/2011092500-1.8.0.1-forum_reply_river_view-5758ce8d86ac56ce.php b/engine/lib/upgrades/2011092500-1.8.0.1-forum_reply_river_view-5758ce8d86ac56ce.php new file mode 100644 index 000000000..3a9200b51 --- /dev/null +++ b/engine/lib/upgrades/2011092500-1.8.0.1-forum_reply_river_view-5758ce8d86ac56ce.php @@ -0,0 +1,12 @@ +<?php +/** + * Elgg 1.8.0.1 upgrade 2011092500 + * forum_reply_river_view + * + * The forum reply river view is in a new location in Elgg 1.8 + */ + +$query = "UPDATE {$CONFIG->dbprefix}river SET view='river/annotation/group_topic_post/reply', + action_type='reply' + WHERE view='river/forum/create' AND action_type='create'"; +update_data($query); diff --git a/engine/lib/users.php b/engine/lib/users.php index 36e137876..ce1b409f6 100644 --- a/engine/lib/users.php +++ b/engine/lib/users.php @@ -813,6 +813,7 @@ function validate_username($username) { if ( preg_match($blacklist, $username) ) { + // @todo error message needs work throw new RegistrationException(elgg_echo('registration:invalidchars')); } @@ -823,6 +824,7 @@ function validate_username($username) { for ($n = 0; $n < strlen($blacklist2); $n++) { if (strpos($username, $blacklist2[$n]) !== false) { $msg = elgg_echo('registration:invalidchars', array($blacklist2[$n], $blacklist2)); + $msg = htmlentities($msg, ENT_COMPAT, 'UTF-8'); throw new RegistrationException($msg); } } @@ -1222,12 +1224,14 @@ function elgg_user_hover_menu($hook, $type, $return, $params) { if ($user->isFriend()) { $url = "action/friends/remove?friend={$user->guid}"; $text = elgg_echo('friend:remove'); + $name = 'remove_friend'; } else { $url = "action/friends/add?friend={$user->guid}"; $text = elgg_echo('friend:add'); + $name = 'add_friend'; } $url = elgg_add_action_tokens_to_url($url); - $item = new ElggMenuItem('addfriend', $text, $url); + $item = new ElggMenuItem($name, $text, $url); $item->setSection('action'); $return[] = $item; } else { diff --git a/engine/lib/views.php b/engine/lib/views.php index 2f1661e83..a18118f32 100644 --- a/engine/lib/views.php +++ b/engine/lib/views.php @@ -411,19 +411,25 @@ function elgg_view($view, $vars = array(), $bypass = false, $debug = false, $vie } // internalname => name (1.8) - if (isset($vars['internalname']) && !isset($vars['name'])) { + if (isset($vars['internalname']) && !isset($vars['__ignoreInternalname']) && !isset($vars['name'])) { elgg_deprecated_notice('You should pass $vars[\'name\'] now instead of $vars[\'internalname\']', 1.8, 2); $vars['name'] = $vars['internalname']; $test=false; } elseif (isset($vars['name'])) { + if (!isset($vars['internalname'])) { + $vars['__ignoreInternalname'] = ''; + } $vars['internalname'] = $vars['name']; } // internalid => id (1.8) - if (isset($vars['internalid']) && !isset($vars['name'])) { + if (isset($vars['internalid']) && !isset($vars['__ignoreInternalid']) && !isset($vars['name'])) { elgg_deprecated_notice('You should pass $vars[\'id\'] now instead of $vars[\'internalid\']', 1.8, 2); $vars['id'] = $vars['internalid']; } elseif (isset($vars['id'])) { + if (!isset($vars['internalid'])) { + $vars['__ignoreInternalid'] = ''; + } $vars['internalid'] = $vars['id']; } @@ -703,9 +709,9 @@ function elgg_view_layout($layout_name, $vars = array()) { * * This function triggers a 'register', 'menu:<menu name>' plugin hook that enables * plugins to add menu items just before a menu is rendered. This is used by - * context-sensitive menus (menus that are specific to a particular entity such - * as the user hover menu). Using elgg_register_menu_item() in response to the hook - * can cause incorrect links to show up. See the blog plugin's blog_owner_block_menu() + * dynamic menus (menus that change based on some input such as the user hover + * menu). Using elgg_register_menu_item() in response to the hook can cause + * incorrect links to show up. See the blog plugin's blog_owner_block_menu() * for an example of using this plugin hook. * * An additional hook is the 'prepare', 'menu:<menu name>' which enables plugins @@ -718,8 +724,9 @@ function elgg_view_layout($layout_name, $vars = array()) { * @param array $vars An associative array of display options for the menu. * Options include: * sort_by => string or php callback - * string options: 'name', 'priority', 'title' (default), 'register' (registration order) - * php callback: a compare function for usort + * string options: 'name', 'priority', 'title' (default), + * 'register' (registration order) or a + * php callback (a compare function for usort) * handler: string the page handler to build action URLs * entity: ElggEntity to use to build action URLs * class: string the class for the entire menu. @@ -738,7 +745,7 @@ function elgg_view_menu($menu_name, array $vars = array()) { $menu = $CONFIG->menus[$menu_name]; // Give plugins a chance to add menu items just before creation. - // This supports context sensitive menus (ex. user_hover). + // This supports dynamic menus (example: user_hover). $menu = elgg_trigger_plugin_hook('register', "menu:$menu_name", $vars, $menu); $builder = new ElggMenuBuilder($menu); @@ -1038,7 +1045,7 @@ $list_type_toggle = true, $pagination = true) { function elgg_view_annotation_list($annotations, array $vars = array()) { $defaults = array( 'items' => $annotations, - 'list_class' => 'elgg-annotation-list', + 'list_class' => 'elgg-list-annotation elgg-annotation-list', // @todo remove elgg-annotation-list in Elgg 1.9 'full_view' => true, 'offset_key' => 'annoff', ); @@ -1547,6 +1554,7 @@ function elgg_views_boot() { elgg_register_simplecache_view('css/elgg'); elgg_register_simplecache_view('css/ie'); elgg_register_simplecache_view('css/ie6'); + elgg_register_simplecache_view('css/ie7'); elgg_register_simplecache_view('js/elgg'); elgg_register_js('jquery', '/vendors/jquery/jquery-1.6.2.min.js', 'head'); @@ -1568,7 +1576,7 @@ function elgg_views_boot() { elgg_register_css('lightbox', $lightbox_css_url); $elgg_css_url = elgg_get_simplecache_url('css', 'elgg'); - elgg_register_css('elgg', $elgg_css_url, 1); + elgg_register_css('elgg', $elgg_css_url); elgg_load_css('elgg'); elgg_register_plugin_hook_handler('output:before', 'layout', 'elgg_views_add_rss_link'); diff --git a/engine/tests/api/entity_getter_functions.php b/engine/tests/api/entity_getter_functions.php index aef7a991e..59b48999c 100644 --- a/engine/tests/api/entity_getter_functions.php +++ b/engine/tests/api/entity_getter_functions.php @@ -2789,4 +2789,13 @@ class ElggCoreEntityGetterFunctionsTest extends ElggCoreUnitTest { $this->assertEqual($a_e_map[$a->id], $a->owner_guid); } } + + public function testElggGetEntitiesBadWheres() { + $options = array( + 'container_guid' => 'abc' + ); + + $entities = elgg_get_entities($options); + $this->assertFalse($entities); + } } diff --git a/engine/tests/api/helpers.php b/engine/tests/api/helpers.php index ee2e64cfe..36d680d54 100644 --- a/engine/tests/api/helpers.php +++ b/engine/tests/api/helpers.php @@ -204,7 +204,7 @@ class ElggCoreHelpersTest extends ElggCoreUnitTest { $this->assertTrue($result); $js_urls = elgg_get_loaded_js('footer'); - $this->assertIdentical(array('http://test1.com'), $js_urls); + $this->assertIdentical(array(500 => 'http://test1.com'), $js_urls); } /** @@ -227,9 +227,10 @@ class ElggCoreHelpersTest extends ElggCoreUnitTest { } $js_urls = elgg_get_loaded_js('head'); - $this->assertIdentical($js_urls[0], $urls['id1']); - $this->assertIdentical($js_urls[1], $urls['id2']); - $this->assertIdentical($js_urls[2], $urls['id3']); + + $this->assertIdentical($js_urls[500], $urls['id1']); + $this->assertIdentical($js_urls[501], $urls['id2']); + $this->assertIdentical($js_urls[502], $urls['id3']); $js_urls = elgg_get_loaded_js('footer'); $this->assertIdentical(array(), $js_urls); diff --git a/engine/tests/api/plugins.php b/engine/tests/api/plugins.php index 00b0d4513..72092b688 100644 --- a/engine/tests/api/plugins.php +++ b/engine/tests/api/plugins.php @@ -215,18 +215,6 @@ class ElggCorePluginsAPITest extends ElggCoreUnitTest { $this->assertEqual($this->package17->getManifest()->getDescription(), 'A 1.7-style manifest.'); } - public function testElggPluginManifestGetDescriptionTranslated() { - $en = array( - $this->package18->getManifest()->getDescription() => 'A translated 1.8 description!', - $this->package17->getManifest()->getDescription() => 'A translated 1.7 description!', - ); - - add_translation('en', $en); - - $this->assertEqual($this->package18->getManifest()->getDescription(), 'A translated 1.8 description!'); - $this->assertEqual($this->package17->getManifest()->getDescription(), 'A translated 1.7 description!'); - } - public function testElggPluginManifestGetCategories() { $categories = array( 'Admin', 'ServiceAPI' diff --git a/engine/tests/regression/trac_bugs.php b/engine/tests/regression/trac_bugs.php index 6f98c67bd..23d6d1dc6 100644 --- a/engine/tests/regression/trac_bugs.php +++ b/engine/tests/regression/trac_bugs.php @@ -112,4 +112,91 @@ class ElggCoreRegressionBugsTest extends ElggCoreUnitTest { $this->assertEqual($params['xoffset'], $options['x1']); $this->assertEqual($params['yoffset'], $options['y1']); } + + // #3722 Check canEdit() works for contains regardless of groups + function test_can_write_to_container() { + $user = new ElggUser(); + $user->username = 'test_user_' . rand(); + $user->name = 'test_user_name_' . rand(); + $user->email = 'test@user.net'; + $user->container_guid = 0; + $user->owner_guid = 0; + $user->save(); + + $object = new ElggObject(); + $object->save(); + + $group = new ElggGroup(); + $group->save(); + + // disable access overrides because we're admin. + $ia = elgg_set_ignore_access(false); + + $this->assertFalse(can_write_to_container($user->guid, $object->guid)); + + global $elgg_test_user; + $elgg_test_user = $user; + + // register hook to allow access + function can_write_to_container_test_hook($hook, $type, $value, $params) { + global $elgg_test_user; + + if ($params['user']->getGUID() == $elgg_test_user->getGUID()) { + return true; + } + } + + register_plugin_hook('container_permissions_check', 'all', 'can_write_to_container_test_hook'); + $this->assertTrue(can_write_to_container($user->guid, $object->guid)); + unregister_plugin_hook('container_permissions_check', 'all', 'can_write_to_container_test_hook'); + + $this->assertFalse(can_write_to_container($user->guid, $group->guid)); + $group->join($user); + $this->assertTrue(can_write_to_container($user->guid, $group->guid)); + + elgg_set_ignore_access($ia); + + $user->delete(); + $object->delete(); + $group->delete(); + } + + function test_db_shutdown_links() { + global $DB_DELAYED_QUERIES, $test_results; + $DB_DELAYED_QUERIES = array(); + + function test_delayed_results($results) { + global $test_results; + $test_results = $results; + } + + $q = 'SELECT 1 as test'; + + $links = array('read', 'write', get_db_link('read'), get_db_link('write')); + + foreach ($links as $link) { + $DB_DELAYED_QUERIES = array(); + + $result = execute_delayed_query($q, $link, 'test_delayed_results'); + + $this->assertTrue($result, "Failed with link = $link"); + $this->assertEqual(count($DB_DELAYED_QUERIES), 1); + $this->assertEqual($DB_DELAYED_QUERIES[0]['q'], $q); + $this->assertEqual($DB_DELAYED_QUERIES[0]['l'], $link); + $this->assertEqual($DB_DELAYED_QUERIES[0]['h'], 'test_delayed_results'); + + db_delayedexecution_shutdown_hook(); + + $num_rows = mysql_num_rows($test_results); + $this->assertEqual($num_rows, 1); + $row = mysql_fetch_assoc($test_results); + $this->assertEqual($row['test'], 1); + } + + // test bad case + $DB_DELAYED_QUERIES = array(); + $result = execute_delayed_query($q, 'not_a_link', 'test_delayed_results'); + $this->assertFalse($result); + $this->assertEqual(array(), $DB_DELAYED_QUERIES); + } } diff --git a/engine/tests/suite.php b/engine/tests/suite.php index 8f2eb41a3..4203bc5d6 100644 --- a/engine/tests/suite.php +++ b/engine/tests/suite.php @@ -9,6 +9,8 @@ require_once(dirname( __FILE__ ) . '/../start.php'); +admin_gatekeeper(); + $vendor_path = "$CONFIG->path/vendors/simpletest"; $test_path = "$CONFIG->path/engine/tests"; |