Skip to content

Commit

Permalink
Merge branch 'refs/heads/elgg_51'
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGES.txt
#	elgg-plugin.php
  • Loading branch information
jdalsem committed Aug 7, 2024
2 parents 7dd25ae + 83e9d44 commit 61ad0ee
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 61 deletions.
4 changes: 4 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Version history
===============

16.2 (2024-08-07):

- added: widget page manager can now edit page on the front end

17.0 (2024-06-28):

- changed: updated for Elgg 6.0
Expand Down
17 changes: 14 additions & 3 deletions actions/widget_manager/widget_page.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
<?php

$entity_guid = (int) get_input('guid');
$entity = null;

if ($entity_guid) {
$entity = get_entity($entity_guid);
if (!$entity instanceof \WidgetPage) {
return elgg_error_response(elgg_echo('error:missing_data'));
} elseif (!$entity->canEdit()) {
return elgg_error_response(elgg_echo('actionunauthorized'));
}
}

$url = get_input('url');
if (empty($url)) {
if (empty($url) && !($entity instanceof \WidgetPage && !elgg_is_admin_logged_in())) {
return elgg_error_response(elgg_echo('error:missing_data'));
}

if (!isset($entity)) {
if (!$entity instanceof \WidgetPage) {
if (!elgg_is_admin_logged_in()) {
return elgg_error_response(elgg_echo('actionunauthorized'));
}

$entity = new \WidgetPage();
}

$entity->url = $url;
if (elgg_is_admin_logged_in()) {
$entity->url = $url;
}

$entity->title = get_input('title');
$entity->description = get_input('description');
$entity->show_description = (bool) get_input('show_description');
Expand Down
18 changes: 18 additions & 0 deletions classes/ColdTrick/WidgetManager/Access.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,22 @@ public static function moreRightsForWidgetManager(\Elgg\Event $event): void {
}
}
}

/**
* Only allow widget page delete by admins
*
* @param \Elgg\Event $event 'permissions_check:delete', 'object'
*
* @return boolean
*/
public static function onlyAdminsCanDeleteWidgetPages(\Elgg\Event $event) {
$user = $event->getUserParam();
$entity = $event->getEntityParam();

if (!$user instanceof \ElggUser || !$entity instanceof \WidgetPage) {
return;
}

return $user->isAdmin();
}
}
9 changes: 6 additions & 3 deletions elgg-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@
'widget_manager/manage_widgets' => [
'access' => 'admin',
],
'widget_manager/widget_page' => [
'access' => 'admin',
],
'widget_manager/widget_page' => [],
'widget_manager/cleanup' => [
'access' => 'admin',
],
Expand Down Expand Up @@ -165,6 +163,11 @@
'\ColdTrick\WidgetManager\Widgets::layoutPermissionsCheck' => [],
],
],
'permissions_check:delete' => [
'object' => [
'\ColdTrick\WidgetManager\Access::onlyAdminsCanDeleteWidgetPages' => [],
],
],
'register' => [
'menu:admin_header' => [
'\ColdTrick\WidgetManager\Menus\AdminHeader::registerAdminHeaderMenu' => [],
Expand Down
4 changes: 3 additions & 1 deletion languages/en.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@
'widget_manager:settings:extra_contexts:description' => "Enter the page handler name of the new page which will get a layout similar to the index page. You can add as much pages as you need. Be sure not to add a page handler that is already in use. You can also configure the column layout for that page and optionally assign non-admin users as manager of the page.",
'widget_manager:settings:extra_contexts:page' => "Page",
'widget_manager:settings:extra_contexts:layout' => "Layout",
'widget_manager:settings:extra_contexts:manager' => "Manager",
'widget_manager:settings:extra_contexts:layout:help' => "Set the number of columns",
'widget_manager:settings:extra_contexts:manager' => "Managers",
'widget_manager:settings:extra_contexts:manager:help' => "Configure the users that are allowed to manage the page",

'widget_manager:settings:lazy_loading:enabled' => "Enable Lazy Loading",
'widget_manager:settings:lazy_loading:enabled:help' => "Globally enables the lazy loading feature",
Expand Down
4 changes: 3 additions & 1 deletion languages/nl.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@
'widget_manager:settings:group:force_tool_widgets:confirm' => 'Weet je het zeker? Dit zal widgets toevoegen/verwijderen die beheerd worden door een groep tool optie (voor de groepen waar widget management is ingeschakeld)',
'widget_manager:settings:extra_contexts:page' => 'Pagina',
'widget_manager:settings:extra_contexts:layout' => 'Layout',
'widget_manager:settings:extra_contexts:manager' => 'Beheerder',
'widget_manager:settings:extra_contexts:layout:help' => 'Bepaald het aantal kolommen',
'widget_manager:settings:extra_contexts:manager' => 'Beheerders',
'widget_manager:settings:extra_contexts:manager:help' => 'Gebruikers die deze pagina kunnen beheren',
'widget_manager:action:force_tool_widgets:error:not_enabled' => 'Widget beheer voor groepen is niet ingeschakeld',
'widget_manager:action:force_tool_widgets:success' => 'Widgets voor groep tool geforceerd bij %s groepen',
'widget_manager:settings:extra_contexts:description' => 'Voer de url in van de nieuwe pagina welke een layout gelijk de widget manager startpagina krijgt. U kunt zoveel pagina\'s toevoegen als nodig is. Vergewis uzelve dat opgegeven pagina nog niet in gebruik is. Alle widgets die normaliter op de voorpagina beschikbaar zijn, zullen ook op deze nieuwe pagina beschikbaar komen. U kunt ook de kolom indeling kiezen en optioneel gewone gebruikers als manager van deze pagina toewijzen.',
Expand Down
22 changes: 15 additions & 7 deletions views/default/forms/widget_manager/widget_page.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?php

$entity = elgg_extract('entity', $vars);
if (!$entity->canEdit()) {
throw new \Elgg\Exceptions\Http\EntityPermissionsException();
}

echo elgg_format_element('div', ['class' => 'elgg-subtext mbm'], elgg_echo('widget_manager:settings:extra_contexts:description'));

Expand All @@ -10,13 +13,15 @@
'value' => $entity?->guid,
]);

