add.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. /**
  3. * Elgg widget add action
  4. *
  5. * @package Elgg.Core
  6. * @subpackage Widgets.Management
  7. */
  8. $page_owner_guid = get_input('page_owner_guid');
  9. $handler = get_input('handler');
  10. $context = get_input('context');
  11. $show_access = (bool)get_input('show_access', true);
  12. $column = get_input('column', 1);
  13. $default_widgets = get_input('default_widgets', 0);
  14. elgg_set_page_owner_guid($page_owner_guid);
  15. elgg_push_context($context);
  16. if ($default_widgets) {
  17. elgg_push_context('default_widgets');
  18. }
  19. elgg_push_context('widgets');
  20. // logged in user must be able to edit the layout to add a widget
  21. $page_owner = elgg_get_page_owner_entity();
  22. if ($page_owner && elgg_can_edit_widget_layout($context)) {
  23. $guid = elgg_create_widget($page_owner->getGUID(), $handler, $context);
  24. if ($guid) {
  25. $widget = get_entity($guid);
  26. // position the widget
  27. $widget->move($column, 0);
  28. // send widget html for insertion
  29. echo elgg_view_entity($widget, array('show_access' => $show_access));
  30. forward(REFERER);
  31. }
  32. }
  33. register_error(elgg_echo('widgets:add:failure'));
  34. forward(REFERER);