diff options
Diffstat (limited to 'actions/widgets')
| -rw-r--r-- | actions/widgets/add.php | 46 | ||||
| -rw-r--r-- | actions/widgets/delete.php | 20 | ||||
| -rw-r--r-- | actions/widgets/move.php | 24 | ||||
| -rw-r--r-- | actions/widgets/reorder.php | 8 | ||||
| -rw-r--r-- | actions/widgets/save.php | 52 | ||||
| -rw-r--r-- | actions/widgets/upgrade.php | 65 |
6 files changed, 173 insertions, 42 deletions
diff --git a/actions/widgets/add.php b/actions/widgets/add.php index 66d133195..d7b2f291c 100644 --- a/actions/widgets/add.php +++ b/actions/widgets/add.php @@ -2,31 +2,41 @@ /** * Elgg widget add action * - * @package Elgg - * @subpackage Core - * @author Curverider Ltd - * @link http://elgg.org/ + * @package Elgg.Core + * @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($_SERVER['HTTP_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/reorder.php b/actions/widgets/reorder.php index 9398630ca..e43a0ba73 100644 --- a/actions/widgets/reorder.php +++ b/actions/widgets/reorder.php @@ -2,10 +2,8 @@ /** * Elgg widget reorder action * - * @package Elgg - * @subpackage Core - * @author Curverider Ltd - * @link http://elgg.org/ + * @package Elgg.Core + * @subpackage Widgets.Management */ $owner = get_input('owner'); @@ -23,4 +21,4 @@ if ($result) { register_error(elgg_echo('widgets:panel:save:failure')); } -forward($_SERVER['HTTP_REFERER']);
\ No newline at end of file +forward(REFERER);
\ No newline at end of file diff --git a/actions/widgets/save.php b/actions/widgets/save.php index 7e9c91dcd..e15deab77 100644 --- a/actions/widgets/save.php +++ b/actions/widgets/save.php @@ -1,30 +1,44 @@ <?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. * - * @package Elgg - * @subpackage Core - * @author Curverider Ltd - * @link http://elgg.org/ */ -$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); -} +$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')); } -if (!$noforward) { - forward($_SERVER['HTTP_REFERER']); -} +forward(REFERER);
\ No newline at end of file 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); |
