From 373ff03a2b6315eea13a97065774972ad3713ab6 Mon Sep 17 00:00:00 2001 From: brettp Date: Sat, 19 Feb 2011 02:12:32 +0000 Subject: Fixes #2753: Default widgets merged into core as extensible admin section and updated to work with new widgets. Will need an upgrade for users running the old default widgets in 1.7. git-svn-id: http://code.elgg.org/elgg/trunk@8302 36083f99-b078-4883-b0ff-0f9b5a30f544 --- mod/defaultwidgets/actions/update.php | 55 ----- mod/defaultwidgets/languages/en.php | 28 --- mod/defaultwidgets/manifest.xml | 15 -- mod/defaultwidgets/start.php | 206 ---------------- .../admin/appearance/default_dashboard_widgets.php | 18 -- .../admin/appearance/default_profile_widgets.php | 18 -- .../views/default/defaultwidgets/editor.php | 265 --------------------- mod/groups/start.php | 29 ++- mod/profile/start.php | 28 ++- 9 files changed, 55 insertions(+), 607 deletions(-) delete mode 100644 mod/defaultwidgets/actions/update.php delete mode 100644 mod/defaultwidgets/languages/en.php delete mode 100644 mod/defaultwidgets/manifest.xml delete mode 100644 mod/defaultwidgets/start.php delete mode 100644 mod/defaultwidgets/views/default/admin/appearance/default_dashboard_widgets.php delete mode 100644 mod/defaultwidgets/views/default/admin/appearance/default_profile_widgets.php delete mode 100644 mod/defaultwidgets/views/default/defaultwidgets/editor.php (limited to 'mod') diff --git a/mod/defaultwidgets/actions/update.php b/mod/defaultwidgets/actions/update.php deleted file mode 100644 index 9b34c228c..000000000 --- a/mod/defaultwidgets/actions/update.php +++ /dev/null @@ -1,55 +0,0 @@ - 'object', 'subtype' => 'moddefaultwidgets', 'limit' => 9999)); - - // create new object unless one already exists - if (! isset ( $entities [0] )) { - $entity = new ElggObject ( ); - $entity->subtype = 'moddefaultwidgets'; - $entity->owner_guid = $_SESSION ['user']->getGUID (); - } else { - $entity = $entities [0]; - } - - // store the default widgets for each context - $entity->$context = $widgets; - - // make sure this object is public. - $entity->access_id = 2; - - // save the object or report error - if ($entity->save ()) { - system_message ( elgg_echo ( 'defaultwidgets:update:success' ) ); - $entity->state = "active"; - forward ( 'pg/admin' ); - } else { - register_error ( elgg_echo ( 'defaultwidgets:update:failed' ) ); - forward("pg/admin/appearance/default_{$context}_widgets"); - } - -} else { - - // report incorrect parameters error - register_error ( elgg_echo ( 'defaultwidgets:update:noparams' ) ); - forward("pg/admin/appearance/default_{$context}_widgets"); - -} diff --git a/mod/defaultwidgets/languages/en.php b/mod/defaultwidgets/languages/en.php deleted file mode 100644 index d6da12ba5..000000000 --- a/mod/defaultwidgets/languages/en.php +++ /dev/null @@ -1,28 +0,0 @@ - 'DefaultWidgets settings', - - /** - * Menu items - */ - 'defaultwidgets:menu:profile' => 'Default profile widgets', - 'defaultwidgets:menu:dashboard' => 'Default dashboard widgets', - - 'defaultwidgets:admin:error' => 'Error: You are not logged in as an administrator', - 'defaultwidgets:admin:notfound' => 'Error: Page not found', - 'defaultwidgets:admin:loginfailure' => 'Warning: You are not currently logged is as an administrator', - - 'defaultwidgets:update:success' => 'Your widget settings have been saved', - 'defaultwidgets:update:failed' => 'Error: settings have not been saved', - 'defaultwidgets:update:noparams' => 'Error: incorrect form parameters', - - 'defaultwidgets:profile:title' => 'Set default widgets for new user profile pages', - 'defaultwidgets:dashboard:title' => 'Set default widgets for new user dashboard pages', -); - -add_translation ( "en", $english ); diff --git a/mod/defaultwidgets/manifest.xml b/mod/defaultwidgets/manifest.xml deleted file mode 100644 index 6aea32ab0..000000000 --- a/mod/defaultwidgets/manifest.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - Default Widgets - Milan Magudia & Core developers - 2.04 - This plugin enables an administrator to define a default set of widgets for new users - See COPYRIGHT.txt - GNU Public License version 2 - - elgg_version - 2010030101 - - true - advanced - diff --git a/mod/defaultwidgets/start.php b/mod/defaultwidgets/start.php deleted file mode 100644 index 89754f4f4..000000000 --- a/mod/defaultwidgets/start.php +++ /dev/null @@ -1,206 +0,0 @@ -guid; - - if (elgg_is_admin_logged_in()) { - // this is an admin-created user - // no permissions problems, so set proper access now - // use system default access (not the admin's default access!, because that could be a personal access level) - $widget_access = elgg_get_config('default_access'); - } else { - // this is a regular registration - // set widget access to public for now and reset it properly during the validate event - // to avoid Elgg permissions problems - $widget_access = ACCESS_PUBLIC; - } - - // check if it's set - if (! empty ( $guid )) { - - // get the user entity - if ($user = get_entity ( $guid )) { - - // can this user edit - if ($user->canEdit ()) { - - // each of the contexts to add widgets for - $contexts = array ('profile', 'dashboard' ); - - // get the entities for the module - $entities = elgg_get_entities (array('type' => 'object', 'subtype' => 'moddefaultwidgets', 'limit' => 9999)); - - // check if the entity exists - if (isset ( $entities [0] )) { - - // get the widgets for the context - $entity = $entities [0]; - - foreach ( $contexts as $context ) { - $current_widgets = $entity->$context; - list ( $left, $middle, $right ) = split ( '%%', $current_widgets ); - - // split columns into seperate widgets - $area1widgets = split ( '::', $left ); - $area2widgets = split ( '::', $middle ); - $area3widgets = split ( '::', $right ); - - // clear out variables if no widgets are available - if ($area1widgets [0] == "") - $area1widgets = false; - if ($area2widgets [0] == "") - $area2widgets = false; - if ($area3widgets [0] == "") - $area3widgets = false; - - // generate left column widgets for a new user - if ($area1widgets) { - foreach ( $area1widgets as $i => $widget ) { - add_widget ( $guid, $widget, $context, ($i + 1), 1, $widget_access ); - } - } - - // generate middle column widgets for a new user - if ($area2widgets) { - foreach ( $area2widgets as $i => $widget ) { - add_widget ( $guid, $widget, $context, ($i + 1), 2, $widget_access ); - } - } - - // generate right column widgets for a new user - if ($area3widgets) { - foreach ( $area3widgets as $i => $widget ) { - add_widget ( $guid, $widget, $context, ($i + 1), 3, $widget_access ); - } - } - } - } - } - } - } - - // turn off permissions override - $defaultwidget_access = false; -} - -function defaultwidgets_reset_access($event, $object_type, $object) { - - global $defaultwidget_access; - - // turn on permissions override - $defaultwidget_access = true; - - // the widgets are disabled, so turn on the ability to see disabled entities - - $access_status = access_get_show_hidden_status(); - access_show_hidden_entities(true); - - $widgets = elgg_get_entities(array('type' => 'object', 'subtype' => 'widget', 'owner_guid' => $object->getGUID())); - - if ($widgets) { - foreach($widgets as $widget) { - $widget->access_id = get_default_access(); - $widget->save(); - } - } - - access_show_hidden_entities($access_status); - - // turn off permissions override - $defaultwidget_access = false; - - return true; -} - -// Make sure the status initialisation function is called on initialisation -elgg_register_event_handler('init', 'system', 'defaultwidgets_init'); diff --git a/mod/defaultwidgets/views/default/admin/appearance/default_dashboard_widgets.php b/mod/defaultwidgets/views/default/admin/appearance/default_dashboard_widgets.php deleted file mode 100644 index e4a6ca51f..000000000 --- a/mod/defaultwidgets/views/default/admin/appearance/default_dashboard_widgets.php +++ /dev/null @@ -1,18 +0,0 @@ - generate_action_token($time), - 'ts' => $time, - 'context' => 'dashboard', -)); diff --git a/mod/defaultwidgets/views/default/admin/appearance/default_profile_widgets.php b/mod/defaultwidgets/views/default/admin/appearance/default_profile_widgets.php deleted file mode 100644 index b95a123eb..000000000 --- a/mod/defaultwidgets/views/default/admin/appearance/default_profile_widgets.php +++ /dev/null @@ -1,18 +0,0 @@ - generate_action_token($time), - 'ts' => $time, - 'context' => 'profile', -)); diff --git a/mod/defaultwidgets/views/default/defaultwidgets/editor.php b/mod/defaultwidgets/views/default/defaultwidgets/editor.php deleted file mode 100644 index b03023b35..000000000 --- a/mod/defaultwidgets/views/default/defaultwidgets/editor.php +++ /dev/null @@ -1,265 +0,0 @@ - 'object', 'subtype' => 'moddefaultwidgets', 'limit' => 9999)); - - // check if the entity exists - if(isset($entities[0])) { - - // get the widgets for the context - $entity = $entities[0]; - $current_widgets = $entity->$context; - list($left, $middle, $right) = split('%%',$current_widgets); - - // split columns into seperate widgets - $area1widgets = split('::',$left); - $area2widgets = split('::',$middle); - $area3widgets = split('::',$right); - - // clear out variables if no widgets are available - if ($area1widgets[0] == "") $area1widgets = false; - if ($area2widgets[0] == "") $area2widgets = false; - if ($area3widgets[0] == "") $area3widgets = false; - } - -?> - -
- -
-