echo elgg_view_field([
'#type' => 'text',
'#label' => elgg_echo('widget_manager:settings:extra_contexts:page'),
'name' => 'url',
'value' => $entity?->url,
'required' => true,
]);
if (elgg_is_admin_logged_in()) {
echo elgg_view_field([
'#type' => 'text',
'#label' => elgg_echo('widget_manager:settings:extra_contexts:page'),
'name' => 'url',
'value' => $entity?->url,
'required' => true,
]);
}

echo elgg_view_field([
'#type' => 'text',
Expand Down Expand Up @@ -47,6 +52,7 @@
echo elgg_view_field([
'#type' => 'select',
'#label' => elgg_echo('widget_manager:settings:extra_contexts:layout'),
'#help' => elgg_echo('widget_manager:settings:extra_contexts:layout:help'),
'name' => 'layout',
'options_values' => [
'33|33|33' => elgg_echo('widget_manager:settings:widget_layout:33|33|33'),
Expand All @@ -66,8 +72,10 @@
echo elgg_view_field([
'#type' => 'userpicker',
'#label' => elgg_echo('widget_manager:settings:extra_contexts:manager'),
'#help' => elgg_echo('widget_manager:settings:extra_contexts:manager:help'),
'name' => 'manager',
'value' => $entity?->getManagers(),
'show_friends' => false,
]);

$footer = elgg_view_field([
Expand Down
48 changes: 43 additions & 5 deletions views/default/object/widget_page.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,49 @@
return;
}

$vars['icon'] = false;
$vars['byline'] = false;
if (!elgg_extract('full_view', $vars)) {
$vars['icon'] = false;
$vars['byline'] = false;

$title = $entity->getDisplayName() . " [{$entity->url}]";

$vars['title'] = elgg_view_url($entity->getURL(), elgg_get_excerpt($title, 100));

echo elgg_view('object/elements/summary', $vars);
return;
}

$num_columns = $entity->getNumColumns();
$layout = $entity->layout;

$title = $entity->getDisplayName() . " [{$entity->url}]";
$classes = [];
$column_classes = [];

$vars['title'] = elgg_view_url($entity->getURL(), elgg_get_excerpt($title, 100));
switch ($layout) {
case '33|33|33':
$classes[] = 'widgets-3-columns';
break;
case '50|50':
$classes[] = 'widgets-2-columns';
break;
default:
$classes[] = "widgets-{$num_columns}-columns";

$columns = array_reverse(explode('|', $layout));
foreach ($columns as $column_index => $column_width) {
$column_classes[$column_index + 1] = "col-width-{$column_width}";
}
break;
}

if ($entity->show_description !== false && !empty($entity->description)) {
echo elgg_view('output/longtext', ['value' => $entity->description, 'class' => 'widget-page-description']);
}

echo elgg_view('object/elements/summary', $vars);
echo elgg_view_layout('widgets', [
'class' => $classes,
'num_columns' => $num_columns,
'column_classes' => $column_classes,
'exact_match' => true,
'show_add_widgets' => false,
]);
45 changes: 4 additions & 41 deletions views/default/resources/widget_manager/widget_page.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,7 @@
elgg_push_context('index');
elgg_set_page_owner_guid($widget_page->guid);

$num_columns = $widget_page->getNumColumns();
$layout = $widget_page->layout;

$classes = [];
$column_classes = [];

switch ($layout) {
case '33|33|33':
$classes[] = 'widgets-3-columns';
break;
case '50|50':
$classes[] = 'widgets-2-columns';
break;
default:
$classes[] = "widgets-{$num_columns}-columns";

$columns = array_reverse(explode('|', $layout));
foreach ($columns as $column_index => $column_width) {
$column_classes[$column_index + 1] = "col-width-{$column_width}";
}
break;
}

$title = $widget_page->title ?: false;
if ($title && $widget_page->canEdit()) {
if ($widget_page->canEdit()) {
$href = elgg_generate_url('widgets:add_panel', [
'context' => elgg_get_context(),
'context_stack' => elgg_get_context_stack(),
Expand Down Expand Up @@ -85,21 +61,8 @@
]);
}

$content = '';

if ($widget_page->show_description !== false && !empty($widget_page->description)) {
$content .= elgg_view('output/longtext', ['value' => $widget_page->description, 'class' => 'widget-page-description']);
}

$content .= elgg_view_layout('widgets', [
'class' => $classes,
'num_columns' => $num_columns,
'column_classes' => $column_classes,
'exact_match' => true,
'show_add_widgets' => empty($title),
]);

echo elgg_view_page($widget_page->getDisplayName(), [
'title' => $title,
'content' => $content,
'title' => $widget_page->title ?: false,
'content' => elgg_view_entity($widget_page),
'entity' => $widget_page,
]);

0 comments on commit 61ad0ee

Please sign in to comment.