widget.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * Widget object
  4. *
  5. * @uses $vars['entity'] ElggWidget
  6. * @uses $vars['show_access'] Show the access control in edit area? (true)
  7. * @uses $vars['class'] Optional additional CSS class
  8. */
  9. $widget = $vars['entity'];
  10. if (!elgg_instanceof($widget, 'object', 'widget')) {
  11. return true;
  12. }
  13. $show_access = elgg_extract('show_access', $vars, true);
  14. // @todo catch for disabled plugins
  15. $widget_types = elgg_get_widget_types('all');
  16. $handler = $widget->handler;
  17. $title = $widget->getTitle();
  18. $edit_area = '';
  19. $can_edit = $widget->canEdit();
  20. if ($can_edit) {
  21. $edit_area = elgg_view('object/widget/elements/settings', array(
  22. 'widget' => $widget,
  23. 'show_access' => $show_access,
  24. ));
  25. }
  26. $controls = elgg_view('object/widget/elements/controls', array(
  27. 'widget' => $widget,
  28. 'show_edit' => $edit_area != '',
  29. ));
  30. $content = elgg_view('object/widget/elements/content', $vars);
  31. $widget_id = "elgg-widget-$widget->guid";
  32. $widget_instance = preg_replace('/[^a-z0-9-]/i', '-', "elgg-widget-instance-$handler");
  33. if ($can_edit) {
  34. $widget_class = "elgg-state-draggable $widget_instance";
  35. } else {
  36. $widget_class = "elgg-state-fixed $widget_instance";
  37. }
  38. $additional_class = elgg_extract('class', $vars, '');
  39. if ($additional_class) {
  40. $widget_class = "$widget_class $additional_class";
  41. }
  42. $widget_header = <<<HEADER
  43. <div class="elgg-widget-handle clearfix"><h3 class="elgg-widget-title">$title</h3>
  44. $controls
  45. </div>
  46. HEADER;
  47. $widget_body = <<<BODY
  48. $edit_area
  49. <div class="elgg-widget-content" id="elgg-widget-content-$widget->guid">
  50. $content
  51. </div>
  52. BODY;
  53. echo elgg_view_module('widget', '', $widget_body, array(
  54. 'class' => $widget_class,
  55. 'id' => $widget_id,
  56. 'header' => $widget_header,
  57. ));