- -
- - -
-

- elgg_echo('widgets:add:description'))); ?> -
- - -
- - - - - - - - - - - - - - - - - - - - - - -
- - -

-
-

-
- - -
-

-
> - 0) { - foreach($area3widgets as $widget) { - if (!empty($rightcolumn_widgets)) { - $rightcolumn_widgets .= "::"; - } - $rightcolumn_widgets .= "{$widget}::0"; - ?> - - - - - -
-

- name; ?> - - - - - - -

-
- - - -
-
-

-
- - 0) { - foreach($area1widgets as $widget) { - if (!empty($leftcolumn_widgets)) { - $leftcolumn_widgets .= "::"; - } - $leftcolumn_widgets .= "{$widget}::0"; -?> - - - - - -
-

- name; ?> - - - - - - -

-
- - -
-
- -

-
- - 0) { - foreach($area2widgets as $widget) { - if (!empty($middlecolumn_widgets)) { - $middlecolumn_widgets .= "::"; - } - $middlecolumn_widgets .= "{$widget}::0"; -?> - - - - - -
-

- name; ?> - - - - - - -

-
- - - -
-
- -
- -
- - - - '__elgg_token', 'value' => $vars['token'])); - echo elgg_view('input/hidden',array('name' => '__elgg_ts', 'value' => $vars['ts'])); -?> - - - elgg_echo('save'))); -?> - -
-
diff --git a/mod/groups/start.php b/mod/groups/start.php index 96eca34d4..b86dbd43f 100644 --- a/mod/groups/start.php +++ b/mod/groups/start.php @@ -79,11 +79,14 @@ function groups_init() { // Register a handler for delete groups elgg_register_event_handler('delete', 'group', 'groups_delete_event_listener'); - + elgg_register_event_handler('join', 'group', 'groups_user_join_event_listener'); elgg_register_event_handler('leave', 'group', 'groups_user_leave_event_listener'); elgg_register_event_handler('pagesetup', 'system', 'groups_submenus'); elgg_register_event_handler('annotate', 'all', 'group_object_notifications'); + + // allow admins to set default widgets for users on profiles + elgg_register_plugin_hook_handler('get_list', 'default_widgets', 'groups_default_widgets_hook'); } /** @@ -669,3 +672,27 @@ function groups_can_edit_discussion($entity, $group_owner) { return false; } } + + +/** + * Register profile widgets with default widgets + * + * @param unknown_type $hook + * @param unknown_type $type + * @param unknown_type $return + * @param unknown_type $params + * @return array + */ +function groups_default_widgets_hook($hook, $type, $return, $params) { + $return[] = array( + 'name' => elgg_echo('groups'), + 'widget_context' => 'groups', + 'widget_columns' => 3, + + 'event' => 'create', + 'entity_type' => 'group', + 'entity_subtype' => ELGG_ENTITIES_ANY_VALUE, + ); + + return $return; +} \ No newline at end of file diff --git a/mod/profile/start.php b/mod/profile/start.php index 67be35e7e..e17f955c5 100644 --- a/mod/profile/start.php +++ b/mod/profile/start.php @@ -31,9 +31,12 @@ function profile_init() { elgg_extend_view('html_head/extend', 'profile/metatags'); elgg_extend_view('css/screen', 'profile/css'); - + // allow ECML in parts of the profile elgg_register_plugin_hook_handler('get_views', 'ecml', 'profile_ecml_views_hook'); + + // allow admins to set default widgets for users on profiles + elgg_register_plugin_hook_handler('get_list', 'default_widgets', 'profile_default_widgets_hook'); } /** @@ -101,3 +104,26 @@ function profile_ecml_views_hook($hook, $entity_type, $return_value, $params) { return $return_value; } + +/** + * Register profile widgets with default widgets + * + * @param unknown_type $hook + * @param unknown_type $type + * @param unknown_type $return + * @param unknown_type $params + * @return array + */ +function profile_default_widgets_hook($hook, $type, $return, $params) { + $return[] = array( + 'name' => elgg_echo('profile'), + 'widget_context' => 'profile', + 'widget_columns' => 3, + + 'event' => 'create', + 'entity_type' => 'user', + 'entity_subtype' => ELGG_ENTITIES_ANY_VALUE, + ); + + return $return; +} \ No newline at end of file -- cgit v1.2.3