diff options
Diffstat (limited to 'engine/lib')
| -rw-r--r-- | engine/lib/access.php | 2 | ||||
| -rw-r--r-- | engine/lib/elgglib.php | 54 | ||||
| -rw-r--r-- | engine/lib/entities.php | 4 | ||||
| -rw-r--r-- | engine/lib/notification.php | 56 | ||||
| -rw-r--r-- | engine/lib/river2.php | 1 | ||||
| -rw-r--r-- | engine/lib/sessions.php | 12 | ||||
| -rw-r--r-- | engine/lib/system_log.php | 2 | ||||
| -rw-r--r-- | engine/lib/tags.php | 4 | ||||
| -rw-r--r-- | engine/lib/users.php | 13 | 
9 files changed, 78 insertions, 70 deletions
diff --git a/engine/lib/access.php b/engine/lib/access.php index fa9510d7a..fc5081ced 100644 --- a/engine/lib/access.php +++ b/engine/lib/access.php @@ -173,7 +173,7 @@ function get_default_access(ElggUser $user = null) {  		return $CONFIG->default_access;  	} -	if (!($user) || (!$user = get_loggedin_user())) { +	if (!($user) && (!$user = get_loggedin_user())) {  		return $CONFIG->default_access;  	} 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; @@ -139,6 +143,45 @@ function elgg_get_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.   *   * @param string $view The 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'); diff --git a/engine/lib/entities.php b/engine/lib/entities.php index 56d6b1749..481feac6b 100644 --- a/engine/lib/entities.php +++ b/engine/lib/entities.php @@ -1989,11 +1989,11 @@ $count = false, $site_guid = 0, $container_guid = null, $timelower = 0, $timeupp  	}  	if ($timeupper) { -		$options['time_upper'] = $timeupper; +		$options['created_time_upper'] = $timeupper;  	}  	if ($timelower) { -		$options['time_lower'] = $timelower; +		$options['created_time_lower'] = $timelower;  	}  	$r = elgg_get_entities($options); diff --git a/engine/lib/notification.php b/engine/lib/notification.php index 58e2a10f6..726f76993 100644 --- a/engine/lib/notification.php +++ b/engine/lib/notification.php @@ -243,9 +243,6 @@ function email_notify_handler(ElggEntity $from, ElggUser $to, $subject, $message  		throw new NotificationException(sprintf(elgg_echo('NotificationException:NoEmailAddress'), $to->guid));  	} -	// Sanitise subject -	$subject = preg_replace("/(\r\n|\r|\n)/", " ", $subject); // Strip line endings -  	// To  	$to = $to->email; @@ -257,55 +254,12 @@ function email_notify_handler(ElggEntity $from, ElggUser $to, $subject, $message  	} else if (($site) && (isset($site->email))) {  		// Has the current site got a from email address?  		$from = $site->email; -	} else if (isset($from->url))  { -		// If we have a url then try and use that. -		$breakdown = parse_url($from->url); -		$from = 'noreply@' . $breakdown['host']; // Handle anything with a url  	} else {  		// If all else fails, use the domain of the site.  		$from = 'noreply@' . get_site_domain($CONFIG->site_guid);  	} -	if (is_callable('mb_internal_encoding')) { -		mb_internal_encoding('UTF-8'); -	} -	$site = get_entity($CONFIG->site_guid); -	$sitename = $site->name; -	if (is_callable('mb_encode_mimeheader')) { -		$sitename = mb_encode_mimeheader($site->name,"UTF-8", "B"); -	} - -	$header_eol = "\r\n"; -	if ( -		(isset($CONFIG->broken_mta)) && -		($CONFIG->broken_mta) -	) { -		// Allow non-RFC 2822 mail headers to support some broken MTAs -		$header_eol = "\n"; -	} - -	$from_email = "\"$sitename\" <$from>"; -	if (strtolower(substr(PHP_OS, 0 , 3)) == 'win') { -		// Windows is somewhat broken, so we use a different format from header -		$from_email = "$from"; -	} - -	$headers = "From: $from_email{$header_eol}" -		. "Content-Type: text/plain; charset=UTF-8; format=flowed{$header_eol}" -		. "MIME-Version: 1.0{$header_eol}" -		. "Content-Transfer-Encoding: 8bit{$header_eol}"; - -	if (is_callable('mb_encode_mimeheader')) { -		$subject = mb_encode_mimeheader($subject,"UTF-8", "B"); -	} - -	// Format message -	$message = html_entity_decode($message, ENT_COMPAT, 'UTF-8'); // Decode any html entities -	$message = strip_tags($message); // Strip tags from message -	$message = preg_replace("/(\r\n|\r)/", "\n", $message); // Convert to unix line endings in body -	$message = preg_replace("/^From/", ">From", $message); // Change lines starting with From to >From - -	return mail($to, $subject, wordwrap($message), $headers); +	return elgg_send_email($from, $to, $subject, $message);  }  /** @@ -372,10 +326,10 @@ function elgg_send_email($from, $to, $subject, $body, array $params = NULL) {  	}  	// Format message -	$message = html_entity_decode($body, ENT_COMPAT, 'UTF-8'); // Decode any html entities -	$message = strip_tags($body); // Strip tags from message -	$message = preg_replace("/(\r\n|\r)/", "\n", $body); // Convert to unix line endings in body -	$message = preg_replace("/^From/", ">From", $body); // Change lines starting with From to >From +	$body = html_entity_decode($body, ENT_COMPAT, 'UTF-8'); // Decode any html entities +	$body = strip_tags($body); // Strip tags from message +	$body = preg_replace("/(\r\n|\r)/", "\n", $body); // Convert to unix line endings in body +	$body = preg_replace("/^From/", ">From", $body); // Change lines starting with From to >From  	return mail($to, $subject, wordwrap($body), $headers);  } diff --git a/engine/lib/river2.php b/engine/lib/river2.php index 8fb20ac40..a4908167d 100644 --- a/engine/lib/river2.php +++ b/engine/lib/river2.php @@ -191,6 +191,7 @@ function get_river_items($subject_guid = 0, $object_guid = 0, $subject_relations  	// Construct 'where' clauses for the river  	$where = array(); +	// river table does not have columns expected by get_access_sql_suffix so we modify its output  	$where[] = str_replace("and enabled='yes'",'',str_replace('owner_guid','subject_guid',get_access_sql_suffix()));  	if (empty($subject_relationship)) { diff --git a/engine/lib/sessions.php b/engine/lib/sessions.php index b5b68ebe0..ffea2dcc2 100644 --- a/engine/lib/sessions.php +++ b/engine/lib/sessions.php @@ -60,8 +60,8 @@ class ElggSession implements ArrayAccess {  			return ElggSession::$__localcache[$key];  		} -		$value = null; -		$value = trigger_plugin_hook('session:get', $key, null, $value); +		$value = NULL; +		$value = trigger_plugin_hook('session:get', $key, NULL, $value);  		ElggSession::$__localcache[$key] = $value; @@ -110,10 +110,11 @@ class ElggSession implements ArrayAccess {  /** - * Return the current logged in user, or null if no user is logged in. + * Return the current logged in user, or NULL if no user is logged in.   *   * If no user can be found in the current session, a plugin hook - 'session:get' 'user' to give plugin   * authors another way to provide user details to the ACL system without touching the session. + * @return ElggUser|NULL   */  function get_loggedin_user() {  	global $SESSION; @@ -122,7 +123,7 @@ function get_loggedin_user() {  		return $SESSION['user'];  	} -	return false; +	return NULL;  }  /** @@ -133,8 +134,9 @@ function get_loggedin_user() {   */  function get_loggedin_userid() {  	$user = get_loggedin_user(); -	if ($user) +	if ($user) {  		return $user->guid; +	}  	return 0;  } diff --git a/engine/lib/system_log.php b/engine/lib/system_log.php index 75a7cc531..74597ed5d 100644 --- a/engine/lib/system_log.php +++ b/engine/lib/system_log.php @@ -203,7 +203,7 @@ function system_log($object, $event) {  		$object_subtype = $object->getSubtype();  		$event = sanitise_string($event);  		$time = time(); -		$performed_by = (int)$_SESSION['guid']; +		$performed_by = get_loggedin_userid();  		if (isset($object->access_id)) {  			$access_id = $object->access_id; diff --git a/engine/lib/tags.php b/engine/lib/tags.php index 84ea1b978..8d67a89bb 100644 --- a/engine/lib/tags.php +++ b/engine/lib/tags.php @@ -292,11 +292,11 @@ function get_tags($threshold = 1, $limit = 10, $metadata_name = "", $entity_type  	}  	if ($end_ts) { -		$options['time_upper'] = $end_ts; +		$options['created_time_upper'] = $end_ts;  	}  	if ($start_ts) { -		$options['time_lower'] = $start_ts; +		$options['created_time_lower'] = $start_ts;  	}  	$r = elgg_get_tags($options); diff --git a/engine/lib/users.php b/engine/lib/users.php index 9bb2a3f15..dae7341ac 100644 --- a/engine/lib/users.php +++ b/engine/lib/users.php @@ -1602,7 +1602,7 @@ function collections_submenu_items() {  	global $CONFIG;  	$user = get_loggedin_user();  	add_submenu_item(elgg_echo('friends:collections'), $CONFIG->wwwroot . "pg/collections/" . $user->username); -	add_submenu_item(elgg_echo('friends:collections:add'),$CONFIG->wwwroot."pg/collections/add"); +	add_submenu_item(elgg_echo('friends:collections:add'), $CONFIG->wwwroot . "pg/collections/add");  }  /** @@ -1613,10 +1613,9 @@ function friends_page_handler($page_elements) {  	if (isset($page_elements[0]) && $user = get_user_by_username($page_elements[0])) {  		set_page_owner($user->getGUID());  	} -	if ($_SESSION['guid'] == page_owner()) { +	if (get_loggedin_userid() == page_owner()) {  		// collections_submenu_items(); disabled for now as we no longer use friends collections (replaced by shared access)  	} -  	require_once(dirname(dirname(dirname(__FILE__))) . "/friends/index.php");  } @@ -1628,26 +1627,26 @@ function friends_of_page_handler($page_elements) {  	if (isset($page_elements[0]) && $user = get_user_by_username($page_elements[0])) {  		set_page_owner($user->getGUID());  	} -	if ($_SESSION['guid'] == page_owner()) { +	if (get_loggedin_userid() == page_owner()) {  		// collections_submenu_items(); disabled for now as we no longer use friends collections (replaced by shared access)  	}  	require_once(dirname(dirname(dirname(__FILE__))) . "/friends/of.php");  }  /** - * Page handler for friends of + * Page handler for friends collections   *   */  function collections_page_handler($page_elements) {  	if (isset($page_elements[0])) {  		if ($page_elements[0] == "add") { -			set_page_owner($_SESSION['guid']); +			set_page_owner(get_loggedin_userid());  			collections_submenu_items();  			require_once(dirname(dirname(dirname(__FILE__))) . "/friends/add.php");  		} else {  			if ($user = get_user_by_username($page_elements[0])) {  				set_page_owner($user->getGUID()); -				if ($_SESSION['guid'] == page_owner()) { +				if (get_loggedin_userid() == page_owner()) {  					collections_submenu_items();  				}  				require_once(dirname(dirname(dirname(__FILE__))) . "/friends/collections.php");  | 
