* * @package Elgg.Core * @subpackage Widgets.Management */ $page_owner_guid = get_input('page_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_set_page_owner_guid($page_owner_guid); elgg_push_context($context); if ($default_widgets) { elgg_push_context('default_widgets'); } elgg_push_context('widgets'); // logged in user must be able to edit the layout to add a widget $page_owner = elgg_get_page_owner_entity(); if ($page_owner && elgg_can_edit_widget_layout($context)) { $guid = elgg_create_widget($page_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)); forward(REFERER); } } register_error(elgg_echo('widgets:add:failure')); forward(REFERER);
* @uses $vars['num_columns'] Number of widget columns for this layout (3) * @uses $vars['show_add_widgets'] Display the add widgets button and panel (true) * @uses $vars['exact_match'] Widgets must match the current context (false) * @uses $vars['show_access'] Show the access control (true) */ $num_columns = elgg_extract('num_columns', $vars, 2); $show_add_widgets = elgg_extract('show_add_widgets', $vars, true); $exact_match = elgg_extract('exact_match', $vars, false); $show_access = elgg_extract('show_access', $vars, true); $owner = elgg_get_page_owner_entity(); $widget_types = elgg_get_widget_types(); $context = elgg_get_context(); elgg_push_context('widgets'); $widgets = elgg_get_widgets($owner->guid, $context); echo '<div class="elgg-layout-widgets">'; if (elgg_can_edit_widget_layout($context)) { if ($show_add_widgets) { echo elgg_view('page/layouts/widgets/add_button'); } $params = array('widgets' => $widgets, 'context' => $context, 'exact_match' => $exact_match, 'show_access' => $show_access, 'class' => 'btn btn-primary mrgn-bttm-sm'); echo elgg_view('page/layouts/widgets/add_panel', $params); } /* if (isset($vars['content'])) { echo $vars['content']; } */ //$widget_class = "elgg-col-1of{$num_columns}"; $widget_class = "col-sm-6"; for ($column_index = 1; $column_index <= $num_columns; $column_index++) { if (isset($widgets[$column_index])) {
$widget_types = elgg_get_widget_types("index", false); elgg_push_context('widgets'); $widgets = elgg_get_widgets(elgg_get_page_owner_guid(), $handler); $widget_content = ""; if (isset($widgets[4])) { $column_widgets = $widgets[4]; if (sizeof($column_widgets) > 0) { foreach ($column_widgets as $widget) { if (array_key_exists($widget->handler, $widget_types)) { $widget_content .= elgg_view_entity($widget, array('show_access' => true)); } } } } $top_row = "<div id='elgg-widget-col-4' class='elgg-widgets'>" . $widget_content . "</div>"; if (elgg_can_edit_widget_layout($handler)) { $min_height = "min-height: 50px !important;"; } else { $min_height = "min-height: 0px !important;"; } $style .= "#elgg-widget-col-4 { width: " . $top_row_width . "%;" . $min_height . $float . "}"; elgg_pop_context(); $top_row_used = true; } if (!empty($style)) { $style = "<style type='text/css'>" . $style . "</style>"; } // draw the page $params = ['content' => $top_row, 'top_row_used' => $top_row_used, 'num_columns' => $num_columns, 'exact_match' => true]; $content = elgg_view_layout('widgets', $params); $body = elgg_view_layout('one_column', ['content' => $style . $content, 'title' => false]);
function widget_reminder($hook, $type, $return, $params) { $group = elgg_get_page_owner_entity(); if (elgg_instanceof($group, 'group')) { $groupid = $group->getGUID(); $context = elgg_get_context(); if (elgg_can_edit_widget_layout($context)) { if ($context == 'group_profile' && elgg_is_active_plugin('widget_manager') && elgg_get_plugin_setting("group_enable", "widget_manager") == "yes" && $group->widget_manager_enable == "yes") { $options = array('type' => 'object', 'subtype' => 'widget', 'container_guid' => $groupid); $widgets = elgg_get_entities($options); if (count($widgets) == 0) { //elgg_extend_view('groups/profile/widgets','au_landing/widget_reminder'); return $return . elgg_echo('au_landing:widget_reminder'); } } } } }
// Underlying views and functions assume that the page owner is the owner of the widgets if ($owner->guid != $page_owner->guid) { elgg_set_page_owner_guid($owner->guid); } $context = elgg_get_context(); $widgets = elgg_get_widgets($owner->guid, $context); $result = ''; $no_widgets = elgg_extract('no_widgets', $vars); if (empty($widgets) && !empty($no_widgets)) { if ($no_widgets instanceof \Closure) { echo $no_widgets(); } else { $result .= $no_widgets; } } if ($show_add_widgets && elgg_can_edit_widget_layout($context)) { $result .= elgg_view('page/layouts/widgets/add_button', $vars); } // push context after the add_button as add button uses current context elgg_push_context('widgets'); if ($widgets) { $widget_types = elgg_get_widget_types(['context' => $context, 'container' => $owner]); } $widget_class = "elgg-col-1of{$num_columns}"; // move hidden columns widgets to last visible column if (!isset($widgets[$num_columns])) { $widgets[$num_columns] = []; } foreach ($widgets as $index => $column_widgets) { if ($index <= $num_columns) { continue;
<?php /** * Elgg widget delete action * * @package Elgg.Core * @subpackage Widgets.Management */ $widget = get_entity(get_input('widget_guid')); if ($widget) { $layout_owner_guid = $widget->getContainerGUID(); elgg_set_page_owner_guid($layout_owner_guid); if (elgg_can_edit_widget_layout($widget->context) && $widget->delete()) { forward(REFERER); } } register_error(elgg_echo('widgets:remove:failure')); forward(REFERER);
/** * Checks if current user can edit a widget if it is in a context he/she can manage * * @param string $hook_name name of the hook * @param string $entity_type type of the hook * @param string $return_value current return value * @param array $params hook parameters * * @return boolean */ function widget_manager_permissions_check_object_hook_handler($hook_name, $entity_type, $return_value, $params) { $user = elgg_extract('user', $params); $entity = elgg_extract('entity', $params); if ($return_value || !$user) { return $return_value; } if (!$entity instanceof ElggWidget) { return $return_value; } $site = $entity->getOwnerEntity(); if (!$site instanceof ElggSite) { // special permission is only for widget owned by site return $return_value; } $context = $entity->context; if ($context) { $return_value = elgg_can_edit_widget_layout($context, $user->getGUID()); } return $return_value; }
$show_access = elgg_extract('show_access', $vars, true); $owner = elgg_get_page_owner_entity(); $context = elgg_get_context(); $available_widgets_context = elgg_trigger_plugin_hook('available_widgets_context', 'widget_manager', [], $context); $widget_types = elgg_get_widget_types(['context' => $available_widgets_context, 'exact' => $exact_match, 'container' => $owner]); elgg_push_context('widgets'); $widgets = elgg_extract('widgets', $vars); if (!isset($vars['widgets'])) { $widgets = elgg_get_widgets($owner->guid, $context); } $top_row_used = elgg_extract('top_row_used', $vars); if ($top_row_used) { unset($widgets[4]); } echo "<div class='elgg-layout-widgets layout-widgets-{$context}'>"; if (elgg_can_edit_widget_layout($context) && $show_add_widgets) { echo elgg_view('page/layouts/widgets/add_button', ['context' => $context, 'exact_match' => $exact_match, 'show_access' => $show_access]); } if (empty($widgets) || $context !== 'dashboard') { echo elgg_extract('content', $vars); } if ($context == 'groups') { $groups_top_row = ''; if (isset($widgets[3]) && sizeof($widgets[3]) > 0) { foreach ($widgets[3] as $widget) { if (array_key_exists($widget->handler, $widget_types)) { $groups_top_row .= elgg_view_entity($widget, ['show_access' => $show_access]); } } } echo elgg_format_element('div', ['id' => 'elgg-widget-col-3', 'class' => 'elgg-col-1of1 elgg-widgets widget-manager-groups-widgets-top-row'], $groups_top_row);
<?php /** * Elgg widget delete action * * @package Elgg.Core * @subpackage Widgets.Management */ $widget_guid = (int) get_input('widget_guid'); $widget = get_entity($widget_guid); if (!$widget instanceof \ElggWidget) { return elgg_error_response(elgg_echo('widgets:remove:failure')); } elgg_set_page_owner_guid($widget->getContainerGUID()); if (!elgg_can_edit_widget_layout($widget->context)) { return elgg_error_response(elgg_echo('widgets:remove:failure')); } if (!$widget->delete()) { return elgg_error_response(elgg_echo('widgets:remove:failure')); } return elgg_ok_response();