Skip to content

Commit

Permalink
changed: updated for Elgg 6
Browse files Browse the repository at this point in the history
  • Loading branch information
jeabakker committed May 14, 2024
1 parent d72b633 commit 7006b36
Show file tree
Hide file tree
Showing 17 changed files with 75 additions and 213 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ name: PHPUnit Plugin Tests
on: [push, pull_request]

jobs:
lint:
phpunit:
name: Run PHPUnit test suites
uses: ColdTrick/.github/.github/workflows/phpunit.yml@master
with:
elgg_major_version: 6
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Blog Tools
==========

![Elgg 5.1](https://img.shields.io/badge/Elgg-5.1-green.svg)
![Elgg 6.0](https://img.shields.io/badge/Elgg-6.0-green.svg)
![Lint Checks](https://github.com/ColdTrick/blog_tools/actions/workflows/lint.yml/badge.svg?event=push)
[![Latest Stable Version](https://poser.pugx.org/coldtrick/blog_tools/v/stable.svg)](https://packagist.org/packages/coldtrick/blog_tools)
[![License](https://poser.pugx.org/coldtrick/blog_tools/license.svg)](https://packagist.org/packages/coldtrick/blog_tools)
Expand Down
7 changes: 3 additions & 4 deletions classes/ColdTrick/BlogTools/Cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Cron {
*
* @return void
*/
public static function publication(\Elgg\Event $event) {
public static function publication(\Elgg\Event $event): void {
// only do if this is configured
if (elgg_get_plugin_setting('advanced_publication', 'blog_tools') !== 'yes') {
return;
Expand All @@ -35,10 +35,9 @@ public static function publication(\Elgg\Event $event) {
*
* @return void
*/
protected static function publishBlogs($time) {

protected static function publishBlogs(int $time): void {
// adjust for time drift of the cron start
// eg. CRON started @ 11:00:05
// e.g. CRON started @ 11:00:05
$time_min = $time - 60; // - 1 minute
$time_max = $time + 60; // + 1 minute

Expand Down
83 changes: 0 additions & 83 deletions classes/ColdTrick/BlogTools/Upgrades/MoveHeaderIcons.php

This file was deleted.

26 changes: 3 additions & 23 deletions classes/ColdTrick/BlogTools/Views.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,16 @@ class Views {
*
* @param \Elgg\Event $event 'view_vars', 'blog/sidebar/archives'
*
* @return void|array
* @return null|array
*/
public static function preventBlogArchiveSidebar(\Elgg\Event $event) {

public static function preventBlogArchiveSidebar(\Elgg\Event $event): ?array {
if (!(bool) elgg_get_plugin_setting('archive_menu', 'blog_tools')) {
return;
return null;
}

$return = $event->getValue();
$return[ViewsService::OUTPUT_KEY] = '';

return $return;
}

/**
* Prevent double submit of the blog/save form
*
* @param \Elgg\Event $event 'view_vars', 'input/form'
*
* @return null|array
* @todo remove in Elgg 5.1
*/
public static function preventDoubleSubmit(\Elgg\Event $event): ?array {
$vars = $event->getValue();
if (elgg_extract('action_name', $vars) !== 'blog/save') {
return null;
}

$vars['prevent_double_submit'] = true;

return $vars;
}
}
31 changes: 7 additions & 24 deletions classes/ColdTrick/BlogTools/Widgets.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,20 @@ class Widgets {
*
* @param \Elgg\Event $event 'entity:url', 'object'
*
* @return void|string
* @return null|string
*/
public static function widgetUrl(\Elgg\Event $event) {

public static function widgetUrl(\Elgg\Event $event): ?string {
if (!empty($event->getValue())) {
return;
// url already provided
return null;
}

$widget = $event->getEntityParam();
if (!$widget instanceof \ElggWidget) {
return;
if (!$widget instanceof \ElggWidget || $widget->handler !== 'index_blog') {
return null;
}

switch ($widget->handler) {
case 'index_blog':
return elgg_generate_url('collection:object:blog:all');

case 'blog':
$owner = $widget->getOwnerEntity();
if ($owner instanceof \ElggUser) {
return elgg_generate_url('collection:object:blog:owner', [
'username' => $owner->username,
]);
} elseif ($owner instanceof \ElggGroup) {
return elgg_generate_url('collection:object:blog:group', [
'guid' => $owner->guid,
]);
}
break;
}
return elgg_generate_url('collection:object:blog:all');
}

/**
Expand All @@ -52,7 +36,6 @@ public static function widgetUrl(\Elgg\Event $event) {
* @return void|array
*/
public static function groupTools(\Elgg\Event $event) {

$entity = $event->getEntityParam();
if (!$entity instanceof \ElggGroup) {
return;
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"issues": "https://github.com/ColdTrick/blog_tools/issues"
},
"conflict": {
"elgg/elgg": "<5.1"
"elgg/elgg": "<6.0"
}
}
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions elgg-plugin.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

use ColdTrick\BlogTools\Upgrades\MoveHeaderIcons;

return [
'plugin' => [
'version' => '13.0.1',
Expand All @@ -16,9 +14,6 @@
'archive_menu' => false,
'advanced_publication' => 'no',
],
'upgrades' => [
MoveHeaderIcons::class,
],
'actions' => [
'blog/save' => [],
'blog_tools/toggle_featured' => [
Expand Down Expand Up @@ -74,9 +69,6 @@
'blog/sidebar/archives' => [
'\ColdTrick\BlogTools\Views::preventBlogArchiveSidebar' => [],
],
'input/form' => [
'\ColdTrick\BlogTools\Views::preventDoubleSubmit' => [],
],
],
],
'view_extensions' => [
Expand Down
3 changes: 0 additions & 3 deletions languages/en.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,4 @@
'blog_tools:widgets:index_blog:view_mode:preview' => "Preview",
'blog_tools:widgets:index_blog:view_mode:slider' => "Slider",
'blog_tools:widgets:index_blog:view_mode:simple' => "Simple",

'blog_tools:upgrade:2023032800:title' => "Move blog icons to header images",
'blog_tools:upgrade:2023032800:description' => "In Elgg 5 there is built in header image support. This migration moves old icons uploaded with blogs to this new location.",
];
2 changes: 0 additions & 2 deletions languages/nl.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
*/

return array (
'blog_tools:upgrade:2023032800:title' => 'Verplaats blog iconen naar kopafbeeldingen',
'blog_tools:upgrade:2023032800:description' => 'In Elgg 5 is ondersteuning voor kopafbeeldingen. Deze migratie verplaatst de oude iconen naar de nieuwe locatie.',
'collection:object:blog:tag' => 'Blogs met de tag: %s',
'blog_tools:label:publication_time' => 'Publicatie tijd',
'blog_tools:publication_time:description' => 'In combinatie met de publicatie datum, stelt dit de tijd van publicatie in',
Expand Down
2 changes: 1 addition & 1 deletion views/default/forms/blog/save.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* - status moved to blog_tools/edit/publication_options
*/

elgg_require_js('forms/blog/save');
elgg_import_esm('forms/blog/save');

$blog = elgg_extract('entity', $vars);

Expand Down
15 changes: 6 additions & 9 deletions views/default/widgets/blog/content.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
* User blog widget display view
*/

/* @var $widget \ElggWidget */
$widget = elgg_extract('entity', $vars);
if (!$widget instanceof \ElggWidget) {
return;
}

$num_display = (int) $widget->num_display ?: 4;

Expand All @@ -17,20 +19,17 @@
'metadata_name_value_pairs' => [],
'metadata_case_sensitive' => false,
'no_results' => elgg_echo('blog:none'),
'widget_more' => elgg_view_url($widget->getURL(), elgg_echo('blog:moreblogs')),
];

$owner = $widget->getOwnerEntity();
if ($owner instanceof \ElggUser) {
$options['owner_guid'] = $owner->guid;
$url = elgg_generate_url('collection:object:blog:owner', ['username' => $owner->username]);
} elseif ($owner instanceof \ElggGroup) {
$options['container_guid'] = $widget->owner_guid;
$url = elgg_generate_url('collection:object:blog:group', ['guid' => $owner->guid]);
} else {
$url = elgg_generate_url('collection:object:blog:all');
$options['container_guid'] = $owner->guid;
}

if (!elgg_is_admin_logged_in() && ($widget->owner_guid !== elgg_get_logged_in_user_guid())) {
if (!elgg_is_admin_logged_in() && ($owner->guid !== elgg_get_logged_in_user_guid())) {
$options['metadata_name_value_pairs'][] = [
'name' => 'status',
'value' => 'published',
Expand All @@ -45,6 +44,4 @@
];
}

$options['widget_more'] = elgg_view_url($url, elgg_echo('blog:moreblogs'));

echo elgg_list_entities($options);
3 changes: 1 addition & 2 deletions views/default/widgets/index_blog/blog/simple.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,5 @@
'subtitle' => false,
'show_social_menu' => false,
];
$params + $vars;

$params = $params + $vars;
echo elgg_view('object/elements/summary', $params);
10 changes: 5 additions & 5 deletions views/default/widgets/index_blog/content.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@
echo elgg_format_element('ul', $navigator_attr, implode(PHP_EOL, $lis));

?>
<script type='text/javascript'>
require(['widgets/index_blog/slider'], function(Slider) {
var slider = new Slider();
slider.init(<?php echo $widget->guid; ?>);
});
<script type='module'>
import Slider from 'widgets/index_blog/slider';

var slider = new Slider();
slider.init(<?php echo $widget->guid; ?>);
</script>
45 changes: 0 additions & 45 deletions views/default/widgets/index_blog/slider.js

This file was deleted.

Loading

0 comments on commit 7006b36

Please sign in to comment.