aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--actions/widgets/add.php14
-rw-r--r--actions/widgets/delete.php9
-rw-r--r--actions/widgets/move.php10
-rw-r--r--actions/widgets/save.php7
-rw-r--r--engine/lib/views.php28
-rw-r--r--engine/lib/widgets.php100
-rw-r--r--js/lib/ui.widgets.js18
-rw-r--r--languages/en.php5
-rw-r--r--mod/defaultwidgets/actions/update.php55
-rw-r--r--mod/defaultwidgets/languages/en.php28
-rw-r--r--mod/defaultwidgets/manifest.xml15
-rw-r--r--mod/defaultwidgets/start.php206
-rw-r--r--mod/defaultwidgets/views/default/admin/appearance/default_dashboard_widgets.php18
-rw-r--r--mod/defaultwidgets/views/default/admin/appearance/default_profile_widgets.php18
-rw-r--r--mod/defaultwidgets/views/default/defaultwidgets/editor.php265
-rw-r--r--mod/groups/start.php29
-rw-r--r--mod/profile/start.php28
-rw-r--r--views/default/object/plugin.php2
-rw-r--r--views/default/page/components/widget.php15
-rw-r--r--views/default/page/layouts/widgets.php3
20 files changed, 215 insertions, 658 deletions
diff --git a/actions/widgets/add.php b/actions/widgets/add.php
index 38686b36d..ac8983115 100644
--- a/actions/widgets/add.php
+++ b/actions/widgets/add.php
@@ -6,18 +6,22 @@
* @subpackage Widgets.Management
*/
-$user_guid = get_input('user_guid');
+$owner_guid = get_input('owner_guid');
$handler = get_input('handler');
$context = get_input('context');
$column = get_input('column', 1);
+$default_widgets = get_input('default_widgets', 0);
elgg_push_context($context);
+if ($default_widgets) {
+ elgg_push_context('default_widgets');
+}
elgg_push_context('widgets');
-if (!empty($user_guid)) {
- $user = get_entity($user_guid);
- if ($user && $user->canEdit()) {
- $guid = elgg_create_widget($user->getGUID(), $handler, $context);
+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);
diff --git a/actions/widgets/delete.php b/actions/widgets/delete.php
index 5b8aaf75e..47920013d 100644
--- a/actions/widgets/delete.php
+++ b/actions/widgets/delete.php
@@ -6,12 +6,13 @@
* @subpackage Widgets.Management
*/
-$guid = get_input('guid');
+$widget_guid = get_input('widget_guid');
+$owner_guid = get_input('owner_guid', elgg_get_logged_in_user_guid());
-$user = elgg_get_logged_in_user_entity();
+$widget = get_entity($widget_guid);
+$owner = get_entity($owner_guid);
-$widget = get_entity($guid);
-if ($widget && $user->canEdit() && $widget->delete()) {
+if ($widget && $owner->canEdit() && $widget->delete()) {
forward(REFERER);
}
diff --git a/actions/widgets/move.php b/actions/widgets/move.php
index 2edc7912e..eab650c9c 100644
--- a/actions/widgets/move.php
+++ b/actions/widgets/move.php
@@ -6,14 +6,16 @@
* @subpackage Widgets.Management
*/
-$guid = get_input('guid');
+$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());
-$user = elgg_get_logged_in_user_entity();
+$widget = get_entity($widget_guid);
+$owner = get_entity($owner_guid);
-$widget = get_entity($guid);
-if ($widget && $user->canEdit()) {
+
+if ($widget && $owner->canEdit()) {
$widget->move($column, $position);
forward(REFERER);
}
diff --git a/actions/widgets/save.php b/actions/widgets/save.php
index b1649cc17..0a2de0c4d 100644
--- a/actions/widgets/save.php
+++ b/actions/widgets/save.php
@@ -10,12 +10,15 @@ elgg_set_context('widgets');
$guid = get_input('guid');
$params = get_input('params');
+$default_widgets = get_input('default_widgets', 0);
$widget = get_entity($guid);
if ($widget && $widget->saveSettings($params)) {
elgg_set_page_owner_guid($widget->getContainerGUID());
- $view = "widgets/$widget->handler/content";
- echo elgg_view($view, array('entity' => $widget));
+ if (!$default_widgets) {
+ $view = "widgets/$widget->handler/content";
+ echo elgg_view($view, array('entity' => $widget));
+ }
} else {
register_error(elgg_echo('widgets:save:failure'));
}
diff --git a/engine/lib/views.php b/engine/lib/views.php
index 918ca6446..c26e96dd5 100644
--- a/engine/lib/views.php
+++ b/engine/lib/views.php
@@ -393,7 +393,7 @@ function elgg_view($view, $vars = array(), $bypass = false, $debug = false, $vie
if (!isset($vars['url'])) {
$vars['url'] = elgg_get_site_url();
}
-
+
// internalname => name (1.8)
if (isset($vars['internalname'])) {
elgg_deprecated_notice('You should pass $vars[\'name\'] now instead of $vars[\'internalname\']', 1.8);
@@ -401,7 +401,7 @@ function elgg_view($view, $vars = array(), $bypass = false, $debug = false, $vie
} elseif (isset($vars['name'])) {
$vars['internalname'] = $vars['name'];
}
-
+
// internalid => id (1.8)
if (isset($vars['internalid'])) {
elgg_deprecated_notice('You should pass $vars[\'id\'] now instead of $vars[\'internalid\']', 1.8);
@@ -637,8 +637,8 @@ function elgg_view_page($title, $body, $page_shell = 'default', $vars = array())
* filter_context => string (selected content filter)
* See the content layout view for more parameters
*
- * @param string $layout The name of the view in page/layouts/.
- * @param array $vars Associative array of parameters for the layout view
+ * @param string $layout_name The name of the view in page/layouts/.
+ * @param array $vars Associative array of parameters for the layout view
*
* @return string The layout
*/
@@ -667,11 +667,11 @@ function elgg_view_layout($layout_name, $vars = array()) {
* Render a menu
*
* @param string $menu_name The name of the menu
- * @param array $vars An associative array of display options for the menu.
- * Options include:
- * sort_by => string or php callback
- * string options: 'name', 'title' (default), 'order' (registration order)
- * php callback: a compare function for usort
+ * @param array $vars An associative array of display options for the menu.
+ * Options include:
+ * sort_by => string or php callback
+ * string options: 'name', 'title' (default), 'order' (registration order)
+ * php callback: a compare function for usort
*
* @return string
* @since 1.8.0
@@ -797,7 +797,7 @@ function elgg_view_entity(ElggEntity $entity, $full = false, $bypass = true, $de
* the icon/$type/default view.
*
* @param ElggEntity $entity The entity to display
- * @param string $string The size: tiny, small, medium, large
+ * @param string $size The size: tiny, small, medium, large
* @param array $vars An array of variables to pass to the view
*
* @return string HTML to display or false
@@ -1148,9 +1148,9 @@ function elgg_view_likes($entity) {
*
* This is a shortcut for {@elgg_view page/components/image_block}.
*
- * @param string $image The icon and other information
- * @param string $body Description content
- * @param string $vars Additional parameters for the view
+ * @param string $image The icon and other information
+ * @param string $body Description content
+ * @param string $vars Additional parameters for the view
*
* @return string
* @since 1.8.0
@@ -1452,6 +1452,8 @@ function autoregister_views($view_base, $folder, $base_location_path, $viewtype)
/**
* Add the core Elgg head elements that could be cached
+ *
+ * @return void
*/
function elgg_views_register_core_head_elements() {
$url = elgg_get_simplecache_url('js', 'elgg');
diff --git a/engine/lib/widgets.php b/engine/lib/widgets.php
index 8310e83cc..6cca2a18d 100644
--- a/engine/lib/widgets.php
+++ b/engine/lib/widgets.php
@@ -16,7 +16,7 @@
*
* @param int $user_guid The owner user GUID
* @param string $context The context (profile, dashboard, etc)
- *
+ *
* @return array An 2D array of ElggWidget objects
* @since 1.8.0
*/
@@ -26,7 +26,8 @@ function elgg_get_widgets($user_guid, $context) {
'subtype' => 'widget',
'owner_guid' => $user_guid,
'private_setting_name' => 'context',
- 'private_setting_value' => $context
+ 'private_setting_value' => $context,
+ 'limit' => 0
);
$widgets = elgg_get_entities_from_private_settings($options);
if (!$widgets) {
@@ -54,7 +55,7 @@ function elgg_get_widgets($user_guid, $context) {
* @param int $entity_guid GUID of entity that owns this widget
* @param string $handler The handler for this widget
* @param int $access_id If not specified, it is set to the default access level
- *
+ *
* @return int|false Widget GUID or false on failure
* @since 1.8.0
*/
@@ -134,7 +135,7 @@ function elgg_can_edit_widget_layout($context, $user_guid = 0) {
* widget is allowed (default: 'all')
* @param bool $multiple Whether or not multiple instances of this widget
* are allowed in a single layout (default: false)
- *
+ *
* @return bool
* @since 1.8.0
*/
@@ -168,7 +169,7 @@ function elgg_register_widget_type($handler, $name, $description, $context = "al
* Remove a widget type
*
* @param string $handler The identifier for the widget
- *
+ *
* @return void
* @since 1.8.0
*/
@@ -192,7 +193,7 @@ function elgg_unregister_widget_type($handler) {
* Has a widget type with the specified handler been registered
*
* @param string $handler The widget handler identifying string
- *
+ *
* @return bool Whether or not that widget type exists
* @since 1.8.0
*/
@@ -217,7 +218,7 @@ function elgg_is_widget_type($handler) {
*
* @param string $context The widget context or empty string for current context
* @param bool $exact Only return widgets registered for this context (false)
- *
+ *
* @return array
* @since 1.8.0
*/
@@ -274,4 +275,87 @@ function elgg_widgets_init() {
run_function_once("elgg_widget_run_once");
}
-elgg_register_event_handler('init', 'system', 'elgg_widgets_init'); \ No newline at end of file
+/**
+ * Gets a list of events to create default widgets for and
+ * register menu items for default widgets with the admin section.
+ *
+ * @return void
+ */
+function elgg_default_widgets_init() {
+ global $CONFIG;
+ $default_widgets = elgg_trigger_plugin_hook('get_list', 'default_widgets', null, array());
+
+ $CONFIG->default_widget_info = $default_widgets;
+
+ if ($default_widgets) {
+ elgg_add_admin_menu_item('default_widgets', elgg_echo('admin:appearance:default_widgets'), 'appearance', 30);
+
+ foreach ($default_widgets as $info) {
+ elgg_register_event_handler($info['event'], $info['entity_type'], 'elgg_default_widgets_hook');
+ }
+ }
+}
+
+/**
+ * Checks for plugins who have registered default widgets and
+ * hooks into events to save.
+ *
+ * @param string $event The event
+ * @param string $type The type of object
+ * @param object $object The object
+ * @return null
+ */
+function elgg_default_widgets_hook($event, $type, $object) {
+ $default_widget_info = elgg_get_config('default_widget_info');
+
+ if (!$default_widget_info) {
+ return null;
+ }
+
+ $subtype = $object->getSubtype();
+
+ // event is already guaranteed by the hook registration.
+ // need to check subtype and type.
+ foreach ($default_widget_info as $temp) {
+ if ($temp['entity_type'] == $type && $temp['entity_subtype'] == $subtype) {
+ $info = $temp;
+ break;
+ }
+ }
+
+ // pull in by widget context with widget owners as the site
+ // not using elgg_get_widgets() because it sorts by columns and we don't care right now.
+ $options = array(
+ 'type' => 'object',
+ 'subtype' => 'widget',
+ 'owner_guid' => elgg_get_site_entity()->guid,
+ 'private_setting_name' => 'context',
+ 'private_setting_value' => $info['context'],
+ 'limit' => 0
+ );
+
+ $widgets = elgg_get_entities_from_private_settings($options);
+
+ foreach ($widgets as $widget) {
+ // change the container and owner
+ $new_widget = clone $widget;
+ $new_widget->container_guid = $object->guid;
+ $new_widget->owner_guid = $object->guid;
+
+ // pull in settings
+ $settings = get_all_private_settings($widget->guid);
+
+ foreach ($settings as $name => $value) {
+ $new_widget->$name = $value;
+ }
+
+ $new_widget->save();
+ }
+
+ // failure here shouldn't stop the event.
+ return null;
+}
+
+elgg_register_event_handler('init', 'system', 'elgg_widgets_init');
+// register default widget hooks from plugins
+elgg_register_event_handler('ready', 'system', 'elgg_default_widgets_init'); \ No newline at end of file
diff --git a/js/lib/ui.widgets.js b/js/lib/ui.widgets.js
index b6e81617a..1acc22928 100644
--- a/js/lib/ui.widgets.js
+++ b/js/lib/ui.widgets.js
@@ -56,8 +56,9 @@ elgg.ui.widgets.add = function(event) {
elgg.action('widgets/add', {
data: {
handler: type,
- user_guid: elgg.get_logged_in_user_guid(),
- context: $("input[name='widget_context']").val()
+ owner_guid: elgg.get_page_owner_guid(),
+ context: $("input[name='widget_context']").val(),
+ default_widgets: $("input[name='default_widgets']").val() || 0
},
success: function(json) {
$('#elgg-widget-col-1').prepend(json.output);
@@ -86,7 +87,7 @@ elgg.ui.widgets.move = function(event, ui) {
elgg.action('widgets/move', {
data: {
- guid: guidString,
+ widget_guid: guidString,
column: col,
position: ui.item.index()
}
@@ -129,7 +130,7 @@ elgg.ui.widgets.remove = function(event) {
elgg.action('widgets/delete', {
data: {
- guid: id
+ widget_guid: id
}
});
event.preventDefault();
@@ -158,13 +159,18 @@ elgg.ui.widgets.collapseToggle = function(event) {
elgg.ui.widgets.saveSettings = function(event) {
$(this).parent().slideToggle('medium');
var $widgetContent = $(this).parent().parent().children('.elgg-widget-content');
-
- // stick the ajaxk loader in there
+
+ // stick the ajax loader in there
var $loader = $('#elgg-widget-loader').clone();
$loader.attr('id', '#elgg-widget-active-loader');
$loader.removeClass('hidden');
$widgetContent.html($loader);
+ var default_widgets = $("input[name='default_widgets']").val() || 0;
+ if (default_widgets) {
+ $(this).append('<input type="hidden" name="default_widgets" value="1">');
+ }
+
elgg.action('widgets/save', {
data: $(this).serialize(),
success: function(json) {
diff --git a/languages/en.php b/languages/en.php
index e1eed9996..6232c97d9 100644
--- a/languages/en.php
+++ b/languages/en.php
@@ -265,7 +265,7 @@ $english = array(
'dashboard:nowidgets' => "Your dashboard lets you track the activity and content on this site that matters to you.",
'widgets:add' => 'Add widgets',
- 'widgets:add:description' => "Click on any widget button below to add it to your page.",
+ 'widgets:add:description' => "Click on any widget button below to add it to the page.",
'widgets:position:fixed' => '(Fixed position on page)',
'widget:unavailable' => 'You have already added this widget',
'widget:numbertodisplay' => 'Number of items to display',
@@ -650,6 +650,9 @@ $english = array(
'admin:add_menu_item' => 'Add a custom menu item',
'admin:add_menu_item:description' => 'Fill out the Display name and URL to add custom items to your navigation menu.',
+ 'admin:appearance:default_widgets' => 'Default Widgets',
+ 'admin:appearance:default_widgets:unknown_type' => 'Unknown widget type',
+
/**
* User settings
*/
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 @@
-<?php
-/**
- * Elgg default_widgets plugin.
- *
- * @package DefaultWidgets
- *
- **/
-
-// get parameters
-$context = get_input ( 'context' );
-$leftbar = str_replace ( '::0', '', get_input ( 'debugField1' ) );
-$middlebar = str_replace ( '::0', '', get_input ( 'debugField2' ) );
-$rightbar = str_replace ( '::0', '', get_input ( 'debugField3' ) );
-
-// make sure enough parameters are set
-if ($context && isset ( $leftbar ) && isset ( $middlebar ) && isset ( $rightbar )) {
-
- // join widgets into a single string
- $widgets = $leftbar . '%%' . $middlebar . '%%' . $rightbar;
-
- // get the elgg object that contains our settings
- $entities = elgg_get_entities (array('type' => '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 @@
-<?php
-
-$english = array (
-
- /**
- * Nice name for the entity (shown in admin panel)
- */
- 'item:object:moddefaultwidgets' => '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 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<plugin_manifest xmlns="http://www.elgg.org/plugin_manifest/1.8">
- <name>Default Widgets</name>
- <author>Milan Magudia &amp; Core developers</author>
- <version>2.04</version>
- <description>This plugin enables an administrator to define a default set of widgets for new users</description>
- <copyright>See COPYRIGHT.txt</copyright>
- <license>GNU Public License version 2</license>
- <requires>
- <type>elgg_version</type>
- <version>2010030101</version>
- </requires>
- <activate_on_install>true</activate_on_install>
- <admin_interface>advanced</admin_interface>
-</plugin_manifest>
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 @@
-<?php
-/**
- * Elgg default_widgets plugin.
- *
- * @package DefaultWidgets
- *
- * Code based on the work of:
- * @link http://www.tastyseed.com
- * @link http://www.chadsowald.com
- * @links http://www.somosmas.org
- *
- */
-
-/**
- * Default widgets initialisation
- *
- * These parameters are required for the event API, but we won't use them:
- *
- * @param unknown_type $event
- * @param unknown_type $object_type
- * @param unknown_type $object
- */
-function defaultwidgets_init() {
- // register create user event hook
- elgg_register_event_handler('create', 'user', 'defaultwidgets_newusers' );
-
- // set the widget access to the default access on validation if this is not an admin-created user
- if (!elgg_is_admin_logged_in()) {
- elgg_register_event_handler('validate', 'user', 'defaultwidgets_reset_access');
- }
-
- $action_dir = elgg_get_plugins_path() . 'defaultwidgets/actions';
- elgg_register_action("defaultwidgets/update", "$action_dir/update.php", 'admin');
-
- elgg_register_plugin_hook_handler('permissions_check', 'user', 'defaultwidgets_can_edit');
- elgg_register_plugin_hook_handler('permissions_check', 'object', 'defaultwidgets_can_edit');
- elgg_register_plugin_hook_handler('container_permissions_check', 'user', 'defaultwidgets_can_edit_container');
-
- // @todo These submenu pages should be DRYed up
- //elgg_add_admin_menu_item('default_profile_widgets', elgg_echo('defaultwidgets:menu:profile'), 'appearance');
- //elgg_add_admin_menu_item('default_dashboard_widgets', elgg_echo('defaultwidgets:menu:dashboard'), 'appearance');
-}
-
-/**
- * Overrides default permissions for the default widgets context
- *
- */
-function defaultwidgets_can_edit($hook_name, $entity_type, $return_value, $parameters) {
- global $defaultwidget_access;
-
- if ($defaultwidget_access) {
- return true;
- }
- return $return_value;
-}
-
-/**
- * Override the canEditMetadata function to return true for messages
- *
- */
-function defaultwidgets_can_edit_metadata($hook_name, $entity_type, $return_value, $parameters) {
- global $defaultwidget_access;
-
- if ($defaultwidget_access) {
- return true;
- }
- return $return_value;
-
-}
-
-/**
- * Override the canEdit function to return true for messages within a particular context.
- *
- */
-function defaultwidgets_can_edit_container($hook_name, $entity_type, $return_value, $parameters) {
- global $defaultwidget_access;
-
- if ($defaultwidget_access) {
- return true;
- }
- return $return_value;
-}
-
-/**
- * Extends the create user event to add admin defined widgets to the dashboard/profile context
- */
-function defaultwidgets_newusers($event, $object_type, $object) {
-
- // turn on permissions override
- global $defaultwidget_access, $CONFIG;
- $defaultwidget_access = true;
-
- // get the new user guid
- $guid = $object->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 @@
-<?php
-/**
- * Elgg default_widgets plugin.
- *
- * @package DefaultWidgets
- *
- **/
-
-// Set admin user for user block
-set_page_owner(elgg_get_logged_in_user_guid());
-
-// create the view
-$time = time();
-echo elgg_view('defaultwidgets/editor', array(
- 'token' => 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 @@
-<?php
-/**
- * Elgg default_widgets plugin.
- *
- * @package DefaultWidgets
- *
- **/
-
-// set admin user for user block
-set_page_owner(elgg_get_logged_in_user_guid());
-
-// create the view
-$time = time();
-echo elgg_view('defaultwidgets/editor', array (
- 'token' => 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 @@
-<?php
-
- /**
- * Elgg default widget layout
- *
- * @package Elgg
- * @subpackage Core
- *
- * Edited version of the widget editor to be used to set default widgets
- *
- **/
-
- // set some defaults
- $owner = elgg_get_page_owner_entity();
- $context = $vars['context'];
- $area1widgets = false;
- $area2widgets = false;
- $area3widgets = false;
-
- // get available widget types
- elgg_set_context($context);
- $widgettypes = get_widget_types();
- elgg_set_context('admin');
-
- // 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];
- $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;
- }
-
-?>
-
-<div id="customise_editpanel" style="visibility:visible;">
-
-<div id="customise_editpanel_rhs">
-<h2><?php echo elgg_echo("widgets:gallery"); ?></h2>
-<div id="widget_picker_gallery">
-
-
-<?php
-
- foreach($widgettypes as $handler => $widget) {
-
-?>
-
-<table class="draggable_widget" cellspacing="0"><tr><td>
- <h3>
- <?php echo $widget->name; ?>
- <input type="hidden" name="multiple" value="<?php if ((isset($widget->handler)) && (isset($widgettypes[$widget->handler]->multiple))) echo $widgettypes[$widget->handler]->multiple; ?>" />
- <input type="hidden" name="side" value="<?php if ((isset($widget->handler)) && (isset($widgettypes[$widget->handler])) && (is_array($widgettypes[$widget->handler]->positions))) echo in_array('side',$widgettypes[$widget->handler]->positions); ?>" />
- <input type="hidden" name="main" value="<?php if ((isset($widget->handler)) && (isset($widgettypes[$widget->handler])) && (is_array($widgettypes[$widget->handler]->positions))) echo in_array('main',$widgettypes[$widget->handler]->positions); ?>" />
- <input type="hidden" name="handler" value="<?php echo htmlentities($handler); ?>" />
- <input type="hidden" name="description" value="<?php echo htmlentities($widget->description, null, 'UTF-8'); ?>" />
- <input type="hidden" name="guid" value="0" />
- </h3>
-</td>
-<td width="17px" align="right"></td>
-<td width="17px" align="right"><a href="#"><img src="<?php echo elgg_get_site_url(); ?>_graphics/spacer.gif" width="14" height="14" class="more_info" /></a></td>
-<td width="17px" align="right"><a href="#"><img src="<?php echo elgg_get_site_url(); ?>_graphics/spacer.gif" width="15" height="15" class="drag-handle" /></a></td>
-</tr></table>
-
-<?php
- }
-?>
-
-<br /><!-- bit of space at the bottom of the widget gallery -->
-
-</div><!-- /#customise_editpanel_rhs -->
-</div><!-- /#widget_picker_gallery -->
-
-
-<div class="customise_editpanel_instructions">
-<h2><?php echo elgg_echo('defaultwidgets:'.$context.':title'); ?></h2>
-<?php echo elgg_view('output/longtext', array('value' => elgg_echo('widgets:add:description'))); ?>
-</div>
-
-
-<div id="customise_page_view">
-
-<table cellspacing="0">
-<tr>
- <td colspan="2" align="left" valign="top">
-
- <?php
- if (elgg_get_context() == "profile"){
- ?>
- <h2 class="profile_box"><?php echo elgg_echo("widgets:profilebox"); ?></h2>
- <div id="profile_box_widgets">
- <p><small><?php echo elgg_echo('widgets:position:fixed'); ?></small></p>
- </div>
- <?php
- }
- ?>
-
- </td>
-
-
- <td rowspan="2" align="left" valign="top">
- <h2><?php echo elgg_echo("widgets:rightcolumn"); ?></h2>
- <div id="rightcolumn_widgets" <?php if (elgg_get_context() == "profile") echo "class=\"long\""; ?>>
- <?php
- $rightcolumn_widgets = "";
- if (is_array($area3widgets) && sizeof($area3widgets) > 0) {
- foreach($area3widgets as $widget) {
- if (!empty($rightcolumn_widgets)) {
- $rightcolumn_widgets .= "::";
- }
- $rightcolumn_widgets .= "{$widget}::0";
- ?>
-
- <table class="draggable_widget" cellspacing="0"><tr><td width="149px">
- <h3>
- <?php echo $widgettypes[$widget]->name; ?>
- <input type="hidden" name="handler" value="<?php
- echo $widget;
- ?>" />
- <input type="hidden" name="multiple" value="<?php echo $widgettypes[$widget]->multiple; ?>" />
- <input type="hidden" name="side" value="<?php echo in_array('side',$widgettypes[$widget]->positions); ?>" />
- <input type="hidden" name="main" value="<?php echo in_array('main',$widgettypes[$widget]->positions); ?>" />
- <input type="hidden" name="description" value="<?php echo htmlentities($widgettypes[$widget]->description); ?>" />
- <input type="hidden" name="guid" value="0" />
- </h3>
- </td>
- <td width="17px" align="right"></td>
- <td width="17px" align="right"><a href="#"><img src="<?php echo elgg_get_site_url(); ?>_graphics/spacer.gif" width="14" height="14" class="more_info" /></a></td>
- <td width="17px" align="right"><a href="#"><img src="<?php echo elgg_get_site_url(); ?>_graphics/spacer.gif" width="15" height="15" class="drag-handle" /></a></td>
- </tr></table>
-
- <?php
-
- }
- }
- ?>
-
- </div>
- </td><!-- /rightcolumn td -->
-
-</tr>
-
-<tr>
-
-<td>
-<h2><?php echo elgg_echo("widgets:leftcolumn"); ?></h2>
-<div id="leftcolumn_widgets">
-
-<?php
- $leftcolumn_widgets = "";
- if (is_array($area1widgets) && sizeof($area1widgets) > 0) {
- foreach($area1widgets as $widget) {
- if (!empty($leftcolumn_widgets)) {
- $leftcolumn_widgets .= "::";
- }
- $leftcolumn_widgets .= "{$widget}::0";
-?>
-
-<table class="draggable_widget" cellspacing="0"><tr><td width="149px">
- <h3>
- <?php echo $widgettypes[$widget]->name; ?>
- <input type="hidden" name="handler" value="<?php
- echo $widget;
- ?>" />
- <input type="hidden" name="multiple" value="<?php echo $widgettypes[$widget]->multiple; ?>" />
- <input type="hidden" name="side" value="<?php echo in_array('side',$widgettypes[$widget]->positions); ?>" />
- <input type="hidden" name="main" value="<?php echo in_array('main',$widgettypes[$widget]->positions); ?>" />
- <input type="hidden" name="description" value="<?php echo htmlentities($widgettypes[$widget]->description); ?>" />
- <input type="hidden" name="guid" value="0" />
- </h3>
-</td>
-<td width="17px" align="right"></td>
-<td width="17px" align="right"><a href="#"><img src="<?php echo elgg_get_site_url(); ?>_graphics/spacer.gif" width="14" height="14" class="more_info" /></a></td>
-<td width="17px" align="right"><a href="#"><img src="<?php echo elgg_get_site_url(); ?>_graphics/spacer.gif" width="15" height="15" class="drag-handle" /></a></td>
-</tr></table>
-
-<?php
-
- }
- }
-?>
-</div>
-</td>
-
-<td>
-
-<h2><?php echo elgg_echo("widgets:middlecolumn"); ?></h2>
-<div id="middlecolumn_widgets">
-
-<?php
- $middlecolumn_widgets = "";
- if (is_array($area2widgets) && sizeof($area2widgets) > 0) {
- foreach($area2widgets as $widget) {
- if (!empty($middlecolumn_widgets)) {
- $middlecolumn_widgets .= "::";
- }
- $middlecolumn_widgets .= "{$widget}::0";
-?>
-
-<table class="draggable_widget" cellspacing="0"><tr><td width="149px">
- <h3>
- <?php echo $widgettypes[$widget]->name; ?>
- <input type="hidden" name="handler" value="<?php
- echo $widget;
- ?>" />
- <input type="hidden" name="multiple" value="<?php echo $widgettypes[$widget]->multiple; ?>" />
- <input type="hidden" name="side" value="<?php echo in_array('side',$widgettypes[$widget]->positions); ?>" />
- <input type="hidden" name="main" value="<?php echo in_array('main',$widgettypes[$widget]->positions); ?>" />
- <input type="hidden" name="description" value="<?php echo htmlentities($widgettypes[$widget]->description); ?>" />
- <input type="hidden" name="guid" value="0" />
- </h3>
-</td>
-<td width="17px" align="right"></td>
-<td width="17px" align="right"><a href="#"><img src="<?php echo elgg_get_site_url(); ?>_graphics/spacer.gif" width="14" height="14" class="more_info" /></a></td>
-<td width="17px" align="right"><a href="#"><img src="<?php echo elgg_get_site_url(); ?>_graphics/spacer.gif" width="15" height="15" class="drag-handle" /></a></td>
-</tr></table>
-
-<?php
-
- }
- }
-?>
-
-</div>
-</td>
-
-
-
-
-
-
-</tr>
-</table>
-
-</div><!-- /#customise_page_view -->
-
-<form action="<?php echo elgg_get_site_url(); ?>action/defaultwidgets/update" method="post">
-<textarea type="textarea" value="Left widgets" style="display:none" name="debugField1" id="debugField1" /><?php echo $leftcolumn_widgets; ?></textarea>
-<textarea type="textarea" value="Middle widgets" style="display:none" name="debugField2" id="debugField2" /><?php echo $middlecolumn_widgets; ?></textarea>
-<textarea type="textarea" value="Right widgets" style="display:none" name="debugField3" id="debugField3" /><?php echo $rightcolumn_widgets; ?></textarea>
-<?php
- echo elgg_view('input/hidden',array('name' => '__elgg_token', 'value' => $vars['token']));
- echo elgg_view('input/hidden',array('name' => '__elgg_ts', 'value' => $vars['ts']));
-?>
-<input type="hidden" name="context" value="<?php echo $context; ?>" />
-<input type="hidden" name="owner" value="<?php echo elgg_get_page_owner_guid(); ?>" />
-<?php
- echo elgg_view('input/submit', array('value' => elgg_echo('save')));
-?>
-
-</form>
-</div><!-- /customise_editpanel -->
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
diff --git a/views/default/object/plugin.php b/views/default/object/plugin.php
index befd61018..e9cacca35 100644
--- a/views/default/object/plugin.php
+++ b/views/default/object/plugin.php
@@ -4,7 +4,7 @@
*
* @package Elgg.Core
* @subpackage Plugins
- *
+ *
* @todo This view really should be used to display visualization on the admin panel, \
* rather than emitting the settings forms
*/
diff --git a/views/default/page/components/widget.php b/views/default/page/components/widget.php
index d5e2c4ca2..e7a16b318 100644
--- a/views/default/page/components/widget.php
+++ b/views/default/page/components/widget.php
@@ -33,15 +33,18 @@ $controls = elgg_view('layout/objects/widget/controls', array(
'show_edit' => $edit_area != '',
));
-
-if (elgg_view_exists("widgets/$handler/content")) {
- $content = elgg_view("widgets/$handler/content", $vars);
+// don't show content for default widgets
+if (elgg_in_context('default_widgets')) {
+ $content = '';
} else {
- elgg_deprecated_notice("widgets use content as the display view", 1.8);
- $content = elgg_view("widgets/$handler/view", $vars);
+ if (elgg_view_exists("widgets/$handler/content")) {
+ $content = elgg_view("widgets/$handler/content", $vars);
+ } else {
+ elgg_deprecated_notice("widgets use content as the display view", 1.8);
+ $content = elgg_view("widgets/$handler/view", $vars);
+ }
}
-
$widget_id = "elgg-widget-$widget->guid";
$widget_instance = "elgg-widget-instance-$handler";
$widget_class = "elgg-module elgg-module-widget";
diff --git a/views/default/page/layouts/widgets.php b/views/default/page/layouts/widgets.php
index 4c98a156c..eac9d43fc 100644
--- a/views/default/page/layouts/widgets.php
+++ b/views/default/page/layouts/widgets.php
@@ -2,7 +2,7 @@
/**
* Elgg widgets layout
*
- * @uses $vars['content'] Optional display box at the top of layout
+ * @uses $vars['content'] Optional display box at the top of layout
* @uses $vars['num_columns'] Number of widget columns for this layout (3)
* @uses $vars['show_add_widgets'] Display the add widgets button and panel (true)
* @uses $vars['exact_match'] Widgets must match the current context (false)
@@ -15,6 +15,7 @@ $exact_match = elgg_extract('exact_match', $vars, false);
$show_access = elgg_extract('show_access', $vars, true);
$owner = elgg_get_page_owner_entity();
+
$context = elgg_get_context();
elgg_push_context('widgets');