Skip to content

Commit

Permalink
Merge pull request #11133 from jdalsem/forms-input
Browse files Browse the repository at this point in the history
small changes to forms and actions
  • Loading branch information
jdalsem committed Aug 9, 2017
2 parents 5089f02 + 0ec03aa commit fe71c49
Show file tree
Hide file tree
Showing 16 changed files with 223 additions and 188 deletions.
62 changes: 28 additions & 34 deletions actions/admin/plugins/activate.php
Expand Up @@ -6,9 +6,6 @@
* After activating the plugin(s), the views cache and simplecache are invalidated.
*
* @uses mixed $_GET['plugin_guids'] The GUIDs of the plugin to activate. Can be an array.
*
* @package Elgg.Core
* @subpackage Administration.Plugins
*/

$plugin_guids = get_input('plugin_guids');
Expand All @@ -17,7 +14,7 @@
$plugin_guids = [$plugin_guids];
}

$activated_guids = [];
$activated_plugins = [];
foreach ($plugin_guids as $guid) {
$plugin = get_entity($guid);

Expand All @@ -26,42 +23,39 @@
continue;
}

if ($plugin->activate()) {
$activated_guids[] = $guid;
$ids = [
'cannot_start' . $plugin->getID(),
'invalid_and_deactivated_' . $plugin->getID()
];

foreach ($ids as $id) {
elgg_delete_admin_notice($id);
}
} else {
if (!$plugin->activate()) {
$msg = $plugin->getError();
$string = ($msg) ? 'admin:plugins:activate:no_with_msg' : 'admin:plugins:activate:no';
register_error(elgg_echo($string, [$plugin->getDisplayName(), $plugin->getError()]));
continue;
}

$ids = [
'cannot_start' . $plugin->getID(),
'invalid_and_deactivated_' . $plugin->getID()
];

foreach ($ids as $id) {
elgg_delete_admin_notice($id);
}

$activated_plugins[] = $plugin;
}

// don't regenerate the simplecache because the plugin won't be
// loaded until next run. Just invalidate and let it regenerate as needed
elgg_flush_caches();
if (empty($activated_plugins)) {
return elgg_error_response();
}

if (count($activated_guids) === 1) {
$url = 'admin/plugins';
$query = (string) parse_url($_SERVER['HTTP_REFERER'], PHP_URL_QUERY);
if ($query) {
$url .= "?$query";
}
$plugin = get_entity($plugin_guids[0]);
$id = $css_id = preg_replace('/[^a-z0-9-]/i', '-', $plugin->getID());
$url = "$url#id";
if (count($activated_plugins) === 1) {
$plugin = $activated_plugins[0];

$url = elgg_http_build_url([
'path' => 'admin/plugins',
'query' => parse_url($_SERVER['HTTP_REFERER'], PHP_URL_QUERY),
'fragment' => preg_replace('/[^a-z0-9-]/i', '-', $plugin->getID()),
]);
return elgg_ok_response('', '', $url);
} else {
// forward to top of page with a failure so remove any #foo
$url = $_SERVER['HTTP_REFERER'];
if (strpos($url, '#')) {
$url = substr(0, strpos($url, '#'));
}
forward($url);
}

return elgg_ok_response();
16 changes: 5 additions & 11 deletions actions/admin/plugins/activate_all.php
Expand Up @@ -4,9 +4,6 @@
*
* All specified plugins in the mod/ directory that aren't active are activated and the views
* cache and simplecache are invalidated.
*
* @package Elgg.Core
* @subpackage Administration.Plugins
*/

$guids = get_input('guids');
Expand All @@ -18,12 +15,12 @@
'type' => 'object',
'subtype' => 'plugin',
'guids' => explode(',', $guids),
'limit' => false
'limit' => false,
]);
}

if (empty($plugins)) {
forward(REFERER);
return elgg_ok_response();
}

do {
Expand Down Expand Up @@ -63,12 +60,9 @@
foreach ($plugins as $plugin) {
$msg = $plugin->getError();
$string = ($msg) ? 'admin:plugins:activate:no_with_msg' : 'admin:plugins:activate:no';
register_error(elgg_echo($string, [$plugin->getDisplayName(), $msg]));

return elgg_error_response(elgg_echo($string, [$plugin->getDisplayName(), $msg]));
}
}

