diff options
Diffstat (limited to 'actions/widgets')
| -rw-r--r-- | actions/widgets/add.php | 85 | ||||
| -rw-r--r-- | actions/widgets/delete.php | 20 | ||||
| -rw-r--r-- | actions/widgets/move.php | 24 | ||||
| -rw-r--r-- | actions/widgets/reorder.php | 56 | ||||
| -rw-r--r-- | actions/widgets/save.php | 82 | ||||
| -rw-r--r-- | actions/widgets/upgrade.php | 65 |
6 files changed, 219 insertions, 113 deletions
diff --git a/actions/widgets/add.php b/actions/widgets/add.php index ff4af4a47..d7b2f291c 100644 --- a/actions/widgets/add.php +++ b/actions/widgets/add.php @@ -1,43 +1,42 @@ -<?php
-
- /**
- * Elgg widget add action
- *
- * @package Elgg
- * @subpackage Core
- * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
- * @author Curverider Ltd
- * @copyright Curverider Ltd 2008-2009
- * @link http://elgg.org/
- */
-
- $guid = get_input('user');
- $handler = get_input('handler');
- $context = get_input('context');
- $column = get_input('column');
-
- $result = false;
-
- if (!empty($guid)) {
-
- if ($user = get_entity($guid)) {
-
- if ($user->canEdit()) {
-
- $result = add_widget($user->getGUID(),$handler,$context,0,$column);
-
- }
-
- }
-
- }
-
- 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 +<?php +/** + * Elgg widget add action + * + * @package Elgg.Core + * @subpackage Widgets.Management + */ + +$owner_guid = get_input('owner_guid'); +$handler = get_input('handler'); +$context = get_input('context'); +$show_access = (bool)get_input('show_access', true); +$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($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); + + // send widget html for insertion + echo elgg_view_entity($widget, array('show_access' => $show_access)); + + //system_message(elgg_echo('widgets:add:success')); + forward(REFERER); + } + } +} + +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 47f799889..e43a0ba73 100644 --- a/actions/widgets/reorder.php +++ b/actions/widgets/reorder.php @@ -1,32 +1,24 @@ -<?php
-
- /**
- * Elgg widget reorder action
- *
- * @package Elgg
- * @subpackage Core
- * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
- * @author Curverider Ltd
- * @copyright Curverider Ltd 2008-2009
- * @link http://elgg.org/
- */
-
-
- $owner = get_input('owner');
- $context = get_input('context');
-
- $maincontent = get_input('debugField1');
- $sidebar = get_input('debugField2');
- $rightbar = get_input('debugField3');
-
- $result = reorder_widgets_from_panel($maincontent, $sidebar, $rightbar, $context, $owner);
-
- if ($result) {
- system_message(elgg_echo('widgets:panel:save:success'));
- } else {
- register_error(elgg_echo('widgets:panel:save:failure'));
- }
-
- forward($_SERVER['HTTP_REFERER']);
-
-?>
\ No newline at end of file +<?php +/** + * Elgg widget reorder action + * + * @package Elgg.Core + * @subpackage Widgets.Management + */ + +$owner = get_input('owner'); +$context = get_input('context'); + +$maincontent = get_input('debugField1'); +$sidebar = get_input('debugField2'); +$rightbar = get_input('debugField3'); + +$result = reorder_widgets_from_panel($maincontent, $sidebar, $rightbar, $context, $owner); + +if ($result) { + system_message(elgg_echo('widgets:panel:save:success')); +} else { + register_error(elgg_echo('widgets:panel:save:failure')); +} + +forward(REFERER);
\ No newline at end of file diff --git a/actions/widgets/save.php b/actions/widgets/save.php index e86632c6e..e15deab77 100644 --- a/actions/widgets/save.php +++ b/actions/widgets/save.php @@ -1,38 +1,44 @@ -<?php
-
- /**
- * Elgg widget save action
- *
- * @package Elgg
- * @subpackage Core
- * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
- * @author Curverider Ltd
- * @copyright Curverider Ltd 2008-2009
- * @link http://elgg.org/
- */
-
- action_gatekeeper(); -
- $guid = get_input('guid');
- $params = $_REQUEST['params'];
- $pageurl = get_input('pageurl');
- $noforward = get_input('noforward',false);
-
- $result = false;
-
- if (!empty($guid)) {
-
- $result = save_widget_info($guid,$params);
-
- }
-
- if ($result) {
- system_message(elgg_echo('widgets:save:success'));
- } else {
- register_error(elgg_echo('widgets:save:failure'));
- }
-
- if (!$noforward)
- forward($_SERVER['HTTP_REFERER']);
-
-?>
\ No newline at end of file +<?php +/** + * 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. + * + */ + +elgg_set_context('widgets'); + +$guid = get_input('guid'); +$params = get_input('params'); +$default_widgets = get_input('default_widgets', 0); +$context = get_input('context'); + +$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')); +} + +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); |
