save.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * Saves user-specific plugin settings.
  4. *
  5. * This action can be overriden for a specific plugin by creating the
  6. * <plugin_id>/usersettings/save action in that plugin.
  7. *
  8. * @uses array $_REQUEST['params'] A set of key/value pairs to save to the ElggPlugin entity
  9. * @uses int $_REQUEST['plugin_id'] The id of the plugin
  10. * @uses int $_REQUEST['user_guid'] The GUID of the user to save settings for.
  11. *
  12. * @package Elgg.Core
  13. * @subpackage Plugins.Settings
  14. */
  15. $params = get_input('params');
  16. $plugin_id = get_input('plugin_id');
  17. $user_guid = get_input('user_guid', elgg_get_logged_in_user_guid());
  18. $plugin = elgg_get_plugin_from_id($plugin_id);
  19. $user = get_entity($user_guid);
  20. if (!($plugin instanceof ElggPlugin)) {
  21. register_error(elgg_echo('plugins:usersettings:save:fail', array($plugin_id)));
  22. forward(REFERER);
  23. }
  24. if (!($user instanceof ElggUser)) {
  25. register_error(elgg_echo('plugins:usersettings:save:fail', array($plugin_id)));
  26. forward(REFERER);
  27. }
  28. $plugin_name = $plugin->getManifest()->getName();
  29. // make sure we're admin or the user
  30. if (!$user->canEdit()) {
  31. register_error(elgg_echo('plugins:usersettings:save:fail', array($plugin_name)));
  32. forward(REFERER);
  33. }
  34. $result = false;
  35. if (elgg_action_exists("$plugin_id/usersettings/save")) {
  36. action("$plugin_id/usersettings/save");
  37. } else {
  38. foreach ($params as $k => $v) {
  39. // Save
  40. $result = $plugin->setUserSetting($k, $v, $user->guid);
  41. // Error?
  42. if (!$result) {
  43. register_error(elgg_echo('plugins:usersettings:save:fail', array($plugin_name)));
  44. forward(REFERER);
  45. }
  46. }
  47. }
  48. system_message(elgg_echo('plugins:usersettings:save:ok', array($plugin_name)));
  49. forward(REFERER);