diff options
Diffstat (limited to 'engine/lib')
-rw-r--r-- | engine/lib/access.php | 7 | ||||
-rw-r--r-- | engine/lib/admin.php | 12 | ||||
-rw-r--r-- | engine/lib/annotations.php | 4 | ||||
-rw-r--r-- | engine/lib/cron.php | 7 | ||||
-rw-r--r-- | engine/lib/database.php | 12 | ||||
-rw-r--r-- | engine/lib/deprecated-1.8.php | 37 | ||||
-rw-r--r-- | engine/lib/elgglib.php | 42 | ||||
-rw-r--r-- | engine/lib/entities.php | 50 | ||||
-rw-r--r-- | engine/lib/input.php | 12 | ||||
-rw-r--r-- | engine/lib/location.php | 2 | ||||
-rw-r--r-- | engine/lib/metadata.php | 2 | ||||
-rw-r--r-- | engine/lib/metastrings.php | 2 | ||||
-rw-r--r-- | engine/lib/navigation.php | 8 | ||||
-rw-r--r-- | engine/lib/pagehandler.php | 68 | ||||
-rw-r--r-- | engine/lib/plugins.php | 2 | ||||
-rw-r--r-- | engine/lib/private_settings.php | 2 | ||||
-rw-r--r-- | engine/lib/relationships.php | 8 | ||||
-rw-r--r-- | engine/lib/river.php | 32 | ||||
-rw-r--r-- | engine/lib/tags.php | 30 | ||||
-rw-r--r-- | engine/lib/user_settings.php | 14 | ||||
-rw-r--r-- | engine/lib/users.php | 104 | ||||
-rw-r--r-- | engine/lib/views.php | 15 |
22 files changed, 255 insertions, 217 deletions
diff --git a/engine/lib/access.php b/engine/lib/access.php index 002413baa..08b9283cd 100644 --- a/engine/lib/access.php +++ b/engine/lib/access.php @@ -610,8 +610,7 @@ function delete_access_collection($collection_id) { WHERE id = {$collection_id}"; $result = delete_data($q); - - return $result; + return (bool)$result; } /** @@ -718,7 +717,7 @@ function remove_user_from_access_collection($user_guid, $collection_id) { WHERE access_collection_id = {$collection_id} AND user_guid = {$user_guid}"; - return delete_data($q); + return (bool)delete_data($q); } /** @@ -792,7 +791,7 @@ function get_members_of_access_collection($collection, $idonly = FALSE) { * access_id => int The access ID of the entity. * * @see elgg_get_entities() - * @return mixed if count, int. if not count, array. false on errors. + * @return mixed If count, int. If not count, array. false on errors. * @since 1.7.0 */ function elgg_get_entities_from_access_id(array $options = array()) { diff --git a/engine/lib/admin.php b/engine/lib/admin.php index ae6429baf..3baf2ff61 100644 --- a/engine/lib/admin.php +++ b/engine/lib/admin.php @@ -314,7 +314,7 @@ function admin_init() { // automatic adding of widgets for admin elgg_register_event_handler('make_admin', 'user', 'elgg_add_admin_widgets'); - elgg_register_page_handler('admin', 'admin_settings_page_handler'); + elgg_register_page_handler('admin', 'admin_page_handler'); elgg_register_page_handler('admin_plugin_screenshot', 'admin_plugin_screenshot_page_handler'); elgg_register_page_handler('admin_plugin_text_file', 'admin_markdown_page_handler'); } @@ -427,10 +427,10 @@ function admin_pagesetup() { * * @param array $page Array of pages * - * @return void + * @return bool * @access private */ -function admin_settings_page_handler($page) { +function admin_page_handler($page) { admin_gatekeeper(); elgg_admin_add_plugin_settings_menu(); @@ -478,6 +478,7 @@ function admin_settings_page_handler($page) { $body = elgg_view_layout('admin', array('content' => $content, 'title' => $title)); echo elgg_view_page($title, $body, 'admin'); + return true; } /** @@ -485,7 +486,7 @@ function admin_settings_page_handler($page) { * admin_plugin_screenshot/<plugin_id>/<size>/<ss_name>.<ext> * * @param array $pages The pages array - * @return true + * @return bool * @access private */ function admin_plugin_screenshot_page_handler($pages) { @@ -524,7 +525,6 @@ function admin_plugin_screenshot_page_handler($pages) { echo file_get_contents($file); break; } - return true; } @@ -541,6 +541,7 @@ function admin_plugin_screenshot_page_handler($pages) { * * LICENSE.txt * * @param type $page + * @return bool * @access private */ function admin_markdown_page_handler($pages) { @@ -596,6 +597,7 @@ function admin_markdown_page_handler($pages) { )); echo elgg_view_page($title, $body, 'admin'); + return true; } /** diff --git a/engine/lib/annotations.php b/engine/lib/annotations.php index 66c6454c3..e40ab2e39 100644 --- a/engine/lib/annotations.php +++ b/engine/lib/annotations.php @@ -320,7 +320,7 @@ function elgg_list_annotations($options) { * * annotation_ids => NULL|ARR Annotation IDs * - * @return mixed if count, int. if not count, array or false if no entities. false also on errors. + * @return mixed If count, int. If not count, array. false on errors. * @since 1.7.0 */ function elgg_get_entities_from_annotations(array $options = array()) { @@ -397,7 +397,7 @@ function elgg_list_entities_from_annotations($options = array()) { * 'metadata_names' => The name of metadata on the entity. * 'metadata_values' => The value of metadata on the entitiy. * - * @return mixed + * @return mixed If count, int. If not count, array. false on errors. */ function elgg_get_entities_from_annotation_calculation($options) { $db_prefix = elgg_get_config('dbprefix'); diff --git a/engine/lib/cron.php b/engine/lib/cron.php index 8c0b62a53..f7a032f4a 100644 --- a/engine/lib/cron.php +++ b/engine/lib/cron.php @@ -25,7 +25,7 @@ function cron_init() { * * @param array $page Pages * - * @return void + * @return bool * @access private */ function cron_page_handler($page) { @@ -50,10 +50,6 @@ function cron_page_handler($page) { $params = array(); $params['time'] = time(); - foreach ($CONFIG->input as $k => $v) { - $params[$k] = $v; - } - // Data to return to $std_out = ""; $old_stdout = ""; @@ -63,6 +59,7 @@ function cron_page_handler($page) { $std_out = ob_get_clean(); echo $std_out . $old_stdout; + return true; } /** diff --git a/engine/lib/database.php b/engine/lib/database.php index b5ad7897f..c44fdf1fd 100644 --- a/engine/lib/database.php +++ b/engine/lib/database.php @@ -400,11 +400,10 @@ function get_data_row($query, $callback = "") { function elgg_query_runner($query, $callback = null, $single = false) { global $CONFIG, $DB_QUERY_CACHE; - $query = elgg_format_query($query); - - // since we want to cache results of running the callback, we need to - // need to namespace the query with the callback, and single result request. - $hash = (string)$callback . (string)$single . $query; + // Since we want to cache results of running the callback, we need to + // need to namespace the query with the callback and single result request. + // http://trac.elgg.org/ticket/4049 + $hash = (string)$callback . (int)$single . $query; // Is cached? if ($DB_QUERY_CACHE) { @@ -466,7 +465,6 @@ function elgg_query_runner($query, $callback = null, $single = false) { function insert_data($query) { global $CONFIG, $DB_QUERY_CACHE; - $query = elgg_format_query($query); elgg_log("DB query $query", 'NOTICE'); $dblink = get_db_link('write'); @@ -498,7 +496,6 @@ function insert_data($query) { function update_data($query) { global $CONFIG, $DB_QUERY_CACHE; - $query = elgg_format_query($query); elgg_log("DB query $query", 'NOTICE'); $dblink = get_db_link('write'); @@ -529,7 +526,6 @@ function update_data($query) { function delete_data($query) { global $CONFIG, $DB_QUERY_CACHE; - $query = elgg_format_query($query); elgg_log("DB query $query", 'NOTICE'); $dblink = get_db_link('write'); diff --git a/engine/lib/deprecated-1.8.php b/engine/lib/deprecated-1.8.php index beba7d2b7..e1866498b 100644 --- a/engine/lib/deprecated-1.8.php +++ b/engine/lib/deprecated-1.8.php @@ -4735,3 +4735,40 @@ function remove_from_river_by_id($id) { return elgg_delete_river(array('id' => $id)); } + +/** + * A default page handler + * Tries to locate a suitable file to include. Only works for core pages, not plugins. + * + * @param array $page The page URL elements + * @param string $handler The base handler + * + * @return true|false Depending on success + * @deprecated 1.8 + */ +function default_page_handler($page, $handler) { + global $CONFIG; + + elgg_deprecated_notice("default_page_handler is deprecated", "1.8"); + + $page = implode('/', $page); + + // protect against including arbitary files + $page = str_replace("..", "", $page); + + $callpath = $CONFIG->path . $handler . "/" . $page; + if (is_dir($callpath)) { + $callpath = sanitise_filepath($callpath); + $callpath .= "index.php"; + if (file_exists($callpath)) { + if (include($callpath)) { + return TRUE; + } + } + } else if (file_exists($callpath)) { + include($callpath); + return TRUE; + } + + return FALSE; +} diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php index 66268cc96..57d602450 100644 --- a/engine/lib/elgglib.php +++ b/engine/lib/elgglib.php @@ -107,7 +107,10 @@ function elgg_load_library($name) { } if (!include_once($CONFIG->libraries[$name])) { - $error = elgg_echo('InvalidParameterException:LibraryNotRegistered', array($name)); + $error = elgg_echo('InvalidParameterException:LibraryNotFound', array( + $name, + $CONFIG->libraries[$name]) + ); throw new InvalidParameterException($error); } } @@ -1475,8 +1478,12 @@ function elgg_http_url_is_identical($url1, $url2, $ignore_params = array('offset $url1_info = parse_url($url1); $url2_info = parse_url($url2); - $url1_info['path'] = trim($url1_info['path'], '/'); - $url2_info['path'] = trim($url2_info['path'], '/'); + if (isset($url1_info['path'])) { + $url1_info['path'] = trim($url1_info['path'], '/'); + } + if (isset($url2_info['path'])) { + $url2_info['path'] = trim($url2_info['path'], '/'); + } // compare basic bits $parts = array('scheme', 'host', 'path'); @@ -1740,7 +1747,7 @@ function _elgg_shutdown_hook() { * * @param array $page The page array * - * @return void + * @return bool * @elgg_pagehandler js * @access private */ @@ -1755,7 +1762,7 @@ function elgg_js_page_handler($page) { * * @param array $page The page array * - * @return void + * @return bool * @elgg_pagehandler ajax * @access private */ @@ -1776,9 +1783,9 @@ function elgg_ajax_page_handler($page) { } echo elgg_view($view, $vars); + return true; } - - return true; + return false; } /** @@ -1809,7 +1816,7 @@ function elgg_css_page_handler($page) { * @param array $page The page array * @param string $type The type: js or css * - * @return mixed + * @return bool * @access private */ function elgg_cacheable_view_page_handler($page, $type) { @@ -1850,9 +1857,8 @@ function elgg_cacheable_view_page_handler($page, $type) { //header("Content-Length: " . strlen($return)); echo $return; + return true; } - - return true; } /** @@ -1886,6 +1892,8 @@ function elgg_sql_reverse_order_by_clause($order_by) { * * Used as a callback for ElggBatch. * + * @todo why aren't these static methods on ElggBatch? + * * @param object $object The object to enable * @return bool * @access private @@ -1990,10 +1998,12 @@ function elgg_is_valid_options_for_batch_operation($options, $type) { function elgg_walled_garden_index() { elgg_register_css('elgg.walled_garden', '/css/walled_garden.css'); elgg_load_css('elgg.walled_garden'); + elgg_register_js('elgg.walled_garden', '/js/walled_garden.js'); + elgg_load_js('elgg.walled_garden'); - $login = elgg_view('core/account/login_walled_garden'); + $body = elgg_view('core/walled_garden/body'); - echo elgg_view_page('', $login, 'walled_garden'); + echo elgg_view_page('', $body, 'walled_garden'); // return true to prevent other plugins from adding a front page return true; @@ -2041,12 +2051,12 @@ function elgg_init() { elgg_register_page_handler('css', 'elgg_css_page_handler'); elgg_register_page_handler('ajax', 'elgg_ajax_page_handler'); - elgg_register_js('elgg.autocomplete', 'js/lib/autocomplete.js'); + elgg_register_js('elgg.autocomplete', 'js/lib/ui.autocomplete.js'); elgg_register_js('jquery.ui.autocomplete.html', 'vendors/jquery/jquery.ui.autocomplete.html.js'); - elgg_register_js('elgg.userpicker', 'js/lib/userpicker.js'); - elgg_register_js('elgg.friendspicker', 'js/lib/friends_picker.js'); + elgg_register_js('elgg.userpicker', 'js/lib/ui.userpicker.js'); + elgg_register_js('elgg.friendspicker', 'js/lib/ui.friends_picker.js'); elgg_register_js('jquery.easing', 'vendors/jquery/jquery.easing.1.3.packed.js'); - elgg_register_js('elgg.avatar_cropper', 'js/lib/avatar_cropper.js'); + elgg_register_js('elgg.avatar_cropper', 'js/lib/ui.avatar_cropper.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'); diff --git a/engine/lib/entities.php b/engine/lib/entities.php index fcd4544bf..f7ae108ed 100644 --- a/engine/lib/entities.php +++ b/engine/lib/entities.php @@ -124,8 +124,6 @@ function retrieve_cached_entity_row($guid) { * @internal Subtypes are stored in the entity_subtypes table. There is a foreign * key in the entities table. * - * @todo Move to a nicer place? - * * @param string $type Type * @param string $subtype Subtype * @@ -144,7 +142,7 @@ function get_subtype_id($type, $subtype) { return FALSE; } - // Todo: cache here? Or is looping less efficient that going to the db each time? + // @todo use the cache before hitting database $result = get_data_row("SELECT * from {$CONFIG->dbprefix}entity_subtypes where type='$type' and subtype='$subtype'"); @@ -163,8 +161,6 @@ function get_subtype_id($type, $subtype) { /** * Return string name for a given subtype ID. * - * @todo Move to a nicer place? - * * @param int $subtype_id Subtype ID * * @return string Subtype name @@ -199,11 +195,11 @@ function get_subtype_from_id($subtype_id) { } /** - * Return a classname for a registered type and subtype. + * Return the class name for a registered type and subtype. * * Entities can be registered to always be loaded as a certain class - * with {@link register_entity_subtype()}. This function returns - * the class name if found, and NULL if not. + * with add_subtype() or update_subtype(). This function returns the class + * name if found and NULL if not. * * @param string $type The type * @param string $subtype The subtype @@ -219,7 +215,7 @@ function get_subtype_class($type, $subtype) { $type = sanitise_string($type); $subtype = sanitise_string($subtype); - // Todo: cache here? Or is looping less efficient that going to the db each time? + // @todo use the cache before going to the database $result = get_data_row("SELECT * from {$CONFIG->dbprefix}entity_subtypes where type='$type' and subtype='$subtype'"); @@ -236,7 +232,7 @@ function get_subtype_class($type, $subtype) { } /** - * Returns the classname for a subtype id. + * Returns the class name for a subtype id. * * @param int $subtype_id The subtype id * @@ -279,6 +275,9 @@ function get_subtype_class_from_id($subtype_id) { * it will be loaded as that class automatically when retrieved from the database with * {@link get_entity()}. * + * @warning This function cannot be used to change the class for a type-subtype pair. + * Use update_subtype() for that. + * * @param string $type The type you're subtyping (site, user, object, or group) * @param string $subtype The subtype * @param string $class Optional class name for the object @@ -410,7 +409,7 @@ function update_entity($guid, $owner_guid, $access_id, $container_guid = null, $ $newentity_cache = new ElggMemcache('new_entity_cache'); } if ($newentity_cache) { - $new_entity = $newentity_cache->delete($guid); + $newentity_cache->delete($guid); } // Handle cases where there was no error BUT no rows were updated! @@ -466,12 +465,10 @@ function can_write_to_container($user_guid = 0, $container_guid = 0, $type = 'al $return = true; } - // Basics, see if the user is a member of the group. + // If still not approved, see if the user is a member of the group // @todo this should be moved to the groups plugin/library - if ($user && $container instanceof ElggGroup) { - if (!$container->isMember($user)) { - $return = false; - } else { + if (!$return && $user && $container instanceof ElggGroup) { + if ($container->isMember($user)) { $return = true; } } @@ -774,7 +771,7 @@ function elgg_entity_exists($guid) { * * callback => string A callback function to pass each row through * - * @return mixed if count, int. if not count, array or false if no entities. false also on errors. + * @return mixed If count, int. If not count, array. false on errors. * @since 1.7.0 * @see elgg_get_entities_from_metadata() * @see elgg_get_entities_from_relationship() @@ -987,7 +984,7 @@ function elgg_get_entity_type_subtype_where_sql($table, $types, $subtypes, $pair foreach ($types as $type) { if (!in_array($type, $valid_types)) { $valid_types_count--; - unset ($types[array_search($type, $types)]); + unset($types[array_search($type, $types)]); } else { // do the checking (and decrementing) in the subtype section. $valid_subtypes_count += count($subtypes); @@ -1039,7 +1036,7 @@ function elgg_get_entity_type_subtype_where_sql($table, $types, $subtypes, $pair foreach ($pairs as $paired_type => $paired_subtypes) { if (!in_array($paired_type, $valid_types)) { $valid_pairs_count--; - unset ($pairs[array_search($paired_type, $pairs)]); + unset($pairs[array_search($paired_type, $pairs)]); } else { if ($paired_subtypes && !is_array($paired_subtypes)) { $pairs[$paired_type] = array($paired_subtypes); @@ -1489,6 +1486,15 @@ function delete_entity($guid, $recursive = true) { if (isset($ENTITY_CACHE[$guid])) { invalidate_cache_for_entity($guid); } + + // If memcache is available then delete this entry from the cache + static $newentity_cache; + if ((!$newentity_cache) && (is_memcache_available())) { + $newentity_cache = new ElggMemcache('new_entity_cache'); + } + if ($newentity_cache) { + $newentity_cache->delete($guid); + } // Delete contained owned and otherwise releated objects (depth first) if ($recursive) { @@ -1556,7 +1562,7 @@ function delete_entity($guid, $recursive = true) { } } - return $res; + return (bool)$res; } } } @@ -2069,7 +2075,7 @@ function is_registered_entity_type($type, $subtype = null) { * * @param array $page Page elements from pain page handler * - * @return void + * @return bool * @elgg_page_handler view * @access private */ @@ -2078,7 +2084,9 @@ function entities_page_handler($page) { global $CONFIG; set_input('guid', $page[0]); include($CONFIG->path . "pages/entities/index.php"); + return true; } + return false; } /** diff --git a/engine/lib/input.php b/engine/lib/input.php index 2f68195f2..57e35786f 100644 --- a/engine/lib/input.php +++ b/engine/lib/input.php @@ -301,12 +301,12 @@ function input_livesearch_page_handler($page) { } $output = elgg_view_list_item($entity, array( - 'hover' => false, + 'use_hover' => false, 'class' => 'elgg-autocomplete-item', )); $icon = elgg_view_entity_icon($entity, 'tiny', array( - 'hover' => false, + 'use_hover' => false, )); $result = array( @@ -344,12 +344,12 @@ function input_livesearch_page_handler($page) { } $output = elgg_view_list_item($entity, array( - 'hover' => false, + 'use_hover' => false, 'class' => 'elgg-autocomplete-item', )); $icon = elgg_view_entity_icon($entity, 'tiny', array( - 'hover' => false, + 'use_hover' => false, )); $result = array( @@ -391,12 +391,12 @@ function input_livesearch_page_handler($page) { } $output = elgg_view_list_item($entity, array( - 'hover' => false, + 'use_hover' => false, 'class' => 'elgg-autocomplete-item', )); $icon = elgg_view_entity_icon($entity, 'tiny', array( - 'hover' => false, + 'use_hover' => false, )); $result = array( diff --git a/engine/lib/location.php b/engine/lib/location.php index 7e2c38fc8..5b889509b 100644 --- a/engine/lib/location.php +++ b/engine/lib/location.php @@ -74,7 +74,7 @@ function elgg_geocode_location($location) { * * @see ElggEntity::setLatLong() * - * @return array + * @return mixed If count, int. If not count, array. false on errors. * @since 1.8.0 */ function elgg_get_entities_from_location(array $options = array()) { diff --git a/engine/lib/metadata.php b/engine/lib/metadata.php index 0220e6c1f..050e69526 100644 --- a/engine/lib/metadata.php +++ b/engine/lib/metadata.php @@ -398,7 +398,7 @@ function elgg_enable_metadata(array $options) { * * metadata_owner_guids => NULL|ARR guids for metadata owners * - * @return mixed if count, int. if not count, array or false if no entities. false also on errors. + * @return mixed If count, int. If not count, array. false 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 9dccec700..9fe9b4bff 100644 --- a/engine/lib/metastrings.php +++ b/engine/lib/metastrings.php @@ -810,7 +810,7 @@ function elgg_delete_metastring_based_object_by_id($id, $type) { } if (($obj->canEdit()) && (elgg_trigger_event('delete', $type, $obj))) { - return delete_data("DELETE from $table where id=$id"); + return (bool)delete_data("DELETE from $table where id=$id"); } } diff --git a/engine/lib/navigation.php b/engine/lib/navigation.php index aaf9fb544..176790188 100644 --- a/engine/lib/navigation.php +++ b/engine/lib/navigation.php @@ -207,7 +207,7 @@ function elgg_register_title_button($handler = null, $name = 'add') { */ function elgg_push_breadcrumb($title, $link = NULL) { global $CONFIG; - if (!is_array($CONFIG->breadcrumbs)) { + if (!isset($CONFIG->breadcrumbs)) { $CONFIG->breadcrumbs = array(); } @@ -242,7 +242,11 @@ function elgg_pop_breadcrumb() { function elgg_get_breadcrumbs() { global $CONFIG; - return (is_array($CONFIG->breadcrumbs)) ? $CONFIG->breadcrumbs : array(); + if (isset($CONFIG->breadcrumbs) && is_array($CONFIG->breadcrumbs)) { + return $CONFIG->breadcrumbs; + } + + return array(); } /** diff --git a/engine/lib/pagehandler.php b/engine/lib/pagehandler.php index 0d5e5f89b..aba921416 100644 --- a/engine/lib/pagehandler.php +++ b/engine/lib/pagehandler.php @@ -7,14 +7,16 @@ */ /** - * Turns the current page over to the page handler, allowing registered handlers to take over. + * Routes the request to a registered page handler * - * If a page handler returns FALSE, the request is handed over to the default_page_handler. + * This function sets the context based on the handler name (first segment of the + * URL). It also triggers a plugin hook 'route', $handler so that plugins can + * modify the routing or handle a request. * * @param string $handler The name of the handler type (eg 'blog') * @param array $page The parameters to the page, as an array (exploded by '/' slashes) * - * @return true|false Depending on whether a registered page handler was found + * @return bool * @access private */ function page_handler($handler, $page) { @@ -42,26 +44,13 @@ function page_handler($handler, $page) { $handler = $params['handler']; $page = $params['segments']; - if (!isset($CONFIG->pagehandler) || empty($handler)) { - $result = false; - } else if (isset($CONFIG->pagehandler[$handler]) && is_callable($CONFIG->pagehandler[$handler])) { + $result = false; + if (isset($CONFIG->pagehandler) && !empty($handler) && isset($CONFIG->pagehandler[$handler])) { $function = $CONFIG->pagehandler[$handler]; $result = call_user_func($function, $page, $handler); - if ($result !== false) { - $result = true; - } - } else { - $result = false; } - if (!$result) { - $result = default_page_handler($page, $handler); - } - if ($result !== false) { - $result = true; - } - - return $result; + return $result || headers_sent(); } /** @@ -74,14 +63,16 @@ function page_handler($handler, $page) { * For example, the URL http://yoururl/blog/username/friends/ would result in the call: * blog_page_handler(array('username','friends'), blog); * - * Page handler functions should return true or the default page handler will be called. - * * A request to register a page handler with the same identifier as previously registered * handler will replace the previous one. * * The context is set to the page handler identifier before the registered * page handler function is called. For the above example, the context is set to 'blog'. * + * Page handlers should return true to indicate that they handled the request. + * Requests not handled are forwarded to the front page with a reason of 404. + * Plugins can register for the 'forward', '404' plugin hook. @see forward() + * * @param string $handler The page type to handle * @param string $function Your function name * @@ -119,38 +110,3 @@ function elgg_unregister_page_handler($handler) { unset($CONFIG->pagehandler[$handler]); } - -/** - * A default page handler - * Tries to locate a suitable file to include. Only works for core pages, not plugins. - * - * @param array $page The page URL elements - * @param string $handler The base handler - * - * @return true|false Depending on success - * @access private - */ -function default_page_handler($page, $handler) { - global $CONFIG; - - $page = implode('/', $page); - - // protect against including arbitary files - $page = str_replace("..", "", $page); - - $callpath = $CONFIG->path . $handler . "/" . $page; - if (is_dir($callpath)) { - $callpath = sanitise_filepath($callpath); - $callpath .= "index.php"; - if (file_exists($callpath)) { - if (include($callpath)) { - return TRUE; - } - } - } else if (file_exists($callpath)) { - include($callpath); - return TRUE; - } - - return FALSE; -} diff --git a/engine/lib/plugins.php b/engine/lib/plugins.php index fac52b152..be871d025 100644 --- a/engine/lib/plugins.php +++ b/engine/lib/plugins.php @@ -1007,7 +1007,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 int if count is true, an array of entity objects, or false on failure + * @return mixed int If count, int. If not count, array. false on errors. */ 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 95b1afa57..386af5279 100644 --- a/engine/lib/private_settings.php +++ b/engine/lib/private_settings.php @@ -38,7 +38,7 @@ * their own settings. * * - * @return mixed int if count is true, an array of entity objects, or false on failure + * @return mixed int If count, int. If not count, array. false on errors. * @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 1a5833732..5b7080b56 100644 --- a/engine/lib/relationships.php +++ b/engine/lib/relationships.php @@ -123,7 +123,7 @@ function check_entity_relationship($guid_one, $relationship, $guid_two) { AND relationship='$relationship' AND guid_two=$guid_two limit 1"; - $row = $row = get_data_row($query); + $row = get_data_row($query); if ($row) { return $row; } @@ -158,7 +158,7 @@ function remove_entity_relationship($guid_one, $relationship, $guid_two) { and relationship='$relationship' and guid_two=$guid_two"; - return delete_data($query); + return (bool)delete_data($query); } else { return false; } @@ -250,7 +250,7 @@ function get_entity_relationships($guid, $inverse_relationship = FALSE) { * * inverse_relationship => BOOL Inverse the relationship * - * @return mixed if count, int. if not count, array or false if no entities. false also on errors. + * @return mixed If count, int. If not count, array. false on errors. * @since 1.7.0 */ function elgg_get_entities_from_relationship($options) { @@ -372,7 +372,7 @@ function elgg_list_entities_from_relationship(array $options = array()) { * * @param array $options An options array compatible with * elgg_get_entities_from_relationship() - * @return mixed int if count is true, an array of entity objects, or false on failure + * @return mixed int If count, int. If not count, array. false on errors. * @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 f430eb224..02d52dea1 100644 --- a/engine/lib/river.php +++ b/engine/lib/river.php @@ -447,7 +447,8 @@ function elgg_get_river_type_subtype_where_sql($table, $types, $subtypes, $pairs return ''; } - $wheres = array(); + $types_wheres = array(); + $subtypes_wheres = array(); // if no pairs, use types and subtypes if (!is_array($pairs)) { @@ -457,7 +458,7 @@ function elgg_get_river_type_subtype_where_sql($table, $types, $subtypes, $pairs } foreach ($types as $type) { $type = sanitise_string($type); - $wheres[] = "({$table}.type = '$type')"; + $types_wheres[] = "({$table}.type = '$type')"; } } @@ -467,13 +468,20 @@ function elgg_get_river_type_subtype_where_sql($table, $types, $subtypes, $pairs } foreach ($subtypes as $subtype) { $subtype = sanitise_string($subtype); - $wheres[] = "({$table}.subtype = '$subtype')"; + $subtypes_wheres[] = "({$table}.subtype = '$subtype')"; } } - if (is_array($wheres) && count($wheres)) { - $wheres = array(implode(' OR ', $wheres)); + if (is_array($types_wheres) && count($types_wheres)) { + $types_wheres = array(implode(' OR ', $types_wheres)); } + + if (is_array($subtypes_wheres) && count($subtypes_wheres)) { + $subtypes_wheres = array(implode(' OR ', $subtypes_wheres)); + } + + $wheres = array(implode(' AND ', array_merge($types_wheres, $subtypes_wheres))); + } else { // using type/subtype pairs foreach ($pairs as $paired_type => $paired_subtypes) { @@ -586,6 +594,7 @@ function update_river_access_by_object($object_guid, $access_id) { * Page handler for activiy * * @param array $page + * @return bool * @access private */ function elgg_river_page_handler($page) { @@ -606,6 +615,17 @@ function elgg_river_page_handler($page) { $entity_subtype = ''; require_once("{$CONFIG->path}pages/river.php"); + return true; +} + +/** + * Register river unit tests + * @access private + */ +function elgg_river_test($hook, $type, $value) { + global $CONFIG; + $value[] = $CONFIG->path . 'engine/tests/api/river.php'; + return $value; } /** @@ -618,6 +638,8 @@ function elgg_river_init() { elgg_register_menu_item('site', $item); elgg_register_widget_type('river_widget', elgg_echo('river:widget:title'), elgg_echo('river:widget:description')); + + elgg_register_plugin_hook_handler('unit_test', 'system', 'elgg_river_test'); } elgg_register_event_handler('init', 'system', 'elgg_river_init'); diff --git a/engine/lib/tags.php b/engine/lib/tags.php index 6275d653c..a0887d0f3 100644 --- a/engine/lib/tags.php +++ b/engine/lib/tags.php @@ -321,25 +321,23 @@ function elgg_get_registered_tag_metadata_names() { * * @param array $page Page array * - * @return void + * @return bool * @access private */ function elgg_tagcloud_page_handler($page) { - switch ($page[0]) { - default: - $title = elgg_view_title(elgg_echo('tags:site_cloud')); - $options = array( - 'threshold' => 0, - 'limit' => 100, - 'tag_name' => 'tags', - ); - $tags = elgg_view_tagcloud($options); - $content = $title . $tags; - $body = elgg_view_layout('one_sidebar', array('content' => $content)); - - echo elgg_view_page(elgg_echo('tags:site_cloud'), $body); - break; - } + + $title = elgg_view_title(elgg_echo('tags:site_cloud')); + $options = array( + 'threshold' => 0, + 'limit' => 100, + 'tag_name' => 'tags', + ); + $tags = elgg_view_tagcloud($options); + $content = $title . $tags; + $body = elgg_view_layout('one_sidebar', array('content' => $content)); + + echo elgg_view_page(elgg_echo('tags:site_cloud'), $body); + return true; } /** diff --git a/engine/lib/user_settings.php b/engine/lib/user_settings.php index bb5d8d6c4..c71670357 100644 --- a/engine/lib/user_settings.php +++ b/engine/lib/user_settings.php @@ -265,8 +265,8 @@ function elgg_set_user_default_access() { * @access private */ function usersettings_pagesetup() { - if (elgg_get_context() == "settings" && elgg_get_logged_in_user_guid()) { - $user = elgg_get_logged_in_user_entity(); + if (elgg_get_context() == "settings") { + $user = elgg_get_page_owner_entity(); $params = array( 'name' => '1_account', @@ -294,7 +294,7 @@ function usersettings_pagesetup() { * * @param array $page Pages array * - * @return void + * @return bool * @access private */ function usersettings_page_handler($page) { @@ -304,7 +304,7 @@ function usersettings_page_handler($page) { $page[0] = 'user'; } - if ($page[1]) { + if (isset($page[1])) { $user = get_user_by_username($page[1]); elgg_set_page_owner_guid($user->guid); } else { @@ -324,12 +324,14 @@ function usersettings_page_handler($page) { $path = $CONFIG->path . "pages/settings/tools.php"; break; case 'user': - default: $path = $CONFIG->path . "pages/settings/account.php"; break; } - require($path); + if (isset($path)) { + require $path; + return true; + } } /** diff --git a/engine/lib/users.php b/engine/lib/users.php index 843b897e9..3a86c1faa 100644 --- a/engine/lib/users.php +++ b/engine/lib/users.php @@ -565,6 +565,8 @@ function get_user_by_username($username) { $entity = get_data_row($query, 'entity_row_to_elggstar'); if ($entity) { $USERNAME_TO_GUID_MAP_CACHE[$username] = $entity->guid; + } else { + $entity = false; } return $entity; @@ -1044,40 +1046,35 @@ function collections_submenu_items() { } /** - * Page handler for friends + * Page handler for friends-related pages * - * @param array $page_elements Page elements + * @param array $segments URL segments + * @param string $handler The first segment in URL used for routing * - * @return void + * @return bool * @access private */ -function friends_page_handler($page_elements) { +function friends_page_handler($page_elements, $handler) { + elgg_set_context('friends'); + if (isset($page_elements[0]) && $user = get_user_by_username($page_elements[0])) { elgg_set_page_owner_guid($user->getGUID()); } if (elgg_get_logged_in_user_guid() == elgg_get_page_owner_guid()) { collections_submenu_items(); } - require_once(dirname(dirname(dirname(__FILE__))) . "/pages/friends/index.php"); -} -/** - * Page handler for friends of - * - * @param array $page_elements Page elements - * - * @return void - * @access private - */ -function friends_of_page_handler($page_elements) { - elgg_set_context('friends'); - if (isset($page_elements[0]) && $user = get_user_by_username($page_elements[0])) { - set_page_owner($user->getGUID()); - } - if (elgg_get_logged_in_user_guid() == elgg_get_page_owner_guid()) { - collections_submenu_items(); + switch ($handler) { + case 'friends': + require_once(dirname(dirname(dirname(__FILE__))) . "/pages/friends/index.php"); + break; + case 'friendsof': + require_once(dirname(dirname(dirname(__FILE__))) . "/pages/friends/of.php"); + break; + default: + return false; } - require_once(dirname(dirname(dirname(__FILE__))) . "/pages/friends/of.php"); + return true; } /** @@ -1085,7 +1082,7 @@ function friends_of_page_handler($page_elements) { * * @param array $page_elements Page elements * - * @return void + * @return bool * @access private */ function collections_page_handler($page_elements) { @@ -1093,20 +1090,23 @@ function collections_page_handler($page_elements) { $base = elgg_get_config('path'); if (isset($page_elements[0])) { if ($page_elements[0] == "add") { - set_page_owner(elgg_get_logged_in_user_guid()); + elgg_set_page_owner_guid(elgg_get_logged_in_user_guid()); collections_submenu_items(); require_once "{$base}pages/friends/collections/add.php"; + return true; } else { $user = get_user_by_username($page_elements[0]); if ($user) { - set_page_owner($user->getGUID()); + elgg_set_page_owner_guid($user->getGUID()); if (elgg_get_logged_in_user_guid() == elgg_get_page_owner_guid()) { collections_submenu_items(); } require_once "{$base}pages/friends/collections/view.php"; + return true; } } } + return false; } /** @@ -1115,13 +1115,16 @@ function collections_page_handler($page_elements) { * @param array $page_elements Page elements * @param string $handler The handler string * - * @return void + * @return bool * @access private */ function elgg_user_account_page_handler($page_elements, $handler) { $base_dir = elgg_get_root_path() . 'pages/account'; switch ($handler) { + case 'login': + require_once("$base_dir/login.php"); + break; case 'forgotpassword': require_once("$base_dir/forgotten_password.php"); break; @@ -1131,26 +1134,10 @@ function elgg_user_account_page_handler($page_elements, $handler) { case 'register': require_once("$base_dir/register.php"); break; + default: + return false; } -} - -/** - * Display a login box. - * - * This is a fallback for non-JS users who click on the - * dropdown login link. - * - * @return void - * @access private - */ -function elgg_user_login_page_handler() { - if (elgg_is_logged_in()) { - forward(); - } - - $login_box = elgg_view('core/account/login_box'); - $content = elgg_view_layout('one_column', array('content' => $login_box)); - echo elgg_view_page(elgg_echo('login'), $content); + return true; } /** @@ -1296,6 +1283,11 @@ function elgg_user_hover_menu($hook, $type, $return, $params) { $item = new ElggMenuItem('profile:edit', elgg_echo('profile:edit'), $url); $item->setSection('admin'); $return[] = $item; + + $url = "settings/user/$user->username"; + $item = new ElggMenuItem('settings:edit', elgg_echo('settings:edit'), $url); + $item->setSection('admin'); + $return[] = $item; } return $return; @@ -1404,6 +1396,7 @@ function elgg_profile_fields_setup() { * /avatar/view/<username>/<size>/<icontime> * * @param array $page + * @return bool * @access private */ function elgg_avatar_page_handler($page) { @@ -1416,16 +1409,20 @@ function elgg_avatar_page_handler($page) { if ($page[0] == 'edit') { require_once("{$CONFIG->path}pages/avatar/edit.php"); + return true; } else { set_input('size', $page[2]); require_once("{$CONFIG->path}pages/avatar/view.php"); + return true; } + return false; } /** * Profile page handler * * @param array $page + * @return bool * @access private */ function elgg_profile_page_handler($page) { @@ -1436,7 +1433,9 @@ function elgg_profile_page_handler($page) { if ($page[1] == 'edit') { require_once("{$CONFIG->path}pages/profile/edit.php"); + return true; } + return false; } /** @@ -1484,14 +1483,15 @@ function users_pagesetup() { // topbar if ($viewer) { - - $icon_url = $viewer->getIconURL('topbar'); - $class = 'elgg-border-plain elgg-transition'; - $title = elgg_echo('profile'); elgg_register_menu_item('topbar', array( 'name' => 'profile', 'href' => $viewer->getURL(), - 'text' => "<img src=\"$icon_url\" alt=\"$viewer->name\" title=\"$title\" class=\"$class\" />", + 'text' => elgg_view('output/img', array( + 'src' => $viewer->getIconURL('topbar'), + 'alt' => $viewer->name, + 'title' => elgg_echo('profile'), + 'class' => 'elgg-border-plain elgg-transition', + )), 'priority' => 100, 'link_class' => 'elgg-topbar-avatar', )); @@ -1532,11 +1532,11 @@ function users_pagesetup() { function users_init() { elgg_register_page_handler('friends', 'friends_page_handler'); - elgg_register_page_handler('friendsof', 'friends_of_page_handler'); + elgg_register_page_handler('friendsof', 'friends_page_handler'); elgg_register_page_handler('register', 'elgg_user_account_page_handler'); elgg_register_page_handler('forgotpassword', 'elgg_user_account_page_handler'); elgg_register_page_handler('resetpassword', 'elgg_user_account_page_handler'); - elgg_register_page_handler('login', 'elgg_user_login_page_handler'); + elgg_register_page_handler('login', 'elgg_user_account_page_handler'); elgg_register_page_handler('avatar', 'elgg_avatar_page_handler'); elgg_register_page_handler('profile', 'elgg_profile_page_handler'); elgg_register_page_handler('collections', 'collections_page_handler'); diff --git a/engine/lib/views.php b/engine/lib/views.php index e7bc44cf7..d3c9ff551 100644 --- a/engine/lib/views.php +++ b/engine/lib/views.php @@ -743,7 +743,11 @@ function elgg_view_menu($menu_name, array $vars = array()) { $sort_by = elgg_extract('sort_by', $vars, 'text'); - $menu = $CONFIG->menus[$menu_name]; + if (isset($CONFIG->menus[$menu_name])) { + $menu = $CONFIG->menus[$menu_name]; + } else { + $menu = array(); + } // Give plugins a chance to add menu items just before creation. // This supports dynamic menus (example: user_hover). @@ -860,7 +864,9 @@ function elgg_view_entity(ElggEntity $entity, $vars = array(), $bypass = true, $ * * @param ElggEntity $entity The entity to display * @param string $size The size: tiny, small, medium, large - * @param array $vars An array of variables to pass to the view + * @param array $vars An array of variables to pass to the view. Some possible + * variables are img_class and link_class. See the + * specific icon view for more parameters. * * @return string HTML to display or false */ @@ -1196,7 +1202,8 @@ function elgg_view_image_block($image, $body, $vars = array()) { * @since 1.8.0 */ function elgg_view_module($type, $title, $body, $vars = array()) { - $vars['class'] .= " elgg-module-$type"; + + $vars['class'] = elgg_extract('class', $vars, '') . " elgg-module-$type"; $vars['title'] = $title; $vars['body'] = $body; return elgg_view('page/components/module', $vars); @@ -1582,7 +1589,7 @@ function elgg_views_boot() { 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'); + elgg_register_js('jquery', '/vendors/jquery/jquery-1.6.4.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'); |