// don't regenerate the simplecache because the plugin won't be
// loaded until next run. Just invalidate and let it regnerate as needed
elgg_flush_caches();

forward(REFERER);
return elgg_ok_response();
35 changes: 18 additions & 17 deletions actions/admin/plugins/deactivate.php
Expand Up @@ -6,9 +6,6 @@
* After deactivating the plugin(s), the views cache and simplecache are invalidated.
*
* @uses mixed $_GET['plugin_guids'] The GUIDs of the plugin to deactivate. Can be an array.
*
* @package Elgg.Core
* @subpackage Administration.Plugins
*/

$plugin_guids = get_input('plugin_guids');
Expand All @@ -17,6 +14,7 @@
$plugin_guids = [$plugin_guids];
}

$deactivated_plugins = [];
foreach ($plugin_guids as $guid) {
$plugin = get_entity($guid);

Expand All @@ -29,23 +27,26 @@
$msg = $plugin->getError();
$string = ($msg) ? 'admin:plugins:deactivate:no_with_msg' : 'admin:plugins:deactivate:no';
register_error(elgg_echo($string, [$plugin->getDisplayName(), $msg]));
continue;
}

$deactivated_plugins[] = $plugin;
}

// don't regenerate the simplecache because the plugin won't be
// loaded until next run. Just invalidate and let it regnerate as needed
elgg_flush_caches();
if (empty($deactivated_plugins)) {
return elgg_error_response();
}

if (count($plugin_guids) == 1) {
$url = 'admin/plugins';
$query = (string) parse_url($_SERVER['HTTP_REFERER'], PHP_URL_QUERY);
if ($query) {
$url .= "?$query";
}
$plugin = get_entity($plugin_guids[0]);
$id = preg_replace('/[^a-z0-9-]/i', '-', $plugin->getID());
$url = "$url#$id";
if (count($deactivated_plugins) == 1) {
$plugin = $deactivated_plugins[0];

$url = elgg_http_build_url([
'path' => 'admin/plugins',
'query' => parse_url($_SERVER['HTTP_REFERER'], PHP_URL_QUERY),
'fragment' => preg_replace('/[^a-z0-9-]/i', '-', $plugin->getID()),
]);
return elgg_ok_response('', '', $url);
} else {
forward(REFERER);
}

return elgg_ok_response();
14 changes: 4 additions & 10 deletions actions/admin/plugins/deactivate_all.php
Expand Up @@ -4,9 +4,6 @@
*
* Specified plugins in the mod/ directory are disabled and the views cache and simplecache
* are reset.
*
* @package Elgg.Core
* @subpackage Administration.Plugins
*/

$guids = get_input('guids');
Expand All @@ -23,7 +20,7 @@
}

if (empty($plugins)) {
forward(REFERER);
return elgg_ok_response();
}

foreach ($plugins as $plugin) {
Expand All @@ -34,12 +31,9 @@
if (!$plugin->deactivate()) {
$msg = $plugin->getError();
$string = ($msg) ? 'admin:plugins:deactivate:no_with_msg' : 'admin:plugins:deactivate:no';
register_error(elgg_echo($string, [$plugin->getDisplayName(), $plugin->getError()]));

return elgg_error_response(elgg_echo($string, [$plugin->getDisplayName(), $msg]));
}
}

// don't regenerate the simplecache because the plugin won't be
// loaded until next run. Just invalidate and let it regnerate as needed
elgg_flush_caches();

forward(REFERER);
return elgg_ok_response();
15 changes: 10 additions & 5 deletions actions/comment/save.php
Expand Up @@ -14,6 +14,8 @@
return elgg_error_response(elgg_echo('generic_comment:blank'));
}

$result = '';

