From 0c2c36ff3b0329ff849930d0403f933653a84dcd Mon Sep 17 00:00:00 2001
From: brettp
Date: Fri, 14 May 2010 20:50:34 +0000
Subject: Merged 5928-6908 from 1.7 branch to trunk.
git-svn-id: http://code.elgg.org/elgg/trunk@6059 36083f99-b078-4883-b0ff-0f9b5a30f544
---
engine/lib/actions.php | 10 +-
engine/lib/activity.php | 169 -------
engine/lib/api.php | 11 -
engine/lib/elgglib.php | 73 +--
engine/lib/entities.php | 4 +-
engine/lib/input.php | 96 ----
engine/lib/output.php | 150 ++++++
engine/lib/pagehandler.php | 15 +-
engine/lib/river.php | 491 +++++++++++++++++++
engine/lib/river2.php | 544 ---------------------
engine/lib/sessions.php | 21 -
engine/start.php | 22 +-
htaccess_dist | 8 +-
languages/en.php | 1 +
mod/groups/invitations.php | 2 +
mod/groups/new.php | 2 +
mod/groups/views/default/river/forum/create.php | 17 +-
.../views/default/river/forum/topic/create.php | 10 +-
.../views/default/river/object/page/create.php | 10 +-
mod/profile/actions/edit.php | 6 +-
20 files changed, 719 insertions(+), 943 deletions(-)
delete mode 100644 engine/lib/activity.php
create mode 100644 engine/lib/output.php
create mode 100644 engine/lib/river.php
delete mode 100644 engine/lib/river2.php
diff --git a/engine/lib/actions.php b/engine/lib/actions.php
index 66c2d9505..57da1389f 100644
--- a/engine/lib/actions.php
+++ b/engine/lib/actions.php
@@ -21,9 +21,6 @@
function action($action, $forwarder = "") {
global $CONFIG;
- // set GET params
- elgg_set_input_from_uri();
-
// @todo REMOVE THESE ONCE #1509 IS IN PLACE.
// Allow users to disable plugins without a token in order to
// remove plugins that are imcompatible.
@@ -72,6 +69,8 @@ function action($action, $forwarder = "") {
} else {
register_error(elgg_echo('actionloggedout'));
}
+ } else {
+ register_error(elgg_echo('actionunauthorized'));
}
} else {
register_error(sprintf(elgg_echo('actionundefined'),$action));
@@ -197,14 +196,11 @@ function generate_action_token($timestamp) {
// Current session id
$session_id = session_id();
- // Get user agent
- $ua = $_SERVER['HTTP_USER_AGENT'];
-
// Session token
$st = $_SESSION['__elgg_session'];
if (($site_secret) && ($session_id)) {
- return md5($site_secret.$timestamp.$session_id.$ua.$st);
+ return md5($site_secret.$timestamp.$session_id.$st);
}
return FALSE;
diff --git a/engine/lib/activity.php b/engine/lib/activity.php
deleted file mode 100644
index 51b083531..000000000
--- a/engine/lib/activity.php
+++ /dev/null
@@ -1,169 +0,0 @@
-owner_guid"
- * @return array An array of system log entries.
- */
-function get_activity_stream_data($limit = 10, $offset = 0, $type = "", $subtype = "", $owner_guid = "", $owner_relationship = "") {
- global $CONFIG;
-
- $limit = (int)$limit;
- $offset = (int)$offset;
-
- if ($type) {
- if (!is_array($type)) {
- $type = array(sanitise_string($type));
- } else {
- foreach ($type as $k => $v) {
- $type[$k] = sanitise_string($v);
- }
- }
- }
-
- if ($subtype) {
- if (!is_array($subtype)) {
- $subtype = array(sanitise_string($subtype));
- } else {
- foreach ($subtype as $k => $v) {
- $subtype[$k] = sanitise_string($v);
- }
- }
- }
-
- if ($owner_guid) {
- if (is_array($owner_guid)) {
- foreach ($owner_guid as $k => $v) {
- $owner_guid[$k] = (int)$v;
- }
- } else {
- $owner_guid = array((int)$owner_guid);
- }
- }
-
- $owner_relationship = sanitise_string($owner_relationship);
-
- // Get a list of possible views
- $activity_events= array();
- $activity_views = array_merge(elgg_view_tree('activity', 'default'), elgg_view_tree('river', 'default')); // Join activity with river
-
- $done = array();
-
- foreach ($activity_views as $view) {
- $fragments = explode('/', $view);
- $tmp = explode('/',$view, 2);
- $tmp = $tmp[1];
-
- if ((isset($fragments[0])) && (($fragments[0] == 'river') || ($fragments[0] == 'activity'))
- && (!in_array($tmp, $done))) {
-
- if (isset($fragments[1])) {
- $f = array();
- for ($n = 1; $n < count($fragments); $n++) {
- $val = sanitise_string($fragments[$n]);
- switch($n) {
- case 1: $key = 'type'; break;
- case 2: $key = 'subtype'; break;
- case 3: $key = 'event'; break;
- }
- $f[$key] = $val;
- }
-
- // Filter result based on parameters
- $add = true;
- if ($type) {
- if (!in_array($f['type'], $type)) {
- $add = false;
- }
- }
- if (($add) && ($subtype)) {
- if (!in_array($f['subtype'], $subtype)) {
- $add = false;
- }
- }
- if (($add) && ($event)) {
- if (!in_array($f['event'], $event)) {
- $add = false;
- }
- }
-
- if ($add) {
- $activity_events[] = $f;
- }
- }
-
- $done[] = $tmp;
- }
- }
-
- $n = 0;
- foreach ($activity_events as $details) {
- // Get what we're talking about
- if ($details['subtype'] == 'default') {
- $details['subtype'] = '';
- }
-
- if (($details['type']) && ($details['event'])) {
- if ($n > 0) {
- $obj_query .= " or ";
- }
-
- $access = "";
- if ($details['type']!='relationship') {
- $access = " and " . get_access_sql_suffix('sl');
- }
-
- $obj_query .= "( sl.object_type='{$details['type']}'
- AND sl.object_subtype='{$details['subtype']}'
- AND sl.event='{$details['event']}' $access )";
-
- $n++;
- }
- }
-
- // User
- if ((count($owner_guid)) && ($owner_guid[0] != 0)) {
- $user = " and sl.performed_by_guid in (".implode(',', $owner_guid).")";
-
- if ($owner_relationship) {
- $friendsarray = "";
- if ($friends = elgg_get_entities_from_relationship(array(
- 'relationship' => $owner_relationship,
- 'relationship_guid' => $owner_guid[0],
- 'inverse_relationship' => FALSE,
- 'types' => 'user',
- 'subtypes' => $subtype,
- 'limit' => 9999))
- ) {
-
- $friendsarray = array();
- foreach($friends as $friend) {
- $friendsarray[] = $friend->getGUID();
- }
-
- $user = " and sl.performed_by_guid in (" . implode(',', $friendsarray).")";
- }
- }
- }
-
- $query = "SELECT sl.* FROM {$CONFIG->dbprefix}system_log sl
- WHERE 1 $user AND ($obj_query)
- ORDER BY sl.time_created desc limit $offset, $limit";
- return get_data($query);
-}
diff --git a/engine/lib/api.php b/engine/lib/api.php
index 6707a7418..0da0c82f0 100644
--- a/engine/lib/api.php
+++ b/engine/lib/api.php
@@ -1438,17 +1438,6 @@ function __php_api_exception_handler($exception) {
function service_handler($handler, $request) {
global $CONFIG;
- // setup the input parameters since this comes through rewrite rule
- $query = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], '?')+1);
- if (isset($query)) {
- $query_arr = elgg_parse_str($query);
- if (is_array($query_arr)) {
- foreach($query_arr as $name => $val) {
- set_input($name, $val);
- }
- }
- }
-
set_context('api');
$request = explode('/',$request);
diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php
index fd99cee0b..eac75403f 100644
--- a/engine/lib/elgglib.php
+++ b/engine/lib/elgglib.php
@@ -476,11 +476,10 @@ function elgg_view_regenerate_simplecache() {
function elgg_view_enable_simplecache() {
global $CONFIG;
- if(!$CONFIG->simplecache_enabled) {
- datalist_set('simplecache_enabled',1);
- $CONFIG->simplecache_enabled = 1;
- elgg_view_regenerate_simplecache();
- }
+
+ datalist_set('simplecache_enabled',1);
+ $CONFIG->simplecache_enabled = 1;
+ elgg_view_regenerate_simplecache();
}
/**
@@ -1385,6 +1384,39 @@ function elgg_extend_view($view, $view_extension, $priority = 501, $viewtype = '
ksort($CONFIG->views->extensions[$view]);
}
+/**
+ * Unextends a view.
+ *
+ * @param string $view The view that was extended.
+ * @param string $view_extension This view that was added to $view
+ * @return bool
+ * @since 1.7.2
+ */
+function elgg_unextend_view($view, $view_extension) {
+ global $CONFIG;
+
+ if (!isset($CONFIG->views)) {
+ return FALSE;
+ }
+
+ if (!isset($CONFIG->views->extensions)) {
+ return FALSE;
+ }
+
+ if (!isset($CONFIG->views->extensions[$view])) {
+ return FALSE;
+ }
+
+ $priority = array_search($view_extension, $CONFIG->views->extensions[$view]);
+ if ($priority === FALSE) {
+ return FALSE;
+ }
+
+ unset($CONFIG->views->extensions[$view][$priority]);
+
+ return TRUE;
+}
+
/**
* @deprecated 1.7. Use elgg_extend_view().
* @param $view
@@ -1497,26 +1529,6 @@ function page_draw($title, $body, $sidebar = "") {
}
}
-/**
- * Displays a UNIX timestamp in a friendly way (eg "less than a minute ago")
- *
- * @param int $time A UNIX epoch timestamp
- * @return string The friendly time
- */
-function friendly_time($time) {
- return elgg_view('output/friendlytime', array('time' => $time));
-}
-
-/**
- * When given a title, returns a version suitable for inclusion in a URL
- *
- * @param string $title The title
- * @return string The optimised title
- */
-function friendly_title($title) {
- return elgg_view('output/friendlytitle', array('title' => $title));
-}
-
/**
* Library loading and handling
*/
@@ -2812,17 +2824,6 @@ interface Friendable {
public function countObjects($subtype = "");
}
-/**
- * Handles formatting of ampersands in urls
- *
- * @param string $url
- * @return string
- * @since 1.7.1
- */
-function elgg_format_url($url) {
- return preg_replace('/&(?!amp;)/', '&', $url);
-}
-
/**
* Rebuilds a parsed (partial) URL
*
diff --git a/engine/lib/entities.php b/engine/lib/entities.php
index 481feac6b..8e20ec269 100644
--- a/engine/lib/entities.php
+++ b/engine/lib/entities.php
@@ -2319,8 +2319,8 @@ function elgg_get_entity_site_where_sql($table, $site_guids) {
*/
function elgg_list_entities($options) {
$defaults = array(
- 'offset' => 0,
- 'limit' => 10,
+ 'offset' => (int) max(get_input('offset', 0), 0),
+ 'limit' => (int) max(get_input('limit', 10), 0),
'full_view' => TRUE,
'view_type_toggle' => FALSE,
'pagination' => TRUE
diff --git a/engine/lib/input.php b/engine/lib/input.php
index 26416d646..cf0af2b8e 100644
--- a/engine/lib/input.php
+++ b/engine/lib/input.php
@@ -105,102 +105,6 @@ function sanitise_filepath($path) {
return $path;
}
-
-/**
- * Takes a string and turns any URLs into formatted links
- *
- * @param string $text The input string
- * @return string The output stirng with formatted links
- **/
-function parse_urls($text) {
- // @todo this causes problems with
- // must be ing format (no space).
- // By default htmlawed rewrites tags to this format.
- // if PHP supported conditional negative lookbehinds we could use this:
- // $r = preg_replace_callback('/(?"\'\!\(\),]+)/i',
- //
- // we can put , in the list of excluded char but need to keep . because of domain names.
- // it is removed in the callback.
- $r = preg_replace_callback('/(?"\'\!\(\),]+)/i',
- create_function(
- '$matches',
- '
- $url = $matches[1];
- $period = \'\';
- if (substr($url, -1, 1) == \'.\') {
- $period = \'.\';
- $url = trim($url, \'.\');
- }
- $urltext = str_replace("/", "/", $url);
- return "$urltext$period";
- '
- ), $text);
-
- return $r;
-}
-
-/**
- *
- * Adds P tags.
- * Borrowed from Wordpress.
- *
- **/
-function autop($pee, $br = 1) {
- $pee = $pee . "\n"; // just to make things a little easier, pad the end
- $pee = preg_replace('|
\s*
|', "\n\n", $pee);
- // Space things out a little
- $allblocks = '(?:table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|map|area|blockquote|address|math|style|input|p|h[1-6]|hr)';
- $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n$1", $pee);
- $pee = preg_replace('!(' . $allblocks . '>)!', "$1\n\n", $pee);
- $pee = str_replace(array("\r\n", "\r"), "\n", $pee); // cross-platform newlines
- if ( strpos($pee, '
', '', $pee);
- $pee = preg_replace('!\s*(?' . $allblocks . '[^>]*>)!', "$1", $pee);
- $pee = preg_replace('!(?' . $allblocks . '[^>]*>)\s*
!', "$1", $pee);
- if ($br) {
- $pee = preg_replace_callback('/<(script|style).*?<\/\\1>/s', create_function('$matches', 'return str_replace("\n", "", $matches[0]);'), $pee);
- $pee = preg_replace('|(?)\s*\n|', "
\n", $pee); // optionally make line breaks
- $pee = str_replace('', "\n", $pee);
- }
- $pee = preg_replace('!(?' . $allblocks . '[^>]*>)\s*
!', "$1", $pee);
- $pee = preg_replace('!
(\s*?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)[^>]*>)!', '$1', $pee);
-// if (strpos($pee, '. Only there because of the comment.
-// $pee = preg_replace_callback('!()(.*?)
!is', 'clean_pre', $pee );
-// }
- $pee = preg_replace( "|\n$|", '', $pee );
-
- return $pee;
-}
-
-/**
- * Examins $_SERVER['REQUEST_URI'] and set_input()s on each.
- * Required if the params are sent as GET and not forwarded by mod_rewrite.
- *
- * @return bool on success
- */
-function elgg_set_input_from_uri() {
- $query = parse_url($_SERVER['REQUEST_URI'], PHP_URL_QUERY);
- $query_arr = elgg_parse_str($query);
-
- if (is_array($query_arr)) {
- foreach($query_arr as $name => $val) {
- set_input($name, $val);
- }
- }
-}
-
/**
* Page handler for autocomplete endpoint.
*
diff --git a/engine/lib/output.php b/engine/lib/output.php
new file mode 100644
index 000000000..d2b76a482
--- /dev/null
+++ b/engine/lib/output.php
@@ -0,0 +1,150 @@
+
+ * @link http://elgg.org/
+ */
+
+/**
+ * Takes a string and turns any URLs into formatted links
+ *
+ * @param string $text The input string
+ * @return string The output stirng with formatted links
+ **/
+function parse_urls($text) {
+ // @todo this causes problems with
+ // must be ing format (no space).
+ // By default htmlawed rewrites tags to this format.
+ // if PHP supported conditional negative lookbehinds we could use this:
+ // $r = preg_replace_callback('/(?"\'\!\(\),]+)/i',
+ //
+ // we can put , in the list of excluded char but need to keep . because of domain names.
+ // it is removed in the callback.
+ $r = preg_replace_callback('/(?"\'\!\(\),]+)/i',
+ create_function(
+ '$matches',
+ '
+ $url = $matches[1];
+ $period = \'\';
+ if (substr($url, -1, 1) == \'.\') {
+ $period = \'.\';
+ $url = trim($url, \'.\');
+ }
+ $urltext = str_replace("/", "/", $url);
+ return "$urltext$period";
+ '
+ ), $text);
+
+ return $r;
+}
+
+/**
+ * Create paragraphs from text with line spacing
+ * Borrowed from Wordpress.
+ *
+ **/
+function autop($pee, $br = 1) {
+ $pee = $pee . "\n"; // just to make things a little easier, pad the end
+ $pee = preg_replace('|
\s*
|', "\n\n", $pee);
+ // Space things out a little
+ $allblocks = '(?:table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|map|area|blockquote|address|math|style|input|p|h[1-6]|hr)';
+ $pee = preg_replace('!(<' . $allblocks . '[^>]*>)!', "\n$1", $pee);
+ $pee = preg_replace('!(' . $allblocks . '>)!', "$1\n\n", $pee);
+ $pee = str_replace(array("\r\n", "\r"), "\n", $pee); // cross-platform newlines
+ if ( strpos($pee, '