Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sax master #5

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions actions/admin/site/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@
elgg_save_config('pagination_behaviour', get_input('pagination_behaviour', 'ajax-replace'));
elgg_save_config('mentions_display_format', get_input('mentions_display_format'));

$trash_retention = (int) get_input('trash_retention', 30);
if ($trash_retention < 0) {
$trash_retention = 30;
}

elgg_save_config('trash_retention', $trash_retention);
elgg_save_config('trash_enabled', (bool) get_input('trash_enabled'));

elgg_save_config('user_joined_river', get_input('user_joined_river') === 'on');
elgg_save_config('can_change_username', get_input('can_change_username') === 'on');

Expand Down
2 changes: 1 addition & 1 deletion actions/admin/user/bulk/delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
return elgg_error_response(elgg_echo('error:missing_data'));
}

elgg_call(ELGG_SHOW_DISABLED_ENTITIES, function() use ($user_guids) {
elgg_call(ELGG_SHOW_DISABLED_ENTITIES | ELGG_SHOW_DELETED_ENTITIES, function() use ($user_guids) {
foreach ($user_guids as $user_guid) {
$user = get_user($user_guid);
if (empty($user)) {
Expand Down
4 changes: 2 additions & 2 deletions actions/admin/user/delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
return elgg_error_response(elgg_echo('admin:user:self:delete:no'));
}

$user = elgg_call(ELGG_SHOW_DISABLED_ENTITIES, function() use ($guid) {
$user = elgg_call(ELGG_SHOW_DISABLED_ENTITIES | ELGG_SHOW_DELETED_ENTITIES, function() use ($guid) {
return get_user($guid);
});
if (!$user || !$user->canDelete()) {
Expand All @@ -22,7 +22,7 @@
$name = $user->getDisplayName();
$username = $user->username;

$deleted = elgg_call(ELGG_SHOW_DISABLED_ENTITIES, function() use ($user) {
$deleted = elgg_call(ELGG_SHOW_DISABLED_ENTITIES | ELGG_SHOW_DELETED_ENTITIES, function() use ($user) {
return $user->delete();
});
if (!$deleted) {
Expand Down
60 changes: 60 additions & 0 deletions actions/entity/chooserestoredestination.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
/**
* Action for choosing destination to restore a post to.
*
*/

$guid = (int) get_input('entity_guid');
$destination_container_guid = (array) get_input('destination_container_guid');
$destination_container_guid = array_filter($destination_container_guid, function($value) {
return is_numeric($value);
});
$destination_container_guid = array_map(function($value) {
return (int) $value;
}, $destination_container_guid);

if (empty($guid) || empty($destination_container_guid)) {
return elgg_error_response(elgg_echo('error:missing_data'));
}

$entity = elgg_call(ELGG_SHOW_DELETED_ENTITIES, function () use ($guid) {
return get_entity($guid);
});
if (!$entity instanceof \ElggEntity || $entity->deleted !== 'yes') {
return elgg_error_response(elgg_echo('entity:restore:item_not_found'));
}

$new_container = get_entity($destination_container_guid[0]);
if (!$new_container instanceof \ElggEntity || !$new_container->canWriteToContainer(0, $entity->type, $entity->subtype)) {
return elgg_error_response(elgg_echo('actionunauthorized'));
}

// determine what name to show on success
$display_name = $entity->getDisplayName() ?: elgg_echo('entity:restore:item');

if (!$entity->restore()) {
return elgg_error_response(elgg_echo('entity:restore:fail', [$display_name]));
}

$entity->container_guid = $new_container->guid;
if (!$entity->save()) {
return elgg_error_response(elgg_echo('entity:restore:fail', [$display_name]));
}

$success_keys = [
"entity:restore:{$entity->type}:{$entity->subtype}:success",
"entity:restore:{$entity->type}:success",
'entity:restore:success',
];

$message = '';
if (get_input('show_success', true)) {
foreach ($success_keys as $success_key) {
if (elgg_language_key_exists($success_key)) {
$message = elgg_echo($success_key, [$display_name]);
break;
}
}
}

return elgg_ok_response('', $message);
9 changes: 4 additions & 5 deletions actions/entity/delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
*/

$guid = (int) get_input('guid');

$entity = get_entity($guid);
$entity = elgg_call(ELGG_SHOW_DELETED_ENTITIES, function() use ($guid) {
return get_entity($guid);
});
if (!$entity instanceof \ElggEntity) {
return elgg_error_response(elgg_echo('entity:delete:item_not_found'));
}
Expand All @@ -14,16 +15,14 @@
return elgg_error_response(elgg_echo('entity:delete:permission_denied'));
}

set_time_limit(0);

// determine what name to show on success
$display_name = $entity->getDisplayName() ?: elgg_echo('entity:delete:item');

$type = $entity->getType();
$subtype = $entity->getSubtype();
$container = $entity->getContainerEntity();

if (!$entity->delete()) {
if (!$entity->delete(true, true)) {
return elgg_error_response(elgg_echo('entity:delete:fail', [$display_name]));
}

Expand Down
41 changes: 41 additions & 0 deletions actions/entity/restore.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/**
* Default entity restore action
*/

$guid = (int) get_input('guid');
$entity = elgg_call(ELGG_SHOW_DELETED_ENTITIES, function() use ($guid) {
return get_entity($guid);
});
if (!$entity instanceof \ElggEntity || $entity->deleted !== 'yes') {
return elgg_error_response(elgg_echo('entity:restore:item_not_found'));
}

if (!$entity->canEdit()) {
return elgg_error_response(elgg_echo('actionunauthorized'));
}

// determine what name to show on success
$display_name = $entity->getDisplayName() ?: elgg_echo('entity:restore:item');

if (!$entity->restore()) {
return elgg_error_response(elgg_echo('entity:restore:fail', [$display_name]));
}

$success_keys = [
"entity:restore:{$entity->type}:{$entity->subtype}:success",
"entity:restore:{$entity->type}:success",
'entity:restore:success',
];

$message = '';
if (get_input('show_success', true)) {
foreach ($success_keys as $success_key) {
if (elgg_language_key_exists($success_key)) {
$message = elgg_echo($success_key, [$display_name]);
break;
}
}
}

return elgg_ok_response('', $message);
94 changes: 94 additions & 0 deletions actions/entity/trash.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php
/**
* Default entity trash action
*/

$guid = (int) get_input('guid');
$entity = get_entity($guid);
if (!$entity instanceof \ElggEntity) {
return elgg_error_response(elgg_echo('entity:delete:item_not_found'));
}

if (!$entity->canDelete() || !$entity->hasCapability('restorable') || $entity instanceof \ElggPlugin || $entity instanceof \ElggSite || $entity instanceof \ElggUser) {
return elgg_error_response(elgg_echo('entity:delete:permission_denied'));
}

// determine what name to show on success
$display_name = $entity->getDisplayName() ?: elgg_echo('entity:delete:item');

$type = $entity->getType();
$subtype = $entity->getSubtype();
$container = $entity->getContainerEntity();

if (!$entity->delete(true, false)) {
return elgg_error_response(elgg_echo('entity:delete:fail', [$display_name]));
}

// determine forward URL
$forward_url = get_input('forward_url');
if (!empty($forward_url)) {
$forward_url = elgg_normalize_site_url((string) $forward_url);
}

if (empty($forward_url)) {
$forward_url = REFERRER;
$referrer_url = elgg_extract('HTTP_REFERER', $_SERVER, '');
$site_url = elgg_get_site_url();

$find_forward_url = function (\ElggEntity $container = null) use ($type, $subtype) {
$routes = _elgg_services()->routes;

// check if there is a collection route (eg. blog/owner/username)
$route_name = false;
if ($container instanceof \ElggUser) {
$route_name = "collection:{$type}:{$subtype}:owner";
} elseif ($container instanceof \ElggGroup) {
$route_name = "collection:{$type}:{$subtype}:group";
}

if ($route_name && $routes->get($route_name)) {
$params = $routes->resolveRouteParameters($route_name, $container);

return elgg_generate_url($route_name, $params);
}

// no route found, fallback to container url
if ($container instanceof \ElggEntity) {
return $container->getURL();
}

// no container
return '';
};

if (!empty($referrer_url) && elgg_strpos($referrer_url, $site_url) === 0) {
// referer is on current site
$referrer_path = elgg_substr($referrer_url, elgg_strlen($site_url));
$segments = explode('/', $referrer_path);

if (in_array($guid, $segments)) {
// referrer URL contains a reference to the entity that will be deleted
$forward_url = $find_forward_url($container);
}
} elseif ($container instanceof \ElggEntity) {
$forward_url = $find_forward_url($container);
}
}

$success_keys = [
"entity:delete:{$type}:{$subtype}:success",
"entity:delete:{$type}:success",
'entity:delete:success',
];

$message = '';
if (get_input('show_success', true)) {
foreach ($success_keys as $success_key) {
if (elgg_language_key_exists($success_key)) {
$message = elgg_echo($success_key, [$display_name]);
break;
}
}
}

return elgg_ok_response('', $message, $forward_url);
1 change: 1 addition & 0 deletions docs/appendix/upgrade-notes/5.x-to-6.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ Removed class functions
Lib functions function parameters
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

* ``elgg_get_entity_statistics()`` now requires an ``array`` of ``$options`` to be used by ``elgg_get_entities()``.
* ``elgg_get_simplecache_url()`` has the second argument (``$subview``) removed. The full ``$view`` name needs to be provided as the first argument.

Miscellaneous API changes
Expand Down
4 changes: 4 additions & 0 deletions docs/design/database.rst
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,10 @@ It contains the following fields:
- **enabled** If this is 'yes' an entity is accessible, if 'no' the entity
has been disabled (Elgg treats it as if it were deleted without actually
removing it from the database)
- **deleted** If this is 'yes' an entity is marked for deletion,
if 'no' (default) the entity is visible within the regular site.
If the bin plugin is enabled, soft deleted content is stored in the Temporary Bin.
- **time\_deleted** Unix timestamp of when the entity was soft deleted.

Table: metadata
~~~~~~~~~~~~~~~
Expand Down
3 changes: 2 additions & 1 deletion docs/tutorials/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ The instructions are detailed enough that you don't need much previous experienc
indexpage
blog
wysiwyg
widget
widget
temporary_bin
Loading
Loading