widgets.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * Elgg widgets layout
  4. *
  5. * @uses $vars['content'] Optional display box at the top of layout
  6. * @uses $vars['num_columns'] Number of widget columns for this layout (3)
  7. * @uses $vars['show_add_widgets'] Display the add widgets button and panel (true)
  8. * @uses $vars['exact_match'] Widgets must match the current context (false)
  9. * @uses $vars['show_access'] Show the access control (true)
  10. */
  11. $num_columns = elgg_extract('num_columns', $vars, 3);
  12. $show_add_widgets = elgg_extract('show_add_widgets', $vars, true);
  13. $exact_match = elgg_extract('exact_match', $vars, false);
  14. $show_access = elgg_extract('show_access', $vars, true);
  15. $owner = elgg_get_page_owner_entity();
  16. $widget_types = elgg_get_widget_types();
  17. $context = elgg_get_context();
  18. elgg_push_context('widgets');
  19. $widgets = elgg_get_widgets($owner->guid, $context);
  20. echo '<div class="elgg-layout-widgets">';
  21. if (elgg_can_edit_widget_layout($context)) {
  22. if ($show_add_widgets) {
  23. echo elgg_view('page/layouts/widgets/add_button');
  24. }
  25. $params = array(
  26. 'widgets' => $widgets,
  27. 'context' => $context,
  28. 'exact_match' => $exact_match,
  29. 'show_access' => $show_access,
  30. );
  31. echo elgg_view('page/layouts/widgets/add_panel', $params);
  32. }
  33. if (isset($vars['content'])) {
  34. echo $vars['content'];
  35. }
  36. $widget_class = "elgg-col-1of{$num_columns}";
  37. for ($column_index = 1; $column_index <= $num_columns; $column_index++) {
  38. if (isset($widgets[$column_index])) {
  39. $column_widgets = $widgets[$column_index];
  40. } else {
  41. $column_widgets = array();
  42. }
  43. echo "<div class=\"$widget_class elgg-widgets\" id=\"elgg-widget-col-$column_index\">";
  44. if (sizeof($column_widgets) > 0) {
  45. foreach ($column_widgets as $widget) {
  46. if (array_key_exists($widget->handler, $widget_types)) {
  47. echo elgg_view_entity($widget, array('show_access' => $show_access));
  48. }
  49. }
  50. }
  51. echo '</div>';
  52. }
  53. elgg_pop_context();
  54. echo elgg_view('graphics/ajax_loader', array('id' => 'elgg-widget-loader'));
  55. echo '</div>';