if ($comment_guid) {
// Edit an existing comment
$comment = get_entity($comment_guid);
Expand All @@ -33,14 +35,14 @@

if (elgg_is_xhr()) {
// @todo move to its own view object/comment/content in 1.x
echo elgg_view('output/longtext', [
$result = elgg_view('output/longtext', [
'value' => $comment->description,
'class' => 'elgg-inner',
'data-role' => 'comment-text',
]);
}

system_message(elgg_echo('generic_comment:updated'));
$success_message = elgg_echo('generic_comment:updated');

} else {
// Create a new comment on the target entity
Expand Down Expand Up @@ -71,16 +73,19 @@
'target_guid' => $entity_guid,
]);

system_message(elgg_echo('generic_comment:posted'));
$success_message = elgg_echo('generic_comment:posted');
}

$forward = $comment->getURL();

// return to activity page if posted from there
// this can be removed once saving new comments is ajaxed
if (!empty($_SERVER['HTTP_REFERER'])) {
// don't redirect to URLs from client without verifying within site
$site_url = preg_quote(elgg_get_site_url(), '~');
if (preg_match("~^{$site_url}activity(/|\\z)~", $_SERVER['HTTP_REFERER'], $m)) {
forward("{$m[0]}#elgg-object-{$comment->guid}");
$forward = "{$m[0]}#elgg-object-{$comment->guid}";
}
}

forward($comment->getURL());
return elgg_ok_response($result, $success_message, $forward);
12 changes: 7 additions & 5 deletions actions/entity/delete.php
Expand Up @@ -30,19 +30,21 @@
$forward_url = get_input('forward_url');
if (!$forward_url) {

// @todo rewrite this to be more readable
$forward_url = REFERRER;
$referrer_url = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
$forward_url = REFERER;
$referrer_url = $_SERVER['HTTP_REFERER'] ?: '';
$site_url = elgg_get_site_url();

if ($referrer_url && 0 == strpos($referrer_url, $site_url)) {
// referer is on current site

$referrer_path = substr($referrer_url, 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 = ($container) ? $container->getURL() : '';
}
} else if ($container) {
$forward_url = $container->getURL() ? : '';
} elseif ($container) {
$forward_url = $container->getURL();
}
}

Expand Down
2 changes: 1 addition & 1 deletion actions/register.php
Expand Up @@ -58,7 +58,7 @@

elgg_clear_sticky_form('register');

if ($new_user->enabled == 'yes') {
if ($new_user->isEnabled()) {
// if exception thrown, this probably means there is a validation
// plugin that has disabled the user
try {
Expand Down
26 changes: 13 additions & 13 deletions engine/classes/ElggPlugin.php
Expand Up @@ -814,22 +814,22 @@ public function deactivate() {
];

$return = _elgg_services()->hooks->getEvents()->trigger('deactivate', 'plugin', $params);

// run any deactivate code
if ($return) {
if ($this->canReadFile('deactivate.php')) {
$return = $this->includeFile('deactivate.php');
}

$this->deactivateEntities();
}

if ($return === false) {
return false;
} else {
_elgg_services()->hooks->getEvents()->trigger('cache:flush', 'system');
return $this->setStatus(false);
}

// run any deactivate code
if ($this->canReadFile('deactivate.php')) {
// allows you to prevent disabling a plugin by returning false in a deactivate.php file
if ($this->includeFile('deactivate.php') === false) {
return false;
}
}

$this->deactivateEntities();

_elgg_services()->hooks->getEvents()->trigger('cache:flush', 'system');
return $this->setStatus(false);
}

/**
Expand Down
18 changes: 8 additions & 10 deletions mod/groups/views/default/groups/edit/tools.php
Expand Up @@ -21,15 +21,13 @@
$group_option_toggle_name = $group_option->name . "_enable";
$value = elgg_extract($group_option_toggle_name, $vars);

echo elgg_format_element([
'#tag_name' => 'div',
'#text' => elgg_view('input/checkbox', [
'name' => $group_option_toggle_name,
'value' => 'yes',
'default' => 'no',
'switch' => true,
'checked' => ($value === 'yes') ? true : false,
'label' => $group_option->label,
]),
echo elgg_view_field([
'#type' => 'checkbox',
'#label' => $group_option->label,
'name' => $group_option_toggle_name,
'value' => 'yes',
'default' => 'no',
'switch' => true,
'checked' => ($value === 'yes') ? true : false,
]);
}

0 comments on commit fe71c49

Please sign in to comment.