From 37875ae23f33b487bfb406c39400cea71dc1d662 Mon Sep 17 00:00:00 2001 From: Sem Date: Sat, 7 Jul 2012 05:52:48 +0200 Subject: Fixes #4008. Sets a vertical align for admin icons consistent with the text, and set it as before (baseline) for heads. --- views/default/css/admin.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/views/default/css/admin.php b/views/default/css/admin.php index 0f5c1f677..aca8ee3de 100644 --- a/views/default/css/admin.php +++ b/views/default/css/admin.php @@ -1239,6 +1239,10 @@ a.elgg-widget-collapsed:before { height: 16px; display: inline-block; margin: 0 2px; + vertical-align: text-bottom; +} +.elgg-head .elgg-icon { + vertical-align: baseline; } .elgg-icon-delete:hover, .elgg-icon-delete-alt:hover { -- cgit v1.2.3 From d1efed149b0ae8b137617978d46ea5841b3d5044 Mon Sep 17 00:00:00 2001 From: Sem Date: Sun, 29 Jul 2012 00:30:56 +0200 Subject: Refs #4008. Modified CSS selector to be more specific. --- views/default/css/admin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/default/css/admin.php b/views/default/css/admin.php index aca8ee3de..ae22df691 100644 --- a/views/default/css/admin.php +++ b/views/default/css/admin.php @@ -1241,7 +1241,7 @@ a.elgg-widget-collapsed:before { margin: 0 2px; vertical-align: text-bottom; } -.elgg-head .elgg-icon { +.elgg-module .elgg-head .elgg-icon { vertical-align: baseline; } .elgg-icon-delete:hover, -- cgit v1.2.3 From 2536e0bbcf1b20bbbdecd2ef378e0b4e488f7f2f Mon Sep 17 00:00:00 2001 From: Matt Beckett Date: Mon, 22 Oct 2012 00:01:45 -0600 Subject: adds parentheses to clarify comparison logic --- mod/messages/pages/messages/read.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mod/messages/pages/messages/read.php b/mod/messages/pages/messages/read.php index eb36eaa4b..05411b68b 100644 --- a/mod/messages/pages/messages/read.php +++ b/mod/messages/pages/messages/read.php @@ -40,7 +40,7 @@ if ($inbox) { $content .= elgg_view_form('messages/reply', $form_params, $body_params); $from_user = get_user($message->fromID); - if (elgg_get_logged_in_user_guid() == elgg_get_page_owner_guid() && $from_user) { + if ((elgg_get_logged_in_user_guid() == elgg_get_page_owner_guid()) && $from_user) { elgg_register_menu_item('title', array( 'name' => 'reply', 'href' => '#messages-reply-form', -- cgit v1.2.3 From 388080a1ada96423816e62b86196f7bee3e7afa4 Mon Sep 17 00:00:00 2001 From: Sem Date: Mon, 5 Nov 2012 09:09:34 +0100 Subject: Fixes #4904. Elgg 1.7 group blog RSS links forward correctly now. --- mod/blog/lib/blog.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mod/blog/lib/blog.php b/mod/blog/lib/blog.php index 4622a9e7e..34ea5a01c 100644 --- a/mod/blog/lib/blog.php +++ b/mod/blog/lib/blog.php @@ -403,12 +403,12 @@ function blog_url_forwarder($page) { global $CONFIG; // group usernames - if (substr_count($page[0], 'group:')) { - preg_match('/group\:([0-9]+)/i', $page[0], $matches); + if (substr_count($page[1], 'group:')) { + preg_match('/group\:([0-9]+)/i', $page[1], $matches); $guid = $matches[1]; $entity = get_entity($guid); if ($entity) { - $url = "{$CONFIG->wwwroot}blog/group/$guid/all"; + $url = "{$CONFIG->wwwroot}blog/group/$guid/all?view=" . elgg_get_viewtype(); register_error(elgg_echo("changebookmark")); forward($url); } -- cgit v1.2.3 From 45480715e699ed61cd2b70242c323de99d7325c5 Mon Sep 17 00:00:00 2001 From: Sem Date: Tue, 6 Nov 2012 05:44:26 +0100 Subject: Refs #4904. Forwarding pre and post-1.7.5 blog urls. --- mod/blog/lib/blog.php | 18 +++++++++++++++--- mod/blog/start.php | 3 +-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/mod/blog/lib/blog.php b/mod/blog/lib/blog.php index 34ea5a01c..1ccfe4dc4 100644 --- a/mod/blog/lib/blog.php +++ b/mod/blog/lib/blog.php @@ -396,6 +396,14 @@ function blog_prepare_form_vars($post = NULL, $revision = NULL) { /** * Forward to the new style of URLs + * + * Pre-1.7.5 + * Group blogs page: /blog/group:/ + * Group blog view: /blog/group:/read// + * 1.7.5-1.8 + * Group blogs page: /blog/owner/group:<container_guid>/ + * Group blog view: /blog/read/<guid> + * * * @param string $page */ @@ -403,12 +411,16 @@ function blog_url_forwarder($page) { global $CONFIG; // group usernames - if (substr_count($page[1], 'group:')) { - preg_match('/group\:([0-9]+)/i', $page[1], $matches); + if (substr_count("$page[0]/$page[1]", 'group:')) { + preg_match('/group\:([0-9]+)/i', "$page[0]/$page[1]", $matches); $guid = $matches[1]; $entity = get_entity($guid); if ($entity) { - $url = "{$CONFIG->wwwroot}blog/group/$guid/all?view=" . elgg_get_viewtype(); + if (isset($page[2])) { + $url = "{$CONFIG->wwwroot}blog/view/$page[2]/?view=" . elgg_get_viewtype(); + } else { + $url = "{$CONFIG->wwwroot}blog/group/$guid/all?view=" . elgg_get_viewtype(); + } register_error(elgg_echo("changebookmark")); forward($url); } diff --git a/mod/blog/start.php b/mod/blog/start.php index 9faf1794e..8cbaf5cca 100644 --- a/mod/blog/start.php +++ b/mod/blog/start.php @@ -99,8 +99,7 @@ function blog_page_handler($page) { elgg_load_library('elgg:blog'); - // @todo remove the forwarder in 1.9 - // forward to correct URL for blog pages pre-1.7.5 + // forward to correct URL for blog pages pre-1.8 blog_url_forwarder($page); // push all blogs breadcrumb -- cgit v1.2.3 From cb8231ad16a9fbd9e4b5df9af8b8d79f563a2bbb Mon Sep 17 00:00:00 2001 From: Jerome Bakker <jeabakker@coldtrick.com> Date: Thu, 8 Nov 2012 10:57:45 +0100 Subject: fixes missing error message on manual login of an unvalidated user --- mod/uservalidationbyemail/start.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/mod/uservalidationbyemail/start.php b/mod/uservalidationbyemail/start.php index f98f57faf..a453f36a4 100644 --- a/mod/uservalidationbyemail/start.php +++ b/mod/uservalidationbyemail/start.php @@ -238,8 +238,16 @@ function uservalidationbyemail_check_manual_login($event, $type, $user) { $access_status = access_get_show_hidden_status(); access_show_hidden_entities(TRUE); - // @todo register_error()? - $return = ($user instanceof ElggUser && !$user->isEnabled() && !$user->validated) ? FALSE : NULL; + if(($user instanceof ElggUser) && !$user->isEnabled() && !$user->validated){ + // send new validation email + uservalidationbyemail_request_validation($user->getGUID()); + + // restore hidden entities settings + access_show_hidden_entities($access_status); + + // throw error so we get a nice error message + throw new LoginException(elgg_echo('uservalidationbyemail:login:fail')); + } access_show_hidden_entities($access_status); -- cgit v1.2.3 From e40468a7aff9a445a5352b509044cb6a3597a341 Mon Sep 17 00:00:00 2001 From: Sem <sembrestels@riseup.net> Date: Sat, 10 Nov 2012 03:11:44 +0100 Subject: Fixes #4911. Cleaning register form after last check. --- actions/register.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/actions/register.php b/actions/register.php index f23d5b381..810ceaf27 100644 --- a/actions/register.php +++ b/actions/register.php @@ -30,8 +30,6 @@ if (elgg_get_config('allow_registration')) { $guid = register_user($username, $password, $name, $email, false, $friend_guid, $invitecode); if ($guid) { - elgg_clear_sticky_form('register'); - $new_user = get_entity($guid); // allow plugins to respond to self registration @@ -54,6 +52,7 @@ if (elgg_get_config('allow_registration')) { throw new RegistrationException(elgg_echo('registerbad')); } + elgg_clear_sticky_form('register'); system_message(elgg_echo("registerok", array(elgg_get_site_entity()->name))); // if exception thrown, this probably means there is a validation @@ -76,4 +75,4 @@ if (elgg_get_config('allow_registration')) { register_error(elgg_echo('registerdisabled')); } -forward(REFERER); \ No newline at end of file +forward(REFERER); -- cgit v1.2.3 From 20a4439735bdba0236d158813c7a9ac47c56ea75 Mon Sep 17 00:00:00 2001 From: German Bortoli <germanazo@gmail.com> Date: Mon, 12 Nov 2012 12:33:03 -0200 Subject: Removed unnecessary disabled class from blog delete button --- mod/blog/views/default/forms/blog/save.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mod/blog/views/default/forms/blog/save.php b/mod/blog/views/default/forms/blog/save.php index 7c3265c8d..36fa2e0e8 100644 --- a/mod/blog/views/default/forms/blog/save.php +++ b/mod/blog/views/default/forms/blog/save.php @@ -23,7 +23,7 @@ if ($vars['guid']) { $delete_link = elgg_view('output/confirmlink', array( 'href' => $delete_url, 'text' => elgg_echo('delete'), - 'class' => 'elgg-button elgg-button-delete elgg-state-disabled float-alt' + 'class' => 'elgg-button elgg-button-delete float-alt' )); } -- cgit v1.2.3 From f760ea1880bbeb46b210aa797d480dcef1a8f49e Mon Sep 17 00:00:00 2001 From: RiverVanRain <river.vanrain@gmail.com> Date: Wed, 14 Nov 2012 14:12:57 +0300 Subject: Fixes #4890: Correct URL for requesting a timeline --- mod/twitter/views/default/widgets/twitter/content.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mod/twitter/views/default/widgets/twitter/content.php b/mod/twitter/views/default/widgets/twitter/content.php index e429d0103..c616d944c 100644 --- a/mod/twitter/views/default/widgets/twitter/content.php +++ b/mod/twitter/views/default/widgets/twitter/content.php @@ -20,7 +20,7 @@ if ($username) { <ul id="twitter_update_list"></ul> <p class="visit_twitter"><a href="http://twitter.com/<?php echo $username; ?>"><?php echo elgg_echo("twitter:visit"); ?></a></p> <script type="text/javascript" src="http://twitter.com/javascripts/blogger.js"></script> - <script type="text/javascript" src="http://twitter.com/statuses/user_timeline/<?php echo $username; ?>.json?callback=twitterCallback2&count=<?php echo $num; ?>"></script> + <script type="text/javascript" src="https://api.twitter.com/1/statuses/user_timeline/<?php echo $username; ?>.json?callback=twitterCallback2&count=<?php echo $num; ?>"></script> </div> <?php -- cgit v1.2.3 From a9b4cd53032222b65bcd8e2692ac5337c12e94a3 Mon Sep 17 00:00:00 2001 From: RiverVanRain <river.vanrain@gmail.com> Date: Wed, 14 Nov 2012 14:15:06 +0300 Subject: Fixes #4916: Twitter API request token --- mod/twitter_api/vendors/twitteroauth/OAuth.php | 3 ++- mod/twitter_api/vendors/twitteroauth/twitterOAuth.php | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/mod/twitter_api/vendors/twitteroauth/OAuth.php b/mod/twitter_api/vendors/twitteroauth/OAuth.php index b0e3cfd5e..e132a5bc8 100644 --- a/mod/twitter_api/vendors/twitteroauth/OAuth.php +++ b/mod/twitter_api/vendors/twitteroauth/OAuth.php @@ -78,6 +78,7 @@ class twitterOAuthRequest extends OAuthRequest { private $http_url; // for debug purposes public $base_string; + public static $version = '1.0'; public static $POST_INPUT = 'php://input'; function __construct($http_method, $http_url, $parameters=NULL) { @@ -145,7 +146,7 @@ class twitterOAuthRequest extends OAuthRequest { */ public static function from_consumer_and_token($consumer, $token, $http_method, $http_url, $parameters=NULL) { @$parameters or $parameters = array(); - $defaults = array("oauth_version" => '1.0', + $defaults = array("oauth_version" => twitterOAuthRequest::$version, "oauth_nonce" => twitterOAuthRequest::generate_nonce(), "oauth_timestamp" => twitterOAuthRequest::generate_timestamp(), "oauth_consumer_key" => $consumer->key); diff --git a/mod/twitter_api/vendors/twitteroauth/twitterOAuth.php b/mod/twitter_api/vendors/twitteroauth/twitterOAuth.php index a1021ce6f..f36e6158d 100644 --- a/mod/twitter_api/vendors/twitteroauth/twitterOAuth.php +++ b/mod/twitter_api/vendors/twitteroauth/twitterOAuth.php @@ -43,8 +43,8 @@ class TwitterOAuth { * Set API URLS */ function accessTokenURL() { return 'https://api.twitter.com/oauth/access_token'; } - function authenticateURL() { return 'https://twitter.com/oauth/authenticate'; } - function authorizeURL() { return 'https://twitter.com/oauth/authorize'; } + function authenticateURL() { return 'https://api.twitter.com/oauth/authenticate'; } + function authorizeURL() { return 'https://api.twitter.com/oauth/authorize'; } function requestTokenURL() { return 'https://api.twitter.com/oauth/request_token'; } /** -- cgit v1.2.3 From 4f01b88b9fc1fe476189d53df7a34303502ba17e Mon Sep 17 00:00:00 2001 From: Sem <sembrestels@riseup.net> Date: Thu, 15 Nov 2012 01:16:42 +0100 Subject: Refs #4904. Checking if page has segments before using them. --- mod/blog/lib/blog.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mod/blog/lib/blog.php b/mod/blog/lib/blog.php index 1ccfe4dc4..4dcc7d56e 100644 --- a/mod/blog/lib/blog.php +++ b/mod/blog/lib/blog.php @@ -411,8 +411,8 @@ function blog_url_forwarder($page) { global $CONFIG; // group usernames - if (substr_count("$page[0]/$page[1]", 'group:')) { - preg_match('/group\:([0-9]+)/i', "$page[0]/$page[1]", $matches); + if (substr_count(implode('/', $page), 'group:')) { + preg_match('/group\:([0-9]+)/i', implode('/', $page), $matches); $guid = $matches[1]; $entity = get_entity($guid); if ($entity) { @@ -426,6 +426,10 @@ function blog_url_forwarder($page) { } } + if (!isset($page[0])) { + return; + } + // user usernames $user = get_user_by_username($page[0]); if (!$user) { -- cgit v1.2.3 From 72c444e03c02d0e77af1d2717d933cdc6e9b2175 Mon Sep 17 00:00:00 2001 From: Jerome Bakker <jeabakker@coldtrick.com> Date: Thu, 8 Nov 2012 11:10:44 +0100 Subject: Added missing language key for LoginException:Unknown --- languages/en.php | 1 + 1 file changed, 1 insertion(+) diff --git a/languages/en.php b/languages/en.php index bb5376a44..62b35dd81 100644 --- a/languages/en.php +++ b/languages/en.php @@ -229,6 +229,7 @@ $english = array( 'LoginException:PasswordFailure' => 'We could not log you in. Please check your username/email and password.', 'LoginException:AccountLocked' => 'Your account has been locked for too many log in failures.', 'LoginException:ChangePasswordFailure' => 'Failed current password check.', + 'LoginException:Unknown' => 'We could not log you in due to an unknown error.', 'deprecatedfunction' => 'Warning: This code uses the deprecated function \'%s\' and is not compatible with this version of Elgg', -- cgit v1.2.3 From 7758aea5e6dc9cca024491cbac6de447675e4ef0 Mon Sep 17 00:00:00 2001 From: Steve Clay <steve@mrclay.org> Date: Wed, 14 Nov 2012 20:56:44 -0500 Subject: Style cleanup --- mod/uservalidationbyemail/start.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mod/uservalidationbyemail/start.php b/mod/uservalidationbyemail/start.php index a453f36a4..f44d2ab50 100644 --- a/mod/uservalidationbyemail/start.php +++ b/mod/uservalidationbyemail/start.php @@ -233,12 +233,14 @@ function uservalidationbyemail_public_pages($hook, $type, $return_value, $params * @param string $type * @param ElggUser $user * @return bool + * + * @throws LoginException */ function uservalidationbyemail_check_manual_login($event, $type, $user) { $access_status = access_get_show_hidden_status(); access_show_hidden_entities(TRUE); - if(($user instanceof ElggUser) && !$user->isEnabled() && !$user->validated){ + if (($user instanceof ElggUser) && !$user->isEnabled() && !$user->validated) { // send new validation email uservalidationbyemail_request_validation($user->getGUID()); @@ -250,6 +252,4 @@ function uservalidationbyemail_check_manual_login($event, $type, $user) { } access_show_hidden_entities($access_status); - - return $return; } -- cgit v1.2.3 From 3048db0f3f1ade31d6f3a2cdd3268e978a3e3cf3 Mon Sep 17 00:00:00 2001 From: Steve Clay <steve@mrclay.org> Date: Mon, 17 Sep 2012 17:41:15 -0400 Subject: Fixes #4861: allow lazy-loading for static method callbacks, allow more callables --- engine/classes/ElggPAM.php | 8 +++++++- engine/lib/elgglib.php | 16 +++++++++------- engine/lib/entities.php | 2 +- engine/lib/extender.php | 6 +++--- engine/lib/notification.php | 7 ++++--- engine/lib/pagehandler.php | 9 ++++++--- engine/lib/pam.php | 7 +++++-- engine/lib/relationships.php | 2 +- engine/lib/views.php | 2 +- engine/lib/web_services.php | 9 ++++----- 10 files changed, 41 insertions(+), 27 deletions(-) diff --git a/engine/classes/ElggPAM.php b/engine/classes/ElggPAM.php index 0681a909b..f07095fc1 100644 --- a/engine/classes/ElggPAM.php +++ b/engine/classes/ElggPAM.php @@ -53,11 +53,17 @@ class ElggPAM { foreach ($_PAM_HANDLERS[$this->policy] as $k => $v) { $handler = $v->handler; + if (!is_callable($handler)) { + continue; + } + /* @var callable $handler */ + $importance = $v->importance; try { // Execute the handler - $result = $handler($credentials); + // @todo don't assume $handler is a global function + $result = call_user_func($handler, $credentials); if ($result) { $authenticated = true; } elseif ($result === false) { diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php index 26c1cccfd..85610f0c2 100644 --- a/engine/lib/elgglib.php +++ b/engine/lib/elgglib.php @@ -684,7 +684,7 @@ function elgg_register_event_handler($event, $object_type, $callback, $priority $CONFIG->events[$event][$object_type] = array(); } - if (!is_callable($callback)) { + if (!is_callable($callback, true)) { return FALSE; } @@ -770,7 +770,7 @@ function elgg_trigger_event($event, $object_type, $object = null) { foreach ($events as $callback_list) { if (is_array($callback_list)) { foreach ($callback_list as $callback) { - if (call_user_func_array($callback, $args) === FALSE) { + if (is_callable($callback) && (call_user_func_array($callback, $args) === FALSE)) { return FALSE; } } @@ -863,7 +863,7 @@ function elgg_register_plugin_hook_handler($hook, $type, $callback, $priority = $CONFIG->hooks[$hook][$type] = array(); } - if (!is_callable($callback)) { + if (!is_callable($callback, true)) { return FALSE; } @@ -970,10 +970,12 @@ function elgg_trigger_plugin_hook($hook, $type, $params = null, $returnvalue = n foreach ($hooks as $callback_list) { if (is_array($callback_list)) { foreach ($callback_list as $hookcallback) { - $args = array($hook, $type, $returnvalue, $params); - $temp_return_value = call_user_func_array($hookcallback, $args); - if (!is_null($temp_return_value)) { - $returnvalue = $temp_return_value; + if (is_callable($hookcallback)) { + $args = array($hook, $type, $returnvalue, $params); + $temp_return_value = call_user_func_array($hookcallback, $args); + if (!is_null($temp_return_value)) { + $returnvalue = $temp_return_value; + } } } } diff --git a/engine/lib/entities.php b/engine/lib/entities.php index a50567d9f..5a5906b1f 100644 --- a/engine/lib/entities.php +++ b/engine/lib/entities.php @@ -2011,7 +2011,7 @@ function get_entity_url($entity_guid) { function elgg_register_entity_url_handler($entity_type, $entity_subtype, $function_name) { global $CONFIG; - if (!is_callable($function_name)) { + if (!is_callable($function_name, true)) { return false; } diff --git a/engine/lib/extender.php b/engine/lib/extender.php index 43421342c..636b711ea 100644 --- a/engine/lib/extender.php +++ b/engine/lib/extender.php @@ -136,7 +136,7 @@ function can_edit_extender($extender_id, $type, $user_guid = 0) { $functionname = "elgg_get_{$type}_from_id"; if (is_callable($functionname)) { - $extender = $functionname($extender_id); + $extender = call_user_func($functionname, $extender_id); } else { return false; } @@ -175,7 +175,7 @@ function elgg_register_extender_url_handler($extender_type, $extender_name, $fun global $CONFIG; - if (!is_callable($function_name)) { + if (!is_callable($function_name, true)) { return false; } @@ -228,7 +228,7 @@ function get_extender_url(ElggExtender $extender) { if ($url == "") { $nameid = $extender->id; if ($type == 'volatile') { - $nameid == $extender->name; + $nameid = $extender->name; } $url = "export/$view/$guid/$type/$nameid/"; } diff --git a/engine/lib/notification.php b/engine/lib/notification.php index 18faff27f..9e3c075a8 100644 --- a/engine/lib/notification.php +++ b/engine/lib/notification.php @@ -38,7 +38,7 @@ $NOTIFICATION_HANDLERS = array(); function register_notification_handler($method, $handler, $params = NULL) { global $NOTIFICATION_HANDLERS; - if (is_callable($handler)) { + if (is_callable($handler, true)) { $NOTIFICATION_HANDLERS[$method] = new stdClass; $NOTIFICATION_HANDLERS[$method]->handler = $handler; @@ -131,8 +131,9 @@ function notify_user($to, $from, $subject, $message, array $params = NULL, $meth // Extract method details from list $details = $NOTIFICATION_HANDLERS[$method]; $handler = $details->handler; + /* @var callable $handler */ - if ((!$NOTIFICATION_HANDLERS[$method]) || (!$handler)) { + if ((!$NOTIFICATION_HANDLERS[$method]) || (!$handler) || (!is_callable($handler))) { error_log(elgg_echo('NotificationException:NoHandlerFound', array($method))); } @@ -140,7 +141,7 @@ function notify_user($to, $from, $subject, $message, array $params = NULL, $meth // Trigger handler and retrieve result. try { - $result[$guid][$method] = $handler( + $result[$guid][$method] = call_user_func($handler, $from ? get_entity($from) : NULL, // From entity get_entity($guid), // To entity $subject, // The subject diff --git a/engine/lib/pagehandler.php b/engine/lib/pagehandler.php index ba7518a77..a53506812 100644 --- a/engine/lib/pagehandler.php +++ b/engine/lib/pagehandler.php @@ -45,7 +45,10 @@ function page_handler($handler, $page) { $page = $request['segments']; $result = false; - if (isset($CONFIG->pagehandler) && !empty($handler) && isset($CONFIG->pagehandler[$handler])) { + if (isset($CONFIG->pagehandler) + && !empty($handler) + && isset($CONFIG->pagehandler[$handler]) + && is_callable($CONFIG->pagehandler[$handler])) { $function = $CONFIG->pagehandler[$handler]; $result = call_user_func($function, $page, $handler); } @@ -76,14 +79,14 @@ function page_handler($handler, $page) { * @param string $handler The page type to handle * @param string $function Your function name * - * @return true|false Depending on success + * @return bool Depending on success */ function elgg_register_page_handler($handler, $function) { global $CONFIG; if (!isset($CONFIG->pagehandler)) { $CONFIG->pagehandler = array(); } - if (is_callable($function)) { + if (is_callable($function, true)) { $CONFIG->pagehandler[$handler] = $function; return true; } diff --git a/engine/lib/pam.php b/engine/lib/pam.php index 4f9f44278..1c9c3bfe1 100644 --- a/engine/lib/pam.php +++ b/engine/lib/pam.php @@ -30,7 +30,9 @@ $_PAM_HANDLERS = array(); * failure, return false or throw an exception. Returning nothing indicates that * the handler wants to be skipped. * - * @param string $handler The handler function in the format + * Note, $handler must be string callback (not an array/Closure). + * + * @param string $handler Callable global handler function in the format () * pam_handler($credentials = NULL); * @param string $importance The importance - "sufficient" (default) or "required" * @param string $policy The policy type, default is "user" @@ -45,7 +47,8 @@ function register_pam_handler($handler, $importance = "sufficient", $policy = "u $_PAM_HANDLERS[$policy] = array(); } - if (is_callable($handler)) { + // @todo remove requirement that $handle be a global function + if (is_string($handler) && is_callable($handler, true)) { $_PAM_HANDLERS[$policy][$handler] = new stdClass; $_PAM_HANDLERS[$policy][$handler]->handler = $handler; diff --git a/engine/lib/relationships.php b/engine/lib/relationships.php index 09d541e22..01654b1ce 100644 --- a/engine/lib/relationships.php +++ b/engine/lib/relationships.php @@ -416,7 +416,7 @@ function elgg_list_entities_from_relationship_count($options) { function elgg_register_relationship_url_handler($relationship_type, $function_name) { global $CONFIG; - if (!is_callable($function_name)) { + if (!is_callable($function_name, true)) { return false; } diff --git a/engine/lib/views.php b/engine/lib/views.php index 6135026a7..e43c29cb2 100644 --- a/engine/lib/views.php +++ b/engine/lib/views.php @@ -1403,7 +1403,7 @@ function elgg_view_access_collections($owner_guid) { */ function set_template_handler($function_name) { global $CONFIG; - if (!empty($function_name) && is_callable($function_name)) { + if (is_callable($function_name)) { $CONFIG->template_handler = $function_name; return true; } diff --git a/engine/lib/web_services.php b/engine/lib/web_services.php index da3ed76a9..39fb0dc44 100644 --- a/engine/lib/web_services.php +++ b/engine/lib/web_services.php @@ -232,6 +232,7 @@ function execute_method($method) { $function = $API_METHODS[$method]["function"]; $serialised_parameters = trim($serialised_parameters, ", "); + // @todo document why we cannot use call_user_func_array here $result = eval("return $function($serialised_parameters);"); // Sanity check result @@ -1278,11 +1279,9 @@ function service_handler($handler, $request) { // no handlers set or bad url header("HTTP/1.0 404 Not Found"); exit; - } else if (isset($CONFIG->servicehandler[$handler]) - && is_callable($CONFIG->servicehandler[$handler])) { - + } else if (isset($CONFIG->servicehandler[$handler]) && is_callable($CONFIG->servicehandler[$handler])) { $function = $CONFIG->servicehandler[$handler]; - $function($request, $handler); + call_user_func($function, $request, $handler); } else { // no handler for this web service header("HTTP/1.0 404 Not Found"); @@ -1304,7 +1303,7 @@ function register_service_handler($handler, $function) { if (!isset($CONFIG->servicehandler)) { $CONFIG->servicehandler = array(); } - if (is_callable($function)) { + if (is_callable($function, true)) { $CONFIG->servicehandler[$handler] = $function; return true; } -- cgit v1.2.3 From 4f9fb7df0dabfa470e1f7045428c5e47a6ce3919 Mon Sep 17 00:00:00 2001 From: Steve Clay <steve@mrclay.org> Date: Wed, 14 Nov 2012 21:54:13 -0500 Subject: Style cleanup --- engine/lib/access.php | 11 +++-------- engine/lib/elgglib.php | 18 +++++++++--------- engine/lib/entities.php | 2 +- engine/lib/extender.php | 3 ++- engine/lib/pagehandler.php | 1 + engine/lib/views.php | 1 + engine/lib/web_services.php | 35 +++++++++++++++++++++++------------ 7 files changed, 40 insertions(+), 31 deletions(-) diff --git a/engine/lib/access.php b/engine/lib/access.php index e8b3b0d52..3b2b7aeaa 100644 --- a/engine/lib/access.php +++ b/engine/lib/access.php @@ -88,11 +88,7 @@ function get_access_array($user_id = 0, $site_id = 0, $flush = false) { // @todo everything from the db is cached. // this cache might be redundant. But db cache is flushed on every db write. - static $access_array; - - if (!isset($access_array)) { - $access_array = array(); - } + static $access_array = array(); if ($user_id == 0) { $user_id = elgg_get_logged_in_user_guid(); @@ -476,7 +472,7 @@ function can_edit_access_collection($collection_id, $user_guid = null) { return false; } - $write_access = get_write_access_array($user->getGUID(), null, true); + $write_access = get_write_access_array($user->getGUID(), 0, true); // don't ignore access when checking users. if ($user_guid) { @@ -560,8 +556,6 @@ function create_access_collection($name, $owner_guid = 0, $site_guid = 0) { * @see remove_user_from_access_collection() */ function update_access_collection($collection_id, $members) { - global $CONFIG; - $acl = get_access_collection($collection_id); if (!$acl) { @@ -1018,6 +1012,7 @@ function elgg_override_permissions($hook, $type, $value, $params) { */ function access_test($hook, $type, $value, $params) { global $CONFIG; + $value[] = $CONFIG->path . 'engine/tests/api/access_collections.php'; return $value; } diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php index 85610f0c2..974f38aad 100644 --- a/engine/lib/elgglib.php +++ b/engine/lib/elgglib.php @@ -671,7 +671,7 @@ function elgg_register_event_handler($event, $object_type, $callback, $priority global $CONFIG; if (empty($event) || empty($object_type)) { - return FALSE; + return false; } if (!isset($CONFIG->events)) { @@ -685,7 +685,7 @@ function elgg_register_event_handler($event, $object_type, $callback, $priority } if (!is_callable($callback, true)) { - return FALSE; + return false; } $priority = max((int) $priority, 0); @@ -695,7 +695,7 @@ function elgg_register_event_handler($event, $object_type, $callback, $priority } $CONFIG->events[$event][$object_type][$priority] = $callback; ksort($CONFIG->events[$event][$object_type]); - return TRUE; + return true; } /** @@ -770,14 +770,14 @@ function elgg_trigger_event($event, $object_type, $object = null) { foreach ($events as $callback_list) { if (is_array($callback_list)) { foreach ($callback_list as $callback) { - if (is_callable($callback) && (call_user_func_array($callback, $args) === FALSE)) { - return FALSE; + if (is_callable($callback) && (call_user_func_array($callback, $args) === false)) { + return false; } } } } - return TRUE; + return true; } /** @@ -850,7 +850,7 @@ function elgg_register_plugin_hook_handler($hook, $type, $callback, $priority = global $CONFIG; if (empty($hook) || empty($type)) { - return FALSE; + return false; } if (!isset($CONFIG->hooks)) { @@ -864,7 +864,7 @@ function elgg_register_plugin_hook_handler($hook, $type, $callback, $priority = } if (!is_callable($callback, true)) { - return FALSE; + return false; } $priority = max((int) $priority, 0); @@ -874,7 +874,7 @@ function elgg_register_plugin_hook_handler($hook, $type, $callback, $priority = } $CONFIG->hooks[$hook][$type][$priority] = $callback; ksort($CONFIG->hooks[$hook][$type]); - return TRUE; + return true; } /** diff --git a/engine/lib/entities.php b/engine/lib/entities.php index 5a5906b1f..a14160e14 100644 --- a/engine/lib/entities.php +++ b/engine/lib/entities.php @@ -1838,7 +1838,7 @@ function oddentity_to_elggentity(ODDEntity $element) { function import_entity_plugin_hook($hook, $entity_type, $returnvalue, $params) { $element = $params['element']; - $tmp = NULL; + $tmp = null; if ($element instanceof ODDEntity) { $tmp = oddentity_to_elggentity($element); diff --git a/engine/lib/extender.php b/engine/lib/extender.php index 636b711ea..538f601e1 100644 --- a/engine/lib/extender.php +++ b/engine/lib/extender.php @@ -141,9 +141,10 @@ function can_edit_extender($extender_id, $type, $user_guid = 0) { return false; } - if (!is_a($extender, "ElggExtender")) { + if (!($extender instanceof ElggExtender)) { return false; } + /* @var ElggExtender $extender */ // If the owner is the specified user, great! They can edit. if ($extender->getOwnerGUID() == $user->getGUID()) { diff --git a/engine/lib/pagehandler.php b/engine/lib/pagehandler.php index a53506812..0cf99b6fe 100644 --- a/engine/lib/pagehandler.php +++ b/engine/lib/pagehandler.php @@ -83,6 +83,7 @@ function page_handler($handler, $page) { */ function elgg_register_page_handler($handler, $function) { global $CONFIG; + if (!isset($CONFIG->pagehandler)) { $CONFIG->pagehandler = array(); } diff --git a/engine/lib/views.php b/engine/lib/views.php index e43c29cb2..8a0642c2b 100644 --- a/engine/lib/views.php +++ b/engine/lib/views.php @@ -1403,6 +1403,7 @@ function elgg_view_access_collections($owner_guid) { */ function set_template_handler($function_name) { global $CONFIG; + if (is_callable($function_name)) { $CONFIG->template_handler = $function_name; return true; diff --git a/engine/lib/web_services.php b/engine/lib/web_services.php index 39fb0dc44..c8e4a13cc 100644 --- a/engine/lib/web_services.php +++ b/engine/lib/web_services.php @@ -1195,6 +1195,8 @@ $ERRORS = array(); * * @return void * @access private + * + * @throws Exception */ function _php_api_error_handler($errno, $errmsg, $filename, $linenum, $vars) { global $ERRORS; @@ -1300,6 +1302,7 @@ function service_handler($handler, $request) { */ function register_service_handler($handler, $function) { global $CONFIG; + if (!isset($CONFIG->servicehandler)) { $CONFIG->servicehandler = array(); } @@ -1318,11 +1321,13 @@ function register_service_handler($handler, $function) { * * @param string $handler web services type * - * @return 1.7.0 + * @return void + * @since 1.7.0 */ function unregister_service_handler($handler) { global $CONFIG; - if (isset($CONFIG->servicehandler) && isset($CONFIG->servicehandler[$handler])) { + + if (isset($CONFIG->servicehandler, $CONFIG->servicehandler[$handler])) { unset($CONFIG->servicehandler[$handler]); } } @@ -1332,6 +1337,8 @@ function unregister_service_handler($handler) { * * @return void * @access private + * + * @throws SecurityException|APIException */ function rest_handler() { global $CONFIG; @@ -1386,7 +1393,7 @@ function rest_handler() { /** * Unit tests for API * - * @param sting $hook unit_test + * @param string $hook unit_test * @param string $type system * @param mixed $value Array of tests * @param mixed $params Params @@ -1396,6 +1403,7 @@ function rest_handler() { */ function api_unit_test($hook, $type, $value, $params) { global $CONFIG; + $value[] = $CONFIG->path . 'engine/tests/services/api.php'; return $value; } @@ -1417,15 +1425,18 @@ function api_init() { elgg_echo("system.api.list"), "GET", false, false); // The authentication token api - expose_function("auth.gettoken", - "auth_gettoken", array( - 'username' => array ('type' => 'string'), - 'password' => array ('type' => 'string'), - ), - elgg_echo('auth.gettoken'), - 'POST', - false, - false); + expose_function( + "auth.gettoken", + "auth_gettoken", + array( + 'username' => array ('type' => 'string'), + 'password' => array ('type' => 'string'), + ), + elgg_echo('auth.gettoken'), + 'POST', + false, + false + ); } -- cgit v1.2.3 From 28b76dca0de501efb2c908afb9b239f0f3c4a4d6 Mon Sep 17 00:00:00 2001 From: Steve Clay <steve@mrclay.org> Date: Wed, 14 Nov 2012 22:30:05 -0500 Subject: Prevent false testElggDeleteMetadata() failures --- engine/tests/api/metadata.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/engine/tests/api/metadata.php b/engine/tests/api/metadata.php index 9933263d1..825290d80 100644 --- a/engine/tests/api/metadata.php +++ b/engine/tests/api/metadata.php @@ -102,14 +102,14 @@ class ElggCoreMetadataAPITest extends ElggCoreUnitTest { $e = new ElggObject(); $e->save(); - for ($i=0; $i<30; $i++) { - $name = "test_metadata" . rand(0, 10000); + for ($i = 0; $i < 30; $i++) { + $name = "test_metadata$i"; $e->$name = rand(0, 10000); } $options = array( 'guid' => $e->getGUID(), - 'limit' => 0 + 'limit' => 0, ); $md = elgg_get_metadata($options); -- cgit v1.2.3 From cbf1943fe9b17ba371c533d2d6482ea8b2149d2e Mon Sep 17 00:00:00 2001 From: Matt Beckett <beck24@gmail.com> Date: Wed, 7 Nov 2012 15:16:49 -0700 Subject: Fixes #4896: Limit group profile RSS to seachable object types --- mod/groups/views/rss/groups/profile/layout.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/mod/groups/views/rss/groups/profile/layout.php b/mod/groups/views/rss/groups/profile/layout.php index 3eeb9eaf2..0dafe78ad 100644 --- a/mod/groups/views/rss/groups/profile/layout.php +++ b/mod/groups/views/rss/groups/profile/layout.php @@ -7,7 +7,12 @@ * @uses $vars['entity'] ElggGroup object */ -echo elgg_list_entities(array( - 'type' => 'object', - 'container_guid' => $vars['entity']->getGUID(), -)); +$entities = elgg_get_config('registered_entities'); + +if (!empty($entities['object'])) { + echo elgg_list_entities(array( + 'type' => 'object', + 'subtypes' => $entities['object'], + 'container_guid' => $vars['entity']->getGUID(), + )); +} -- cgit v1.2.3 From 5cce825ba165da9430b514a9c11532968e6c5af8 Mon Sep 17 00:00:00 2001 From: Steve Clay <steve@mrclay.org> Date: Thu, 15 Nov 2012 00:56:51 -0500 Subject: Blog forwarder cleanup & viewtype propagation --- mod/blog/lib/blog.php | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/mod/blog/lib/blog.php b/mod/blog/lib/blog.php index 4dcc7d56e..db6b7846f 100644 --- a/mod/blog/lib/blog.php +++ b/mod/blog/lib/blog.php @@ -408,25 +408,31 @@ function blog_prepare_form_vars($post = NULL, $revision = NULL) { * @param string $page */ function blog_url_forwarder($page) { - global $CONFIG; + + $viewtype = elgg_get_viewtype(); + $qs = ($viewtype === 'default') ? "" : "?view=$viewtype"; + + $url = "blog/all"; + + // easier to work with & no notices + $page = array_pad($page, 4, ""); // group usernames - if (substr_count(implode('/', $page), 'group:')) { - preg_match('/group\:([0-9]+)/i', implode('/', $page), $matches); + if (preg_match('~/group\:([0-9]+)/~', "/{$page[0]}/{$page[1]}/", $matches)) { $guid = $matches[1]; $entity = get_entity($guid); - if ($entity) { - if (isset($page[2])) { - $url = "{$CONFIG->wwwroot}blog/view/$page[2]/?view=" . elgg_get_viewtype(); + if (elgg_instanceof($entity, 'group')) { + if (!empty($page[2])) { + $url = "blog/view/$page[2]/"; } else { - $url = "{$CONFIG->wwwroot}blog/group/$guid/all?view=" . elgg_get_viewtype(); + $url = "blog/group/$guid/all"; } register_error(elgg_echo("changebookmark")); - forward($url); + forward($url . $qs); } } - if (!isset($page[0])) { + if (empty($page[0])) { return; } @@ -436,28 +442,28 @@ function blog_url_forwarder($page) { return; } - if (!isset($page[1])) { + if (empty($page[1])) { $page[1] = 'owner'; } switch ($page[1]) { case "read": - $url = "{$CONFIG->wwwroot}blog/view/{$page[2]}/{$page[3]}"; + $url = "blog/view/{$page[2]}/{$page[3]}"; break; case "archive": - $url = "{$CONFIG->wwwroot}blog/archive/{$page[0]}/{$page[2]}/{$page[3]}"; + $url = "blog/archive/{$page[0]}/{$page[2]}/{$page[3]}"; break; case "friends": - $url = "{$CONFIG->wwwroot}blog/friends/{$page[0]}"; + $url = "blog/friends/{$page[0]}"; break; case "new": - $url = "{$CONFIG->wwwroot}blog/add/$user->guid"; + $url = "blog/add/$user->guid"; break; case "owner": - $url = "{$CONFIG->wwwroot}blog/owner/{$page[0]}"; + $url = "blog/owner/{$page[0]}"; break; } register_error(elgg_echo("changebookmark")); - forward($url); + forward($url . $qs); } -- cgit v1.2.3 From 8a1cd5595970f6be4cfd3d8f10509cae8e51f192 Mon Sep 17 00:00:00 2001 From: Steve Clay <steve@mrclay.org> Date: Thu, 15 Nov 2012 01:04:58 -0500 Subject: Blog lib cleanup, logic simplification, remove notices & unused code --- mod/blog/lib/blog.php | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/mod/blog/lib/blog.php b/mod/blog/lib/blog.php index db6b7846f..3c71dfbab 100644 --- a/mod/blog/lib/blog.php +++ b/mod/blog/lib/blog.php @@ -50,7 +50,7 @@ function blog_get_page_content_read($guid = NULL) { /** * Get page components to list a user's or all blogs. * - * @param int $owner_guid The GUID of the page owner or NULL for all blogs + * @param int $container_guid The GUID of the page owner or NULL for all blogs * @return array */ function blog_get_page_content_list($container_guid = NULL) { @@ -62,10 +62,11 @@ function blog_get_page_content_list($container_guid = NULL) { $options = array( 'type' => 'object', 'subtype' => 'blog', - 'full_view' => FALSE, + 'full_view' => false, ); - $loggedin_userid = elgg_get_logged_in_user_guid(); + $current_user = elgg_get_logged_in_user_entity(); + if ($container_guid) { // access check for closed groups group_gatekeeper(); @@ -80,7 +81,7 @@ function blog_get_page_content_list($container_guid = NULL) { $crumbs_title = $container->name; elgg_push_breadcrumb($crumbs_title); - if ($container_guid == $loggedin_userid) { + if ($current_user && ($container_guid == $current_user->guid)) { $return['filter_context'] = 'mine'; } else if (elgg_instanceof($container, 'group')) { $return['filter'] = false; @@ -99,7 +100,13 @@ function blog_get_page_content_list($container_guid = NULL) { // show all posts for admin or users looking at their own blogs // show only published posts for other users. - if (!(elgg_is_admin_logged_in() || (elgg_is_logged_in() && $container_guid == $loggedin_userid))) { + $show_only_published = true; + if ($current_user) { + if (($current_user->guid == $container_guid) || $current_user->isAdmin()) { + $show_only_published = false; + } + } + if ($show_only_published) { $options['metadata_name_value_pairs'] = array( array('name' => 'status', 'value' => 'published'), ); @@ -155,11 +162,14 @@ function blog_get_page_content_friends($user_guid) { // admin / owners can see any posts // everyone else can only see published posts - if (!(elgg_is_admin_logged_in() || (elgg_is_logged_in() && $owner_guid == elgg_get_logged_in_user_guid()))) { - if ($upper > $now) { - $upper = $now; + $show_only_published = true; + $current_user = elgg_get_logged_in_user_entity(); + if ($current_user) { + if (($user_guid == $current_user->guid) || $current_user->isAdmin()) { + $show_only_published = false; } - + } + if ($show_only_published) { $options['metadata_name_value_pairs'][] = array( array('name' => 'status', 'value' => 'published') ); @@ -240,9 +250,9 @@ function blog_get_page_content_archive($owner_guid, $lower = 0, $upper = 0) { $list = elgg_list_entities_from_metadata($options); if (!$list) { - $content .= elgg_echo('blog:none'); + $content = elgg_echo('blog:none'); } else { - $content .= $list; + $content = $list; } $title = elgg_echo('date:month:' . date('m', $lower), array(date('Y', $lower))); @@ -274,6 +284,7 @@ function blog_get_page_content_edit($page, $guid = 0, $revision = NULL) { $vars['id'] = 'blog-post-edit'; $vars['class'] = 'elgg-form-alt'; + $sidebar = ''; if ($page == 'edit') { $blog = get_entity((int)$guid); @@ -310,14 +321,8 @@ function blog_get_page_content_edit($page, $guid = 0, $revision = NULL) { $content = elgg_echo('blog:error:cannot_edit_post'); } } else { - if (!$guid) { - $container = elgg_get_logged_in_user_entity(); - } else { - $container = get_entity($guid); - } - elgg_push_breadcrumb(elgg_echo('blog:add')); - $body_vars = blog_prepare_form_vars($blog); + $body_vars = blog_prepare_form_vars(null); $title = elgg_echo('blog:add'); $content = elgg_view_form('blog/save', $vars, $body_vars); @@ -384,7 +389,7 @@ function blog_prepare_form_vars($post = NULL, $revision = NULL) { if ($auto_save_annotations = $post->getAnnotations('blog_auto_save', 1)) { $auto_save = $auto_save_annotations[0]; } else { - $auto_save == FALSE; + $auto_save = false; } if ($auto_save && $auto_save->id != $revision->id) { -- cgit v1.2.3 From dca0df8297b578c85676b1ff868a2182981bee25 Mon Sep 17 00:00:00 2001 From: Lars Hærvig <lars@laptus.dk> Date: Wed, 31 Oct 2012 19:45:00 +0100 Subject: Limit messageboard posts to excerpts in activity stream --- .../default/river/object/messageboard/create.php | 23 +++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/mod/messageboard/views/default/river/object/messageboard/create.php b/mod/messageboard/views/default/river/object/messageboard/create.php index 7ce7f6b4e..ac10a55c1 100644 --- a/mod/messageboard/views/default/river/object/messageboard/create.php +++ b/mod/messageboard/views/default/river/object/messageboard/create.php @@ -1,11 +1,12 @@ -<?php -/** - * Messageboard river view - */ - -$messageboard = $vars['item']->getAnnotation(); - -echo elgg_view('river/elements/layout', array( - 'item' => $vars['item'], - 'message' => $messageboard->value, -)); +<?php +/** + * Messageboard river view + */ + +$messageboard = $vars['item']->getAnnotation(); +$excerpt = elgg_get_excerpt($messageboard->value); + +echo elgg_view('river/elements/layout', array( + 'item' => $vars['item'], + 'message' => $excerpt, +)); -- cgit v1.2.3 From d857c68fd91b1bcf586a30d86108b1898c2bb2d3 Mon Sep 17 00:00:00 2001 From: Steve Clay <steve@mrclay.org> Date: Mon, 29 Oct 2012 20:59:21 -0400 Subject: Fixes #4895: Output valid ETag and Expires headers --- engine/handlers/cache_handler.php | 6 +++--- engine/lib/elgglib.php | 2 +- mod/file/thumbnail.php | 2 +- mod/groups/icon.php | 6 +++--- mod/profile/icondirect.php | 18 +++++++----------- pages/avatar/view.php | 2 +- 6 files changed, 16 insertions(+), 20 deletions(-) diff --git a/engine/handlers/cache_handler.php b/engine/handlers/cache_handler.php index b332ec379..7706c2c92 100644 --- a/engine/handlers/cache_handler.php +++ b/engine/handlers/cache_handler.php @@ -64,7 +64,7 @@ $ts = $matches[4]; // If is the same ETag, content didn't changed. $etag = $ts; -if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && trim($_SERVER['HTTP_IF_NONE_MATCH']) == $etag) { +if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && trim($_SERVER['HTTP_IF_NONE_MATCH']) == "\"$etag\"") { header("HTTP/1.1 304 Not Modified"); exit; } @@ -80,10 +80,10 @@ switch ($type) { break; } -header('Expires: ' . date('r', strtotime("+6 months")), true); +header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', strtotime("+6 months")), true); header("Pragma: public", true); header("Cache-Control: public", true); -header("ETag: $etag"); +header("ETag: \"$etag\""); $filename = $dataroot . 'views_simplecache/' . md5($viewtype . $view); diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php index 974f38aad..dd3cba25d 100644 --- a/engine/lib/elgglib.php +++ b/engine/lib/elgglib.php @@ -1885,7 +1885,7 @@ function elgg_cacheable_view_page_handler($page, $type) { header("Content-type: $content_type"); // @todo should js be cached when simple cache turned off - //header('Expires: ' . date('r', time() + 864000)); + //header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', strtotime("+10 days")), true); //header("Pragma: public"); //header("Cache-Control: public"); //header("Content-Length: " . strlen($return)); diff --git a/mod/file/thumbnail.php b/mod/file/thumbnail.php index 35bf8c7f7..851f13a8f 100644 --- a/mod/file/thumbnail.php +++ b/mod/file/thumbnail.php @@ -46,7 +46,7 @@ if ($simpletype == "image") { // caching images for 10 days header("Content-type: $mime"); - header('Expires: ' . date('r',time() + 864000)); + header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', strtotime("+10 days")), true); header("Pragma: public", true); header("Cache-Control: public", true); header("Content-Length: " . strlen($contents)); diff --git a/mod/groups/icon.php b/mod/groups/icon.php index 1bd240ea6..ebdc1eb6d 100644 --- a/mod/groups/icon.php +++ b/mod/groups/icon.php @@ -18,7 +18,7 @@ if (!($group instanceof ElggGroup)) { // If is the same ETag, content didn't changed. $etag = $group->icontime . $group_guid; -if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && trim($_SERVER['HTTP_IF_NONE_MATCH']) == $etag) { +if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && trim($_SERVER['HTTP_IF_NONE_MATCH']) == "\"$etag\"") { header("HTTP/1.1 304 Not Modified"); exit; } @@ -46,9 +46,9 @@ if (!$success) { } header("Content-type: image/jpeg"); -header('Expires: ' . date('r',time() + 864000)); +header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', strtotime("+10 days")), true); header("Pragma: public"); header("Cache-Control: public"); header("Content-Length: " . strlen($contents)); -header("ETag: $etag"); +header("ETag: \"$etag\""); echo $contents; diff --git a/mod/profile/icondirect.php b/mod/profile/icondirect.php index c4439f78c..dbab5d31f 100644 --- a/mod/profile/icondirect.php +++ b/mod/profile/icondirect.php @@ -23,7 +23,7 @@ $guid = (int)$_GET['guid']; // If is the same ETag, content didn't changed. $etag = $last_cache . $guid; -if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && trim($_SERVER['HTTP_IF_NONE_MATCH']) == $etag) { +if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && trim($_SERVER['HTTP_IF_NONE_MATCH']) == "\"$etag\"") { header("HTTP/1.1 304 Not Modified"); exit; } @@ -55,19 +55,15 @@ if ($mysql_dblink) { $user_path = date('Y/m/d/', $join_date) . $guid; $filename = "$data_root$user_path/profile/{$guid}{$size}.jpg"; - $contents = @file_get_contents($filename); - if (!empty($contents)) { + $size = @filesize($filename); + if ($size) { header("Content-type: image/jpeg"); - header('Expires: ' . date('r', strtotime("+6 months")), true); + header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', strtotime("+6 months")), true); header("Pragma: public"); header("Cache-Control: public"); - header("Content-Length: " . strlen($contents)); - header("ETag: $etag"); - // this chunking is done for supposedly better performance - $split_string = str_split($contents, 1024); - foreach ($split_string as $chunk) { - echo $chunk; - } + header("Content-Length: $size"); + header("ETag: \"$etag\""); + readfile($filename); exit; } } diff --git a/pages/avatar/view.php b/pages/avatar/view.php index bd6c95821..10d81fef1 100644 --- a/pages/avatar/view.php +++ b/pages/avatar/view.php @@ -46,7 +46,7 @@ if (!$success) { } header("Content-type: image/jpeg", true); -header('Expires: ' . date('r', strtotime("+6 months")), true); +header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', strtotime("+6 months")), true); header("Pragma: public", true); header("Cache-Control: public", true); header("Content-Length: " . strlen($contents)); -- cgit v1.2.3 From 8183d5bbc2c18b6825da8ebfc15581231e23de04 Mon Sep 17 00:00:00 2001 From: Sem <sembrestels@riseup.net> Date: Sun, 8 Jul 2012 19:31:39 +0200 Subject: Fixes #1854. Group owners can delegate the ownership to another group member. --- mod/groups/actions/groups/edit.php | 33 ++++++++++++++++++++++++++ mod/groups/languages/en.php | 1 + mod/groups/views/default/forms/groups/edit.php | 31 ++++++++++++++++++++++++ mod/groups/views/default/groups/js.php | 25 +++++++++++++++++++ 4 files changed, 90 insertions(+) diff --git a/mod/groups/actions/groups/edit.php b/mod/groups/actions/groups/edit.php index 2d7e1f023..fa96345e0 100644 --- a/mod/groups/actions/groups/edit.php +++ b/mod/groups/actions/groups/edit.php @@ -92,6 +92,18 @@ if ($new_group_flag) { $group->access_id = ACCESS_PUBLIC; } +$owner_guid = (int) get_input('owner_guid'); +$loggedin_guid = elgg_get_logged_in_user_guid(); +$is_admin = elgg_is_admin_logged_in(); + +if (!$new_group_flag && $owner_guid && $owner_guid != $group->owner_guid) { + if($group->isMember($owner_guid) && ($group->owner_guid == $loggedin_guid || $is_admin)) { + $old_owner_guid = $group->owner_guid; + $group->owner_guid = $owner_guid; + $owner_changed_flag = true; + } +} + $group->save(); // Invisible group support @@ -167,6 +179,27 @@ if ((isset($_FILES['icon'])) && (substr_count($_FILES['icon']['type'],'image/')) $group->icontime = time(); } + + if ($owner_changed_flag) { + // @todo remove other user's pictures + } + +} elseif ($owner_changed_flag) { + + $filehandler = new ElggFile(); + $filehandler->setFilename('groups'); + + $filehandler->owner_guid = $old_owner_guid; + $old_path = $filehandler->getFilenameOnFilestore(); + + $filehandler->owner_guid = $group->owner_guid; + $new_path = $filehandler->getFilenameOnFilestore(); + + $sizes = array('', 'tiny', 'small', 'medium', 'large'); + + foreach($sizes as $size) { + rename("$old_path/{$group_guid}{$size}.jpg", "$new_path/{$group_guid}{$size}.jpg"); + } } system_message(elgg_echo("groups:saved")); diff --git a/mod/groups/languages/en.php b/mod/groups/languages/en.php index 0ca980108..67b0bbb89 100644 --- a/mod/groups/languages/en.php +++ b/mod/groups/languages/en.php @@ -19,6 +19,7 @@ $english = array( 'groups:add' => "Create a new group", 'groups:edit' => "Edit group", 'groups:delete' => 'Delete group', + 'groups:handover' => 'Hand over', 'groups:membershiprequests' => 'Manage join requests', 'groups:invitations' => 'Group invitations', diff --git a/mod/groups/views/default/forms/groups/edit.php b/mod/groups/views/default/forms/groups/edit.php index 532e89c35..52900d2d9 100644 --- a/mod/groups/views/default/forms/groups/edit.php +++ b/mod/groups/views/default/forms/groups/edit.php @@ -83,6 +83,37 @@ if (elgg_get_plugin_setting('hidden_groups', 'groups') == 'yes') { <?php } +if (isset($vars['entity'])) { + $entity = $vars['entity']; + $owner_guid = $vars['entity']->owner_guid; +} else { + $entity = false; +} + +if ($entity && ($owner_guid == elgg_get_logged_in_user_guid() || elgg_is_admin_logged_in())) { + $owner_guid = $vars['entity']->owner_guid; + $members = array(); + foreach ($vars['entity']->getMembers(0) as $member) { + $members[$member->guid] = "$member->name (@$member->username)"; + } +?> + +<div> + <label> + <?php echo elgg_echo('groups:owner'); ?><br /> + <?php echo elgg_view('input/dropdown', array( + 'name' => 'owner_guid', + 'value' => $owner_guid, + 'options_values' => $members, + 'class' => 'groups-owner-input', + )); + ?> + </label> +</div> + +<?php +} + $tools = elgg_get_config('group_tool_options'); if ($tools) { usort($tools, create_function('$a,$b', 'return strcmp($a->label,$b->label);')); diff --git a/mod/groups/views/default/groups/js.php b/mod/groups/views/default/groups/js.php index 1b4d33f32..c3698aadc 100644 --- a/mod/groups/views/default/groups/js.php +++ b/mod/groups/views/default/groups/js.php @@ -1,6 +1,31 @@ +<?php +/** + * Javascript for Groups forms + * + * @package ElggGroups + */ +?> // this adds a class to support IE8 and older elgg.register_hook_handler('init', 'system', function() { // jQuery uses 0-based indexing $('#groups-tools').children('li:even').addClass('odd'); }); + +// Hide group owner dropdown +elgg.register_hook_handler('init', 'system', function() { + $('.groups-owner-input').hide().each(function(){ + $(this).after($( + '<?php + echo elgg_view('output/url', array( + 'text' => elgg_echo('groups:handover'), + 'rel' => 'toggle', + 'class' => 'elgg-button elgg-button-delete', + )); + ?>' + ).click(function(){ + $(this).hide() + .prev().show(); + })); + }); +}); -- cgit v1.2.3 From 004c2fbbb557ba2de60c2f05853d0f892383df45 Mon Sep 17 00:00:00 2001 From: Sem <sembrestels@riseup.net> Date: Tue, 17 Jul 2012 18:18:28 +0200 Subject: Refs #1854. Using text to warn of the handover, instead the toggle with javascript. --- mod/groups/languages/en.php | 2 +- mod/groups/views/default/forms/groups/edit.php | 5 +++++ mod/groups/views/default/groups/js.php | 18 ------------------ 3 files changed, 6 insertions(+), 19 deletions(-) diff --git a/mod/groups/languages/en.php b/mod/groups/languages/en.php index 67b0bbb89..0d57f1680 100644 --- a/mod/groups/languages/en.php +++ b/mod/groups/languages/en.php @@ -19,7 +19,6 @@ $english = array( 'groups:add' => "Create a new group", 'groups:edit' => "Edit group", 'groups:delete' => 'Delete group', - 'groups:handover' => 'Hand over', 'groups:membershiprequests' => 'Manage join requests', 'groups:invitations' => 'Group invitations', @@ -36,6 +35,7 @@ $english = array( 'groups:membership' => "Group membership permissions", 'groups:access' => "Access permissions", 'groups:owner' => "Owner", + 'groups:owner:warning' => "Warning: if you change this value, you will no longer be the owner of this group.", 'groups:widget:num_display' => 'Number of groups to display', 'groups:widget:membership' => 'Group membership', 'groups:widgets:description' => 'Display the groups you are a member of on your profile', diff --git a/mod/groups/views/default/forms/groups/edit.php b/mod/groups/views/default/forms/groups/edit.php index 52900d2d9..7a740b878 100644 --- a/mod/groups/views/default/forms/groups/edit.php +++ b/mod/groups/views/default/forms/groups/edit.php @@ -109,6 +109,11 @@ if ($entity && ($owner_guid == elgg_get_logged_in_user_guid() || elgg_is_admin_l )); ?> </label> + <?php + if ($owner_guid == elgg_get_logged_in_user_guid()) { + echo '<span class="elgg-text-help">' . elgg_echo('groups:owner:warning') . '</span>'; + } + ?> </div> <?php diff --git a/mod/groups/views/default/groups/js.php b/mod/groups/views/default/groups/js.php index c3698aadc..0319be14a 100644 --- a/mod/groups/views/default/groups/js.php +++ b/mod/groups/views/default/groups/js.php @@ -11,21 +11,3 @@ elgg.register_hook_handler('init', 'system', function() { // jQuery uses 0-based indexing $('#groups-tools').children('li:even').addClass('odd'); }); - -// Hide group owner dropdown -elgg.register_hook_handler('init', 'system', function() { - $('.groups-owner-input').hide().each(function(){ - $(this).after($( - '<?php - echo elgg_view('output/url', array( - 'text' => elgg_echo('groups:handover'), - 'rel' => 'toggle', - 'class' => 'elgg-button elgg-button-delete', - )); - ?>' - ).click(function(){ - $(this).hide() - .prev().show(); - })); - }); -}); -- cgit v1.2.3 From 158a02f263a2d48e9832b5f403b04f3fdcf21ac4 Mon Sep 17 00:00:00 2001 From: Sem <sembrestels@riseup.net> Date: Tue, 17 Jul 2012 19:59:48 +0200 Subject: Refs #1854. Removing old owner icons when changing the owner and changing the icon at the same time. --- mod/groups/actions/groups/edit.php | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/mod/groups/actions/groups/edit.php b/mod/groups/actions/groups/edit.php index fa96345e0..d8c7a7566 100644 --- a/mod/groups/actions/groups/edit.php +++ b/mod/groups/actions/groups/edit.php @@ -100,7 +100,10 @@ if (!$new_group_flag && $owner_guid && $owner_guid != $group->owner_guid) { if($group->isMember($owner_guid) && ($group->owner_guid == $loggedin_guid || $is_admin)) { $old_owner_guid = $group->owner_guid; $group->owner_guid = $owner_guid; + + // @todo Remove this when #4683 fixed $owner_changed_flag = true; + $old_icontime = $group->icontime; } } @@ -180,11 +183,22 @@ if ((isset($_FILES['icon'])) && (substr_count($_FILES['icon']['type'],'image/')) $group->icontime = time(); } - if ($owner_changed_flag) { - // @todo remove other user's pictures + if ($owner_changed_flag && $old_icontime) { // @todo Remove this when #4683 fixed + + $filehandler = new ElggFile(); + $filehandler->setFilename('groups'); + + $filehandler->owner_guid = $old_owner_guid; + $old_path = $filehandler->getFilenameOnFilestore(); + + $sizes = array('', 'tiny', 'small', 'medium', 'large'); + + foreach($sizes as $size) { + unlink("$old_path/{$group_guid}{$size}.jpg"); + } } -} elseif ($owner_changed_flag) { +} elseif ($owner_changed_flag && $old_icontime) { // @todo Remove this when #4683 fixed $filehandler = new ElggFile(); $filehandler->setFilename('groups'); -- cgit v1.2.3 From f189ceb861d8456844f9d588f1582a5a5c49a9dc Mon Sep 17 00:00:00 2001 From: Steve Clay <steve@mrclay.org> Date: Sun, 18 Nov 2012 10:59:17 -0500 Subject: Group edit action refactoring --- mod/groups/actions/groups/edit.php | 164 +++++++++++++++++-------------------- 1 file changed, 75 insertions(+), 89 deletions(-) diff --git a/mod/groups/actions/groups/edit.php b/mod/groups/actions/groups/edit.php index d8c7a7566..d0689be2e 100644 --- a/mod/groups/actions/groups/edit.php +++ b/mod/groups/actions/groups/edit.php @@ -5,9 +5,6 @@ * @package ElggGroups */ -// Load configuration -global $CONFIG; - elgg_make_sticky_form('groups'); /** @@ -19,9 +16,10 @@ function profile_array_decoder(&$v) { // Get group fields $input = array(); -foreach ($CONFIG->group as $shortname => $valuetype) { - // another work around for Elgg's encoding problems: #561, #1963 +foreach (elgg_get_config('group') as $shortname => $valuetype) { $input[$shortname] = get_input($shortname); + + // @todo treat profile fields as unescaped: don't filter, encode on output if (is_array($input[$shortname])) { array_walk_recursive($input[$shortname], 'profile_array_decoder'); } else { @@ -38,15 +36,17 @@ $input['name'] = htmlspecialchars(get_input('name', '', false), ENT_QUOTES, 'UTF $user = elgg_get_logged_in_user_entity(); $group_guid = (int)get_input('group_guid'); -$new_group_flag = $group_guid == 0; +$is_new_group = $group_guid == 0; -if ($new_group_flag && elgg_get_plugin_setting('limited_groups', 'groups') == 'yes' && !elgg_is_admin_logged_in()) { +if ($is_new_group + && (elgg_get_plugin_setting('limited_groups', 'groups') == 'yes') + && !$user->isAdmin()) { register_error(elgg_echo("groups:cantcreate")); forward(REFERER); } $group = new ElggGroup($group_guid); // load if present, if not create a new group -if (($group_guid) && (!$group->canEdit())) { +if ($group_guid && !$group->canEdit()) { register_error(elgg_echo("groups:cantedit")); forward(REFERER); } @@ -61,52 +61,46 @@ if (sizeof($input) > 0) { // Validate create if (!$group->name) { register_error(elgg_echo("groups:notitle")); - forward(REFERER); } // Set group tool options -if (isset($CONFIG->group_tool_options)) { - foreach ($CONFIG->group_tool_options as $group_option) { - $group_option_toggle_name = $group_option->name . "_enable"; - if ($group_option->default_on) { - $group_option_default_value = 'yes'; - } else { - $group_option_default_value = 'no'; - } - $group->$group_option_toggle_name = get_input($group_option_toggle_name, $group_option_default_value); +$tool_options = elgg_get_config('group_tool_options'); +if ($tool_options) { + foreach ($tool_options as $group_option) { + $option_toggle_name = $group_option->name . "_enable"; + $option_default = $group_option->default_on ? 'yes' : 'no'; + $group->$option_toggle_name = get_input($option_toggle_name, $option_default); } } // Group membership - should these be treated with same constants as access permissions? -switch (get_input('membership')) { - case ACCESS_PUBLIC: - $group->membership = ACCESS_PUBLIC; - break; - default: - $group->membership = ACCESS_PRIVATE; -} +$is_public_membership = (get_input('membership') == ACCESS_PUBLIC); +$group->membership = $is_public_membership ? ACCESS_PUBLIC : ACCESS_PRIVATE; -if ($new_group_flag) { +if ($is_new_group) { $group->access_id = ACCESS_PUBLIC; } -$owner_guid = (int) get_input('owner_guid'); -$loggedin_guid = elgg_get_logged_in_user_guid(); -$is_admin = elgg_is_admin_logged_in(); +$old_owner_guid = $is_new_group ? 0 : $group->owner_guid; +$new_owner_guid = (int) get_input('owner_guid'); -if (!$new_group_flag && $owner_guid && $owner_guid != $group->owner_guid) { - if($group->isMember($owner_guid) && ($group->owner_guid == $loggedin_guid || $is_admin)) { - $old_owner_guid = $group->owner_guid; - $group->owner_guid = $owner_guid; +$owner_has_changed = false; +$old_icontime = null; +if (!$is_new_group && $new_owner_guid && $new_owner_guid != $old_owner_guid) { + // verify new owner is member and old owner/admin is logged in + if (is_group_member($group_guid, $new_owner_guid) && ($old_owner_guid == $user->guid || $user->isAdmin())) { + $group->owner_guid = $new_owner_guid; // @todo Remove this when #4683 fixed - $owner_changed_flag = true; - $old_icontime = $group->icontime; + $owner_has_changed = true; + $old_icontime = $group->icontime; } } +$must_move_icons = ($owner_has_changed && $old_icontime); + $group->save(); // Invisible group support @@ -130,14 +124,18 @@ $group->save(); elgg_clear_sticky_form('groups'); // group creator needs to be member of new group and river entry created -if ($new_group_flag) { +if ($is_new_group) { + + // @todo this should not be necessary... elgg_set_page_owner_guid($group->guid); + $group->join($user); add_to_river('river/group/create', 'create', $user->guid, $group->guid, $group->access_id); } -// Now see if we have a file icon -if ((isset($_FILES['icon'])) && (substr_count($_FILES['icon']['type'],'image/'))) { +$has_uploaded_icon = (!empty($_FILES['icon']['type']) && substr_count($_FILES['icon']['type'], 'image/')); + +if ($has_uploaded_icon) { $icon_sizes = elgg_get_config('icon_sizes'); @@ -149,70 +147,58 @@ if ((isset($_FILES['icon'])) && (substr_count($_FILES['icon']['type'],'image/')) $filehandler->open("write"); $filehandler->write(get_uploaded_file('icon')); $filehandler->close(); + $filename = $filehandler->getFilenameOnFilestore(); + + $sizes = array('tiny', 'small', 'medium', 'large'); + + $thumbs = array(); + foreach ($sizes as $size) { + $thumbs[$size] = get_resized_image_from_existing_file( + $filename, + $icon_sizes[$size]['w'], + $icon_sizes[$size]['h'], + $icon_sizes[$size]['square'] + ); + } - $thumbtiny = get_resized_image_from_existing_file($filehandler->getFilenameOnFilestore(), $icon_sizes['tiny']['w'], $icon_sizes['tiny']['h'], $icon_sizes['tiny']['square']); - $thumbsmall = get_resized_image_from_existing_file($filehandler->getFilenameOnFilestore(), $icon_sizes['small']['w'], $icon_sizes['small']['h'], $icon_sizes['small']['square']); - $thumbmedium = get_resized_image_from_existing_file($filehandler->getFilenameOnFilestore(), $icon_sizes['medium']['w'], $icon_sizes['medium']['h'], $icon_sizes['medium']['square']); - $thumblarge = get_resized_image_from_existing_file($filehandler->getFilenameOnFilestore(), $icon_sizes['large']['w'], $icon_sizes['large']['h'], $icon_sizes['large']['square']); - if ($thumbtiny) { - + if ($thumbs['tiny']) { // just checking if resize successful $thumb = new ElggFile(); $thumb->owner_guid = $group->owner_guid; $thumb->setMimeType('image/jpeg'); - $thumb->setFilename($prefix."tiny.jpg"); - $thumb->open("write"); - $thumb->write($thumbtiny); - $thumb->close(); - - $thumb->setFilename($prefix."small.jpg"); - $thumb->open("write"); - $thumb->write($thumbsmall); - $thumb->close(); - - $thumb->setFilename($prefix."medium.jpg"); - $thumb->open("write"); - $thumb->write($thumbmedium); - $thumb->close(); - - $thumb->setFilename($prefix."large.jpg"); - $thumb->open("write"); - $thumb->write($thumblarge); - $thumb->close(); + foreach ($sizes as $size) { + $thumb->setFilename("{$prefix}{$size}.jpg"); + $thumb->open("write"); + $thumb->write($thumbs[$size]); + $thumb->close(); + } $group->icontime = time(); } - - if ($owner_changed_flag && $old_icontime) { // @todo Remove this when #4683 fixed - - $filehandler = new ElggFile(); - $filehandler->setFilename('groups'); - - $filehandler->owner_guid = $old_owner_guid; - $old_path = $filehandler->getFilenameOnFilestore(); - - $sizes = array('', 'tiny', 'small', 'medium', 'large'); - - foreach($sizes as $size) { - unlink("$old_path/{$group_guid}{$size}.jpg"); - } - } - -} elseif ($owner_changed_flag && $old_icontime) { // @todo Remove this when #4683 fixed - +} + +// @todo Remove this when #4683 fixed +if ($must_move_icons) { $filehandler = new ElggFile(); $filehandler->setFilename('groups'); - $filehandler->owner_guid = $old_owner_guid; $old_path = $filehandler->getFilenameOnFilestore(); - - $filehandler->owner_guid = $group->owner_guid; - $new_path = $filehandler->getFilenameOnFilestore(); - + $sizes = array('', 'tiny', 'small', 'medium', 'large'); - - foreach($sizes as $size) { - rename("$old_path/{$group_guid}{$size}.jpg", "$new_path/{$group_guid}{$size}.jpg"); + + if ($has_uploaded_icon) { + // delete those under old owner + foreach ($sizes as $size) { + unlink("$old_path/{$group_guid}{$size}.jpg"); + } + } else { + // move existing to new owner + $filehandler->owner_guid = $group->owner_guid; + $new_path = $filehandler->getFilenameOnFilestore(); + + foreach ($sizes as $size) { + rename("$old_path/{$group_guid}{$size}.jpg", "$new_path/{$group_guid}{$size}.jpg"); + } } } -- cgit v1.2.3 From 63cc3777af6922ab5de1f6f96bcc6ebe08e7caf2 Mon Sep 17 00:00:00 2001 From: Steve Clay <steve@mrclay.org> Date: Wed, 21 Nov 2012 22:25:18 -0500 Subject: Fixes #4926: prefetches entities to be displayed in river --- engine/lib/river.php | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/engine/lib/river.php b/engine/lib/river.php index b717a7756..7bc3af9de 100644 --- a/engine/lib/river.php +++ b/engine/lib/river.php @@ -361,6 +361,7 @@ function elgg_get_river(array $options = array()) { } $river_items = get_data($query, 'elgg_row_to_elgg_river_item'); + _elgg_prefetch_river_entities($river_items); return $river_items; } else { @@ -369,12 +370,46 @@ function elgg_get_river(array $options = array()) { } } +/** + * Prefetch entities that will be displayed in the river. + * + * @param ElggRiverItem[] $river_items + * @access private + */ +function _elgg_prefetch_river_entities(array $river_items) { + // prefetch objects and subjects + $guids = array(); + foreach ($river_items as $item) { + $guids[$item->object_guid] = true; + $guids[$item->subject_guid] = true; + if (count($guids) > 100) { + break; + } + } + // return value unneeded, just priming cache + elgg_get_entities(array('guids' => array_keys($guids))); + + // prefetch object containers + $guids = array(); + foreach ($river_items as $item) { + $object = $item->getObjectEntity(); + if ($object) { + $guids[$object->container_guid] = true; + } + if (count($guids) > 100) { + break; + } + } + // return value unneeded, just priming cache + elgg_get_entities(array('guids' => array_keys($guids))); +} + /** * List river items * * @param array $options Any options from elgg_get_river() plus: * pagination => BOOL Display pagination links (true) - + * * @return string * @since 1.8.0 */ -- cgit v1.2.3 From 646c0c13b75efb55940245e27ad5c281a8eadd67 Mon Sep 17 00:00:00 2001 From: Steve Clay <steve@mrclay.org> Date: Sun, 25 Nov 2012 16:49:34 -0500 Subject: check entity cache first, and remove limit (from Paweł Sroka's branch) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- engine/lib/river.php | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/engine/lib/river.php b/engine/lib/river.php index 7bc3af9de..133ef6de9 100644 --- a/engine/lib/river.php +++ b/engine/lib/river.php @@ -380,28 +380,35 @@ function _elgg_prefetch_river_entities(array $river_items) { // prefetch objects and subjects $guids = array(); foreach ($river_items as $item) { - $guids[$item->object_guid] = true; - $guids[$item->subject_guid] = true; - if (count($guids) > 100) { - break; + if ($item->subject_guid && !retrieve_cached_entity($item->subject_guid)) { + $guids[$item->subject_guid] = true; + } + if ($item->object_guid && !retrieve_cached_entity($item->object_guid)) { + $guids[$item->object_guid] = true; } } + // avoid creating oversized query + // @todo how to better handle this? + $guids = array_slice($guids, 0, 300, true); // return value unneeded, just priming cache - elgg_get_entities(array('guids' => array_keys($guids))); + elgg_get_entities(array( + 'guids' => array_keys($guids), + 'limit' => 0, + )); // prefetch object containers $guids = array(); foreach ($river_items as $item) { $object = $item->getObjectEntity(); - if ($object) { + if ($object->container_guid && !retrieve_cached_entity($object->container_guid)) { $guids[$object->container_guid] = true; } - if (count($guids) > 100) { - break; - } } - // return value unneeded, just priming cache - elgg_get_entities(array('guids' => array_keys($guids))); + $guids = array_slice($guids, 0, 300, true); + elgg_get_entities(array( + 'guids' => array_keys($guids), + 'limit' => 0, + )); } /** -- cgit v1.2.3 From 7ca70cd97dc3b7f728eb79dcacc7c2c972f129e0 Mon Sep 17 00:00:00 2001 From: Steve Clay <steve@mrclay.org> Date: Mon, 26 Nov 2012 01:20:30 -0500 Subject: Fixes #4932: Allow plugins to be saved in entity cache --- engine/lib/entities.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/engine/lib/entities.php b/engine/lib/entities.php index a14160e14..0b28750d5 100644 --- a/engine/lib/entities.php +++ b/engine/lib/entities.php @@ -59,9 +59,9 @@ function invalidate_cache_for_entity($guid) { function cache_entity(ElggEntity $entity) { global $ENTITY_CACHE; - // Don't cache entities while access control is off, otherwise they could be + // Don't cache non-plugin entities while access control is off, otherwise they could be // exposed to users who shouldn't see them when control is re-enabled. - if (elgg_get_ignore_access()) { + if (!($entity instanceof ElggPlugin) && elgg_get_ignore_access()) { return; } -- cgit v1.2.3 From 3a3027ac4bf011873a8b08d56c19fa1379cd0a07 Mon Sep 17 00:00:00 2001 From: Steve Clay <steve@mrclay.org> Date: Mon, 26 Nov 2012 01:32:46 -0500 Subject: river prefetch: Don't call elgg_get_entities if no GUIDs to fetch --- engine/lib/river.php | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/engine/lib/river.php b/engine/lib/river.php index 133ef6de9..33f34360e 100644 --- a/engine/lib/river.php +++ b/engine/lib/river.php @@ -387,14 +387,16 @@ function _elgg_prefetch_river_entities(array $river_items) { $guids[$item->object_guid] = true; } } - // avoid creating oversized query - // @todo how to better handle this? - $guids = array_slice($guids, 0, 300, true); - // return value unneeded, just priming cache - elgg_get_entities(array( - 'guids' => array_keys($guids), - 'limit' => 0, - )); + if ($guids) { + // avoid creating oversized query + // @todo how to better handle this? + $guids = array_slice($guids, 0, 300, true); + // return value unneeded, just priming cache + elgg_get_entities(array( + 'guids' => array_keys($guids), + 'limit' => 0, + )); + } // prefetch object containers $guids = array(); @@ -404,11 +406,13 @@ function _elgg_prefetch_river_entities(array $river_items) { $guids[$object->container_guid] = true; } } - $guids = array_slice($guids, 0, 300, true); - elgg_get_entities(array( - 'guids' => array_keys($guids), - 'limit' => 0, - )); + if ($guids) { + $guids = array_slice($guids, 0, 300, true); + elgg_get_entities(array( + 'guids' => array_keys($guids), + 'limit' => 0, + )); + } } /** -- cgit v1.2.3 From e83db6a59a42902e4d6e112dda4ced4a749b6d39 Mon Sep 17 00:00:00 2001 From: Paweł Sroka <srokap@gmail.com> Date: Mon, 26 Nov 2012 11:46:44 +0100 Subject: Fixes #4933 - Adds plugin_id to GUID lookup map --- engine/lib/plugins.php | 62 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 45 insertions(+), 17 deletions(-) diff --git a/engine/lib/plugins.php b/engine/lib/plugins.php index d5cd4fe76..127d4bf8e 100644 --- a/engine/lib/plugins.php +++ b/engine/lib/plugins.php @@ -107,6 +107,7 @@ function elgg_generate_plugin_entities() { $old_access = access_get_show_hidden_status(); access_show_hidden_entities(true); $known_plugins = elgg_get_entities_from_relationship($options); + _elgg_add_plugin_ids_mapping($known_plugins); if (!$known_plugins) { $known_plugins = array(); @@ -151,6 +152,7 @@ function elgg_generate_plugin_entities() { // priority is force to last in save() if not set. $plugin = new ElggPlugin($plugin_id); $plugin->save(); + _elgg_add_plugin_ids_mapping(array($plugin)); } } @@ -175,6 +177,25 @@ function elgg_generate_plugin_entities() { return true; } +/** + * Registers given plugins in plugin_id to entity mapping data structure + * + * @param array $plugins ElggPlugin instances to be registered + * + * @access private + */ +function _elgg_add_plugin_ids_mapping($plugins) { + global $CONFIG; + if (!is_array($CONFIG->plugin_ids_mapping)) { + $CONFIG->plugin_ids_mapping = array(); + } + foreach ($plugins as $plugin) { + if ($plugin instanceof ElggPlugin) { + $CONFIG->plugin_ids_mapping[$plugin->getID()] = $plugin; + } + } +} + /** * Returns an ElggPlugin object with the path $path. * @@ -183,24 +204,30 @@ function elgg_generate_plugin_entities() { * @since 1.8.0 */ function elgg_get_plugin_from_id($plugin_id) { - $plugin_id = sanitize_string($plugin_id); - $db_prefix = get_config('dbprefix'); - - $options = array( - 'type' => 'object', - 'subtype' => 'plugin', - 'joins' => array("JOIN {$db_prefix}objects_entity oe on oe.guid = e.guid"), - 'wheres' => array("oe.title = '$plugin_id'"), - 'limit' => 1 - ); - - $plugins = elgg_get_entities($options); - - if ($plugins) { - return $plugins[0]; + global $CONFIG; + if (isset($CONFIG->plugin_ids_mapping[$plugin_id])) { + return $CONFIG->plugin_ids_mapping[$plugin_id]; + } else { + $plugin_id = sanitize_string($plugin_id); + $db_prefix = get_config('dbprefix'); + + $options = array( + 'type' => 'object', + 'subtype' => 'plugin', + 'joins' => array("JOIN {$db_prefix}objects_entity oe on oe.guid = e.guid"), + 'wheres' => array("oe.title = '$plugin_id'"), + 'limit' => 1 + ); + + $plugins = elgg_get_entities($options); + + if ($plugins) { + _elgg_add_plugin_ids_mapping($plugins); + return $plugins[0]; + } + + return false; } - - return false; } /** @@ -390,6 +417,7 @@ function elgg_get_plugins($status = 'active', $site_guid = null) { $old_ia = elgg_set_ignore_access(true); $plugins = elgg_get_entities_from_relationship($options); + _elgg_add_plugin_ids_mapping($plugins); elgg_set_ignore_access($old_ia); return $plugins; -- cgit v1.2.3 From 6c4e75b19ddadaadac9bc78423a837045fa90b15 Mon Sep 17 00:00:00 2001 From: Paweł Sroka <srokap@gmail.com> Date: Mon, 26 Nov 2012 21:16:04 +0100 Subject: Fixes #4927 - Removes obsolete commas in JS code for IE7 compatibility --- js/lib/ui.js | 2 +- js/tests/ElggLibTest.js | 2 +- views/default/js/walled_garden.php | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/js/lib/ui.js b/js/lib/ui.js index 616e71d54..2a4d269d6 100644 --- a/js/lib/ui.js +++ b/js/lib/ui.js @@ -283,7 +283,7 @@ elgg.ui.initDatePicker = function() { dataType: "script", cache: true, success: loadDatePicker, - error: loadDatePicker, // english language is already loaded. + error: loadDatePicker // english language is already loaded. }); } }; diff --git a/js/tests/ElggLibTest.js b/js/tests/ElggLibTest.js index a29ebf743..2a676e22a 100644 --- a/js/tests/ElggLibTest.js +++ b/js/tests/ElggLibTest.js @@ -99,7 +99,7 @@ ElggLibTest.prototype.testNormalizeUrl = function() { ['/mod/plugin/file.php', elgg.config.wwwroot + 'mod/plugin/file.php'], ['/mod/plugin/file.php?p=v&p2=v2', elgg.config.wwwroot + 'mod/plugin/file.php?p=v&p2=v2'], ['/rootfile.php', elgg.config.wwwroot + 'rootfile.php'], - ['/rootfile.php?p=v&p2=v2', elgg.config.wwwroot + 'rootfile.php?p=v&p2=v2'], + ['/rootfile.php?p=v&p2=v2', elgg.config.wwwroot + 'rootfile.php?p=v&p2=v2'] ].forEach(function(args) { assertEquals(args[1], elgg.normalize_url(args[0])); diff --git a/views/default/js/walled_garden.php b/views/default/js/walled_garden.php index 13ec83c04..99d050505 100644 --- a/views/default/js/walled_garden.php +++ b/views/default/js/walled_garden.php @@ -47,10 +47,10 @@ elgg.walled_garden.load = function(view) { $(id).find('input.elgg-button-submit').after('<?php echo $cancel_button; ?>'); $('#elgg-walledgarden-login').fadeToggle(); $(id).fadeToggle(); - }, + } }); event.preventDefault(); - }; + }; }; elgg.register_hook_handler('init', 'system', elgg.walled_garden.init); \ No newline at end of file -- cgit v1.2.3 From 1965e4d3642e3e8bcf53c83a85aa79765541a50e Mon Sep 17 00:00:00 2001 From: Steve Clay <steve@mrclay.org> Date: Mon, 26 Nov 2012 16:28:07 -0500 Subject: JS views: enable syntax highlighting and add missing semicolons --- views/default/js/admin.php | 11 ++++++----- views/default/js/elgg.php | 1 + views/default/js/initialize_elgg.php | 1 + views/default/js/lightbox.php | 1 + views/default/js/walled_garden.php | 1 + 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/views/default/js/admin.php b/views/default/js/admin.php index 5cefba512..e8aa0d2ed 100644 --- a/views/default/js/admin.php +++ b/views/default/js/admin.php @@ -4,8 +4,9 @@ * * @since 1.8 */ + +if (0) { ?><script><?php } ?> -//<script> elgg.provide('elgg.admin'); elgg.admin.init = function () { @@ -47,7 +48,7 @@ elgg.admin.init = function () { // admin notices delete ajax $('a.elgg-admin-notice').click(elgg.admin.deleteNotice); -} +}; /** * Save the plugin order after a move event. @@ -88,7 +89,7 @@ elgg.admin.editProfileField = function(value, settings) { elgg.action('profile/fields/edit', data); return value; -} +}; /** * Save the plugin profile order after a move event. @@ -104,7 +105,7 @@ elgg.admin.moveProfileField = function(e, ui) { elgg.action('profile/fields/reorder', { fieldorder: orderStr }); -} +}; /** * Fires the ajax action to delete the admin notice then hides the notice. @@ -120,6 +121,6 @@ elgg.admin.deleteNotice = function(e) { $container.slideUp('medium'); } }); -} +}; elgg.register_hook_handler('init', 'system', elgg.admin.init, 1000); \ No newline at end of file diff --git a/views/default/js/elgg.php b/views/default/js/elgg.php index 6460e93d6..b82d98ce4 100644 --- a/views/default/js/elgg.php +++ b/views/default/js/elgg.php @@ -50,6 +50,7 @@ foreach ($libs as $file) { /** * Set some values that are cacheable */ +if (0) { ?><script><?php } ?> elgg.version = '<?php echo get_version(); ?>'; diff --git a/views/default/js/initialize_elgg.php b/views/default/js/initialize_elgg.php index f8234f84f..b45c33463 100644 --- a/views/default/js/initialize_elgg.php +++ b/views/default/js/initialize_elgg.php @@ -3,6 +3,7 @@ * Initialize Elgg's js lib with the uncacheable data */ +if (0) { ?><script><?php } ?> /** * Don't want to cache these -- they could change for every request diff --git a/views/default/js/lightbox.php b/views/default/js/lightbox.php index c45d46098..d2bceaf90 100644 --- a/views/default/js/lightbox.php +++ b/views/default/js/lightbox.php @@ -16,6 +16,7 @@ * @todo add support for passing options: $('#myplugin-lightbox').elgg.ui.lightbox(options); */ +if (0) { ?><script><?php } ?> /** diff --git a/views/default/js/walled_garden.php b/views/default/js/walled_garden.php index 99d050505..7a482fe23 100644 --- a/views/default/js/walled_garden.php +++ b/views/default/js/walled_garden.php @@ -12,6 +12,7 @@ $cancel_button = elgg_view('input/button', array( )); $cancel_button = trim($cancel_button); +if (0) { ?><script><?php } ?> elgg.provide('elgg.walled_garden'); -- cgit v1.2.3 From 937119200300ebc2b09df4354fb7cd547535ecfb Mon Sep 17 00:00:00 2001 From: Steve Clay <steve@mrclay.org> Date: Mon, 26 Nov 2012 17:31:53 -0500 Subject: Refs #4933: cache in plugin constructor, remove $CONFIG --- engine/classes/ElggPlugin.php | 7 +++-- engine/lib/plugins.php | 69 +++++++++++++++++++------------------------ 2 files changed, 36 insertions(+), 40 deletions(-) diff --git a/engine/classes/ElggPlugin.php b/engine/classes/ElggPlugin.php index 3e43c8e81..c6ce2905f 100644 --- a/engine/classes/ElggPlugin.php +++ b/engine/classes/ElggPlugin.php @@ -36,8 +36,9 @@ class ElggPlugin extends ElggObject { * @warning Unlike other ElggEntity objects, you cannot null instantiate * ElggPlugin. You must point it to an actual plugin GUID or location. * - * @param mixed $plugin The GUID of the ElggPlugin object or the path of - * the plugin to load. + * @param mixed $plugin The GUID of the ElggPlugin object or the path of the plugin to load. + * + * @throws PluginException */ public function __construct($plugin) { if (!$plugin) { @@ -76,6 +77,8 @@ class ElggPlugin extends ElggObject { // load the rest of the plugin parent::__construct($existing_guid); } + + _elgg_cache_plugin_by_id($this); } /** diff --git a/engine/lib/plugins.php b/engine/lib/plugins.php index 127d4bf8e..ca4a957f4 100644 --- a/engine/lib/plugins.php +++ b/engine/lib/plugins.php @@ -107,7 +107,6 @@ function elgg_generate_plugin_entities() { $old_access = access_get_show_hidden_status(); access_show_hidden_entities(true); $known_plugins = elgg_get_entities_from_relationship($options); - _elgg_add_plugin_ids_mapping($known_plugins); if (!$known_plugins) { $known_plugins = array(); @@ -152,7 +151,6 @@ function elgg_generate_plugin_entities() { // priority is force to last in save() if not set. $plugin = new ElggPlugin($plugin_id); $plugin->save(); - _elgg_add_plugin_ids_mapping(array($plugin)); } } @@ -178,22 +176,16 @@ function elgg_generate_plugin_entities() { } /** - * Registers given plugins in plugin_id to entity mapping data structure + * Cache a reference to this plugin by its ID * - * @param array $plugins ElggPlugin instances to be registered + * @param ElggPlugin $plugin * * @access private */ -function _elgg_add_plugin_ids_mapping($plugins) { - global $CONFIG; - if (!is_array($CONFIG->plugin_ids_mapping)) { - $CONFIG->plugin_ids_mapping = array(); - } - foreach ($plugins as $plugin) { - if ($plugin instanceof ElggPlugin) { - $CONFIG->plugin_ids_mapping[$plugin->getID()] = $plugin; - } - } +function _elgg_cache_plugin_by_id(ElggPlugin $plugin) { + $map = (array) elgg_get_config('plugins_by_id_map'); + $map[$plugin->getID()] = $plugin; + elgg_set_config('plugins_by_id_map', $map); } /** @@ -204,30 +196,29 @@ function _elgg_add_plugin_ids_mapping($plugins) { * @since 1.8.0 */ function elgg_get_plugin_from_id($plugin_id) { - global $CONFIG; - if (isset($CONFIG->plugin_ids_mapping[$plugin_id])) { - return $CONFIG->plugin_ids_mapping[$plugin_id]; - } else { - $plugin_id = sanitize_string($plugin_id); - $db_prefix = get_config('dbprefix'); - - $options = array( - 'type' => 'object', - 'subtype' => 'plugin', - 'joins' => array("JOIN {$db_prefix}objects_entity oe on oe.guid = e.guid"), - 'wheres' => array("oe.title = '$plugin_id'"), - 'limit' => 1 - ); - - $plugins = elgg_get_entities($options); - - if ($plugins) { - _elgg_add_plugin_ids_mapping($plugins); - return $plugins[0]; - } - - return false; + $map = (array) elgg_get_config('plugins_by_id_map'); + if (isset($map[$plugin_id])) { + return $map[$plugin_id]; + } + + $plugin_id = sanitize_string($plugin_id); + $db_prefix = get_config('dbprefix'); + + $options = array( + 'type' => 'object', + 'subtype' => 'plugin', + 'joins' => array("JOIN {$db_prefix}objects_entity oe on oe.guid = e.guid"), + 'wheres' => array("oe.title = '$plugin_id'"), + 'limit' => 1 + ); + + $plugins = elgg_get_entities($options); + + if ($plugins) { + return $plugins[0]; } + + return false; } /** @@ -417,7 +408,6 @@ function elgg_get_plugins($status = 'active', $site_guid = null) { $old_ia = elgg_set_ignore_access(true); $plugins = elgg_get_entities_from_relationship($options); - _elgg_add_plugin_ids_mapping($plugins); elgg_set_ignore_access($old_ia); return $plugins; @@ -540,6 +530,8 @@ function elgg_namespace_plugin_private_setting($type, $name, $id = null) { * @return string|false Plugin name, or false if no plugin name was called * @since 1.8.0 * @access private + * + * @todo get rid of this */ function elgg_get_calling_plugin_id($mainfilename = false) { if (!$mainfilename) { @@ -948,6 +940,7 @@ function elgg_set_plugin_setting($name, $value, $plugin_id = null) { * * @return mixed * @since 1.8.0 + * @todo make $plugin_id required in future version */ function elgg_get_plugin_setting($name, $plugin_id = null) { if ($plugin_id) { -- cgit v1.2.3 From 04e73aa6428eb792bedbbd616891de52eed3dcbf Mon Sep 17 00:00:00 2001 From: Krzysztof Różalski <cristo.rabani@gmail.com> Date: Wed, 28 Nov 2012 00:09:05 +0100 Subject: Fixes #4935 - Adds admin listing in admin panel --- engine/lib/admin.php | 5 +++-- languages/en.php | 2 ++ views/default/admin/users/admins.php | 12 ++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 views/default/admin/users/admins.php diff --git a/engine/lib/admin.php b/engine/lib/admin.php index b65d98c95..3f23f079c 100644 --- a/engine/lib/admin.php +++ b/engine/lib/admin.php @@ -268,8 +268,9 @@ function admin_init() { // users elgg_register_admin_menu_item('administer', 'users', null, 20); elgg_register_admin_menu_item('administer', 'online', 'users', 10); - elgg_register_admin_menu_item('administer', 'newest', 'users', 20); - elgg_register_admin_menu_item('administer', 'add', 'users', 30); + elgg_register_admin_menu_item('administer', 'admins', 'users', 20); + elgg_register_admin_menu_item('administer', 'newest', 'users', 30); + elgg_register_admin_menu_item('administer', 'add', 'users', 40); // configure // plugins diff --git a/languages/en.php b/languages/en.php index 62b35dd81..2b5ba00fd 100644 --- a/languages/en.php +++ b/languages/en.php @@ -582,6 +582,7 @@ $english = array( 'admin:users' => "Users", 'admin:users:online' => 'Currently Online', 'admin:users:newest' => 'Newest', + 'admin:users:admins' => 'Administrators', 'admin:users:add' => 'Add New User', 'admin:users:description' => "This admin panel allows you to control user settings for your site. Choose an option below to get started.", 'admin:users:adduser:label' => "Click here to add a new user...", @@ -733,6 +734,7 @@ $english = array( 'admin:statistics:label:numusers' => "Number of users", 'admin:statistics:label:numonline' => "Number of users online", 'admin:statistics:label:onlineusers' => "Users online now", + 'admin:statistics:label:admins'=>"Admins", 'admin:statistics:label:version' => "Elgg version", 'admin:statistics:label:version:release' => "Release", 'admin:statistics:label:version:version' => "Version", diff --git a/views/default/admin/users/admins.php b/views/default/admin/users/admins.php new file mode 100644 index 000000000..9b175d437 --- /dev/null +++ b/views/default/admin/users/admins.php @@ -0,0 +1,12 @@ +<?php +$admins = elgg_list_entities(array(), 'elgg_get_admins'); + +?> +<div class="elgg-module elgg-module-inline"> + <div class="elgg-head"> + <h3><?php echo elgg_echo('admin:statistics:label:admins'); ?></h3> + </div> + <div class="elgg-body"> + <?php echo $admins; ?> + </div> +</div> -- cgit v1.2.3 From 2f0c5900465d3e12467cc5154394c44b6712759c Mon Sep 17 00:00:00 2001 From: Paweł Sroka <srokap@gmail.com> Date: Sun, 4 Nov 2012 04:39:50 +0100 Subject: Don't hit DB on elgg_get_config after putting all configuration into local object --- engine/lib/configuration.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/engine/lib/configuration.php b/engine/lib/configuration.php index 305aa00b6..540312481 100644 --- a/engine/lib/configuration.php +++ b/engine/lib/configuration.php @@ -95,11 +95,14 @@ function elgg_get_config($name, $site_guid = 0) { // installation wide setting $value = datalist_get($name); } else { - // site specific setting - if ($site_guid == 0) { - $site_guid = (int) $CONFIG->site_id; + // hit DB only if we're not sure if value exists or not + if (!isset($CONFIG->site_config_loaded)) { + // site specific setting + if ($site_guid == 0) { + $site_guid = (int) $CONFIG->site_id; + } + $value = get_config($name, $site_guid); } - $value = get_config($name, $site_guid); } if ($value !== false) { @@ -558,6 +561,8 @@ function _elgg_load_site_config() { $CONFIG->url = $CONFIG->wwwroot; get_all_config(); + // gives hint to elgg_get_config function how to approach missing values + $CONFIG->site_config_loaded = true; } /** -- cgit v1.2.3 From 8e0355da502d3e61e6c5ef66f34831cfbad6506e Mon Sep 17 00:00:00 2001 From: Steve Clay <steve@mrclay.org> Date: Tue, 27 Nov 2012 23:05:03 -0500 Subject: elgg_get_config: Don't generate NOTICE if $value not set --- engine/lib/configuration.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/engine/lib/configuration.php b/engine/lib/configuration.php index 540312481..b10e51130 100644 --- a/engine/lib/configuration.php +++ b/engine/lib/configuration.php @@ -91,7 +91,7 @@ function elgg_get_config($name, $site_guid = 0) { return $CONFIG->$name; } - if ($site_guid === NULL) { + if ($site_guid === null) { // installation wide setting $value = datalist_get($name); } else { @@ -102,15 +102,18 @@ function elgg_get_config($name, $site_guid = 0) { $site_guid = (int) $CONFIG->site_id; } $value = get_config($name, $site_guid); + } else { + $value = null; } } - if ($value !== false) { - $CONFIG->$name = $value; - return $value; + // @todo document why we don't cache false + if ($value === false) { + return null; } - return null; + $CONFIG->$name = $value; + return $value; } /** -- cgit v1.2.3 From f09e927d13ba0beb41121691fe531cbf76a0f37b Mon Sep 17 00:00:00 2001 From: Paweł Sroka <srokap@gmail.com> Date: Sun, 4 Nov 2012 11:25:42 +0100 Subject: Added caching of all subtypes with single query --- engine/lib/entities.php | 112 ++++++++++++++++++++++++++++++------------------ 1 file changed, 70 insertions(+), 42 deletions(-) diff --git a/engine/lib/entities.php b/engine/lib/entities.php index a14160e14..3642856bf 100644 --- a/engine/lib/entities.php +++ b/engine/lib/entities.php @@ -17,7 +17,7 @@ global $ENTITY_CACHE; $ENTITY_CACHE = array(); /** - * Cache subtypes and related class names once loaded. + * Cache subtypes and related class names. * * @global array $SUBTYPE_CACHE * @access private @@ -156,18 +156,15 @@ function get_subtype_id($type, $subtype) { if ($subtype == "") { return FALSE; } + + if (!$SUBTYPE_CACHE) { + populate_subtype_cache(); + } - // @todo use the cache before hitting database - $result = get_data_row("SELECT * from {$CONFIG->dbprefix}entity_subtypes - where type='$type' and subtype='$subtype'"); - - if ($result) { - if (!$SUBTYPE_CACHE) { - $SUBTYPE_CACHE = array(); - } - - $SUBTYPE_CACHE[$result->id] = $result; - return $result->id; + // use the cache before hitting database + $result = retrieve_cached_subtype($type, $subtype); + if ($result!==null) { + return $result->id; } return FALSE; @@ -192,21 +189,47 @@ function get_subtype_from_id($subtype_id) { return false; } + if (!$SUBTYPE_CACHE) { + populate_subtype_cache(); + } + if (isset($SUBTYPE_CACHE[$subtype_id])) { return $SUBTYPE_CACHE[$subtype_id]->subtype; } - $result = get_data_row("SELECT * from {$CONFIG->dbprefix}entity_subtypes where id=$subtype_id"); - if ($result) { - if (!$SUBTYPE_CACHE) { - $SUBTYPE_CACHE = array(); - } + return false; +} - $SUBTYPE_CACHE[$subtype_id] = $result; - return $result->subtype; +/** + * Retrieve subtype from the cache. + * + * @return stdClass|null + * @access private + */ +function retrieve_cached_subtype($type, $subtype) { + global $SUBTYPE_CACHE; + + foreach ($SUBTYPE_CACHE as $id => $obj) { + if ($obj->type==$type && $obj->subtype==$subtype) { + return $obj; + } } + return null; +} - return false; +/** + * Fetch all suptypes from DB to local cache. + * @access private + */ +function populate_subtype_cache() { + global $CONFIG, $SUBTYPE_CACHE; + + $results = get_data("SELECT * from {$CONFIG->dbprefix}entity_subtypes"); + + $SUBTYPE_CACHE = array(); + foreach ($results as $result) { + $SUBTYPE_CACHE[$result->id] = $result; + } } /** @@ -230,16 +253,13 @@ function get_subtype_class($type, $subtype) { $type = sanitise_string($type); $subtype = sanitise_string($subtype); - // @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'"); - - if ($result) { - if (!$SUBTYPE_CACHE) { - $SUBTYPE_CACHE = array(); - } - - $SUBTYPE_CACHE[$result->id] = $result; + if (!$SUBTYPE_CACHE) { + populate_subtype_cache(); + } + + // use the cache before going to the database + $result = retrieve_cached_subtype($type, $subtype); + if ($result!==null) { return $result->class; } @@ -265,20 +285,14 @@ function get_subtype_class_from_id($subtype_id) { return false; } + if (!$SUBTYPE_CACHE) { + populate_subtype_cache(); + } + if (isset($SUBTYPE_CACHE[$subtype_id])) { return $SUBTYPE_CACHE[$subtype_id]->class; } - $result = get_data_row("SELECT * from {$CONFIG->dbprefix}entity_subtypes where id=$subtype_id"); - - if ($result) { - if (!$SUBTYPE_CACHE) { - $SUBTYPE_CACHE = array(); - } - $SUBTYPE_CACHE[$subtype_id] = $result; - return $result->class; - } - return NULL; } @@ -305,7 +319,7 @@ function get_subtype_class_from_id($subtype_id) { * @see get_entity() */ function add_subtype($type, $subtype, $class = "") { - global $CONFIG; + global $CONFIG, $SUBTYPE_CACHE; $type = sanitise_string($type); $subtype = sanitise_string($subtype); $class = sanitise_string($class); @@ -318,8 +332,18 @@ function add_subtype($type, $subtype, $class = "") { $id = get_subtype_id($type, $subtype); if ($id == 0) { - return insert_data("insert into {$CONFIG->dbprefix}entity_subtypes" + $result = insert_data("insert into {$CONFIG->dbprefix}entity_subtypes" . " (type, subtype, class) values ('$type','$subtype','$class')"); + + // add entry to cache + $obj = new stdClass(); + $obj->id = $result; + $obj->type = $type; + $obj->subtype = $subtype; + $obj->class = $class; + $SUBTYPE_CACHE[$obj->id] = $obj; + + return $result; } return $id; @@ -367,6 +391,10 @@ function update_subtype($type, $subtype, $class = '') { $type = sanitise_string($type); $subtype = sanitise_string($subtype); + if (!$SUBTYPE_CACHE) { + populate_subtype_cache(); + } + $result = update_data("UPDATE {$CONFIG->dbprefix}entity_subtypes SET type = '$type', subtype = '$subtype', class = '$class' WHERE id = $id -- cgit v1.2.3 From 867d094d56df02ed93806f0c2c72890ecf762e41 Mon Sep 17 00:00:00 2001 From: Steve Clay <steve@mrclay.org> Date: Wed, 28 Nov 2012 00:27:53 -0500 Subject: Subtype functions cleanup --- engine/lib/entities.php | 178 ++++++++++++++++++++++++------------------------ 1 file changed, 90 insertions(+), 88 deletions(-) diff --git a/engine/lib/entities.php b/engine/lib/entities.php index 3642856bf..a1c1c2997 100644 --- a/engine/lib/entities.php +++ b/engine/lib/entities.php @@ -19,11 +19,11 @@ $ENTITY_CACHE = array(); /** * Cache subtypes and related class names. * - * @global array $SUBTYPE_CACHE + * @global array|null $SUBTYPE_CACHE array once populated from DB, initially null * @access private */ global $SUBTYPE_CACHE; -$SUBTYPE_CACHE = NULL; +$SUBTYPE_CACHE = null; /** * Invalidate this class's entry in the cache. @@ -87,8 +87,6 @@ function cache_entity(ElggEntity $entity) { function retrieve_cached_entity($guid) { global $ENTITY_CACHE; - $guid = (int)$guid; - if (isset($ENTITY_CACHE[$guid])) { if ($ENTITY_CACHE[$guid]->isFullyLoaded()) { return $ENTITY_CACHE[$guid]; @@ -148,26 +146,23 @@ function retrieve_cached_entity_row($guid) { * @access private */ function get_subtype_id($type, $subtype) { - global $CONFIG, $SUBTYPE_CACHE; + global $SUBTYPE_CACHE; - $type = sanitise_string($type); - $subtype = sanitise_string($subtype); - - if ($subtype == "") { - return FALSE; + if (!$subtype) { + return false; } - - if (!$SUBTYPE_CACHE) { - populate_subtype_cache(); + + if ($SUBTYPE_CACHE === null) { + _elgg_populate_subtype_cache(); } - // use the cache before hitting database - $result = retrieve_cached_subtype($type, $subtype); - if ($result!==null) { - return $result->id; + // use the cache before hitting database + $result = _elgg_retrieve_cached_subtype($type, $subtype); + if ($result !== null) { + return $result->id; } - return FALSE; + return false; } /** @@ -175,24 +170,22 @@ function get_subtype_id($type, $subtype) { * * @param int $subtype_id Subtype ID * - * @return string Subtype name + * @return string|false Subtype name, false if subtype not found * @link http://docs.elgg.org/DataModel/Entities/Subtypes * @see get_subtype_from_id() * @access private */ function get_subtype_from_id($subtype_id) { - global $CONFIG, $SUBTYPE_CACHE; - - $subtype_id = (int)$subtype_id; + global $SUBTYPE_CACHE; if (!$subtype_id) { return false; } - if (!$SUBTYPE_CACHE) { - populate_subtype_cache(); - } - + if ($SUBTYPE_CACHE === null) { + _elgg_populate_subtype_cache(); + } + if (isset($SUBTYPE_CACHE[$subtype_id])) { return $SUBTYPE_CACHE[$subtype_id]->subtype; } @@ -200,35 +193,43 @@ function get_subtype_from_id($subtype_id) { return false; } -/** - * Retrieve subtype from the cache. - * - * @return stdClass|null - * @access private - */ -function retrieve_cached_subtype($type, $subtype) { - global $SUBTYPE_CACHE; - - foreach ($SUBTYPE_CACHE as $id => $obj) { - if ($obj->type==$type && $obj->subtype==$subtype) { +/** + * Retrieve subtype from the cache. + * + * @param string $type + * @param string $subtype + * @return stdClass|null + * + * @access private + */ +function _elgg_retrieve_cached_subtype($type, $subtype) { + global $SUBTYPE_CACHE; + + if ($SUBTYPE_CACHE === null) { + _elgg_populate_subtype_cache(); + } + + foreach ($SUBTYPE_CACHE as $obj) { + if ($obj->type === $type && $obj->subtype === $subtype) { return $obj; } } - return null; + return null; } /** * Fetch all suptypes from DB to local cache. + * * @access private */ -function populate_subtype_cache() { +function _elgg_populate_subtype_cache() { global $CONFIG, $SUBTYPE_CACHE; - $results = get_data("SELECT * from {$CONFIG->dbprefix}entity_subtypes"); + $results = get_data("SELECT * FROM {$CONFIG->dbprefix}entity_subtypes"); $SUBTYPE_CACHE = array(); - foreach ($results as $result) { - $SUBTYPE_CACHE[$result->id] = $result; + foreach ($results as $row) { + $SUBTYPE_CACHE[$row->id] = $row; } } @@ -248,22 +249,19 @@ function populate_subtype_cache() { * @access private */ function get_subtype_class($type, $subtype) { - global $CONFIG, $SUBTYPE_CACHE; + global $SUBTYPE_CACHE; - $type = sanitise_string($type); - $subtype = sanitise_string($subtype); - - if (!$SUBTYPE_CACHE) { - populate_subtype_cache(); - } + if ($SUBTYPE_CACHE === null) { + _elgg_populate_subtype_cache(); + } // use the cache before going to the database - $result = retrieve_cached_subtype($type, $subtype); - if ($result!==null) { - return $result->class; + $obj = _elgg_retrieve_cached_subtype($type, $subtype); + if ($obj) { + return $obj->class; } - return NULL; + return null; } /** @@ -277,23 +275,21 @@ function get_subtype_class($type, $subtype) { * @access private */ function get_subtype_class_from_id($subtype_id) { - global $CONFIG, $SUBTYPE_CACHE; - - $subtype_id = (int)$subtype_id; + global $SUBTYPE_CACHE; if (!$subtype_id) { - return false; + return null; } - if (!$SUBTYPE_CACHE) { - populate_subtype_cache(); - } + if ($SUBTYPE_CACHE === null) { + _elgg_populate_subtype_cache(); + } if (isset($SUBTYPE_CACHE[$subtype_id])) { return $SUBTYPE_CACHE[$subtype_id]->class; } - return NULL; + return null; } /** @@ -320,30 +316,31 @@ function get_subtype_class_from_id($subtype_id) { */ function add_subtype($type, $subtype, $class = "") { global $CONFIG, $SUBTYPE_CACHE; - $type = sanitise_string($type); - $subtype = sanitise_string($subtype); - $class = sanitise_string($class); - // Short circuit if no subtype is given - if ($subtype == "") { + if (!$subtype) { return 0; } $id = get_subtype_id($type, $subtype); - if ($id == 0) { - $result = insert_data("insert into {$CONFIG->dbprefix}entity_subtypes" - . " (type, subtype, class) values ('$type','$subtype','$class')"); + if (!$id) { + // In cache we store non-SQL-escaped strings because that's what's returned by query + $cache_obj = (object) array( + 'type' => $type, + 'subtype' => $subtype, + 'class' => $class, + ); + + $type = sanitise_string($type); + $subtype = sanitise_string($subtype); + $class = sanitise_string($class); + + $id = insert_data("INSERT INTO {$CONFIG->dbprefix}entity_subtypes" + . " (type, subtype, class) VALUES ('$type', '$subtype', '$class')"); // add entry to cache - $obj = new stdClass(); - $obj->id = $result; - $obj->type = $type; - $obj->subtype = $subtype; - $obj->class = $class; - $SUBTYPE_CACHE[$obj->id] = $obj; - - return $result; + $cache_obj->id = $id; + $SUBTYPE_CACHE[$id] = $cache_obj; } return $id; @@ -385,26 +382,31 @@ function remove_subtype($type, $subtype) { function update_subtype($type, $subtype, $class = '') { global $CONFIG, $SUBTYPE_CACHE; - if (!$id = get_subtype_id($type, $subtype)) { - return FALSE; + $id = get_subtype_id($type, $subtype); + if (!$id) { + return false; } + + if ($SUBTYPE_CACHE === null) { + _elgg_populate_subtype_cache(); + } + + $unescaped_class = $class; + $type = sanitise_string($type); $subtype = sanitise_string($subtype); - - if (!$SUBTYPE_CACHE) { - populate_subtype_cache(); - } + $class = sanitise_string($class); - $result = update_data("UPDATE {$CONFIG->dbprefix}entity_subtypes + $success = update_data("UPDATE {$CONFIG->dbprefix}entity_subtypes SET type = '$type', subtype = '$subtype', class = '$class' WHERE id = $id "); - if ($result && isset($SUBTYPE_CACHE[$id])) { - $SUBTYPE_CACHE[$id]->class = $class; + if ($success && isset($SUBTYPE_CACHE[$id])) { + $SUBTYPE_CACHE[$id]->class = $unescaped_class; } - return $result; + return $success; } /** @@ -1800,7 +1802,7 @@ function oddentity_to_elggentity(ODDEntity $element) { if (!$tmp) { // Construct new class with owner from session $classname = get_subtype_class($class, $subclass); - if ($classname != "") { + if ($classname) { if (class_exists($classname)) { $tmp = new $classname(); -- cgit v1.2.3 From 87b2da7e3d8f06ba541fea29d44c4c2e9630584d Mon Sep 17 00:00:00 2001 From: Steve Clay <steve@mrclay.org> Date: Wed, 28 Nov 2012 16:05:35 -0500 Subject: Fixes #4937: Metadata cache is purged when entity cache item removed --- engine/lib/entities.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/engine/lib/entities.php b/engine/lib/entities.php index a1c1c2997..e9c96a596 100644 --- a/engine/lib/entities.php +++ b/engine/lib/entities.php @@ -68,7 +68,15 @@ function cache_entity(ElggEntity $entity) { // Don't store too many or we'll have memory problems // TODO(evan): Pick a less arbitrary limit if (count($ENTITY_CACHE) > 256) { - unset($ENTITY_CACHE[array_rand($ENTITY_CACHE)]); + $random_guid = array_rand($ENTITY_CACHE); + + unset($ENTITY_CACHE[$random_guid]); + + // Purge separate metadata cache. Original idea was to do in entity destructor, but that would + // have caused a bunch of unnecessary purges at every shutdown. Doing it this way we have no way + // to know that the expunged entity will be GCed (might be another reference living), but that's + // OK; the metadata will reload if necessary. + elgg_get_metadata_cache()->clear($random_guid); } $ENTITY_CACHE[$entity->guid] = $entity; -- cgit v1.2.3 From acdb5bf2b7e516ece1ab60256235973d2bfb0b04 Mon Sep 17 00:00:00 2001 From: Steve Clay <steve@mrclay.org> Date: Thu, 29 Nov 2012 15:29:42 -0500 Subject: Don't need htmlawed for ?view, prevent "Array" from being used as view type --- engine/lib/views.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/engine/lib/views.php b/engine/lib/views.php index 8a0642c2b..8b10fe3e0 100644 --- a/engine/lib/views.php +++ b/engine/lib/views.php @@ -101,15 +101,15 @@ function elgg_get_viewtype() { return $CURRENT_SYSTEM_VIEWTYPE; } - $viewtype = get_input('view', NULL); - if ($viewtype) { + $viewtype = get_input('view', '', false); + if (is_string($viewtype) && $viewtype !== '') { // only word characters allowed. - if (!preg_match('[\W]', $viewtype)) { + if (!preg_match('/\W/', $viewtype)) { return $viewtype; } } - if (isset($CONFIG->view) && !empty($CONFIG->view)) { + if (!empty($CONFIG->view)) { return $CONFIG->view; } -- cgit v1.2.3 From 2b4e77edc2f175c60d8513f2fc2fec5f6572f720 Mon Sep 17 00:00:00 2001 From: Steve Clay <steve@mrclay.org> Date: Thu, 29 Nov 2012 15:36:58 -0500 Subject: Views code/docs cleanup, remove unneeded vars/code --- engine/lib/views.php | 80 +++++++++++++++++++--------------------------------- 1 file changed, 29 insertions(+), 51 deletions(-) diff --git a/engine/lib/views.php b/engine/lib/views.php index 8b10fe3e0..e6932f17c 100644 --- a/engine/lib/views.php +++ b/engine/lib/views.php @@ -258,8 +258,6 @@ function elgg_get_view_location($view, $viewtype = '') { } else { return $CONFIG->views->locations[$viewtype][$view]; } - - return false; } /** @@ -329,7 +327,7 @@ function elgg_view_exists($view, $viewtype = '', $recurse = true) { $location = $CONFIG->views->locations[$viewtype][$view]; } - if (file_exists($location . "{$viewtype}/{$view}.php")) { + if (file_exists("{$location}{$viewtype}/{$view}.php")) { return true; } @@ -378,7 +376,7 @@ function elgg_view_exists($view, $viewtype = '', $recurse = true) { * @param boolean $bypass If set to true, elgg_view will bypass any specified * alternative template handler; by default, it will * hand off to this if requested (see set_template_handler) - * @param boolean $debug If set to true, the viewer will complain if it can't find a view + * @param boolean $ignored This argument is ignored and will be removed eventually * @param string $viewtype If set, forces the viewtype for the elgg_view call to be * this value (default: standard detection) * @@ -386,18 +384,14 @@ function elgg_view_exists($view, $viewtype = '', $recurse = true) { * @see set_template_handler() * @example views/elgg_view.php * @link http://docs.elgg.org/View - * @todo $debug isn't used. - * @todo $usercache is redundant. */ -function elgg_view($view, $vars = array(), $bypass = false, $debug = false, $viewtype = '') { +function elgg_view($view, $vars = array(), $bypass = false, $ignored = false, $viewtype = '') { global $CONFIG; - static $usercache; - $view = (string)$view; // basic checking for bad paths if (strpos($view, '..') !== false) { - return false; + return ''; } $view_orig = $view; @@ -408,9 +402,6 @@ function elgg_view($view, $vars = array(), $bypass = false, $debug = false, $vie elgg_trigger_event('pagesetup', 'system'); } - if (!is_array($usercache)) { - $usercache = array(); - } if (!is_array($vars)) { elgg_log("Vars in views must be an array: $view", 'ERROR'); @@ -496,6 +487,7 @@ function elgg_view($view, $vars = array(), $bypass = false, $debug = false, $vie ob_start(); foreach ($viewlist as $priority => $view) { + $view_location = elgg_get_view_location($view, $viewtype); $view_file = "$view_location$viewtype/$view.php"; @@ -533,7 +525,7 @@ function elgg_view($view, $vars = array(), $bypass = false, $debug = false, $vie // backward compatibility with less granular hook will be gone in 2.0 $content_tmp = elgg_trigger_plugin_hook('display', 'view', $params, $content); - if ($content_tmp != $content) { + if ($content_tmp !== $content) { $content = $content_tmp; elgg_deprecated_notice('The display:view plugin hook is deprecated by view:view_name', 1.8); } @@ -559,33 +551,32 @@ function elgg_view($view, $vars = array(), $bypass = false, $debug = false, $vie * @param string $view_extension This view is added to $view * @param int $priority The priority, from 0 to 1000, * to add at (lowest numbers displayed first) - * @param string $viewtype Not used * * @return void * @since 1.7.0 * @link http://docs.elgg.org/Views/Extend * @example views/extend.php */ -function elgg_extend_view($view, $view_extension, $priority = 501, $viewtype = '') { +function elgg_extend_view($view, $view_extension, $priority = 501) { global $CONFIG; if (!isset($CONFIG->views)) { - $CONFIG->views = new stdClass; - } - - if (!isset($CONFIG->views->extensions)) { - $CONFIG->views->extensions = array(); - } - - if (!isset($CONFIG->views->extensions[$view])) { - $CONFIG->views->extensions[$view][500] = "{$view}"; + $CONFIG->views = (object) array( + 'extensions' => array(), + ); + $CONFIG->views->extensions[$view][500] = (string)$view; + } else { + if (!isset($CONFIG->views->extensions[$view])) { + $CONFIG->views->extensions[$view][500] = (string)$view; + } } + // raise priority until it doesn't match one already registered while (isset($CONFIG->views->extensions[$view][$priority])) { $priority++; } - $CONFIG->views->extensions[$view][$priority] = "{$view_extension}"; + $CONFIG->views->extensions[$view][$priority] = (string)$view_extension; ksort($CONFIG->views->extensions[$view]); } @@ -601,14 +592,6 @@ function elgg_extend_view($view, $view_extension, $priority = 501, $viewtype = ' 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; } @@ -1105,10 +1088,6 @@ function elgg_view_annotation_list($annotations, array $vars = array()) { * @todo Change the hook name. */ function elgg_view_entity_annotations(ElggEntity $entity, $full_view = true) { - if (!$entity) { - return false; - } - if (!($entity instanceof ElggEntity)) { return false; } @@ -1131,7 +1110,7 @@ function elgg_view_entity_annotations(ElggEntity $entity, $full_view = true) { * This is a shortcut for {@elgg_view page/elements/title}. * * @param string $title The page title - * @param string $vars View variables (was submenu be displayed? (deprecated)) + * @param array $vars View variables (was submenu be displayed? (deprecated)) * * @return string The HTML (etc) */ @@ -1203,7 +1182,7 @@ function elgg_view_comments($entity, $add_comment = true, array $vars = array()) * * @param string $image The icon and other information * @param string $body Description content - * @param string $vars Additional parameters for the view + * @param array $vars Additional parameters for the view * * @return string * @since 1.8.0 @@ -1230,7 +1209,6 @@ function elgg_view_image_block($image, $body, $vars = array()) { * @since 1.8.0 */ function elgg_view_module($type, $title, $body, array $vars = array()) { - $vars['class'] = elgg_extract('class', $vars, '') . " elgg-module-$type"; $vars['title'] = $title; $vars['body'] = $body; @@ -1243,11 +1221,15 @@ function elgg_view_module($type, $title, $body, array $vars = array()) { * @param ElggRiverItem $item A river item object * @param array $vars An array of variables for the view * - * @return string|false Depending on success + * @return string returns empty string if could not be rendered */ function elgg_view_river_item($item, array $vars = array()) { + if (!($item instanceof ElggRiverItem)) { + return ''; + } // checking default viewtype since some viewtypes do not have unique views per item (rss) - if (!$item || !$item->getView() || !elgg_view_exists($item->getView(), 'default')) { + $view = $item->getView(); + if (!$view || !elgg_view_exists($view, 'default')) { return ''; } @@ -1339,7 +1321,7 @@ function elgg_view_list_item($item, array $vars = array()) { return elgg_view_river_item($item, $vars); } - return false; + return ''; } /** @@ -1354,7 +1336,7 @@ function elgg_view_list_item($item, array $vars = array()) { */ function elgg_view_icon($name, $class = '') { // @todo deprecate boolean in Elgg 1.9 - if (is_bool($class) && $class === true) { + if ($class === true) { $class = 'float'; } return "<span class=\"elgg-icon elgg-icon-$name $class\"></span>"; @@ -1517,17 +1499,13 @@ function elgg_view_tree($view_root, $viewtype = "") { * @param string $base_location_path The base views directory to use with elgg_set_view_location() * @param string $viewtype The type of view we're looking at (default, rss, etc) * - * @return void + * @return bool returns false if folder can't be read * @since 1.7.0 * @see elgg_set_view_location() * @todo This seems overly complicated. * @access private */ function autoregister_views($view_base, $folder, $base_location_path, $viewtype) { - if (!isset($i)) { - $i = 0; - } - if ($handle = opendir($folder)) { while ($view = readdir($handle)) { if (!in_array($view, array('.', '..', '.svn', 'CVS')) && !is_dir($folder . "/" . $view)) { @@ -1648,7 +1626,7 @@ function elgg_views_boot() { $views = scandir($view_path); foreach ($views as $view) { - if ('.' !== substr($view, 0, 1) && is_dir($view_path . $view)) { + if ($view[0] !== '.' && is_dir($view_path . $view)) { elgg_register_viewtype($view); } } -- cgit v1.2.3 From 4f92258bb06ea22335d8e68986ef280b2815f463 Mon Sep 17 00:00:00 2001 From: Steve Clay <steve@mrclay.org> Date: Thu, 29 Nov 2012 15:40:29 -0500 Subject: elgg_view: cut 2 function calls in usual case, consolidated argument checking at top --- engine/lib/views.php | 47 ++++++++++++++++++++++------------------------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/engine/lib/views.php b/engine/lib/views.php index e6932f17c..489190cea 100644 --- a/engine/lib/views.php +++ b/engine/lib/views.php @@ -387,13 +387,29 @@ function elgg_view_exists($view, $viewtype = '', $recurse = true) { */ function elgg_view($view, $vars = array(), $bypass = false, $ignored = false, $viewtype = '') { global $CONFIG; - $view = (string)$view; + if (!is_string($view) || !is_string($viewtype)) { + elgg_log("View and Viewtype in views must be a strings: $view", 'NOTICE'); + return ''; + } // basic checking for bad paths if (strpos($view, '..') !== false) { return ''; } + if (!is_array($vars)) { + elgg_log("Vars in views must be an array: $view", 'ERROR'); + $vars = array(); + } + + // Get the current viewtype + if ($viewtype === '') { + $viewtype = elgg_get_viewtype(); + } elseif (preg_match('/\W/', $viewtype)) { + // Viewtypes can only be alphanumeric + return ''; + } + $view_orig = $view; // Trigger the pagesetup event @@ -402,16 +418,6 @@ function elgg_view($view, $vars = array(), $bypass = false, $ignored = false, $v elgg_trigger_event('pagesetup', 'system'); } - - if (!is_array($vars)) { - elgg_log("Vars in views must be an array: $view", 'ERROR'); - $vars = array(); - } - - if (empty($vars)) { - $vars = array(); - } - // @warning - plugin authors: do not expect user, config, and url to be // set by elgg_view() in the future. Instead, use elgg_get_logged_in_user_entity(), // elgg_get_config(), and elgg_get_site_url() in your views. @@ -466,16 +472,6 @@ function elgg_view($view, $vars = array(), $bypass = false, $ignored = false, $v } } - // Get the current viewtype - if (empty($viewtype)) { - $viewtype = elgg_get_viewtype(); - } - - // Viewtypes can only be alphanumeric - if (preg_match('[\W]', $viewtype)) { - return ''; - } - // Set up any extensions to the requested view if (isset($CONFIG->views->extensions[$view])) { $viewlist = $CONFIG->views->extensions[$view]; @@ -491,16 +487,17 @@ function elgg_view($view, $vars = array(), $bypass = false, $ignored = false, $v $view_location = elgg_get_view_location($view, $viewtype); $view_file = "$view_location$viewtype/$view.php"; - $default_location = elgg_get_view_location($view, 'default'); - $default_view_file = "{$default_location}default/$view.php"; - // try to include view if (!file_exists($view_file) || !include($view_file)) { // requested view does not exist $error = "$viewtype/$view view does not exist."; // attempt to load default view - if ($viewtype != 'default' && elgg_does_viewtype_fallback($viewtype)) { + if ($viewtype !== 'default' && elgg_does_viewtype_fallback($viewtype)) { + + $default_location = elgg_get_view_location($view, 'default'); + $default_view_file = "{$default_location}default/$view.php"; + if (file_exists($default_view_file) && include($default_view_file)) { // default view found $error .= " Using default/$view instead."; -- cgit v1.2.3 From a5d1fd6eed3b4da39dad99df7fda9569a6304cd2 Mon Sep 17 00:00:00 2001 From: Steve Clay <steve@mrclay.org> Date: Thu, 29 Nov 2012 15:41:54 -0500 Subject: views boot: clearer organization --- engine/lib/views.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/engine/lib/views.php b/engine/lib/views.php index 489190cea..69bceabf5 100644 --- a/engine/lib/views.php +++ b/engine/lib/views.php @@ -1584,16 +1584,15 @@ function elgg_views_handle_deprecated_views() { function elgg_views_boot() { global $CONFIG; - 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.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'); - + + elgg_register_simplecache_view('js/elgg'); $elgg_js_url = elgg_get_simplecache_url('js', 'elgg'); elgg_register_js('elgg', $elgg_js_url, 'head'); @@ -1602,14 +1601,17 @@ function elgg_views_boot() { elgg_load_js('elgg'); elgg_register_simplecache_view('js/lightbox'); - elgg_register_simplecache_view('css/lightbox'); $lightbox_js_url = elgg_get_simplecache_url('js', 'lightbox'); elgg_register_js('lightbox', $lightbox_js_url); + + elgg_register_simplecache_view('css/lightbox'); $lightbox_css_url = elgg_get_simplecache_url('css', 'lightbox'); elgg_register_css('lightbox', $lightbox_css_url); + elgg_register_simplecache_view('css/elgg'); $elgg_css_url = elgg_get_simplecache_url('css', 'elgg'); elgg_register_css('elgg', $elgg_css_url); + elgg_load_css('elgg'); elgg_register_ajax_view('js/languages'); -- cgit v1.2.3 From 9168cf7df39e404516c45f77bd64b47b3c61c75d Mon Sep 17 00:00:00 2001 From: Steve Clay <steve@mrclay.org> Date: Sat, 1 Dec 2012 20:09:11 -0500 Subject: Make metadata prefetch respect access --- engine/classes/ElggVolatileMetadataCache.php | 3 +++ mod/profile/views/default/profile/details.php | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/engine/classes/ElggVolatileMetadataCache.php b/engine/classes/ElggVolatileMetadataCache.php index 24ae58d42..8a33c198d 100644 --- a/engine/classes/ElggVolatileMetadataCache.php +++ b/engine/classes/ElggVolatileMetadataCache.php @@ -279,6 +279,9 @@ class ElggVolatileMetadataCache { ), 'selects' => array('n.string AS name', 'v.string AS value'), 'order_by' => 'n_table.entity_guid, n_table.time_created ASC', + + // @todo don't know why this is necessary + 'wheres' => array(get_access_sql_suffix('n_table')), ); $data = elgg_get_metadata($options); diff --git a/mod/profile/views/default/profile/details.php b/mod/profile/views/default/profile/details.php index 3af5cb756..7b05b0e15 100644 --- a/mod/profile/views/default/profile/details.php +++ b/mod/profile/views/default/profile/details.php @@ -28,7 +28,7 @@ if (is_array($profile_fields) && sizeof($profile_fields) > 0) { <div class="<?php echo $even_odd; ?>"> <b><?php echo elgg_echo("profile:{$shortname}"); ?>: </b> <?php - echo elgg_view("output/{$valtype}", array('value' => $user->$shortname)); + echo elgg_view("output/{$valtype}", array('value' => $value)); ?> </div> <?php -- cgit v1.2.3 From 8b6ef5a2081e0436a5135e8cfa954fd3ab158282 Mon Sep 17 00:00:00 2001 From: Brett Profitt <brett.profitt@gmail.com> Date: Tue, 4 Dec 2012 19:00:14 -0500 Subject: Bumped version to 1.8.10. Updated changes. Refs #4947. --- CHANGES.txt | 28 ++++++++++++++++++++++++++++ version.php | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/CHANGES.txt b/CHANGES.txt index 5eb9aca0d..e2f9f4e3f 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,31 @@ +Version 1.8.10 +(December 4th, 2012 from https://github.com/Elgg/Elgg/tree/1.8) + + Contributing Developers: + * Krzysztof Różalski + * Lars Hærvig + * Paweł Sroka + * RiverVanRain + * Sem + * Steve Clay + + Security Enhancements: + * Cached metadata respects access restrictions to fix problems with profile + field display. + * Group RSS feeds are restricted to valid entities + + Enhancements: + * UX: Added a list of Administrators in the admin area + * UX: Limiting message board activity stream entries to excerpts + * Performance: Prefetching river entries + * Performance: Plugin entities are cached + + Bugfixes: + * Removed superfluous commas in JS files to fix IE compatibility. + * API: Fixed Twitter API. + * Performance: Outputting valid ETags and expires headers. + + Version 1.8.9 (November 11, 2012 from https://github.com/Elgg/Elgg/tree/1.8) diff --git a/version.php b/version.php index a2417d848..67f8fd480 100644 --- a/version.php +++ b/version.php @@ -14,4 +14,4 @@ $version = 2012111100; // Human-friendly version name -$release = '1.8.9'; +$release = '1.8.10'; -- cgit v1.2.3 From ce1cff247caf418af1fab52c5c2182883b7a26d0 Mon Sep 17 00:00:00 2001 From: Steve Clay <steve@mrclay.org> Date: Wed, 5 Dec 2012 09:45:31 -0500 Subject: Fixes fatal error in groups/add page. --- mod/groups/views/default/forms/groups/edit.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mod/groups/views/default/forms/groups/edit.php b/mod/groups/views/default/forms/groups/edit.php index 7a740b878..41d97e6c3 100644 --- a/mod/groups/views/default/forms/groups/edit.php +++ b/mod/groups/views/default/forms/groups/edit.php @@ -147,7 +147,7 @@ if ($tools) { <div class="elgg-foot"> <?php -if (isset($entity)) { +if ($entity) { echo elgg_view('input/hidden', array( 'name' => 'group_guid', 'value' => $entity->getGUID(), @@ -156,7 +156,7 @@ if (isset($entity)) { echo elgg_view('input/submit', array('value' => elgg_echo('save'))); -if (isset($entity)) { +if ($entity) { $delete_url = 'action/groups/delete?guid=' . $entity->getGUID(); echo elgg_view('output/confirmlink', array( 'text' => elgg_echo('groups:delete'), -- cgit v1.2.3 From f58bf0eb83d0624ffb6e99d51e0ba65490619eb6 Mon Sep 17 00:00:00 2001 From: Steve Clay <steve@mrclay.org> Date: Wed, 5 Dec 2012 10:35:35 -0500 Subject: Prep for 1.8.11 release. version/CHANGES updates --- CHANGES.txt | 7 +++++++ version.php | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index e2f9f4e3f..ca1bdc675 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,10 @@ +Version 1.8.11 +(December 5th, 2012 from https://github.com/Elgg/Elgg/tree/1.8) + + Bugfix: + * Fixed fatal error in group creation form + + Version 1.8.10 (December 4th, 2012 from https://github.com/Elgg/Elgg/tree/1.8) diff --git a/version.php b/version.php index 67f8fd480..77d151bb6 100644 --- a/version.php +++ b/version.php @@ -11,7 +11,7 @@ // YYYYMMDD = Elgg Date // XX = Interim incrementer -$version = 2012111100; +$version = 2012120500; // Human-friendly version name -$release = '1.8.10'; +$release = '1.8.11'; -- cgit v1.2.3