diff options
Diffstat (limited to 'actions')
70 files changed, 1221 insertions, 915 deletions
diff --git a/actions/admin/delete_admin_notice.php b/actions/admin/delete_admin_notice.php new file mode 100644 index 000000000..a9c3b8758 --- /dev/null +++ b/actions/admin/delete_admin_notice.php @@ -0,0 +1,13 @@ +<?php +/** + * Removes an admin notice. + */ + +$guid = get_input('guid'); +$notice = get_entity($guid); + +if (!(elgg_instanceof($notice, 'object', 'admin_notice') && $notice->delete())) { + register_error(elgg_echo("admin:notices:could_not_delete")); +} + +forward(REFERER);
\ No newline at end of file diff --git a/actions/admin/menu/save.php b/actions/admin/menu/save.php new file mode 100644 index 000000000..66ce71082 --- /dev/null +++ b/actions/admin/menu/save.php @@ -0,0 +1,34 @@ +<?php +/** + * Save menu items. + * + * @package Elgg + * @subpackage Core + */ + +// featured menu items +$featured_names = get_input('featured_menu_names', array()); +$featured_names = array_unique($featured_names); +if (in_array(' ', $featured_names)) { + unset($featured_names[array_search(' ', $featured_names)]); +} +elgg_save_config('site_featured_menu_names', $featured_names); + +// custom menu items +$custom_menu_titles = get_input('custom_menu_titles', array()); +$custom_menu_urls = get_input('custom_menu_urls', array()); +$num_menu_items = count($custom_menu_titles); +$custom_menu_items = array(); +for ($i = 0; $i < $num_menu_items; $i++) { + if (trim($custom_menu_urls[$i]) && trim($custom_menu_titles[$i])) { + $url = $custom_menu_urls[$i]; + $title = $custom_menu_titles[$i]; + $custom_menu_items[$title] = $url; + } +} +elgg_save_config('site_custom_menu_items', $custom_menu_items); + + +system_message(elgg_echo('admin:menu_items:saved')); + +forward(REFERER); diff --git a/actions/admin/menu_items.php b/actions/admin/menu_items.php deleted file mode 100644 index c9efb8bee..000000000 --- a/actions/admin/menu_items.php +++ /dev/null @@ -1,50 +0,0 @@ -<?php -/** - * Save menu items. - * - * @package Elgg - * @subpackage Core - */ - -$featured_urls = get_input('featured_urls', array()); -$custom_item_names = get_input('custom_item_names', array()); -$custom_item_urls = get_input('custom_item_urls', array()); - -// save the full information from the menu item into the config table -// this will be checked upon display that it is still valid (based upon url) -$menu_items = get_register('menu'); -$menu_urls = array(); -$featured_url_info = array(); - -foreach ($menu_items as $name => $info) { - $menu_urls[$info->value->url] = $info; -} - -foreach ($featured_urls as $url) { - if (array_key_exists($url, $menu_urls)) { - $featured_url_info[] = $menu_urls[$url]; - } -} - -// save the custom items -$custom_count = count($custom_item_names); -$custom_items = array(); -for ($i = 0; $i < $custom_count; $i++) { - if (isset($custom_item_names[$i]) && isset($custom_item_names[$i])) { - $name = $custom_item_names[$i]; - $url = $custom_item_urls[$i]; - - if ($name && $url) { - $custom_items[$url] = $name; - } - } -} - - -// set_config() always returns 0 so can't check for failures -set_config('menu_items_featured_urls', $featured_url_info); -set_config('menu_items_custom_items', $custom_items); - -system_message(elgg_echo('admin:menu_items:saved')); - -forward(REFERER); diff --git a/actions/admin/plugins/activate.php b/actions/admin/plugins/activate.php new file mode 100644 index 000000000..5234a4ca5 --- /dev/null +++ b/actions/admin/plugins/activate.php @@ -0,0 +1,59 @@ +<?php +/** + * Activate a plugin or plugins. + * + * Plugins to be activated are passed via $_REQUEST['plugin_guids'] as GUIDs. + * 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'); + +if (!is_array($plugin_guids)) { + $plugin_guids = array($plugin_guids); +} + +$activated_guids = array(); +foreach ($plugin_guids as $guid) { + $plugin = get_entity($guid); + + if (!($plugin instanceof ElggPlugin)) { + register_error(elgg_echo('admin:plugins:activate:no', array($guid))); + continue; + } + + if ($plugin->activate()) { + $activated_guids[] = $guid; + } else { + $msg = $plugin->getError(); + $string = ($msg) ? 'admin:plugins:activate:no_with_msg' : 'admin:plugins:activate:no'; + register_error(elgg_echo($string, array($plugin->getFriendlyName(), $plugin->getError()))); + } +} + +// don't regenerate the simplecache because the plugin won't be +// loaded until next run. Just invalidate and let it regenerate as needed +elgg_invalidate_simplecache(); +elgg_reset_system_cache(); + +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()); + forward("$url#$id"); +} 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); +}
\ No newline at end of file diff --git a/actions/admin/plugins/activate_all.php b/actions/admin/plugins/activate_all.php new file mode 100644 index 000000000..4514ccbdf --- /dev/null +++ b/actions/admin/plugins/activate_all.php @@ -0,0 +1,33 @@ +<?php +/** + * Activates all specified installed and inactive plugins. + * + * All specified plugins in the mod/ directory are that aren't active are activated and the views + * cache and simplecache are invalidated. + * + * @package Elgg.Core + * @subpackage Administration.Plugins + */ + +$guids = get_input('guids'); +$guids = explode(',', $guids); + +foreach ($guids as $guid) { + $plugin = get_entity($guid); + if (!$plugin->isActive()) { + if ($plugin->activate()) { + //system_message(elgg_echo('admin:plugins:activate:yes', array($plugin->getManifest()->getName()))); + } else { + $msg = $plugin->getError(); + $string = ($msg) ? 'admin:plugins:activate:no_with_msg' : 'admin:plugins:activate:no'; + register_error(elgg_echo($string, array($plugin->getFriendlyName(), $plugin->getError()))); + } + } +} + +// don't regenerate the simplecache because the plugin won't be +// loaded until next run. Just invalidate and let it regnerate as needed +elgg_invalidate_simplecache(); +elgg_reset_system_cache(); + +forward(REFERER);
\ No newline at end of file diff --git a/actions/admin/plugins/deactivate.php b/actions/admin/plugins/deactivate.php new file mode 100644 index 000000000..354f4717d --- /dev/null +++ b/actions/admin/plugins/deactivate.php @@ -0,0 +1,53 @@ +<?php +/** + * Deactivate a plugin or plugins. + * + * Plugins to be deactivated are passed via $_REQUEST['plugin_guids'] as GUIDs. + * 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'); + +if (!is_array($plugin_guids)) { + $plugin_guids = array($plugin_guids); +} + +foreach ($plugin_guids as $guid) { + $plugin = get_entity($guid); + + if (!($plugin instanceof ElggPlugin)) { + register_error(elgg_echo('admin:plugins:deactivate:no', array($guid))); + continue; + } + + if ($plugin->deactivate()) { + //system_message(elgg_echo('admin:plugins:deactivate:yes', array($plugin->getManifest()->getName()))); + } else { + $msg = $plugin->getError(); + $string = ($msg) ? 'admin:plugins:deactivate:no_with_msg' : 'admin:plugins:deactivate:no'; + register_error(elgg_echo($string, array($plugin->getFriendlyName(), $plugin->getError()))); + } +} + +// don't regenerate the simplecache because the plugin won't be +// loaded until next run. Just invalidate and let it regnerate as needed +elgg_invalidate_simplecache(); +elgg_reset_system_cache(); + +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()); + forward("$url#$id"); +} else { + forward(REFERER); +} diff --git a/actions/admin/plugins/deactivate_all.php b/actions/admin/plugins/deactivate_all.php new file mode 100644 index 000000000..8b347a633 --- /dev/null +++ b/actions/admin/plugins/deactivate_all.php @@ -0,0 +1,33 @@ +<?php +/** + * Disable all specified installed plugins. + * + * 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'); +$guids = explode(',', $guids); + +foreach ($guids as $guid) { + $plugin = get_entity($guid); + if ($plugin->isActive()) { + if ($plugin->deactivate()) { + //system_message(elgg_echo('admin:plugins:activate:yes', array($plugin->getManifest()->getName()))); + } else { + $msg = $plugin->getError(); + $string = ($msg) ? 'admin:plugins:deactivate:no_with_msg' : 'admin:plugins:deactivate:no'; + register_error(elgg_echo($string, array($plugin->getFriendlyName(), $plugin->getError()))); + } + } +} + +// don't regenerate the simplecache because the plugin won't be +// loaded until next run. Just invalidate and let it regnerate as needed +elgg_invalidate_simplecache(); +elgg_reset_system_cache(); + +forward(REFERER); diff --git a/actions/admin/plugins/disable.php b/actions/admin/plugins/disable.php deleted file mode 100644 index 48116e43a..000000000 --- a/actions/admin/plugins/disable.php +++ /dev/null @@ -1,35 +0,0 @@ -<?php -/** - * Disable a plugin or plugins. - * - * Plugins to be disabled are passed via $_REQUEST['plugin'] as plugin ID (directory name). - * After disabling the plugin(s), the views cache and simplecache are both reset. - * - * @uses mixed $_GET['plugin'] The id (directory name) of the plugin to disable. Can be an array. - * - * @package Elgg.Core - * @subpackage Administration.Site - */ - -admin_gatekeeper(); - -$plugin = get_input('plugin'); -if (!is_array($plugin)) { - $plugin = array($plugin); -} - -foreach ($plugin as $p) { - if (disable_plugin($p)) { - system_message(sprintf(elgg_echo('admin:plugins:disable:yes'), $p)); - elgg_delete_admin_notice('first_installation_plugin_reminder'); - } else { - register_error(sprintf(elgg_echo('admin:plugins:disable:no'), $p)); - } -} - -// don't regenerate the simplecache because the plugin won't be -// loaded until next run. Just invalidate and let it regnerate as needed -elgg_invalidate_simplecache(); -elgg_filepath_cache_reset(); - -forward(REFERER); diff --git a/actions/admin/plugins/disableall.php b/actions/admin/plugins/disableall.php deleted file mode 100644 index bd68c17b1..000000000 --- a/actions/admin/plugins/disableall.php +++ /dev/null @@ -1,30 +0,0 @@ -<?php -/** - * Disable all installed plugins. - * - * All plugins in the mod/ directory are disabled and the views cache and simplecache - * are reset. - * - * @package Elgg.Core - * @subpackage Administration.Site - */ - -admin_gatekeeper(); - -$plugins = get_installed_plugins(); - -foreach ($plugins as $p => $data) { - if (disable_plugin($p)) { - elgg_delete_admin_notice('first_installation_plugin_reminder'); - system_message(sprintf(elgg_echo('admin:plugins:disable:yes'), $p)); - } else { - register_error(sprintf(elgg_echo('admin:plugins:disable:no'), $p)); - } -} - -// don't regenerate the simplecache because the plugin won't be -// loaded until next run. Just invalidate and let it regnerate as needed -elgg_invalidate_simplecache(); -elgg_filepath_cache_reset(); - -forward(REFERER); diff --git a/actions/admin/plugins/enable.php b/actions/admin/plugins/enable.php deleted file mode 100644 index b15666093..000000000 --- a/actions/admin/plugins/enable.php +++ /dev/null @@ -1,36 +0,0 @@ -<?php -/** - * Enables a plugin or plugins. - * - * Plugins to be enabled are passed via $_REQUEST['plugin'] as plugin ID (directory name). - * After enabling the plugin(s), the views cache and simplecache are reset. - * - * @uses mixed $_GET['plugin'] The id (directory name) of the plugin to enable. Can be an array. - * - * @package Elgg.Core - * @subpackage Administration.Site - */ - -admin_gatekeeper(); - -$plugin = get_input('plugin'); - -if (!is_array($plugin)) { - $plugin = array($plugin); -} - -foreach ($plugin as $p) { - if (enable_plugin($p)) { - elgg_delete_admin_notice('first_installation_plugin_reminder'); - system_message(sprintf(elgg_echo('admin:plugins:enable:yes'), $p)); - } else { - register_error(sprintf(elgg_echo('admin:plugins:enable:no'), $p)); - } -} - -// don't regenerate the simplecache because the plugin won't be -// loaded until next run. Just invalidate and let it regnerate as needed -elgg_invalidate_simplecache(); -elgg_filepath_cache_reset(); - -forward(REFERER);
\ No newline at end of file diff --git a/actions/admin/plugins/enableall.php b/actions/admin/plugins/enableall.php deleted file mode 100644 index b959c235f..000000000 --- a/actions/admin/plugins/enableall.php +++ /dev/null @@ -1,30 +0,0 @@ -<?php -/** - * Enables all installed plugins. - * - * All plugins in the mod/ directory are enabled and the views cache and simplecache - * are reset. - * - * @package Elgg.Core - * @subpackage Administration.Site - */ - -admin_gatekeeper(); - -$plugins = get_installed_plugins(); - -foreach ($plugins as $p => $data) { - if (enable_plugin($p)) { - elgg_delete_admin_notice('first_installation_plugin_reminder'); - system_message(sprintf(elgg_echo('admin:plugins:enable:yes'), $p)); - } else { - register_error(sprintf(elgg_echo('admin:plugins:enable:no'), $p)); - } -} - -// don't regenerate the simplecache because the plugin won't be -// loaded until next run. Just invalidate and let it regnerate as needed -elgg_invalidate_simplecache(); -elgg_filepath_cache_reset(); - -forward(REFERER);
\ No newline at end of file diff --git a/actions/admin/plugins/reorder.php b/actions/admin/plugins/reorder.php deleted file mode 100644 index e3c65f6e5..000000000 --- a/actions/admin/plugins/reorder.php +++ /dev/null @@ -1,53 +0,0 @@ -<?php -/** - * Changes the load order of a plugin. - * - * Plugin order affects priority for view, action, and page handler - * overriding as well as the order of view extensions. Higher numbers - * are loaded after lower numbers, and so receive higher priority. - * - * NOTE: When viewing the admin page (advanced plugin admin in >= 1.8) plugins - * LOWER on the page have HIGHER priority and will override views, etc - * from plugins above them. - * - * @package Elgg.Core - * @subpackage Administration.Site - */ - -admin_gatekeeper(); - -$mod = get_input('plugin'); -$mod = str_replace('.', '', $mod); -$mod = str_replace('/', '', $mod); - -// Get the new order -$order = (int) get_input('order'); - -// Get the current plugin list -$plugins = get_plugin_list(); - -// Inject the plugin order back into the list -if ($key = array_search($mod, $plugins)) { - - unset($plugins[$key]); - while (isset($plugins[$order])) { - $order++; - } - - $plugins[$order] = $mod; -} - -// Disable -if (regenerate_plugin_list($plugins)) { - elgg_delete_admin_notice('first_installation_plugin_reminder'); - system_message(sprintf(elgg_echo('admin:plugins:reorder:yes'), $plugin)); -} else { - register_error(sprintf(elgg_echo('admin:plugins:reorder:no'), $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_invalidate_simplecache(); -elgg_filepath_cache_reset(); - -forward(REFERER);
\ No newline at end of file diff --git a/actions/admin/plugins/set_priority.php b/actions/admin/plugins/set_priority.php new file mode 100644 index 000000000..edd735371 --- /dev/null +++ b/actions/admin/plugins/set_priority.php @@ -0,0 +1,39 @@ +<?php +/** + * Changes the load priority of a plugin. + * + * Plugin priority affects view, action, and page handler + * overriding as well as the order of view extensions. Plugins with higher + * priority are loaded after and override plugins with lower priorities. + * + * NOTE: When viewing the plugin admin page, plugins LOWER on the page + * have HIGHER priority and will override views, etc from plugins above them. + * + * @package Elgg.Core + * @subpackage Administration.Plugins + */ + +$plugin_guid = get_input('plugin_guid'); +$priority = get_input('priority'); + +$plugin = get_entity($plugin_guid); + +if (!($plugin instanceof ElggPlugin)) { + register_error(elgg_echo('admin:plugins:set_priority:no', array($plugin_guid))); + forward(REFERER); +} + +if ($plugin->setPriority($priority)) { + //system_message(elgg_echo('admin:plugins:set_priority:yes', array($plugin->getManifest()->getName()))); +} else { + $msg = $plugin->getError(); + $string = ($msg) ? 'admin:plugins:set_priority:no_with_msg' : 'admin:plugins:set_priority:no'; + register_error(elgg_echo($string, array($plugin->getFriendlyName(), $plugin->getError()))); +} + +// don't regenerate the simplecache because the plugin won't be +// loaded until next run. Just invalidate and let it regnerate as needed +elgg_invalidate_simplecache(); +elgg_reset_system_cache(); + +forward(REFERER);
\ No newline at end of file diff --git a/actions/admin/plugins/simple_update_states.php b/actions/admin/plugins/simple_update_states.php deleted file mode 100644 index 7d01e4a46..000000000 --- a/actions/admin/plugins/simple_update_states.php +++ /dev/null @@ -1,53 +0,0 @@ -<?php -/** - * Bulk enable and disable for plugins appearing in the "simple" interface. - * - * Plugins marked as using the "simple" interface can be enabled and disabled - * en masse by passing the enabled plugins as an array of their plugin ids - * (directory names) through $_REQUEST['enabled_plugins']. All "simple" plugins - * not in this array will be disabled. - * - * Simplecache and views cache are reset. - * - * @uses array $_REQUEST['enabled_plugins'] An array of plugin ids (directory names) to enable. - * - * @since 1.8 - * @package Elgg.Core - * @subpackage Administration.Site - */ - -$installed_plugins = get_installed_plugins(); -$enabled_plugins = get_input('enabled_plugins', array()); - -$success = TRUE; - -foreach ($installed_plugins as $plugin => $info) { - // this is only for simple plugins. - $interface_type = elgg_get_array_value('admin_interface', $info['manifest'], NULL); - if (!$interface_type || $interface_type != 'simple') { - continue; - } - - $plugin_enabled = is_plugin_enabled($plugin); - - // only effect changes to plugins not already in that state. - if ($plugin_enabled && !in_array($plugin, $enabled_plugins)) { - $success = $success && disable_plugin($plugin); - } elseif (!$plugin_enabled && in_array($plugin, $enabled_plugins)) { - $success = $success && enable_plugin($plugin); - } -} - -if ($success) { - elgg_delete_admin_notice('first_installation_plugin_reminder'); - system_message(elgg_echo('admin:plugins:simple_simple_success')); -} else { - register_error(elgg_echo('admins:plugins:simple_simple_fail')); -} - -// don't regenerate the simplecache because the plugin won't be -// loaded until next run. Just invalidate and let it regnerate as needed -elgg_invalidate_simplecache(); -elgg_filepath_cache_reset(); - -forward(REFERER);
\ No newline at end of file diff --git a/actions/admin/site/flush_cache.php b/actions/admin/site/flush_cache.php new file mode 100644 index 000000000..ebb8296c7 --- /dev/null +++ b/actions/admin/site/flush_cache.php @@ -0,0 +1,10 @@ +<?php +/** + * Flush all the caches + */ + +elgg_invalidate_simplecache(); +elgg_reset_system_cache(); + +system_message(elgg_echo('admin:cache:flushed')); +forward(REFERER);
\ No newline at end of file diff --git a/actions/admin/site/regenerate_secret.php b/actions/admin/site/regenerate_secret.php new file mode 100644 index 000000000..3112fb5f3 --- /dev/null +++ b/actions/admin/site/regenerate_secret.php @@ -0,0 +1,11 @@ +<?php +/** + * Generate a new site secret + */ + +init_site_secret(); +elgg_reset_system_cache(); + +system_message(elgg_echo('admin:site:secret_regenerated')); + +forward(REFERER); diff --git a/actions/admin/site/unlock_upgrade.php b/actions/admin/site/unlock_upgrade.php new file mode 100644 index 000000000..b625b1d26 --- /dev/null +++ b/actions/admin/site/unlock_upgrade.php @@ -0,0 +1,10 @@ +<?php +/** + * Unlocks the upgrade script + */ + +if (_elgg_upgrade_is_locked()) { + _elgg_upgrade_unlock(); +} +system_message(elgg_echo('upgrade:unlock:success')); +forward(REFERER); diff --git a/actions/admin/site/update_advanced.php b/actions/admin/site/update_advanced.php index 127fd38b6..4888b0a8d 100644 --- a/actions/admin/site/update_advanced.php +++ b/actions/admin/site/update_advanced.php @@ -9,29 +9,43 @@ * @subpackage Administration.Site */ -admin_gatekeeper(); - -if (datalist_get('default_site')) { - $site = get_entity(datalist_get('default_site')); +if ($site = elgg_get_site_entity()) { if (!($site instanceof ElggSite)) { throw new InstallationException(elgg_echo('InvalidParameterException:NonElggSite')); } - $site->url = get_input('wwwroot'); + $site->url = rtrim(get_input('wwwroot', '', false), '/') . '/'; + + datalist_set('path', sanitise_filepath(get_input('path', '', false))); + $dataroot = sanitise_filepath(get_input('dataroot', '', false)); + + // check for relative paths + if (stripos(PHP_OS, 'win') === 0) { + if (strpos($dataroot, ':') !== 1) { + $msg = elgg_echo('admin:configuration:dataroot:relative_path', array($dataroot)); + register_error($msg); + forward(REFERER); + } + } else { + if (strpos($dataroot, '/') !== 0) { + $msg = elgg_echo('admin:configuration:dataroot:relative_path', array($dataroot)); + register_error($msg); + forward(REFERER); + } + } - datalist_set('path', sanitise_filepath(get_input('path'))); - datalist_set('dataroot', sanitise_filepath(get_input('dataroot'))); + datalist_set('dataroot', $dataroot); if (get_input('simplecache_enabled')) { - elgg_view_enable_simplecache(); + elgg_enable_simplecache(); } else { - elgg_view_disable_simplecache(); + elgg_disable_simplecache(); } - if (get_input('viewpath_cache_enabled')) { - elgg_enable_filepath_cache(); + if (get_input('system_cache_enabled')) { + elgg_enable_system_cache(); } else { - elgg_disable_filepath_cache(); + elgg_disable_system_cache(); } set_config('default_access', get_input('default_access', ACCESS_PRIVATE), $site->getGUID()); @@ -39,8 +53,6 @@ if (datalist_get('default_site')) { $user_default_access = (get_input('allow_user_default_access')) ? 1 : 0; set_config('allow_user_default_access', $user_default_access, $site->getGUID()); - set_config('view', get_input('view'), $site->getGUID()); - $debug = get_input('debug'); if ($debug) { set_config('debug', $debug, $site->getGUID()); diff --git a/actions/admin/site/update_basic.php b/actions/admin/site/update_basic.php index 94882cfd3..9765182cc 100644 --- a/actions/admin/site/update_basic.php +++ b/actions/admin/site/update_basic.php @@ -10,20 +10,18 @@ * @subpackage Administration.Site */ -admin_gatekeeper(); - -if (datalist_get('default_site')) { - $site = get_entity(datalist_get('default_site')); +if ($site = elgg_get_site_entity()) { if (!($site instanceof ElggSite)) { throw new InstallationException(elgg_echo('InvalidParameterException:NonElggSite')); } $site->description = get_input('sitedescription'); - $site->name = get_input('sitename'); + $site->name = strip_tags(get_input('sitename')); $site->email = get_input('siteemail'); $site->save(); set_config('language', get_input('language'), $site->getGUID()); } +system_message(elgg_echo('admin:configuration:success')); forward(REFERER);
\ No newline at end of file diff --git a/actions/admin/user/ban.php b/actions/admin/user/ban.php index 6622673e6..209ece2a0 100644 --- a/actions/admin/user/ban.php +++ b/actions/admin/user/ban.php @@ -9,13 +9,16 @@ * @subpackage Administration.User */ -admin_gatekeeper(); - $guid = get_input('guid'); -$obj = get_entity($guid); +$user = get_entity($guid); + +if ($guid == elgg_get_logged_in_user_guid()) { + register_error(elgg_echo('admin:user:self:ban:no')); + forward(REFERER); +} -if (($obj instanceof ElggUser) && ($obj->canEdit())) { - if ($obj->ban('banned')) { +if (($user instanceof ElggUser) && ($user->canEdit())) { + if ($user->ban('banned')) { system_message(elgg_echo('admin:user:ban:yes')); } else { register_error(elgg_echo('admin:user:ban:no')); @@ -24,4 +27,4 @@ if (($obj instanceof ElggUser) && ($obj->canEdit())) { register_error(elgg_echo('admin:user:ban:no')); } -forward('pg/admin/user/');
\ No newline at end of file +forward(REFERER);
\ No newline at end of file diff --git a/actions/admin/user/delete.php b/actions/admin/user/delete.php index 375f8b809..7cfbd0925 100644 --- a/actions/admin/user/delete.php +++ b/actions/admin/user/delete.php @@ -9,20 +9,21 @@ * @subpackage Administration.User */ -// block non-admin users - require since this action is not registered -// @todo why isn't this action registered? -admin_gatekeeper(); - // Get the user $guid = get_input('guid'); -$obj = get_entity($guid); +$user = get_entity($guid); + +if ($guid == elgg_get_logged_in_user_guid()) { + register_error(elgg_echo('admin:user:self:delete:no')); + forward(REFERER); +} -$name = $obj->name; -$username = $obj->username; +$name = $user->name; +$username = $user->username; -if (($obj instanceof ElggUser) && ($obj->canEdit())) { - if ($obj->delete()) { - system_message(sprintf(elgg_echo('admin:user:delete:yes'), $name)); +if (($user instanceof ElggUser) && ($user->canEdit())) { + if ($user->delete()) { + system_message(elgg_echo('admin:user:delete:yes', array($name))); } else { register_error(elgg_echo('admin:user:delete:no')); } @@ -33,7 +34,7 @@ if (($obj instanceof ElggUser) && ($obj->canEdit())) { // forward to user administration if on a user's page as it no longer exists $forward = REFERER; if (strpos($_SERVER['HTTP_REFERER'], $username) != FALSE) { - $forward = "pg/admin/user/"; + $forward = "admin/users/newest"; } forward($forward); diff --git a/actions/admin/user/makeadmin.php b/actions/admin/user/makeadmin.php index 19f365d62..54b0b7070 100644 --- a/actions/admin/user/makeadmin.php +++ b/actions/admin/user/makeadmin.php @@ -11,8 +11,6 @@ * @subpackage Administration.User */ -admin_gatekeeper(); - $guid = get_input('guid'); $user = get_entity($guid); diff --git a/actions/admin/user/removeadmin.php b/actions/admin/user/removeadmin.php index 468670940..8cebc7078 100644 --- a/actions/admin/user/removeadmin.php +++ b/actions/admin/user/removeadmin.php @@ -6,11 +6,14 @@ * @subpackage Administration.User */ -admin_gatekeeper(); - $guid = get_input('guid'); $user = get_entity($guid); +if ($guid == elgg_get_logged_in_user_guid()) { + register_error(elgg_echo('admin:user:self:removeadmin:no')); + forward(REFERER); +} + if (($user instanceof ElggUser) && ($user->canEdit())) { if ($user->removeAdmin()) { system_message(elgg_echo('admin:user:removeadmin:yes')); diff --git a/actions/admin/user/resetpassword.php b/actions/admin/user/resetpassword.php index 46a983c86..d019a7f55 100644 --- a/actions/admin/user/resetpassword.php +++ b/actions/admin/user/resetpassword.php @@ -14,25 +14,23 @@ * @subpackage Administration.User */ -admin_gatekeeper(); - $guid = get_input('guid'); -$obj = get_entity($guid); +$user = get_entity($guid); -if (($obj instanceof ElggUser) && ($obj->canEdit())) { +if (($user instanceof ElggUser) && ($user->canEdit())) { $password = generate_random_cleartext_password(); // Always reset the salt before generating the user password. - $obj->salt = generate_random_cleartext_password(); - $obj->password = generate_user_password($obj, $password); + $user->salt = generate_random_cleartext_password(); + $user->password = generate_user_password($user, $password); - if ($obj->save()) { + if ($user->save()) { system_message(elgg_echo('admin:user:resetpassword:yes')); - notify_user($obj->guid, - $CONFIG->site->guid, + notify_user($user->guid, + elgg_get_site_entity()->guid, elgg_echo('email:resetpassword:subject'), - sprintf(elgg_echo('email:resetpassword:body'), $obj->username, $password), + elgg_echo('email:resetpassword:body', array($user->username, $password)), NULL, 'email'); } else { diff --git a/actions/admin/user/unban.php b/actions/admin/user/unban.php index 66173623a..7a772a0d3 100644 --- a/actions/admin/user/unban.php +++ b/actions/admin/user/unban.php @@ -6,16 +6,14 @@ * @subpackage Administration.User */ -admin_gatekeeper(); - $access_status = access_get_show_hidden_status(); access_show_hidden_entities(true); $guid = get_input('guid'); -$obj = get_entity($guid); +$user = get_entity($guid); -if (($obj instanceof ElggUser) && ($obj->canEdit())) { - if ($obj->unban()) { +if (($user instanceof ElggUser) && ($user->canEdit())) { + if ($user->unban()) { system_message(elgg_echo('admin:user:unban:yes')); } else { register_error(elgg_echo('admin:user:unban:no')); diff --git a/actions/avatar/crop.php b/actions/avatar/crop.php new file mode 100644 index 000000000..b9a80f331 --- /dev/null +++ b/actions/avatar/crop.php @@ -0,0 +1,72 @@ +<?php +/** + * Avatar crop action + * + */ + +$guid = get_input('guid'); +$owner = get_entity($guid); + +if (!$owner || !($owner instanceof ElggUser) || !$owner->canEdit()) { + register_error(elgg_echo('avatar:crop:fail')); + forward(REFERER); +} + +$x1 = (int) get_input('x1', 0); +$y1 = (int) get_input('y1', 0); +$x2 = (int) get_input('x2', 0); +$y2 = (int) get_input('y2', 0); + +$filehandler = new ElggFile(); +$filehandler->owner_guid = $owner->getGUID(); +$filehandler->setFilename("profile/" . $owner->guid . "master" . ".jpg"); +$filename = $filehandler->getFilenameOnFilestore(); + +// ensuring the avatar image exists in the first place +if (!file_exists($filename)) { + register_error(elgg_echo('avatar:crop:fail')); + forward(REFERER); +} + +$icon_sizes = elgg_get_config('icon_sizes'); +unset($icon_sizes['master']); + +// get the images and save their file handlers into an array +// so we can do clean up if one fails. +$files = array(); +foreach ($icon_sizes as $name => $size_info) { + $resized = get_resized_image_from_existing_file($filename, $size_info['w'], $size_info['h'], $size_info['square'], $x1, $y1, $x2, $y2, $size_info['upscale']); + + if ($resized) { + //@todo Make these actual entities. See exts #348. + $file = new ElggFile(); + $file->owner_guid = $guid; + $file->setFilename("profile/{$guid}{$name}.jpg"); + $file->open('write'); + $file->write($resized); + $file->close(); + $files[] = $file; + } else { + // cleanup on fail + foreach ($files as $file) { + $file->delete(); + } + + register_error(elgg_echo('avatar:resize:fail')); + forward(REFERER); + } +} + +$owner->icontime = time(); + +$owner->x1 = $x1; +$owner->x2 = $x2; +$owner->y1 = $y1; +$owner->y2 = $y2; + +system_message(elgg_echo('avatar:crop:success')); +$view = 'river/user/default/profileiconupdate'; +elgg_delete_river(array('subject_guid' => $owner->guid, 'view' => $view)); +add_to_river($view, 'update', $owner->guid, $owner->guid); + +forward(REFERER); diff --git a/actions/avatar/remove.php b/actions/avatar/remove.php new file mode 100644 index 000000000..9cb40a760 --- /dev/null +++ b/actions/avatar/remove.php @@ -0,0 +1,36 @@ +<?php +/** + * Avatar remove action + */ + +$user_guid = get_input('guid'); +$user = get_user($user_guid); + +if (!$user || !$user->canEdit()) { + register_error(elgg_echo('avatar:remove:fail')); + forward(REFERER); +} + +// Delete all icons from diskspace +$icon_sizes = elgg_get_config('icon_sizes'); +foreach ($icon_sizes as $name => $size_info) { + $file = new ElggFile(); + $file->owner_guid = $user_guid; + $file->setFilename("profile/{$user_guid}{$name}.jpg"); + $filepath = $file->getFilenameOnFilestore(); + if (!$file->delete()) { + elgg_log("Avatar file remove failed. Remove $filepath manually, please.", 'WARNING'); + } +} + +// Remove crop coords +unset($user->x1); +unset($user->x2); +unset($user->y1); +unset($user->y2); + +// Remove icon +unset($user->icontime); + +system_message(elgg_echo('avatar:remove:success')); +forward(REFERER); diff --git a/actions/avatar/upload.php b/actions/avatar/upload.php new file mode 100644 index 000000000..0752615e0 --- /dev/null +++ b/actions/avatar/upload.php @@ -0,0 +1,62 @@ +<?php +/** + * Avatar upload action + */ + +$guid = get_input('guid'); +$owner = get_entity($guid); + +if (!$owner || !($owner instanceof ElggUser) || !$owner->canEdit()) { + register_error(elgg_echo('avatar:upload:fail')); + forward(REFERER); +} + +if ($_FILES['avatar']['error'] != 0) { + register_error(elgg_echo('avatar:upload:fail')); + forward(REFERER); +} + +$icon_sizes = elgg_get_config('icon_sizes'); + +// get the images and save their file handlers into an array +// so we can do clean up if one fails. +$files = array(); +foreach ($icon_sizes as $name => $size_info) { + $resized = get_resized_image_from_uploaded_file('avatar', $size_info['w'], $size_info['h'], $size_info['square'], $size_info['upscale']); + + if ($resized) { + //@todo Make these actual entities. See exts #348. + $file = new ElggFile(); + $file->owner_guid = $guid; + $file->setFilename("profile/{$guid}{$name}.jpg"); + $file->open('write'); + $file->write($resized); + $file->close(); + $files[] = $file; + } else { + // cleanup on fail + foreach ($files as $file) { + $file->delete(); + } + + register_error(elgg_echo('avatar:resize:fail')); + forward(REFERER); + } +} + +// reset crop coordinates +$owner->x1 = 0; +$owner->x2 = 0; +$owner->y1 = 0; +$owner->y2 = 0; + +$owner->icontime = time(); +if (elgg_trigger_event('profileiconupdate', $owner->type, $owner)) { + system_message(elgg_echo("avatar:upload:success")); + + $view = 'river/user/default/profileiconupdate'; + elgg_delete_river(array('subject_guid' => $owner->guid, 'view' => $view)); + add_to_river($view, 'update', $owner->guid, $owner->guid); +} + +forward(REFERER); diff --git a/actions/comments/add.php b/actions/comments/add.php index b7feb4b66..5bd741413 100644 --- a/actions/comments/add.php +++ b/actions/comments/add.php @@ -6,14 +6,9 @@ * @subpackage Comments */ -// Make sure we're logged in; forward to the front page if not -gatekeeper(); - -// Get input $entity_guid = (int) get_input('entity_guid'); $comment_text = get_input('generic_comment'); -// make sure comment is not empty if (empty($comment_text)) { register_error(elgg_echo("generic_comment:blank")); forward(REFERER); @@ -26,7 +21,7 @@ if (!$entity) { forward(REFERER); } -$user = get_loggedin_user(); +$user = elgg_get_logged_in_user_entity(); $annotation = create_annotation($entity->guid, 'generic_comment', @@ -47,22 +42,21 @@ if ($entity->owner_guid != $user->guid) { notify_user($entity->owner_guid, $user->guid, elgg_echo('generic_comment:email:subject'), - sprintf( - elgg_echo('generic_comment:email:body'), + elgg_echo('generic_comment:email:body', array( $entity->title, $user->name, $comment_text, $entity->getURL(), $user->name, $user->getURL() - ) + )) ); } system_message(elgg_echo("generic_comment:posted")); //add to river -add_to_river('annotation/annotate', 'comment', $user->guid, $entity->guid, "", 0, $annotation); +add_to_river('river/annotation/generic_comment/create', 'comment', $user->guid, $entity->guid, "", 0, $annotation); // Forward to the page the action occurred on forward(REFERER); diff --git a/actions/comments/delete.php b/actions/comments/delete.php index d0f5c7b84..c6b481da4 100644 --- a/actions/comments/delete.php +++ b/actions/comments/delete.php @@ -5,26 +5,14 @@ * @package Elgg */ -// Ensure we're logged in -if (!isloggedin()) { - forward(); -} - // Make sure we can get the comment in question $annotation_id = (int) get_input('annotation_id'); -if ($comment = get_annotation($annotation_id)) { - - $entity = get_entity($comment->entity_guid); - - if ($comment->canEdit()) { - $comment->delete(); - system_message(elgg_echo("generic_comment:deleted")); - forward($entity->getURL()); - } - +$comment = elgg_get_annotation_from_id($annotation_id); +if ($comment && $comment->canEdit()) { + $comment->delete(); + system_message(elgg_echo("generic_comment:deleted")); } else { - $url = ""; + register_error(elgg_echo("generic_comment:notdeleted")); } -register_error(elgg_echo("generic_comment:notdeleted")); forward(REFERER);
\ No newline at end of file diff --git a/actions/email/save.php b/actions/email/save.php deleted file mode 100644 index 0dee6ee1e..000000000 --- a/actions/email/save.php +++ /dev/null @@ -1,43 +0,0 @@ -<?php -/** - * Save email address for user. - * - * @package Elgg.Core - * @subpackage Administration.Users - */ - -gatekeeper(); - -$email = get_input('email'); -$user_id = get_input('guid'); - -if (!$user_id) { - $user = get_loggedin_user(); -} else { - $user = get_entity($user_id); -} - -if (!is_email_address($email)) { - register_error(elgg_echo('email:save:fail')); - forward(REFERER); -} - -if ($user) { - if (strcmp($email, $user->email) != 0) { - if (!get_user_by_email($email)) { - if ($user->email != $email) { - - $user->email = $email; - if ($user->save()) { - system_message(elgg_echo('email:save:success')); - } else { - register_error(elgg_echo('email:save:fail')); - } - } - } else { - register_error(elgg_echo('registration:dupeemail')); - } - } -} else { - register_error(elgg_echo('email:save:fail')); -} diff --git a/actions/entities/delete.php b/actions/entities/delete.php index 3ec88bd04..251e1f01c 100644 --- a/actions/entities/delete.php +++ b/actions/entities/delete.php @@ -6,19 +6,17 @@ * @subpackage Core */ -gatekeeper(); - $guid = get_input('guid'); $entity = get_entity($guid); if (($entity) && ($entity->canEdit())) { if ($entity->delete()) { - system_message(sprintf(elgg_echo('entity:delete:success'), $guid)); + system_message(elgg_echo('entity:delete:success', array($guid))); } else { - register_error(sprintf(elgg_echo('entity:delete:fail'), $guid)); + register_error(elgg_echo('entity:delete:fail', array($guid))); } } else { - register_error(sprintf(elgg_echo('entity:delete:fail'), $guid)); + register_error(elgg_echo('entity:delete:fail', array($guid))); } forward(REFERER); diff --git a/actions/friends/add.php b/actions/friends/add.php index 60431a27d..d1800ee14 100644 --- a/actions/friends/add.php +++ b/actions/friends/add.php @@ -6,28 +6,29 @@ * @subpackage Friends.Management */ -// Ensure we are logged in -gatekeeper(); - // Get the GUID of the user to friend $friend_guid = get_input('friend'); $friend = get_entity($friend_guid); +if (!$friend) { + register_error(elgg_echo('error:missing_data')); + forward(REFERER); +} $errors = false; // Get the user try { - if (!get_loggedin_user()->addFriend($friend_guid)) { + if (!elgg_get_logged_in_user_entity()->addFriend($friend_guid)) { $errors = true; } } catch (Exception $e) { - register_error(sprintf(elgg_echo("friends:add:failure"), $friend->name)); + register_error(elgg_echo("friends:add:failure", array($friend->name))); $errors = true; } if (!$errors) { // add to river - add_to_river('friends/river/create', 'friend', get_loggedin_userid(), $friend_guid); - system_message(sprintf(elgg_echo("friends:add:successful"), $friend->name)); + add_to_river('river/relationship/friend/create', 'friend', elgg_get_logged_in_user_guid(), $friend_guid); + system_message(elgg_echo("friends:add:successful", array($friend->name))); } // Forward back to the page you friended the user on diff --git a/actions/friends/addcollection.php b/actions/friends/addcollection.php deleted file mode 100644 index 8fdb2be87..000000000 --- a/actions/friends/addcollection.php +++ /dev/null @@ -1,39 +0,0 @@ -<?php -/** - * Elgg collection add page - * - * @package Elgg.Core - * @subpackage Friends.Collections - */ - -//must be logged in -gatekeeper(); - -$collection_name = get_input('collection_name'); -$friends = get_input('friends_collection'); - -//first check to make sure that a collection name has been set and create the new colection -if ($collection_name) { - - //create the collection - $create_collection = create_access_collection($collection_name, get_loggedin_userid()); - - //if the collection was created and the user passed some friends from the form, add them - if ($create_collection && (!empty($friends))) { - //add friends to the collection - foreach ($friends as $friend) { - add_user_to_access_collection($friend, $create_collection); - } - } - - // Success message - system_message(elgg_echo("friends:collectionadded")); - // Forward to the collections page - forward("pg/collections/" . get_loggedin_user()->username); - -} else { - register_error(elgg_echo("friends:nocollectionname")); - - // Forward to the add collection page - forward("pg/collections/add"); -} diff --git a/actions/friends/collections/add.php b/actions/friends/collections/add.php new file mode 100644 index 000000000..e63a149f7 --- /dev/null +++ b/actions/friends/collections/add.php @@ -0,0 +1,31 @@ +<?php +/** + * Elgg collection add page + * + * @package Elgg.Core + * @subpackage Friends.Collections + */ + +$collection_name = htmlspecialchars(get_input('collection_name', '', false), ENT_QUOTES, 'UTF-8'); +$friends = get_input('friends_collection'); + +if (!$collection_name) { + register_error(elgg_echo("friends:nocollectionname")); + forward(REFERER); +} + +$id = create_access_collection($collection_name); + +if ($id) { + $result = update_access_collection($id, $friends); + if ($result) { + system_message(elgg_echo("friends:collectionadded")); + forward("collections/" . elgg_get_logged_in_user_entity()->username); + } else { + register_error(elgg_echo("friends:nocollectionname")); + forward(REFERER); + } +} else { + register_error(elgg_echo("friends:nocollectionname")); + forward(REFERER); +}
\ No newline at end of file diff --git a/actions/friends/collections/delete.php b/actions/friends/collections/delete.php new file mode 100644 index 000000000..ff8f1fb55 --- /dev/null +++ b/actions/friends/collections/delete.php @@ -0,0 +1,23 @@ +<?php +/** + * Elgg friends: delete collection action + * + * @package Elgg.Core + * @subpackage Friends.Collections + */ + +$collection_id = (int) get_input('collection'); + +// check the ACL exists and we can edit +if (!can_edit_access_collection($collection_id)) { + register_error(elgg_echo("friends:collectiondeletefailed")); + forward(REFERER); +} + +if (delete_access_collection($collection_id)) { + system_message(elgg_echo("friends:collectiondeleted")); +} else { + register_error(elgg_echo("friends:collectiondeletefailed")); +} + +forward(REFERER); diff --git a/actions/friends/collections/edit.php b/actions/friends/collections/edit.php new file mode 100644 index 000000000..9eb5e1eab --- /dev/null +++ b/actions/friends/collections/edit.php @@ -0,0 +1,23 @@ +<?php +/** + * Friends collection edit action + * + * @package Elgg.Core + * @subpackage Friends.Collections + */ + +$collection_id = get_input('collection_id'); +$friends = get_input('friend'); + +// check it exists and we can edit +if (!can_edit_access_collection($collection_id)) { + system_message(elgg_echo('friends:collection:edit_failed')); +} + +if (update_access_collection($collection_id, $friends)) { + system_message(elgg_echo('friends:collections:edited')); +} else { + system_message(elgg_echo('friends:collection:edit_failed')); +} + +forward(REFERER);
\ No newline at end of file diff --git a/actions/friends/deletecollection.php b/actions/friends/deletecollection.php deleted file mode 100644 index b57802ce7..000000000 --- a/actions/friends/deletecollection.php +++ /dev/null @@ -1,40 +0,0 @@ -<?php -/** - * Elgg friends: delete collection action - * - * @package Elgg.Core - * @subpackage Friends.Collections - */ - -// Make sure we're logged in (send us to the front page if not) -gatekeeper(); - -// Get input data -$collection_id = (int) get_input('collection'); - -// Check to see that the access collection exist and grab its owner -$get_collection = get_access_collection($collection_id); - -if ($get_collection) { - - if ($get_collection->owner_guid == get_loggedin_userid()) { - - $delete_collection = delete_access_collection($collection_id); - - // Success message - if ($delete_collection) { - system_message(elgg_echo("friends:collectiondeleted")); - } else { - register_error(elgg_echo("friends:collectiondeletefailed")); - } - } else { - // Failure message - register_error(elgg_echo("friends:collectiondeletefailed")); - } -} else { - // Failure message - register_error(elgg_echo("friends:collectiondeletefailed")); -} - -// Forward to the collections page -forward("pg/collections/" . get_loggedin_user()->username); diff --git a/actions/friends/editcollection.php b/actions/friends/editcollection.php deleted file mode 100644 index 8fd1eae18..000000000 --- a/actions/friends/editcollection.php +++ /dev/null @@ -1,13 +0,0 @@ -<?php -/** - * Elgg collection add page - * - * @package Elgg.Core - * @subpackage Friends.Collections - */ - -$collection_id = get_input('collection_id'); -$friends = get_input('friend'); - -//chech the collection exists and the current user owners it -update_access_collection($collection_id, $friends);
\ No newline at end of file diff --git a/actions/friends/remove.php b/actions/friends/remove.php index 786b5975b..d69d18f31 100644 --- a/actions/friends/remove.php +++ b/actions/friends/remove.php @@ -6,9 +6,6 @@ * @subpackage Friends.Management */ -// Ensure we are logged in -gatekeeper(); - // Get the GUID of the user to friend $friend_guid = get_input('friend'); $friend = get_entity($friend_guid); @@ -17,18 +14,18 @@ $errors = false; // Get the user try{ if ($friend instanceof ElggUser) { - get_loggedin_user()->removeFriend($friend_guid); + elgg_get_logged_in_user_entity()->removeFriend($friend_guid); } else { - register_error(sprintf(elgg_echo("friends:remove:failure"), $friend->name)); + register_error(elgg_echo("friends:remove:failure", array($friend->name))); $errors = true; } } catch (Exception $e) { - register_error(sprintf(elgg_echo("friends:remove:failure"), $friend->name)); + register_error(elgg_echo("friends:remove:failure", array($friend->name))); $errors = true; } if (!$errors) { - system_message(sprintf(elgg_echo("friends:remove:successful"), $friend->name)); + system_message(elgg_echo("friends:remove:successful", array($friend->name))); } // Forward back to the page you made the friend on diff --git a/actions/import/opendd.php b/actions/import/opendd.php index 0bf748734..e63607145 100644 --- a/actions/import/opendd.php +++ b/actions/import/opendd.php @@ -9,13 +9,8 @@ * @subpackage Core */ -// Safety -admin_gatekeeper(); - -// Get input $data = get_input('data', '', false); -// Import $return = import($data); if ($return) { diff --git a/actions/likes/add.php b/actions/likes/add.php deleted file mode 100644 index 211cb340b..000000000 --- a/actions/likes/add.php +++ /dev/null @@ -1,62 +0,0 @@ -<?php -/** - * Elgg add like action - * - * @package Elgg.Core - * @subpackage Likes - */ - -gatekeeper(); -$entity_guid = (int) get_input('guid'); - -//check to see if the user has already liked the item -if (elgg_annotation_exists($entity_guid, 'likes')) { - system_message(elgg_echo("likes:alreadyliked")); - forward(REFERER); -} -// Let's see if we can get an entity with the specified GUID -$entity = get_entity($entity_guid); -if (!$entity) { - register_error(elgg_echo("likes:notfound")); - forward(REFERER); -} - -$user = get_loggedin_user(); -$annotation = create_annotation($entity->guid, - 'likes', - "likes", - "", - $user->guid, - $entity->access_id); - -// tell user annotation didn't work if that is the case -if (!$annotation) { - register_error(elgg_echo("likes:failure")); - forward(REFERER); -} - -// notify if poster wasn't owner -if ($entity->owner_guid != $user->guid) { - - notify_user($entity->owner_guid, - $user->guid, - elgg_echo('likes:email:subject'), - sprintf( - elgg_echo('likes:email:body'), - $user->name, - $entity->title, - //$comment_text, - $entity->getURL(), - $user->name, - $user->getURL() - ) - ); -} - -system_message(elgg_echo("likes:likes")); - -//add to river -add_to_river('annotation/annotatelike', 'likes', $user->guid, $entity->guid, "", 0, $annotation); - -// Forward back to the page where the user 'liked' the object -forward(REFERER); diff --git a/actions/likes/delete.php b/actions/likes/delete.php deleted file mode 100644 index 45984b581..000000000 --- a/actions/likes/delete.php +++ /dev/null @@ -1,31 +0,0 @@ -<?php -/** - * Elgg delete like action - * - * @package Elgg.Core - * @subpackage Likes - */ - -// Ensure we're logged in -if (!isloggedin()) { - forward(); -} - -// Make sure we can get the comment in question -$annotation_id = (int) get_input('annotation_id'); -if ($likes = get_annotation($annotation_id)) { - - $entity = get_entity($likes->entity_guid); - - if ($likes->canEdit()) { - $likes->delete(); - system_message(elgg_echo("likes:deleted")); - forward($entity->getURL()); - } - -} else { - $url = ""; -} - -register_error(elgg_echo("likes:notdeleted")); -forward(REFERER);
\ No newline at end of file diff --git a/actions/login.php b/actions/login.php index 67a2052b6..bd7f91299 100644 --- a/actions/login.php +++ b/actions/login.php @@ -6,59 +6,64 @@ * @subpackage User.Authentication */ +// set forward url +if (!empty($_SESSION['last_forward_from'])) { + $forward_url = $_SESSION['last_forward_from']; +} elseif (get_input('returntoreferer')) { + $forward_url = REFERER; +} else { + // forward to main index page + $forward_url = ''; +} + $username = get_input('username'); -$password = get_input("password"); -$persistent = get_input("persistent", FALSE); -$result = FALSE; +$password = get_input('password', null, false); +$persistent = (bool) get_input("persistent"); +$result = false; if (empty($username) || empty($password)) { - register_error(elgg_echo('loginerror')); + register_error(elgg_echo('login:empty')); forward(); } -// check first if logging in with email address -if (strpos($username, '@') !== FALSE && ($users = get_user_by_email($username))) { +// check if logging in with email address +if (strpos($username, '@') !== false && ($users = get_user_by_email($username))) { $username = $users[0]->username; } -if ($user = authenticate($username, $password)) { - $result = login($user, $persistent); +$result = elgg_authenticate($username, $password); +if ($result !== true) { + register_error($result); + forward(REFERER); } -// forward to correct page -if ($result) { - system_message(elgg_echo('loginok')); +$user = get_user_by_username($username); +if (!$user) { + register_error(elgg_echo('login:baduser')); + forward(REFERER); +} - if (isset($_SESSION['last_forward_from']) && $_SESSION['last_forward_from']) { - $forward_url = $_SESSION['last_forward_from']; - unset($_SESSION['last_forward_from']); +try { + login($user, $persistent); + // re-register at least the core language file for users with language other than site default + register_translations(dirname(dirname(__FILE__)) . "/languages/"); +} catch (LoginException $e) { + register_error($e->getMessage()); + forward(REFERER); +} - forward($forward_url); - } else { - if (get_input('returntoreferer')) { - forward(REFERER); - } else { - // forward to index for front page overrides. - // index will forward to dashboard if appropriate. - forward('index.php'); - } - } +// elgg_echo() caches the language and does not provide a way to change the language. +// @todo we need to use the config object to store this so that the current language +// can be changed. Refs #4171 +if ($user->language) { + $message = elgg_echo('loginok', array(), $user->language); } else { - register_error(elgg_echo('loginerror')); - // // let a plugin hook say why login failed or react to it. - // $params = array( - // 'username' => $username, - // 'password' => $password, - // 'persistent' => $persistent, - // 'user' => $user - // ); - // - // // Returning FALSE to this function will generate a standard - // // "Could not log you in" message. - // // Plugins should use this hook to provide details, and then return TRUE. - // if (!trigger_plugin_hook('failed_login', 'user', $params, FALSE)) { - // register_error(elgg_echo('loginerror')); - // } + $message = elgg_echo('loginok'); +} + +if (isset($_SESSION['last_forward_from'])) { + unset($_SESSION['last_forward_from']); } -forward(REFERRER); +system_message($message); +forward($forward_url); diff --git a/actions/logout.php b/actions/logout.php index 98926d205..c48a26b15 100644 --- a/actions/logout.php +++ b/actions/logout.php @@ -12,6 +12,7 @@ $result = logout(); // Set the system_message as appropriate if ($result) { system_message(elgg_echo('logoutok')); + forward(); } else { register_error(elgg_echo('logouterror')); }
\ No newline at end of file diff --git a/actions/notifications/settings/usersettings/save.php b/actions/notifications/settings/usersettings/save.php index da855c6b5..455a444e1 100644 --- a/actions/notifications/settings/usersettings/save.php +++ b/actions/notifications/settings/usersettings/save.php @@ -6,9 +6,7 @@ * @subpackage Core */ -// Method $method = get_input('method'); -gatekeeper(); $current_settings = get_user_notification_settings(); @@ -19,7 +17,7 @@ foreach ($method as $k => $v) { continue; } - $result = set_user_notification_setting(get_loggedin_userid(), $k, ($v == 'yes') ? true : false); + $result = set_user_notification_setting(elgg_get_logged_in_user_guid(), $k, ($v == 'yes') ? true : false); if (!$result) { register_error(elgg_echo('notifications:usersettings:save:fail')); diff --git a/actions/plugins/settings/save.php b/actions/plugins/settings/save.php index 1a8b2db3d..581a2f9ec 100644 --- a/actions/plugins/settings/save.php +++ b/actions/plugins/settings/save.php @@ -1,59 +1,43 @@ <?php /** - * Elgg plugin settings save action. + * Saves global plugin settings. * - * @package Elgg - * @subpackage Core + * This action can be overriden for a specific plugin by creating the + * <plugin_id>/settings/save action in that plugin. + * + * @uses array $_REQUEST['params'] A set of key/value pairs to save to the ElggPlugin entity + * @uses int $_REQUEST['plugin_id'] The ID of the plugin + * + * @package Elgg.Core + * @subpackage Plugins.Settings */ $params = get_input('params'); -$plugin = get_input('plugin'); -if (!$plugin_info = load_plugin_manifest($plugin)) { - register_error(sprintf(elgg_echo('plugins:settings:save:fail'), $plugin)); +$plugin_id = get_input('plugin_id'); +$plugin = elgg_get_plugin_from_id($plugin_id); + +if (!($plugin instanceof ElggPlugin)) { + register_error(elgg_echo('plugins:settings:save:fail', array($plugin_id))); forward(REFERER); } -$plugin_name = $plugin_info['name']; - -admin_gatekeeper(); +$plugin_name = $plugin->getManifest()->getName(); $result = false; -$options = array( - 'plugin' => $plugin, - 'manifest' => $plugin_info, - 'settings' => $params -); - // allow a plugin to override the save action for their settings -if (elgg_action_exist("settings/$plugin/save")) { - action("settings/$plugin/save"); +if (elgg_action_exists("$plugin_id/settings/save")) { + action("$plugin_id/settings/save"); } else { foreach ($params as $k => $v) { - if (!$result = set_plugin_setting($k, $v, $plugin)) { - register_error(sprintf(elgg_echo('plugins:settings:save:fail'), $plugin_name)); + $result = $plugin->setSetting($k, $v); + if (!$result) { + register_error(elgg_echo('plugins:settings:save:fail', array($plugin_name))); forward(REFERER); exit; } } } -system_message(sprintf(elgg_echo('plugins:settings:save:ok'), $plugin_name)); -forward(REFERER); -// -//$trigger = trigger_plugin_hook('plugin:save_settings', $plugin, $options, NULL); -//if ($trigger === NULL) { -// foreach ($params as $k => $v) { -// if (!$result = set_plugin_setting($k, $v, $plugin)) { -// register_error(sprintf(elgg_echo('plugins:settings:save:fail'), $plugin_name)); -// forward(REFERER); -// exit; -// } -// } -//} elseif ($trigger === FALSE) { -// register_error(sprintf(elgg_echo('plugins:settings:save:fail'), $plugin_name)); -// forward(REFERER); -//} -// -//system_message(sprintf(elgg_echo('plugins:settings:save:ok'), $plugin_name)); -//forward(REFERER);
\ No newline at end of file +system_message(elgg_echo('plugins:settings:save:ok', array($plugin_name))); +forward(REFERER);
\ No newline at end of file diff --git a/actions/plugins/usersettings/save.php b/actions/plugins/usersettings/save.php index 27f549184..f6b8ab0b6 100644 --- a/actions/plugins/usersettings/save.php +++ b/actions/plugins/usersettings/save.php @@ -1,29 +1,58 @@ <?php /** - * Elgg plugin user settings save action. + * Saves user-specific plugin settings. * - * @package Elgg - * @subpackage Core + * This action can be overriden for a specific plugin by creating the + * <plugin_id>/usersettings/save action in that plugin. + * + * @uses array $_REQUEST['params'] A set of key/value pairs to save to the ElggPlugin entity + * @uses int $_REQUEST['plugin_id'] The id of the plugin + * @uses int $_REQUEST['user_guid'] The GUID of the user to save settings for. + * + * @package Elgg.Core + * @subpackage Plugins.Settings */ $params = get_input('params'); -$plugin = get_input('plugin'); +$plugin_id = get_input('plugin_id'); +$user_guid = get_input('user_guid', elgg_get_logged_in_user_guid()); +$plugin = elgg_get_plugin_from_id($plugin_id); +$user = get_entity($user_guid); + +if (!($plugin instanceof ElggPlugin)) { + register_error(elgg_echo('plugins:usersettings:save:fail', array($plugin_id))); + forward(REFERER); +} -gatekeeper(); +if (!($user instanceof ElggUser)) { + register_error(elgg_echo('plugins:usersettings:save:fail', array($plugin_id))); + forward(REFERER); +} + +$plugin_name = $plugin->getManifest()->getName(); + +// make sure we're admin or the user +if (!$user->canEdit()) { + register_error(elgg_echo('plugins:usersettings:save:fail', array($plugin_name))); + forward(REFERER); +} $result = false; -foreach ($params as $k => $v) { - // Save - $result = set_plugin_usersetting($k, $v, get_loggedin_userid(), $plugin); +if (elgg_action_exists("$plugin_id/usersettings/save")) { + action("$plugin_id/usersettings/save"); +} else { + foreach ($params as $k => $v) { + // Save + $result = $plugin->setUserSetting($k, $v, $user->guid); - // Error? - if (!$result) { - register_error(sprintf(elgg_echo('plugins:usersettings:save:fail'), $plugin)); - forward(REFERER); - exit; + // Error? + if (!$result) { + register_error(elgg_echo('plugins:usersettings:save:fail', array($plugin_name))); + forward(REFERER); + } } } -system_message(sprintf(elgg_echo('plugins:usersettings:save:ok'), $plugin)); +system_message(elgg_echo('plugins:usersettings:save:ok', array($plugin_name))); forward(REFERER); diff --git a/actions/profile/edit.php b/actions/profile/edit.php new file mode 100644 index 000000000..e1f066e82 --- /dev/null +++ b/actions/profile/edit.php @@ -0,0 +1,116 @@ +<?php +/** + * Elgg profile edit action + * + */ + +elgg_make_sticky_form('profile:edit'); + +$guid = get_input('guid'); +$owner = get_entity($guid); + +if (!$owner || !($owner instanceof ElggUser) || !$owner->canEdit()) { + register_error(elgg_echo('profile:edit:fail')); + forward(REFERER); +} + +// grab the defined profile field names and their load the values from POST. +// each field can have its own access, so sort that too. +$input = array(); +$accesslevel = get_input('accesslevel'); + +if (!is_array($accesslevel)) { + $accesslevel = array(); +} + +/** + * wrapper for recursive array walk decoding + */ +function profile_array_decoder(&$v) { + $v = _elgg_html_decode($v); +} + +$profile_fields = elgg_get_config('profile_fields'); +foreach ($profile_fields as $shortname => $valuetype) { + // the decoding is a stop gap to prevent && showing up in profile fields + // because it is escaped on both input (get_input()) and output (view:output/text). see #561 and #1405. + // must decode in utf8 or string corruption occurs. see #1567. + $value = get_input($shortname); + if (is_array($value)) { + array_walk_recursive($value, 'profile_array_decoder'); + } else { + $value = _elgg_html_decode($value); + } + + // limit to reasonable sizes + // @todo - throwing away changes due to this is dumb! + if (!is_array($value) && $valuetype != 'longtext' && elgg_strlen($value) > 250) { + $error = elgg_echo('profile:field_too_long', array(elgg_echo("profile:{$shortname}"))); + register_error($error); + forward(REFERER); + } + + if ($value && $valuetype == 'url' && !preg_match('~^https?\://~i', $value)) { + $value = "http://$value"; + } + + if ($valuetype == 'tags') { + $value = string_to_tag_array($value); + } + + $input[$shortname] = $value; +} + +// display name is handled separately +$name = strip_tags(get_input('name')); +if ($name) { + if (elgg_strlen($name) > 50) { + register_error(elgg_echo('user:name:fail')); + } elseif ($owner->name != $name) { + $owner->name = $name; + $owner->save(); + } +} + +// go through custom fields +if (sizeof($input) > 0) { + foreach ($input as $shortname => $value) { + $options = array( + 'guid' => $owner->guid, + 'metadata_name' => $shortname, + 'limit' => false + ); + elgg_delete_metadata($options); + + if (!is_null($value) && ($value !== '')) { + // only create metadata for non empty values (0 is allowed) to prevent metadata records with empty string values #4858 + + if (isset($accesslevel[$shortname])) { + $access_id = (int) $accesslevel[$shortname]; + } else { + // this should never be executed since the access level should always be set + $access_id = ACCESS_DEFAULT; + } + if (is_array($value)) { + $i = 0; + foreach ($value as $interval) { + $i++; + $multiple = ($i > 1) ? TRUE : FALSE; + create_metadata($owner->guid, $shortname, $interval, 'text', $owner->guid, $access_id, $multiple); + } + } else { + create_metadata($owner->getGUID(), $shortname, $value, 'text', $owner->getGUID(), $access_id); + } + } + } + + $owner->save(); + + // Notify of profile update + elgg_trigger_event('profileupdate', $owner->type, $owner); + + elgg_clear_sticky_form('profile:edit'); + system_message(elgg_echo("profile:saved")); +} + +forward($owner->getUrl()); diff --git a/actions/profile/fields/add.php b/actions/profile/fields/add.php new file mode 100644 index 000000000..fce783092 --- /dev/null +++ b/actions/profile/fields/add.php @@ -0,0 +1,40 @@ +<?php +/** + * Elgg profile plugin edit default profile action + * + */ + +$label = get_input('label'); +$type = get_input('type'); + +$fieldlist = elgg_get_config('profile_custom_fields'); +if (!$fieldlist) { + $fieldlist = ''; + $id = 1; +} else { + $fieldlistarray = explode(',', $fieldlist); + foreach ($fieldlistarray as $key => $value) { + $fieldlistarray[$key] = (int)$value; + } + $id = max($fieldlistarray) + 1; +} + +if (($label) && ($type)) { + if (!empty($fieldlist)) { + $fieldlist .= ','; + } + $fieldlist .= "$id"; + + if (elgg_save_config("admin_defined_profile_$id", $label) && + elgg_save_config("admin_defined_profile_type_$id", $type) && + elgg_save_config('profile_custom_fields', $fieldlist)) { + + system_message(elgg_echo('profile:editdefault:success')); + } else { + register_error(elgg_echo('profile:editdefault:fail')); + } +} else { + register_error(elgg_echo('profile:editdefault:fail')); +} + +forward(REFERER);
\ No newline at end of file diff --git a/actions/profile/fields/delete.php b/actions/profile/fields/delete.php new file mode 100644 index 000000000..9879feb3f --- /dev/null +++ b/actions/profile/fields/delete.php @@ -0,0 +1,28 @@ +<?php +/** + * Elgg profile plugin edit default profile action removal + * + */ + +$id = get_input('id'); + +$fieldlist = elgg_get_config('profile_custom_fields'); +if (!$fieldlist) { + $fieldlist = ''; +} + +$fieldlist = str_replace("{$id},", "", $fieldlist); +$fieldlist = str_replace(",{$id}", "", $fieldlist); +$fieldlist = str_replace("{$id}", "", $fieldlist); + +if ($id && + unset_config("admin_defined_profile_$id") && + unset_config("admin_defined_profile_type_$id") && + elgg_save_config('profile_custom_fields', $fieldlist)) { + + system_message(elgg_echo('profile:editdefault:delete:success')); +} else { + register_error(elgg_echo('profile:editdefault:delete:fail')); +} + +forward(REFERER);
\ No newline at end of file diff --git a/actions/profile/fields/edit.php b/actions/profile/fields/edit.php new file mode 100644 index 000000000..5fc84ff11 --- /dev/null +++ b/actions/profile/fields/edit.php @@ -0,0 +1,20 @@ +<?php +/** + * Edit a custom profile field + */ + +$id = get_input('id'); +$label = get_input('label'); + +if (!elgg_get_config("admin_defined_profile_$id")) { + register_error(elgg_echo('profile:editdefault:fail')); + forward(REFERER); +} + +if (elgg_save_config("admin_defined_profile_$id", $label)) { + system_message(elgg_echo('profile:editdefault:success')); +} else { + register_error(elgg_echo('profile:editdefault:fail')); +} + +forward(REFERER);
\ No newline at end of file diff --git a/actions/profile/fields/reorder.php b/actions/profile/fields/reorder.php new file mode 100644 index 000000000..27c716749 --- /dev/null +++ b/actions/profile/fields/reorder.php @@ -0,0 +1,12 @@ +<?php +/** + * Elgg profile plugin reorder fields + * + */ + +$ordering = get_input('fieldorder'); + +$result = elgg_save_config('profile_custom_fields', $ordering); + +// called by ajax so we exit +exit; diff --git a/actions/profile/fields/reset.php b/actions/profile/fields/reset.php new file mode 100644 index 000000000..19efae479 --- /dev/null +++ b/actions/profile/fields/reset.php @@ -0,0 +1,20 @@ +<?php +/** + * Reset profile fields action + * + */ + +$fieldlist = elgg_get_config('profile_custom_fields'); +if ($fieldlist) { + $fieldlistarray = explode(',', $fieldlist); + foreach ($fieldlistarray as $listitem) { + unset_config("admin_defined_profile_{$listitem}"); + unset_config("admin_defined_profile_type_{$listitem}"); + } +} + +unset_config('profile_custom_fields'); + +system_message(elgg_echo('profile:defaultprofile:reset')); + +forward(REFERER);
\ No newline at end of file diff --git a/actions/register.php b/actions/register.php index fcb25de35..73926232c 100644 --- a/actions/register.php +++ b/actions/register.php @@ -6,18 +6,18 @@ * @subpackage User.Account */ -global $CONFIG; +elgg_make_sticky_form('register'); // Get variables $username = get_input('username'); -$password = get_input('password'); -$password2 = get_input('password2'); +$password = get_input('password', null, false); +$password2 = get_input('password2', null, false); $email = get_input('email'); $name = get_input('name'); $friend_guid = (int) get_input('friend_guid', 0); $invitecode = get_input('invitecode'); -if ($CONFIG->allow_registration) { +if (elgg_get_config('allow_registration')) { try { if (trim($password) == "" || trim($password2) == "") { throw new RegistrationException(elgg_echo('RegistrationException:EmptyPassword')); @@ -44,18 +44,28 @@ if ($CONFIG->allow_registration) { ); // @todo should registration be allowed no matter what the plugins return? - if (!trigger_plugin_hook('register', 'user', $params, TRUE)) { + if (!elgg_trigger_plugin_hook('register', 'user', $params, TRUE)) { + $ia = elgg_set_ignore_access(true); $new_user->delete(); + elgg_set_ignore_access($ia); // @todo this is a generic messages. We could have plugins // throw a RegistrationException, but that is very odd // for the plugin hooks system. throw new RegistrationException(elgg_echo('registerbad')); } - system_message(sprintf(elgg_echo("registerok"), $CONFIG->sitename)); + 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 + // plugin that has disabled the user + try { + login($new_user); + } catch (LoginException $e) { + // do nothing + } // Forward on success, assume everything else is an error... - login($new_user); forward(); } else { register_error(elgg_echo("registerbad")); @@ -67,4 +77,4 @@ if ($CONFIG->allow_registration) { register_error(elgg_echo('registerdisabled')); } -forward(REFERER);
\ No newline at end of file +forward(REFERER); diff --git a/actions/river/delete.php b/actions/river/delete.php new file mode 100644 index 000000000..0d8297932 --- /dev/null +++ b/actions/river/delete.php @@ -0,0 +1,21 @@ +<?php +/** + * River item delete action + * + * @package Elgg + * @subpackage Core + */ + +$id = get_input('id', false); + +if ($id !== false && elgg_is_admin_logged_in()) { + if (elgg_delete_river(array('id' => $id))) { + system_message(elgg_echo('river:delete:success')); + } else { + register_error(elgg_echo('river:delete:fail')); + } +} else { + register_error(elgg_echo('river:delete:fail')); +} + +forward(REFERER); diff --git a/actions/user/default_access.php b/actions/user/default_access.php deleted file mode 100644 index ae489dcbe..000000000 --- a/actions/user/default_access.php +++ /dev/null @@ -1,35 +0,0 @@ -<?php -/** - * Action for changing a user's default access level - * - * @package Elgg - * @subpackage Core - */ - -global $CONFIG; - -if ($CONFIG->allow_user_default_access) { - gatekeeper(); - - $default_access = get_input('default_access'); - $user_id = get_input('guid'); - - if (!$user_id) { - $user = get_loggedin_user(); - } else { - $user = get_entity($user_id); - } - - if ($user) { - $current_default_access = $user->getPrivateSetting('elgg_default_access'); - if ($default_access !== $current_default_access) { - if ($user->setPrivateSetting('elgg_default_access', $default_access)) { - system_message(elgg_echo('user:default_access:success')); - } else { - register_error(elgg_echo('user:default_access:fail')); - } - } - } else { - register_error(elgg_echo('user:default_access:fail')); - } -} diff --git a/actions/user/language.php b/actions/user/language.php deleted file mode 100644 index 252263cd2..000000000 --- a/actions/user/language.php +++ /dev/null @@ -1,31 +0,0 @@ -<?php -/** - * Action for changing a user's personal language settings - * - * @package Elgg - * @subpackage Core - */ - -gatekeeper(); - -$language = get_input('language'); -$user_id = get_input('guid'); - -if (!$user_id) { - $user = get_loggedin_user(); -} else { - $user = get_entity($user_id); -} - -if (($user) && ($language)) { - if (strcmp($language, $user->language) != 0) { - $user->language = $language; - if ($user->save()) { - system_message(elgg_echo('user:language:success')); - } else { - register_error(elgg_echo('user:language:fail')); - } - } -} else { - register_error(elgg_echo('user:language:fail')); -} diff --git a/actions/user/name.php b/actions/user/name.php deleted file mode 100644 index c3e79d725..000000000 --- a/actions/user/name.php +++ /dev/null @@ -1,36 +0,0 @@ -<?php -/** - * Action for changing a user's name - * - * @package Elgg - * @subpackage Core - */ - -gatekeeper(); - -$name = strip_tags(get_input('name')); -$user_id = get_input('guid'); - -if (!$user_id) { - $user = get_loggedin_user(); -} else { - $user = get_entity($user_id); -} - -if (elgg_strlen($name) > 50) { - register_error(elgg_echo('user:name:fail')); - forward(REFERER); -} - -if (($user) && ($user->canEdit()) && ($name)) { - if ($name != $user->name) { - $user->name = $name; - if ($user->save()) { - system_message(elgg_echo('user:name:success')); - } else { - register_error(elgg_echo('user:name:fail')); - } - } -} else { - register_error(elgg_echo('user:name:fail')); -} diff --git a/actions/user/password.php b/actions/user/password.php deleted file mode 100644 index ceb9d4585..000000000 --- a/actions/user/password.php +++ /dev/null @@ -1,37 +0,0 @@ -<?php -/** - * Action for changing a user's password - * - * @package Elgg - * @subpackage Core - */ - -gatekeeper(); - -$password = get_input('password'); -$password2 = get_input('password2'); -$user_id = get_input('guid'); - -if (!$user_id) { - $user = get_loggedin_user(); -} else { - $user = get_entity($user_id); -} - -if (($user) && ($password != "")) { - if (strlen($password) >= 4) { - if ($password == $password2) { - $user->salt = generate_random_cleartext_password(); // Reset the salt - $user->password = generate_user_password($user, $password); - if ($user->save()) { - system_message(elgg_echo('user:password:success')); - } else { - register_error(elgg_echo('user:password:fail')); - } - } else { - register_error(elgg_echo('user:password:fail:notsame')); - } - } else { - register_error(elgg_echo('user:password:fail:tooshort')); - } -} diff --git a/actions/user/passwordreset.php b/actions/user/passwordreset.php index 230dfd68f..201d6abcf 100644 --- a/actions/user/passwordreset.php +++ b/actions/user/passwordreset.php @@ -6,8 +6,6 @@ * @subpackage Core */ -global $CONFIG; - $user_guid = get_input('u'); $code = get_input('c'); diff --git a/actions/user/requestnewpassword.php b/actions/user/requestnewpassword.php index 22b4008e8..f1d4fa43c 100644 --- a/actions/user/requestnewpassword.php +++ b/actions/user/requestnewpassword.php @@ -8,6 +8,11 @@ $username = get_input('username'); +// allow email addresses +if (strpos($username, '@') !== false && ($users = get_user_by_email($username))) { + $username = $users[0]->username; +} + $user = get_user_by_username($username); if ($user) { if (send_new_password_request($user->guid)) { @@ -16,7 +21,7 @@ if ($user) { register_error(elgg_echo('user:password:resetreq:fail')); } } else { - register_error(sprintf(elgg_echo('user:username:notfound'), $username)); + register_error(elgg_echo('user:username:notfound', array($username))); } forward(); diff --git a/actions/user/spotlight.php b/actions/user/spotlight.php index 00525254b..202dde387 100644 --- a/actions/user/spotlight.php +++ b/actions/user/spotlight.php @@ -7,8 +7,6 @@ * @todo This is deprecated in 1.8 */ -gatekeeper(); - $closed = get_input('closed', 'true'); if ($closed != 'true') { $closed = false; @@ -16,6 +14,6 @@ if ($closed != 'true') { $closed = true; } -get_loggedin_user()->spotlightclosed = $closed; +elgg_get_logged_in_user_entity()->spotlightclosed = $closed; // exit as this action is called through Ajax exit;
\ No newline at end of file diff --git a/actions/useradd.php b/actions/useradd.php index 54def11b3..17459021b 100644 --- a/actions/useradd.php +++ b/actions/useradd.php @@ -6,13 +6,12 @@ * @subpackage Core */ -admin_gatekeeper(); // Only admins can add a user +elgg_make_sticky_form('useradd'); // Get variables -global $CONFIG; $username = get_input('username'); -$password = get_input('password'); -$password2 = get_input('password2'); +$password = get_input('password', null, false); +$password2 = get_input('password2', null, false); $email = get_input('email'); $name = get_input('name'); @@ -21,26 +20,45 @@ if (is_array($admin)) { $admin = $admin[0]; } +// no blank fields +if ($username == '' || $password == '' || $password2 == '' || $email == '' || $name == '') { + register_error(elgg_echo('register:fields')); + forward(REFERER); +} + +if (strcmp($password, $password2) != 0) { + register_error(elgg_echo('RegistrationException:PasswordMismatch')); + forward(REFERER); +} + // For now, just try and register the user try { $guid = register_user($username, $password, $name, $email, TRUE); - if (((trim($password) != "") && (strcmp($password, $password2) == 0)) && ($guid)) { + if ($guid) { $new_user = get_entity($guid); - if (($guid) && ($admin)) { + if ($new_user && $admin && elgg_is_admin_logged_in()) { $new_user->makeAdmin(); } + elgg_clear_sticky_form('useradd'); + $new_user->admin_created = TRUE; - $new_user->created_by_guid = get_loggedin_userid(); + // @todo ugh, saving a guid as metadata! + $new_user->created_by_guid = elgg_get_logged_in_user_guid(); $subject = elgg_echo('useradd:subject'); - $body = sprintf(elgg_echo('useradd:body'), $name, - $CONFIG->site->name, $CONFIG->site->url, $username, $password); + $body = elgg_echo('useradd:body', array( + $name, + elgg_get_site_entity()->name, + elgg_get_site_entity()->url, + $username, + $password, + )); - notify_user($new_user->guid, $CONFIG->site->guid, $subject, $body); + notify_user($new_user->guid, elgg_get_site_entity()->guid, $subject, $body); - system_message(sprintf(elgg_echo("adduser:ok"), $CONFIG->sitename)); + system_message(elgg_echo("adduser:ok", array(elgg_get_site_entity()->name))); } else { register_error(elgg_echo("adduser:bad")); } diff --git a/actions/usersettings/save.php b/actions/usersettings/save.php index 3e0117f06..eb6cdbd5d 100644 --- a/actions/usersettings/save.php +++ b/actions/usersettings/save.php @@ -6,10 +6,6 @@ * @subpackage UserSettings */ -global $CONFIG; - -gatekeeper(); - -trigger_plugin_hook('usersettings:save', 'user'); +elgg_trigger_plugin_hook('usersettings:save', 'user'); forward(REFERER); diff --git a/actions/widgets/add.php b/actions/widgets/add.php index 57c331e21..d7b2f291c 100644 --- a/actions/widgets/add.php +++ b/actions/widgets/add.php @@ -6,25 +6,37 @@ * @subpackage Widgets.Management */ -$guid = get_input('user'); +$owner_guid = get_input('owner_guid'); $handler = get_input('handler'); $context = get_input('context'); -$column = get_input('column'); +$show_access = (bool)get_input('show_access', true); +$column = get_input('column', 1); +$default_widgets = get_input('default_widgets', 0); -$result = false; +elgg_push_context($context); +if ($default_widgets) { + elgg_push_context('default_widgets'); +} +elgg_push_context('widgets'); + +if (!empty($owner_guid)) { + $owner = get_entity($owner_guid); + if ($owner && $owner->canEdit()) { + $guid = elgg_create_widget($owner->getGUID(), $handler, $context); + if ($guid) { + $widget = get_entity($guid); + + // position the widget + $widget->move($column, 0); -if (!empty($guid)) { - if ($user = get_entity($guid)) { - if ($user->canEdit()) { - $result = add_widget($user->getGUID(), $handler, $context, 0, $column); + // send widget html for insertion + echo elgg_view_entity($widget, array('show_access' => $show_access)); + + //system_message(elgg_echo('widgets:add:success')); + forward(REFERER); } } } -if ($result) { - system_message(elgg_echo('widgets:save:success')); -} else { - register_error(elgg_echo('widgets:save:failure')); -} - -forward(REFERER);
\ No newline at end of file +register_error(elgg_echo('widgets:add:failure')); +forward(REFERER); diff --git a/actions/widgets/delete.php b/actions/widgets/delete.php new file mode 100644 index 000000000..47920013d --- /dev/null +++ b/actions/widgets/delete.php @@ -0,0 +1,20 @@ +<?php +/** + * Elgg widget delete action + * + * @package Elgg.Core + * @subpackage Widgets.Management + */ + +$widget_guid = get_input('widget_guid'); +$owner_guid = get_input('owner_guid', elgg_get_logged_in_user_guid()); + +$widget = get_entity($widget_guid); +$owner = get_entity($owner_guid); + +if ($widget && $owner->canEdit() && $widget->delete()) { + forward(REFERER); +} + +register_error(elgg_echo('widgets:remove:failure')); +forward(REFERER); diff --git a/actions/widgets/move.php b/actions/widgets/move.php new file mode 100644 index 000000000..eab650c9c --- /dev/null +++ b/actions/widgets/move.php @@ -0,0 +1,24 @@ +<?php +/** + * Elgg widget move action + * + * @package Elgg.Core + * @subpackage Widgets.Management + */ + +$widget_guid = get_input('widget_guid'); +$column = get_input('column', 1); +$position = get_input('position'); +$owner_guid = get_input('owner_guid', elgg_get_logged_in_user_guid()); + +$widget = get_entity($widget_guid); +$owner = get_entity($owner_guid); + + +if ($widget && $owner->canEdit()) { + $widget->move($column, $position); + forward(REFERER); +} + +register_error(elgg_echo('widgets:move:failure')); +forward(REFERER);
\ No newline at end of file diff --git a/actions/widgets/save.php b/actions/widgets/save.php index 945634d97..e15deab77 100644 --- a/actions/widgets/save.php +++ b/actions/widgets/save.php @@ -1,28 +1,42 @@ <?php /** - * Elgg widget save action + * Elgg save widget settings action * * @package Elgg.Core * @subpackage Widgets.Management + * + * @uses int $_REQUEST['guid'] The guid of the widget to save + * @uses array $_REQUEST['params'] An array of params to set on the widget. + * @uses int $_REQUEST['default_widgets'] Flag for if these settings are for default wigets. + * @uses string $_REQUEST['context'] An optional context of the widget. Used to return + * the correct output if widget content changes + * depending on context. + * */ -$guid = get_input('guid'); -$params = $_REQUEST['params']; -$pageurl = get_input('pageurl'); -$noforward = get_input('noforward', false); - -$result = false; +elgg_set_context('widgets'); -if (!empty($guid)) { - $result = save_widget_info($guid, $params); -} - -if ($noforward) { - exit; -} +$guid = get_input('guid'); +$params = get_input('params'); +$default_widgets = get_input('default_widgets', 0); +$context = get_input('context'); -if ($result) { - system_message(elgg_echo('widgets:save:success')); +$widget = get_entity($guid); +if ($widget && $widget->saveSettings($params)) { + elgg_set_page_owner_guid($widget->getContainerGUID()); + if ($context) { + elgg_push_context($context); + } + + if (!$default_widgets) { + if (elgg_view_exists("widgets/$widget->handler/content")) { + $view = "widgets/$widget->handler/content"; + } else { + elgg_deprecated_notice("widgets use content as the display view", 1.8); + $view = "widgets/$widget->handler/view"; + } + echo elgg_view($view, array('entity' => $widget)); + } } else { register_error(elgg_echo('widgets:save:failure')); } diff --git a/actions/widgets/upgrade.php b/actions/widgets/upgrade.php new file mode 100644 index 000000000..0a5cf8d48 --- /dev/null +++ b/actions/widgets/upgrade.php @@ -0,0 +1,65 @@ +<?php +/** + * Upgrade default widgets for Elgg 1.8 + * + * Pre-1.8, default widgets were stored as metadata on a defaultwidgets object. + * Now they are stored as widget objects owned by the site. + * + * @package Elgg.Core + * @subpackage Widgets.Management + */ + +$object = elgg_get_entities(array( + 'type' => 'object', + 'subtype' => 'moddefaultwidgets', + 'limit' => 1, +)); + +if (!$object) { + forward(REFERER); +} + +$object = $object[0]; + +$site = elgg_get_site_entity(); + +$ia = elgg_set_ignore_access(true); +foreach (array('profile', 'dashboard') as $context) { + if (isset($object->$context)) { + elgg_push_context($context); + elgg_push_context('default_widgets'); + elgg_push_context('widgets'); + + // deserialize the widget information + list($left, $middle, $right) = split('%%', $object->$context); + $left_widgets = split('::', $left); + $middle_widgets = split('::', $middle); + $right_widgets = split('::', $right); + + // 1st column is right column in default theme + $widgets = array( + 1 => array_reverse($right_widgets), + 2 => array_reverse($middle_widgets), + 3 => array_reverse($left_widgets), + ); + + foreach ($widgets as $column => $column_widgets) { + foreach ($column_widgets as $handler) { + $guid = elgg_create_widget($site->getGUID(), $handler, $context); + if ($guid) { + $widget = get_entity($guid); + $widget->move($column, 0); + } + } + } + + elgg_pop_context(); + elgg_pop_context(); + elgg_pop_context(); + } +} +elgg_set_ignore_access($ia); + +$object->delete(); +system_message(elgg_echo('upgrade:core')); +forward(REFERER); |
