From b6aaba915151dd07800761a01b67ffffaee1302b Mon Sep 17 00:00:00 2001 From: brettp Date: Fri, 14 May 2010 20:01:59 +0000 Subject: merge -r5898:5928 (not excluding riverdashboard, notifications, and messageboard) from 1.7 to trunk. git-svn-id: http://code.elgg.org/elgg/trunk@6058 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/elgglib.php | 54 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) (limited to 'engine/lib/elgglib.php') diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php index f6aae2b97..fd99cee0b 100644 --- a/engine/lib/elgglib.php +++ b/engine/lib/elgglib.php @@ -24,6 +24,10 @@ function forward($location = "") { global $CONFIG; if (!headers_sent()) { + if ($location === REFERER) { + $location = $_SERVER['HTTP_REFERER']; + } + $current_page = current_page_url(); if ((substr_count($location, 'http://') == 0) && (substr_count($location, 'https://') == 0)) { $location = $CONFIG->url . $location; @@ -138,6 +142,45 @@ function elgg_get_viewtype() { return $viewtype; } +/** + * Register a viewtype to fall back to a default view if view does not exist in + * that viewtype. + * + * This is useful for alternate html viewtypes (such as for mobile devices) + * + * @param string $viewtype The viewtype to register + */ +function elgg_register_viewtype_fallback($viewtype) { + global $CONFIG; + + if (!isset($CONFIG->viewtype)) { + $CONFIG->viewtype = new stdClass; + } + + if (!isset($CONFIG->viewtype->fallback)) { + $CONFIG->viewtype->fallback = array(); + } + + $CONFIG->viewtype->fallback[] = $viewtype; +} + +/** + * Checks if this viewtype falls back to default + * + * @param string $viewtype + * @return boolean + */ +function elgg_does_viewtype_fallback($viewtype) { + global $CONFIG; + + if (isset($CONFIG->viewtype) && isset($CONFIG->viewtype->fallback)) { + return in_array($viewtype, $CONFIG->viewtype->fallback); + } + + return FALSE; +} + + /** * Return the location of a given view. * @@ -282,7 +325,7 @@ function elgg_view($view, $vars = array(), $bypass = false, $debug = false, $vie $error = "$viewtype/$view view does not exist."; // attempt to load default view - if ($viewtype != 'default') { + if ($viewtype != 'default' && elgg_does_viewtype_fallback($viewtype)) { if (file_exists($default_view_file) && include($default_view_file)) { // default view found $error .= " Using default/$view instead."; @@ -3326,9 +3369,18 @@ define('ACCESS_LOGGED_IN', 1); define('ACCESS_PUBLIC', 2); define('ACCESS_FRIENDS', -2); +/** + * @since 1.7 + */ define('ELGG_ENTITIES_ANY_VALUE', NULL); define('ELGG_ENTITIES_NO_VALUE', 0); +/** + * @since 1.7.2 + */ +define('REFERRER', -1); +define('REFERER', -1); + register_elgg_event_handler('init', 'system', 'elgg_init'); register_elgg_event_handler('boot', 'system', 'elgg_boot', 1000); register_plugin_hook('unit_test', 'system', 'elgg_api_test'); -- cgit v1.2.3