Skip to content

Commit a89771f

Browse files
committed
changed: updated for ELgg 6.2
1 parent d9c9fc1 commit a89771f

File tree

11 files changed

+165
-93
lines changed

11 files changed

+165
-93
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
The Wire Tools
22
==============
33

4-
![Elgg 6.0](https://img.shields.io/badge/Elgg-6.0-green.svg)
4+
![Elgg 6.2](https://img.shields.io/badge/Elgg-6.2-green.svg)
55
![Lint Checks](https://github.com/ColdTrick/thewire_tools/actions/workflows/lint.yml/badge.svg?event=push)
66
[![Latest Stable Version](https://poser.pugx.org/coldtrick/thewire_tools/v/stable.svg)](https://packagist.org/packages/coldtrick/thewire_tools)
77
[![License](https://poser.pugx.org/coldtrick/thewire_tools/license.svg)](https://packagist.org/packages/coldtrick/thewire_tools)

actions/thewire/add.php

Lines changed: 0 additions & 44 deletions
This file was deleted.
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
3+
namespace ColdTrick\TheWireTools\Controllers;
4+
5+
use Elgg\Exceptions\Http\ValidationException;
6+
7+
/**
8+
* Additions to the core TheWire EditAction
9+
* - allow group content / access
10+
* - link reshared content
11+
*/
12+
class EditAction extends \Elgg\TheWire\Controllers\EditAction {
13+
14+
/**
15+
* {@inheritdoc}
16+
*/
17+
protected function validate(): void {
18+
parent::validate();
19+
20+
// validate container guid (to allow for group content)
21+
if (elgg_get_plugin_setting('enable_group', 'thewire_tools') !== 'yes') {
22+
$this->request->setParam('container_guid', null);
23+
} else {
24+
$container_guid = (int) $this->request->getParam('container_guid');
25+
26+
$group = get_entity($container_guid);
27+
if ($group instanceof \ElggGroup) {
28+
if (!$group->isToolEnabled('thewire')) {
29+
// not allowed to post in this group
30+
throw new ValidationException(elgg_echo('thewire_tools:groups:error:not_enabled'));
31+
}
32+
}
33+
}
34+
}
35+
36+
/**
37+
* {@inheritdoc}
38+
*/
39+
protected function execute(array $skip_field_names = []): void {
40+
$skip_field_names[] = 'access_id';
41+
42+
parent::execute($skip_field_names);
43+
44+
// save access ID
45+
$this->entity->access_id = $this->getAccessID();
46+
}
47+
48+
/**
49+
* {@inheritdoc}
50+
*/
51+
protected function executeAfter(): void {
52+
parent::executeAfter();
53+
54+
// save reshare guid
55+
$reshare_guid = (int) $this->request->getParam('reshare_guid');
56+
if ($reshare_guid > 0) {
57+
$this->entity->addRelationship($reshare_guid, 'reshare');
58+
}
59+
}
60+
61+
/**
62+
* Get the correct access_id for content in groups etc
63+
*
64+
* @return int
65+
*/
66+
protected function getAccessID(): int {
67+
$access_id = (int) $this->request->getParam('access_id', ACCESS_PUBLIC);
68+
if ($access_id === -100) {
69+
$access_id = null;
70+
}
71+
72+
if (elgg_get_plugin_setting('enable_group', 'thewire_tools') === 'yes') {
73+
$container_guid = (int) $this->request->getParam('container_guid');
74+
75+
$group = get_entity($container_guid);
76+
if ($group instanceof \ElggGroup) {
77+
$acl = $group->getOwnedAccessCollection('group_acl');
78+
if ($acl instanceof \ElggAccessCollection) {
79+
if (is_null($access_id) || $group->getContentAccessMode() === \ElggGroup::CONTENT_ACCESS_MODE_MEMBERS_ONLY) {
80+
$access_id = $acl->id;
81+
}
82+
}
83+
}
84+
}
85+
86+
// check the access id
87+
if ($access_id === ACCESS_PRIVATE) {
88+
// private wire posts aren't allowed
89+
$access_id = ACCESS_LOGGED_IN;
90+
}
91+
92+
if (is_null($access_id)) {
93+
$access_id = ACCESS_PUBLIC;
94+
}
95+
96+
return $access_id;
97+
}
98+
}

classes/ColdTrick/TheWireTools/Widgets.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,25 @@ public static function widgetTitleURL(\Elgg\Event $event): ?string {
2323
switch ($widget->handler) {
2424
case 'thewire':
2525
$owner = $widget->getOwnerEntity();
26-
if (!$owner instanceof \ElggGroup) {
27-
return null;
26+
27+
switch ($widget->owner) {
28+
case 'friends':
29+
return elgg_generate_url('collection:object:thewire:friends', [
30+
'username' => $owner->username,
31+
]);
32+
33+
case 'all':
34+
return elgg_generate_url('collection:object:thewire:all');
35+
36+
default:
37+
if ($owner instanceof \ElggGroup) {
38+
return elgg_generate_url('collection:object:thewire:group', [
39+
'guid' => $owner->guid,
40+
]);
41+
}
42+
break;
2843
}
29-
return elgg_generate_url('collection:object:thewire:group', [
30-
'guid' => $owner->guid,
31-
]);
44+
break;
3245

3346
case 'index_thewire':
3447
case 'thewire_post':

elgg-plugin.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
<?php
22

33
use ColdTrick\TheWireTools\Notifications\CreateTheWireEventHandler;
4-
use Elgg\Blog\GroupToolContainerLogicCheck;
54
use Elgg\Router\Middleware\GroupPageOwnerGatekeeper;
65

7-
require_once(dirname(__FILE__) . '/lib/functions.php');
8-
96
return [
107
'plugin' => [
118
'version' => '14.0.3',
@@ -21,7 +18,13 @@
2118
'extend_activity' => 'no',
2219
],
2320
'actions' => [
24-
'thewire/add' => [],
21+
'thewire/add' => [
22+
'controller' => \ColdTrick\TheWireTools\Controllers\EditAction::class,
23+
'options' => [
24+
'entity_type' => 'object',
25+
'entity_subtype' => 'thewire',
26+
],
27+
],
2528
'thewire_tools/toggle_feature' => [],
2629
],
2730
'events' => [

views/default/forms/thewire/add.php

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
elgg_require_css('forms/thewire/add');
99

1010
$post = elgg_extract('post', $vars);
11-
$char_limit = thewire_tools_get_wire_length();
11+
$char_limit = (int) elgg_get_plugin_setting('limit', 'thewire');
1212
$reshare = elgg_extract('reshare', $vars); // for reshare functionality
1313

1414
$text = elgg_echo('post');
@@ -22,15 +22,6 @@
2222
]);
2323
}
2424

25-
$chars_left = elgg_echo('thewire:charleft');
26-
27-
$count_down = ($char_limit === 0) ? '' : elgg_format_element('span', [], $char_limit) . " {$chars_left}";
28-
$num_lines = ($char_limit === 0) ? 3 : 2;
29-
30-
if ($char_limit > 140) {
31-
$num_lines = 3;
32-
}
33-
3425
if ($char_limit && !elgg_is_active_plugin('ckeditor')) {
3526
elgg_import_esm('forms/thewire/add');
3627
}
@@ -56,16 +47,20 @@
5647
$post_value = htmlspecialchars_decode($post_value, ENT_QUOTES);
5748
}
5849

59-
echo elgg_view('input/longtext', [
60-
'name' => 'body',
61-
'value' => $post_value,
62-
'class' => 'thewire-textarea',
63-
'rows' => $num_lines,
64-
'data-max-length' => $char_limit,
65-
'required' => true,
66-
'placeholder' => elgg_echo('thewire:form:body:placeholder'),
67-
'editor_type' => 'thewire',
68-
]);
50+
$fields = elgg()->fields->get('object', 'thewire');
51+
52+
foreach ($fields as $field) {
53+
$name = $field['name'];
54+
$default = null;
55+
56+
if ($name === 'description') {
57+
$default = $post_value;
58+
}
59+
60+
$field['value'] = elgg_extract($name, $vars, $default);
61+
62+
echo elgg_view_field($field);
63+
}
6964

7065
// form footer
7166
$fields = [
@@ -86,6 +81,8 @@
8681
];
8782

8883
if ($char_limit > 0) {
84+
$count_down = elgg_format_element('span', [], $char_limit) . ' ' . elgg_echo('thewire:charleft');
85+
8986
$chars = elgg_format_element('div', ['class' => 'elgg-field-input'], $count_down);
9087

9188
$fields[] = [

views/default/forms/thewire/add/access.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,8 @@
4848
$access_options[ACCESS_LOGGED_IN] = elgg_echo('thewire_tools:add:access', [elgg_echo('access:label:logged_in')]);
4949
$access_options[-100] = elgg_echo('thewire_tools:add:access:group');
5050

51-
$access_params = [
51+
echo elgg_view_field([
5252
'#type' => 'access',
5353
'name' => 'access_id',
5454
'options_values' => $access_options,
55-
];
56-
57-
echo elgg_view_field($access_params);
55+
]);

views/default/forms/thewire/add/container.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
}
2020

2121
$page_owner_entity = elgg_get_page_owner_entity();
22-
2322
if ($page_owner_entity instanceof \ElggGroup) {
2423
// in a group only allow sharing in the current group
2524
echo elgg_view_field([

views/default/object/thewire.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,20 @@
5151

5252
elgg_push_context('input');
5353
$content = elgg_view('output/longtext', [
54-
'value' => elgg_sanitize_input(thewire_filter($text)) . $more_link,
54+
'value' => elgg_sanitize_input($text) . $more_link,
5555
'id' => "thewire-summary-view-{$entity->guid}",
5656
'data-toggle-slide' => 0,
5757
'sanitize' => false, // already done and will cause issues with the more link
58+
'parse_thewire_hashtags' => true,
5859
]);
5960

6061
if (!empty($more_content)) {
6162
$content .= elgg_view('output/longtext', [
62-
'value' => elgg_sanitize_input(thewire_filter($more_content)),
63+
'value' => elgg_sanitize_input($more_content),
6364
'id' => "thewire-full-view-{$entity->guid}",
6465
'class' => 'hidden',
6566
'sanitize' => false, // already done
67+
'parse_thewire_hashtags' => true,
6668
]);
6769
}
6870

@@ -99,8 +101,8 @@
99101

100102
$params = [
101103
'title' => false,
102-
'access' => false,
103104
'tags' => false,
105+
'access' => false,
104106
'icon_entity' => $entity->getOwnerEntity(),
105107
];
106108

views/default/river/object/thewire/create.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<?php
22

3-
/* @var $item ElggRiverItem */
43
$item = elgg_extract('item', $vars);
4+
if (!$item instanceof \ElggRiverItem) {
5+
return;
6+
}
57

68
$object = $item->getObjectEntity();
79
$excerpt = elgg_get_excerpt((string) $object->description);
8-
$excerpt = thewire_filter($excerpt);
9-
if (substr($excerpt, -3) === '...') {
10+
if (str_ends_with($excerpt, '...')) {
1011
// add read more link
1112
$excerpt .= '&nbsp;' . elgg_view('output/url', [
1213
'text' => strtolower(elgg_echo('more')),
@@ -49,7 +50,10 @@
4950

5051
echo elgg_view('river/elements/layout', [
5152
'item' => $item,
52-
'message' => elgg_view('output/longtext', ['value' => $excerpt]),
53+
'message' => elgg_view('output/longtext', [
54+
'value' => $excerpt,
55+
'parse_thewire_hashtags' => true,
56+
]),
5357
'summary' => $summary,
5458
'attachments' => $attachments,
5559
]);

0 commit comments

Comments
 (0)